Don't update listeners / instrumentation levels when shutting down
When a plugin is unloaded, JVMTI unregisters listeners and updates
instrumentation level to remove any instrumentation added for jvmti.
However when we unload the plugin as a part of runtime shutdown it
is not always safe to update instrumentation level or update runtime
callbacks. Several of these require a GC critical section and a suspend
all scope. When we are unloading a plugin due to a shutdown GC has
already stopped and requesting a GC critical section is unsafe. So this
CL just returns early if we are unloading the plugin as a part of the
shutdown.
Test: art/test.py
Change-Id: Ieb4d57926ab007776e9110da5f3fd4ae518186d4
diff --git a/openjdkjvmti/OpenjdkJvmTi.cc b/openjdkjvmti/OpenjdkJvmTi.cc
index d7db3d2..276b3a8 100644
--- a/openjdkjvmti/OpenjdkJvmTi.cc
+++ b/openjdkjvmti/OpenjdkJvmTi.cc
@@ -1475,6 +1475,14 @@
}
extern "C" bool ArtPlugin_Deinitialize() {
+ // When runtime is shutting down, it is not necessary to unregister callbacks or update
+ // instrumentation levels. Removing callbacks require a GC critical section in some cases and
+ // when runtime is shutting down we already stop GC and hence it is not safe to request to
+ // enter a GC critical section.
+ if (art::Runtime::Current()->IsShuttingDown(art::Thread::Current())) {
+ return true;
+ }
+
gEventHandler->Shutdown();
gDeoptManager->Shutdown();
PhaseUtil::Unregister();