diff options
-rw-r--r-- | runtime/class_linker-inl.h | 2 | ||||
-rw-r--r-- | runtime/handle_scope-inl.h | 3 | ||||
-rw-r--r-- | runtime/handle_scope.h | 31 | ||||
-rw-r--r-- | runtime/mirror/dex_cache-inl.h | 2 |
4 files changed, 30 insertions, 8 deletions
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h index 9d8888c..f745088 100644 --- a/runtime/class_linker-inl.h +++ b/runtime/class_linker-inl.h @@ -20,7 +20,7 @@ #include "class_linker.h" #include "mirror/art_field.h" #include "mirror/class_loader.h" -#include "mirror/dex_cache.h" +#include "mirror/dex_cache-inl.h" #include "mirror/iftable.h" #include "mirror/object_array.h" #include "object_utils.h" diff --git a/runtime/handle_scope-inl.h b/runtime/handle_scope-inl.h index 634f2be..62c7614 100644 --- a/runtime/handle_scope-inl.h +++ b/runtime/handle_scope-inl.h @@ -28,8 +28,7 @@ template<size_t kNumReferences> inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self) : HandleScope(kNumReferences), self_(self), pos_(0) { // TODO: Figure out how to use a compile assert. - DCHECK_EQ(OFFSETOF_MEMBER(HandleScope, references_), - OFFSETOF_MEMBER(StackHandleScope<1>, references_storage_)); + DCHECK_EQ(&references_[0], &references_storage_[0]); for (size_t i = 0; i < kNumReferences; ++i) { SetReference(i, nullptr); } diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h index 8ff7086..629e4ec 100644 --- a/runtime/handle_scope.h +++ b/runtime/handle_scope.h @@ -31,7 +31,7 @@ class Thread; // HandleScopes can be allocated within the bridge frame between managed and native code backed by // stack storage or manually allocated in native. -class HandleScope { +class PACKED(4) HandleScope { public: ~HandleScope() {} @@ -46,7 +46,7 @@ class HandleScope { // Returns the size of a HandleScope containing num_references handles. static size_t SizeOf(uint32_t num_references) { - size_t header_size = OFFSETOF_MEMBER(HandleScope, references_); + size_t header_size = sizeof(HandleScope); size_t data_size = sizeof(StackReference<mirror::Object>) * num_references; return header_size + data_size; } @@ -98,8 +98,8 @@ class HandleScope { // jni_compiler should have a jobject/jclass as a native method is // passed in a this pointer or a class DCHECK_GT(number_of_references_, 0U); - return ((&references_[0] <= handle_scope_entry) - && (handle_scope_entry <= (&references_[number_of_references_ - 1]))); + return &references_[0] <= handle_scope_entry && + handle_scope_entry <= &references_[number_of_references_ - 1]; } // Offset of link within HandleScope, used by generated code @@ -152,11 +152,32 @@ class HandleWrapper : public Handle<T> { // Scoped handle storage of a fixed size that is usually stack allocated. template<size_t kNumReferences> -class StackHandleScope : public HandleScope { +class PACKED(4) StackHandleScope : public HandleScope { public: 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. + mirror::Object* GetReference(size_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + ALWAYS_INLINE { + DCHECK_LT(i, number_of_references_); + return references_storage_[i].AsMirrorPtr(); + } + + Handle<mirror::Object> GetHandle(size_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + ALWAYS_INLINE { + DCHECK_LT(i, number_of_references_); + return Handle<mirror::Object>(&references_storage_[i]); + } + + void SetReference(size_t i, mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) + ALWAYS_INLINE { + DCHECK_LT(i, number_of_references_); + references_storage_[i].Assign(object); + } + template<class T> Handle<T> NewHandle(T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { SetReference(pos_, object); diff --git a/runtime/mirror/dex_cache-inl.h b/runtime/mirror/dex_cache-inl.h index f59c3a2..7e40f64 100644 --- a/runtime/mirror/dex_cache-inl.h +++ b/runtime/mirror/dex_cache-inl.h @@ -19,6 +19,8 @@ #include "dex_cache.h" +#include "runtime.h" + namespace art { namespace mirror { |