There are two portions of SquirrelJME, the SquirrelJME Virtual Machine and the SquirrelJME Runtime. The virtual machine is the one which executes the program and provides an environment that runs on the operating system or other bare hardware. The runtime is the class libraries which provide a standard set of classes and interfaces which are used by Java programs. This document describes the requirements which are needed to have a virtual machine which can use the SquirrelJME runtime.
Note that J2ME was renamed to Java ME, so any mentions of Java ME retroactively mentions J2ME.
There are two cases where the runtime is used, those two cases are pure and hosted. There are two major differences between the two:
- All of the classes in the runtime are solely provided by SquirrelJME.
- More consistent.
- Portability is increased because there is less code to be ported.
- More likely to be less complicated.
- Requires more implementation work
- Runs an extra SquirrelJME APIs on top of an existing virtual machine.
- Hacks will be required for correct operation to match the semantics of Java ME.
- May have compatibility issues.
- Requires maintaining two separate programs.
- Faster to implement non-provided APIs, there is no need to implement the core APIs because the host environment provides them.
- Does not need a virtual machine to be modified to support SquirrelJME.
SquirrelJME operates in one of two fashions: Single Program Mode where only a single program is ran at once which eventually terminates, and Launcher Mode where a launcher is available and multiple programs can be launched and ran at the same time.
- Single Program Mode
- Simple to implement, only need to worry about a single program running at a time.
- Not possible to run other programs.
- Class initialization and static initialization is easier.
- Launcher Mode
- Potentially allows JARs to be loaded at run-time to run other programs.
- Provides an interface for selecting JARs to be ran.
- Allows multiple programs to be ran at the same time.
- Requires that different program execution domains be supported, this is because static variables need to be initialized for each program.
Requirements of Java ME
Java ME is different from Java SE and operates in a slightly different fashion. However, every conforming Java SE JVM can run Java ME programs but the same is not possible in most cases because Java ME is a subset of Java SE.
JAR Resource Lookup
Class.getResourceAsStream() in Java ME, there is a strict method
in how resource lookup is performed. A single JAR is considered to be a single
unit where resources and classes are located. A class within one unit is not
able to access the resources in another unit. Class files should not be visible
to this method and not accessible as resources, the reason for this is that
output executables may be ROMized which would destroy the class files that
executable code is derived from.
As an example, here is a set of two JAR files:
This would be the result of multiple
Class.getResourceAsStream() calls from
Foo-> onlyinfoo.txt: Returns foo.jar/onlyinfoo.txt.
Foo-> onlyinbar.txt: Returns
Foo-> inboth.txt: Returns foo.jar/inboth.txt.
Foo-> Foo.class: Should return
Foo-> Bar.class: Should return
Bar-> onlyinfoo.txt: Returns
Bar-> onlyinbar.txt: Returns bar.jar/onlyinbar.txt
Bar-> inboth.txt: Returns bar.jar/inboth.txt.
Bar-> Foo.class: Should return
Bar-> Bar.class: Should return
This reason for this is that in each JAR, there is a resource called META-INF/MANIFEST.MF. This resource is used and looked up my programs which are MIDlets in order to obtain their application properties. It also is used by the run-time to determine what a JAR is and what it supports.
Class Loading And Lookup
Unlike Java SE, there are no
ClassLoaders. Java ME operates entirely on a
single two tier approach. The first tier are classes which are built-in and
available to every program. The second tier are classes which are not
built-in and which have been loaded dynamically from the launcher. When a
class is looked up, the order is always built-in classes first. If a program is
currently being executed then it may only look up classes which exist in its
execution context. If two programs are loaded they are both in two different
execution contexts and they cannot lookup each others classes. Thus if two
JARs have the same class, it will only use the class that is in their same
Virtual Machine Structure
The virtual machine is structured like a micro-kernel in that there is a kernel and each task which runs on the machine is its own process with its own memory space.
For simplicity, sanity, and portability; SquirrelJME has a very simple means to provide support for many systems and is designed in a way to reduce the amount of work that is required to support various systems. This means that porting SquirrelJME will be very simple and straightforward once the base semantics of the virtual machine are implemented.
Both kernel and user-space tasks use an API that provides system calls to
perform some unsafe operations in the kernel and to interact with the kernel.
Each function is specified in the enumeration
cc.squirreljme.runtime.cldc.system.SystemFunction. System calls are directly
used with the
cc.squirreljme.runtime.cldc.system.SystemCall class. System
calls can be initialized by either setting the internal
_CALLS field or
modifying the method
__calls() to return an array of system call
The system calls allow for basic types to be passed to and from the remote side and also provides a mean to have remote execution as it is needed via remote function handlers. This means that system call operations should be fast as there only needs to be handling of the basic types.