inside the kvm real-time java team university of pennsylvania

Post on 20-Dec-2015

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

• 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

• Platforms– Win32– PalmOS– Solaris– Linux

• JAR compatibility & dynamic class loading

• Source code is in 100% ANSI C

Compatibility(1)

• No floating point support

• No JNI support (not really)

• Limited error handling

• New bytecode (pre)verifier

Compatibility(2)

• Memory model• GC• Interpreter• Frames• File Loading• Verification• Security• Romizer

Features of VM

• cell

• CLASS

• FIELD

• METHOD

• OBJECT

• FRAME

Data Structures

• THREAD

• MONITOR

• BYTEARRAY

• SHORTARRAY

• POINTERLIST

• HASHTABLE

• 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

Objects in action

Every object is created in Heap

• 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

Memory Layout

• 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

• mallocBytes()• mallocHeapObject(size, type)• mallocObject(size, type)• callocObject(size, type)• instantiate(instance_class)• instantiateArray(arrayclass, count)

Allocating Objects

• Original mark-and-sweep

• Single-space

• Non-moving, non-incremental

• Small and simple

• Slow allocation, long pause, and fragmentation

Garbage Collector

Interpretor

• 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

Thread & Monitors

1. Low-level VM securityBytecode verifier

2. Application-level security (sandbox)Set of supported JNI(sorta) calls closed

Security

Preverifier and verifier

• 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’

• 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

• 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

top related