Skip to content

Commit 3dc78e7

Browse files
author
Alex Menkov
committedJun 2, 2020
8204994: SA might fail to attach to process with "Windbg Error: WaitForEvent failed"
Reviewed-by: sspitsyn, cjplummer
1 parent 453f6cf commit 3dc78e7

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎src/jdk.hotspot.agent/windows/native/libsaproc/sawindbg.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,19 @@ static bool setImageAndSymbolPath(JNIEnv* env, jobject obj) {
398398
return true;
399399
}
400400

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+
401414
static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
402415
// open the dump file
403416
AutoJavaString coreFile(env, coreFileName);
@@ -413,7 +426,7 @@ static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
413426

414427
IDebugControl* ptrIDebugControl = (IDebugControl*)env->GetLongField(obj, ptrIDebugControl_ID);
415428
CHECK_EXCEPTION_(false);
416-
COM_VERIFY_OK_(ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE),
429+
COM_VERIFY_OK_(WaitForEvent(ptrIDebugControl),
417430
"Windbg Error: WaitForEvent failed!", false);
418431

419432
return true;
@@ -450,7 +463,7 @@ static bool attachToProcess(JNIEnv* env, jobject obj, jint pid) {
450463
IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
451464
ptrIDebugControl_ID);
452465
CHECK_EXCEPTION_(false);
453-
COM_VERIFY_OK_(ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE),
466+
COM_VERIFY_OK_(WaitForEvent(ptrIDebugControl),
454467
"Windbg Error: WaitForEvent failed!", false);
455468

456469
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.