Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BCI library for Java in C

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.

like image 237
vektor Avatar asked Nov 04 '22 19:11

vektor


2 Answers

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.

like image 159
obataku Avatar answered Nov 09 '22 23:11

obataku


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.

like image 29
npr Avatar answered Nov 10 '22 00:11

npr