[2092] in java-interest

home help back first fref pref prev next nref lref last post

re:WWWClassLoader problems (mobile objects)

daemon@ATHENA.MIT.EDU (andrew (a.) francis)
Sun Sep 24 17:26:37 1995

Date:  Sun, 24 Sep 1995 14:43:00 -0400 
From: "andrew (a.) francis" <andrewfr@bnr.ca>
To: chanda@PRPA.Philips.COM
Cc: java-interest@java.sun.com

In message "WWWClassLoader problems (mobile objects)", you write:

[lines deleted]

CD> 1) Have I understood this correctly ? So if the referenced classes are
CD> also on remote machines I have to make sure they are all loaded
CD> before the current one, by explicitly calling loadClass ??

    If I understand LoadClass correctly, The loadClass(String name, boolean
resolve) method recursively calls (via resolveClass) itself when it is loading 
classes. Since loadClass(string, boolean) is an abstract method that has to be 
overriden to be used, you have to provide the mechanisms to find the 
remote classes, transfer them, and load them.

CD> 2) I'm having other problems with WWWClassLoader. However, before
CD posting any questions I wonder if anyone has saved a copy of Chuck
CD> McManis's "Secrets of the ClassLoader"

Actually, the original article is called "Help with ClassLoader"
anyhow here it is

----

Class loader secrets:

	#1) After calling defineClass() you _must_ call resolveClass() before you
	    hand the class back to the person loading it.

	#2) You must use the system versions of class Class and Object or it won't
	    be able to cast your objects into something runnable. Typical class loader
	    flow is:
			loadClass(String name, boolean resolve) {
			    Class c = Class.forName(name);
			    if (c == null) {
				c = (Class)(classHashTable.get(name));
				if (c != null)
				    return c;
			    }
			    ... load class some other way ...
			    c = defineClass(...);
			    if (resolve)
			        resolveClass(c)
			    classHashTable.put(name, c);
			    return c;
			}

	#3) To invoke this new class you need to define an interface loaded on the
	    "system" side of the class loader (for example
		public interface fooable {
			void foo();
		}
	    and then cast your new object to a fooable and invoke foo. like so:
		c = tstLoader.loadClass("my.class", true);
		Object x = c.newInstance();
		((fooable) c).foo();
	    Of course you can do this in only one line:
		(fooable)(c.newInstance()).foo();
	
	#4) Classes loaded through your class loader will be run through the code
	    verifier. (This is a good way to see how good the code verifier is!) 
	    That also means that if you compile them with the -O switch they may not
	    verify (the compiler inlines accesses to private data which the verifier
	    will complain about).

That's about it. Once you've got a working class loader you have to be aware however
that a lot of the system classes key off the fact that there is a class loader on
the stack and assume you are an applet. So if your newly loaded class tries to open
a file for example it will be constrained to the read path and write path that HotJava
uses. This will change somewhat in Beta. 

------

Cheers,
Andrew
            
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post