JVMTI SetBreakpoint only works on certain instructions

Hello,

I'm developing a java decompiler and bytecode debugger application and have been playing around with JVMTI, in particular the SetBreakpoint function (so i can set a breakpoint on each instruction and step-through them).

For example, I have a simple java method which calls System.out.println(n) several times.

This is the decompiled bytecode:

publicvoid method1(){

//(0):getstatic #0, #18

//(1):ldc #52

//(2):invokevirtual #0, #54

//(3):iconst_0

//(4):istore_1

//(5):iinc #1, #1

//(6):getstatic #0, #18

//(7):ldc #57

//(8):invokevirtual #0, #54

//(9):getstatic #0, #18

//(10):ldc #59

//(11):invokevirtual #0, #54

//(12):getstatic #0, #18

//(13):ldc #61

//(14):invokevirtual #0, #54

//(15):getstatic #0, #18

//(16):ldc #63

...etc

}

I can set a breakpoint on any instruction (with no jvmtiErrors returned), but my breakpoint event handler function in my agent is only called when i set breakpoints on instructions: 0, 3, 5, 8, 9, 10, 13, 16.

When i set a breakpoint on line 2 for example, I get a this erro message from the JVM:

#

# An unexpected error has been detected by HotSpot Virtual Machine:

#

# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d6d1046, pid=4988, tid=1456

#

# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode)

# Problematic frame:

# V [jvm.dll+0x61046]

#

# An error report file with more information is saved as hs_err_pid4988.log

#

# If you would like to submit a bug report, please visit:

#http://java.sun.com/webapps/bugreport/crash.jsp

#

Does anyone have any idea what the cause of this intermittent behaviour is? It seems very odd that I can set a breakpoint on instruction 8 which is an invokevirtual bytecode, but not on instruction 11 which is also an invokevirtual instruction!

Also, what could be causing the EXCEPTION_ACCESS_VIOLATION error inside the JVM?

Any help would be greatly appreciated.

Thank you for your time.

Joe

[2796 byte] By [jmw2trinculoa] at [2007-10-3 4:10:23]
# 1

I apologise, I've solved my own problem.

I was looking too closely at my decompiler's bytecode output; the setBreakpoint() function's bytecode location index argument does not mean 'bytecode instruction index', but rather byte index.

I was attempting to set breakpoints on operand byte indexes rather than instructions themselves, hence why i was getting inconsistent results.

Still though, it would have been nice if the jvmti api or the jvm error message made that clearer.

Oh well, hope this post is useful to someone with the same problem in the future.

Cheers anyway,

Joe

jmw2trinculoa at 2007-7-14 22:10:38 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
It sounds like you have resolved this and the isuse was a bad location argument to the SetBreakpoint function - is that right? In any case, the spec does not require that an implementation detect this error. It is can detect the error then INVALID_LOCATION is returned.
alan.batemana at 2007-7-14 22:10:38 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...