diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2014-07-22 18:08:23 -0700 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2014-07-29 13:30:46 -0700 |
commit | 94f7b49578b6aaa80de8ffed230648d601393905 (patch) | |
tree | cfc69e453faefee38178ceb85378e1f0f1e17812 /runtime/mirror/class.cc | |
parent | 8df73882c60451e7f789bf9b1f3db2d7dc228640 (diff) | |
download | art-94f7b49578b6aaa80de8ffed230648d601393905.zip art-94f7b49578b6aaa80de8ffed230648d601393905.tar.gz art-94f7b49578b6aaa80de8ffed230648d601393905.tar.bz2 |
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
Diffstat (limited to 'runtime/mirror/class.cc')
-rw-r--r-- | runtime/mirror/class.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index a218b1c..f29ba73 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -36,24 +36,24 @@ namespace art { namespace mirror { -Class* Class::java_lang_Class_ = nullptr; +GcRoot<Class> Class::java_lang_Class_; void Class::SetClassClass(Class* java_lang_Class) { - CHECK(java_lang_Class_ == nullptr) - << ReadBarrier::BarrierForRoot<mirror::Class, kWithReadBarrier>(&java_lang_Class_) + CHECK(java_lang_Class_.IsNull()) + << java_lang_Class_.Read() << " " << java_lang_Class; CHECK(java_lang_Class != nullptr); - java_lang_Class_ = java_lang_Class; + java_lang_Class_ = GcRoot<Class>(java_lang_Class); } void Class::ResetClass() { - CHECK(java_lang_Class_ != nullptr); - java_lang_Class_ = nullptr; + CHECK(!java_lang_Class_.IsNull()); + java_lang_Class_ = GcRoot<Class>(nullptr); } void Class::VisitRoots(RootCallback* callback, void* arg) { - if (java_lang_Class_ != nullptr) { - callback(reinterpret_cast<mirror::Object**>(&java_lang_Class_), arg, 0, kRootStickyClass); + if (!java_lang_Class_.IsNull()) { + java_lang_Class_.VisitRoot(callback, arg, 0, kRootStickyClass); } } @@ -879,8 +879,9 @@ Class* Class::CopyOf(Thread* self, int32_t new_length) { CopyClassVisitor visitor(self, &h_this, new_length, sizeof(Class)); mirror::Object* new_class = - kMovingClasses ? heap->AllocObject<true>(self, java_lang_Class_, new_length, visitor) - : heap->AllocNonMovableObject<true>(self, java_lang_Class_, new_length, visitor); + kMovingClasses + ? heap->AllocObject<true>(self, java_lang_Class_.Read(), new_length, visitor) + : heap->AllocNonMovableObject<true>(self, java_lang_Class_.Read(), new_length, visitor); if (UNLIKELY(new_class == nullptr)) { CHECK(self->IsExceptionPending()); // Expect an OOME. return NULL; |