summaryrefslogtreecommitdiff
path: root/runtime/mirror/array.cc
diff options
context:
space:
mode:
author Mathieu Chartier <mathieuc@google.com> 2015-04-22 13:56:20 -0700
committer Mathieu Chartier <mathieuc@google.com> 2015-05-29 18:45:49 -0700
commite401d146407d61eeb99f8d6176b2ac13c4df1e33 (patch)
tree17927f9bfe7d2041b5942c89832d55f9dedb24c5 /runtime/mirror/array.cc
parent2006b7b9b8e32722bd0d640c62549d8a0ac624b6 (diff)
Move mirror::ArtMethod to native
Optimizing + quick tests are passing, devices boot. TODO: Test and fix bugs in mips64. Saves 16 bytes per most ArtMethod, 7.5MB reduction in system PSS. Some of the savings are from removal of virtual methods and direct methods object arrays. Bug: 19264997 Change-Id: I622469a0cfa0e7082a2119f3d6a9491eb61e3f3d
Diffstat (limited to 'runtime/mirror/array.cc')
-rw-r--r--runtime/mirror/array.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/runtime/mirror/array.cc b/runtime/mirror/array.cc
index b92f01797a..d72c03ff86 100644
--- a/runtime/mirror/array.cc
+++ b/runtime/mirror/array.cc
@@ -125,6 +125,26 @@ void Array::ThrowArrayStoreException(Object* object) {
art::ThrowArrayStoreException(object->GetClass(), this->GetClass());
}
+Array* Array::CopyOf(Thread* self, int32_t new_length) {
+ CHECK(GetClass()->GetComponentType()->IsPrimitive()) << "Will miss write barriers";
+ DCHECK_GE(new_length, 0);
+ // We may get copied by a compacting GC.
+ StackHandleScope<1> hs(self);
+ auto h_this(hs.NewHandle(this));
+ auto* heap = Runtime::Current()->GetHeap();
+ gc::AllocatorType allocator_type = heap->IsMovableObject(this) ? heap->GetCurrentAllocator() :
+ heap->GetCurrentNonMovingAllocator();
+ const auto component_size = GetClass()->GetComponentSize();
+ const auto component_shift = GetClass()->GetComponentSizeShift();
+ Array* new_array = Alloc<true>(self, GetClass(), new_length, component_shift, allocator_type);
+ if (LIKELY(new_array != nullptr)) {
+ memcpy(new_array->GetRawData(component_size, 0), h_this->GetRawData(component_size, 0),
+ std::min(h_this->GetLength(), new_length) << component_shift);
+ }
+ return new_array;
+}
+
+
template <typename T> GcRoot<Class> PrimitiveArray<T>::array_class_;
// Explicitly instantiate all the primitive array types.