Fix race in AllocEntrypointsInstrumented
We were using the quick_alloc_entry_points_instrumentation_counter_,
this counter is updated before the threads are suspended. The
allocator could come out of a suspend point, see that threads are
supposedly still no instrumented, continue the allocation, then
suddenly quick_alloc_entry_points_instrumentation_counter_ becomes
1 and alloc_tracking_enabled_ becomes true resulting in a failing
DCHECK.
The fix is to add a boolean that is updated only when the threads
are suspended.
Bug: 27506909
(cherry picked from commit 77d993107773b7b9bd7f07ce08d0aaac1631bf84)
Change-Id: Id12983ef77c4fddb0394e4439ce0829777f1a70b
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index b107b72..a0c6bfb 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -83,7 +83,8 @@
deoptimized_methods_lock_("deoptimized methods lock"),
deoptimization_enabled_(false),
interpreter_handler_table_(kMainHandlerTable),
- quick_alloc_entry_points_instrumentation_counter_(0) {
+ quick_alloc_entry_points_instrumentation_counter_(0),
+ alloc_entrypoints_instrumented_(false) {
}
void Instrumentation::InstallStubsForClass(mirror::Class* klass) {
@@ -642,10 +643,12 @@
MutexLock mu(self, *Locks::runtime_shutdown_lock_);
SetQuickAllocEntryPointsInstrumented(instrumented);
ResetQuickAllocEntryPoints();
+ alloc_entrypoints_instrumented_ = instrumented;
} else {
MutexLock mu(self, *Locks::runtime_shutdown_lock_);
SetQuickAllocEntryPointsInstrumented(instrumented);
ResetQuickAllocEntryPoints();
+ alloc_entrypoints_instrumented_ = instrumented;
}
}