8039497: Testlibrary should be updated to provide information about all VM types as well as access to Unsafe

Reviewed-by: kvn, iignatyev
This commit is contained in:
Filipp Zhinkin 2014-04-11 00:34:56 +04:00 committed by Igor Ignatyev
parent 2b032b10e1
commit 04d2944301
2 changed files with 39 additions and 8 deletions

View file

@ -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 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 isEmbedded() {
return vmName.contains("Embedded");
}
public static boolean is32bit() {
return dataModel.equals("32");

View file

@ -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'};
/**