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 require that system calls be made available. This means an implementation of the cc.squirreljme.runtime.cldc.SystemCaller class. Regardless for the kernel or the user-space, the _CALLER field must be set in cc.squirreljme.runtime.cldc.SystemCall. For additional support, it is possible for __systemCaller() be replaced as needed to return the appropriate instance of SystemCaller if the field cannot statically be set by the virtual machine.

The kernel task is required to create an implementation of the cc.squirreljme.runtime.kernel.Kernel class. The actual implementation can vary according to the required means. The system call interface that can be used in the kernel task is an instance of cc.squirreljme.runtime.kernel.syscall.DirectCaller which is capable of calling into the kernel as needed. The _CALLER field is set to this caller.

User-space tasks use IPC to communicate with the kernel process and as such the recommended means of handling that is by implementing cc.squirreljme.runtime.clsyscall.ClientCaller. The _CALLER field is set to this caller.