changeset 240:4768218cfa50

Runners: move to auto-detect and auto-enable JVM features, instead of asking users to do that.
author shade
date Thu, 12 May 2016 15:01:11 +0300
parents f1395382fbc4
children 5349847b972e
files jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java jcstress-core/src/main/java/org/openjdk/jcstress/Main.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java jcstress-core/src/main/java/org/openjdk/jcstress/util/ContendedSupport.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/ContendedTestMain.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/DeoptTestMain.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/SimpleTestMain.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupportException.java jcstress-core/src/main/java/org/openjdk/jcstress/vm/WhiteBoxSupport.java
diffstat 12 files changed, 422 insertions(+), 102 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java	Wed May 11 18:50:43 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/ForkedMain.java	Thu May 12 15:01:11 2016 +0300
@@ -25,7 +25,7 @@
 package org.openjdk.jcstress;
 
 import org.openjdk.jcstress.infra.collectors.NetworkOutputCollector;
-import org.openjdk.jcstress.util.VMSupport;
+import org.openjdk.jcstress.vm.WhiteBoxSupport;
 
 /**
  * Entry point for the forked VM run.
@@ -41,7 +41,7 @@
         }
 
         try {
-            VMSupport.tryInit();
+            WhiteBoxSupport.initSafely();
         } catch (NoClassDefFoundError e) {
             // expected on JDK 7 and lower, parent should have printed the message for user
         }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Wed May 11 18:50:43 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Thu May 12 15:01:11 2016 +0300
@@ -40,9 +40,9 @@
 import org.openjdk.jcstress.infra.runners.Runner;
 import org.openjdk.jcstress.infra.runners.TestList;
 import org.openjdk.jcstress.util.InputStreamDrainer;
+import org.openjdk.jcstress.vm.VMSupport;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
@@ -157,8 +157,9 @@
 
     void runForked0(Options opts, String test, TestResultCollector collector) {
         try {
-            Collection<String> commandString = getSeparateExecutionCommand(opts, test);
-            Process p = Runtime.getRuntime().exec(commandString.toArray(new String[commandString.size()]));
+            List<String> commandString = getSeparateExecutionCommand(opts, test);
+            ProcessBuilder pb = new ProcessBuilder(commandString);
+            Process p = pb.start();
 
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
@@ -223,19 +224,11 @@
         }
     }
 
-    public Collection<String> getSeparateExecutionCommand(Options opts, String test) {
+    public List<String> getSeparateExecutionCommand(Options opts, String test) {
         List<String> command = new ArrayList<>();
 
-        // jvm path
-        command.add(getDefaultJvm());
-
-        // jvm classpath
-        command.add("-cp");
-        if (isWindows()) {
-            command.add('"' + System.getProperty("java.class.path") + '"');
-        } else {
-            command.add(System.getProperty("java.class.path"));
-        }
+        List<String> o = VMSupport.getJavaInvokeLine();
+        command.addAll(o);
 
         // jvm args
         command.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments());
@@ -262,21 +255,6 @@
         return command;
     }
 
-    private String getDefaultJvm() {
-        StringBuilder javaExecutable = new StringBuilder();
-        javaExecutable.append(System.getProperty("java.home"));
-        javaExecutable.append(File.separator);
-        javaExecutable.append("bin");
-        javaExecutable.append(File.separator);
-        javaExecutable.append("java");
-        javaExecutable.append(isWindows() ? ".exe" : "");
-        return javaExecutable.toString();
-    }
-
-    private boolean isWindows() {
-        return System.getProperty("os.name").contains("indows");
-    }
-
     static SortedSet<String> getTests(final String filter) {
         SortedSet<String> s = new TreeSet<>();
 
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Main.java	Wed May 11 18:50:43 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Main.java	Thu May 12 15:01:11 2016 +0300
@@ -24,8 +24,7 @@
  */
 package org.openjdk.jcstress;
 
