hotspot/test/compiler/stable/TestStableShort.java
changeset 25641 d99065e4572b
parent 23192 f6a1c8866065
child 26916 8a1deee4f9b4
--- a/hotspot/test/compiler/stable/TestStableShort.java	Mon Jul 14 03:24:35 2014 -0700
+++ b/hotspot/test/compiler/stable/TestStableShort.java	Mon Jul 14 03:25:40 2014 -0700
@@ -26,9 +26,11 @@
 /*
  * @test TestStableShort
  * @summary tests on stable fields and arrays
- * @library /testlibrary
- * @compile -XDignore.symbol.file TestStableShort.java
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestStableShort StableConfiguration sun.hotspot.WhiteBox
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  * @run main ClassFileInstaller
+ *           java/lang/invoke/StableConfiguration
  *           java/lang/invoke/TestStableShort
  *           java/lang/invoke/TestStableShort$ShortStable
  *           java/lang/invoke/TestStableShort$StaticShortStable
@@ -48,46 +50,60 @@
  *           java/lang/invoke/TestStableShort$NestedStableField3
  *           java/lang/invoke/TestStableShort$NestedStableField3$A
  *           java/lang/invoke/TestStableShort$DefaultValue
+ *           java/lang/invoke/TestStableShort$DefaultStaticValue
  *           java/lang/invoke/TestStableShort$ObjectArrayLowerDim2
  *
  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
- *                   -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:+UseCompressedOop
- *                   -server -XX:-TieredCompilation -Xcomp
+ *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
+ *                   -server -XX:-TieredCompilation
+ *                   -XX:+FoldStableValues
+ *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
+ *                   java.lang.invoke.TestStableShort
+ * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
+ *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
+ *                   -server -XX:-TieredCompilation
+ *                   -XX:-FoldStableValues
  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  *                   java.lang.invoke.TestStableShort
  *
  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
- *                   -XX:+UnlockDiagnosticVMOptions -XX:+FoldStableValues -XX:-UseCompressedOop
- *                   -server -XX:-TieredCompilation -Xcomp
+ *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
+ *                   -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
+ *                   -XX:+FoldStableValues
+ *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
+ *                   java.lang.invoke.TestStableShort
+ * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
+ *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
+ *                   -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1
+ *                   -XX:-FoldStableValues
  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  *                   java.lang.invoke.TestStableShort
  *
  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
- *                   -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:+UseCompressedOop
- *                   -server -XX:-TieredCompilation -Xcomp
+ *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
+ *                   -client -XX:-TieredCompilation
+ *                   -XX:+FoldStableValues
  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  *                   java.lang.invoke.TestStableShort
- *
  * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions
- *                   -XX:+UnlockDiagnosticVMOptions -XX:-FoldStableValues -XX:-UseCompressedOop
- *                   -server -XX:-TieredCompilation -Xcomp
+ *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp
+ *                   -client -XX:-TieredCompilation
+ *                   -XX:-FoldStableValues
  *                   -XX:CompileOnly=::get,::get1,::get2,::get3,::get4
  *                   java.lang.invoke.TestStableShort
  */
 package java.lang.invoke;
 
-import com.sun.management.HotSpotDiagnosticMXBean;
-import com.sun.management.VMOption;
-import sun.management.ManagementFactoryHelper;
 import java.lang.reflect.InvocationTargetException;
 
 public class TestStableShort {
+    static final boolean isStableEnabled    = StableConfiguration.isStableEnabled;
+    static final boolean isServerWithStable = StableConfiguration.isServerWithStable;
+
     public static void main(String[] args) throws Exception {
-        System.out.println("@Stable enabled: "+isStableEnabled);
-        System.out.println();
-
         run(DefaultValue.class);
         run(ShortStable.class);
+        run(DefaultStaticValue.class);
         run(StaticShortStable.class);
         run(VolatileShortStable.class);
 
@@ -145,6 +161,21 @@
 
     /* ==================================================== */
 
+    static class DefaultStaticValue {
+        public static @Stable short v;
+
+        public static final DefaultStaticValue c = new DefaultStaticValue();
+        public static short get() { return c.v; }
+        public static void test() throws Exception {
+                     short val1 = get();
+            c.v = 1; short val2 = get();
+            assertEquals(val1, 0);
+            assertEquals(val2, 1);
+        }
+    }
+
+    /* ==================================================== */
+
     static class StaticShortStable {
         public static @Stable short v;
 
@@ -188,20 +219,22 @@
                 c.v = new short[1]; c.v[0] = 1; short val1 = get();
                                     c.v[0] = 2; short val2 = get();
                 assertEquals(val1, 1);
-                assertEquals(val2, (isStableEnabled ? 1 : 2));
+                assertEquals(val2, (isServerWithStable ? 1 : 2));
 
                 c.v = new short[1]; c.v[0] = 3; short val3 = get();
-                assertEquals(val3, (isStableEnabled ? 1 : 3));
+                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 3));
             }
 
             {
                 c.v = new short[20]; c.v[10] = 1; short val1 = get1();
                                      c.v[10] = 2; short val2 = get1();
                 assertEquals(val1, 1);
-                assertEquals(val2, (isStableEnabled ? 1 : 2));
+                assertEquals(val2, (isServerWithStable ? 1 : 2));
 
                 c.v = new short[20]; c.v[10] = 3; short val3 = get1();
-                assertEquals(val3, (isStableEnabled ? 1 : 3));
+                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 3));
             }
 
             {
@@ -226,19 +259,21 @@
                 c.v = new short[1][1]; c.v[0][0] = 1; short val1 = get();
                                        c.v[0][0] = 2; short val2 = get();
                 assertEquals(val1, 1);
-                assertEquals(val2, (isStableEnabled ? 1 : 2));
+                assertEquals(val2, (isServerWithStable ? 1 : 2));
 
                 c.v = new short[1][1]; c.v[0][0] = 3; short val3 = get();
-                assertEquals(val3, (isStableEnabled ? 1 : 3));
+                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 3));
 
                 c.v[0] = new short[1]; c.v[0][0] = 4; short val4 = get();
