Add GcRoot to clean up and enforce read barriers.
Introduce a value-type wrapper around Object* for GC roots so that 1)
we won't have to directly add the read barrier code in many places and
2) we can avoid accidentally bypassing/missing read barriers on GC
roots (the GcRoot interface ensures that the read barrier is executed
on a read).
The jdwp test passed.
Bug: 12687968
Change-Id: Ib167c7c325b3c7e3900133578815f04d219972a1
diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc
index 5c57dce..e81e431 100644
--- a/runtime/mirror/string.cc
+++ b/runtime/mirror/string.cc
@@ -31,7 +31,7 @@
namespace mirror {
// TODO: get global references for these
-Class* String::java_lang_String_ = NULL;
+GcRoot<Class> String::java_lang_String_;
int32_t String::FastIndexOf(int32_t ch, int32_t start) {
int32_t count = GetLength();
@@ -52,14 +52,14 @@
}
void String::SetClass(Class* java_lang_String) {
- CHECK(java_lang_String_ == NULL);
+ CHECK(java_lang_String_.IsNull());
CHECK(java_lang_String != NULL);
- java_lang_String_ = java_lang_String;
+ java_lang_String_ = GcRoot<Class>(java_lang_String);
}
void String::ResetClass() {
- CHECK(java_lang_String_ != NULL);
- java_lang_String_ = NULL;
+ CHECK(!java_lang_String_.IsNull());
+ java_lang_String_ = GcRoot<Class>(nullptr);
}
int32_t String::GetHashCode() {
@@ -233,8 +233,8 @@
}
void String::VisitRoots(RootCallback* callback, void* arg) {
- if (java_lang_String_ != nullptr) {
- callback(reinterpret_cast<mirror::Object**>(&java_lang_String_), arg, 0, kRootStickyClass);
+ if (!java_lang_String_.IsNull()) {
+ java_lang_String_.VisitRoot(callback, arg, 0, kRootStickyClass);
}
}