From f5949168d4142cde1582117173b03c614b632938 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 10 Jan 2011 15:30:18 -0800 Subject: [PATCH] Move nio direct byte buffers onto the Java heap. Specifically, implement VMRuntime.newNonMovableArray and VMRuntime.addressOf. For now these are pretty trivial because we don't have a copying collector, but this (a) prevents code from allocating arbitrary amounts of direct byte buffer without being charged for it, and (b) lets us move to a copying collector in future. Change-Id: I5de156dc8ac4ab5c997e18d447f635eb01ff08ab --- vm/native/dalvik_system_VMRuntime.c | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/vm/native/dalvik_system_VMRuntime.c b/vm/native/dalvik_system_VMRuntime.c index 0672d7171..839f7c038 100644 --- a/vm/native/dalvik_system_VMRuntime.c +++ b/vm/native/dalvik_system_VMRuntime.c @@ -151,6 +151,43 @@ static void Dalvik_dalvik_system_VMRuntime_disableJitCompilation(const u4* args, RETURN_VOID(); } +static void Dalvik_dalvik_system_VMRuntime_newNonMovableArray(const u4* args, + JValue* pResult) +{ + ClassObject* elementClass = (ClassObject*) args[1]; + int length = args[2]; + ArrayObject* newArray; + + if (elementClass == NULL) { + dvmThrowException("Ljava/lang/NullPointerException;", NULL); + RETURN_VOID(); + } + if (length < 0) { + dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL); + RETURN_VOID(); + } + + // TODO: right now, we don't have a copying collector, so there's no need + // to do anything special here, but we ought to pass the non-movability + // through to the allocator. + newArray = dvmAllocObjectArray(elementClass, length, ALLOC_DEFAULT); + if (newArray == NULL) { + assert(dvmCheckException(dvmThreadSelf())); + RETURN_VOID(); + } + dvmReleaseTrackedAlloc((Object*) newArray, NULL); + + RETURN_PTR(newArray); +} + +static void Dalvik_dalvik_system_VMRuntime_addressOf(const u4* args, + JValue* pResult) +{ + ArrayObject* array = (ArrayObject*) args[1]; + s8 result = (uintptr_t) array->contents; + RETURN_LONG(result); +} + const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = { { "getTargetHeapUtilization", "()F", Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization }, @@ -166,5 +203,9 @@ const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = { Dalvik_dalvik_system_VMRuntime_startJitCompilation }, { "disableJitCompilation", "()V", Dalvik_dalvik_system_VMRuntime_disableJitCompilation }, + { "newNonMovableArray", "(Ljava/lang/Class;I)Ljava/lang/Object;", + Dalvik_dalvik_system_VMRuntime_newNonMovableArray }, + { "addressOf", "(Ljava/lang/Object;)J", + Dalvik_dalvik_system_VMRuntime_addressOf }, { NULL, NULL, NULL }, }; -- 2.11.0