diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2014-02-11 11:46:18 -0800 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2014-02-11 13:14:28 -0800 |
commit | 7ce6ae5ece6b7a2085d4445e2030f964986dca88 (patch) | |
tree | 9658ffff11a17fb4a7bf0b8ab57dc4060807a723 | |
parent | 58ac1fd09dddd681504868831909c5185b183582 (diff) | |
download | libcore-7ce6ae5ece6b7a2085d4445e2030f964986dca88.zip libcore-7ce6ae5ece6b7a2085d4445e2030f964986dca88.tar.gz libcore-7ce6ae5ece6b7a2085d4445e2030f964986dca88.tar.bz2 |
Don't hardcode object layout in Unsafe.
Change-Id: I0e2509a1a46c2aa937e4a45cabefb4998a8ed7f4
-rw-r--r-- | libart/src/main/java/sun/misc/Unsafe.java | 24 |
1 files 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 <code>int</code> * field within the given object. |