[3096] in java-interest

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

Re: dynamic method invocation -- any more discussion?

daemon@ATHENA.MIT.EDU (Steve V. Yalovitser)
Mon Oct 30 21:00:49 1995

From: "Steve V. Yalovitser" <root@cyberpunk.com>
In-Reply-To: <9510301605.AA01854@m-space.com>
To: java-interest@java.sun.com
Cc: Chris Cuilla <ccuilla@m-space.com>
Date: Mon, 30 Oct 1995 19:09:59 +0800 (EST)

Dynamic method invocation was relatively simple to hack up for the simple
case. There was an old mail by Tom Ball or Arthur which gave a blueprint. It isnt
really correct but should give a start:

From daemon@java.sun.com Tue Sep 26 09:37 EDT 1995
Received: from java.Sun.COM by sensenet.cyberpunk.com with SMTP
	(1.38.193.4/16.2) id AA11084; Tue, 26 Sep 1995 09:37:07 -0400
Return-Path: <daemon@java.sun.com>
Received: (from daemon@localhost) by java.sun.com (8.6.12/8.6.12) id CAA02579
for java-interest-recipients; Tue, 26 Sep 1995 02:24:23 -0700
Received: (from majordom@localhost) by java.sun.com (8.6.12/8.6.12) id
CAA02572 for java-interest-outgoing; Tue, 26 Sep 1995 02:24:20 -0700
Date: Mon, 25 Sep 1995 10:26:28 -0700
From: cmcmanis@scndprsn.Eng.Sun.COM (Chuck McManis)
Message-Id: <9509251726.AA16926@pepper.Eng.Sun.COM>
To: gbolcer@liege.ICS.UCI.EDU, mikec@metronet.com
Subject: Re: Dynamic Loading of Classes
Cc: java-interest@java.Eng.Sun.COM
X-Sun-Charset: US-ASCII
Sender: owner-java-interest@java.sun.com
Precedence: bulk
X-Info: To unsubscribe, send 'unsubscribe' to
java-interest-request@java.sun.com
Status: RO

>In article  Gregory Alan Bolcer <gbolcer@liege.ICS.UCI.EDU> writes:
>>    I've programmed myself into a corner, and I am seeking advice
>>on the following problem.  I have a Java unix process that is
>>maintaining a dynamically changeable object model (categories) 
>>built on top of Java.  The methods to these categories can be 
>>dynamically changed at runtime and are implemented as Java classes
>>within a file directory.  

Mike Responds...

>Sounds cool however, Java is not a dynamic language in the sense that 
>Smalltalk is a dynamic language. This works it self back to the request for 
>perform: capabilities ala Smalltalk. The reason for no perform: (as it was 
>explained to me) is that it opens a big security hole. For example, a Nasty 
>Old Java App (NOJA) could evoke the method "MySystem.sendUglyMailToMyBoss"
if
>a class with such an interface exists. I guess that the NOJA could scan the 
>class which it finds on a given workstation and try things at random causing 
>all sorts of havoc. 

Mike is correct, however if your already running UNIX processes then
you are not an applet and just a Java ap. Consider writing your own
"perform" class, to do some (most?) of it is fairly trivial.

NOTES: THE FOLLOWING CODE IS WRITTEN "on the fly" And probably won't
	even compile, much less work, however it should provide sufficient
	information to do what you want.

Write a class "DynamicMethodInvoker" which is defined something like:
class DynamicMethodInvoker {
    static {System.loadLibrary("dynamix");}

    private native Object executeDynamicMethod(Object o, String meth,
					String sig, Object args[]);

    public Object doDynamicMethod(Object o, String meth, String sig, 
		Object args[]) {
	/* Implement some security policy here. Maybe call SecurityManger
	   canInvoke or something you make up, what ever you do, don't
	   let applets call this. */
	SecurityManager.mySecurityPolicy();
	return (executeDynamicMethod(o,meth, sig, args));
    }
}

And in the C code write:

int parseSignature(char *sig) {
    static char *cursig;
    if (sig != NULL) {
	cursig = sig;	/* set the signature */
	cursig = strchar(sig, '['); /* find the arguments */
	return 0;
    }
    return (getnextparameter(cursig)); /* return next argument type
				          (int, object ref, etc) */
}

int sigComponents(char *sig) {
	/* return number of arguments to the method */
}

ClassDynamicMethodInvoker_executeDynamicMethod(HObject *this,
	HObject *that, HString *meth, HString *sig, HArrayOfObject *args) {
	long res;
	
	switch (sigComponents(sig)) {
	case 0:
		res = java_execute_dynamic_method(getEE(), unhand (that),
			unhand(meth), unhand(sig));
		break;

	case 1:
		parseSignature(sig);
		res = java_execute_dynamic_method(getEE(), unhand (that),
			unhand(meth), unhand(sig),getnextParameter(sig));
		break;
	...
	/* repeat for as many arguments as you would like. */

	}
	type = parsesignatureResult(sig);
	/* this should simply parse the return type. */
	/* if it is a simple type (int, long, etc) then call
	   execute_java_constructor() on the result with the
	   simple type's class
	   (ie execute_java_constructor(..,"Integer", res,...)
	*/
	return res;
}

Note that amateur spelunkers should not try to do this, it will just
confuse you.

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

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

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