diff options
author | Fabien Sanglard <sanglardf@google.com> | 2022-11-16 17:20:41 -0800 |
---|---|---|
committer | Fabien Sanglard <sanglardf@google.com> | 2022-12-02 19:11:28 +0000 |
commit | 1180666a3dac61b7a31c93e54243a82d806e5f6f (patch) | |
tree | 0a420535e388766cabdf6b0d46e00c94867e6bd5 | |
parent | 19ecab6e21f4fbafff69797c2094c3fa5895749d (diff) | |
download | oj-libjdwp-1180666a3dac61b7a31c93e54243a82d806e5f6f.tar.gz |
Remove 1.3s "Waiting for Debugger" delay
Remove arbitrary loop when a debugged app starts. Instead for waiting
for 1.3 seconds, we instruct oj-jdwplib to suspendfor all the threads
and sent VM_START. We continue as soon as the debugger sends ResumeAll.
Design doc: go/waitingfordebugger
Test: Manually tested against Android Studio and jdb
Bug: 261096302
Change-Id: I8850668fe306b14ba9979d1baa00b5be1d2cb60e
-rw-r--r-- | src/share/back/vmDebug.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/share/back/vmDebug.c b/src/share/back/vmDebug.c index 4b51ee295..010cb8a3b 100644 --- a/src/share/back/vmDebug.c +++ b/src/share/back/vmDebug.c @@ -31,6 +31,8 @@ #include "debugLoop.h" #include "transport.h" #include "util.h" +#include "eventHelper.h" +#include "threadControl.h" static _Atomic(jlong) lastDebuggerActivity = ATOMIC_VAR_INIT(0LL); static _Atomic(jboolean) hasSeenDebuggerActivity = ATOMIC_VAR_INIT(JNI_FALSE); @@ -70,6 +72,14 @@ VMDebug_isDebuggerConnected(JNIEnv* env, jclass klass) return isDebuggerConnected(); } +static void JNICALL +VMDebug_suspendAllAndSendVmStart(JNIEnv* env, jclass klass) +{ + jthread currentThread; + JVMTI_FUNC_PTR(gdata->jvmti, GetCurrentThread)(gdata->jvmti, ¤tThread); + eventHelper_reportVMInit(getEnv(), 0, currentThread, JDWP_SUSPEND_POLICY(ALL)); +} + static jboolean JNICALL VMDebug_isDebuggingEnabled(JNIEnv* env, jclass klass) { @@ -115,9 +125,9 @@ vmDebug_initalize(JNIEnv* env) goto finish; } - JNINativeMethod methods[3]; + JNINativeMethod methods[4]; - // Take over the implementation of these three functions. + // Take over the implementation of these functions. methods[0].name = "lastDebuggerActivity"; methods[0].signature = "()J"; methods[0].fnPtr = (void*)VMDebug_lastDebuggerActivity; @@ -130,6 +140,10 @@ vmDebug_initalize(JNIEnv* env) methods[2].signature = "()Z"; methods[2].fnPtr = (void*)VMDebug_isDebuggerConnected; + methods[3].name = "suspendAllAndSendVmStart"; + methods[3].signature = "()V"; + methods[3].fnPtr = (void*)VMDebug_suspendAllAndSendVmStart; + jint res = JNI_FUNC_PTR(env,RegisterNatives)(env, vmdebug_class, methods, |