1 / 19

J e a n n i e : Granting Java Native Interface Developers their Wishes

J e a n n i e : Granting Java Native Interface Developers their Wishes. FFI: Foreign Function Interface. User Program — nqueens. Brown: Java. Stan dard Libra ries — ja va. io. Cus tom Libra ries — Java BDD. Motivation: OS Services Legacy Code Performance Convenience.

abner
Download Presentation

J e a n n i e : Granting Java Native Interface Developers their Wishes

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jeannie: Granting Java Native Interface Developers their Wishes

  2. FFI: Foreign Function Interface UserProgram — nqueens Brown:Java StandardLibraries—java.io CustomLibraries—JavaBDD • Motivation: • OS Services • Legacy Code • Performance • Convenience Virtual Execution Environment —JVM Operating System —Linux Blue:C

  3. JNI = Java Native Interface Java Native method:no body in Java C function with mangled nameimplements Java method C Read Javafield from C Throw Javaexception from C

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

  5. JeannieExample Support fullC syntax Can useshort names Native methods have a body Nestedblock Nestedexpression Can nest toany depth Exception handling in C

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

  7. Translation Scheme Jeannie source code Generated code 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) 1 2 3 4 “1” “2”

  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. Java Garbage Collection

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

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

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

  13. Scalable Composition: CodeGen Jeannie code C grammar Rats!parsergenerator Jeannie Parser Jeannie grammar Java grammar Jeannie AST xtc visitors,commontype rep. C +Jeannie +Java Analyzer Jeannie AST+SymTab xtc ASTgenerator Code generator Java stencils C stencils C AST Java AST C pretty printer Java pretty printer C code Java code

  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. Efficiency: JNI vs. Jeannie 1

  16. 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<n; i++) s += ca[i]; }

  17. Efficiency:Bulk vs. Simple Array Access 1

  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, XTATIC, C, Linq, DALI • Scalable composition • Polyglot, JastAdd, Silver, Stratego/XT, Safari

  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

More Related