Merge "Remove 1.3s "Waiting for Debugger" delay" am: 7a949c3bcd am: d79072f109 am: d6da5a269a

Original change: https://android-review.googlesource.com/c/platform/external/oj-libjdwp/+/2305596

Change-Id: I897feb296882ccd61fafb7628c66705f36e82a21
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/share/back/vmDebug.c b/src/share/back/vmDebug.c
index 4b51ee2..010cb8a 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 @@
     return isDebuggerConnected();
 }
 
+static void JNICALL
+VMDebug_suspendAllAndSendVmStart(JNIEnv* env, jclass klass)
+{
+    jthread currentThread;
+    JVMTI_FUNC_PTR(gdata->jvmti, GetCurrentThread)(gdata->jvmti, &currentThread);
+    eventHelper_reportVMInit(getEnv(), 0, currentThread, JDWP_SUSPEND_POLICY(ALL));
+}
+
 static jboolean JNICALL
 VMDebug_isDebuggingEnabled(JNIEnv* env, jclass klass)
 {
@@ -115,9 +125,9 @@
             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 @@
         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,