OSDN Git Service

ART: Make run-test 931 more defensive wrt/ shutdown
authorAndreas Gampe <agampe@google.com>
Tue, 7 Feb 2017 22:59:08 +0000 (14:59 -0800)
committerAndreas Gampe <agampe@google.com>
Tue, 7 Feb 2017 22:59:08 +0000 (14:59 -0800)
Make the main thread loop a bit longer waiting for the agent
thread to die, so we don't unload under its feet.

Bug: 34701734
Test: m test-art-host-run-test-931-agent-thread
Change-Id: I554d72249c366b17c644f6c17c2b59fda2ab810e

test/931-agent-thread/agent_thread.cc

index 6ace4ce..a488d9a 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <inttypes.h>
+#include <sched.h>
 
 #include "barrier.h"
 #include "base/logging.h"
@@ -125,6 +126,24 @@ extern "C" JNIEXPORT void JNICALL Java_Main_testAgentThread(
 
   data.b.Wait(Thread::Current());
 
+  // Scheduling may mean that the agent thread is put to sleep. Wait until it's dead in an effort
+  // to not unload the plugin and crash.
+  for (;;) {
+    NanoSleep(1000 * 1000);
+    jint thread_state;
+    jvmtiError state_result = jvmti_env->GetThreadState(thread.get(), &thread_state);
+    if (JvmtiErrorToException(env, state_result)) {
+      return;
+    }
+    if (thread_state == 0 ||                                    // Was never alive.
+        (thread_state & JVMTI_THREAD_STATE_TERMINATED) != 0) {  // Was alive and died.
+      break;
+    }
+  }
+  // Yield and sleep a bit more, to give the plugin time to tear down the native thread structure.
+  sched_yield();
+  NanoSleep(100 * 1000 * 1000);
+
   env->DeleteGlobalRef(data.main_thread);
 }