com.svincent.smalljava
Class SmallClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--com.svincent.smalljava.SmallClassLoader

public class SmallClassLoader
extends java.lang.ClassLoader

Allows dynamic loading and execution of Smalljava code.

Beware. JDK 1.2 added new rules regarding the garbage collection of classes. In particular,

"A class or interface may be unloaded if and only if its class loader is unreachable (the definition of unreachable is given in JLS 12.6.1). Classes loaded by the bootstrap loader may not be unloaded."

Here is Sun's technical rationale for this decision

This means that you must be careful about how you use dynamically generated classes. One model that is guaranteed to work is to create a ClassLoader, define and execute a class using it, and then drop the ClassLoader on the floor. This works for some applications, but not all.

Fancier schemes are possible, and may be documented here later. It is possible that a fancy scheme using weak references and many ClassLoaders may be implemented in Smalljava. If that happens, these facilities will be made available as part of the Smalljava API.

There may be issues with this ClassLoader, particularly with respect to redefining classes again and again. This has not been thoroughly tested.

Author:
Shawn Vincent

Constructor Summary
SmallClassLoader()
           
 
Method Summary
 java.lang.Class findClass(java.lang.String name)
          Finds a class, trying the current installed classes first, and then the system classloader, if all else fails.
 void installClass(SmallClass smallClass)
          Install the given SmallClass into this ClassLoader.
 java.lang.Class loadClass(SmallClass smallClass)
          Requests the immediate loading of the given SmallClass object.
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmallClassLoader

public SmallClassLoader()
Method Detail

loadClass

public java.lang.Class loadClass(SmallClass smallClass)
Requests the immediate loading of the given SmallClass object.

installClass

public void installClass(SmallClass smallClass)
Install the given SmallClass into this ClassLoader.

findClass

public java.lang.Class findClass(java.lang.String name)
                          throws java.lang.ClassNotFoundException
Finds a class, trying the current installed classes first, and then the system classloader, if all else fails.
Overrides:
findClass in class java.lang.ClassLoader



This is documentation for Moksa Prolog, which can be found at http://www.svincent.com/moksa/

Copyright © 1999 Shawn P. Vincent.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.