From 590fee9e8972f872301c2d16a575d579ee564bee Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Fri, 13 Sep 2013 13:46:47 -0700 Subject: Compacting collector. The compacting collector is currently similar to semispace. It works by copying objects back and forth between two bump pointer spaces. There are types of objects which are "non-movable" due to current runtime limitations. These are Classes, Methods, and Fields. Bump pointer spaces are a new type of continuous alloc space which have no lock in the allocation code path. When you allocate from these it uses atomic operations to increase an index. Traversing the objects in the bump pointer space relies on Object::SizeOf matching the allocated size exactly. Runtime changes: JNI::GetArrayElements returns copies objects if you attempt to get the backing data of a movable array. For GetArrayElementsCritical, we return direct backing storage for any types of arrays, but temporarily disable the GC until the critical region is completed. Added a new runtime call called VisitObjects, this is used in place of the old pattern which was flushing the allocation stack and walking the bitmaps. Changed image writer to be compaction safe and use object monitor word for forwarding addresses. Added a bunch of added SIRTs to ClassLinker, MethodLinker, etc.. TODO: Enable switching allocators, compacting on background, etc.. Bug: 8981901 Change-Id: I3c886fd322a6eef2b99388d19a765042ec26ab99 --- runtime/mirror/array.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'runtime/mirror/array.cc') diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc index 020085dbf0..f8a283224c 100644 --- a/runtime/mirror/array.cc +++ b/runtime/mirror/array.cc @@ -41,15 +41,16 @@ namespace mirror { // 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, - IntArray* dimensions) + 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)); + SirtRef new_array(self, Array::Alloc(self, array_class, + array_length)); if (UNLIKELY(new_array.get() == NULL)) { CHECK(self->IsExceptionPending()); return NULL; } - if ((current_dimension + 1) < dimensions->GetLength()) { + 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(), @@ -87,13 +88,15 @@ Array* Array::CreateMultiArray(Thread* self, Class* element_class, IntArray* dim // Find/generate the array class. ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); - Class* array_class = class_linker->FindClass(descriptor.c_str(), element_class->GetClassLoader()); + SirtRef class_loader(self, element_class->GetClassLoader()); + Class* array_class = class_linker->FindClass(descriptor.c_str(), class_loader); if (UNLIKELY(array_class == NULL)) { CHECK(self->IsExceptionPending()); return NULL; } // create the array - Array* new_array = RecursiveCreateMultiArray(self, array_class, 0, dimensions); + SirtRef sirt_dimensions(self, dimensions); + Array* new_array = RecursiveCreateMultiArray(self, array_class, 0, sirt_dimensions); if (UNLIKELY(new_array == NULL)) { CHECK(self->IsExceptionPending()); return NULL; @@ -112,7 +115,7 @@ void Array::ThrowArrayStoreException(Object* object) const { template PrimitiveArray* PrimitiveArray::Alloc(Thread* self, size_t length) { DCHECK(array_class_ != NULL); - Array* raw_array = Array::Alloc(self, array_class_, length, sizeof(T)); + Array* raw_array = Array::Alloc(self, array_class_, length, sizeof(T)); return down_cast*>(raw_array); } -- cgit v1.2.3