ART: Make RuntimeCallbacks unique_ptr
Reduce the transitive closure of headers on runtime.h
Test: m
Change-Id: Ib5a3632c28b08bf07773f217a7ad711c1f12af6b
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 92d1554..14918df 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -96,6 +96,7 @@
#include "object_lock.h"
#include "os.h"
#include "runtime.h"
+#include "runtime_callbacks.h"
#include "ScopedLocalRef.h"
#include "scoped_thread_state_change-inl.h"
#include "thread-inl.h"
@@ -2681,7 +2682,7 @@
// At this point the class is loaded. Publish a ClassLoad even.
// Note: this may be a temporary class. It is a listener's responsibility to handle this.
- Runtime::Current()->GetRuntimeCallbacks().ClassLoad(klass);
+ Runtime::Current()->GetRuntimeCallbacks()->ClassLoad(klass);
// Link the class (if necessary)
CHECK(!klass->IsResolved());
@@ -2723,7 +2724,7 @@
* The class has been prepared and resolved but possibly not yet verified
* at this point.
*/
- Runtime::Current()->GetRuntimeCallbacks().ClassPrepare(klass, h_new_class);
+ Runtime::Current()->GetRuntimeCallbacks()->ClassPrepare(klass, h_new_class);
// Notify native debugger of the new class and its layout.
jit::Jit::NewTypeLoadedIfUsingJit(h_new_class.Get());
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index a2b462e..5a5ed75 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -137,6 +137,7 @@
#include "jit/profile_saver.h"
#include "quick/quick_method_frame_info.h"
#include "reflection.h"
+#include "runtime_callbacks.h"
#include "runtime_options.h"
#include "ScopedLocalRef.h"
#include "scoped_thread_state_change-inl.h"
@@ -253,10 +254,12 @@
pruned_dalvik_cache_(false),
// Initially assume we perceive jank in case the process state is never updated.
process_state_(kProcessStateJankPerceptible),
- zygote_no_threads_(false) {
+ zygote_no_threads_(false),
+ cha_(nullptr) {
CheckAsmSupportOffsetsAndSizes();
std::fill(callee_save_methods_, callee_save_methods_ + arraysize(callee_save_methods_), 0u);
interpreter::CheckInterpreterAsmConstants();
+ callbacks_.reset(new RuntimeCallbacks());
}
Runtime::~Runtime() {
@@ -1100,8 +1103,8 @@
if (runtime_options.Exists(Opt::JdwpOptions)) {
Dbg::ConfigureJdwp(runtime_options.GetOrDefault(Opt::JdwpOptions));
}
- callbacks_.AddThreadLifecycleCallback(Dbg::GetThreadLifecycleCallback());
- callbacks_.AddClassLoadCallback(Dbg::GetClassLoadCallback());
+ callbacks_->AddThreadLifecycleCallback(Dbg::GetThreadLifecycleCallback());
+ callbacks_->AddClassLoadCallback(Dbg::GetClassLoadCallback());
jit_options_.reset(jit::JitOptions::CreateFromRuntimeArguments(runtime_options));
if (IsAotCompiler()) {
@@ -2255,4 +2258,8 @@
Runtime::Abort(abort_message);
}
+RuntimeCallbacks* Runtime::GetRuntimeCallbacks() {
+ return callbacks_.get();
+}
+
} // namespace art
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 17e0788..f7d6810 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -40,7 +40,6 @@
#include "offsets.h"
#include "process_state.h"
#include "quick/quick_method_frame_info.h"
-#include "runtime_callbacks.h"
#include "runtime_stats.h"
namespace art {
@@ -91,6 +90,7 @@
class OatFileManager;
class Plugin;
struct RuntimeArgumentMap;
+class RuntimeCallbacks;
class SignalCatcher;
class StackOverflowHandler;
class SuspensionHandler;
@@ -661,9 +661,7 @@
void AttachAgent(const std::string& agent_arg);
- RuntimeCallbacks& GetRuntimeCallbacks() {
- return callbacks_;
- }
+ RuntimeCallbacks* GetRuntimeCallbacks();
private:
static void InitPlatformSignalHandlers();
@@ -922,7 +920,7 @@
ClassHierarchyAnalysis* cha_;
- RuntimeCallbacks callbacks_;
+ std::unique_ptr<RuntimeCallbacks> callbacks_;
DISALLOW_COPY_AND_ASSIGN(Runtime);
};
diff --git a/runtime/runtime_callbacks_test.cc b/runtime/runtime_callbacks_test.cc
index 8cd39a0..f05794d 100644
--- a/runtime/runtime_callbacks_test.cc
+++ b/runtime/runtime_callbacks_test.cc
@@ -96,10 +96,10 @@
protected:
void AddListener() OVERRIDE REQUIRES(Locks::mutator_lock_) {
- Runtime::Current()->GetRuntimeCallbacks().AddThreadLifecycleCallback(&cb_);
+ Runtime::Current()->GetRuntimeCallbacks()->AddThreadLifecycleCallback(&cb_);
}
void RemoveListener() OVERRIDE REQUIRES(Locks::mutator_lock_) {
- Runtime::Current()->GetRuntimeCallbacks().RemoveThreadLifecycleCallback(&cb_);
+ Runtime::Current()->GetRuntimeCallbacks()->RemoveThreadLifecycleCallback(&cb_);
}
enum CallbackState {
@@ -215,10 +215,10 @@
class ClassLoadCallbackRuntimeCallbacksTest : public RuntimeCallbacksTest {
protected:
void AddListener() OVERRIDE REQUIRES(Locks::mutator_lock_) {
- Runtime::Current()->GetRuntimeCallbacks().AddClassLoadCallback(&cb_);
+ Runtime::Current()->GetRuntimeCallbacks()->AddClassLoadCallback(&cb_);
}
void RemoveListener() OVERRIDE REQUIRES(Locks::mutator_lock_) {
- Runtime::Current()->GetRuntimeCallbacks().RemoveClassLoadCallback(&cb_);
+ Runtime::Current()->GetRuntimeCallbacks()->RemoveClassLoadCallback(&cb_);
}
bool Expect(std::initializer_list<const char*> list) {
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 97c0c55..7a2999d 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -67,6 +67,7 @@
#include "quick/quick_method_frame_info.h"
#include "reflection.h"
#include "runtime.h"
+#include "runtime_callbacks.h"
#include "scoped_thread_state_change-inl.h"
#include "ScopedLocalRef.h"
#include "ScopedUtfChars.h"
@@ -432,7 +433,7 @@
ArtField* priorityField = jni::DecodeArtField(WellKnownClasses::java_lang_Thread_priority);
self->SetNativePriority(priorityField->GetInt(self->tlsPtr_.opeer));
- runtime->GetRuntimeCallbacks().ThreadStart(self);
+ runtime->GetRuntimeCallbacks()->ThreadStart(self);
// Invoke the 'run' method of our java.lang.Thread.
ObjPtr<mirror::Object> receiver = self->tlsPtr_.opeer;
@@ -794,7 +795,7 @@
{
ScopedObjectAccess soa(self);
- runtime->GetRuntimeCallbacks().ThreadStart(self);
+ runtime->GetRuntimeCallbacks()->ThreadStart(self);
}
return self;
@@ -1932,7 +1933,7 @@
}
Runtime* runtime = Runtime::Current();
if (runtime != nullptr) {
- runtime->GetRuntimeCallbacks().ThreadDeath(self);
+ runtime->GetRuntimeCallbacks()->ThreadDeath(self);
}