From 9ef78b59da51080882e47505896b420977fd79ae Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 25 Sep 2014 17:03:12 -0700 Subject: Fix broken runtime SetStatsEnabled logic Previously, Runtime::SetStatsEnabled wouldn't take stats_enabled_ into account when deciding whether or not to increment / decrement teh stats enabled counter. This resulted in counter underflows and other errors which caused some CTS tests to fail. Also added some locking to prevent race conditions. Bug: 17360878 (cherry picked from commit a98ffd745bbecb2e84a492194950c0b94966546b) Change-Id: I21d241a58d35bd6a607aa2305c6da81720bd0886 --- runtime/instrumentation.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'runtime/instrumentation.h') diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h index 3c1c756..3017bf6 100644 --- a/runtime/instrumentation.h +++ b/runtime/instrumentation.h @@ -182,9 +182,13 @@ class Instrumentation { return interpreter_handler_table_; } - void InstrumentQuickAllocEntryPoints(bool suspended) + void InstrumentQuickAllocEntryPoints() LOCKS_EXCLUDED(Locks::instrument_entrypoints_lock_); + void UninstrumentQuickAllocEntryPoints() LOCKS_EXCLUDED(Locks::instrument_entrypoints_lock_); + void InstrumentQuickAllocEntryPointsLocked() + EXCLUSIVE_LOCKS_REQUIRED(Locks::instrument_entrypoints_lock_) LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::runtime_shutdown_lock_); - void UninstrumentQuickAllocEntryPoints(bool suspended) + void UninstrumentQuickAllocEntryPointsLocked() + EXCLUSIVE_LOCKS_REQUIRED(Locks::instrument_entrypoints_lock_) LOCKS_EXCLUDED(Locks::thread_list_lock_, Locks::runtime_shutdown_lock_); void ResetQuickAllocEntryPoints() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_); @@ -350,7 +354,7 @@ class Instrumentation { // No thread safety analysis to get around SetQuickAllocEntryPointsInstrumented requiring // exclusive access to mutator lock which you can't get if the runtime isn't started. - void SetEntrypointsInstrumented(bool instrumented, bool suspended) NO_THREAD_SAFETY_ANALYSIS; + void SetEntrypointsInstrumented(bool instrumented) NO_THREAD_SAFETY_ANALYSIS; void MethodEnterEventImpl(Thread* thread, mirror::Object* this_object, mirror::ArtMethod* method, uint32_t dex_pc) const @@ -455,8 +459,8 @@ class Instrumentation { InterpreterHandlerTable interpreter_handler_table_ GUARDED_BY(Locks::mutator_lock_); // Greater than 0 if quick alloc entry points instrumented. - // TODO: The access and changes to this is racy and should be guarded by a lock. - AtomicInteger quick_alloc_entry_points_instrumentation_counter_; + size_t quick_alloc_entry_points_instrumentation_counter_ + GUARDED_BY(Locks::instrument_entrypoints_lock_); DISALLOW_COPY_AND_ASSIGN(Instrumentation); }; -- cgit v1.1