8204994: SA might fail to attach to process with "Windbg Error: WaitForEvent failed"

Reviewed-by: sspitsyn, cjplummer
This commit is contained in:
Alex Menkov 2020-06-02 13:22:06 -07:00
parent 453f6cf4d9
commit 3dc78e76e4

View File

@ -398,6 +398,19 @@ static bool setImageAndSymbolPath(JNIEnv* env, jobject obj) {
return true;
}
static HRESULT WaitForEvent(IDebugControl *ptrIDebugControl) {
HRESULT hr = ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
// see JDK-8204994: sometimes WaitForEvent fails with E_ACCESSDENIED,
// but succeeds on 2nd call.
// To minimize possible noise retry 3 times.
for (int i = 0; hr == E_ACCESSDENIED && i < 3; i++) {
// yield current thread use of a processor (short delay).
SwitchToThread();
hr = ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
}
return hr;
}
static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
// open the dump file
AutoJavaString coreFile(env, coreFileName);
@ -413,7 +426,7 @@ static bool openDumpFile(JNIEnv* env, jobject obj, jstring coreFileName) {
IDebugControl* ptrIDebugControl = (IDebugControl*)env->GetLongField(obj, ptrIDebugControl_ID);
CHECK_EXCEPTION_(false);
COM_VERIFY_OK_(ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE),
COM_VERIFY_OK_(WaitForEvent(ptrIDebugControl),
"Windbg Error: WaitForEvent failed!", false);
return true;
@ -450,7 +463,7 @@ static bool attachToProcess(JNIEnv* env, jobject obj, jint pid) {
IDebugControl* ptrIDebugControl = (IDebugControl*) env->GetLongField(obj,
ptrIDebugControl_ID);
CHECK_EXCEPTION_(false);
COM_VERIFY_OK_(ptrIDebugControl->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE),
COM_VERIFY_OK_(WaitForEvent(ptrIDebugControl),
"Windbg Error: WaitForEvent failed!", false);
return true;