Inlining java native calls at runtime cascon 2005 4 th workshop on compiler driven performance
Download
1 / 36

Levon Stepanian, Angela Demke Brown Computer Systems Group - PowerPoint PPT Presentation


  • 162 Views
  • Uploaded on

Inlining Java Native Calls at Runtime (CASCON 2005 – 4 th Workshop on Compiler Driven Performance). Levon Stepanian, Angela Demke Brown Computer Systems Group Department of Computer Science, University of Toronto Allan Kielstra, Gita Koblents, Kevin Stoodley IBM Toronto Software Lab.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Levon Stepanian, Angela Demke Brown Computer Systems Group' - wyatt


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Inlining java native calls at runtime cascon 2005 4 th workshop on compiler driven performance

Inlining Java Native Calls at Runtime(CASCON 2005 – 4th Workshop on Compiler Driven Performance)

Levon Stepanian, Angela Demke Brown

Computer Systems Group

Department of Computer Science, University of Toronto

Allan Kielstra, Gita Koblents, Kevin Stoodley

IBM Toronto Software Lab


In a nutshell
In a nutshell

  • Runtime native function inlining into Java

    • Optimizing transformations on inlined JNI calls

    • Opaque and binary-compatible while boosting performance

Java Code

Native Function Call

Native Code


In a nutshell1
In a nutshell

  • Runtime native function inlining into Java

    • Optimizing transformations on inlined JNI calls

    • Opaque and binary-compatible while boosting performance

Java Code

Native Code

inlined


In a nutshell2
In a nutshell

  • Runtime native function inlining into Java

    • Optimizing transformations on inlined JNI calls

    • Opaque and binary-compatible while boosting performance

Java Code

Native Code

inlined

+

optimized


Motivation
Motivation

  • The JNI

    • Java’s interoperability API

    • Callouts and callbacks

    • Opaque

    • Binary-compatible

Java App

JVM + JIT

JNI

Callout

Callback

Native (Host) Environment

Native App/Lib


Motivation1
Motivation

  • The JNI

    • Pervasive

      • Legacy codes

      • Performance-critical, architecture-dependent

      • Features unavailable in Java (files, sockets etc.)


Motivation2
Motivation

  • Callouts run to 2 to 3x slower than Java calls

  • Callback overheads are an order of magnitude larger

    • JVM handshaking requirements for threads leaving and re-entering JVM context

    • i.e. stack switching, reference collection, exception handling

  • JIT compiler can’t predict side-effects of native function call


Our solution
Our Solution

  • JIT compiler based optimization that inlines native code into Java

  • JIT compiler transforms inlined JNI function calls to constants, cheaper operations

  • Inlined code exposed to JIT compiler optimizations


Infrastructure
Infrastructure

  • IBM TR JIT Compiler + IBM J9 VM

  • Native IL to JIT IL conversion mechanism

    • Exploit Native IL stored in native libraries

    • W-Code to TR-IL at runtime

Machine

code

+

TR JIT

Static

compiler IL


Outline
Outline

  • Background Information 

  • Method

  • Results

  • Future Work


Sample java class
Sample Java Class

class SetFieldXToFive{

public int x;

public native foo();

static{

System.loadLibrary(…);

}

}


Sample java class1
Sample Java Class

class SetFieldXToFive{

public int x;

public native foo();

static{

System.loadLibrary(…);

}

}


Sample native code
Sample Native Code

JNIEXPORT void JNICALL Java_SetFieldXToFive_foo

(JNIEnv * env, jobject obj){

jclass cls = (*env)->GetObjectClass(env,obj);

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

(*env)->SetIntField(env,obj,fid,5);

}

GOAL: obj.x = 5


Sample native code1
Sample Native Code

JNIEXPORT void JNICALL Java_SetFieldXToFive_foo

(JNIEnv * env, jobject obj){

jclass cls = (*env)->GetObjectClass(env,obj);

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

(*env)->SetIntField(env,obj,fid,5);

}

GOAL: obj.x = 5

SetFieldXToFive


Sample native code2
Sample Native Code

JNIEXPORT void JNICALL Java_SetFieldXToFive_foo

