[Biojava-l] byte-code generation

Simon Brocklehurst simon.brocklehurst@CambridgeAntibody.com
Tue, 19 Sep 2000 18:42:53 +0100


Matthew Pocock wrote:

> Dear all,
>
> Does anybody here know how to generate java byte-code? I am hoping to
> write an implementation of DPFactory that generates java classes at
> run-time that implement the algorithms using code, rather than
> interpreting them.  The optimizers will have a much better chance at
> making the algorithms go faster. This may end up being heavy-duty
> byte-code generation stuff, but should mean that it goes about as fast
> as is possible.
>
> Any pointers or interested people?

Matthew,

I'm not sure if I understand what you want to do - mainly because I don't
know:

o what you mean by "implement the algorithms using code"
o what you mean by "the optimizers"
o what your DPFactory class does

But if what you mean is that you want to generate java classes on the fly
from within your software, here's a couple of suggestions....

To generate byte-code, you can obviously use.... wait for it... javac!
You can fairly trivially do this on-the-fly from within your DPFactory
either by using runtime.exec() or by accessing sun.tools.javac, and then
load your new classes dynamically.  Pluses and minuses of both approaches,
but both will work.

If you actually want to getting into writing your own optimized byte-code
this is rather more difficult and more work.  You might want to at least
consider running javac-generated byte code through a byte code optimizer
(again, you could do this on the fly with runtime.exec() and seeing if
this gets you where you want to go.

Failing that, buy some more CPU ;-)

Simon
--
Simon M. Brocklehurst, Ph.D.
Head of Bioinformatics & Advanced IS
Cambridge Antibody Technology
The Science Park, Melbourn, Cambridgeshire, UK
http://www.CambridgeAntibody.com/
mailto:simon.brocklehurst@CambridgeAntibody.com