Artifact [e504ab3a20]

Artifact e504ab3a20978b86eca1b8a5499aeabeaabbdb83:


# SquirrelJME As A Runtime

To use the SquirrelJME library as the main supporting run-time library will
require that you implement the native methods which are located in the
`cc.squirreljme.runtime.cldc.asm` package. Implementing these native methods
will in the result end up with a library compatible implementation of
SquirrelJME.

# 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:

 * _foo.jar_
   * _Foo.class_
   * _onlyinfoo.txt_
   * _inboth.txt_
 * _bar.jar_
   * _Bar.class_
   * _onlyinbar.txt_
   * _inboth.txt_

This would be the result of multiple `Class.getResourceAsStream()` calls from
each class:

 * `Foo` -> _onlyinfoo.txt_: Returns _foo.jar/onlyinfoo.txt_.
 * `Foo` -> _onlyinbar.txt_: Returns `null`.
 * `Foo` -> _inboth.txt_: Returns _foo.jar/inboth.txt_.
 * `Foo` -> _Foo.class_: Should return `null`.
 * `Foo` -> _Bar.class_: Should return `null`.
 * `Bar` -> _onlyinfoo.txt_: Returns `null`.
 * `Bar` -> _onlyinbar.txt_: Returns _bar.jar/onlyinbar.txt_
 * `Bar` -> _inboth.txt_: Returns _bar.jar/inboth.txt_.
 * `Bar` -> _Foo.class_: Should return `null`.
 * `Bar` -> _Bar.class_: Should return `null`.

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.

## Thread Starting

All threads including the main thread must have a `Thread` object initialized
in which `Thread.__start()` is executed for the threads. This method is in
the virtual machine itself and performs most of the logic needed by the
library so that porting is simpler.