Inlining Java Native Calls at Runtime (CASCON 2005 – 4 th Workshop on Compiler Driven Performance) Levon Stepanian, Angela Demke Brown Computer Systems.

Slides:



Advertisements
Similar presentations
Efficient Program Compilation through Machine Learning Techniques Gennady Pekhimenko IBM Canada Angela Demke Brown University of Toronto.
Advertisements

C++ Programming Languages
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Compilation Technology Oct. 16, 2006 © 2006 IBM Corporation Software Group Reducing Startup Costs of Java Applications with Shared Relocatable Code Derek.
1 Jeannie: Granting Java Native Interface Developers their Wishes Martin HirzelRobert Grimm IBM Watson Research CenterNew York University October 23, 2007.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
More Specifically JNI Justin Catterson.  ADA  C++  Java  Ruby  Python  Haskell  Perl  etc. What is a Foreign Function Interface? Simply an interface.
Online Performance Auditing Using Hot Optimizations Without Getting Burned Jeremy Lau (UCSD, IBM) Matthew Arnold (IBM) Michael Hind (IBM) Brad Calder (UCSD)
Java Native Interface Modified from CS587x Lecture Department of Computer Science Iowa State University.
mbe/pa/olm 1 Integration of BETA with Eclipse eTX presentation Barcelona 2004 Peter Andersen Mads Brøgger Enevoldsen Ole Lehrmann Madsen.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
Administrivia No class next Monday (May 2) Enjoy extra time on P3. ;-) Reading 3 available “Reflections on Trusting Trust”, Ken Thompson No written summary.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Java Native Interface (JNI). JNI Linking Java and C code.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Adaptive Optimization in the Jalapeño JVM M. Arnold, S. Fink, D. Grove, M. Hind, P. Sweeney Presented by Andrew Cove Spring 2006.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Previous Next 06/18/2000Shanghai Jiaotong Univ. Computer Science & Engineering Dept. C+J Software Architecture Shanghai Jiaotong University Author: Lu,
Advanced Java Programming Lecture 5 Reflection dr hab. Szymon Grabowski dr inż. Wojciech Bieniecki
Authors: William Enck The Pennsylvania State University Peter Gilbert Duke University Byung-Gon Chun Intel Labs Landon P. Cox Duke University Jaeyeon Jung.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
Arpit Jain Mtech1. Outline Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation.
Java Native Interface CS587x Lecture Department of Computer Science Iowa State University.
What is Android NDK ● A toolset that lets you embed in you app native source code ● C, C++(recently supported December 2010) and assembly(?) ● It is supported.
Problem Solving Environements WebPDELab Online Problem Solving Environment for Partial Differential Equations Applications: a Web Server for the PELLPACK.
Adaptive Optimization in the Jalapeño JVM Matthew Arnold Stephen Fink David Grove Michael Hind Peter F. Sweeney Source: UIUC.
Lecture 10 : Introduction to Java Virtual Machine
Compilation Technology © 2007 IBM Corporation CGO Performance Overheads In Real-Time Java Programs Mark Stoodley and Mike Fulton Compilation.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Rutgers University Excellence Campaign 2/20/2004 Java Native Interface Tutorial Xiaolin Li Rutgers.
Java Introduction to JNI Prepared by Humaira Siddiqui.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
Research supported by IBM CAS, NSERC, CITO Context Threading: A flexible and efficient dispatch technique for virtual machine interpreters Marc Berndl.
1 Introduction to JVM Based on material produced by Bill Venners.
Roopa.T PESIT, Bangalore. Source and Credits Dalvik VM, Dan Bornstein Google IO 2008 The Dalvik virtual machine Architecture by David Ehringer.
Jan Benda Martin Maly Tomas Matousek Ladislav Prosek Pavel Novak Vaclav Novak Tomas Matousek Department of Software Engineering Faculty.
Java Virtual Machine Case Study on the Design of JikesRVM.
The Daikon system for dynamic detection of likely invariants MIT Computer Science and Artificial Intelligence Lab. 16 January 2007 Presented by Chervet.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
CISC Machine Learning for Solving Systems Problems Presented by: Alparslan SARI Dept of Computer & Information Sciences University of Delaware
On Performance of Delegation in Java. Department of Computer Science, Software Technology Group HotSWUp 2009, Orlando, USA, Sebastian Götz (TU.
Android JNI and JAR Library JNI Library 1. JNI *.c sources file must include jni header file jni.h #include 2. In Make file CFLAGS must add -I $(NDK_INC)/
A High Performance Middleware in Java with a Real Application Fabrice Huet*, Denis Caromel*, Henri Bal + * Inria-I3S-CNRS, Sophia-Antipolis, France + Vrije.
CS Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
WTM’12, Bern, April 10, 2012 In-Place Metainfo Support in DeuceSTM Ricardo J. Dias, Tiago M. Vale and João M. Lourenço CITI / Universidade Nova de Lisboa.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
Slide Advanced Programming 2004, based on LY Stefanus's slides Native Methods.
CoCo: Sound and Adaptive Replacement of Java Collections Guoqing (Harry) Xu Department of Computer Science University of California, Irvine.
From C++ to Java SNU iDB Lab. Hyoung-woo Park March 26, 2007.
High-level Interfaces for Scalable Data Mining Ruoming Jin Gagan Agrawal Department of Computer and Information Sciences Ohio State University.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 9: Designing Exceptionally.
Wel come To Seminar On C#.
By Nitin Bahadur Gokul Nadathur Department of Computer Sciences University of Wisconsin-Madison Spring 2000.
RealTimeSystems Lab Jong-Koo, Lim
JNI: Java Native Interface(1/32) Real Time Systems LAB. JNI: Java Native Interface October 31, 2001 Kyung-Yim, Kim.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Java Native Interface (JNI)
Before You Begin Nahla Abuel-ola /WIT.
Module 9: Memory and Resource Management
2.1. Compilers and Interpreters
Improving java performance using Dynamic Method Migration on FPGAs
Mark Claypool and Jonathan Tanner Computer Science Department
CSc 453 Interpreters & Interpretation
Adaptive Code Unloading for Resource-Constrained JVMs
Adaptive Optimization in the Jalapeño JVM
Java for IOI.
CSc 453 Interpreters & Interpretation
Nikola Grcevski Testarossa JIT Compiler IBM Toronto Lab
Presentation transcript:

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

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 Native Function Call

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 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 The JNI Java’s interoperability API Callouts and callbacks Opaque Binary-compatible Java App Native (Host) Environment Native App/Lib JVM + JIT Callout Callback JNI

Motivation The JNI Pervasive Legacy codes Performance-critical, architecture-dependent Features unavailable in Java (files, sockets etc.)

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 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 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 TR JIT Machine code Static compiler IL +

Outline Background Information Method Results Future Work

Sample Java Class class SetFieldXToFive{ public int x; public native foo(); static{ System.loadLibrary(…); }

Sample Java Class class SetFieldXToFive{ public int x; public native foo(); static{ System.loadLibrary(…); }

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 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 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 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 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 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls 4.Transforms inlined JNI calls 5.Finishes inlining

Method – Step 1 1. Inliner detects a native callsite Inliner Java Code Call to obj.foo() foo(){…} (Native code) TR JIT

Method – Step 2 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL Native IL JIT IL

Method – Step 3 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls JIT IL /* call to GetObjectClass */ … /* call to GetFieldID */ … /* call to SetFieldID */ … Pre-constructed IL shapes

Method – Step 4 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls 4.Transforms inlined JNI calls jclass cls = (*env)->GetObjectClass(env,obj); jfieldID fid = (*env)->GetFieldID(env,cls,“x","I"); if (fid == NULL) return; (*env)->SetIntField(env,obj,fid,5);

Method – Step 4 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls 4.Transforms inlined JNI calls (*env)->SetIntField(env,obj,fid,5); Constant: SetFieldXToFive class data structure Constant: Offset of field “x” JIT IL: obj.x = 5 jclass cls = (*env)->GetObjectClass(env,obj); jfieldID fid = (*env)->GetFieldID(env,cls,“x","I"); if (fid == NULL) return;

The Big Picture 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls 4.Transforms inlined JNI calls 5.Finishes inlining Before Native Inlining & Callback Transformations Inliner Java Code Call to obj.foo() TR JIT foo(){…} (Native code)

The Big Picture After Native Inlining & Callback Transformations 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls 4.Transforms inlined JNI calls 5.Finishes inlining Inliner Java Code obj.x = 5 TR JIT foo(){…} (Native code)

The Big Picture After Native Inlining & Callback Transformations 1.Inliner detects a native callsite 2.Extracts and converts Native IL to JIT IL 3.Identifies inlined JNI calls 4.Transforms inlined JNI calls 5.Finishes inlining Inliner Java Code obj.x = 5 TR JIT

Outline Background Information Method Results Future Work

Experimental Setup Native function microbenchmarks Average of 300 million runs 1.4 GHz Power4 setup Prototype implementation

Cost of IL Conversion 5.3 microseconds per W-Code

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 Speedup (X) Microbenchmark TestInstanceStatic hash smaller speedups for natives performing work instance vs. static speedup

Inlining & Transforming Callbacks Reclaim order of magnitude overhead Speedup (X) Microbenchmark TestInstanceStatic CallVoidMethod

Data-Copy Speedups Transformed GetIntArrayRegion Array Length Speedup (X)

Exposing Inlined Code To JIT Optimizations Microbenchmark TestSpeedup (X) GetArrayLength93.4 FindClass GetMethodID NewCharArray GetArrayLength

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

Fin