< prev index next >

test/compiler/jvmci/SecurityRestrictionsTest.java

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
  29  * @library /testlibrary /../../test/lib /
  30  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI



  31  *      compiler.jvmci.SecurityRestrictionsTest
  32  *      NO_SEC_MAN
  33  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI

  34  *      compiler.jvmci.SecurityRestrictionsTest
  35  *      NO_PERM
  36  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI

  37  *      compiler.jvmci.SecurityRestrictionsTest
  38  *      ALL_PERM
  39  * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI

  40  *      compiler.jvmci.SecurityRestrictionsTest
  41  *      NO_JVMCI_ACCESS_PERM
  42  * @run main/othervm -XX:+UnlockExperimentalVMOptions

  43  *      compiler.jvmci.SecurityRestrictionsTest
  44  *      NO_JVMCI
  45  */
  46 
  47 package compiler.jvmci;
  48 
  49 import jdk.vm.ci.hotspot.CompilerToVM;
  50 import jdk.test.lib.Utils;
  51 import java.lang.InternalError;

  52 import java.security.AccessControlException;
  53 import java.security.Permission;
  54 import java.util.PropertyPermission;
  55 import java.util.function.Consumer;


  56 
  57 public class SecurityRestrictionsTest {
  58 
  59     public static void main(String[] args) {
  60         try {
  61             // to init Utils before call SecurityManager
  62             Class.forName(Utils.class.getName(), true,
  63                     Utils.class.getClassLoader());
  64         } catch (ClassNotFoundException e) {
  65             throw new Error("[TEST BUG]: jdk.test.lib.Utils not found", e);
  66         }
  67         try {
  68             TestCase mode = TestCase.valueOf(args[0]);
  69             mode.run();
  70         } catch (IllegalArgumentException e) {
  71             throw new Error("[TEST BUG]: Unknown mode " + args[0], e);
  72         }
  73     }
  74 
  75     private enum TestCase {


 147                         throw new AssertionError(message);
 148                     }
 149                 } else {
 150                     String message = name() + ": Got unexpected exception "
 151                             + e.getClass().getSimpleName();
 152                     if (getExpectedException() == null){
 153                         throw new AssertionError(message, e);
 154                     }
 155 
 156                     Throwable t = e;
 157                     while (t.getCause() != null) {
 158                         t = t.getCause();
 159                     }
 160                     if (!getExpectedException().isAssignableFrom(t.getClass())) {
 161                         message += " instead of " + getExpectedException()
 162                                 .getSimpleName();
 163                         throw new AssertionError(message, e);
 164                     }
 165                 }
 166             };
 167             Utils.runAndCheckException(CompilerToVM::new, exceptionCheck);







 168         }
 169 
 170         public SecurityManager getSecurityManager() {
 171             return null;
 172         }
 173 
 174         public Class<? extends Throwable> getExpectedException() {
 175             return null;
 176         }
 177 
 178         private static final String JVMCI_RT_PERM_START
 179                 = "accessClassInPackage.jdk.vm.ci";
 180         private static final String JVMCI_SERVICES = "jvmciServices";
 181         private static final String JVMCI_PROP_START = "jvmci.";
 182 
 183     }
 184 }


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /**
  26  * @test
  27  * @bug 8136421
  28  * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
  29  * @library /testlibrary /../../test/lib /
  30  * @compile ./common/CompilerToVMHelper.java
  31  * @run main ClassFileInstaller jdk.vm.ci.hotspot.CompilerToVMHelper
  32  * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xbootclasspath/a:.
  33  *      -XX:+EnableJVMCI
  34  *      compiler.jvmci.SecurityRestrictionsTest
  35  *      NO_SEC_MAN
  36  * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xbootclasspath/a:.
  37  *      -XX:+EnableJVMCI
  38  *      compiler.jvmci.SecurityRestrictionsTest
  39  *      NO_PERM
  40  * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xbootclasspath/a:.
  41  *      -XX:+EnableJVMCI
  42  *      compiler.jvmci.SecurityRestrictionsTest
  43  *      ALL_PERM
  44  * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xbootclasspath/a:.
  45  *      -XX:+EnableJVMCI
  46  *      compiler.jvmci.SecurityRestrictionsTest
  47  *      NO_JVMCI_ACCESS_PERM
  48  * @run main/othervm -XX:+UnlockExperimentalVMOptions -Xbootclasspath/a:.
  49  *      -XX:-EnableJVMCI
  50  *      compiler.jvmci.SecurityRestrictionsTest
  51  *      NO_JVMCI
  52  */
  53 
  54 package compiler.jvmci;
  55 

  56 import jdk.test.lib.Utils;
  57 import java.lang.InternalError;
  58 import java.lang.reflect.Constructor;
  59 import java.security.AccessControlException;
  60 import java.security.Permission;
  61 import java.util.PropertyPermission;
  62 import java.util.function.Consumer;
  63 import java.util.logging.Level;
  64 import java.util.logging.Logger;
  65 
  66 public class SecurityRestrictionsTest {
  67 
  68     public static void main(String[] args) {
  69         try {
  70             // to init Utils before call SecurityManager
  71             Class.forName(Utils.class.getName(), true,
  72                     Utils.class.getClassLoader());
  73         } catch (ClassNotFoundException e) {
  74             throw new Error("[TEST BUG]: jdk.test.lib.Utils not found", e);
  75         }
  76         try {
  77             TestCase mode = TestCase.valueOf(args[0]);
  78             mode.run();
  79         } catch (IllegalArgumentException e) {
  80             throw new Error("[TEST BUG]: Unknown mode " + args[0], e);
  81         }
  82     }
  83 
  84     private enum TestCase {


 156                         throw new AssertionError(message);
 157                     }
 158                 } else {
 159                     String message = name() + ": Got unexpected exception "
 160                             + e.getClass().getSimpleName();
 161                     if (getExpectedException() == null){
 162                         throw new AssertionError(message, e);
 163                     }
 164 
 165                     Throwable t = e;
 166                     while (t.getCause() != null) {
 167                         t = t.getCause();
 168                     }
 169                     if (!getExpectedException().isAssignableFrom(t.getClass())) {
 170                         message += " instead of " + getExpectedException()
 171                                 .getSimpleName();
 172                         throw new AssertionError(message, e);
 173                     }
 174                 }
 175             };
 176             Utils.runAndCheckException(() -> {
 177                 try {
 178                     // CompilerToVM::<cinit> provokes CompilerToVM::<init> 
 179                     Class.forName("jdk.vm.ci.hotspot.CompilerToVMHelper");
 180                 } catch (ClassNotFoundException e) {
 181                     throw new Error("TESTBUG : " + e, e);
 182                 }
 183             }, exceptionCheck);
 184         }
 185 
 186         public SecurityManager getSecurityManager() {
 187             return null;
 188         }
 189 
 190         public Class<? extends Throwable> getExpectedException() {
 191             return null;
 192         }
 193 
 194         private static final String JVMCI_RT_PERM_START
 195                 = "accessClassInPackage.jdk.vm.ci";
 196         private static final String JVMCI_SERVICES = "jvmciServices";
 197         private static final String JVMCI_PROP_START = "jvmci.";
 198 
 199     }
 200 }
< prev index next >