From 4b0bbd85e8027df0353b3ff945bbb3964775aa6e Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 13 May 2013 14:25:59 -0600 Subject: [PATCH] fix sun.misc.Unsafe.arrayIndexScale implementation The original implementation was based on the assumption that the passed class would be the array element type, whereas it is actually the array type itself. --- src/classpath-openjdk.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 18a507bda3..1c43ee44fb 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -2665,24 +2665,21 @@ extern "C" JNIEXPORT int64_t JNICALL Avian_sun_misc_Unsafe_arrayIndexScale (Thread* t, object, uintptr_t* arguments) { - object c = jclassVmClass(t, reinterpret_cast(arguments[1])); - - if (classVmFlags(t, c) & PrimitiveFlag) { - const char* name = reinterpret_cast - (&byteArrayBody(t, local::getClassName(t, c), 0)); - - switch (*name) { - case 'b': return 1; - case 's': - case 'c': return 2; - case 'l': - case 'd': return 8; - case 'i': - case 'f': return 4; - default: abort(t); - } - } else { - return BytesPerWord; + switch (byteArrayBody + (t, className + (t, jclassVmClass(t, reinterpret_cast(arguments[1]))), 1)) + { + case 'Z': + case 'B': return 1; + case 'S': + case 'C': return 2; + case 'I': + case 'F': return 4; + case 'J': + case 'D': return 8; + case '[': + case 'L': return BytesPerWord; + default: abort(t); } }