Java Reference
In-Depth Information
At VM startup, the system classes are bootstrapped and a main Java
thread object is allocated (see VM::start() and Universe:: boot-
strap() ). 6 After the main Java thread is initialized, its execution stack
is set up with a first stack frame corresponding to the main method (see
Thread::initialize_main() , Thread::setup_lightweight_
stack() and JVM::load_main_class() ). 6 At that point, the VM is
ready to start executing Java bytecode by calling JVM::run() . This is
how CLDC-HI is initialized.
Let's take a short look at how the LWT emulates multiple Java threads
on top of a single native OS thread (see Figure 10.7). The VM runs
on a single native OS thread, named the primordial thread. During the
execution of the primordial thread, either bytecodes in the context of a
Java thread can be executed or no Java bytecodes are executed and the
VM runs other internal required functionality.
The scheduling of Java threads is managed by the LWT Scheduler (see
src/vm/share/runtime/Scheduler.cpp ). For example, switching
between Java threads is performed in Scheduler::switch_thread() .
The switching between execution of the current Java thread and the pri-
mordial thread is achieved by two assembler code fragments in the inter-
preter: current_thread_to_primordial and primordial_to_
current_thread . The code for those two assembler fragments is gen-
erated in src/vm/cpu/arm/InterpreterStubs_arm.cpp .
Main
Java Thread
Java
Thread 1
Java
Thread 2
Java
Thread N
Java
Thread 1
Primordial Thread
Figure 10.7 LWT model
10.4.2 Linkage of Native Operations
Although there is no JNI in CLDC, every Profile and its libraries still need
to invoke native operations. Java SE (and CDC) has a JNI mechanism in
which Java code can instruct the VM to load a native library and define
Java methods that are implemented in C. In Java SE, this mechanism is
dynamic - the loading of the library and lookup of the corresponding C
function is done at run time.
CLDC-HI HotSpot takes a static approach more suitable to constrained
mobile environments. The native invocation mechanism is available
only to system classes and not to applications. System classes define
the methods that are implemented in native code in a similar way but
6 You will find the JVM.cpp and Thread.cpp files in the runtime folder
at phoneme.dev.java.net/svn/phoneme/components/cldc/trunk/src/vm/share . The Uni-
verse.cpp file is in the handles folder.
Search WWH ::




Custom Search