2015-10-08 22:49:30 +00:00
|
|
|
/*
|
2016-08-19 14:06:30 +00:00
|
|
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
2015-10-08 22:49:30 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @bug 8136421
|
2016-06-17 10:07:27 +00:00
|
|
|
* @requires (vm.simpleArch == "x64" | vm.simpleArch == "sparcv9" | vm.simpleArch == "aarch64")
|
2016-08-19 14:06:30 +00:00
|
|
|
* @library /test/lib /
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @library common/patches
|
2016-05-01 09:47:00 +00:00
|
|
|
* @modules java.base/jdk.internal.misc
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @modules jdk.vm.ci/jdk.vm.ci.hotspot
|
|
|
|
* @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
|
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2015-11-04 17:23:23 +00:00
|
|
|
* -XX:+EnableJVMCI
|
2015-10-08 22:49:30 +00:00
|
|
|
* compiler.jvmci.SecurityRestrictionsTest
|
|
|
|
* NO_SEC_MAN
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2015-11-04 17:23:23 +00:00
|
|
|
* -XX:+EnableJVMCI
|
2015-10-08 22:49:30 +00:00
|
|
|
* compiler.jvmci.SecurityRestrictionsTest
|
|
|
|
* NO_PERM
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2015-11-04 17:23:23 +00:00
|
|
|
* -XX:+EnableJVMCI
|
2015-10-08 22:49:30 +00:00
|
|
|
* compiler.jvmci.SecurityRestrictionsTest
|
|
|
|
* ALL_PERM
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2015-11-04 17:23:23 +00:00
|
|
|
* -XX:+EnableJVMCI
|
2015-10-08 22:49:30 +00:00
|
|
|
* compiler.jvmci.SecurityRestrictionsTest
|
|
|
|
* NO_JVMCI_ACCESS_PERM
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
* @run main/othervm -XX:+UnlockExperimentalVMOptions
|
2015-11-04 17:23:23 +00:00
|
|
|
* -XX:-EnableJVMCI
|
2015-10-08 22:49:30 +00:00
|
|
|
* compiler.jvmci.SecurityRestrictionsTest
|
|
|
|
* NO_JVMCI
|
|
|
|
*/
|
|
|
|
|
|
|
|
package compiler.jvmci;
|
|
|
|
|
|
|
|
import jdk.test.lib.Utils;
|
2016-07-12 15:24:48 +00:00
|
|
|
|
2015-10-08 22:49:30 +00:00
|
|
|
import java.security.AccessControlException;
|
|
|
|
import java.security.Permission;
|
2015-10-14 22:58:28 +00:00
|
|
|
import java.util.PropertyPermission;
|
|
|
|
import java.util.function.Consumer;
|
2015-10-08 22:49:30 +00:00
|
|
|
|
|
|
|
public class SecurityRestrictionsTest {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
try {
|
|
|
|
// to init Utils before call SecurityManager
|
|
|
|
Class.forName(Utils.class.getName(), true,
|
|
|
|
Utils.class.getClassLoader());
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
throw new Error("[TEST BUG]: jdk.test.lib.Utils not found", e);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
TestCase mode = TestCase.valueOf(args[0]);
|
|
|
|
mode.run();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
throw new Error("[TEST BUG]: Unknown mode " + args[0], e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum TestCase {
|
|
|
|
NO_SEC_MAN,
|
|
|
|
NO_JVMCI {
|
|
|
|
@Override
|
|
|
|
public Class<? extends Throwable> getExpectedException() {
|
|
|
|
return InternalError.class;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ALL_PERM {
|
|
|
|
@Override
|
|
|
|
public SecurityManager getSecurityManager() {
|
|
|
|
return new SecurityManager() {
|
|
|
|
@Override
|
|
|
|
public void checkPermission(Permission perm) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NO_PERM {
|
|
|
|
@Override
|
|
|
|
public SecurityManager getSecurityManager() {
|
|
|
|
return new SecurityManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Throwable> getExpectedException() {
|
|
|
|
return AccessControlException.class;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NO_JVMCI_ACCESS_PERM {
|
|
|
|
@Override
|
|
|
|
public SecurityManager getSecurityManager() {
|
|
|
|
return new SecurityManager() {
|
|
|
|
@Override
|
|
|
|
public void checkPermission(Permission perm) {
|
|
|
|
if (isJvmciPermission(perm)) {
|
|
|
|
super.checkPermission(perm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void checkPropertyAccess(String key) {
|
|
|
|
if (key.startsWith(JVMCI_PROP_START)) {
|
|
|
|
super.checkPropertyAccess(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isJvmciPermission(Permission perm) {
|
|
|
|
String name = perm.getName();
|
2015-10-14 22:58:28 +00:00
|
|
|
boolean isJvmciRuntime = perm instanceof RuntimePermission
|
2015-10-08 22:49:30 +00:00
|
|
|
&& (JVMCI_SERVICES.equals(name)
|
2015-10-14 22:58:28 +00:00
|
|
|
|| name.startsWith(JVMCI_RT_PERM_START));
|
|
|
|
boolean isJvmciProperty = perm instanceof PropertyPermission
|
|
|
|
&& name.startsWith(JVMCI_PROP_START);
|
|
|
|
return isJvmciRuntime || isJvmciProperty;
|
2015-10-08 22:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends Throwable> getExpectedException() {
|
|
|
|
return AccessControlException.class;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
System.setSecurityManager(getSecurityManager());
|
2015-10-14 22:58:28 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-11-04 17:23:23 +00:00
|
|
|
Utils.runAndCheckException(() -> {
|
|
|
|
try {
|
|
|
|
// CompilerToVM::<cinit> provokes CompilerToVM::<init>
|
|
|
|
Class.forName("jdk.vm.ci.hotspot.CompilerToVMHelper");
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
throw new Error("TESTBUG : " + e, e);
|
|
|
|
}
|
|
|
|
}, exceptionCheck);
|
2015-10-08 22:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public SecurityManager getSecurityManager() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Class<? extends Throwable> getExpectedException() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final String JVMCI_RT_PERM_START
|
|
|
|
= "accessClassInPackage.jdk.vm.ci";
|
|
|
|
private static final String JVMCI_SERVICES = "jvmciServices";
|
|
|
|
private static final String JVMCI_PROP_START = "jvmci.";
|
2015-10-14 22:58:28 +00:00
|
|
|
|
2015-10-08 22:49:30 +00:00
|
|
|
}
|
|
|
|
}
|