> I want to port an application from BCEL to ASM (which is smaller and
> seems to be faster)
I rather suspect that for your application, the difference may not be as great
as you might expect. More below
> an existing class is read. For each method in the class:
> - l is the list of instructions in the method
[quoted text clipped - 7 lines]
> finally the class is dumped as an array of bytes (with the modified
> instruction list of each method).
[...]
> What I whish to know from someone that already used ASM is: is it
> possible to do something like that?
>
> I played a bit with ASM and I was not able to do anything in the right
> direction (but maybe it's because I'm used to BCEL).
The way ASM naturally works is unlike BCEL, and it does not (by default) create
a web of objects corresponding to the structure of the classfile. The
difference is very like that between processing XML using a SAX-style API and a
DOM-style one. The SAX-style tends to be small and fast, but only if you don't
need to consider the overall structure of the document. ASM (by default) has
similar advantages. However, for your application I think you do need
"non-local" processing -- you want to have a complete, modifiable,
representation of each method's bytecode in memory at the same time. BCEL
provides that for you whether you need it or not, ASM (by default) does not.
You /can/ tell ASM to build an object representation of the bytecode, see
package org.objectweb.asm.tree, but the cost is that ASM will run slower and
use more memory (both for allocated objects, and for more loaded classes).
Thus the advantage over BCEL will be reduced, it might even be eliminated (I
would /guess/ not).
I find the ASM API a little obscure. If you haven't already read it, then the
tutorial
http://asm.objectweb.org/doc/tutorial-asm-2.0.html
seems pretty good. It doesn't directly address how to build a tree, but it
should provide a useful background "orientation". The javadoc for
org.objectweb.asm.tree has more info on how to use it. You might find the
org.objectweb.asm.tree.analysis package useful too, but there doesn't seem to
be much guidance on how to use it -- and in any case you probably already have
code that does what the analysis framework helps with.
-- chris
Francesco Devittori - 21 Dec 2005 11:01 GMT
>>I want to port an application from BCEL to ASM (which is smaller and
>>seems to be faster)
[quoted text clipped - 19 lines]
> [...]
> -- chris
Thanks! This is exactly what I suspected, but I was not able to put it
in words like you did!
Francesco