Question

I am looking for a BCI (Bytecode Instrumentation) library for Java in C or C++, to use in a JVMTI agent.

Best case scenario would be something like ASM or BCEL in pure C.

The closest thing I have found so far is only a demo java_crw_demo written by Kelly O'Hair a few years ago and used in Sun's/Oracle's tutorials ever since.

Do you know of anything else?

Some rationale: I am building an instrumentation tool to add a getter method to java.lang.Object and overload this getter in every direct subclass of Object. For this reason I cannot use a Java agent. Also, I would like to avoid spawning a secondary JVM to perform the instrumentation - for complexity and speed reasons.

Was it helpful?

Solution

I once started writing one in C quite a while ago, but I didn't get very far due to lack of motivation. AFAIK there's no public releases in C, but it shouldn't be too hard to write a simple one for your needs according to the JVM Specification. You should be particularly interested in the chapter on the class file format, as well as that on the instruction set.

OTHER TIPS

The only reasonable solution I have found is to actually pipe the byte codes over to a separate Java program that uses ASM (or the BCI framework of your choice). This is not fast, but you only need to do it once per instrumented class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top