< prev index next > src/java.base/share/classes/jdk/internal/vm/ThreadSnapshot.java
Print this page
*/
package jdk.internal.vm;
import java.util.Arrays;
import java.util.stream.Stream;
/**
* Represents a snapshot of information about a Thread.
*/
! class ThreadSnapshot {
private static final StackTraceElement[] EMPTY_STACK = new StackTraceElement[0];
private static final ThreadLock[] EMPTY_LOCKS = new ThreadLock[0];
// filled by VM
private String name;
*/
package jdk.internal.vm;
import java.util.Arrays;
import java.util.stream.Stream;
+ import jdk.internal.access.JavaLangAccess;
+ import jdk.internal.access.SharedSecrets;
/**
* Represents a snapshot of information about a Thread.
*/
! public class ThreadSnapshot {
+ private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
private static final StackTraceElement[] EMPTY_STACK = new StackTraceElement[0];
private static final ThreadLock[] EMPTY_LOCKS = new ThreadLock[0];
// filled by VM
private String name;
private ThreadSnapshot() {}
/**
* Take a snapshot of a Thread to get all information about the thread.
! * Return null if a ThreadSnapshot is not created, for example if the
! * thread has terminated.
! * @throws UnsupportedOperationException if not supported by VM
*/
! static ThreadSnapshot of(Thread thread) {
! ThreadSnapshot snapshot = create(thread);
if (snapshot == null) {
! return null; // thread terminated
}
if (snapshot.stackTrace == null) {
snapshot.stackTrace = EMPTY_STACK;
}
if (snapshot.locks != null) {
Arrays.stream(snapshot.locks).forEach(ThreadLock::finishInit);
} else {
snapshot.locks = EMPTY_LOCKS;
private ThreadSnapshot() {}
/**
* Take a snapshot of a Thread to get all information about the thread.
! * @param thread the thread
! * @param includeMonitors true to include the blocked on and owned object monitors
! * @return the snapshot or {@code null} if the thread is not alive
*/
! public static ThreadSnapshot of(Thread thread, boolean includeMonitors) {
! ThreadSnapshot snapshot = create(thread, includeMonitors);
if (snapshot == null) {
! return null; // thread not alive
}
if (snapshot.stackTrace == null) {
snapshot.stackTrace = EMPTY_STACK;
+ } else {
+ JLA.finishInit(snapshot.stackTrace);
}
if (snapshot.locks != null) {
Arrays.stream(snapshot.locks).forEach(ThreadLock::finishInit);
} else {
snapshot.locks = EMPTY_LOCKS;
}
/**
* Returns the thread stack trace.
*/
! StackTraceElement[] stackTrace() {
return stackTrace;
}
/**
* Returns the thread's parkBlocker.
}
/**
* Returns the thread stack trace.
*/
! public StackTraceElement[] stackTrace() {
return stackTrace;
}
/**
* Returns the thread's parkBlocker.
ThreadBlocker(int typeOrdinal, Object obj, Thread owner) {
this(lockTypeValues[typeOrdinal], obj, owner);
}
}
! private static native ThreadSnapshot create(Thread thread);
}
ThreadBlocker(int typeOrdinal, Object obj, Thread owner) {
this(lockTypeValues[typeOrdinal], obj, owner);
}
}
! private static native ThreadSnapshot create(Thread thread, boolean includeMonitors);
}
< prev index next >