mirror of
https://github.com/corda/corda.git
synced 2025-01-23 21:08:48 +00:00
implement Thread.getStackTrace, activeCount, and enumerate
This commit is contained in:
parent
04c3abc967
commit
d9ec8e20bf
@ -108,4 +108,14 @@ public class Thread implements Runnable {
|
|||||||
t.sleepLock.wait(milliseconds);
|
t.sleepLock.wait(milliseconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StackTraceElement[] getStackTrace() {
|
||||||
|
return Throwable.resolveTrace(getStackTrace(peer));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native Object getStackTrace(long peer);
|
||||||
|
|
||||||
|
public static native int activeCount();
|
||||||
|
|
||||||
|
public static native int enumerate(Thread[] array);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class Throwable {
|
|||||||
|
|
||||||
private static native Object trace(int skipCount);
|
private static native Object trace(int skipCount);
|
||||||
|
|
||||||
private static native StackTraceElement[] resolveTrace(Object trace);
|
static native StackTraceElement[] resolveTrace(Object trace);
|
||||||
|
|
||||||
private StackTraceElement[] resolveTrace() {
|
private StackTraceElement[] resolveTrace() {
|
||||||
if (! (trace instanceof StackTraceElement[])) {
|
if (! (trace instanceof StackTraceElement[])) {
|
||||||
|
@ -47,6 +47,19 @@ search(Thread* t, jstring name, object (*op)(Thread*, object),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
enumerateThreads(Thread* t, Thread* x, object array, unsigned* index,
|
||||||
|
unsigned limit)
|
||||||
|
{
|
||||||
|
if (*index < limit) {
|
||||||
|
set(t, array, ArrayBody + (*index * BytesPerWord), x->javaThread);
|
||||||
|
|
||||||
|
if (x->peer) enumerateThreads(t, x->peer, array, index, limit);
|
||||||
|
|
||||||
|
if (x->child) enumerateThreads(t, x->child, array, index, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern "C" JNIEXPORT jstring JNICALL
|
extern "C" JNIEXPORT jstring JNICALL
|
||||||
@ -697,6 +710,36 @@ Java_java_lang_Thread_interrupt(Thread* t, jclass, jlong peer)
|
|||||||
interrupt(t, reinterpret_cast<Thread*>(peer));
|
interrupt(t, reinterpret_cast<Thread*>(peer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jobject JNICALL
|
||||||
|
Java_java_lang_Thread_getTrace(Thread* t, jclass, jlong peer)
|
||||||
|
{
|
||||||
|
if (reinterpret_cast<Thread*>(peer) == t) {
|
||||||
|
return makeLocalReference(t, makeTrace(t));
|
||||||
|
} else {
|
||||||
|
return makeLocalReference
|
||||||
|
(t, t->m->processor->getStackTrace(t, reinterpret_cast<Thread*>(peer)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
|
Java_java_lang_Thread_activeCount(Thread* t, jclass)
|
||||||
|
{
|
||||||
|
return t->m->liveCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
|
Java_java_lang_Thread_enumerate(Thread* t, jclass, jobjectArray array)
|
||||||
|
{
|
||||||
|
ACQUIRE_RAW(t, t->m->stateLock);
|
||||||
|
|
||||||
|
ENTER(t, Thread::ActiveState);
|
||||||
|
|
||||||
|
unsigned count = min(t->m->liveCount, objectArrayLength(t, *array));
|
||||||
|
unsigned index = 0;
|
||||||
|
enumerateThreads(t, t->m->rootThread, *array, &index, count);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT jlong JNICALL
|
extern "C" JNIEXPORT jlong JNICALL
|
||||||
Java_java_net_URL_00024ResourceInputStream_open
|
Java_java_net_URL_00024ResourceInputStream_open
|
||||||
(Thread* t, jclass, jstring path)
|
(Thread* t, jclass, jstring path)
|
||||||
|
@ -3051,6 +3051,11 @@ class MyProcessor: public Processor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual object getStackTrace(Thread*, Thread*) {
|
||||||
|
// not implemented
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void dispose(vm::Thread* t) {
|
virtual void dispose(vm::Thread* t) {
|
||||||
t->m->heap->free(t, sizeof(Thread), false);
|
t->m->heap->free(t, sizeof(Thread), false);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,9 @@ class Processor {
|
|||||||
virtual void
|
virtual void
|
||||||
dispose() = 0;
|
dispose() = 0;
|
||||||
|
|
||||||
|
virtual object
|
||||||
|
getStackTrace(Thread* t, Thread* target) = 0;
|
||||||
|
|
||||||
object
|
object
|
||||||
invoke(Thread* t, object method, object this_, ...)
|
invoke(Thread* t, object method, object this_, ...)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user