提交 e00c70f2 编写于 作者: I iignatyev

8039497: Testlibrary should be updated to provide information about all VM...

8039497: Testlibrary should be updated to provide information about all VM types as well as access to Unsafe
Reviewed-by: kvn, iignatyev
Contributed-by: filipp.zhinkin@oracle.com
上级 cc79ea3e
......@@ -30,13 +30,25 @@ public class Platform {
private static final String osArch = System.getProperty("os.arch");
private static final String vmName = System.getProperty("java.vm.name");
public static boolean isClient() {
return vmName.endsWith(" Client VM");
}
public static boolean isClient() {
return vmName.endsWith(" Client VM");
}
public static boolean isServer() {
return vmName.endsWith(" Server VM");
}
public static boolean isGraal() {
return vmName.endsWith(" Graal VM");
}
public static boolean isMinimal() {
return vmName.endsWith(" Minimal VM");
}
public static boolean isServer() {
return vmName.endsWith(" Server VM");
}
public static boolean isEmbedded() {
return vmName.contains("Embedded");
}
public static boolean is32bit() {
return dataModel.equals("32");
......
......@@ -38,6 +38,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.lang.reflect.Field;
import sun.misc.Unsafe;
/**
* Common library for various test helper functions.
......@@ -59,6 +61,8 @@ public final class Utils {
*/
public static final String JAVA_OPTIONS = System.getProperty("test.java.opts", "").trim();
private static Unsafe unsafe = null;
/**
* Returns the value of 'test.timeout.factor' system property
* converted to {@code double}.
......@@ -109,10 +113,10 @@ public final class Utils {
/**
* Returns the default JTReg arguments for a jvm running a test without
* options that matches regular expresions in {@code filters}.
* options that matches regular expressions in {@code filters}.
* This is the combination of JTReg arguments test.vm.opts and test.java.opts.
* @param filters Regular expressions used to filter out options.
* @return An array of options, or an empty array if no opptions.
* @return An array of options, or an empty array if no options.
*/
public static String[] getFilteredTestJavaOpts(String... filters) {
String options[] = getTestJavaOpts();
......@@ -294,6 +298,21 @@ public final class Utils {
return output;
}
/**
* @return Unsafe instance.
*/
public static synchronized Unsafe getUnsafe() {
if (unsafe == null) {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe) f.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("Unable to get Unsafe instance.", e);
}
}
return unsafe;
}
private static final char[] hexArray = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册