ART: Shut down runtime in patchoat
When in a debug build, or under sanitization, shut down the runtime
after patching an image. This avoids tripping leak checks, while
keeping regular shutdown fast (similar to dex2oat).
Bug: 37728254
Test: m SANITIZE_HOST=true test-art-host
Change-Id: I812cf0c7e60745081b3c1c0e68d4631a43783ead
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index fbb0978..e750ede 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -30,6 +30,7 @@
#include "art_field-inl.h"
#include "art_method-inl.h"
#include "base/dumpable.h"
+#include "base/memory_tool.h"
#include "base/scoped_flock.h"
#include "base/stringpiece.h"
#include "base/unix_file/fd_file.h"
@@ -142,6 +143,8 @@
LOG(ERROR) << "Unable to initialize runtime";
return false;
}
+ std::unique_ptr<Runtime> runtime(Runtime::Current());
+
// Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start,
// give it away now and then switch to a more manageable ScopedObjectAccess.
Thread::Current()->TransitionFromRunnableToSuspended(kNative);
@@ -286,6 +289,13 @@
return false;
}
}
+
+ if (!kIsDebugBuild && !(RUNNING_ON_MEMORY_TOOL && kMemoryToolDetectsLeaks)) {
+ // We want to just exit on non-debug builds, not bringing the runtime down
+ // in an orderly fashion. So release the following fields.
+ runtime.release();
+ }
+
return true;
}