Title: Jeannie: Granting Java Native Interface Developers their Wishes
1Jeannie Granting Java Native Interface
Developers their Wishes
2FFI Foreign Function Interface
UserProgram nqueens
BrownJava
StandardLibraries java.io
CustomLibraries JavaBDD
- Motivation
- OS Services
- Legacy Code
- Performance
- Convenience
Virtual Execution Environment JVM
Operating System Linux
BlueC
3JNI Java Native Interface
Java
Native methodno body in Java
C function with mangled nameimplements Java
method
C
Read Javafield from C
Throw Javaexception from C
4FFI Design Goals
- Productivity
- Writing maintaining code
- Safety
- Preventing detecting bugs
- Efficiency
- At transition elsewhere
- Portability
- Different OS, HW, virtual execution environment
5Jeannie Example
Support fullC syntax
Can useshort names
Native methods have a body
Nestedblock
Nestedexpression
Can nest toany depth
Exception handling in C
6Jeannie Build Process
Socket.jni
Preprocessor
Socket.jni.i
Jeannie Compiler
Java sources
C sources
Socket.i
Socket.java
Java Compiler
C Compiler
Network.jar
Network.dll
7Translation Scheme
Jeannie source code
Generated code
class JavaEnv int x int z native m1()
m2(CEnv) native m3(CEnv) m4(CEnv) struct
CEnv jint yJava_C_m1(JEnv) Java_C_m3(JEnv,
CEnv)
1
2
3
4
1
2
8Typing
- 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
9Java Garbage Collection
10Compiler Stages
Jeannie code
Jeannie grammar
Jeannie Parser
Jeannie AST
Jeannie Analyzer
Jeannie ASTSymTab
Code generator
C code
Java code
11Scalable Composition Syntax
Jeannie code
C grammar
Rats!parsergenerator
Jeannie Parser
Jeannie grammar
Java grammar
Jeannie AST
Jeannie Analyzer
Jeannie ASTSymTab
Code generator
C code
Java code
12Scalable 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 ASTSymTab
Code generator
C code
Java code
13Scalable 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 ASTSymTab
xtc ASTgenerator
Code generator
Java stencils
C stencils
C AST
Java AST
C pretty printer
Java pretty printer
C code
Java code
14FFI 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
15Efficiency JNI vs. Jeannie
1
16Array Access
- Nested expression is simple
- for (i 0, n ja.length i lt n i)
- s jai
- But bulk access is faster
- with (jint ca ja)
- jint n ja.length
- for (jint i0 iltn i)
- s cai
17EfficiencyBulk vs. Simple Array Access
1
18Related Work
- Improving JNI
- Productivity BubakKurzyniec (Janet)
- Safety Tan et al. (Ccured, ILEA),FurrFoster
(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
19Conclusions
- Have
- Language Jeannie FFI(JavaC)
- Open source compiler contributed to xtc
http//cs.nyu.edu/rgrimm/xtc - Next
- Debugging
- Fault isolation
- Optimization