[Biojava-l] byte-code generation

Matthew Pocock mrp@sanger.ac.uk
Tue, 19 Sep 2000 18:41:12 +0100


Hi Simon,

Simon Brocklehurst wrote:

> 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"

I mean - take the HMM object with states & transitions etc. and write out code
that would implement that algorithm. At the moment, these objects are
interpreted, which is great for flexibility but it is possible to write down
code that gives identical results with a much lower CPU overhead.

>
> o what you mean by "the optimizers"

I think I meant that in the generated code:
  all the loops can be unrolled
  states that can be only reached via one source can have the argMax and sum
opperations optimized out & all probabilities of 1 (log prob 0) can be ignored

  for models with small numbers of parameters (< 64k?) all params can be
stoored localy, removing function call overheads.

This code is then almost exactly the sort of thing that the java runtime
byte-code optimizers, jits and hotspots like to eat for breakfast.

>
> o what your DPFactory class does
>

takes a HMM and returns a DP object that can be used to generate alignments

>
> 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.
>

This involves writing java code. It will work, and will be relatively easy to
debug. I would prefer to write the bytecode directly, as it leaves less room
for mess (like where to stoor the temporary files etc.). It can be done - most
of the java implementations of scripting languages (javascript, tcl, python
etc.) generate byte-code on the fly to interpret the scripts. Also, the proxy
class in 1.3 generates byte-code to glue the delegates to the interfaces.

>
> 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
>
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l@biojava.org
> http://biojava.org/mailman/listinfo/biojava-l

--
Joon: You're out of your tree
Sam:  It wasn't my tree
                                                 (Benny & Joon)