From 56e832d3e8463fada55c8ae7529730cfa87e9526 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 27 Mar 2011 20:25:47 -0600 Subject: [PATCH] fix JVM_GetArrayElement and JVM_SetArrayElement The old versions only handled object arrays properly, but they need to handle primitive arrays as well. --- src/classpath-openjdk.cpp | 87 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 544d1c47a7..c58472c065 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -3173,12 +3173,62 @@ EXPORT(JVM_GetArrayLength)(Thread* t, jobject array) return cast(*array, BytesPerWord); } +uint64_t +jvmGetArrayElement(Thread* t, uintptr_t* arguments) +{ + jobject array = reinterpret_cast(arguments[0]); + jint index = arguments[1]; + + switch (byteArrayBody(t, className(t, objectClass(t, *array)), 1)) { + case 'Z': + return reinterpret_cast + (makeLocalReference + (t, makeBoolean(t, cast(*array, ArrayBody + index)))); + case 'B': + return reinterpret_cast + (makeLocalReference + (t, makeByte(t, cast(*array, ArrayBody + index)))); + case 'C': + return reinterpret_cast + (makeLocalReference + (t, makeChar(t, cast(*array, ArrayBody + (index * 2))))); + case 'S': + return reinterpret_cast + (makeLocalReference + (t, makeShort(t, cast(*array, ArrayBody + (index * 2))))); + case 'I': + return reinterpret_cast + (makeLocalReference + (t, makeInt(t, cast(*array, ArrayBody + (index * 4))))); + case 'F': + return reinterpret_cast + (makeLocalReference + (t, makeFloat(t, cast(*array, ArrayBody + (index * 4))))); + case 'J': + return reinterpret_cast + (makeLocalReference + (t, makeLong(t, cast(*array, ArrayBody + (index * 8))))); + case 'D': + return reinterpret_cast + (makeLocalReference + (t, makeDouble(t, cast(*array, ArrayBody + (index * 8))))); + case 'L': + case '[': + return reinterpret_cast + (makeLocalReference + (t, cast(*array, ArrayBody + (index * BytesPerWord)))); + default: + abort(t); + } +} + extern "C" JNIEXPORT jobject JNICALL EXPORT(JVM_GetArrayElement)(Thread* t, jobject array, jint index) { - ENTER(t, Thread::ActiveState); + uintptr_t arguments[] = { reinterpret_cast(array), + index }; - return makeLocalReference(t, objectArrayBody(t, *array, index)); + return reinterpret_cast(run(t, jvmGetArrayElement, arguments)); } extern "C" JNIEXPORT jvalue JNICALL @@ -3190,7 +3240,38 @@ EXPORT(JVM_SetArrayElement)(Thread* t, jobject array, jint index, { ENTER(t, Thread::ActiveState); - set(t, *array, ArrayBody + (index * BytesPerWord), (value ? *value : 0)); + switch (byteArrayBody(t, className(t, objectClass(t, *array)), 1)) { + case 'Z': + cast(*array, ArrayBody + index) = booleanValue(t, *value); + break; + case 'B': + cast(*array, ArrayBody + index) = byteValue(t, *value); + break; + case 'C': + cast(*array, ArrayBody + (index * 2)) = charValue(t, *value); + break; + case 'S': + cast(*array, ArrayBody + (index * 2)) = shortValue(t, *value); + break; + case 'I': + cast(*array, ArrayBody + (index * 4)) = intValue(t, *value); + break; + case 'F': + cast(*array, ArrayBody + (index * 4)) = floatValue(t, *value); + break; + case 'J': + cast(*array, ArrayBody + (index * 8)) = longValue(t, *value); + break; + case 'D': + cast(*array, ArrayBody + (index * 8)) = doubleValue(t, *value); + break; + case 'L': + case '[': + set(t, *array, ArrayBody + (index * BytesPerWord), (value ? *value : 0)); + break; + default: + abort(t); + } } extern "C" JNIEXPORT void JNICALL