[groovy-dev] ASMifier...

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[groovy-dev] ASMifier...

Guillaume Laforge
Administrator
Hi guys,

Just a quicky to show a nice little and handy tip for those who wanna
hack some ASM bytecode generation. From an article on ASM website,
I've created a command file to use ASM's asmifier class which outputs
the relevant java code used to generate the same code as a compiled
class given in argument.

More concretely, say you have a compiled java class Foo.class and you
want to know how to generate the same bytecode with ASM, you can use
the Asmifier tool to see what the equivalent java code would look
like.

For that, I've created a little command named asmifier.cmd file that
I've put in my %GROOVY_HOME%\bin folder:

--------------------%<----------------------------------------------
@echo off

set cp=%cp%;%GROOVY_HOME%\lib\asm-2.0.jar
set cp=%cp%;%GROOVY_HOME%\lib\asm-attrs-2.0.jar
set cp=%cp%;%GROOVY_HOME%\lib\asm-util-2.0.jar

set c=org.objectweb.asm.util.ASMifierClassVisitor

java -cp %cp% %c% %1
--------------------%<----------------------------------------------

And now, I can do:

asmifier Foo

And it'll output on stdout the java code corresponding to my class.

PS: Thanks blackdrag for pointing me at the asmifier class :-)

--
Guillaume Laforge
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] ASMifier...

Jochen Theodorou
Guillaume Laforge schrieb:
[...]
> asmifier Foo

printclass here

> And it'll output on stdout the java code corresponding to my class.
>
> PS: Thanks blackdrag for pointing me at the asmifier class :-)

don't forget org.objectweb.asm.util.TraceClassVisitor and
org.objectweb.asm.util.CheckClassAdapter ;)

I have them in my shell a long time now... couldn't have done much of
the bytecode things I have done without these 3 tools

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] ASMifier...

Guillaume Laforge
Administrator
On 05/11/05, Jochen Theodorou <[hidden email]> wrote:
> Guillaume Laforge schrieb:
> [...]
> > asmifier Foo
>
> printclass here

Hehe :-)))

> don't forget org.objectweb.asm.util.TraceClassVisitor and
> org.objectweb.asm.util.CheckClassAdapter ;)

What are these doing?

> I have them in my shell a long time now... couldn't have done much of
> the bytecode things I have done without these 3 tools

I guess so, yes ;-)

What's the URL of the bytecode documentation btw? I can't seem to find
it (wrong google keywords I suspect).

Particularly regarding synchronized(foo) {} :-)

--
Guillaume Laforge
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] ASMifier...

Jochen Theodorou
Guillaume Laforge schrieb:

> On 05/11/05, Jochen Theodorou <[hidden email]> wrote:
[...]
>>don't forget org.objectweb.asm.util.TraceClassVisitor and
>>org.objectweb.asm.util.CheckClassAdapter ;)
>
> What are these doing?

CheckClass is a verifier, a little bit stronger than java's verifier. I
don't know the current state but the last time I checked the groovy
distribution with CheckClass all groovy files where ok, only some Java
files had problems ;) It shows you for example if there are problems
with the stack. for an example look at the faq here:
http://asm.objectweb.org/doc/faq.html#Q4

TraceClassVisitor is used to produce human readable bytecode for a
class. Where as it sometimes is good to use the asmifyer, it is
sometimes better to use this one as the asmifiyer tends to hide some
things sometimes.
see also http://asm.objectweb.org/doc/faq.html#Q10

>>I have them in my shell a long time now... couldn't have done much of
>>the bytecode things I have done without these 3 tools
>
> I guess so, yes ;-)
>
> What's the URL of the bytecode documentation btw? I can't seem to find
> it (wrong google keywords I suspect).
>
> Particularly regarding synchronized(foo) {} :-)

look at
http://java.sun.com/docs/books/vmspec/2nd-edition/html/Compiling.doc.html#13842

bye blackdrag
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] ASMifier...

Guillaume Laforge
Administrator
> CheckClass is a verifier, a little bit stronger than java's verifier. I
> don't know the current state but the last time I checked the groovy
> distribution with CheckClass all groovy files where ok, only some Java
> files had problems ;) It shows you for example if there are problems
> with the stack. for an example look at the faq here:
> http://asm.objectweb.org/doc/faq.html#Q4

Groovyc's bytecode is better than javac's one!!! woohooo :-)

> TraceClassVisitor is used to produce human readable bytecode for a
> class. Where as it sometimes is good to use the asmifyer, it is
> sometimes better to use this one as the asmifiyer tends to hide some
> things sometimes.
> see also http://asm.objectweb.org/doc/faq.html#Q10

Hmm, this one is nice, I'll add it to my toolbox ;-)

> look at
> http://java.sun.com/docs/books/vmspec/2nd-edition/html/Compiling.doc.html#13842

I was complaining but I found it just after I sent my mail  ;-)))))

Thanks a lot!

PS: you're not on #groovy?

--
Guillaume Laforge
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: [groovy-dev] ASMifier...

Jochen Theodorou
Guillaume Laforge schrieb:
[...]
> PS: you're not on #groovy?

nope... wrong machine, no irc program here ;)

cu, blackdrag