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/array.h b/runtime/mirror/array.h
index 6588b57..7af88d6 100644
--- a/runtime/mirror/array.h
+++ b/runtime/mirror/array.h
@@ -17,10 +17,10 @@
#ifndef ART_RUNTIME_MIRROR_ARRAY_H_
#define ART_RUNTIME_MIRROR_ARRAY_H_
+#include "gc_root.h"
#include "gc/allocator_type.h"
#include "object.h"
#include "object_callbacks.h"
-#include "read_barrier.h"
namespace art {
@@ -159,27 +159,26 @@
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
static void SetArrayClass(Class* array_class) {
- CHECK(array_class_ == nullptr);
+ CHECK(array_class_.IsNull());
CHECK(array_class != nullptr);
- array_class_ = array_class;
+ array_class_ = GcRoot<Class>(array_class);
}
static Class* GetArrayClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- DCHECK(array_class_ != nullptr);
- return ReadBarrier::BarrierForRoot<mirror::Class, kWithReadBarrier>(
- &array_class_);
+ DCHECK(!array_class_.IsNull());
+ return array_class_.Read();
}
static void ResetArrayClass() {
- CHECK(array_class_ != nullptr);
- array_class_ = nullptr;
+ CHECK(!array_class_.IsNull());
+ array_class_ = GcRoot<Class>(nullptr);
}
static void VisitRoots(RootCallback* callback, void* arg)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
private:
- static Class* array_class_;
+ static GcRoot<Class> array_class_;
DISALLOW_IMPLICIT_CONSTRUCTORS(PrimitiveArray);
};