There's a class called ist/palcom/j/runtime/CheckedJavaArray.som
which is used to make Java-style checked arrays.

The problem is to do with covariant arrays in Java and the
necessity to throw ArrayStoreException when the static typing
in Java fails.

We want Java arrays to inherit from the standard Smalltalk Array
class, since that class is
* Accellerated by the VM
* Compact
* Usable for interlanguage interoperability

The layout of instances of Array is as follows:

------------------
| Classpointer   |
------------------
| length Integer |
------------------
| element 0      |
------------------
| element 1      |
------------------
| element 2      |
etc.

This means there's no 'space' to insert new instance fields.
But the checked arrays of Java need a field for the permitted
type so that the checked store can check the object being stored
against the type.

Rather than bloat the VM by adding this field to all arrays, we
give the checked Java arrays a method, which returns the type.
The method is called Stype (ie it is a 0-parameter Smalltalk
method).  The actual type to check against is then an entry in
the literal table of the Stype method.

On encountering an at:put: send (equivalent to "[x] =" in Java),
the VM checks the array bounds and the type and performs the store
if it can do so without exceptions.  This short-circuits the at:put:
method entirely.  If the VM expects an exception, it calls the
at:put: method, and allows it to throw whatever kind of exception
it sees fit.  This is merely an optimization: the implementation
of at:put: in CheckedJavaArray would perform exactly the same
operations without this special treatment by the VM.

Type checks in the VM are done using the same logic as for the
instanceof checks, using symbols (magic method name) for interfaces
and class objects for subclass checks.

Array classes with the special Stype method are not stored in .prc
files, but generated on the fly.  This is to allow separate
compilation, since a component defining a class cannot know
whether (and what dimension) arrays will be created.  The methods
to construct a new array class are in CheckedJavaArray.

A two-dimensional array in Java is merely a one-dimensional array
that can store other one-dimensional arrays.  Thus the type of a
Foo[][] array is as follows (this is an object diagram showing
the class objects at runtime!).

Subclass of CheckedJavaArray
--------------------
| class pointer    |         Subclass of CheckedJavaArray
--------------------         -----------------
| type pointer     |-------->| class pointer |             Foo class
--------------------         -----------------             -----------------
                             | type pointer  |------------>| class pointer |
                             -----------------             -----------------
                                                           ...
 
(In this diagram, the type pointer is shown as being in the class.
 In fact the class object contains an array of methods, and there
 we find the Stype method, which contains a literal, which is the
 type pointer.  At runtime, the literal table can contain objects
 other than those described in the component format.  The class
 pointers shown all point to the ClassClass object, since the objects
 shown are all classes.)

So a two dimensional array is just an array where the type that can
be stored in it is another array.  This scheme can be extended to
an arbitrary number of dimensions.

One bug in this implementation is that a store of an interface-typed
array into a multidimension interface-typed array will always
succeed if the number of dimensions fits.  This is because the
magic-method technique does not allow interfaces to be checked for
sub-super-interface relationships.  Only concrete instances that
may or may not implement the interface can be checked.  This is a
rather obscure case in most Java programs, but it can cause execeptions
to be unexpectedly delayed or not thrown when compared with the same
program running on the JVM.  This case could be fixed by having a more
elaborate runtime embodiment of interfaces in the PalVM.