-import org.openjdk.jcstress.util.ContendedSupport;
-import org.openjdk.jcstress.util.VMSupport;
+import org.openjdk.jcstress.vm.VMSupport;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -57,30 +56,8 @@
                 System.out.println(test);
             }
         } else {
-            boolean vmSupportInited;
-            try {
-                vmSupportInited = VMSupport.tryInit();
-            } catch (NoClassDefFoundError c) {
-                // expected on JDK 7 and lower
-                vmSupportInited = false;
-            }
-
-            if (!vmSupportInited) {
-                System.out.println("Non-fatal: VM support for online deoptimization is not enabled, tests might miss some issues.\nPossible reasons are:\n" +
-                        "  1) unsupported JDK, only JDK 8+ is supported; \n" +
-                        "  2) -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI are missing; \n" +
-                        "  3) the jcstress JAR is not added to -Xbootclasspath/a\n");
-            } else {
-                System.out.println("VM support is initialized.\n");
-            }
-
-            if (!ContendedSupport.tryContended()) {
-                System.out.println("Non-fatal: VM support for @Contended is not enabled, tests might run slower.\nPossible reasons are:\n" +
-                        "  1) unsupported JDK, only JDK 8+ is supported; \n" +
-                        "  2) -XX:-RestrictContended is missing, or the jcstress JAR is not added to -Xbootclasspath/a\n");
-            } else {
-                System.out.println("@Contended is in use.\n");
-            }
+            VMSupport.initSupport();
+            VMSupport.detectAvailableVMModes();
 
             new JCStress().run(opts);
         }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Wed May 11 18:50:43 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/processors/JCStressTestProcessor.java	Thu May 12 15:01:11 2016 +0300
@@ -32,6 +32,7 @@
 import org.openjdk.jcstress.infra.runners.StateHolder;
 import org.openjdk.jcstress.infra.runners.TestList;
 import org.openjdk.jcstress.util.*;
+import org.openjdk.jcstress.vm.WhiteBoxSupport;
 
 import javax.annotation.processing.AbstractProcessor;
 import javax.annotation.processing.RoundEnvironment;
@@ -556,7 +557,7 @@
         pw.println("        testLog.print(\"Iterations \");");
         pw.println("        for (int c = 0; c < control.iters; c++) {");
         pw.println("            try {");
-        pw.println("                VMSupport.tryDeoptimizeAllInfra(control.deoptRatio);");
+        pw.println("                WhiteBoxSupport.tryDeoptimizeAllInfra(control.deoptRatio);");
         pw.println("            } catch (NoClassDefFoundError err) {");
         pw.println("                // gracefully \"handle\"");
         pw.println("            }");
@@ -724,7 +725,7 @@
                 Options.class, TestResultCollector.class,
                 Control.class, Runner.class, StateHolder.class,
                 ArrayUtils.class, Counter.class,
