From 5bb99037bef70784ae4630c2e4b81688d2a18621 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Sat, 8 Feb 2014 16:20:58 -0800 Subject: Fix CreateMultiArray to be compaction safe. It used to be compaction safe before moving classes was enabled. Added missing SIRTs. Change-Id: I92963ed71fa6d2a20d16ec0e400b8fa0e41ac196 --- runtime/mirror/array.cc | 38 ++++++++++++++++++++------------------ runtime/mirror/array.h | 3 ++- runtime/mirror/object_test.cc | 6 +++--- 3 files changed, 25 insertions(+), 22 deletions(-) (limited to 'runtime/mirror') 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& dimensions) +static Array* RecursiveCreateMultiArray(Thread* self, + const SirtRef& array_class, int current_dimension, + const SirtRef& dimensions) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { int32_t array_length = dimensions->Get(current_dimension); - SirtRef new_array(self, Array::Alloc(self, array_class, array_length)); - if (UNLIKELY(new_array.get() == NULL)) { + SirtRef new_array(self, Array::Alloc(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 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()->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& element_class, + const SirtRef& 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 class_loader(self, element_class->GetClassLoader()); - Class* array_class = class_linker->FindClass(descriptor.c_str(), class_loader); - if (UNLIKELY(array_class == NULL)) { + SirtRef 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 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& element_class, + const SirtRef& 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 c(soa.Self(), class_linker_->FindSystemClass("I")); SirtRef 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) { -- cgit v1.2.3