summaryrefslogtreecommitdiffstats
path: root/runtime/mirror/array.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2014-02-08 16:20:58 -0800
committerMathieu Chartier <mathieuc@google.com>2014-02-08 16:26:12 -0800
commit5bb99037bef70784ae4630c2e4b81688d2a18621 (patch)
tree7c01146719c9bd445f983d470980206952d8719b /runtime/mirror/array.cc
parent9c7f35435b51cdeae8665aabb8e63392105db787 (diff)
downloadart-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/array.cc')
-rw-r--r--runtime/mirror/array.cc38
1 files changed, 20 insertions, 18 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;
}