-                VMSupport.class, OpenAddressHashCounter.class, ExecutionException.class
+                WhiteBoxSupport.class, OpenAddressHashCounter.class, ExecutionException.class
         };
 
         for (Class<?> c : imports) {
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java	Wed May 11 18:50:43 2016 +0300
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/runners/Runner.java	Thu May 12 15:01:11 2016 +0300
@@ -30,7 +30,7 @@
 import org.openjdk.jcstress.infra.collectors.TestResultCollector;
 import org.openjdk.jcstress.util.Counter;
 import org.openjdk.jcstress.util.NullOutputStream;
-import org.openjdk.jcstress.util.VMSupport;
+import org.openjdk.jcstress.vm.WhiteBoxSupport;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -90,7 +90,7 @@
         testLog.print("Iterations ");
         for (int c = 0; c < control.iters; c++) {
             try {
-                VMSupport.tryDeoptimizeAllInfra(control.deoptRatio);
+                WhiteBoxSupport.tryDeoptimizeAllInfra(control.deoptRatio);
             } catch (NoClassDefFoundError err) {
                 // gracefully "handle"
             }
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/util/ContendedSupport.java	Wed May 11 18:50:43 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2005, 2014, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package org.openjdk.jcstress.util;
-
-import org.openjdk.jcstress.infra.results.IntResult2;
-import org.openjdk.jcstress.util.UnsafeHolder;
-
-public class ContendedSupport {
-    public static boolean tryContended() {
-        try {
-            long o1 = UnsafeHolder.U.objectFieldOffset(IntResult2.class.getField("r1"));
-            long o2 = UnsafeHolder.U.objectFieldOffset(IntResult2.class.getField("r2"));
-
-            return Math.abs(o2 - o1) >= 64;
-        } catch (NoSuchFieldException e) {
-            throw new IllegalStateException();
-        }
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/ContendedTestMain.java	Thu May 12 15:01:11 2016 +0300
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014, 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.vm;
+
+import org.openjdk.jcstress.infra.results.IntResult2;
+import org.openjdk.jcstress.util.UnsafeHolder;
+
+public class ContendedTestMain {
+
+    public static void main(String... args) throws NoSuchFieldException {
+        long o1 = UnsafeHolder.U.objectFieldOffset(IntResult2.class.getField("r1"));
+        long o2 = UnsafeHolder.U.objectFieldOffset(IntResult2.class.getField("r2"));
+
+        if (Math.abs(o2 - o1) < 64) {
+            throw new IllegalStateException("@Contended does not seem to be working.");
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/DeoptTestMain.java	Thu May 12 15:01:11 2016 +0300
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.vm;
+
+public class DeoptTestMain {
+
+    public static void main(String... args) throws Throwable {
+        WhiteBoxSupport.init();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/SimpleTestMain.java	Thu May 12 15:01:11 2016 +0300
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.vm;
+
+public class SimpleTestMain {
+
+    public static void main(String... args) {
+        // do nothing
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupport.java	Thu May 12 15:01:11 2016 +0300
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2005, 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.vm;
+
+import org.openjdk.jcstress.util.InputStreamDrainer;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+
+public class VMSupport {
+
+    private static final List<String> ADD_JVM_FLAGS = new ArrayList<>();
+    private static final List<List<String>> AVAIL_JVM_MODES = new ArrayList<>();
+
+    public static void initSupport() {
+        System.out.println("Initializing and probing the target VM: ");
+        System.out.println(" (all failures are non-fatal, but may affect testing accuracy)");
+        System.out.println();
+
+        detect("Unlocking diagnostic VM options",
+                "-XX:+UnlockDiagnosticVMOptions",
+                SimpleTestMain.class);
+
+        detect("@Contended support for avoiding false sharing",
+                "-XX:-RestrictContended",
+                ContendedTestMain.class);
+
+        detect("Whitebox API for online de-optimization",
+                "-XX:+WhiteBoxAPI",
+                DeoptTestMain.class);
+
+        System.out.println();
+    }
+
+    private static void detect(String label, String opt, Class<?> mainClass) {
+        try {
+            tryWith(opt, mainClass.getName());
+            ADD_JVM_FLAGS.add(opt);
+            System.out.printf("----- %s %s%n", "[OK]", label);
+        } catch (VMSupportException ex) {
+            System.out.printf("----- %s %s%n", "[FAILED]", label);
+            System.out.println(ex.getMessage());
+        }
+    }
+
+    public static void detectAvailableVMModes() {
+        List<List<String>> modes = Arrays.asList(
+                Arrays.asList("-Xint"),
+                Arrays.asList("-client"),
+                Arrays.asList("-server"),
+                Arrays.asList("-server", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM"),
+                Arrays.asList("-XX:-TieredCompilation"),
+                Arrays.asList("-XX:-TieredCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+StressLCM", "-XX:+StressGCM"),
+                Arrays.asList("-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1"),
+                Arrays.asList("-XX:+TieredCompilation", "-XX:TieredStopAtLevel=2"),
+                Arrays.asList("-XX:+TieredCompilation", "-XX:TieredStopAtLevel=3")
+        );
+
+        System.out.println("Probing what VM modes are available:");
+        System.out.println(" (failures are non-fatal, but may miss some interesting cases)");
+        System.out.println();
+        for (List<String> mode : modes) {
+            try {
+                List<String> line = new ArrayList<>(mode);
+                line.add(SimpleTestMain.class.getName());
+                tryWith(line.toArray(new String[0]));
+                AVAIL_JVM_MODES.add(mode);
+                System.out.printf("   [OK] %s%n", mode);
+            } catch (VMSupportException e) {
+                System.out.printf("  [N/A] %s%n", mode);
+            }
+        }
+        System.out.println();
+    }
+
+    public static void tryWith(String... lines) throws VMSupportException {
+        try {
+            List<String> commandString = getJavaInvokeLine();
+            commandString.addAll(Arrays.asList(lines));
+
+            ProcessBuilder pb = new ProcessBuilder(commandString);
+            Process p = pb.start();
+
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+            InputStreamDrainer errDrainer = new InputStreamDrainer(p.getErrorStream(), baos);
+            InputStreamDrainer outDrainer = new InputStreamDrainer(p.getInputStream(), baos);
+
+            errDrainer.start();
+            outDrainer.start();
+
+            int ecode = p.waitFor();
+
+            errDrainer.join();
+            outDrainer.join();
+
+            if (ecode != 0) {
+                String msg = new String(baos.toByteArray());
+                throw new VMSupportException(msg);
+            }
+        } catch (IOException | InterruptedException ex) {
+            throw new VMSupportException(ex.getMessage());
+        }
+    }
+
+    public static List<String> getJavaInvokeLine() {
+        List<String> command = new ArrayList<>();
+
+        // jvm path
+        command.add(getDefaultJvm());
+
+        // jvm classpath
+        command.add("-cp");
+        if (isWindows()) {
+            command.add('"' + System.getProperty("java.class.path") + '"');
+        } else {
+            command.add(System.getProperty("java.class.path"));
+        }
+
+        command.addAll(ADD_JVM_FLAGS);
+
+        return command;
+    }
+
+    private static String getDefaultJvm() {
+        StringBuilder javaExecutable = new StringBuilder();
+        javaExecutable.append(System.getProperty("java.home"));
+        javaExecutable.append(File.separator);
+        javaExecutable.append("bin");
+        javaExecutable.append(File.separator);
+        javaExecutable.append("java");
+        javaExecutable.append(isWindows() ? ".exe" : "");
+        return javaExecutable.toString();
+    }
+
+    private static boolean isWindows() {
+        return System.getProperty("os.name").contains("indows");
+    }
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/VMSupportException.java	Thu May 12 15:01:11 2016 +0300
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014, 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.vm;
+
+public class VMSupportException extends Exception {
+    public VMSupportException(String msg) {
+        super(msg);
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/vm/WhiteBoxSupport.java	Thu May 12 15:01:11 2016 +0300
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2014, 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jcstress.vm;
+
+import org.openjdk.jcstress.util.Reflections;
+import sun.hotspot.WhiteBox;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.ThreadLocalRandom;
+
+public class WhiteBoxSupport {
+
+    private static WhiteBox whiteBox;
+    private static volatile boolean tried;
+    private static volatile Collection<Method> infraMethods;
+
+    public static void init() throws Throwable {
+        if (tried) return;
+        try {
+            WhiteBox w = WhiteBox.getWhiteBox();
+            w.deoptimizeAll();
+            whiteBox = w;
+        } finally {
+            tried = true;
+        }
+    }
+
+    public static void initSafely() {
+        if (tried) return;
+        try {
+            WhiteBox w = WhiteBox.getWhiteBox();
+            w.deoptimizeAll();
+            whiteBox = w;
+        } catch (Throwable e) {
+            // expected
+        } finally {
+            tried = true;
+        }
+    }
+
+    public static void tryDeoptimizeAllInfra(int actionProbRatio) {
+        WhiteBox w = whiteBox;
+        if (w != null) {
+            if (ThreadLocalRandom.current().nextInt(actionProbRatio) != 0)
+                return;
+
+            try {
+                Collection<Method> im = infraMethods;
+                if (im == null) {
+                    im = new ArrayList<>();
+                    Collection<String> infraNames = new ArrayList<>();
+                    infraNames.addAll(Reflections.getClassNames("org.openjdk.jcstress.infra"));
+                    infraNames.addAll(Reflections.getClassNames("org.openjdk.jcstress.util"));
+                    for (String name : infraNames) {
+                        try {
+                            Class<?> aClass = Class.forName(name);
+                            Collections.addAll(im, aClass.getDeclaredMethods());
+                        } catch (ClassNotFoundException e) {
+                            throw new IllegalStateException();
+                        }
+                    }
+                    infraMethods = im;
+                }
+
+                for (Method m : im) {
+                    w.deoptimizeMethod(m);
+                }
+            } catch (IOException e) {
+                throw new IllegalStateException();
+            }
+        }
+    }
+
+}