diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-05-07 15:43:14 -0700 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-05-13 14:45:54 -0700 |
commit | eb8167a4f4d27fce0530f6724ab8032610cd146b (patch) | |
tree | bcfeaf13ad78f2dd68466bbd0e20c71944f7e854 /runtime/mirror | |
parent | 6fb66a2bc4e1c0b7931101153e58714991237af7 (diff) | |
download | art-eb8167a4f4d27fce0530f6724ab8032610cd146b.tar.gz art-eb8167a4f4d27fce0530f6724ab8032610cd146b.tar.bz2 art-eb8167a4f4d27fce0530f6724ab8032610cd146b.zip |
Add Handle/HandleScope and delete SirtRef.
Delete SirtRef and replaced it with Handle. Handles are value types
which wrap around StackReference*.
Renamed StackIndirectReferenceTable to HandleScope.
Added a scoped handle wrapper which wraps around an Object** and
restores it in its destructor.
Renamed Handle::get -> Get.
Bug: 8473721
Change-Id: Idbfebd4f35af629f0f43931b7c5184b334822c7a
Diffstat (limited to 'runtime/mirror')
-rw-r--r-- | runtime/mirror/array.cc | 38 | ||||
-rw-r--r-- | runtime/mirror/array.h | 6 | ||||
-rw-r--r-- | runtime/mirror/art_field.cc | 2 | ||||
-rw-r--r-- | runtime/mirror/art_method-inl.h | 6 | ||||
-rw-r--r-- | runtime/mirror/art_method.cc | 13 | ||||
-rw-r--r-- | runtime/mirror/art_method.h | 4 | ||||
-rw-r--r-- | runtime/mirror/class.cc | 32 | ||||
-rw-r--r-- | runtime/mirror/class.h | 2 | ||||
-rw-r--r-- | runtime/mirror/dex_cache_test.cc | 9 | ||||
-rw-r--r-- | runtime/mirror/object.cc | 18 | ||||
-rw-r--r-- | runtime/mirror/object_array-inl.h | 15 | ||||
-rw-r--r-- | runtime/mirror/object_test.cc | 156 | ||||
-rw-r--r-- | runtime/mirror/stack_trace_element.cc | 18 | ||||
-rw-r--r-- | runtime/mirror/stack_trace_element.h | 12 | ||||
-rw-r--r-- | runtime/mirror/string.cc | 11 | ||||
-rw-r--r-- | runtime/mirror/string.h | 4 |
16 files changed, 184 insertions, 162 deletions
diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc index 139e2d030a..552652cd24 100644 --- a/runtime/mirror/array.cc +++ b/runtime/mirror/array.cc @@ -26,7 +26,7 @@ #include "object_array.h" #include "object_array-inl.h" #include "object_utils.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" #include "thread.h" #include "utils.h" @@ -42,22 +42,25 @@ namespace mirror { // Recursively create an array with multiple dimensions. Elements may be // Objects or primitive types. static Array* RecursiveCreateMultiArray(Thread* self, - const SirtRef<Class>& array_class, int current_dimension, - const SirtRef<mirror::IntArray>& dimensions) + const Handle<Class>& array_class, int current_dimension, + const Handle<mirror::IntArray>& dimensions) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { int32_t array_length = dimensions->Get(current_dimension); - SirtRef<Array> new_array(self, Array::Alloc<true>(self, array_class.get(), array_length, - array_class->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator())); - if (UNLIKELY(new_array.get() == nullptr)) { + StackHandleScope<1> hs(self); + Handle<Array> new_array( + hs.NewHandle( + Array::Alloc<true>(self, array_class.Get(), array_length, array_class->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator()))); + if (UNLIKELY(new_array.Get() == nullptr)) { CHECK(self->IsExceptionPending()); return nullptr; } if (current_dimension + 1 < dimensions->GetLength()) { // Create a new sub-array in every element of the array. for (int32_t i = 0; i < array_length; i++) { - SirtRef<mirror::Class> sirt_component_type(self, array_class->GetComponentType()); - Array* sub_array = RecursiveCreateMultiArray(self, sirt_component_type, + StackHandleScope<1> hs(self); + Handle<mirror::Class> h_component_type(hs.NewHandle(array_class->GetComponentType())); + Array* sub_array = RecursiveCreateMultiArray(self, h_component_type, current_dimension + 1, dimensions); if (UNLIKELY(sub_array == nullptr)) { CHECK(self->IsExceptionPending()); @@ -67,11 +70,11 @@ static Array* RecursiveCreateMultiArray(Thread* self, new_array->AsObjectArray<Array>()->Set<false, false>(i, sub_array); } } - return new_array.get(); + return new_array.Get(); } -Array* Array::CreateMultiArray(Thread* self, const SirtRef<Class>& element_class, - const SirtRef<IntArray>& dimensions) { +Array* Array::CreateMultiArray(Thread* self, const Handle<Class>& element_class, + const Handle<IntArray>& dimensions) { // Verify dimensions. // // The caller is responsible for verifying that "dimArray" is non-null @@ -90,15 +93,16 @@ Array* Array::CreateMultiArray(Thread* self, const SirtRef<Class>& element_class // Find/generate the array class. ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - SirtRef<mirror::Class> array_class(self, - class_linker->FindArrayClass(self, element_class.get())); - if (UNLIKELY(array_class.get() == nullptr)) { + StackHandleScope<1> hs(self); + Handle<mirror::Class> array_class( + hs.NewHandle(class_linker->FindArrayClass(self, element_class.Get()))); + if (UNLIKELY(array_class.Get() == nullptr)) { CHECK(self->IsExceptionPending()); return nullptr; } for (int32_t i = 1; i < dimensions->GetLength(); ++i) { - array_class.reset(class_linker->FindArrayClass(self, array_class.get())); - if (UNLIKELY(array_class.get() == nullptr)) { + array_class.Assign(class_linker->FindArrayClass(self, array_class.Get())); + if (UNLIKELY(array_class.Get() == nullptr)) { CHECK(self->IsExceptionPending()); return nullptr; } diff --git a/runtime/mirror/array.h b/runtime/mirror/array.h index eead4ebe08..238506e86d 100644 --- a/runtime/mirror/array.h +++ b/runtime/mirror/array.h @@ -23,7 +23,7 @@ namespace art { -template<class T> class SirtRef; +template<class T> class Handle; namespace mirror { @@ -38,8 +38,8 @@ class MANAGED Array : public Object { bool fill_usable = false) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static Array* CreateMultiArray(Thread* self, const SirtRef<Class>& element_class, - const SirtRef<IntArray>& dimensions) + static Array* CreateMultiArray(Thread* self, const Handle<Class>& element_class, + const Handle<IntArray>& dimensions) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags, diff --git a/runtime/mirror/art_field.cc b/runtime/mirror/art_field.cc index 8eb30f9949..86c5c3fe3b 100644 --- a/runtime/mirror/art_field.cc +++ b/runtime/mirror/art_field.cc @@ -29,7 +29,7 @@ namespace art { namespace mirror { -// TODO: get global references for these +// TODO: Get global references for these Class* ArtField::java_lang_reflect_ArtField_ = NULL; ArtField* ArtField::FromReflectedField(const ScopedObjectAccess& soa, jobject jlr_field) { diff --git a/runtime/mirror/art_method-inl.h b/runtime/mirror/art_method-inl.h index 91753df7f5..c3e2d22c9e 100644 --- a/runtime/mirror/art_method-inl.h +++ b/runtime/mirror/art_method-inl.h @@ -225,10 +225,10 @@ inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() { if (UNLIKELY(entry_point == GetQuickGenericJniTrampoline())) { // Generic JNI frame. DCHECK(IsNative()); - uint32_t sirt_refs = MethodHelper(this).GetNumberOfReferenceArgsWithoutReceiver() + 1; - size_t sirt_size = StackIndirectReferenceTable::GetAlignedSirtSize(sirt_refs); + uint32_t handle_refs = MethodHelper(this).GetNumberOfReferenceArgsWithoutReceiver() + 1; + size_t scope_size = HandleScope::GetAlignedHandleScopeSize(handle_refs); QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); - return QuickMethodFrameInfo(callee_info.FrameSizeInBytes() + sirt_size, + return QuickMethodFrameInfo(callee_info.FrameSizeInBytes() + scope_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask()); } diff --git a/runtime/mirror/art_method.cc b/runtime/mirror/art_method.cc index eef60f7b01..0632a68afa 100644 --- a/runtime/mirror/art_method.cc +++ b/runtime/mirror/art_method.cc @@ -230,14 +230,15 @@ uintptr_t ArtMethod::ToNativePc(const uint32_t dex_pc) { return 0; } -uint32_t ArtMethod::FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc, +uint32_t ArtMethod::FindCatchBlock(Handle<Class>& exception_type, uint32_t dex_pc, bool* has_no_move_exception) { MethodHelper mh(this); const DexFile::CodeItem* code_item = mh.GetCodeItem(); // Set aside the exception while we resolve its type. Thread* self = Thread::Current(); ThrowLocation throw_location; - SirtRef<mirror::Throwable> exception(self, self->GetException(&throw_location)); + StackHandleScope<1> hs(self); + Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException(&throw_location))); self->ClearException(); // Default to handler not found. uint32_t found_dex_pc = DexFile::kDexNoIndex; @@ -251,11 +252,11 @@ uint32_t ArtMethod::FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_ } // Does this catch exception type apply? Class* iter_exception_type = mh.GetClassFromTypeIdx(iter_type_idx); - if (exception_type.get() == nullptr) { + if (exception_type.Get() == nullptr) { self->ClearException(); LOG(WARNING) << "Unresolved exception class when finding catch block: " << mh.GetTypeDescriptorFromTypeIdx(iter_type_idx); - } else if (iter_exception_type->IsAssignableFrom(exception_type.get())) { + } else if (iter_exception_type->IsAssignableFrom(exception_type.Get())) { found_dex_pc = it.GetHandlerAddress(); break; } @@ -266,8 +267,8 @@ uint32_t ArtMethod::FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_ *has_no_move_exception = (first_catch_instr->Opcode() != Instruction::MOVE_EXCEPTION); } // Put the exception back. - if (exception.get() != nullptr) { - self->SetException(throw_location, exception.get()); + if (exception.Get() != nullptr) { + self->SetException(throw_location, exception.Get()); } return found_dex_pc; } diff --git a/runtime/mirror/art_method.h b/runtime/mirror/art_method.h index 49d22ab3a3..27a10be2f2 100644 --- a/runtime/mirror/art_method.h +++ b/runtime/mirror/art_method.h @@ -332,7 +332,7 @@ class MANAGED ArtMethod : public Object { return GetFrameSizeInBytes() - kPointerSize; } - size_t GetSirtOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + size_t GetHandleScopeOffsetInBytes() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { return kPointerSize; } @@ -381,7 +381,7 @@ class MANAGED ArtMethod : public Object { // Find the catch block for the given exception type and dex_pc. When a catch block is found, // indicates whether the found catch block is responsible for clearing the exception or whether // a move-exception instruction is present. - uint32_t FindCatchBlock(SirtRef<Class>& exception_type, uint32_t dex_pc, + uint32_t FindCatchBlock(Handle<Class>& exception_type, uint32_t dex_pc, bool* has_no_move_exception) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc index ff63782314..15b69f378b 100644 --- a/runtime/mirror/class.cc +++ b/runtime/mirror/class.cc @@ -28,7 +28,7 @@ #include "object_array-inl.h" #include "object_utils.h" #include "runtime.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" #include "thread.h" #include "throwable.h" #include "utils.h" @@ -77,20 +77,13 @@ void Class::SetStatus(Status new_status, Thread* self) { << "Attempt to set as erroneous an already erroneous class " << PrettyClass(this); // Stash current exception. - SirtRef<mirror::Object> old_throw_this_object(self, NULL); - SirtRef<mirror::ArtMethod> old_throw_method(self, NULL); - SirtRef<mirror::Throwable> old_exception(self, NULL); - uint32_t old_throw_dex_pc; - { - ThrowLocation old_throw_location; - mirror::Throwable* old_exception_obj = self->GetException(&old_throw_location); - old_throw_this_object.reset(old_throw_location.GetThis()); - old_throw_method.reset(old_throw_location.GetMethod()); - old_exception.reset(old_exception_obj); - old_throw_dex_pc = old_throw_location.GetDexPc(); - self->ClearException(); - } - CHECK(old_exception.get() != NULL); + StackHandleScope<3> hs(self); + ThrowLocation old_throw_location; + Handle<mirror::Throwable> old_exception(hs.NewHandle(self->GetException(&old_throw_location))); + CHECK(old_exception.Get() != nullptr); + Handle<mirror::Object> old_throw_this_object(hs.NewHandle(old_throw_location.GetThis())); + Handle<mirror::ArtMethod> old_throw_method(hs.NewHandle(old_throw_location.GetMethod())); + uint32_t old_throw_dex_pc = old_throw_location.GetDexPc(); // clear exception to call FindSystemClass self->ClearException(); @@ -107,10 +100,10 @@ void Class::SetStatus(Status new_status, Thread* self) { } // Restore exception. - ThrowLocation gc_safe_throw_location(old_throw_this_object.get(), old_throw_method.get(), + ThrowLocation gc_safe_throw_location(old_throw_this_object.Get(), old_throw_method.Get(), old_throw_dex_pc); - self->SetException(gc_safe_throw_location, old_exception.get()); + self->SetException(gc_safe_throw_location, old_exception.Get()); } CHECK(sizeof(Status) == sizeof(uint32_t)) << PrettyClass(this); if (Runtime::Current()->IsActiveTransaction()) { @@ -149,7 +142,8 @@ String* Class::ComputeName() { return name; } Thread* self = Thread::Current(); - SirtRef<mirror::Class> sirt_c(self, this); + StackHandleScope<1> hs(self); + Handle<mirror::Class> handle_c(hs.NewHandle(this)); std::string descriptor(ClassHelper(this).GetDescriptor()); if ((descriptor[0] != 'L') && (descriptor[0] != '[')) { // The descriptor indicates that this is the class for @@ -179,7 +173,7 @@ String* Class::ComputeName() { std::replace(descriptor.begin(), descriptor.end(), '/', '.'); name = String::AllocFromModifiedUtf8(self, descriptor.c_str()); } - sirt_c->SetName(name); + handle_c->SetName(name); return name; } diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h index 1f393db811..92b999e051 100644 --- a/runtime/mirror/class.h +++ b/runtime/mirror/class.h @@ -429,7 +429,7 @@ class MANAGED Class : public Object { ReadBarrierOption kReadBarrierOption = kWithReadBarrier> bool IsVariableSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { // Classes and arrays vary in size, and so the object_size_ field cannot - // be used to get their instance size + // be used to Get their instance size return IsClassClass<kVerifyFlags, kReadBarrierOption>() || IsArrayClass<kVerifyFlags, kReadBarrierOption>(); } diff --git a/runtime/mirror/dex_cache_test.cc b/runtime/mirror/dex_cache_test.cc index fef1f9bb88..3d28dc603f 100644 --- a/runtime/mirror/dex_cache_test.cc +++ b/runtime/mirror/dex_cache_test.cc @@ -23,7 +23,7 @@ #include "gc/heap.h" #include "mirror/object_array-inl.h" #include "mirror/object-inl.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" namespace art { namespace mirror { @@ -32,9 +32,10 @@ class DexCacheTest : public CommonRuntimeTest {}; TEST_F(DexCacheTest, Open) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<DexCache> dex_cache(soa.Self(), class_linker_->AllocDexCache(soa.Self(), - *java_lang_dex_file_)); - ASSERT_TRUE(dex_cache.get() != NULL); + StackHandleScope<1> hs(soa.Self()); + Handle<DexCache> dex_cache( + hs.NewHandle(class_linker_->AllocDexCache(soa.Self(), *java_lang_dex_file_))); + ASSERT_TRUE(dex_cache.Get() != NULL); EXPECT_EQ(java_lang_dex_file_->NumStringIds(), dex_cache->NumStrings()); EXPECT_EQ(java_lang_dex_file_->NumTypeIds(), dex_cache->NumResolvedTypes()); diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc index 2f775bc474..04905a57ca 100644 --- a/runtime/mirror/object.cc +++ b/runtime/mirror/object.cc @@ -32,7 +32,7 @@ #include "object_array-inl.h" #include "object_utils.h" #include "runtime.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" #include "throwable.h" #include "well_known_classes.h" @@ -100,19 +100,19 @@ static Object* CopyObject(Thread* self, mirror::Object* dest, mirror::Object* sr // An allocation pre-fence visitor that copies the object. class CopyObjectVisitor { public: - explicit CopyObjectVisitor(Thread* self, SirtRef<Object>* orig, size_t num_bytes) + explicit CopyObjectVisitor(Thread* self, Handle<Object>* orig, size_t num_bytes) : self_(self), orig_(orig), num_bytes_(num_bytes) { } void operator()(Object* obj, size_t usable_size) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { UNUSED(usable_size); - CopyObject(self_, obj, orig_->get(), num_bytes_); + CopyObject(self_, obj, orig_->Get(), num_bytes_); } private: Thread* const self_; - SirtRef<Object>* const orig_; + Handle<Object>* const orig_; const size_t num_bytes_; DISALLOW_COPY_AND_ASSIGN(CopyObjectVisitor); }; @@ -123,7 +123,8 @@ Object* Object::Clone(Thread* self) { // be wrong. gc::Heap* heap = Runtime::Current()->GetHeap(); size_t num_bytes = SizeOf(); - SirtRef<Object> this_object(self, this); + StackHandleScope<1> hs(self); + Handle<Object> this_object(hs.NewHandle(this)); Object* copy; CopyObjectVisitor visitor(self, &this_object, num_bytes); if (heap->IsMovableObject(this)) { @@ -163,10 +164,11 @@ int32_t Object::IdentityHashCode() const { case LockWord::kThinLocked: { // Inflate the thin lock to a monitor and stick the hash code inside of the monitor. Thread* self = Thread::Current(); - SirtRef<mirror::Object> sirt_this(self, current_this); - Monitor::InflateThinLocked(self, sirt_this, lw, GenerateIdentityHashCode()); + StackHandleScope<1> hs(self); + Handle<mirror::Object> h_this(hs.NewHandle(current_this)); + Monitor::InflateThinLocked(self, h_this, lw, GenerateIdentityHashCode()); // A GC may have occurred when we switched to kBlocked. - current_this = sirt_this.get(); + current_this = h_this.Get(); break; } case LockWord::kFatLocked: { diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h index 203a6b2510..942a2713d2 100644 --- a/runtime/mirror/object_array-inl.h +++ b/runtime/mirror/object_array-inl.h @@ -23,7 +23,7 @@ #include "mirror/art_field.h" #include "mirror/class.h" #include "runtime.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" #include "thread.h" #include <string> @@ -118,7 +118,7 @@ inline void ObjectArray<T>::AssignableMemmove(int32_t dst_pos, ObjectArray<T>* s int32_t src_pos, int32_t count) { if (kIsDebugBuild) { for (int i = 0; i < count; ++i) { - // The Get will perform the VerifyObject. + // The get will perform the VerifyObject. src->GetWithoutChecks(src_pos + i); } } @@ -150,7 +150,7 @@ inline void ObjectArray<T>::AssignableMemmove(int32_t dst_pos, ObjectArray<T>* s Runtime::Current()->GetHeap()->WriteBarrierArray(this, dst_pos, count); if (kIsDebugBuild) { for (int i = 0; i < count; ++i) { - // The Get will perform the VerifyObject. + // The get will perform the VerifyObject. GetWithoutChecks(dst_pos + i); } } @@ -161,7 +161,7 @@ inline void ObjectArray<T>::AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* sr int32_t src_pos, int32_t count) { if (kIsDebugBuild) { for (int i = 0; i < count; ++i) { - // The Get will perform the VerifyObject. + // The get will perform the VerifyObject. src->GetWithoutChecks(src_pos + i); } } @@ -182,7 +182,7 @@ inline void ObjectArray<T>::AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* sr Runtime::Current()->GetHeap()->WriteBarrierArray(this, dst_pos, count); if (kIsDebugBuild) { for (int i = 0; i < count; ++i) { - // The Get will perform the VerifyObject. + // The get will perform the VerifyObject. GetWithoutChecks(dst_pos + i); } } @@ -244,13 +244,14 @@ template<class T> inline ObjectArray<T>* ObjectArray<T>::CopyOf(Thread* self, int32_t new_length) { DCHECK_GE(new_length, 0); // We may get copied by a compacting GC. - SirtRef<ObjectArray<T> > sirt_this(self, this); + StackHandleScope<1> hs(self); + Handle<ObjectArray<T> > h_this(hs.NewHandle(this)); gc::Heap* heap = Runtime::Current()->GetHeap(); gc::AllocatorType allocator_type = heap->IsMovableObject(this) ? heap->GetCurrentAllocator() : heap->GetCurrentNonMovingAllocator(); ObjectArray<T>* new_array = Alloc(self, GetClass(), new_length, allocator_type); if (LIKELY(new_array != nullptr)) { - new_array->AssignableMemcpy(0, sirt_this.get(), 0, std::min(sirt_this->GetLength(), new_length)); + new_array->AssignableMemcpy(0, h_this.Get(), 0, std::min(h_this->GetLength(), new_length)); } return new_array; } diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc index c494f133f2..537fe85565 100644 --- a/runtime/mirror/object_test.cc +++ b/runtime/mirror/object_test.cc @@ -34,7 +34,7 @@ #include "art_method-inl.h" #include "object-inl.h" #include "object_array-inl.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" #include "string-inl.h" #include "UniquePtr.h" @@ -56,7 +56,9 @@ class ObjectTest : public CommonRuntimeTest { } Thread* self = Thread::Current(); - SirtRef<String> string(self, String::AllocFromModifiedUtf8(self, expected_utf16_length, utf8_in)); + StackHandleScope<1> hs(self); + Handle<String> string( + hs.NewHandle(String::AllocFromModifiedUtf8(self, expected_utf16_length, utf8_in))); ASSERT_EQ(expected_utf16_length, string->GetLength()); ASSERT_TRUE(string->GetCharArray() != NULL); ASSERT_TRUE(string->GetCharArray()->GetData() != NULL); @@ -102,8 +104,9 @@ TEST_F(ObjectTest, IsInSamePackage) { TEST_F(ObjectTest, Clone) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<ObjectArray<Object> > a1(soa.Self(), - class_linker_->AllocObjectArray<Object>(soa.Self(), 256)); + StackHandleScope<1> hs(soa.Self()); + Handle<ObjectArray<Object>> a1( + hs.NewHandle(class_linker_->AllocObjectArray<Object>(soa.Self(), 256))); size_t s1 = a1->SizeOf(); Object* clone = a1->Clone(soa.Self()); EXPECT_EQ(s1, clone->SizeOf()); @@ -112,17 +115,18 @@ TEST_F(ObjectTest, Clone) { TEST_F(ObjectTest, AllocObjectArray) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<ObjectArray<Object> > oa(soa.Self(), - class_linker_->AllocObjectArray<Object>(soa.Self(), 2)); + StackHandleScope<1> hs(soa.Self()); + Handle<ObjectArray<Object> > oa( + hs.NewHandle(class_linker_->AllocObjectArray<Object>(soa.Self(), 2))); EXPECT_EQ(2, oa->GetLength()); EXPECT_TRUE(oa->Get(0) == NULL); EXPECT_TRUE(oa->Get(1) == NULL); - oa->Set<false>(0, oa.get()); - EXPECT_TRUE(oa->Get(0) == oa.get()); + oa->Set<false>(0, oa.Get()); + EXPECT_TRUE(oa->Get(0) == oa.Get()); EXPECT_TRUE(oa->Get(1) == NULL); - oa->Set<false>(1, oa.get()); - EXPECT_TRUE(oa->Get(0) == oa.get()); - EXPECT_TRUE(oa->Get(1) == oa.get()); + oa->Set<false>(1, oa.Get()); + EXPECT_TRUE(oa->Get(0) == oa.Get()); + EXPECT_TRUE(oa->Get(1) == oa.Get()); Class* aioobe = class_linker_->FindSystemClass(soa.Self(), "Ljava/lang/ArrayIndexOutOfBoundsException;"); @@ -149,20 +153,22 @@ TEST_F(ObjectTest, AllocObjectArray) { TEST_F(ObjectTest, AllocArray) { ScopedObjectAccess soa(Thread::Current()); Class* c = class_linker_->FindSystemClass(soa.Self(), "[I"); - SirtRef<Array> a(soa.Self(), Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator())); + StackHandleScope<1> hs(soa.Self()); + Handle<Array> a( + hs.NewHandle(Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator()))); EXPECT_TRUE(c == a->GetClass()); EXPECT_EQ(1, a->GetLength()); c = class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"); - a.reset(Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator())); + a.Assign(Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator())); EXPECT_TRUE(c == a->GetClass()); EXPECT_EQ(1, a->GetLength()); c = class_linker_->FindSystemClass(soa.Self(), "[[Ljava/lang/Object;"); - a.reset(Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator())); + a.Assign(Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator())); EXPECT_TRUE(c == a->GetClass()); EXPECT_EQ(1, a->GetLength()); } @@ -170,28 +176,27 @@ TEST_F(ObjectTest, AllocArray) { TEST_F(ObjectTest, AllocArray_FillUsable) { ScopedObjectAccess soa(Thread::Current()); Class* c = class_linker_->FindSystemClass(soa.Self(), "[B"); - SirtRef<Array> a(soa.Self(), Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator(), - true)); + StackHandleScope<1> hs(soa.Self()); + Handle<Array> a( + hs.NewHandle(Array::Alloc<true>(soa.Self(), c, 1, c->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator(), true))); EXPECT_TRUE(c == a->GetClass()); EXPECT_LE(1, a->GetLength()); c = class_linker_->FindSystemClass(soa.Self(), "[I"); - a.reset(Array::Alloc<true>(soa.Self(), c, 2, c->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator(), - true)); + a.Assign(Array::Alloc<true>(soa.Self(), c, 2, c->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator(), true)); EXPECT_TRUE(c == a->GetClass()); EXPECT_LE(2, a->GetLength()); c = class_linker_->FindSystemClass(soa.Self(), "[Ljava/lang/Object;"); - a.reset(Array::Alloc<true>(soa.Self(), c, 2, c->GetComponentSize(), - Runtime::Current()->GetHeap()->GetCurrentAllocator(), - true)); + a.Assign(Array::Alloc<true>(soa.Self(), c, 2, c->GetComponentSize(), + Runtime::Current()->GetHeap()->GetCurrentAllocator(), true)); EXPECT_TRUE(c == a->GetClass()); EXPECT_LE(2, a->GetLength()); c = class_linker_->FindSystemClass(soa.Self(), "[[Ljava/lang/Object;"); - a.reset(Array::Alloc<true>(soa.Self(), c, 2, c->GetComponentSize(), + a.Assign(Array::Alloc<true>(soa.Self(), c, 2, c->GetComponentSize(), Runtime::Current()->GetHeap()->GetCurrentAllocator(), true)); EXPECT_TRUE(c == a->GetClass()); EXPECT_LE(2, a->GetLength()); @@ -273,8 +278,9 @@ TEST_F(ObjectTest, CheckAndAllocArrayFromCode) { TEST_F(ObjectTest, CreateMultiArray) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<Class> c(soa.Self(), class_linker_->FindSystemClass(soa.Self(), "I")); - SirtRef<IntArray> dims(soa.Self(), IntArray::Alloc(soa.Self(), 1)); + StackHandleScope<2> hs(soa.Self()); + Handle<Class> c(hs.NewHandle(class_linker_->FindSystemClass(soa.Self(), "I"))); + Handle<IntArray> dims(hs.NewHandle(IntArray::Alloc(soa.Self(), 1))); dims->Set<false>(0, 1); Array* multi = Array::CreateMultiArray(soa.Self(), c, dims); EXPECT_TRUE(multi->GetClass() == class_linker_->FindSystemClass(soa.Self(), "[I")); @@ -287,7 +293,7 @@ TEST_F(ObjectTest, CreateMultiArray) { "java.lang.NegativeArraySizeException"); soa.Self()->ClearException(); - dims.reset(IntArray::Alloc(soa.Self(), 2)); + dims.Assign(IntArray::Alloc(soa.Self(), 2)); for (int i = 1; i < 20; ++i) { for (int j = 0; j < 20; ++j) { dims->Set<false>(0, i); @@ -311,7 +317,8 @@ TEST_F(ObjectTest, StaticFieldFromCode) { const DexFile* dex_file = Runtime::Current()->GetCompileTimeClassPath(class_loader)[0]; CHECK(dex_file != NULL); - SirtRef<mirror::ClassLoader> loader(soa.Self(), soa.Decode<ClassLoader*>(class_loader)); + StackHandleScope<2> hs(soa.Self()); + Handle<mirror::ClassLoader> loader(hs.NewHandle(soa.Decode<ClassLoader*>(class_loader))); Class* klass = class_linker_->FindClass(soa.Self(), "LStaticsFromCode;", loader); ArtMethod* clinit = klass->FindClassInitializer(); const DexFile::StringId* klass_string_id = dex_file->FindStringId("LStaticsFromCode;"); @@ -339,9 +346,9 @@ TEST_F(ObjectTest, StaticFieldFromCode) { Object* s0 = field->GetObj(klass); EXPECT_TRUE(s0 != NULL); - SirtRef<CharArray> char_array(soa.Self(), CharArray::Alloc(soa.Self(), 0)); - field->SetObj<false>(field->GetDeclaringClass(), char_array.get()); - EXPECT_EQ(char_array.get(), field->GetObj(klass)); + Handle<CharArray> char_array(hs.NewHandle(CharArray::Alloc(soa.Self(), 0))); + field->SetObj<false>(field->GetDeclaringClass(), char_array.Get()); + EXPECT_EQ(char_array.Get(), field->GetObj(klass)); field->SetObj<false>(field->GetDeclaringClass(), NULL); EXPECT_EQ(NULL, field->GetObj(klass)); @@ -375,7 +382,8 @@ TEST_F(ObjectTest, String) { TEST_F(ObjectTest, StringEqualsUtf8) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); + StackHandleScope<2> hs(soa.Self()); + Handle<String> string(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "android"))); EXPECT_TRUE(string->Equals("android")); EXPECT_FALSE(string->Equals("Android")); EXPECT_FALSE(string->Equals("ANDROID")); @@ -383,46 +391,49 @@ TEST_F(ObjectTest, StringEqualsUtf8) { EXPECT_FALSE(string->Equals("and")); EXPECT_FALSE(string->Equals("androids")); - SirtRef<String> empty(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); + Handle<String> empty(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), ""))); EXPECT_TRUE(empty->Equals("")); EXPECT_FALSE(empty->Equals("a")); } TEST_F(ObjectTest, StringEquals) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); - SirtRef<String> string_2(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); - EXPECT_TRUE(string->Equals(string_2.get())); + StackHandleScope<3> hs(soa.Self()); + Handle<String> string(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "android"))); + Handle<String> string_2(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "android"))); + EXPECT_TRUE(string->Equals(string_2.Get())); EXPECT_FALSE(string->Equals("Android")); EXPECT_FALSE(string->Equals("ANDROID")); EXPECT_FALSE(string->Equals("")); EXPECT_FALSE(string->Equals("and")); EXPECT_FALSE(string->Equals("androids")); - SirtRef<String> empty(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); + Handle<String> empty(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), ""))); EXPECT_TRUE(empty->Equals("")); EXPECT_FALSE(empty->Equals("a")); } TEST_F(ObjectTest, StringCompareTo) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); - SirtRef<String> string_2(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); - SirtRef<String> string_3(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "Android")); - SirtRef<String> string_4(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "and")); - SirtRef<String> string_5(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); - EXPECT_EQ(0, string->CompareTo(string_2.get())); - EXPECT_LT(0, string->CompareTo(string_3.get())); - EXPECT_GT(0, string_3->CompareTo(string.get())); - EXPECT_LT(0, string->CompareTo(string_4.get())); - EXPECT_GT(0, string_4->CompareTo(string.get())); - EXPECT_LT(0, string->CompareTo(string_5.get())); - EXPECT_GT(0, string_5->CompareTo(string.get())); + StackHandleScope<5> hs(soa.Self()); + Handle<String> string(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "android"))); + Handle<String> string_2(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "android"))); + Handle<String> string_3(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "Android"))); + Handle<String> string_4(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "and"))); + Handle<String> string_5(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), ""))); + EXPECT_EQ(0, string->CompareTo(string_2.Get())); + EXPECT_LT(0, string->CompareTo(string_3.Get())); + EXPECT_GT(0, string_3->CompareTo(string.Get())); + EXPECT_LT(0, string->CompareTo(string_4.Get())); + EXPECT_GT(0, string_4->CompareTo(string.Get())); + EXPECT_LT(0, string->CompareTo(string_5.Get())); + EXPECT_GT(0, string_5->CompareTo(string.Get())); } TEST_F(ObjectTest, StringLength) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> string(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "android")); + StackHandleScope<1> hs(soa.Self()); + Handle<String> string(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "android"))); EXPECT_EQ(string->GetLength(), 7); EXPECT_EQ(string->GetUtfLength(), 7); @@ -440,8 +451,9 @@ TEST_F(ObjectTest, DescriptorCompare) { jobject jclass_loader_1 = LoadDex("ProtoCompare"); jobject jclass_loader_2 = LoadDex("ProtoCompare2"); - SirtRef<ClassLoader> class_loader_1(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader_1)); - SirtRef<ClassLoader> class_loader_2(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader_2)); + StackHandleScope<2> hs(soa.Self()); + Handle<ClassLoader> class_loader_1(hs.NewHandle(soa.Decode<ClassLoader*>(jclass_loader_1))); + Handle<ClassLoader> class_loader_2(hs.NewHandle(soa.Decode<ClassLoader*>(jclass_loader_2))); Class* klass1 = linker->FindClass(soa.Self(), "LProtoCompare;", class_loader_1); ASSERT_TRUE(klass1 != NULL); @@ -497,9 +509,10 @@ TEST_F(ObjectTest, DescriptorCompare) { TEST_F(ObjectTest, StringHashCode) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> empty(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "")); - SirtRef<String> A(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "A")); - SirtRef<String> ABC(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "ABC")); + StackHandleScope<3> hs(soa.Self()); + Handle<String> empty(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), ""))); + Handle<String> A(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "A"))); + Handle<String> ABC(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "ABC"))); EXPECT_EQ(0, empty->GetHashCode()); EXPECT_EQ(65, A->GetHashCode()); @@ -509,17 +522,18 @@ TEST_F(ObjectTest, StringHashCode) { TEST_F(ObjectTest, InstanceOf) { ScopedObjectAccess soa(Thread::Current()); jobject jclass_loader = LoadDex("XandY"); - SirtRef<ClassLoader> class_loader(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader)); + StackHandleScope<3> hs(soa.Self()); + Handle<ClassLoader> class_loader(hs.NewHandle(soa.Decode<ClassLoader*>(jclass_loader))); Class* X = class_linker_->FindClass(soa.Self(), "LX;", class_loader); Class* Y = class_linker_->FindClass(soa.Self(), "LY;", class_loader); ASSERT_TRUE(X != NULL); ASSERT_TRUE(Y != NULL); - SirtRef<Object> x(soa.Self(), X->AllocObject(soa.Self())); - SirtRef<Object> y(soa.Self(), Y->AllocObject(soa.Self())); - ASSERT_TRUE(x.get() != NULL); - ASSERT_TRUE(y.get() != NULL); + Handle<Object> x(hs.NewHandle(X->AllocObject(soa.Self()))); + Handle<Object> y(hs.NewHandle(Y->AllocObject(soa.Self()))); + ASSERT_TRUE(x.Get() != NULL); + ASSERT_TRUE(y.Get() != NULL); EXPECT_TRUE(x->InstanceOf(X)); EXPECT_FALSE(x->InstanceOf(Y)); @@ -543,7 +557,8 @@ TEST_F(ObjectTest, InstanceOf) { TEST_F(ObjectTest, IsAssignableFrom) { ScopedObjectAccess soa(Thread::Current()); jobject jclass_loader = LoadDex("XandY"); - SirtRef<ClassLoader> class_loader(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader)); + StackHandleScope<1> hs(soa.Self()); + Handle<ClassLoader> class_loader(hs.NewHandle(soa.Decode<ClassLoader*>(jclass_loader))); Class* X = class_linker_->FindClass(soa.Self(), "LX;", class_loader); Class* Y = class_linker_->FindClass(soa.Self(), "LY;", class_loader); @@ -580,7 +595,8 @@ TEST_F(ObjectTest, IsAssignableFrom) { TEST_F(ObjectTest, IsAssignableFromArray) { ScopedObjectAccess soa(Thread::Current()); jobject jclass_loader = LoadDex("XandY"); - SirtRef<ClassLoader> class_loader(soa.Self(), soa.Decode<ClassLoader*>(jclass_loader)); + StackHandleScope<1> hs(soa.Self()); + Handle<ClassLoader> class_loader(hs.NewHandle(soa.Decode<ClassLoader*>(jclass_loader))); Class* X = class_linker_->FindClass(soa.Self(), "LX;", class_loader); Class* Y = class_linker_->FindClass(soa.Self(), "LY;", class_loader); ASSERT_TRUE(X != NULL); @@ -632,8 +648,9 @@ TEST_F(ObjectTest, IsAssignableFromArray) { TEST_F(ObjectTest, FindInstanceField) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> s(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "ABC")); - ASSERT_TRUE(s.get() != NULL); + StackHandleScope<1> hs(soa.Self()); + Handle<String> s(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "ABC"))); + ASSERT_TRUE(s.Get() != NULL); Class* c = s->GetClass(); ASSERT_TRUE(c != NULL); @@ -665,8 +682,9 @@ TEST_F(ObjectTest, FindInstanceField) { TEST_F(ObjectTest, FindStaticField) { ScopedObjectAccess soa(Thread::Current()); - SirtRef<String> s(soa.Self(), String::AllocFromModifiedUtf8(soa.Self(), "ABC")); - ASSERT_TRUE(s.get() != NULL); + StackHandleScope<1> hs(soa.Self()); + Handle<String> s(hs.NewHandle(String::AllocFromModifiedUtf8(soa.Self(), "ABC"))); + ASSERT_TRUE(s.Get() != NULL); Class* c = s->GetClass(); ASSERT_TRUE(c != NULL); diff --git a/runtime/mirror/stack_trace_element.cc b/runtime/mirror/stack_trace_element.cc index f220039e38..d8591cca7a 100644 --- a/runtime/mirror/stack_trace_element.cc +++ b/runtime/mirror/stack_trace_element.cc @@ -20,7 +20,7 @@ #include "class-inl.h" #include "gc/accounting/card_table-inl.h" #include "object-inl.h" -#include "sirt_ref-inl.h" +#include "handle_scope-inl.h" #include "string.h" namespace art { @@ -40,9 +40,9 @@ void StackTraceElement::ResetClass() { } StackTraceElement* StackTraceElement::Alloc(Thread* self, - SirtRef<String>& declaring_class, - SirtRef<String>& method_name, - SirtRef<String>& file_name, + Handle<String>& declaring_class, + Handle<String>& method_name, + Handle<String>& file_name, int32_t line_number) { StackTraceElement* trace = down_cast<StackTraceElement*>(GetStackTraceElement()->AllocObject(self)); @@ -57,14 +57,14 @@ StackTraceElement* StackTraceElement::Alloc(Thread* self, } template<bool kTransactionActive> -void StackTraceElement::Init(SirtRef<String>& declaring_class, SirtRef<String>& method_name, - SirtRef<String>& file_name, int32_t line_number) { +void StackTraceElement::Init(Handle<String>& declaring_class, Handle<String>& method_name, + Handle<String>& file_name, int32_t line_number) { SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_), - declaring_class.get()); + declaring_class.Get()); SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_), - method_name.get()); + method_name.Get()); SetFieldObject<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_), - file_name.get()); + file_name.Get()); SetField32<kTransactionActive>(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_), line_number); } diff --git a/runtime/mirror/stack_trace_element.h b/runtime/mirror/stack_trace_element.h index c324d96639..22d9b71410 100644 --- a/runtime/mirror/stack_trace_element.h +++ b/runtime/mirror/stack_trace_element.h @@ -22,7 +22,7 @@ namespace art { -template<class T> class SirtRef; +template<class T> class Handle; struct StackTraceElementOffsets; namespace mirror { @@ -47,9 +47,9 @@ class MANAGED StackTraceElement : public Object { } static StackTraceElement* Alloc(Thread* self, - SirtRef<String>& declaring_class, - SirtRef<String>& method_name, - SirtRef<String>& file_name, + Handle<String>& declaring_class, + Handle<String>& method_name, + Handle<String>& file_name, int32_t line_number) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); @@ -70,8 +70,8 @@ class MANAGED StackTraceElement : public Object { int32_t line_number_; template<bool kTransactionActive> - void Init(SirtRef<String>& declaring_class, SirtRef<String>& method_name, - SirtRef<String>& file_name, int32_t line_number) + void Init(Handle<String>& declaring_class, Handle<String>& method_name, + Handle<String>& file_name, int32_t line_number) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static Class* java_lang_StackTraceElement_; diff --git a/runtime/mirror/string.cc b/runtime/mirror/string.cc index 6a0c225022..ee719b477b 100644 --- a/runtime/mirror/string.cc +++ b/runtime/mirror/string.cc @@ -22,7 +22,7 @@ #include "intern_table.h" #include "object-inl.h" #include "runtime.h" -#include "sirt_ref.h" +#include "handle_scope-inl.h" #include "thread.h" #include "utf-inl.h" @@ -123,18 +123,19 @@ String* String::AllocFromModifiedUtf8(Thread* self, int32_t utf16_length, } String* String::Alloc(Thread* self, int32_t utf16_length) { - SirtRef<CharArray> array(self, CharArray::Alloc(self, utf16_length)); - if (UNLIKELY(array.get() == nullptr)) { + StackHandleScope<1> hs(self); + Handle<CharArray> array(hs.NewHandle(CharArray::Alloc(self, utf16_length))); + if (UNLIKELY(array.Get() == nullptr)) { return nullptr; } return Alloc(self, array); } -String* String::Alloc(Thread* self, const SirtRef<CharArray>& array) { +String* String::Alloc(Thread* self, const Handle<CharArray>& array) { // Hold reference in case AllocObject causes GC. String* string = down_cast<String*>(GetJavaLangString()->AllocObject(self)); if (LIKELY(string != nullptr)) { - string->SetArray(array.get()); + string->SetArray(array.Get()); string->SetCount(array->GetLength()); } return string; diff --git a/runtime/mirror/string.h b/runtime/mirror/string.h index f97308edc0..169b671574 100644 --- a/runtime/mirror/string.h +++ b/runtime/mirror/string.h @@ -24,7 +24,7 @@ namespace art { -template<class T> class SirtRef; +template<class T> class Handle; struct StringClassOffsets; struct StringOffsets; class StringPiece; @@ -137,7 +137,7 @@ class MANAGED String : public Object { static String* Alloc(Thread* self, int32_t utf16_length) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static String* Alloc(Thread* self, const SirtRef<CharArray>& array) + static String* Alloc(Thread* self, const Handle<CharArray>& array) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); void SetArray(CharArray* new_array) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |