SquirrelJME As A Runtime

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:

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.

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

When using 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 each class:

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 JAR.

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.

Required Methods

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 implementations.

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.