Skip to content

Commit a941826

Browse files
Fix GetThreadCpuTimeWithKind
* Avoid crash if thread is not found * Ensure that thread is alive to make sure that we return -1 as soon as a thread have been joined.
1 parent 1bd583d commit a941826

File tree

1 file changed

+2
-2
lines changed
  • espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/vm

1 file changed

+2
-2
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/vm/Management.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ public long GetThreadCpuTimeWithKind(long threadId, boolean withSysTime,
925925
}
926926
StaticObject[] activeThreads = getContext().getActiveThreads();
927927
StaticObject thread = findThreadById(activeThreads, threadId);
928-
if (getThreadAccess().isVirtualThread(thread)) {
928+
if (StaticObject.isNull(thread) || getThreadAccess().isVirtualThread(thread) || !getThreadAccess().isAlive(thread)) {
929929
return -1;
930930
}
931931
Thread host = getThreadAccess().getHost(thread);
@@ -950,7 +950,7 @@ public void GetThreadCpuTimesWithKind(@JavaType(long[].class) StaticObject threa
950950
for (int i = 0; i < length; i++) {
951951
long guestId = interpreterToVM.getArrayLong(language, i, threadIds);
952952
StaticObject thread = findThreadById(activeThreads, guestId);
953-
if (getThreadAccess().isVirtualThread(thread)) {
953+
if (StaticObject.isNull(thread) || getThreadAccess().isVirtualThread(thread) || !getThreadAccess().isAlive(thread)) {
954954
continue;
955955
}
956956
Thread host = getThreadAccess().getHost(thread);

0 commit comments

Comments
 (0)