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
diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h
index c60e714..ef73e4d 100644
--- a/runtime/mirror/array-inl.h
+++ b/runtime/mirror/array-inl.h
@@ -66,36 +66,36 @@
return array;
}
-inline Array* Array::AllocInstrumented(Thread* self, Class* array_class, int32_t component_count,
- size_t component_size) {
+template <bool kIsMovable, bool kIsInstrumented>
+inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count,
+ size_t component_size) {
size_t size = ComputeArraySize(self, array_class, component_count, component_size);
if (UNLIKELY(size == 0)) {
return NULL;
}
gc::Heap* heap = Runtime::Current()->GetHeap();
- Array* array = down_cast<Array*>(heap->AllocObjectInstrumented(self, array_class, size));
- return SetArrayLength(array, component_count);
-}
-
-inline Array* Array::AllocUninstrumented(Thread* self, Class* array_class, int32_t component_count,
- size_t component_size) {
- size_t size = ComputeArraySize(self, array_class, component_count, component_size);
- if (UNLIKELY(size == 0)) {
- return NULL;
+ Array* array = nullptr;
+ if (kIsMovable) {
+ if (kIsInstrumented) {
+ array = down_cast<Array*>(heap->AllocMovableObjectInstrumented(self, array_class, size));
+ } else {
+ array = down_cast<Array*>(heap->AllocMovableObjectUninstrumented(self, array_class, size));
+ }
+ } else {
+ if (kIsInstrumented) {
+ array = down_cast<Array*>(heap->AllocNonMovableObjectInstrumented(self, array_class, size));
+ } else {
+ array = down_cast<Array*>(heap->AllocNonMovableObjectUninstrumented(self, array_class, size));
+ }
}
- gc::Heap* heap = Runtime::Current()->GetHeap();
- Array* array = down_cast<Array*>(heap->AllocObjectUninstrumented(self, array_class, size));
return SetArrayLength(array, component_count);
}
-inline Array* Array::AllocInstrumented(Thread* self, Class* array_class, int32_t component_count) {
+template <bool kIsMovable, bool kIsInstrumented>
+inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count) {
DCHECK(array_class->IsArrayClass());
- return AllocInstrumented(self, array_class, component_count, array_class->GetComponentSize());
-}
-
-inline Array* Array::AllocUninstrumented(Thread* self, Class* array_class, int32_t component_count) {
- DCHECK(array_class->IsArrayClass());
- return AllocUninstrumented(self, array_class, component_count, array_class->GetComponentSize());
+ return Alloc<kIsMovable, kIsInstrumented>(self, array_class, component_count,
+ array_class->GetComponentSize());
}
} // namespace mirror