summaryrefslogtreecommitdiffstats
path: root/runtime/handle_scope.h
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-10-21 15:05:36 -0700
committerIan Rogers <irogers@google.com>2014-10-21 15:45:49 -0700
commitb5cb18a116dce45fc077b3f5b94af9e521e79e8d (patch)
treed58188cb260beff312dfe4e6c32f0186cf30a591 /runtime/handle_scope.h
parent1428dce77b8b0e8ec3e3665d816678df1253fc10 (diff)
downloadandroid_art-b5cb18a116dce45fc077b3f5b94af9e521e79e8d.tar.gz
android_art-b5cb18a116dce45fc077b3f5b94af9e521e79e8d.tar.bz2
android_art-b5cb18a116dce45fc077b3f5b94af9e521e79e8d.zip
Avoid strict-aliasing problems with Handles.
Replace use of reinterpret_cast with down_cast. Bug: 18074773 Change-Id: Id42d462f2798f69a2210e5912f441c868b8b5812
Diffstat (limited to 'runtime/handle_scope.h')
-rw-r--r--runtime/handle_scope.h40
1 files changed, 16 insertions, 24 deletions
diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h
index f795e387f0..13c939fc3c 100644
--- a/runtime/handle_scope.h
+++ b/runtime/handle_scope.h
@@ -159,7 +159,7 @@ class HandleWrapper : public MutableHandle<T> {
}
private:
- T** obj_;
+ T** const obj_;
};
// Scoped handle storage of a fixed size that is usually stack allocated.
@@ -169,31 +169,10 @@ class PACKED(4) StackHandleScope FINAL : public HandleScope {
explicit StackHandleScope(Thread* self);
~StackHandleScope();
- // Currently unused, using this GetReference instead of the one in HandleScope is preferred to
- // avoid compiler optimizations incorrectly optimizing out of bound array accesses.
- // TODO: Remove this when it is un-necessary.
- ALWAYS_INLINE mirror::Object* GetReference(size_t i) const
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- DCHECK_LT(i, kNumReferences);
- return GetReferences()[i].AsMirrorPtr();
- }
-
- ALWAYS_INLINE MutableHandle<mirror::Object> GetHandle(size_t i)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- DCHECK_LT(i, kNumReferences);
- return MutableHandle<mirror::Object>(&GetReferences()[i]);
- }
-
- ALWAYS_INLINE void SetReference(size_t i, mirror::Object* object)
- SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- DCHECK_LT(i, kNumReferences);
- GetReferences()[i].Assign(object);
- }
-
template<class T>
MutableHandle<T> NewHandle(T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
SetReference(pos_, object);
- MutableHandle<T> h(GetHandle(pos_));
+ MutableHandle<T> h(GetHandle<T>(pos_));
pos_++;
return h;
}
@@ -201,12 +180,25 @@ class PACKED(4) StackHandleScope FINAL : public HandleScope {
template<class T>
HandleWrapper<T> NewHandleWrapper(T** object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
SetReference(pos_, *object);
- MutableHandle<T> h(GetHandle(pos_));
+ MutableHandle<T> h(GetHandle<T>(pos_));
pos_++;
return HandleWrapper<T>(object, h);
}
private:
+ template<class T>
+ ALWAYS_INLINE MutableHandle<T> GetHandle(size_t i)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ DCHECK_LT(i, kNumReferences);
+ return MutableHandle<T>(&GetReferences()[i]);
+ }
+
+ ALWAYS_INLINE void SetReference(size_t i, mirror::Object* object)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ DCHECK_LT(i, kNumReferences);
+ GetReferences()[i].Assign(object);
+ }
+
// Reference storage needs to be first as expected by the HandleScope layout.
StackReference<mirror::Object> storage_[kNumReferences];