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.
|