janino-compiler / janino

Janino is a super-small, super-fast Java™ compiler.
http://janino-compiler.github.io/janino
Other
1.25k stars 208 forks source link

ClassBodyEvaluator dump out .class file #103

Closed helloguo closed 5 years ago

helloguo commented 5 years ago

Hi,

After ClassBodyEvaluator.cook(), is there a way to dump out the java bytecode into a .class file? I see issue https://github.com/janino-compiler/janino/issues/19 and the test file show a way to dump the bytecode into a byte[], which looks like a good start. I was wondering if there's an easy way to dump out into a file?

Some context: I have some auto generated methods, whose java bytecode size could be more than 8000 bytes. Since the JVM has the default HugeMethodLimit 8000, it will not JIT these large methods. I was thinking of letting ClassBodyEvaluator dump out the .class file, then using other tools such as proguard/soot to optimize the bytecode to get a smaller .class file. After that, let the classloader to load the new smaller .class file. So dumping out the java bytecode seems the first step. Any suggestion is appreciated.

aunkrig commented 5 years ago

That‘s possible out-of-the-box! Just set a system property UnitCompiler.disassembleClassFilesToStdout=true and you get what you want.

helloguo commented 5 years ago

@aunkrig Thank you!