From 7ce6ae5ece6b7a2085d4445e2030f964986dca88 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Tue, 11 Feb 2014 11:46:18 -0800 Subject: Don't hardcode object layout in Unsafe. Change-Id: I0e2509a1a46c2aa937e4a45cabefb4998a8ed7f4 --- libart/src/main/java/sun/misc/Unsafe.java | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/libart/src/main/java/sun/misc/Unsafe.java b/libart/src/main/java/sun/misc/Unsafe.java index 0a4d8b2..6f5f5ee 100644 --- a/libart/src/main/java/sun/misc/Unsafe.java +++ b/libart/src/main/java/sun/misc/Unsafe.java @@ -81,12 +81,7 @@ public final class Unsafe { if (component == null) { throw new IllegalArgumentException("Valid for array classes only: " + clazz); } - // TODO: make the following not specific to the object model. - int offset = 12; - if (component == long.class || component == double.class) { - offset += 4; // 4 bytes of padding. - } - return offset; + return getArrayBaseOffsetForComponentType(component); } /** @@ -100,21 +95,12 @@ public final class Unsafe { if (component == null) { throw new IllegalArgumentException("Valid for array classes only: " + clazz); } - // TODO: make the following not specific to the object model. - if (!component.isPrimitive()) { - return 4; - } else if (component == long.class || component == double.class) { - return 8; - } else if (component == int.class || component == float.class) { - return 4; - } else if (component == char.class || component == short.class) { - return 2; - } else { - // component == byte.class || component == boolean.class. - return 1; - } + return getArrayIndexScaleForComponentType(component); } + private static native int getArrayBaseOffsetForComponentType(Class component_class); + private static native int getArrayIndexScaleForComponentType(Class component_class); + /** * Performs a compare-and-set operation on an int * field within the given object. -- cgit v1.1