--- a/hotspot/test/compiler/jvmci/SecurityRestrictionsTest.java Thu Oct 15 07:56:53 2015 +0000
+++ b/hotspot/test/compiler/jvmci/SecurityRestrictionsTest.java Thu Oct 15 11:20:04 2015 +0000
@@ -51,6 +51,8 @@
import java.lang.InternalError;
import java.security.AccessControlException;
import java.security.Permission;
+import java.util.PropertyPermission;
+import java.util.function.Consumer;
public class SecurityRestrictionsTest {
@@ -121,9 +123,12 @@
private boolean isJvmciPermission(Permission perm) {
String name = perm.getName();
- return perm instanceof RuntimePermission
+ boolean isJvmciRuntime = perm instanceof RuntimePermission
&& (JVMCI_SERVICES.equals(name)
- || name.startsWith(JVMCI_RT_PERM_START));
+ || name.startsWith(JVMCI_RT_PERM_START));
+ boolean isJvmciProperty = perm instanceof PropertyPermission
+ && name.startsWith(JVMCI_PROP_START);
+ return isJvmciRuntime || isJvmciProperty;
}
@Override
@@ -134,10 +139,32 @@
public void run() {
System.setSecurityManager(getSecurityManager());
- Utils.runAndCheckException(
- // to run CompilerToVM::<cinit> inside runAndCheckException
- () -> new CompilerToVM(),
- getExpectedException());
+ Consumer<Throwable> exceptionCheck = e -> {
+ if (e == null) {
+ if (getExpectedException() != null) {
+ String message = name() + ": Didn't get expected exception "
+ + getExpectedException();
+ throw new AssertionError(message);
+ }
+ } else {
+ String message = name() + ": Got unexpected exception "
+ + e.getClass().getSimpleName();
+ if (getExpectedException() == null){
+ throw new AssertionError(message, e);
+ }
+
+ Throwable t = e;
+ while (t.getCause() != null) {
+ t = t.getCause();
+ }
+ if (!getExpectedException().isAssignableFrom(t.getClass())) {
+ message += " instead of " + getExpectedException()
+ .getSimpleName();
+ throw new AssertionError(message, e);
+ }
+ }
+ };
+ Utils.runAndCheckException(CompilerToVM::new, exceptionCheck);
}
public SecurityManager getSecurityManager() {
@@ -152,5 +179,6 @@
= "accessClassInPackage.jdk.vm.ci";
private static final String JVMCI_SERVICES = "jvmciServices";
private static final String JVMCI_PROP_START = "jvmci.";
+
}
}
--- a/hotspot/test/compiler/jvmci/compilerToVM/ExecuteInstalledCodeTest.java Thu Oct 15 07:56:53 2015 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/ExecuteInstalledCodeTest.java Thu Oct 15 11:20:04 2015 +0000
@@ -20,6 +20,7 @@
/*
* @test
* @bug 8136421
+ * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
* @library /testlibrary /../../test/lib /
* @compile ../common/CompilerToVMHelper.java
* @build sun.hotspot.WhiteBox
--- a/hotspot/test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java Thu Oct 15 07:56:53 2015 +0000
+++ b/hotspot/test/compiler/jvmci/compilerToVM/MaterializeVirtualObjectTest.java Thu Oct 15 11:20:04 2015 +0000
@@ -33,16 +33,22 @@
* jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
- * -XX:CompileCommand=exclude,*::check -XX:+DoEscapeAnalysis
+ * -XX:CompileCommand=exclude,*::check -XX:+DoEscapeAnalysis -Xbatch
+ * -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=false
+ * compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ * -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
+ * -XX:CompileCommand=exclude,*::check -XX:+DoEscapeAnalysis -Xbatch
+ * -Dcompiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate=true
* compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest
*/
package compiler.jvmci.compilerToVM;
import compiler.jvmci.common.CTVMUtilities;
+import compiler.testlibrary.CompilerUtils;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.test.lib.Asserts;
-import jdk.test.lib.Utils;
import sun.hotspot.WhiteBox;
import java.lang.reflect.Method;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl;
@@ -50,64 +56,74 @@
public class MaterializeVirtualObjectTest {
private static final WhiteBox WB = WhiteBox.getWhiteBox();
- private static final int INVOCATIONS = 100_000;
private static final Method METHOD;
private static final HotSpotResolvedJavaMethodImpl RESOLVED_METHOD;
- private final boolean invalidate;
+ private static final boolean INVALIDATE = Boolean.getBoolean(
+ "compiler.jvmci.compilerToVM.MaterializeVirtualObjectTest.invalidate");
static {
try {
METHOD = MaterializeVirtualObjectTest.class.getDeclaredMethod(
- "testFrame", String.class, Integer.class);
+ "testFrame", String.class, boolean.class);
} catch (NoSuchMethodException e) {
throw new Error("Can't get executable for test method", e);
}
RESOLVED_METHOD = CTVMUtilities.getResolvedMethod(METHOD);
}
- public MaterializeVirtualObjectTest(boolean invalidate) {
- this.invalidate = invalidate;
+ public static void main(String[] args) {
+ int levels[] = CompilerUtils.getAvailableCompilationLevels();
+ // we need compilation level 4 to use EscapeAnalysis
+ if (levels.length < 1 || levels[levels.length - 1] != 4) {
+ System.out.println("INFO: Test needs compilation level 4 to"
+ + " be available. Skipping.");
+ } else {
+ new MaterializeVirtualObjectTest().test();
+ }
}
- public static void main(String[] args) {
- new MaterializeVirtualObjectTest(true).test();
- new MaterializeVirtualObjectTest(false).test();
+ private static String getName() {
+ return "CASE: invalidate=" + INVALIDATE;
}
private void test() {
- System.out.printf("CASE: invalidate=%b%n", invalidate);
- for (int i = 0; i < INVOCATIONS; i++) {
- testFrame("someString", i);
- }
- Utils.waitForCondition(() -> WB.isMethodCompiled(METHOD), 100L);
- Asserts.assertTrue(WB.isMethodCompiled(METHOD));
- testFrame("someString", INVOCATIONS);
+ System.out.println(getName());
+ Asserts.assertFalse(WB.isMethodCompiled(METHOD), getName()
+ + " : method unexpectedly compiled");
+ /* need to call testFrame at least once to be able to compile it, so
+ calling with materialize=false, because testFrame is not compiled */
+ testFrame("someString", /* materialize= */ false);
+ WB.enqueueMethodForCompilation(METHOD, 4);
+ Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
+ + "Method unexpectedly not compiled");
+ // calling with materialize=true to materialize compiled testFrame
+ testFrame("someString", /* materialize= */ true);
}
- private void testFrame(String str, Integer iteration) {
+ private void testFrame(String str, boolean materialize) {
Helper helper = new Helper(str);
- check(iteration);
+ check(materialize);
Asserts.assertTrue((helper.string != null) && (this != null)
- && (helper != null), "Some locals are null");
+ && (helper != null), getName() + " : some locals are null");
}
- private void check(int iteration) {
+ private void check(boolean materialize) {
// Materialize virtual objects on last invocation
- if (iteration == INVOCATIONS) {
+ if (materialize) {
HotSpotStackFrameReference hsFrame = CompilerToVMHelper
.getNextStackFrame(/* topmost frame */ null,
new HotSpotResolvedJavaMethodImpl[]{
RESOLVED_METHOD}, /* don't skip any */ 0);
- Asserts.assertNotNull(hsFrame, "Got null frame");
- Asserts.assertTrue(WB.isMethodCompiled(METHOD),
- "Expected test method to be compiled");
- Asserts.assertTrue(hsFrame.hasVirtualObjects(),
- "Has no virtual object before materialization");
- CompilerToVMHelper.materializeVirtualObjects(hsFrame, invalidate);
- Asserts.assertFalse(hsFrame.hasVirtualObjects(),
- "Has virtual object after materialization");
- Asserts.assertEQ(WB.isMethodCompiled(METHOD), !invalidate,
- "Unexpected compiled status");
+ Asserts.assertNotNull(hsFrame, getName() + " : got null frame");
+ Asserts.assertTrue(WB.isMethodCompiled(METHOD), getName()
+ + "Test method should be compiled");
+ Asserts.assertTrue(hsFrame.hasVirtualObjects(), getName()
+ + ": has no virtual object before materialization");
+ CompilerToVMHelper.materializeVirtualObjects(hsFrame, INVALIDATE);
+ Asserts.assertFalse(hsFrame.hasVirtualObjects(), getName()
+ + " : has virtual object after materialization");
+ Asserts.assertEQ(WB.isMethodCompiled(METHOD), !INVALIDATE, getName()
+ + " : unexpected compiled status");
}
}
--- a/hotspot/test/testlibrary/jdk/test/lib/Utils.java Thu Oct 15 07:56:53 2015 +0000
+++ b/hotspot/test/testlibrary/jdk/test/lib/Utils.java Thu Oct 15 11:20:04 2015 +0000
@@ -41,9 +41,9 @@
import java.util.Random;
import java.util.function.BooleanSupplier;
import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import sun.misc.Unsafe;
/**
@@ -480,23 +480,34 @@
* @param expectedException expected exception
*/
public static void runAndCheckException(Runnable runnable, Class<? extends Throwable> expectedException) {
- boolean expectedExceptionWasNotThrown = false;
+ runAndCheckException(runnable, t -> {
+ if (t == null) {
+ if (expectedException != null) {
+ throw new AssertionError("Didn't get expected exception " + expectedException.getSimpleName());
+ }
+ } else {
+ String message = "Got unexpected exception " + t.getClass().getSimpleName();
+ if (expectedException == null) {
+ throw new AssertionError(message, t);
+ } else if (!expectedException.isAssignableFrom(t.getClass())) {
+ message += " instead of " + expectedException.getSimpleName();
+ throw new AssertionError(message, t);
+ }
+ }
+ });
+ }
+
+ /**
+ * Runs runnable and makes some checks to ensure that it throws expected exception.
+ * @param runnable what we run
+ * @param checkException a consumer which checks that we got expected exception and raises a new exception otherwise
+ */
+ public static void runAndCheckException(Runnable runnable, Consumer<Throwable> checkException) {
try {
runnable.run();
- if (expectedException != null) {
- expectedExceptionWasNotThrown = true;
- }
+ checkException.accept(null);
} catch (Throwable t) {
- if (expectedException == null) {
- throw new AssertionError("Got unexpected exception ", t);
- }
- if (!expectedException.isAssignableFrom(t.getClass())) {
- throw new AssertionError(String.format("Got unexpected exception %s instead of %s",
- t.getClass().getSimpleName(), expectedException.getSimpleName()), t);
- }
- }
- if (expectedExceptionWasNotThrown) {
- throw new AssertionError("Didn't get expected exception " + expectedException.getSimpleName());
+ checkException.accept(t);
}
}