This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
gnu.bytecode class generation
- To: kawa at sources dot redhat dot com
- Subject: gnu.bytecode class generation
- From: Nick Collier <nick at src dot uchicago dot edu>
- Date: Mon, 5 Feb 2001 13:08:29 -0600
- Reply-To: nick at src dot uchicago dot edu
Hi,
I'm interested in using the byte code generation parts to dynamically create
objects. The overall context here is a scheduling mechanism for executing
methods on java objects. These method calls get wrapped by another class that
implements an interface that scheduling mechanism knows how to handle. At the
moment, users need to do this wrapping themselves typically with an inner
class, and then schedule the execution of this inner class object. So we have
something like:
schedule.scheduleActionBeginning(1, new BasicAction() {
public void execute() {
some_object.some_method();
}
});
Its also possible to do this using reflection where a BasicAction subclass
takes an object and a method name as parameters and invokes that method on
the object in the call to execute(). However, execute() potentialy gets
called tens of thousands of times (sometimes more) and reflection is
demonstrably slower.
What I'd like to do is something like:
schedule.scheduleActionBeginning(1, some_object, "some_method_name");
and use gnu.bytecode to generate a BasicAction class that calls
some_object.some_method_name();
inside the execute method. This is the beginning of experiments in
simplifying and ultimately hiding the scheduling mechanism from users.
I've looked at the javadoc docs and it seems that this should be no problem.
I'm familiar with the class file format, but I'm unsure how to proceed using
gnu.bytecode. I suppose what I'm asking is pointers on how to create a fairly
simple java class with a few ivars and a single method using gnu.bytecode.
thanks,
Nick
--
Nick Collier
Social Science Research Computing
University of Chicago
http://repast.sourceforge.net