8039497: Testlibrary should be updated to provide information about all VM types as well as access to Unsafe
authoriignatyev
Fri, 11 Apr 2014 00:34:56 +0400
changeset 24004 f03d58333c6e
parent 24003 372cef87666e
child 24005 6841a4be0faa
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
hotspot/test/testlibrary/com/oracle/java/testlibrary/Platform.java
hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Platform.java	Fri Apr 11 00:34:51 2014 +0400
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Platform.java	Fri Apr 11 00:34:56 2014 +0400
@@ -30,13 +30,25 @@
     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");
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java	Fri Apr 11 00:34:51 2014 +0400
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java	Fri Apr 11 00:34:56 2014 +0400
@@ -38,6 +38,8 @@
 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 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 @@
 
     /**
      * 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 @@
         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'};
 
     /**