jeannie: granting java native interface developers their ... · java garbage collection jeannie...
TRANSCRIPT
Jeannie: Granting Java Native Interface
Developers Their Wishes
Martin Hirzel, Robert Grimm
Presented by: Mengtao Sun SoS Lab, Lehigh University
Motivation
FFI: Foreign Function Interface
OS Services
Legacy code
Performance
Convenience
Design Goals
Productivity: writing & maintaining code
Safety: preventing & detecting bugs
Efficiency
Portability: Different OS & VM
Jeannie
A new FFI for Java
Combining Java and C into one language
Jeannie compiler
Producing conventional JNI code
High-quality error messages
JNI Example
Jeannie Example
Support full
C syntax
Native methods have a body
Nested
block Nested
expression
Can nest to
any depth
Jeannie Build Process
Socket.jni
Socket.jni.i
Preprocessor
Jeannie Compiler
Socket.i Socket.java
Java Compiler
Java sources
Network.jar
C Compiler
C sources
Network.dll
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
Typing
Type equivalences
Primitive types: char ≡ jchar
Reference types: java.lang.Object ≡ jobject
Nested expressions have the same types
Java references are opaque in C
java.io.IOException ≡ `java.io.IOException
C pointers/structs/unions are illegal in Java
Java Garbage Collection
Jeannie recommends that programmers do
not store Java references in C’s static
variables or heap-allocated data structures.
JNI Jeannie
Local
referenc
e
Implicit
(do not collect until
control returns to Java)
Global
referenc
e
Do not collect
until user calls
DeleteGlobalR
ef
Not supported
(just store in
Java and use
`x.f)
Compiler Stages Jeannie code
Jeannie AST
Jeannie AST+SymTab
C code Java code
Jeannie Parser
Jeannie Analyzer
Code generator
Jeannie grammar
Syntactic Analysis Jeannie code
Jeannie AST
Jeannie AST+SymTab
C code Java code
Jeannie Parser
Jeannie Analyzer
Code generator
Jeannie grammar
C grammar
Java grammar
Rats!
parser
generator
Semantic Analysis Jeannie code
Jeannie AST
Jeannie AST+SymTab
C code Java code
Jeannie Parser
Jeannie Analyzer
Code generator
Jeannie grammar
C grammar
Java grammar
Rats!
parser
generator
xtc visitors
Common type representation
Code Generation Jeannie code
Jeannie AST
Jeannie AST+SymTab
Jeannie Parser
Jeannie Analyzer
Code generator
Jeannie grammar
C grammar
Java grammar
Rats!
parser
generator
xtc visitors
Common type representation
C AST Java AST
C code Java code
C pretty printer Java pretty printer
xtc
AST generator
Evaluation
Portability
“Portability is a strong point of JNI, and the
Jeannie compiler preserves it.”
Productivity
Jeannie is more concise than JNI
Jeannie keeps the maintenance cost low
Evaluation (cont.)
Efficiency
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
JavaBDD: 11-Queens
JavaBDD: Rubik's Cube
Empty C block in Java
Empty Java block in C
Constant C expr. in Java
Constant Java expr. in C
Exception in C in Java
With array read
With array writeJ9 / Linux
HotSpot / OS X
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];
}
Array Access (cont.)
Bulk vs. Simple array access
0 10 20 30 40 50 60 70 80 90
Write
Read
J9 / Linux
HotSpot / OS X
Conclusion
Jeannie: a new language integrating Java
with C
Portability
Productivity
Efficiency
Language composition
Rats!
xtc
Critique
Sooooooooo long!!!
The idea of language composition is
fabulous. However:
Debugging (Jinn)
Fault-isolation (Robusta)
Thanks!
Presented by: Mengtao Sun SoS Lab, Lehigh University