inside the kvm real-time java team university of pennsylvania

22
Inside the KVM Real-Time Java Team University of Pennsylvania

Post on 20-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Inside the KVM Real-Time Java Team University of Pennsylvania

Inside the KVM

Real-Time Java Team

University of Pennsylvania

Page 2: Inside the KVM Real-Time Java Team University of Pennsylvania

• 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

• 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

• 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

• 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

• 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

• 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

• 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

Objects in action

Every object is created in Heap

Page 10: Inside the KVM Real-Time Java Team University of Pennsylvania

• 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

Memory Layout

Page 12: Inside the KVM Real-Time Java Team University of Pennsylvania

• 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

• 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

• 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

Interpretor

Page 16: Inside the KVM Real-Time Java Team University of Pennsylvania

• 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

Thread & Monitors

Page 18: Inside the KVM Real-Time Java Team University of Pennsylvania

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

Preverifier and verifier

Page 20: Inside the KVM Real-Time Java Team University of Pennsylvania

• 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

• 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

• 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