Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Jeannie: Granting Java Native Interface Developers their Wishes Martin HirzelRobert Grimm IBM Watson Research CenterNew York University October 23, 2007.

Similar presentations


Presentation on theme: "1 Jeannie: Granting Java Native Interface Developers their Wishes Martin HirzelRobert Grimm IBM Watson Research CenterNew York University October 23, 2007."— Presentation transcript:

1 1 Jeannie: Granting Java Native Interface Developers their Wishes Martin HirzelRobert Grimm IBM Watson Research CenterNew York University October 23, 2007

2 2 FFI: Foreign Function Interface User Program — nqueens Virtual Execution Environment — JVM Operating System — Linux Standard Libraries — java.io Custom Libraries — JavaBDD Motivation: OS Services Legacy Code Performance Convenience Blue: C Brown: Java

3 3 JNI = Java Native Interface Java C Native method: no body in Java C function with mangled name implements Java method Read Java field from C Throw Java exception from C

4 4 FFI Design Goals Productivity –Writing & maintaining code Safety –Preventing & detecting bugs Efficiency –At transition & elsewhere Portability –Different OS, HW, virtual execution environment

5 5 Jeannie Example Native methods have a body Nested block Can nest to any depth Can use short names Nested expression Support full C syntax Exception handling in C

6 6 Jeannie Build Process Socket.jni Socket.jni.i Preprocessor Jeannie Compiler Socket.iSocket.java Java Compiler Java sources Network.jar C Compiler C sources Network.dll

7 7 Translation Scheme “1” “2” class JavaEnv { int x int z native m1() m2(CEnv) native m3(CEnv) m4(CEnv) } struct CEnv { jint y }; Java_C_m1(JEnv) Java_C_m3(JEnv,CEnv) Jeannie source code Generated code 1 2 4 3

8 8 Typing Nested expressions have equivalent types – if (`((jboolean)feof(stdin)))..; Java references are opaque in C –Use in nested Java expression –Assign to variable –Pass as parameter –Return as result C can widen Java references – `List lst = `new ArrayList(10); C pointers/structs/unions are illegal in Java

9 9 Java Garbage Collection JNIJeannie Local reference Implicit (do not collect until control returns to Java) Global reference Do not collect until user calls DeleteGlobalRef Not supported (just store in Java and use `x.f )

10 10 Compiler Stages Jeannie code Jeannie AST Jeannie AST+SymTab C codeJava code Jeannie Parser Jeannie Analyzer Code generator Jeannie grammar

11 11 Scalable Composition: Syntax Jeannie code Jeannie AST+SymTab Jeannie Parser Code generator C grammar Jeannie grammar Java grammar Rats! parser generator Jeannie Analyzer C codeJava code Jeannie AST

12 12 C grammar Jeannie grammar Java grammar Scalable Composition: Analyzers Jeannie code Jeannie Parser Rats! parser generator xtc visitors, common type rep. Jeannie AST+SymTab Code generator C codeJava code C +Jeannie +Java Analyzer Jeannie AST

13 13 C +Jeannie +Java Analyzer C grammar Jeannie grammar Java grammar Scalable Composition: CodeGen Jeannie code Jeannie AST Jeannie AST+SymTab C AST Java AST C codeJava code Jeannie Parser Code generator C pretty printerJava pretty printer C stencils Java stencils xtc AST generator Rats! parser generator xtc visitors, common type rep.

14 14 FFI Design Goals: Revisited Productivity –Concise syntax Safety –Static error checking Efficiency –See next slide … Portability –Java virtual machines: HotSpot, J9, Jikes RVM –Operating systems: Mac OS X, Linux, Cygwin

15 15 Efficiency: JNI vs. Jeannie 1

16 16 Nested expression is simple: for (i = 0, n = `ja.length; i < n; i++) s += `ja[`i]; Array Access But bulk access is faster: with (jint* ca = `ja) { jint n = `ja.length; for (jint i=0; i<n; i++) s += ca[i]; }

17 17 Efficiency: Bulk vs. Simple Array Access 1

18 18 Related Work Improving JNI –Productivity: Bubak+Kurzyniec (Janet) –Safety: Tan et al. (Ccured, ILEA), Furr+Foster (type inference) –Efficiency: Stepanian et al. (JIT native code) –Portability: Chen et al. (dynamic binary translator) Deep language interoperability –XJ, X TATIC, C , Linq, DALI Scalable composition –Polyglot, JastAdd, Silver, Stratego/XT, Safari

19 19 Conclusions Have: –Language: Jeannie = FFI(Java+C) –Open source compiler contributed to xtc http://cs.nyu.edu/rgrimm/xtc Next: –Debugging –Fault isolation –Optimization


Download ppt "1 Jeannie: Granting Java Native Interface Developers their Wishes Martin HirzelRobert Grimm IBM Watson Research CenterNew York University October 23, 2007."

Similar presentations


Ads by Google