diff options
author | Pekka Enberg <penberg@kernel.org> | 2012-08-14 19:31:17 +0000 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2012-08-14 19:32:20 +0000 |
commit | c439bff2ba5e63d6d7b7d343d6c800c13c145b44 (patch) | |
tree | 1432502396bbd3ae702d31977c3c4c532d858156 | |
parent | 7336e6ae93aaaf23d169b3c0ccfb24c0a30eb0cb (diff) | |
download | jato-c439bff2ba5e63d6d7b7d343d6c800c13c145b44.tar.gz |
test/functional: Move UnsafeTest to `test/sun/misc` package
Signed-off-by: Pekka Enberg <penberg@kernel.org>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | test/functional/sun/misc/UnsafeTest.java | 255 | ||||
-rw-r--r-- | test/functional/test/sun/misc/UnsafeTest.java | 258 | ||||
-rwxr-xr-x | tools/test.py | 2 |
4 files changed, 261 insertions, 258 deletions
@@ -376,14 +376,14 @@ REGRESSION_TEST_SUITE_CLASSES = \ test/functional/jvm/TrampolineBackpatchingTest.java \ test/functional/jvm/VirtualAbstractInterfaceMethodTest.java \ test/functional/jvm/lang/ReferenceTest.java \ - test/functional/sun/misc/UnsafeTest.java \ test/functional/test/java/lang/ClassTest.java \ test/functional/test/java/lang/DoubleTest.java \ test/functional/test/java/lang/JNITest.java \ test/functional/test/java/lang/reflect/FieldAccessorsTest.java \ test/functional/test/java/lang/reflect/FieldTest.java \ test/functional/test/java/lang/reflect/MethodTest.java \ - test/functional/test/java/util/HashMapTest.java + test/functional/test/java/util/HashMapTest.java \ + test/functional/test/sun/misc/UnsafeTest.java JASMIN_REGRESSION_TEST_SUITE_CLASSES = \ test/functional/jvm/DupTest.j \ diff --git a/test/functional/sun/misc/UnsafeTest.java b/test/functional/sun/misc/UnsafeTest.java deleted file mode 100644 index 410ef02f..00000000 --- a/test/functional/sun/misc/UnsafeTest.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2009 Pekka Enberg - * - * This file is released under the GPL version 2 with the following - * clarification and special exception: - * - * Linking this library statically or dynamically with other modules is - * making a combined work based on this library. Thus, the terms and - * conditions of the GNU General Public License cover the whole - * combination. - * - * As a special exception, the copyright holders of this library give you - * permission to link this library with independent modules to produce an - * executable, regardless of the license terms of these independent - * modules, and to copy and distribute the resulting executable under terms - * of your choice, provided that you also meet, for each linked independent - * module, the terms and conditions of the license of that module. An - * independent module is a module which is not derived from or based on - * this library. If you modify this library, you may extend this exception - * to your version of the library, but you are not obligated to do so. If - * you do not wish to do so, delete this exception statement from your - * version. - * - * Please refer to the file LICENSE for details. - */ -package sun.misc; - -import java.lang.reflect.Field; -import jvm.TestCase; - -/** - * @author Pekka Enberg - */ -public class UnsafeTest extends TestCase { - private static final Unsafe unsafe = Unsafe.getUnsafe(); - - public static void testArrayGetIntVolatile() { - int[] array = new int[] { 1, Integer.MAX_VALUE, 3 }; - assertEquals(Integer.MAX_VALUE, unsafe.getIntVolatile(array, arrayOffset(array, 1))); - } - - public static void testArrayGetLongVolatile() { - long[] array = new long[] { 1, Long.MAX_VALUE, 3 }; - assertEquals(Long.MAX_VALUE, unsafe.getLongVolatile(array, arrayOffset(array, 1))); - } - - public static void testArrayGetObjectVolatile() { - Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; - assertEquals(new Integer(2), unsafe.getObjectVolatile(array, arrayOffset(array, 1))); - } - - public static void testArrayPutIntVolatile() { - int[] array = new int[] { 1, 2, 3 }; - unsafe.putIntVolatile(array, arrayOffset(array, 1), Integer.MAX_VALUE); - assertEquals(Integer.MAX_VALUE, array[1]); - } - - public static void testArrayPutLong() { - long[] array = new long[] { 1, 2, 3 }; - unsafe.putLong(array, arrayOffset(array, 1), Long.MAX_VALUE); - assertEquals(Long.MAX_VALUE, array[1]); - } - - public static void testArrayPutLongVolatile() { - long[] array = new long[] { 1, 2, 3 }; - unsafe.putLongVolatile(array, arrayOffset(array, 1), Long.MAX_VALUE); - assertEquals(Long.MAX_VALUE, array[1]); - } - - public static void testArrayPutObject() { - Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; - unsafe.putObject(array, arrayOffset(array, 1), Integer.MAX_VALUE); - assertEquals(new Integer(Integer.MAX_VALUE), array[1]); - } - - public static void testArrayPutObjectVolatile() { - Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; - unsafe.putObjectVolatile(array, arrayOffset(array, 1), Integer.MAX_VALUE); - assertEquals(new Integer(Integer.MAX_VALUE), array[1]); - } - - public static void testFieldGetLongVolatile() throws Exception { - UnsafeLongObject obj = new UnsafeLongObject(); - obj.value = Long.MAX_VALUE; - assertEquals(Long.MAX_VALUE, unsafe.getLongVolatile(obj, fieldOffset(obj, "value"))); - } - - public static void testFieldGetObjectVolatile() throws Exception { - final String s = "hello, world"; - UnsafeObjectObject obj = new UnsafeObjectObject(); - obj.value = s; - assertSame(s, unsafe.getObjectVolatile(obj, fieldOffset(obj, "value"))); - } - - public static void testFieldPutIntVolatile() throws Exception { - UnsafeIntObject obj = new UnsafeIntObject(); - obj.value = Integer.MAX_VALUE; - unsafe.putIntVolatile(obj, fieldOffset(obj, "value"), Integer.MAX_VALUE); - assertEquals(Integer.MAX_VALUE, obj.value); - } - - public static void testFieldPutLong() throws Exception { - UnsafeLongObject obj = new UnsafeLongObject(); - obj.value = Long.MAX_VALUE; - unsafe.putLong(obj, fieldOffset(obj, "value"), Long.MAX_VALUE); - assertEquals(Long.MAX_VALUE, obj.value); - } - - public static void testFieldPutLongVolatile() throws Exception { - UnsafeLongObject obj = new UnsafeLongObject(); - obj.value = Long.MAX_VALUE; - unsafe.putLongVolatile(obj, fieldOffset(obj, "value"), Long.MAX_VALUE); - assertEquals(Long.MAX_VALUE, obj.value); - } - - public static void testFieldPutObject() throws Exception { - UnsafeObjectObject obj = new UnsafeObjectObject(); - obj.value = Integer.MAX_VALUE; - unsafe.putObject(obj, fieldOffset(obj, "value"), Integer.MAX_VALUE); - assertEquals(new Integer(Integer.MAX_VALUE), obj.value); - } - - public static void testFieldPutObjectVolatile() throws Exception { - final String s = "hello, world"; - UnsafeObjectObject obj = new UnsafeObjectObject(); - obj.value = s; - unsafe.putObjectVolatile(obj, fieldOffset(obj, "value"), s); - assertEquals(s, obj.value); - } - - public static long arrayOffset(Object object, int index) { - int base = unsafe.arrayBaseOffset(object.getClass()); - int indexScale = unsafe.arrayIndexScale(object.getClass()); - return base + (index * indexScale); - } - - public static long fieldOffset(Object object, String name) throws Exception { - Field field = UnsafeObjectObject.class.getDeclaredField(name); - return unsafe.objectFieldOffset(field); - } - - public static void testCompareAndSwapInt() throws Exception { - assertSwapsInt(Integer.MIN_VALUE, Integer.MAX_VALUE); - assertSwapsInt(Integer.MAX_VALUE, Integer.MIN_VALUE); - - assertDoesNotSwapInt(0, Integer.MIN_VALUE, Integer.MAX_VALUE); - } - - public static void assertSwapsInt(int expect, int update) throws Exception { - UnsafeIntObject object = new UnsafeIntObject(); - object.value = expect; - assertTrue(compareAndSwapInt(object, expect, update)); - assertEquals(update, object.value); - } - - public static void assertDoesNotSwapInt(int initial, int expect, int update) throws Exception { - UnsafeIntObject object = new UnsafeIntObject(); - object.value = initial; - assertFalse(compareAndSwapInt(object, expect, update)); - assertEquals(initial, object.value); - } - - public static boolean compareAndSwapInt(Object object, int expect, int update) throws Exception { - Field field = UnsafeIntObject.class.getDeclaredField("value"); - long valueOffset = unsafe.objectFieldOffset(field); - return unsafe.compareAndSwapInt(object, valueOffset, expect, update); - } - - public static class UnsafeIntObject { - public int value; - } - - public static void testCompareAndSwapLong() throws Exception { - assertSwapsLong(Long.MIN_VALUE, Long.MAX_VALUE); - assertSwapsLong(Long.MAX_VALUE, Long.MIN_VALUE); - - assertDoesNotSwapLong(0, Long.MIN_VALUE, Long.MAX_VALUE); - } - - public static void assertSwapsLong(long expect, long update) throws Exception { - UnsafeLongObject object = new UnsafeLongObject(); - object.value = expect; - assertTrue(compareAndSwapLong(object, expect, update)); - assertEquals(update, object.value); - } - - public static void assertDoesNotSwapLong(long initial, long expect, long update) throws Exception { - UnsafeLongObject object = new UnsafeLongObject(); - object.value = initial; - assertFalse(compareAndSwapLong(object, expect, update)); - assertEquals(initial, object.value); - } - - public static boolean compareAndSwapLong(Object object, long expect, long update) throws Exception { - Field field = UnsafeLongObject.class.getDeclaredField("value"); - long valueOffset = unsafe.objectFieldOffset(field); - return unsafe.compareAndSwapLong(object, valueOffset, expect, update); - } - - public static class UnsafeLongObject { - public long value; - } - - public static void testCompareAndSwapObject() throws Exception { - assertSwapsObject(new Object(), new Object()); - assertSwapsObject(new Object(), new Object()); - - assertDoesNotSwapObject(new Object(), new Object(), new Object()); - } - - public static void assertSwapsObject(Object expect, Object update) throws Exception { - UnsafeObjectObject object = new UnsafeObjectObject(); - object.value = expect; - assertTrue(compareAndSwapObject(object, expect, update)); - assertEquals(update, object.value); - } - - public static void assertDoesNotSwapObject(Object initial, Object expect, Object update) throws Exception { - UnsafeObjectObject object = new UnsafeObjectObject(); - object.value = initial; - assertFalse(compareAndSwapObject(object, expect, update)); - assertEquals(initial, object.value); - } - - public static boolean compareAndSwapObject(Object object, Object expect, Object update) throws Exception { - Field field = UnsafeObjectObject.class.getDeclaredField("value"); - long valueOffset = unsafe.objectFieldOffset(field); - return unsafe.compareAndSwapObject(object, valueOffset, expect, update); - } - - public static class UnsafeObjectObject { - public Object value; - } - - public static void main(String[] args) throws Exception { - testArrayGetIntVolatile(); - testArrayGetLongVolatile(); - testArrayGetObjectVolatile(); - testArrayPutIntVolatile(); - testArrayPutLong(); - testArrayPutLongVolatile(); - testArrayPutObject(); - testArrayPutObjectVolatile(); - testFieldGetLongVolatile(); - testFieldGetObjectVolatile(); - testFieldPutIntVolatile(); - testFieldPutLong(); - testFieldPutLongVolatile(); - testFieldPutObject(); - testFieldPutObjectVolatile(); - testCompareAndSwapInt(); - testCompareAndSwapLong(); - testCompareAndSwapObject(); - } -} diff --git a/test/functional/test/sun/misc/UnsafeTest.java b/test/functional/test/sun/misc/UnsafeTest.java new file mode 100644 index 00000000..895457f7 --- /dev/null +++ b/test/functional/test/sun/misc/UnsafeTest.java @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2009 Pekka Enberg + * + * This file is released under the GPL version 2 with the following + * clarification and special exception: + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. An + * independent module is a module which is not derived from or based on + * this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + * + * Please refer to the file LICENSE for details. + */ + +package test.sun.misc; + +import java.lang.reflect.Field; +import sun.misc.Unsafe; + +import jvm.TestCase; + +/** + * @author Pekka Enberg + */ +public class UnsafeTest extends TestCase { + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + public static void testArrayGetIntVolatile() { + int[] array = new int[] { 1, Integer.MAX_VALUE, 3 }; + assertEquals(Integer.MAX_VALUE, unsafe.getIntVolatile(array, arrayOffset(array, 1))); + } + + public static void testArrayGetLongVolatile() { + long[] array = new long[] { 1, Long.MAX_VALUE, 3 }; + assertEquals(Long.MAX_VALUE, unsafe.getLongVolatile(array, arrayOffset(array, 1))); + } + + public static void testArrayGetObjectVolatile() { + Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; + assertEquals(new Integer(2), unsafe.getObjectVolatile(array, arrayOffset(array, 1))); + } + + public static void testArrayPutIntVolatile() { + int[] array = new int[] { 1, 2, 3 }; + unsafe.putIntVolatile(array, arrayOffset(array, 1), Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE, array[1]); + } + + public static void testArrayPutLong() { + long[] array = new long[] { 1, 2, 3 }; + unsafe.putLong(array, arrayOffset(array, 1), Long.MAX_VALUE); + assertEquals(Long.MAX_VALUE, array[1]); + } + + public static void testArrayPutLongVolatile() { + long[] array = new long[] { 1, 2, 3 }; + unsafe.putLongVolatile(array, arrayOffset(array, 1), Long.MAX_VALUE); + assertEquals(Long.MAX_VALUE, array[1]); + } + + public static void testArrayPutObject() { + Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; + unsafe.putObject(array, arrayOffset(array, 1), Integer.MAX_VALUE); + assertEquals(new Integer(Integer.MAX_VALUE), array[1]); + } + + public static void testArrayPutObjectVolatile() { + Integer[] array = new Integer[] { new Integer(1), new Integer(2), new Integer(3) }; + unsafe.putObjectVolatile(array, arrayOffset(array, 1), Integer.MAX_VALUE); + assertEquals(new Integer(Integer.MAX_VALUE), array[1]); + } + + public static void testFieldGetLongVolatile() throws Exception { + UnsafeLongObject obj = new UnsafeLongObject(); + obj.value = Long.MAX_VALUE; + assertEquals(Long.MAX_VALUE, unsafe.getLongVolatile(obj, fieldOffset(obj, "value"))); + } + + public static void testFieldGetObjectVolatile() throws Exception { + final String s = "hello, world"; + UnsafeObjectObject obj = new UnsafeObjectObject(); + obj.value = s; + assertSame(s, unsafe.getObjectVolatile(obj, fieldOffset(obj, "value"))); + } + + public static void testFieldPutIntVolatile() throws Exception { + UnsafeIntObject obj = new UnsafeIntObject(); + obj.value = Integer.MAX_VALUE; + unsafe.putIntVolatile(obj, fieldOffset(obj, "value"), Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE, obj.value); + } + + public static void testFieldPutLong() throws Exception { + UnsafeLongObject obj = new UnsafeLongObject(); + obj.value = Long.MAX_VALUE; + unsafe.putLong(obj, fieldOffset(obj, "value"), Long.MAX_VALUE); + assertEquals(Long.MAX_VALUE, obj.value); + } + + public static void testFieldPutLongVolatile() throws Exception { + UnsafeLongObject obj = new UnsafeLongObject(); + obj.value = Long.MAX_VALUE; + unsafe.putLongVolatile(obj, fieldOffset(obj, "value"), Long.MAX_VALUE); + assertEquals(Long.MAX_VALUE, obj.value); + } + + public static void testFieldPutObject() throws Exception { + UnsafeObjectObject obj = new UnsafeObjectObject(); + obj.value = Integer.MAX_VALUE; + unsafe.putObject(obj, fieldOffset(obj, "value"), Integer.MAX_VALUE); + assertEquals(new Integer(Integer.MAX_VALUE), obj.value); + } + + public static void testFieldPutObjectVolatile() throws Exception { + final String s = "hello, world"; + UnsafeObjectObject obj = new UnsafeObjectObject(); + obj.value = s; + unsafe.putObjectVolatile(obj, fieldOffset(obj, "value"), s); + assertEquals(s, obj.value); + } + + public static long arrayOffset(Object object, int index) { + int base = unsafe.arrayBaseOffset(object.getClass()); + int indexScale = unsafe.arrayIndexScale(object.getClass()); + return base + (index * indexScale); + } + + public static long fieldOffset(Object object, String name) throws Exception { + Field field = UnsafeObjectObject.class.getDeclaredField(name); + return unsafe.objectFieldOffset(field); + } + + public static void testCompareAndSwapInt() throws Exception { + assertSwapsInt(Integer.MIN_VALUE, Integer.MAX_VALUE); + assertSwapsInt(Integer.MAX_VALUE, Integer.MIN_VALUE); + + assertDoesNotSwapInt(0, Integer.MIN_VALUE, Integer.MAX_VALUE); + } + + public static void assertSwapsInt(int expect, int update) throws Exception { + UnsafeIntObject object = new UnsafeIntObject(); + object.value = expect; + assertTrue(compareAndSwapInt(object, expect, update)); + assertEquals(update, object.value); + } + + public static void assertDoesNotSwapInt(int initial, int expect, int update) throws Exception { + UnsafeIntObject object = new UnsafeIntObject(); + object.value = initial; + assertFalse(compareAndSwapInt(object, expect, update)); + assertEquals(initial, object.value); + } + + public static boolean compareAndSwapInt(Object object, int expect, int update) throws Exception { + Field field = UnsafeIntObject.class.getDeclaredField("value"); + long valueOffset = unsafe.objectFieldOffset(field); + return unsafe.compareAndSwapInt(object, valueOffset, expect, update); + } + + public static class UnsafeIntObject { + public int value; + } + + public static void testCompareAndSwapLong() throws Exception { + assertSwapsLong(Long.MIN_VALUE, Long.MAX_VALUE); + assertSwapsLong(Long.MAX_VALUE, Long.MIN_VALUE); + + assertDoesNotSwapLong(0, Long.MIN_VALUE, Long.MAX_VALUE); + } + + public static void assertSwapsLong(long expect, long update) throws Exception { + UnsafeLongObject object = new UnsafeLongObject(); + object.value = expect; + assertTrue(compareAndSwapLong(object, expect, update)); + assertEquals(update, object.value); + } + + public static void assertDoesNotSwapLong(long initial, long expect, long update) throws Exception { + UnsafeLongObject object = new UnsafeLongObject(); + object.value = initial; + assertFalse(compareAndSwapLong(object, expect, update)); + assertEquals(initial, object.value); + } + + public static boolean compareAndSwapLong(Object object, long expect, long update) throws Exception { + Field field = UnsafeLongObject.class.getDeclaredField("value"); + long valueOffset = unsafe.objectFieldOffset(field); + return unsafe.compareAndSwapLong(object, valueOffset, expect, update); + } + + public static class UnsafeLongObject { + public long value; + } + + public static void testCompareAndSwapObject() throws Exception { + assertSwapsObject(new Object(), new Object()); + assertSwapsObject(new Object(), new Object()); + + assertDoesNotSwapObject(new Object(), new Object(), new Object()); + } + + public static void assertSwapsObject(Object expect, Object update) throws Exception { + UnsafeObjectObject object = new UnsafeObjectObject(); + object.value = expect; + assertTrue(compareAndSwapObject(object, expect, update)); + assertEquals(update, object.value); + } + + public static void assertDoesNotSwapObject(Object initial, Object expect, Object update) throws Exception { + UnsafeObjectObject object = new UnsafeObjectObject(); + object.value = initial; + assertFalse(compareAndSwapObject(object, expect, update)); + assertEquals(initial, object.value); + } + + public static boolean compareAndSwapObject(Object object, Object expect, Object update) throws Exception { + Field field = UnsafeObjectObject.class.getDeclaredField("value"); + long valueOffset = unsafe.objectFieldOffset(field); + return unsafe.compareAndSwapObject(object, valueOffset, expect, update); + } + + public static class UnsafeObjectObject { + public Object value; + } + + public static void main(String[] args) throws Exception { + testArrayGetIntVolatile(); + testArrayGetLongVolatile(); + testArrayGetObjectVolatile(); + testArrayPutIntVolatile(); + testArrayPutLong(); + testArrayPutLongVolatile(); + testArrayPutObject(); + testArrayPutObjectVolatile(); + testFieldGetLongVolatile(); + testFieldGetObjectVolatile(); + testFieldPutIntVolatile(); + testFieldPutLong(); + testFieldPutLongVolatile(); + testFieldPutObject(); + testFieldPutObjectVolatile(); + testCompareAndSwapInt(); + testCompareAndSwapLong(); + testCompareAndSwapObject(); + } +} diff --git a/tools/test.py b/tools/test.py index 9d2f88ee..c0f55a74 100755 --- a/tools/test.py +++ b/tools/test.py @@ -88,7 +88,6 @@ TESTS = [ , ( "jvm.VirtualAbstractInterfaceMethodTest", 0, NO_SYSTEM_CLASSLOADER, [ "i386", "x86_64" ] ) , ( "jvm.WideTest", 0, NO_SYSTEM_CLASSLOADER, [ "i386", "x86_64" ] ) , ( "jvm.lang.ReferenceTest", 0, NO_SYSTEM_CLASSLOADER, [ "i386", "x86_64" ] ) -, ( "sun.misc.UnsafeTest", 0, NO_SYSTEM_CLASSLOADER, [ "i386", "x86_64" ] ) , ( "test.java.lang.ClassTest", 0, [ ], [ "i386" ] ) , ( "test.java.lang.DoubleTest", 0, [ ], [ "i386" ] ) , ( "test.java.lang.JNITest", 0, NO_SYSTEM_CLASSLOADER, [ "i386" ] ) @@ -96,6 +95,7 @@ TESTS = [ , ( "test.java.lang.reflect.FieldTest", 0, [ ], [ "i386" ] ) , ( "test.java.lang.reflect.MethodTest", 0, [ ], [ "i386" ] ) , ( "test.java.util.HashMapTest", 0, [ ], [ "i386" ] ) +, ( "test.sun.misc.UnsafeTest", 0, NO_SYSTEM_CLASSLOADER, [ "i386", "x86_64" ] ) , ( "corrupt.CorruptedExceptionTableEndsAfterCode", 1, [ ], [ "i386", "x86_64" ] ) , ( "corrupt.CorruptedExceptionTableInvalidHandlerPC", 1, [ ], [ "i386", "x86_64" ] ) , ( "corrupt.CorruptedExceptionTableInvertedBorns", 1, [ ], [ "i386", "x86_64" ] ) |