inside the kvm real-time java team university of pennsylvania
Post on 20-Dec-2015
217 views
TRANSCRIPT
![Page 1: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/1.jpg)
Inside the KVM
Real-Time Java Team
University of Pennsylvania
![Page 2: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/2.jpg)
• Small footprint VM for resource constrained devices
• Build a Java VM that would– Be easy to understand and maintain– Be highly portable– Be small without sacrificing features of
Java language
KVM Design Goals
![Page 3: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/3.jpg)
• KVM = JVM – advanced performance optimizations
• Easy to read and port– 24,000 LOC– 40 ~ 80 KB when loaded– Supports ROMizing (pre-build application)– 30 – 80 % of the speed of JDK w/o JIT
KVM-CLDC
![Page 4: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/4.jpg)
• Platforms– Win32– PalmOS– Solaris– Linux
• JAR compatibility & dynamic class loading
• Source code is in 100% ANSI C
Compatibility(1)
![Page 5: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/5.jpg)
• No floating point support
• No JNI support (not really)
• Limited error handling
• New bytecode (pre)verifier
Compatibility(2)
![Page 6: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/6.jpg)
• Memory model• GC• Interpreter• Frames• File Loading• Verification• Security• Romizer
Features of VM
![Page 7: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/7.jpg)
• cell
• CLASS
• FIELD
• METHOD
• OBJECT
• FRAME
Data Structures
• THREAD
• MONITOR
• BYTEARRAY
• SHORTARRAY
• POINTERLIST
• HASHTABLE
![Page 8: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/8.jpg)
• Saves space for long strings, faster comparisons, etc
• ClassTable: all classes– Instance/array/raw-classes
• InternStringTable– Strings used in program source
• UTFStringTable– Encodes field/class/signature names
Hashtables
![Page 9: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/9.jpg)
Objects in action
Every object is created in Heap
![Page 10: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/10.jpg)
• Visible to user– GCT_INSTANCE– GCT_OBJECTARRAY– GCT_INSTANCE_CLASS– GCT_ARRAY_CLASS– …
• Internal object in heap– GCT_FIELDTABLE– GCT_MONITOR– GCT_GLOBAL_ROOTS– GCT_HASHTABLE– …
Header Types
![Page 11: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/11.jpg)
Memory Layout
![Page 12: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/12.jpg)
• Global roots(permanent)– Cannot undone– makeGloabalRoot(&globalVariable)
• Temporary roots(stack discipline)START_TEMPORARY_ROOTS
MAKE_TEMPORARY_ROOT(x)END_TEMPORARY_ROOTS
• Transient roots(non-stack discipline)makeTransientRoot(y)removeTransientRootByValue(y)
Roots for GC op
![Page 13: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/13.jpg)
• mallocBytes()• mallocHeapObject(size, type)• mallocObject(size, type)• callocObject(size, type)• instantiate(instance_class)• instantiateArray(arrayclass, count)
Allocating Objects
![Page 14: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/14.jpg)
• Original mark-and-sweep
• Single-space
• Non-moving, non-incremental
• Small and simple
• Slow allocation, long pause, and fragmentation
Garbage Collector
![Page 15: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/15.jpg)
Interpretor
![Page 16: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/16.jpg)
• Platform independent multithreading using green thread– Fully deterministic– Active thread kept in a simple linked queue– Every Java thread runs some number of
bytecodes and reschedule()– Given execution time based on priority
Thread Design
![Page 17: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/17.jpg)
Thread & Monitors
![Page 18: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/18.jpg)
1. Low-level VM securityBytecode verifier
2. Application-level security (sandbox)Set of supported JNI(sorta) calls closed
Security
![Page 19: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/19.jpg)
Preverifier and verifier
![Page 20: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/20.jpg)
• Preverifier (off-line)– Space-intensive processing– Stackmap verification making sure the VM
stack consistency– Jmp/return instruction verification– Leaves hints for run-time verifier
• Verifier– Just check the hints left by the preverifier
Cont’
![Page 21: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/21.jpg)
• Synchronous notification• Polling in Java programming language
code• Polling in the interpreter
Suck in an event from the I/O pipe -> deal with it -> next event -> deal with it -> etc
Event Handling
![Page 22: Inside the KVM Real-Time Java Team University of Pennsylvania](https://reader036.vdocuments.us/reader036/viewer/2022062421/56649d425503460f94a1d860/html5/thumbnails/22.jpg)
• Files– Machine_md.h– Runtime_,d.c– Main.c
• Error Handling, memory management
• Native code handling, Time, Timer
• 64bit integer calc, big-little endian
• Class file locations and format
Porting Issues