ART: Start RuntimeCallbacks
Add a central RuntimeCallbacks structure to handle certain interesting
runtime events.
In a first iteration, add ThreadLifecycleCallback with ThreadStart and
ThreadStop. Move Dbg over to ThreadLifecycleCallback.
Add a test.
Bug: 31684920
Test: m test-art-host-gtest-runtime_callbacks_test
Test: art/tools/run-jdwp-tests.sh --mode=host
Change-Id: Ie0f77739a563207bfb4f04374e72dc6935c40b4f
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc
index 9116097..edb58c4 100644
--- a/runtime/base/mutex.cc
+++ b/runtime/base/mutex.cc
@@ -61,6 +61,7 @@
Mutex* Locks::reference_queue_phantom_references_lock_ = nullptr;
Mutex* Locks::reference_queue_soft_references_lock_ = nullptr;
Mutex* Locks::reference_queue_weak_references_lock_ = nullptr;
+ReaderWriterMutex* Locks::runtime_callbacks_lock_ = nullptr;
Mutex* Locks::runtime_shutdown_lock_ = nullptr;
Mutex* Locks::cha_lock_ = nullptr;
Mutex* Locks::thread_list_lock_ = nullptr;
@@ -967,6 +968,7 @@
DCHECK(trace_lock_ != nullptr);
DCHECK(unexpected_signal_lock_ != nullptr);
DCHECK(dex_lock_ != nullptr);
+ DCHECK(runtime_callbacks_lock_ != nullptr);
} else {
// Create global locks in level order from highest lock level to lowest.
LockLevel current_lock_level = kInstrumentEntrypointsLock;
@@ -998,6 +1000,10 @@
DCHECK(runtime_shutdown_lock_ == nullptr);
runtime_shutdown_lock_ = new Mutex("runtime shutdown lock", current_lock_level);
+ UPDATE_CURRENT_LOCK_LEVEL(kRuntimeCallbacksLock);
+ DCHECK(runtime_callbacks_lock_ == nullptr);
+ runtime_callbacks_lock_ = new ReaderWriterMutex("runtime callbacks lock", current_lock_level);
+
UPDATE_CURRENT_LOCK_LEVEL(kProfilerLock);
DCHECK(profiler_lock_ == nullptr);
profiler_lock_ = new Mutex("profiler lock", current_lock_level);
diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h
index 2adeb8c..e44bdb8 100644
--- a/runtime/base/mutex.h
+++ b/runtime/base/mutex.h
@@ -111,6 +111,7 @@
kJdwpEventListLock,
kJdwpAttachLock,
kJdwpStartLock,
+ kRuntimeCallbacksLock,
kRuntimeShutdownLock,
kTraceLock,
kHeapBitmapLock,
@@ -615,8 +616,11 @@
// Guards shutdown of the runtime.
static Mutex* runtime_shutdown_lock_ ACQUIRED_AFTER(heap_bitmap_lock_);
+ // Guards accesses to runtime callback lists.
+ static ReaderWriterMutex* runtime_callbacks_lock_ ACQUIRED_AFTER(runtime_shutdown_lock_);
+
// Guards background profiler global state.
- static Mutex* profiler_lock_ ACQUIRED_AFTER(runtime_shutdown_lock_);
+ static Mutex* profiler_lock_ ACQUIRED_AFTER(runtime_callbacks_lock_);
// Guards trace (ie traceview) requests.
static Mutex* trace_lock_ ACQUIRED_AFTER(profiler_lock_);