JDK-4593133 : API to generate Java stack traces for all threads
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 1.2.2,1.3.0,1.3.1,1.4.0,1.4.1,5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,linux,solaris_8,windows_nt,windows_2000
  • CPU: generic,x86,sparc
  • Submitted: 2001-12-11
  • Updated: 2017-05-16
  • Resolved: 2003-07-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
Provide an API in Java to dump stack traces from Java programmatically.

The stack trace output should be in a standard well-defined format
so it can be parsed by third party tools.

An array of stack trace elements can be returned for a specific thread or
a map of stack trace array elements are returned for all threads.
 

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b09 tiger-b12
2004-06-14

SUGGESTED FIX Two new methods are added to java.lang.Thread class: /** * Returns an array of stack trace elements representing the stack dump * of this thread. This method will return a zero-length array if * this thread has not started or has terminated. * If the returned array is non-zero length (non-empty stack trace), * the zeroth element of the array represents the top * of the stack, which is the most recent method invocation in the sequence. * The last element of the array represents the bottom of the stack, * which is the first method invocation in the sequence. * * <p>First, if there is a security manager, and this thread is not * the current thread, then the security manager's * <code>checkPermission</code> method is called with a * <code>RuntimePermission("getStackTrace")</code> permission * to see if it's ok to get the stack trace. * * @return an array of <tt>StackTraceElement</tt>, * each represents one stack frame. * * @throws SecurityException * if a security manager exists and its * <code>checkPermission</code> method doesn't allow * getting the stack trace of thread. * @see SecurityManager#checkPermission * @see java.lang.RuntimePermission * @see Throwable#getStackTrace * * @since 1.5 */ public StackTraceElement[] getStackTrace(); /** * Returns a map of stack dumps of all threads. * The Map keys are Threads and each Map value is an array of * <tt>StackTraceElement</tt> that represents the stack dump * of the corresponding <tt>Thread</tt>. * * <p>The threads may be executing while this method is called. * The stack trace of each thread only represents a snapshot and * each stack trace may be obtained at different time. A zero-length * array will be returned in the Map value if the virtual machine has * no stack trace information about a thread. * * <p>First, if there is a security manager, then the security manager's * <code>checkPermission</code> method is called with a * <code>RuntimePermission("getStackTrace")</code> permission as well as * <code>RuntimePermission("modifyThreadGroup")</code> permission * to see if it is ok to get the stack trace of all threads. * * @return a <tt>Map</tt> from Threads to an array of * <tt>StackTraceElement</tt> that represents the stack trace of * the corresponding thread. * * @throws SecurityException * if a security manager exists and its * <code>checkPermission</code> method doesn't allow * getting the stack trace of thread. * @see #getStackTrace * @see SecurityManager#checkPermission * @see java.lang.RuntimePermission * @see Throwable#getStackTrace * * @since 1.5 */ public static Map getAllStackTraces(); Two private JVM entry points are added in the VM: 1. jobjectArray JVM_GetAllThreads(JNIEnv* env, jclass dummy) returns an array of Thread objects. 2. jobjectArray JVM_DumpThreads(JNIEnv* env, jclass dummy, jobjectArray threads) returns an array of StackTraceElement[] and each element represents the stack trace of a thread in the given array of Thread objects of the same index.
2004-06-11

EVALUATION Tiger Feature Request ###@###.### 2001-12-13
2001-12-13