|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | #include <string.h> |
| 25 | +#include <atomic> |
25 | 26 | #include "jvmti.h" |
26 | 27 |
|
27 | 28 | extern "C" { |
28 | 29 |
|
29 | 30 | static jvmtiEnv* jvmti = NULL; |
30 | 31 | static jthread* threads = NULL; |
31 | 32 | static jsize threads_count = 0; |
| 33 | +static std::atomic<bool> is_exited_from_suspend; |
32 | 34 |
|
33 | 35 | #define LOG(...) \ |
34 | 36 | do { \ |
@@ -74,6 +76,7 @@ Java_ThreadToSuspend_suspendTestedThreads(JNIEnv *jni, jclass cls) { |
74 | 76 |
|
75 | 77 | LOG("suspendTestedThreads: before JVMTI SuspendThreadList"); |
76 | 78 | err = jvmti->SuspendThreadList(threads_count, threads, results); |
| 79 | + is_exited_from_suspend.store(true); |
77 | 80 | check_jvmti_status(jni, err, "suspendTestedThreads: error in JVMTI SuspendThreadList"); |
78 | 81 |
|
79 | 82 | LOG("suspendTestedThreads: check and print SuspendThreadList results:"); |
@@ -102,6 +105,10 @@ Java_SuspendWithCurrentThread_checkTestedThreadsSuspended(JNIEnv *jni, jclass cl |
102 | 105 | return JNI_FALSE; |
103 | 106 | } |
104 | 107 | } |
| 108 | + if (is_exited_from_suspend.load()) { |
| 109 | + LOG("Thread didn't stop in self suspend."); |
| 110 | + return JNI_FALSE; |
| 111 | + } |
105 | 112 | LOG("checkTestedThreadsSuspended: finished\n"); |
106 | 113 | return JNI_TRUE; |
107 | 114 | } |
@@ -155,7 +162,7 @@ Java_SuspendWithCurrentThread_releaseTestedThreadsInfo(JNIEnv *jni, jclass cls) |
155 | 162 | JNIEXPORT jint JNICALL |
156 | 163 | Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) { |
157 | 164 | LOG("\nAgent_OnLoad started"); |
158 | | - |
| 165 | + is_exited_from_suspend.store(false); |
159 | 166 | // create JVMTI environment |
160 | 167 | if (jvm->GetEnv((void **) (&jvmti), JVMTI_VERSION) != JNI_OK) { |
161 | 168 | return JNI_ERR; |
|
0 commit comments