[JVMTI] RFA: JVMTI Stack Tracing

David Daney ddaney@avtrex.com
Fri Oct 20 14:58:00 GMT 2006


Kyle Galloway wrote:
> This patch implements the GetStackTrace and GetFrameCount methods of 
> JVMTI.
>
> These methods can be used on any java thread, including those with 
> native calls, running on the VM.  To accomplish this, this patch uses 
> the existing stack tracing code, with some modifications.  When a 
> trace is requested, it sets up a handler for SIGTRAP for the thread 
> that is to be traced.  It then dispatches a SIGTRAP to that thread 
> using ptherad_kill ().  The signal handler gets a raw trace of the 
> call stack of that thread, stores it, then resets the default 
> handler.  The actual JVMTI method waits on a semaphore, since it has 
> to be signal safe, so that it will not begin to process the trace 
> until the handler has finished generating it.  This raw trace is then 
> fed into a modified version of _Jv_StackTrace::GetStackTraceElements 
> () called GetJVMTIStyleTrace, which eliminates uninteresting frames, 
> and returns a java-style call stack stored in an array of 
> jvmtiFrameInfo structures, than can be copied into the array sent into 
> the call (or have its length used for GetFrameCount).  The changes to 
> avoid _Jv_AllocBytes is to avoid the GC, which causes problems when 
> used from a signal handler.
>
> I have included a test case for GetFrameCount, the reason I have not 
> included one for GetStackTrace is because the values for jmethodIds 
> will not be constant.  Since GetFrameCount and GetStackTrace differ 
> only in what they do with the jmethodIds and jlocations returned from 
> GetJVMTIStyleTrace, without being able to set jmethodids, a separate 
> test case seems redundant since all it would show is that 
> GetStackTrace retieives the correct number of frames, which is shown 
> by the correct working of GetFrameCount.
>
> Questions/Comments?
Is libc async-signal safe?  What happens if the unwinder cannot produce 
a stacktrace because the thread was stopped somewhere where there was no 
unwind info?

Why don't you set SA_RESTART?

Why SIGTRAP?  That will interact poorly with gdb.

David Daney



More information about the Java-patches mailing list