(JNIEnv * env, jobject obj){

jclass cls = (*env)->GetObjectClass(env,obj);

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

(*env)->SetIntField(env,obj,fid,5);

}

GOAL: obj.x = 5


Sample native code3
Sample Native Code

JNIEXPORT void JNICALL Java_SetFieldXToFive_foo

(JNIEnv * env, jobject obj){

jclass cls = (*env)->GetObjectClass(env,obj);

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

(*env)->SetIntField(env,obj,fid,5);

}

GOAL: obj.x = 5


Sample native code4
Sample Native Code

JNIEXPORT void JNICALL Java_SetFieldXToFive_foo

(JNIEnv * env, jobject obj){

jclass cls = (*env)->GetObjectClass(env,obj);

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

(*env)->SetIntField(env,obj,fid,5);

}

GOAL: obj.x = 5


Native inlining overview
Native Inlining Overview

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

  • Transforms inlined JNI calls

  • Finishes inlining


Method step 1
Method – Step 1

TR JIT

1. Inliner detects a native callsite

Inliner

Java Code

foo(){…}

(Native code)

Call to obj.foo()


Method step 2
Method – Step 2

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

Native IL

JIT IL


Method step 3
Method – Step 3

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

JIT IL

/* call to GetObjectClass */

/* call to GetFieldID */

/* call to SetFieldID */

Pre-constructed IL shapes


Method step 4
Method – Step 4

jclass cls =

(*env)->GetObjectClass(env,obj);

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

(*env)->SetIntField(env,obj,fid,5);

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

  • Transforms inlined JNI calls


Method step 41
Method – Step 4

jclass cls =

(*env)->GetObjectClass(env,obj);

Constant: SetFieldXToFive class data structure

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

  • Transforms inlined JNI calls

jfieldID fid =

(*env)->GetFieldID(env,cls,“x","I");

if (fid == NULL)

return;

Constant: Offset of field “x”

(*env)->SetIntField(env,obj,fid,5);

JIT IL: obj.x = 5


The big picture
The Big Picture

TR JIT

Before Native Inlining & Callback Transformations

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

  • Transforms inlined JNI calls

  • Finishes inlining

Inliner

Java Code

foo(){…}

(Native code)

Call to obj.foo()


The big picture1
The Big Picture

TR JIT

After Native Inlining & Callback Transformations

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

  • Transforms inlined JNI calls

  • Finishes inlining

Inliner

Java Code

foo(){…}

(Native code)

obj.x = 5


The big picture2
The Big Picture

TR JIT

After Native Inlining & Callback Transformations

  • Inliner detects a native callsite

  • Extracts and converts Native IL to JIT IL

  • Identifies inlined JNI calls

  • Transforms inlined JNI calls

  • Finishes inlining

Inliner

Java Code

obj.x = 5


Outline1
Outline

  • Background Information 

  • Method 

  • Results

  • Future Work


Experimental setup
Experimental Setup

  • Native function microbenchmarks

    • Average of 300 million runs

  • 1.4 GHz Power4 setup

  • Prototype implementation


Cost of il conversion
Cost of IL Conversion

  • 5.3 microseconds per W-Code


Inlining null callouts
Inlining Null Callouts

  • Null native method microbenchmarks

  • Varying numbers of args (0, 1, 3, 5)

    • Complete removal of call/return overhead

      • Gain back 2 to 3x slowdown

    • confirmed our expectations


Inlining non null callouts
Inlining Non-Null Callouts

  • smaller speedups for natives performing work

  • instance vs. static speedup


Inlining transforming callbacks
Inlining & Transforming Callbacks

  • Reclaim order of magnitude overhead


Data copy speedups
Data-Copy Speedups

Speedup (X)

Array Length

  • Transformed GetIntArrayRegion


Exposing inlined code to jit optimizations
Exposing Inlined Code To JIT Optimizations

FindClass

GetMethodID

NewCharArray

GetArrayLength


Conclusion
Conclusion

  • Runtime native function inlining into Java code

  • Optimizing transformations on inlined Java Native Interface (JNI) calls

  • JIT optimize inlined native code

  • Opaque and binary-compatible while boosting performance

  • Future Work

    • Engineering issues

    • Heuristics

    • Larger interoperability framework



ad