diff options
author | Mathieu Chartier <mathieuc@google.com> | 2015-01-08 18:54:45 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-01-08 18:54:46 +0000 |
commit | 313c8a167be1022ec72d33897eb944fa61b319b3 (patch) | |
tree | e6c073696b4ec7abbd5ae11fa637c3a7caa37523 | |
parent | c06c1d60ed88fc33574169264a1e7d983538db79 (diff) | |
parent | 3e0acf673ce1fbb3932d288d7b52a6dc551a920f (diff) | |
download | art-313c8a167be1022ec72d33897eb944fa61b319b3.zip art-313c8a167be1022ec72d33897eb944fa61b319b3.tar.gz art-313c8a167be1022ec72d33897eb944fa61b319b3.tar.bz2 |
Merge "Add VerifyObject to StackHandleScope::SetReference"
-rw-r--r-- | compiler/jni/quick/arm/calling_convention_arm.cc | 1 | ||||
-rw-r--r-- | compiler/jni/quick/arm64/calling_convention_arm64.cc | 1 | ||||
-rw-r--r-- | compiler/jni/quick/mips/calling_convention_mips.cc | 1 | ||||
-rw-r--r-- | compiler/jni/quick/x86/calling_convention_x86.cc | 1 | ||||
-rw-r--r-- | compiler/jni/quick/x86_64/calling_convention_x86_64.cc | 1 | ||||
-rw-r--r-- | runtime/handle_scope-inl.h | 66 | ||||
-rw-r--r-- | runtime/handle_scope.h | 62 | ||||
-rw-r--r-- | runtime/mirror/array-inl.h | 1 |
8 files changed, 83 insertions, 51 deletions
diff --git a/compiler/jni/quick/arm/calling_convention_arm.cc b/compiler/jni/quick/arm/calling_convention_arm.cc index 769cd4c..a3323e1 100644 --- a/compiler/jni/quick/arm/calling_convention_arm.cc +++ b/compiler/jni/quick/arm/calling_convention_arm.cc @@ -16,6 +16,7 @@ #include "base/logging.h" #include "calling_convention_arm.h" +#include "handle_scope-inl.h" #include "utils/arm/managed_register_arm.h" namespace art { diff --git a/compiler/jni/quick/arm64/calling_convention_arm64.cc b/compiler/jni/quick/arm64/calling_convention_arm64.cc index 29763a2..b9c8178 100644 --- a/compiler/jni/quick/arm64/calling_convention_arm64.cc +++ b/compiler/jni/quick/arm64/calling_convention_arm64.cc @@ -16,6 +16,7 @@ #include "base/logging.h" #include "calling_convention_arm64.h" +#include "handle_scope-inl.h" #include "utils/arm64/managed_register_arm64.h" namespace art { diff --git a/compiler/jni/quick/mips/calling_convention_mips.cc b/compiler/jni/quick/mips/calling_convention_mips.cc index f7a7be7..aefbf06 100644 --- a/compiler/jni/quick/mips/calling_convention_mips.cc +++ b/compiler/jni/quick/mips/calling_convention_mips.cc @@ -17,6 +17,7 @@ #include "calling_convention_mips.h" #include "base/logging.h" +#include "handle_scope-inl.h" #include "utils/mips/managed_register_mips.h" namespace art { diff --git a/compiler/jni/quick/x86/calling_convention_x86.cc b/compiler/jni/quick/x86/calling_convention_x86.cc index 9bf7d0f..a5686e1 100644 --- a/compiler/jni/quick/x86/calling_convention_x86.cc +++ b/compiler/jni/quick/x86/calling_convention_x86.cc @@ -17,6 +17,7 @@ #include "calling_convention_x86.h" #include "base/logging.h" +#include "handle_scope-inl.h" #include "utils/x86/managed_register_x86.h" #include "utils.h" diff --git a/compiler/jni/quick/x86_64/calling_convention_x86_64.cc b/compiler/jni/quick/x86_64/calling_convention_x86_64.cc index a100552..bbdf1fe 100644 --- a/compiler/jni/quick/x86_64/calling_convention_x86_64.cc +++ b/compiler/jni/quick/x86_64/calling_convention_x86_64.cc @@ -17,6 +17,7 @@ #include "calling_convention_x86_64.h" #include "base/logging.h" +#include "handle_scope-inl.h" #include "utils/x86_64/managed_register_x86_64.h" #include "utils.h" diff --git a/runtime/handle_scope-inl.h b/runtime/handle_scope-inl.h index 9ddaf61..421a413 100644 --- a/runtime/handle_scope-inl.h +++ b/runtime/handle_scope-inl.h @@ -21,6 +21,7 @@ #include "handle.h" #include "thread.h" +#include "verify_object-inl.h" namespace art { @@ -42,6 +43,71 @@ inline StackHandleScope<kNumReferences>::~StackHandleScope() { DCHECK_EQ(top_handle_scope, this); } +inline size_t HandleScope::SizeOf(uint32_t num_references) { + size_t header_size = sizeof(HandleScope); + size_t data_size = sizeof(StackReference<mirror::Object>) * num_references; + return header_size + data_size; +} + +inline size_t HandleScope::SizeOf(size_t pointer_size, uint32_t num_references) { + // Assume that the layout is packed. + size_t header_size = pointer_size + sizeof(number_of_references_); + size_t data_size = sizeof(StackReference<mirror::Object>) * num_references; + return header_size + data_size; +} + +inline mirror::Object* HandleScope::GetReference(size_t i) const { + DCHECK_LT(i, number_of_references_); + return GetReferences()[i].AsMirrorPtr(); +} + +inline Handle<mirror::Object> HandleScope::GetHandle(size_t i) { + DCHECK_LT(i, number_of_references_); + return Handle<mirror::Object>(&GetReferences()[i]); +} + +inline MutableHandle<mirror::Object> HandleScope::GetMutableHandle(size_t i) { + DCHECK_LT(i, number_of_references_); + return MutableHandle<mirror::Object>(&GetReferences()[i]); +} + +inline void HandleScope::SetReference(size_t i, mirror::Object* object) { + DCHECK_LT(i, number_of_references_); + GetReferences()[i].Assign(object); +} + +inline bool HandleScope::Contains(StackReference<mirror::Object>* handle_scope_entry) const { + // A HandleScope should always contain something. One created by the + // 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 &GetReferences()[0] <= handle_scope_entry && + handle_scope_entry <= &GetReferences()[number_of_references_ - 1]; +} + +template<size_t kNumReferences> template<class T> +inline MutableHandle<T> StackHandleScope<kNumReferences>::NewHandle(T* object) { + SetReference(pos_, object); + MutableHandle<T> h(GetHandle<T>(pos_)); + pos_++; + return h; +} + +template<size_t kNumReferences> template<class T> +inline HandleWrapper<T> StackHandleScope<kNumReferences>::NewHandleWrapper(T** object) { + SetReference(pos_, *object); + MutableHandle<T> h(GetHandle<T>(pos_)); + pos_++; + return HandleWrapper<T>(object, h); +} + +template<size_t kNumReferences> +inline void StackHandleScope<kNumReferences>::SetReference(size_t i, mirror::Object* object) { + DCHECK_LT(i, kNumReferences); + VerifyObject(object); + GetReferences()[i].Assign(object); +} + } // namespace art #endif // ART_RUNTIME_HANDLE_SCOPE_INL_H_ diff --git a/runtime/handle_scope.h b/runtime/handle_scope.h index 2c4f0f9..782bbea 100644 --- a/runtime/handle_scope.h +++ b/runtime/handle_scope.h @@ -22,6 +22,7 @@ #include "handle.h" #include "stack.h" #include "utils.h" +#include "verify_object.h" namespace art { namespace mirror { @@ -47,19 +48,10 @@ class PACKED(4) HandleScope { // takes the pointer size explicitly so that at compile time we can cross-compile correctly. // Returns the size of a HandleScope containing num_references handles. - static size_t SizeOf(uint32_t num_references) { - size_t header_size = sizeof(HandleScope); - size_t data_size = sizeof(StackReference<mirror::Object>) * num_references; - return header_size + data_size; - } + static size_t SizeOf(uint32_t num_references); // Returns the size of a HandleScope containing num_references handles. - static size_t SizeOf(size_t pointer_size, uint32_t num_references) { - // Assume that the layout is packed. - size_t header_size = pointer_size + sizeof(number_of_references_); - size_t data_size = sizeof(StackReference<mirror::Object>) * num_references; - return header_size + data_size; - } + static size_t SizeOf(size_t pointer_size, uint32_t num_references); // Link to previous HandleScope or null. HandleScope* GetLink() const { @@ -67,37 +59,18 @@ class PACKED(4) HandleScope { } ALWAYS_INLINE mirror::Object* GetReference(size_t i) const - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK_LT(i, number_of_references_); - return GetReferences()[i].AsMirrorPtr(); - } + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); ALWAYS_INLINE Handle<mirror::Object> GetHandle(size_t i) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK_LT(i, number_of_references_); - return Handle<mirror::Object>(&GetReferences()[i]); - } + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); ALWAYS_INLINE MutableHandle<mirror::Object> GetMutableHandle(size_t i) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK_LT(i, number_of_references_); - return MutableHandle<mirror::Object>(&GetReferences()[i]); - } + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); ALWAYS_INLINE void SetReference(size_t i, mirror::Object* object) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK_LT(i, number_of_references_); - GetReferences()[i].Assign(object); - } + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - bool Contains(StackReference<mirror::Object>* handle_scope_entry) const { - // A HandleScope should always contain something. One created by the - // 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 &GetReferences()[0] <= handle_scope_entry && - handle_scope_entry <= &GetReferences()[number_of_references_ - 1]; - } + ALWAYS_INLINE bool Contains(StackReference<mirror::Object>* handle_scope_entry) const; // Offset of link within HandleScope, used by generated code. static size_t LinkOffset(size_t pointer_size ATTRIBUTE_UNUSED) { @@ -174,27 +147,14 @@ class PACKED(4) StackHandleScope FINAL : public HandleScope { ALWAYS_INLINE ~StackHandleScope(); template<class T> - ALWAYS_INLINE MutableHandle<T> NewHandle(T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - SetReference(pos_, object); - MutableHandle<T> h(GetHandle<T>(pos_)); - pos_++; - return h; - } + ALWAYS_INLINE MutableHandle<T> NewHandle(T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<class T> ALWAYS_INLINE HandleWrapper<T> NewHandleWrapper(T** object) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - SetReference(pos_, *object); - MutableHandle<T> h(GetHandle<T>(pos_)); - pos_++; - return HandleWrapper<T>(object, h); - } + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); ALWAYS_INLINE void SetReference(size_t i, mirror::Object* object) - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK_LT(i, kNumReferences); - GetReferences()[i].Assign(object); - } + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); private: template<class T> diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h index 13f881d..4dddd38 100644 --- a/runtime/mirror/array-inl.h +++ b/runtime/mirror/array-inl.h @@ -19,6 +19,7 @@ #include "array.h" +#include "base/stringprintf.h" #include "class.h" #include "gc/heap-inl.h" #include "thread.h" |