Don't dlclose plugins or agents during shutdown.

We were dlclosing agents and the JVMTI plugin during shutdown but it
seems that some agents assume that their code will remain loaded even
after the Agent_OnUnload function returns. This caused segfaults
during shutdown in some situations. Since the runtime is shutting down
anyway there is not much to lose by just not unloading these agents
and the plugins they depend on.

Test: stress --cpu 60
Test: ./art/tools/run-prebuilt-libjdwp-tests.sh \
        --debug \
        --test org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_05

Bug: 67497270
Bug: 67855829

Change-Id: Ib988c0d21bd12d40f33d709e633312eb68021b38
diff --git a/runtime/plugin.cc b/runtime/plugin.cc
index 731967c..6aa0787 100644
--- a/runtime/plugin.cc
+++ b/runtime/plugin.cc
@@ -74,10 +74,8 @@
     LOG(WARNING) << this << " does not include a deinitialization function";
   }
   dlopen_handle_ = nullptr;
-  if (dlclose(handle) != 0) {
-    LOG(ERROR) << this << " failed to dlclose: " << dlerror();
-    ret = false;
-  }
+  // Don't bother to actually dlclose since we are shutting down anyway and there might be small
+  // amounts of processing still being done.
   return ret;
 }
 
diff --git a/runtime/ti/agent.cc b/runtime/ti/agent.cc
index 6ff9666..20e297c 100644
--- a/runtime/ti/agent.cc
+++ b/runtime/ti/agent.cc
@@ -113,7 +113,8 @@
     if (onunload_ != nullptr) {
       onunload_(Runtime::Current()->GetJavaVM());
     }
-    dlclose(dlopen_handle_);
+    // Don't actually dlclose since some agents assume they will never get unloaded. Since this only
+    // happens when the runtime is shutting down anyway this isn't a big deal.
     dlopen_handle_ = nullptr;
     onload_ = nullptr;
     onattach_ = nullptr;
diff --git a/tools/libjdwp_art_failures.txt b/tools/libjdwp_art_failures.txt
index bd422e9..1812177 100644
--- a/tools/libjdwp_art_failures.txt
+++ b/tools/libjdwp_art_failures.txt
@@ -71,34 +71,6 @@
            "org.apache.harmony.jpda.tests.jdwp.EventModifiers.InstanceOnlyModifierTest#testMethodExit",
            "org.apache.harmony.jpda.tests.jdwp.EventModifiers.InstanceOnlyModifierTest#testMethodExitWithReturnValue" ]
 },
-/* TODO Investigate these failures more closely */
-{
-  description: "Tests that fail when run on the chromium buildbots against the prebuilt libjdwp.so in certain configurations",
-  result: EXEC_FAILED,
-  bug: 67497270,
-  names: [
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEvents003Test#testCombinedEvents003_01",
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_01",
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_02",
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_03",
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_04",
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_05",
-    "org.apache.harmony.jpda.tests.jdwp.Events.CombinedEventsTest#testCombinedEvents_06",
-    "org.apache.harmony.jpda.tests.jdwp.Events.VMDeathTest#testVMDeathEvent",
-    "org.apache.harmony.jpda.tests.jdwp.MultiSession.ClassPrepareTest#testClassPrepare001",
-    "org.apache.harmony.jpda.tests.jdwp.MultiSession.ExceptionTest#testException001",
-    "org.apache.harmony.jpda.tests.jdwp.MultiSession.FieldAccessTest#testFieldAccess001",
-    "org.apache.harmony.jpda.tests.jdwp.MultiSession.FieldModificationTest#testFieldModification001",
-    "org.apache.harmony.jpda.tests.jdwp.MultiSession.SingleStepTest#testSingleStep001",
-    "org.apache.harmony.jpda.tests.jdwp.MultiSession.VMDeathTest#testVMDeathRequest",
-    "org.apache.harmony.jpda.tests.jdwp.ReferenceType.SignatureWithGenericTest#testSignatureWithGeneric001",
-    "org.apache.harmony.jpda.tests.jdwp.StackFrame.GetValues002Test#testGetValues005_Int2",
-    "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.SetDefaultStratumTest#testSetDefaultStratum001",
-    "org.apache.harmony.jpda.tests.jdwp.ThreadReference.StatusTest#testStatus001",
-    "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.AllClassesTest#testAllClasses002",
-    "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.AllClassesWithGenericTest#testAllClassesWithGeneric001"
-  ]
-},
 /* TODO Categorize these failures more. */
 {
   description: "Tests that fail on both ART and RI. These tests are likely incorrect",
diff --git a/tools/wrapagentproperties/wrapagentproperties.cc b/tools/wrapagentproperties/wrapagentproperties.cc
index dca6270..67d5279 100644
--- a/tools/wrapagentproperties/wrapagentproperties.cc
+++ b/tools/wrapagentproperties/wrapagentproperties.cc
@@ -45,7 +45,6 @@
 
 struct Unloader {
   AgentUnloadFunction unload;
-  void* dlclose_handle;
 };
 static std::vector<Unloader> unload_functions;
 
@@ -71,7 +70,6 @@
       std::lock_guard<std::mutex> lk(unload_mutex);
       unload_functions.push_back({
         reinterpret_cast<AgentUnloadFunction>(dlsym(dlopen_handle, kOnUnload)),
-        dlopen_handle
       });
     }
     attach = reinterpret_cast<AgentLoadFunction>(dlsym(dlopen_handle, kOnAttach));
@@ -337,7 +335,7 @@
   std::lock_guard<std::mutex> lk(unload_mutex);
   for (const Unloader& u : unload_functions) {
     u.unload(jvm);
-    dlclose(u.dlclose_handle);
+    // Don't dlclose since some agents expect to still have code loaded after this.
   }
   unload_functions.clear();
 }