i was looking for a Java library to analyze bytecode files. I tried JDK
reflection but it does not provide information about local variables. then i
looked into BCEL but unforunately it does not support Java 1.5. (i want to
extract generic info about the local variables). I read a bit about ASM
but.. it looks a little bit complicated to handle. can anyone give me any
advices or suggestions?
Thanks.
Roedy Green - 27 Mar 2006 06:25 GMT
>i was looking for a Java library to analyze bytecode files. I tried JDK
>reflection but it does not provide information about local variables. then i
>looked into BCEL but unforunately it does not support Java 1.5. (i want to
>extract generic info about the local variables). I read a bit about ASM
>but.. it looks a little bit complicated to handle. can anyone give me any
>advices or suggestions?
see http://mindprod.com/jgloss/jasm.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Piotr Kobzda - 27 Mar 2006 11:17 GMT
> i was looking for a Java library to analyze bytecode files. I tried JDK
> reflection but it does not provide information about local variables. then i
> looked into BCEL but unforunately it does not support Java 1.5. (i want to
> extract generic info about the local variables). I read a bit about ASM
> but.. it looks a little bit complicated to handle. can anyone give me any
> advices or suggestions?
ASM is not as complicated to handle as it seems to be. Key is in
understanding of Visitor design pattern.
See:
http://www.onjava.com/pub/a/onjava/2005/08/17/asm3.html
and Related Articles.
And of course carefully read Tutorial for ASM from the project's home page:
http://asm.objectweb.org/
In order to retrieve generic info of your local variables (assuming I
understand your particular requirement), you will need the signature of
each local variable, which is a part of optional Local Variable Type
Table (new in a class file format since Java 5); use -g:vars compiler
option to adds this optional info into a class file.
ASM supports local variable signature retrieval by visitLocalVariable()
method of MethodVisitor, the signature parsing can be supported with
SignatureVisitor.
Regards,
piotr
Oliver Wong - 27 Mar 2006 20:18 GMT
>i was looking for a Java library to analyze bytecode files. I tried JDK
>reflection but it does not provide information about local variables. then
>i looked into BCEL but unforunately it does not support Java 1.5. (i want
>to extract generic info about the local variables). I read a bit about ASM
>but.. it looks a little bit complicated to handle. can anyone give me any
>advices or suggestions?
My understanding is that generic information is erased at compile time,
so you will not be able to extract any information about it by looking at
bytecode.
- Oliver
Chris Smith - 28 Mar 2006 06:49 GMT
> My understanding is that generic information is erased at compile time,
> so you will not be able to extract any information about it by looking at
> bytecode.
Nah, it's there in the class file. That's how, for example the compiler
knows how many type parameters a class is supposed to take. Without
generics info being available to the compiler, most of the remaining
uses would become impossible.
However, it is not stored in method signatures. It's stored in special
attributes which augment the otherwise non-generic class.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation