Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wisp] Fix infinite loop at ThreadDump operation #84

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/share/vm/runtime/vm_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void VM_ThreadDump::doit() {
ThreadSnapshot* ts = snapshot_thread(jt, tcl);
_result->add_thread_snapshot(ts);

if (EnableCoroutine) {
if (EnableCoroutine && SafepointSynchronize::is_at_safepoint()) {
for (Coroutine* co = jt->coroutine_list()->next();
co != jt->coroutine_list(); co = co->next()) {
oop tw = com_alibaba_wisp_engine_WispTask::get_threadWrapper(co->wisp_task());
Expand Down Expand Up @@ -355,7 +355,7 @@ void VM_ThreadDump::doit() {
continue;
}

if (EnableCoroutine) {
if (EnableCoroutine && SafepointSynchronize::is_at_safepoint()) {
jlong id = java_lang_Thread::thread_id(th());
// this would traverse thread's coroutine list
JavaThread* jt = Threads::find_java_thread_from_java_tid(id);
Expand Down
2 changes: 1 addition & 1 deletion src/share/vm/services/threadService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ ThreadsListEnumerator::ThreadsListEnumerator(Thread* cur_thread,
_threads_array->append(h);
}

if (EnableCoroutine) {
if (EnableCoroutine && SafepointSynchronize::is_at_safepoint()) {
for (Coroutine* co = jt->coroutine_list()->next(); co != jt->coroutine_list(); co = co->next()) {
if (!ThreadsListEnumerator::skipThread(co->thread(), include_jvmti_agent_threads, include_jni_attaching_threads)) {
oop tw = com_alibaba_wisp_engine_WispTask::get_threadWrapper(co->wisp_task());
Expand Down
24 changes: 23 additions & 1 deletion test/runtime/coroutine/WispThreadMXBeanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.stream.LongStream;
import java.util.stream.Stream;


import com.oracle.java.testlibrary.*;
import static com.oracle.java.testlibrary.Asserts.*;

Expand All @@ -31,6 +30,7 @@ public class WispThreadMXBeanTest {

public static void main(String[] args) throws Exception {
getStack();
getThreadInfo();
}

private static void getStack() throws Exception {
Expand All @@ -51,4 +51,26 @@ private static void getStack() throws Exception {

done = true;
}

private static void getThreadInfo() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
Thread thread = new Thread(() -> {
latch.countDown();
while (true) {
try {
Thread.sleep(20);
} catch (InterruptedException e) {
}
}
});
thread.start();

latch.await();
ThreadInfo[] infos = mbean.getThreadInfo(new long[]{thread.getId()}, 0);
StackTraceElement[] stack1 = thread.getStackTrace();
if (infos.length > 0) {
StackTraceElement[] stack2 = infos[0].getStackTrace();
assertTrue(Arrays.equals(stack1, stack2));
}
}
}