Velocity Reviews

Velocity Reviews (
-   Java (
-   -   get current StackFrame thru JDI (

Ken.C 02-05-2007 12:21 PM

get current StackFrame thru JDI
I did Google search but didn't get much useful info...
Basically, I encountered IndexOutOfBoundsException when trying to get
current stack frame:
1 void methodEntryEvent(MethodEntryEvent event) {
2 Method method = event.method();
3 ThreadReference thread = (ThreadReference) event.thread();
4 try {
5 StackFrame stackFrame = thread.frame(0);
catch(IncompatibleThreadStateException e){

The exception occurred at line 5. Test codes running on the target VM

public static void main(String[] args) {
String name = "Someone";

private static String foo(String name) {
return "Hi, " + name + ".";

private static int bar(int a) {
return 999;

Does anyone know why the stack counter is always 0 in my codes?

Thanks a lot

Chris Uppal 02-07-2007 06:53 PM

Re: get current StackFrame thru JDI
Ken.C wrote:

> Does anyone know why the stack counter is always 0 in my codes?

I know very little about JDI, but no one else has replied so....

Was the thread suspended at the time the event was generated ? If not then I
doubt whether frames are available (since the thread will have gone on
executing while the event was passed through the event queue). See the
documentation for

EntryRequest.setSuspendPolicy(EventRequest.SUSPEND _ALL)

And then you'll have to resume() the target ThreadReference. There's more
documentation about it, but I've only skimmed that -- you should probably read
it more carefully than me ;-)

-- chris

All times are GMT. The time now is 12:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.