Looking to rewrite some bytecodes...


I'm playing around with a couple ideas I had for dynamic program analysis, and looking to write a plugin.

1)I have a bytecode rewriter, and I want it to sit IDEAs compilation path. That is, after IDEA compiles a .class file, it should then mutate that file in-place, using my bytecode rewriter. It looks like the Compiler API should allow this (ClassInstrumentingCompiler?), but I honestly can't figure out how. Any pointers or code examples would be greatly appreciated.

2)When the rewritten code is run (using any command-line run configuration), it will communicate with a small runtime library I've written. This runtime library needs to be automatically added to the classpath, and a configuration string needs to be passed to it as a command-line system property. Both of these should happen without the user being aware of it. Again, any pointers or examples would be great.

(No, I won't say what I'm doing with the instrumentation. Trust me, it'll be wicked cool if it works.)

Thanks.

--Dave Griffith

5 comments
Comment actions Permalink

Ask Keith? Sounds exactly like what he did with his null checker.

Dave Griffith schrieb:

I'm playing around with a couple ideas I had for dynamic program analysis, and looking to write a plugin.

1)I have a bytecode rewriter, and I want it to sit IDEAs compilation path. That is, after IDEA compiles a .class file, it should then mutate that file in-place, using my bytecode rewriter. It looks like the Compiler API should allow this (ClassInstrumentingCompiler?), but I honestly can't figure out how. Any pointers or code examples would be greatly appreciated.

2)When the rewritten code is run (using any command-line run configuration), it will communicate with a small runtime library I've written. This runtime library needs to be automatically added to the classpath, and a configuration string needs to be passed to it as a command-line system property. Both of these should happen without the user being aware of it. Again, any pointers or examples would be great.

(No, I won't say what I'm doing with the instrumentation. Trust me, it'll be wicked cool if it works.)

Thanks.

--Dave Griffith

0
Comment actions Permalink

Hello Dave,

1)I have a bytecode rewriter, and I want it to sit IDEAs compilation
path. That is, after IDEA compiles a .class file, it should then
mutate that file in-place, using my bytecode rewriter. It looks like
the Compiler API should allow this (ClassInstrumentingCompiler?), but
I honestly can't figure out how. Any pointers or code examples would
be greatly appreciated.


Maybe GUI Designer?


0
Comment actions Permalink

I'm pretty sure Keith rewrote at the source level, not the class file level. Nonetheless I was certainly hoping to learn his experiences.

--Dave Griffith

0
Comment actions Permalink

Part 2 sounds related to what I'm doing for the JProfiler plugin. Please
contact me by mail if you want any assistance.

Dave Griffith wrote:

I'm playing around with a couple ideas I had for dynamic program analysis, and looking to write a plugin.

1)I have a bytecode rewriter, and I want it to sit IDEAs compilation path. That is, after IDEA compiles a .class file, it should then mutate that file in-place, using my bytecode rewriter. It looks like the Compiler API should allow this (ClassInstrumentingCompiler?), but I honestly can't figure out how. Any pointers or code examples would be greatly appreciated.

2)When the rewritten code is run (using any command-line run configuration), it will communicate with a small runtime library I've written. This runtime library needs to be automatically added to the classpath, and a configuration string needs to be passed to it as a command-line system property. Both of these should happen without the user being aware of it. Again, any pointers or examples would be great.

(No, I won't say what I'm doing with the instrumentation. Trust me, it'll be wicked cool if it works.)

Thanks.

--Dave Griffith


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Dave Griffith wrote:

I'm pretty sure Keith rewrote at the source level, not the class file
level. Nonetheless I was certainly hoping to learn his experiences.


You're correct, I use a source instrumenting compiler. I haven't used it
but I think you could use a ClassInstrumentingCompiler (I believe this
is what the GUI designer uses). In a project component, I do this:

compilerManager = CompilerManager.getInstance(project);
nullChecker = new NullyCompilerStep(project);
compilerManager.addCompiler(nullChecker);

In my case NullyCompilerStep implements JavaSourceInstrumentingCompiler.

0

Please sign in to leave a comment.