6 Replies Latest reply: Nov 24, 2009 12:47 PM by 843810 RSS

    Using JVMTI with ASM

      I've been trying to do instrumentation using JVMTI nad ASM. What I've been doing is getting the classes via a ClassFileLoad hook, and then piping the bytes to a separate process that uses ASM to modify the class, and sends the modified class back over a pipe, since java_crw_demo is not really flexible enough to do what I want. However, since I'm still modifying classes that are used while the VM boots, I need to duplicate some of what java_crw_demo does to handle "system classes" in my ASM program. I seem to be having some trouble doing it correctly though (I some how get null pointer exceptions while the VM is still booting). Does any one have some (non-null) pointers?

      In particular:

      Is there anything in jvmti_crw_demo other than skip_method that discriminates as far as what methods are transformed?

      I see where skip_method skips init, clinit, currentThread, in skip_method. But what does it mean for the length of these methods to be 1, and why is that a special case?

      --Nathan R.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
        • 1. Re: Using JVMTI with ASM
          See lines 2000-2015 or so here:

          I suspect you have seen it, but just to be sure.

          But what's more important is what defines "system_class". As an example, see
          around line 784.

          A system class is defined as any class loaded before the JVM Ti VM_START event.

          Hope this helps...

          • 2. Re: Using JVMTI with ASM
            I just realized that I did not answer your questions about 'length 1'.

            My first reaction is that with a length 1, there is nothing to instrument for java_crw_demo, but I have some vague memories as to why I wrote the code this way. Sorry.

            • 3. Re: Using JVMTI with ASM
              Ah... length==1... The classfile spec says the Code length must never be 0, so a length==1 is like no length at all. See the Java Virtual Machine Specification on the classfile Code attribute.

              • 4. Re: Using JVMTI with ASM
                Hmm, unfortunately ASM seems to provide no way for me to check the code length (at least not that I can find) but since those methods are empty, I think ASM will skip them (since it should never visit any bytecodes if there aren't any there). But do you have an example of a class with a method that has length 1 so that I could run it through my instrumenting code and see what, if any thing, it does? I suppose if you do not know one off the top of your head I could just make java_crw_demo report to me the name of one.

                Thanks for the help.
                • 5. Re: Using JVMTI with ASM
                  If you are using ASM I think you can ignore the length==1 test used in java_crw_demo.

                  • 6. Re: Using JVMTI with ASM
                    is there a MacOSX version of heapTracker project with JVMTI?