From e02201540a4c7aac6b9f530eb2e9de71997810b4 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Tue, 7 Feb 2017 14:59:08 -0800 Subject: [PATCH] ART: Make run-test 931 more defensive wrt/ shutdown 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 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/931-agent-thread/agent_thread.cc b/test/931-agent-thread/agent_thread.cc index 6ace4cea6..a488d9a80 100644 --- a/test/931-agent-thread/agent_thread.cc +++ b/test/931-agent-thread/agent_thread.cc @@ -15,6 +15,7 @@ */ #include +#include #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); } -- 2.11.0