JVMTI GetStackTrace / GetThreadListStackTraces / GetAllStackTraces & GetFrameCount

Erich strale at gmx.net
Wed Dec 22 16:56:26 PST 2010


Hello,

I've a few suggestions for future jvmti revisions regarding the Get*StackTrace[s] functions. First, they are quite inconsistent. While you can provide a start depth when calling the GetStackTrace function, GetThreadListStackTraces / GetAllStackTraces are lacking this parameter. I don't know if somebody wold need to specify this parameter for GetAllStackTraces, but I would welcome it at least for GetThreadListStackTraces.

More important is that it is not possible to get the frame count while getting the stack trace. 

Well, it's possible. You can either set the max stack depth to an astronomical high number to get all the stack frames and just parse those you are interested - which would be a waste of memory and cpu time, or suspend the thread before getting the stacktrace, when max frame count == frame count captured call GetFrameCount and resume the thread - which would imply a big performance overhead.

I would therefore propose 2 new functions ... or replacents when the new jvmti revision is requested:

jvmtiError GetStackTrace(jvmtiEnv* env, jthread thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr, jint* stack_depth)
	... when stack_depth is != NULL the stack_depth is set.
jvmtiError GetThreadListStackTraces(jvmtiEnv* env, jint thread_count, const jthread* thread_list, jint *start_depth_list, jint max_frame_count, jvmtiStackInfo** stack_
info_ptr)

and a change of the jvmtiStackInfo structure:
typedef struct {
    jthread thread;
    jint state;
    jvmtiFrameInfo* frame_buffer;
    jint frame_count;

    jint stack_depth;
} jvmtiStackInfo;

where stack_depth is the current depth of the stack. Which would also solve the issue when the stack is exactly max_stack_depth you can't tell if you got the whole stacktrace or just part of it.

Best regards & merry christmas,
  Erich Hochmuth


More information about the serviceability-dev mailing list