diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-02-08 16:20:58 -0800 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-02-08 16:26:12 -0800 |
commit | 5bb99037bef70784ae4630c2e4b81688d2a18621 (patch) | |
tree | 7c01146719c9bd445f983d470980206952d8719b /runtime/mirror | |
parent | 9c7f35435b51cdeae8665aabb8e63392105db787 (diff) | |
download | art-5bb99037bef70784ae4630c2e4b81688d2a18621.tar.gz art-5bb99037bef70784ae4630c2e4b81688d2a18621.tar.bz2 art-5bb99037bef70784ae4630c2e4b81688d2a18621.zip |
Fix CreateMultiArray to be compaction safe.
It used to be compaction safe before moving classes was enabled.
Added missing SIRTs.
Change-Id: I92963ed71fa6d2a20d16ec0e400b8fa0e41ac196
Diffstat (limited to 'runtime/mirror')
-rw-r--r-- | runtime/mirror/array.cc | 38 | ||||
-rw-r--r-- | runtime/mirror/array.h | 3 | ||||
-rw-r--r-- | runtime/mirror/object_test.cc | 6 |
3 files changed, 25 insertions, 22 deletions
diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc index ca0d1f3977..c23234ee0b 100644 --- a/runtime/mirror/array.cc +++ b/runtime/mirror/array.cc @@ -40,23 +40,25 @@ namespace mirror { // piece and work our way in. // Recursively create an array with multiple dimensions. Elements may be // Objects or primitive types. -static Array* RecursiveCreateMultiArray(Thread* self, Class* array_class, int current_dimension, - SirtRef<mirror::IntArray>& dimensions) +static Array* RecursiveCreateMultiArray(Thread* self, + const SirtRef<Class>& array_class, int current_dimension, + const SirtRef<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, array_length)); - if (UNLIKELY(new_array.get() == NULL)) { + SirtRef<Array> new_array(self, Array::Alloc<true>(self, array_class.get(), array_length)); + if (UNLIKELY(new_array.get() == nullptr)) { CHECK(self->IsExceptionPending()); - return NULL; + 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++) { - Array* sub_array = RecursiveCreateMultiArray(self, array_class->GetComponentType(), + SirtRef<mirror::Class> sirt_component_type(self, array_class->GetComponentType()); + Array* sub_array = RecursiveCreateMultiArray(self, sirt_component_type, current_dimension + 1, dimensions); - if (UNLIKELY(sub_array == NULL)) { + if (UNLIKELY(sub_array == nullptr)) { CHECK(self->IsExceptionPending()); - return NULL; + return nullptr; } new_array->AsObjectArray<Array>()->Set(i, sub_array); } @@ -64,7 +66,8 @@ static Array* RecursiveCreateMultiArray(Thread* self, Class* array_class, int cu return new_array.get(); } -Array* Array::CreateMultiArray(Thread* self, Class* element_class, IntArray* dimensions) { +Array* Array::CreateMultiArray(Thread* self, const SirtRef<Class>& element_class, + const SirtRef<IntArray>& dimensions) { // Verify dimensions. // // The caller is responsible for verifying that "dimArray" is non-null @@ -77,28 +80,27 @@ Array* Array::CreateMultiArray(Thread* self, Class* element_class, IntArray* dim int dimension = dimensions->Get(i); if (UNLIKELY(dimension < 0)) { ThrowNegativeArraySizeException(StringPrintf("Dimension %d: %d", i, dimension).c_str()); - return NULL; + return nullptr; } } // Generate the full name of the array class. std::string descriptor(num_dimensions, '['); - descriptor += ClassHelper(element_class).GetDescriptor(); + descriptor += ClassHelper(element_class.get()).GetDescriptor(); // Find/generate the array class. ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); SirtRef<mirror::ClassLoader> class_loader(self, element_class->GetClassLoader()); - Class* array_class = class_linker->FindClass(descriptor.c_str(), class_loader); - if (UNLIKELY(array_class == NULL)) { + SirtRef<mirror::Class> array_class(self, + class_linker->FindClass(descriptor.c_str(), class_loader)); + if (UNLIKELY(array_class.get() == nullptr)) { CHECK(self->IsExceptionPending()); - return NULL; + return nullptr; } // create the array - SirtRef<mirror::IntArray> sirt_dimensions(self, dimensions); - Array* new_array = RecursiveCreateMultiArray(self, array_class, 0, sirt_dimensions); - if (UNLIKELY(new_array == NULL)) { + Array* new_array = RecursiveCreateMultiArray(self, array_class, 0, dimensions); + if (UNLIKELY(new_array == nullptr)) { CHECK(self->IsExceptionPending()); - return NULL; } return new_array; } diff --git a/runtime/mirror/array.h b/runtime/mirror/array.h index 6e366a08f5..04f03c3a55 100644 --- a/runtime/mirror/array.h +++ b/runtime/mirror/array.h @@ -47,7 +47,8 @@ class MANAGED Array : public Object { size_t component_size) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static Array* CreateMultiArray(Thread* self, Class* element_class, IntArray* dimensions) + static Array* CreateMultiArray(Thread* self, const SirtRef<Class>& element_class, + const SirtRef<IntArray>& dimensions) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); size_t SizeOf() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc index 2af32dacd2..db9723b2de 100644 --- a/runtime/mirror/object_test.cc +++ b/runtime/mirror/object_test.cc @@ -236,12 +236,12 @@ TEST_F(ObjectTest, CreateMultiArray) { SirtRef<Class> c(soa.Self(), class_linker_->FindSystemClass("I")); SirtRef<IntArray> dims(soa.Self(), IntArray::Alloc(soa.Self(), 1)); dims->Set(0, 1); - Array* multi = Array::CreateMultiArray(soa.Self(), c.get(), dims.get()); + Array* multi = Array::CreateMultiArray(soa.Self(), c, dims); EXPECT_TRUE(multi->GetClass() == class_linker_->FindSystemClass("[I")); EXPECT_EQ(1, multi->GetLength()); dims->Set(0, -1); - multi = Array::CreateMultiArray(soa.Self(), c.get(), dims.get()); + multi = Array::CreateMultiArray(soa.Self(), c, dims); EXPECT_TRUE(soa.Self()->IsExceptionPending()); EXPECT_EQ(PrettyDescriptor(soa.Self()->GetException(NULL)->GetClass()), "java.lang.NegativeArraySizeException"); @@ -252,7 +252,7 @@ TEST_F(ObjectTest, CreateMultiArray) { for (int j = 0; j < 20; ++j) { dims->Set(0, i); dims->Set(1, j); - multi = Array::CreateMultiArray(soa.Self(), c.get(), dims.get()); + multi = Array::CreateMultiArray(soa.Self(), c, dims); EXPECT_TRUE(multi->GetClass() == class_linker_->FindSystemClass("[[I")); EXPECT_EQ(i, multi->GetLength()); for (int k = 0; k < i; ++k) { |