提交 d70586b5 编写于 作者: G gtriantafill

8165889: Remove jdk.test.lib.unsafe.UnsafeHelper

Summary: Remove use of setAccessible() to get Unsafe.
Reviewed-by: shade, lfoltan
上级 3270df54
/*
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -38,15 +38,11 @@ import jdk.internal.misc.Unsafe;
import java.lang.reflect.Field;
public class Test6968348 {
static Unsafe unsafe;
static Unsafe unsafe = Unsafe.getUnsafe();
static final long[] buffer = new long[4096];
static int array_long_base_offset;
public static void main(String[] args) throws Exception {
Class c = Test6968348.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
Field f = c.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe)f.get(c);
array_long_base_offset = unsafe.arrayBaseOffset(long[].class);
for (int n = 0; n < 100000; n++) {
......
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -50,14 +50,10 @@ public class TestIntUnsafeCAS {
private static final int ALIGN_OFF = 8;
private static final int UNALIGN_OFF = 5;
private static final Unsafe unsafe;
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final int BASE;
static {
try {
Class c = TestIntUnsafeCAS.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
Field f = c.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe)f.get(c);
BASE = unsafe.arrayBaseOffset(int[].class);
} catch (Exception e) {
InternalError err = new InternalError();
......
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -50,14 +50,10 @@ public class TestIntUnsafeOrdered {
private static final int ALIGN_OFF = 8;
private static final int UNALIGN_OFF = 5;
private static final Unsafe unsafe;
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final int BASE;
static {
try {
Class<?> c = Unsafe.class;
Field f = c.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe) f.get(c);
BASE = unsafe.arrayBaseOffset(int[].class);
} catch (Exception e) {
InternalError err = new InternalError();
......
/*
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -50,14 +50,10 @@ public class TestIntUnsafeVolatile {
private static final int ALIGN_OFF = 8;
private static final int UNALIGN_OFF = 5;
private static final Unsafe unsafe;
private static final Unsafe unsafe = Unsafe.getUnsafe();
private static final int BASE;
static {
try {
Class c = TestIntUnsafeVolatile.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe");
Field f = c.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe)f.get(c);
BASE = unsafe.arrayBaseOffset(int[].class);
} catch (Exception e) {
InternalError err = new InternalError();
......
......@@ -27,7 +27,6 @@
* @bug 8142386
* @summary Unsafe access to an array is wrongly marked as mismatched
* @modules java.base/jdk.internal.misc
* @library /test/lib
*
* @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:-TieredCompilation
* compiler.intrinsics.unsafe.TestUnsafeMismatchedArrayFieldAccess
......@@ -36,11 +35,10 @@
package compiler.intrinsics.unsafe;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.unsafe.UnsafeHelper;
public class TestUnsafeMismatchedArrayFieldAccess {
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
static {
try {
......
......@@ -45,7 +45,6 @@ package compiler.jvmci.compilerToVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
import jdk.vm.ci.hotspot.PublicMetaspaceWrapperObject;
......@@ -114,7 +113,7 @@ public class GetResolvedJavaMethodTest {
abstract HotSpotResolvedJavaMethod getResolvedJavaMethod();
}
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private static final WhiteBox WB = WhiteBox.getWhiteBox();
private static final Field METASPACE_METHOD_FIELD;
private static final Class<?> TEST_CLASS = GetResolvedJavaMethodTest.class;
......
......@@ -53,7 +53,6 @@ package compiler.jvmci.compilerToVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
......@@ -154,7 +153,7 @@ public class GetResolvedJavaTypeTest {
abstract HotSpotResolvedObjectType getResolvedJavaType();
}
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private static final WhiteBox WB = WhiteBox.getWhiteBox();
private static final Class TEST_CLASS = GetResolvedJavaTypeTest.class;
/* a compressed parameter for tested method is set to false because
......
......@@ -53,7 +53,6 @@ import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
import jdk.internal.misc.Unsafe;
import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.test.lib.Asserts;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
import jdk.vm.ci.meta.ConstantPool;
......@@ -69,7 +68,7 @@ import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CON
*/
public class ResolveFieldInPoolTest {
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
public static void main(String[] args) throws Exception {
Map<ConstantTypes, Validator> typeTests = new HashMap<>();
......
......@@ -52,7 +52,6 @@ import compiler.jvmci.common.testcases.SingleSubclassedClass;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
......@@ -61,7 +60,7 @@ import java.util.HashSet;
import java.util.Set;
public class ResolveMethodTest {
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
public static void main(String args[]) {
ResolveMethodTest test = new ResolveMethodTest();
......
......@@ -34,7 +34,6 @@
package compiler.loopopts.superword;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.unsafe.UnsafeHelper;
public class TestVectorizationWithInvariant {
......@@ -43,7 +42,7 @@ public class TestVectorizationWithInvariant {
private static final long CHAR_ARRAY_OFFSET;
static {
unsafe = UnsafeHelper.getUnsafe();
unsafe = Unsafe.getUnsafe();
BYTE_ARRAY_OFFSET = unsafe.arrayBaseOffset(byte[].class);
CHAR_ARRAY_OFFSET = unsafe.arrayBaseOffset(char[].class);
}
......
......@@ -49,7 +49,6 @@ import compiler.testlibrary.rtm.predicate.SupportedVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.test.lib.cli.CommandLineOptionTest;
import jdk.test.lib.cli.predicate.AndPredicate;
......@@ -125,7 +124,7 @@ public class TestRTMAbortRatio extends CommandLineOptionTest {
public static class Test implements CompilableTest {
private static final int TOTAL_ITERATIONS = 10000;
private static final int WARMUP_ITERATIONS = 1000;
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private final Object monitor = new Object();
// Following field have to be static in order to avoid escape analysis.
@SuppressWarnings("UnsuedDeclaration")
......
......@@ -51,7 +51,6 @@ import compiler.testlibrary.rtm.predicate.SupportedVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.test.lib.cli.CommandLineOptionTest;
import jdk.test.lib.cli.predicate.AndPredicate;
......@@ -158,7 +157,7 @@ public class TestRTMAfterNonRTMDeopt extends CommandLineOptionTest {
private static int field = 0;
private static final int ITERATIONS = 10000;
private static final int RANGE_CHECK_AT = ITERATIONS / 2;
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private final Object monitor = new Object();
@Override
......
......@@ -48,7 +48,6 @@ import compiler.testlibrary.rtm.predicate.SupportedVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.test.lib.cli.CommandLineOptionTest;
import jdk.test.lib.cli.predicate.AndPredicate;
......@@ -133,7 +132,7 @@ public class TestRTMDeoptOnLowAbortRatio extends CommandLineOptionTest {
}
public static class Test implements CompilableTest {
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private final Object monitor = new Object();
@Override
......
......@@ -49,7 +49,6 @@ import compiler.testlibrary.rtm.predicate.SupportedVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.test.lib.cli.CommandLineOptionTest;
import jdk.test.lib.cli.predicate.AndPredicate;
......@@ -142,7 +141,7 @@ public class TestRTMLockingThreshold extends CommandLineOptionTest {
@SuppressWarnings("UnsuedDeclaration")
private static int field = 0;
private static final int TOTAL_ITERATIONS = 10000;
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private final Object monitor = new Object();
......
......@@ -49,7 +49,6 @@ import compiler.testlibrary.rtm.predicate.SupportedVM;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.test.lib.cli.CommandLineOptionTest;
import jdk.test.lib.cli.predicate.AndPredicate;
......@@ -113,7 +112,7 @@ public class TestRTMTotalCountIncrRate extends CommandLineOptionTest {
public static class Test implements CompilableTest {
private static final long TOTAL_ITERATIONS = 10000L;
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private final Object monitor = new Object();
// Following field have to be static in order to avoid escape analysis.
@SuppressWarnings("UnsuedDeclaration")
......
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -25,7 +25,6 @@
package compiler.testlibrary.rtm;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.unsafe.UnsafeHelper;
/**
* Current RTM locking implementation force transaction abort
......@@ -35,7 +34,7 @@ class XAbortProvoker extends AbortProvoker {
// Following field have to be static in order to avoid escape analysis.
@SuppressWarnings("UnsuedDeclaration")
private static int field = 0;
private static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
public XAbortProvoker() {
this(new Object());
......
......@@ -35,7 +35,6 @@ package compiler.unsafe;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.Utils;
import jdk.test.lib.unsafe.UnsafeHelper;
import java.util.Random;
......@@ -82,7 +81,7 @@ public class UnsafeRaw {
}
public static void main(String[] args) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
final int array_size = 128;
final int element_size = 4;
final int magic = 0x12345678;
......
......@@ -37,7 +37,6 @@ import java.util.Collections;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
public class TestMaxMinHeapFreeRatioFlags {
......@@ -134,7 +133,7 @@ public class TestMaxMinHeapFreeRatioFlags {
*/
public static class RatioVerifier {
private static final Unsafe unsafe = UnsafeHelper.getUnsafe();
private static final Unsafe unsafe = Unsafe.getUnsafe();
// Size of byte array that will be allocated
public static final int CHUNK_SIZE = 1024;
......
......@@ -46,7 +46,6 @@ import jdk.internal.misc.Unsafe;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;
import jdk.test.lib.unsafe.UnsafeHelper;
import sun.hotspot.WhiteBox;
/* In order to test that TargetSurvivorRatio affects survivor space occupancy
......@@ -249,7 +248,7 @@ public class TestTargetSurvivorRatioFlag {
public static class TargetSurvivorRatioVerifier {
static final WhiteBox wb = WhiteBox.getWhiteBox();
static final Unsafe unsafe = UnsafeHelper.getUnsafe();
static final Unsafe unsafe = Unsafe.getUnsafe();
// Desired size of memory allocated at once
public static final int CHUNK_SIZE = 1024;
......
......@@ -34,13 +34,12 @@
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Platform;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
public class CreateCoredumpOnCrash {
private static class Crasher {
public static void main(String[] args) {
UnsafeHelper.getUnsafe().putInt(0L, 0);
Unsafe.getUnsafe().putInt(0L, 0);
}
}
......
......@@ -35,14 +35,13 @@
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
public class ProblematicFrameTest {
private static class Crasher {
public static void main(String[] args) {
UnsafeHelper.getUnsafe().getInt(0);
Unsafe.getUnsafe().getInt(0);
}
}
......
......@@ -30,12 +30,11 @@
* @run main AllocateInstance
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class AllocateInstance {
static final Unsafe UNSAFE = UnsafeHelper.getUnsafe();
static final Unsafe UNSAFE = Unsafe.getUnsafe();
class TestClass {
public boolean calledConstructor = false;
......
......@@ -31,13 +31,12 @@
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:MallocMaxTestWords=100m AllocateMemory
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class AllocateMemory {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
// Allocate a byte, write to the location and read back the value
long address = unsafe.allocateMemory(1);
......
......@@ -30,14 +30,13 @@
* @run main CopyMemory
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class CopyMemory {
final static int LENGTH = 8;
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
long src = unsafe.allocateMemory(LENGTH);
long dst = unsafe.allocateMemory(LENGTH);
assertNotEquals(src, 0L);
......
......@@ -34,13 +34,12 @@
import java.security.ProtectionDomain;
import java.io.InputStream;
import jdk.test.lib.InMemoryJavaCompiler;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class DefineClass {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
TestClassLoader classloader = new TestClassLoader();
ProtectionDomain pd = new ProtectionDomain(null, null);
......
......@@ -31,14 +31,13 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import java.lang.reflect.*;
import static jdk.test.lib.Asserts.*;
public class FieldOffset {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Field[] fields = Test.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
......
......@@ -30,14 +30,13 @@
* @run main GetField
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import java.lang.reflect.*;
import static jdk.test.lib.Asserts.*;
public class GetField {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
// Unsafe.INVALID_FIELD_OFFSET is a static final int field,
// make sure getField returns the correct field
Field field = Unsafe.class.getField("INVALID_FIELD_OFFSET");
......
......@@ -31,13 +31,12 @@
*/
import jdk.test.lib.Platform;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutAddress {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
int addressSize = unsafe.addressSize();
// Ensure the size returned from Unsafe.addressSize is correct
assertEquals(unsafe.addressSize(), Platform.is32bit() ? 4 : 8);
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutBoolean {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("b1");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutByte {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("b");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutChar {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("c");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutDouble {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("d");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutFloat {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("f");
......
......@@ -30,13 +30,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutInt {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("i");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutLong {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("l");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutObject {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Object o = new Object();
Field field = Test.class.getField("o");
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class GetPutShort {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Test t = new Test();
Field field = Test.class.getField("s");
......
......@@ -30,13 +30,12 @@
import static jdk.test.lib.Asserts.*;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
public class GetUncompressedObject {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
// Allocate some memory and fill it with non-zero values.
final int size = 32;
......
......@@ -35,7 +35,6 @@ import java.security.ProtectionDomain;
import java.io.InputStream;
import java.lang.*;
import jdk.test.lib.InMemoryJavaCompiler;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
......@@ -50,7 +49,7 @@ public class NestedUnsafe {
" } } ");
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
Class klass = unsafe.defineAnonymousClass(NestedUnsafe.class, klassbuf, new Object[0]);
unsafe.ensureClassInitialized(klass);
......
......@@ -31,13 +31,12 @@
*/
import java.lang.reflect.Field;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class PageSize {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
int pageSize = unsafe.pageSize();
for (int n = 1; n != 0; n <<= 1) {
......
......@@ -39,16 +39,7 @@ import jdk.internal.misc.Unsafe;
public class PrimitiveHostClass {
static final Unsafe U;
static {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
U = (Unsafe) theUnsafe.get(null);
} catch (Exception e) {
throw new AssertionError(e);
}
}
static final Unsafe U = Unsafe.getUnsafe();
public static void testVMAnonymousClass(Class<?> hostClass) {
......
......@@ -33,7 +33,6 @@
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Platform;
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
......@@ -60,7 +59,7 @@ public class RangeCheck {
public static class DummyClassWithMainRangeCheck {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
unsafe.getObject(new DummyClassWithMainRangeCheck(), Short.MAX_VALUE);
}
}
......
......@@ -31,13 +31,12 @@
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:MallocMaxTestWords=100m Reallocate
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class Reallocate {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
long address = unsafe.allocateMemory(1);
assertNotEquals(address, 0L);
......
......@@ -30,13 +30,12 @@
* @run main SetMemory
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class SetMemory {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
long address = unsafe.allocateMemory(1);
assertNotEquals(address, 0L);
unsafe.setMemory(address, 1, (byte)17);
......
......@@ -30,13 +30,12 @@
* @run main ThrowException
*/
import jdk.test.lib.unsafe.UnsafeHelper;
import jdk.internal.misc.Unsafe;
import static jdk.test.lib.Asserts.*;
public class ThrowException {
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
try {
unsafe.throwException(new TestException());
} catch (Throwable t) {
......
......@@ -48,20 +48,11 @@ import jdk.internal.vm.annotation.Contended;
*/
public class Basic {
private static final Unsafe U;
private static final Unsafe U = Unsafe.getUnsafe();
private static int ADDRESS_SIZE;
private static int HEADER_SIZE;
static {
// steal Unsafe
try {
Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
unsafe.setAccessible(true);
U = (Unsafe) unsafe.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
// When running with CompressedOops on 64-bit platform, the address size
// reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
// Try to guess the reference field size with this naive trick.
......
......@@ -49,20 +49,11 @@ import jdk.internal.vm.annotation.Contended;
*/
public class DefaultValue {
private static final Unsafe U;
private static final Unsafe U = Unsafe.getUnsafe();
private static int ADDRESS_SIZE;
private static int HEADER_SIZE;
static {
// steal Unsafe
try {
Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
unsafe.setAccessible(true);
U = (Unsafe) unsafe.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
// When running with CompressedOops on 64-bit platform, the address size
// reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
// Try to guess the reference field size with this naive trick.
......
......@@ -49,20 +49,11 @@ import jdk.internal.vm.annotation.Contended;
*/
public class Inheritance1 {
private static final Unsafe U;
private static final Unsafe U = Unsafe.getUnsafe();
private static int ADDRESS_SIZE;
private static int HEADER_SIZE;
static {
// steal Unsafe
try {
Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
unsafe.setAccessible(true);
U = (Unsafe) unsafe.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
// When running with CompressedOops on 64-bit platform, the address size
// reported by Unsafe is still 8, while the real reference fields are 4 bytes long.
// Try to guess the reference field size with this naive trick.
......
......@@ -39,7 +39,6 @@ import java.io.InputStream;
import java.lang.*;
import jdk.test.lib.*;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.unsafe.UnsafeHelper;
// Test that an anonymous class in package 'p' cannot define its own anonymous class
......@@ -54,7 +53,7 @@ public class NestedUnsafe {
" } } ");
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
// The anonymous class calls defineAnonymousClass creating a nested anonymous class.
byte klassbuf2[] = InMemoryJavaCompiler.compile("p.TestClass2",
......
......@@ -39,7 +39,6 @@ import java.io.InputStream;
import java.lang.*;
import jdk.test.lib.*;
import jdk.internal.misc.Unsafe;
import jdk.test.lib.unsafe.UnsafeHelper;
// Test that an anonymous class that gets put in its host's package cannot define
......@@ -54,7 +53,7 @@ public class NestedUnsafe2 {
" } } ");
public static void main(String args[]) throws Exception {
Unsafe unsafe = UnsafeHelper.getUnsafe();
Unsafe unsafe = Unsafe.getUnsafe();
// The anonymous class calls defineAnonymousClass creating a nested anonymous class.
byte klassbuf2[] = InMemoryJavaCompiler.compile("TestClass2",
......
......@@ -39,7 +39,7 @@ import java.util.regex.Pattern;
* Concrete subclasses should implement method {@link #process()}.
*/
public abstract class PathHandler {
private static final Unsafe UNSAFE = jdk.test.lib.unsafe.UnsafeHelper.getUnsafe();
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private static final AtomicLong CLASS_COUNT = new AtomicLong(0L);
private static volatile boolean CLASSES_LIMIT_REACHED = false;
private static final Pattern JAR_IN_DIR_PATTERN
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册