Guard entrypoint changing by runtime shutdown lock.
There was a race when we changed the allocation entrypoints where a
new thread would be starting (Thread::Init) and initialize to the
wrong entrypoints. Guarding allocation entrypoint changing
with the runtime shutdown lock fixes this race condition since
Thread::Init is only called with the runtime shutdown lock held.
Bug: 13250963
Change-Id: I8eb209c124b6bf17020de874e1b0083f158b8200
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 9ad21cf..89601ff 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -45,6 +45,7 @@
#include "gc/space/rosalloc_space-inl.h"
#include "gc/space/space-inl.h"
#include "gc/space/zygote_space.h"
+#include "entrypoints/quick/quick_alloc_entrypoints.h"
#include "heap-inl.h"
#include "image.h"
#include "invoke_arg_array_builder.h"
@@ -65,8 +66,6 @@
namespace art {
-extern void SetQuickAllocEntryPointsAllocator(gc::AllocatorType allocator);
-
namespace gc {
static constexpr bool kGCALotMode = false;
@@ -308,11 +307,12 @@
}
void Heap::ChangeAllocator(AllocatorType allocator) {
- // These two allocators are only used internally and don't have any entrypoints.
- DCHECK_NE(allocator, kAllocatorTypeLOS);
- DCHECK_NE(allocator, kAllocatorTypeNonMoving);
if (current_allocator_ != allocator) {
+ // These two allocators are only used internally and don't have any entrypoints.
+ CHECK_NE(allocator, kAllocatorTypeLOS);
+ CHECK_NE(allocator, kAllocatorTypeNonMoving);
current_allocator_ = allocator;
+ MutexLock mu(nullptr, *Locks::runtime_shutdown_lock_);
SetQuickAllocEntryPointsAllocator(current_allocator_);
Runtime::Current()->GetInstrumentation()->ResetQuickAllocEntryPoints();
}