@@ -49,11 +49,13 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
49
49
{
50
50
RawMonitorLocker rml (jvmti, jni, monitor);
51
51
bp_sync_reached = true ;
52
- rml.wait (0 );
52
+ while (bp_sync_reached) { // guard against spurious wakeups
53
+ rml.wait (0 );
54
+ }
53
55
}
54
56
LOG (" Breakpoint: In method TestTask.B(): after sync section\n " );
55
57
56
- if (do_pop_frame != 0 ) {
58
+ if (do_pop_frame) {
57
59
err = jvmti->PopFrame (thread);
58
60
LOG (" Breakpoint: PopFrame returned code: %s (%d)\n " , TranslateError (err), err);
59
61
check_jvmti_status (jni, err, " Breakpoint: Failed in PopFrame" );
@@ -152,20 +154,25 @@ Java_PopFrameTest_popFrame(JNIEnv *jni, jclass cls, jthread thread) {
152
154
153
155
JNIEXPORT void JNICALL
154
156
Java_PopFrameTest_ensureAtBreakpoint (JNIEnv *jni, jclass cls) {
155
- bool need_stop = false ;
156
-
157
157
LOG (" Main: ensureAtBreakpoint\n " );
158
- while (!need_stop) {
159
- RawMonitorLocker rml (jvmti, jni, monitor);
160
- need_stop = bp_sync_reached;
161
- sleep_ms (1 ); // 1 millisecond
158
+ RawMonitorLocker rml (jvmti, jni, monitor);
159
+ int attempts = 0 ;
160
+ while (!bp_sync_reached) {
161
+ if (++attempts > 100 ) {
162
+ fatal (jni, " Main: ensureAtBreakpoint: waited 20 sec" );
163
+ }
164
+ LOG (" Main: ensureAtBreakpoint: waiting 200 millis\n " );
165
+ rml.wait (200 ); // 200 milliseconds
162
166
}
163
167
}
164
168
165
169
JNIEXPORT void JNICALL
166
170
Java_PopFrameTest_notifyAtBreakpoint (JNIEnv *jni, jclass cls) {
167
171
LOG (" Main: notifyAtBreakpoint\n " );
168
172
RawMonitorLocker rml (jvmti, jni, monitor);
173
+ if (!bp_sync_reached) { // better diagnosability
174
+ fatal (jni, " Main: notifyAtBreakpoint: expected: bp_sync_reached==true" );
175
+ }
169
176
bp_sync_reached = false ;
170
177
rml.notify_all ();
171
178
}
0 commit comments