Implementing support for multiple classloaders in kissme
--------------------------------------------------------------------------------

Java has the notion of "Class Loaders", which allow applications to create a 
separate name space for Classes at runtime.

The separation of name spaces allow a class with the same name (for example "java.lang.System"), to
be loaded twice. 

Associated with every class is a set of static variables. This set is duplicated every time a class is loaded in a new namespace.

In kissme, the internal class structure contains fields of various types:

SuperClass - tClass
Interfaces - tClass
Methods - tMethod
Inst Fields - tField
Stat Fields - tField
Native methods - JNINativeMethod

It is important that whenever these structures reference a class, they do so correctly. They must reference the same class that would be loaded from this class's classloader.

Let's look at each of these structures:

tField:

Pointer to Class - tClass

this is the first point where we need to introduce more information to differeniate different classes of the same name

tMethod:

Pointer to Class - tClass

this is the second case
Pointer to Code structure - tCode

tCode:

exception table - tExceptionInfo
line number table - tLineNumberTable
local variable table - tLocalVariableTable

tExceptionInfo:

catch type - tClass

third case

tLocalVariableTable:

doesn't contain a class pointer, but contains an index into the constant pool

JNINativeMethod:

Has a string for the method name and a string for the signature. We don't expect to specialize native methods anyway.


Let's list the cases where the structures inside tClass referred to tClass:

1. tClass refers to itself
2. tField
3. tMethod
4. tExceptionInfo (from tCode from tMethod)
5. tLocalVariableTable (index into constant pool)

This means that the field information and method information is not automatically shareable between classes. When loading a class that has already been loaded into a new namespace, we can't simply clone the tClass structure. Instead we have to replace all tClass references with one that points to the new <classloader, class> tuple.

This is a grep through the headers for the tClass* pointer

skami> grep -rn "tClass\*" vm/structs/*.h vm/classfil.h vm/interp.h                                 ~/kissme/cvsloader
vm/structs/struct_tarray.h:41:  tClass* pstType;     /* @field Pointer to the class that this object is an instance of */
vm/structs/struct_tclassfil.h:25:  tClass* pstSuperClass;       /* @field Pointer to the class's superclass */
vm/structs/struct_tclassfil.h:30:  tClass** ppstInterfaces;     /* @field Array of pointers to the interface classes that this class implements */
vm/structs/struct_tclassfil.h:61:  tClass** ppstCT;             /* @field Class table of class pointers */
vm/structs/struct_texceptioninfo.h:17:  tClass* pstCatchType; /* @field Type of exception that this clause catches */
vm/structs/struct_tmethod.h:18:  tClass* pstClass;      /* @field Pointer back to the class it's defined in */
vm/structs/struct_tmethod.h:26:    tClass** pstExceptions;  /* Array of types of exceptions thrown by this method */
vm/structs/struct_tobject.h:37:  tClass* pstType;     /* @field Pointer to the class that this object is an instance of */
vm/classfil.h:286://  tClass* pstClass;          /* @field Pointer to class */
vm/interp.h:141:  tClass*  pstCurrClass;            /* @field Pointer to current class */

We can see that objects and arrays also have pointers to the class structure.

The stackframe also contains a current class pointer.

