summaryrefslogtreecommitdiff
path: root/runtime/mirror/array.cc
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2013-09-13 13:46:47 -0700
committer Mathieu Chartier <mathieuc@google.com> 2013-11-11 15:34:27 -0800
commit590fee9e8972f872301c2d16a575d579ee564bee (patch)
treeb02db45c72f1911ec896b93379ada0276aea3199 /runtime/mirror/array.cc
parent5b70680b8df6d8fa95bb8e1070d0107f3d388940 (diff)
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
Diffstat (limited to 'runtime/mirror/array.cc')
-rw-r--r--runtime/mirror/array.cc15
1 files changed, 9 insertions, 6 deletions
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<mirror::IntArray>& dimensions)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
int32_t array_length = dimensions->Get(current_dimension);
- SirtRef<Array> new_array(self, Array::Alloc(self, array_class, array_length));
+ SirtRef<Array> new_array(self, Array::Alloc<kMovingCollector, true>(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<mirror::ClassLoader> 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<mirror::IntArray> 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<typename T>
PrimitiveArray<T>* PrimitiveArray<T>::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<kMovingCollector, true>(self, array_class_, length, sizeof(T));
return down_cast<PrimitiveArray<T>*>(raw_array);
}