United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4593133 : API to generate Java stack traces for all threads

Details
Type:
Enhancement
Submit Date:
2001-12-11
Status:
Resolved
Updated Date:
2005-08-01
Project Name:
JDK
Resolved Date:
2003-07-18
Component:
core-svc
OS:
solaris_8,windows_nt,linux,generic,windows_2000
Sub-Component:
java.lang.management
CPU:
x86,sparc,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.2.2,1.3.0,1.3.1,1.4.0,1.4.1,5.0
Fixed Versions:
5.0 (tiger)

Related Reports
Duplicate:
Duplicate:
Relates:

Sub Tasks

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
EVALUATION

Tiger Feature Request

###@###.### 2001-12-13
                                     
2001-12-13
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
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b09
tiger-b12


                                     
2004-06-14



Hardware and Software, Engineered to Work Together