summaryrefslogtreecommitdiffstats
path: root/runtime/handle.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.h
parent1428dce77b8b0e8ec3e3665d816678df1253fc10 (diff)
downloadart-b5cb18a116dce45fc077b3f5b94af9e521e79e8d.tar.gz
art-b5cb18a116dce45fc077b3f5b94af9e521e79e8d.tar.bz2
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.h')
-rw-r--r--runtime/handle.h24
1 files changed, 12 insertions, 12 deletions
diff --git a/runtime/handle.h b/runtime/handle.h
index addb6638b6..6af3220561 100644
--- a/runtime/handle.h
+++ b/runtime/handle.h
@@ -20,6 +20,7 @@
#include "base/casts.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/value_object.h"
#include "stack.h"
namespace art {
@@ -33,7 +34,7 @@ template<class T> class Handle;
// a wrap pointer. Handles are generally allocated within HandleScopes. Handle is a super-class
// of MutableHandle and doesn't support assignment operations.
template<class T>
-class Handle {
+class Handle : public ValueObject {
public:
Handle() : reference_(nullptr) {
}
@@ -58,7 +59,7 @@ class Handle {
}
ALWAYS_INLINE T* Get() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- return reference_->AsMirrorPtr();
+ return down_cast<T*>(reference_->AsMirrorPtr());
}
ALWAYS_INLINE jobject ToJObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
@@ -70,25 +71,25 @@ class Handle {
}
protected:
- StackReference<T>* reference_;
-
template<typename S>
explicit Handle(StackReference<S>* reference)
- : reference_(reinterpret_cast<StackReference<T>*>(reference)) {
+ : reference_(reference) {
}
template<typename S>
explicit Handle(const Handle<S>& handle)
- : reference_(reinterpret_cast<StackReference<T>*>(handle.reference_)) {
+ : reference_(handle.reference_) {
}
- StackReference<T>* GetReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE {
+ StackReference<mirror::Object>* GetReference() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE {
return reference_;
}
- ALWAYS_INLINE const StackReference<T>* GetReference() const
+ ALWAYS_INLINE const StackReference<mirror::Object>* GetReference() const
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
return reference_;
}
+ StackReference<mirror::Object>* reference_;
+
private:
friend class BuildGenericJniFrameVisitor;
template<class S> friend class Handle;
@@ -121,8 +122,8 @@ class MutableHandle : public Handle<T> {
}
ALWAYS_INLINE T* Assign(T* reference) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
- StackReference<T>* ref = Handle<T>::GetReference();
- T* const old = ref->AsMirrorPtr();
+ StackReference<mirror::Object>* ref = Handle<T>::GetReference();
+ T* old = down_cast<T*>(ref->AsMirrorPtr());
ref->Assign(reference);
return old;
}
@@ -132,7 +133,6 @@ class MutableHandle : public Handle<T> {
: Handle<T>(handle) {
}
- protected:
template<typename S>
explicit MutableHandle(StackReference<S>* reference) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
: Handle<T>(reference) {
@@ -153,7 +153,7 @@ class NullHandle : public Handle<T> {
}
private:
- StackReference<T> null_ref_;
+ StackReference<mirror::Object> null_ref_;
};
} // namespace art