bytecode analysis

A

Apple

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

Roedy Green

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
 
P

Piotr Kobzda

Apple said:
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
 
O

Oliver Wong

Apple said:
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
 
C

Chris Smith

Oliver Wong said:
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.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top