-                assertEquals(val4, (isStableEnabled ? 1 : 4));
+                assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 4));
             }
 
             {
                 c.v = new short[1][1]; short[] val1 = get1();
                 c.v[0] = new short[1]; short[] val2 = get1();
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
@@ -264,28 +299,31 @@
                 c.v = new short[1][1][1]; c.v[0][0][0] = 1; short val1 = get();
                                           c.v[0][0][0] = 2; short val2 = get();
                 assertEquals(val1, 1);
-                assertEquals(val2, (isStableEnabled ? 1 : 2));
+                assertEquals(val2, (isServerWithStable ? 1 : 2));
 
                 c.v = new short[1][1][1]; c.v[0][0][0] = 3; short val3 = get();
-                assertEquals(val3, (isStableEnabled ? 1 : 3));
+                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 3));
 
                 c.v[0] = new short[1][1]; c.v[0][0][0] = 4; short val4 = get();
-                assertEquals(val4, (isStableEnabled ? 1 : 4));
+                assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 4));
 
                 c.v[0][0] = new short[1]; c.v[0][0][0] = 5; short val5 = get();
-                assertEquals(val5, (isStableEnabled ? 1 : 5));
+                assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 5));
             }
 
             {
                 c.v = new short[1][1][1]; short[] val1 = get1();
                 c.v[0][0] = new short[1]; short[] val2 = get1();
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
                 c.v = new short[1][1][1]; short[][] val1 = get2();
                 c.v[0] = new short[1][1]; short[][] val2 = get2();
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
@@ -312,37 +350,41 @@
                 c.v = new short[1][1][1][1]; c.v[0][0][0][0] = 1; short val1 = get();
                                              c.v[0][0][0][0] = 2; short val2 = get();
                 assertEquals(val1, 1);
-                assertEquals(val2, (isStableEnabled ? 1 : 2));
+                assertEquals(val2, (isServerWithStable ? 1 : 2));
 
                 c.v = new short[1][1][1][1]; c.v[0][0][0][0] = 3; short val3 = get();
-                assertEquals(val3, (isStableEnabled ? 1 : 3));
+                assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 3));
 
                 c.v[0] = new short[1][1][1]; c.v[0][0][0][0] = 4; short val4 = get();
-                assertEquals(val4, (isStableEnabled ? 1 : 4));
+                assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 4));
 
                 c.v[0][0] = new short[1][1]; c.v[0][0][0][0] = 5; short val5 = get();
-                assertEquals(val5, (isStableEnabled ? 1 : 5));
+                assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 5));
 
                 c.v[0][0][0] = new short[1]; c.v[0][0][0][0] = 6; short val6 = get();
-                assertEquals(val6, (isStableEnabled ? 1 : 6));
+                assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2)
+                                                    : 6));
             }
 
             {
                 c.v = new short[1][1][1][1]; short[] val1 = get1();
                 c.v[0][0][0] = new short[1]; short[] val2 = get1();
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
                 c.v = new short[1][1][1][1]; short[][] val1 = get2();
                 c.v[0][0] = new short[1][1]; short[][] val2 = get2();
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
                 c.v = new short[1][1][1][1]; short[][][] val1 = get3();
                 c.v[0] = new short[1][1][1]; short[][][] val2 = get3();
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
@@ -350,13 +392,11 @@
                 c.v = new short[1][1][1][1]; short[][][][] val2 = get4();
                 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
             }
-
         }
     }
 
     /* ==================================================== */
     // Dynamic Dim is higher than static
-
     static class ObjectArrayLowerDim0 {
         public @Stable Object v;
 
@@ -404,7 +444,7 @@
                 c.v = new short[1][1]; c.v[0] = new short[0]; short[] val1 = get1();
                                        c.v[0] = new short[0]; short[] val2 = get1();
 
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
@@ -440,14 +480,14 @@
                 c.v = new short[1][1][1]; c.v[0][0] = new short[0]; short[] val1 = get1();
                                           c.v[0][0] = new short[0]; short[] val2 = get1();
 
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
                 c.v = new short[1][1][1]; c.v[0] = new short[0][0]; short[][] val1 = get2();
                                           c.v[0] = new short[0][0]; short[][] val2 = get2();
 
-                assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2)));
+                assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2)));
             }
 
             {
@@ -582,7 +622,7 @@
                                elem.a = 2; short val3 = get(); short val4 = get1();
 
                 assertEquals(val1, 1);
-                assertEquals(val3, (isStableEnabled ? 1 : 2));
+                assertEquals(val3, (isServerWithStable ? 1 : 2));
 
                 assertEquals(val2, 1);
                 assertEquals(val4, 2);
@@ -616,17 +656,4 @@
             }
         }
     }
-
-    static final boolean isStableEnabled;
-    static {
-        HotSpotDiagnosticMXBean diagnostic
-                = ManagementFactoryHelper.getDiagnosticMXBean();
-        VMOption tmp;
-        try {
-            tmp = diagnostic.getVMOption("FoldStableValues");
-        } catch (IllegalArgumentException e) {
-            tmp = null;
-        }
-        isStableEnabled = (tmp == null ? false : Boolean.parseBoolean(tmp.getValue()));
-    }
 }