From 9837939678bb5dcba178e5fb00ed59b5d14c8d9b Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Mon, 24 Feb 2014 16:53:16 -0800 Subject: 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 --- runtime/mirror/array.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'runtime/mirror/array.cc') 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& 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 class_loader(self, element_class->GetClassLoader()); SirtRef 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()); -- cgit v1.2.3