Sunday, June 29, 2008

Using BTrace in Java 6

Got up to speed with BTrace recently and thanks to Sundararajan's clarifications on syntax. This tool is simply TOO cool to give it up since in my opinion, someone whom has developed in Java and/or J2EE would quickly pick this technology up in no time :-)

However, beware of some caveats as i found out while attempting to monitor certain Java classes in Java 6 - coincidentally i attempt to monitor the EJB lifecycle etc.

btrace DEBUG: java.lang.RuntimeException: JSR/RET are not supported with computeFrames option
java.lang.RuntimeException: JSR/RET are not supported with computeFrames option
at org.objectweb.asm.Frame.a(Unknown Source)
at org.objectweb.asm.MethodWriter.visitJumpInsn(Unknown Source)
at org.objectweb.asm.MethodAdapter.visitJumpInsn(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:66)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:62)
at com.sun.btrace.agent.Client.instrument(Client.java:261)
at com.sun.btrace.agent.Client.transform(Client.java:101)
at sun.instrument.TransformerManager.transform(TransformerManager.java:169)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:365)
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:124)
at com.sun.btrace.agent.Main.handleNewClient(Main.java:278)
at com.sun.btrace.agent.Main.startServer(Main.java:245)
at com.sun.btrace.agent.Main.access$000(Main.java:53)
at com.sun.btrace.agent.Main$1.run(Main.java:127)
at java.lang.Thread.run(Thread.java:619)

If you attempted to instrument certain code in your EJBs like ejbXXX() methods you might or would find something similar to the above and that would certainly kill your interest but i would advise you not to be too hasty in this as it still works in the J2SE 1.5.x platform.

But this certainly sparked my interest in the algorithm that is causing this problem and i went browsing through the fundamental technology in which BTrace was built - ASM. According to the ASM 3.0 documentation & the Java Virtual Machine specifications 2nd Edition, it turns out ASM is having a hard time trying to run its algorithm "execute()" which essentially will simulate the java bytecode instruction on the output stack frame ; so the current version of this software will actually throw a Java unchecked exception i.e. java.lang.RuntimeException to inform the user of this tool (in this case, myself) that its not supported .... yet.

0 comments: