Скачать презентацию Jeannie Granting Java Native Interface Developers their Wishes Скачать презентацию Jeannie Granting Java Native Interface Developers their Wishes

c83c644629134e196ba78a8bf7cd25a7.ppt

  • Количество слайдов: 19

Jeannie: Granting Java Native Interface Developers their Wishes Martin Hirzel Robert Grimm IBM Watson Jeannie: Granting Java Native Interface Developers their Wishes Martin Hirzel Robert Grimm IBM Watson Research Center New York University October 23, 2007 1

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

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

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

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

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

Translation Scheme Jeannie source code Generated code 1 2 4 “ 1” “ 2” Translation Scheme Jeannie source code Generated code 1 2 4 “ 1” “ 2” 3 class Java. Env { int x int z native m 1() m 2(CEnv) native m 3(CEnv) m 4(CEnv) } struct CEnv { jint y }; Java_C_m 1(JEnv) Java_C_m 3(JEnv, CEnv) 7

Typing • Nested expressions have equivalent types – if (`((jboolean)feof(stdin))). . ; • Java 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 Array. List(10); • C pointers/structs/unions are illegal in Java 8

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

Compiler Stages Jeannie code Jeannie grammar Jeannie Parser Jeannie AST Jeannie Analyzer Jeannie AST+Sym. Compiler Stages Jeannie code Jeannie grammar Jeannie Parser Jeannie AST Jeannie Analyzer Jeannie AST+Sym. Tab Code generator C code Java code 10

Scalable Composition: Syntax Jeannie code C grammar Jeannie Parser Jeannie grammar Jeannie AST Java Scalable Composition: Syntax Jeannie code C grammar Jeannie Parser Jeannie grammar Jeannie AST Java grammar Rats! parser generator Jeannie Analyzer Jeannie AST+Sym. Tab Code generator C code Java code 11

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

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

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

Efficiency: JNI vs. Jeannie 1 15 Efficiency: JNI vs. Jeannie 1 15

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

Efficiency: Bulk vs. Simple Array Access 1 17 Efficiency: Bulk vs. Simple Array Access 1 17

Related Work • Improving JNI – Productivity: Bubak+Kurzyniec (Janet) – Safety: Tan et al. 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, XTATIC, C , Linq, DALI • Scalable composition – Polyglot, Jast. Add, Silver, Stratego/XT, Safari 18

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