From 37cf51fb00bbe4bb82e713228b460cafbbf79b43 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 22 Sep 2015 11:43:46 +0100 Subject: [PATCH] ART: Fix destruction order in Runtime. Destroy arena allocators as late as possible. With https://android-review.googlesource.com/172057 , the ArenaPool was indirectly used by ClassLinker's destructor (via ~LinearAlloc) after it has already been destroyed. These allocators were being destroyed way too early anyway, they should be orderly destroyed when the unique_ptr<> members of Runtime have their destructors executed. However, due to the potential dependence on MemMap, we destroy them just before the MemMap::ShutDown(). Change-Id: Ifc3e5a24a29536d5767c82353901e2d22b13d643 --- runtime/runtime.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/runtime.cc b/runtime/runtime.cc index ccfc4bcaa..fe97394e0 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -274,9 +274,6 @@ Runtime::~Runtime() { VLOG(jit) << "Deleting jit"; jit_.reset(nullptr); } - linear_alloc_.reset(); - arena_pool_.reset(); - low_4gb_arena_pool_.reset(); // Shutdown the fault manager if it was initialized. fault_manager.Shutdown(); @@ -290,7 +287,13 @@ Runtime::~Runtime() { Thread::Shutdown(); QuasiAtomic::Shutdown(); verifier::MethodVerifier::Shutdown(); + + // Destroy allocators before shutting down the MemMap because they may use it. + linear_alloc_.reset(); + low_4gb_arena_pool_.reset(); + arena_pool_.reset(); MemMap::Shutdown(); + // TODO: acquire a static mutex on Runtime to avoid racing. CHECK(instance_ == nullptr || instance_ == this); instance_ = nullptr; -- 2.11.0