@@ -398,6 +398,19 @@ static bool setImageAndSymbolPath(JNIEnv* env, jobject obj) {
398
398
return true ;
399
399
}
400
400
401
+ static HRESULT WaitForEvent (IDebugControl *ptrIDebugControl) {
402
+ HRESULT hr = ptrIDebugControl->WaitForEvent (DEBUG_WAIT_DEFAULT, INFINITE);
403
+ // see JDK-8204994: sometimes WaitForEvent fails with E_ACCESSDENIED,
404
+ // but succeeds on 2nd call.
405
+ // To minimize possible noise retry 3 times.
406
+ for (int i = 0 ; hr == E_ACCESSDENIED && i < 3 ; i++) {
407
+ // yield current thread use of a processor (short delay).
408
+ SwitchToThread ();
409
+ hr = ptrIDebugControl->WaitForEvent (DEBUG_WAIT_DEFAULT, INFINITE);
410
+ }
411
+ return hr;
412
+ }
413
+
401
414
static bool openDumpFile (JNIEnv* env, jobject obj, jstring coreFileName) {
402
415
// open the dump file
403
416
AutoJavaString coreFile (env, coreFileName);
@@ -413,7 +426,7 @@ static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
413
426
414
427
IDebugControl* ptrIDebugControl = (IDebugControl*)env->GetLongField (obj, ptrIDebugControl_ID);
415
428
CHECK_EXCEPTION_ (false );
416
- COM_VERIFY_OK_ (ptrIDebugControl-> WaitForEvent (DEBUG_WAIT_DEFAULT, INFINITE ),
429
+ COM_VERIFY_OK_ (WaitForEvent (ptrIDebugControl ),
417
430
" Windbg Error: WaitForEvent failed!" , false );
418
431
419
432
return true ;
@@ -450,7 +463,7 @@ static bool attachToProcess(JNIEnv* env, jobject obj, jint pid) {
450
463
IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField (obj,
451
464
ptrIDebugControl_ID);
452
465
CHECK_EXCEPTION_ (false );
453
- COM_VERIFY_OK_ (ptrIDebugControl-> WaitForEvent (DEBUG_WAIT_DEFAULT, INFINITE ),
466
+ COM_VERIFY_OK_ (WaitForEvent (ptrIDebugControl ),
454
467
" Windbg Error: WaitForEvent failed!" , false );
455
468
456
469
return true ;
0 commit comments