summaryrefslogtreecommitdiff
path: root/runtime/mirror/array.cc
diff options
context:
space:
mode:
author Ian Rogers <irogers@google.com> 2014-02-24 16:53:16 -0800
committer Ian Rogers <irogers@google.com> 2014-02-24 18:47:23 -0800
commit9837939678bb5dcba178e5fb00ed59b5d14c8d9b (patch)
tree00f0e6b54d7c4cac78a02752e268724157e50b6e /runtime/mirror/array.cc
parent3fcf18e25241253f23efbeebe77b2a4c4a7c54d3 (diff)
Avoid std::string allocations for finding an array class.
Introduce ClassLinker::FindArrayClass which performs an array class lookup given the element/component class. This has a 16 element cache of recently looked up arrays. Pass the current thread to ClassLinker Find .. Class routines to avoid calls to Thread::Current(). Avoid some uses of FindClass in the debugger where WellKnownClasses is a faster and more compacting GC friendly alternative. Change-Id: I60e231820b349543a7edb3ceb9cf1ce92db3c843
Diffstat (limited to 'runtime/mirror/array.cc')
-rw-r--r--runtime/mirror/array.cc17
1 files changed, 10 insertions, 7 deletions
diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc
index 2180857019..715f072c4a 100644
--- a/runtime/mirror/array.cc
+++ b/runtime/mirror/array.cc
@@ -18,6 +18,7 @@
#include "class.h"
#include "class-inl.h"
+#include "class_linker-inl.h"
#include "common_throws.h"
#include "dex_file-inl.h"
#include "gc/accounting/card_table-inl.h"
@@ -85,20 +86,22 @@ Array* Array::CreateMultiArray(Thread* self, const SirtRef<Class>& element_class
}
}
- // Generate the full name of the array class.
- std::string descriptor(num_dimensions, '[');
- 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());
SirtRef<mirror::Class> array_class(self,
- class_linker->FindClass(descriptor.c_str(), class_loader));
+ class_linker->FindArrayClass(self, element_class.get()));
if (UNLIKELY(array_class.get() == nullptr)) {
CHECK(self->IsExceptionPending());
return nullptr;
}
- // create the array
+ 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)) {
+ CHECK(self->IsExceptionPending());
+ return nullptr;
+ }
+ }
+ // Create the array.
Array* new_array = RecursiveCreateMultiArray(self, array_class, 0, dimensions);
if (UNLIKELY(new_array == nullptr)) {
CHECK(self->IsExceptionPending());