hotspot/test/compiler/jvmci/SecurityRestrictionsTest.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 36508 5f9eee6b383b
child 38152 80e5da81fb2c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    25
/**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
 * @test
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    27
 * @bug 8136421
35148
5cfafc99d791 8143072: [JVMCI] Port JVMCI to AArch64
twisti
parents: 33813
diff changeset
    28
 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 33183
diff changeset
    29
 * @library /testlibrary /test/lib /
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    30
 * @library common/patches
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    31
 * @modules jdk.vm.ci/jdk.vm.ci.hotspot
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    32
 * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    33
 * @run main/othervm -XX:+UnlockExperimentalVMOptions
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    34
 *      -XX:+EnableJVMCI
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    35
 *      compiler.jvmci.SecurityRestrictionsTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    36
 *      NO_SEC_MAN
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    37
 * @run main/othervm -XX:+UnlockExperimentalVMOptions
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    38
 *      -XX:+EnableJVMCI
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
 *      compiler.jvmci.SecurityRestrictionsTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    40
 *      NO_PERM
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    41
 * @run main/othervm -XX:+UnlockExperimentalVMOptions
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    42
 *      -XX:+EnableJVMCI
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    43
 *      compiler.jvmci.SecurityRestrictionsTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    44
 *      ALL_PERM
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    45
 * @run main/othervm -XX:+UnlockExperimentalVMOptions
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    46
 *      -XX:+EnableJVMCI
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
 *      compiler.jvmci.SecurityRestrictionsTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
 *      NO_JVMCI_ACCESS_PERM
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 35148
diff changeset
    49
 * @run main/othervm -XX:+UnlockExperimentalVMOptions
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    50
 *      -XX:-EnableJVMCI
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
 *      compiler.jvmci.SecurityRestrictionsTest
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
 *      NO_JVMCI
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
package compiler.jvmci;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
import jdk.test.lib.Utils;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
import java.lang.InternalError;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    59
import java.lang.reflect.Constructor;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
import java.security.AccessControlException;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
import java.security.Permission;
33183
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
    62
import java.util.PropertyPermission;
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
    63
import java.util.function.Consumer;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    64
import java.util.logging.Level;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
    65
import java.util.logging.Logger;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
public class SecurityRestrictionsTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
    public static void main(String[] args) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
        try {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    71
            // to init Utils before call SecurityManager
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
            Class.forName(Utils.class.getName(), true,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
                    Utils.class.getClassLoader());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
        } catch (ClassNotFoundException e) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
            throw new Error("[TEST BUG]: jdk.test.lib.Utils not found", e);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
        try {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
            TestCase mode = TestCase.valueOf(args[0]);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    79
            mode.run();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    80
        } catch (IllegalArgumentException e) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    81
            throw new Error("[TEST BUG]: Unknown mode " + args[0], e);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    82
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
    private enum TestCase {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
        NO_SEC_MAN,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
        NO_JVMCI {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    88
            @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    89
            public Class<? extends Throwable> getExpectedException() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
                return InternalError.class;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
        },
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    93
        ALL_PERM {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    94
            @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    95
            public SecurityManager getSecurityManager() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    96
                return new SecurityManager() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    97
                    @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
                    public void checkPermission(Permission perm) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
                    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
                };
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
        },
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
        NO_PERM {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
            @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   105
            public SecurityManager getSecurityManager() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   106
                return new SecurityManager();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   107
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   108
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   109
            @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   110
            public Class<? extends Throwable> getExpectedException() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   111
                return AccessControlException.class;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   112
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   113
        },
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   114
        NO_JVMCI_ACCESS_PERM {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   115
            @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   116
            public SecurityManager getSecurityManager() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   117
                return new SecurityManager() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   118
                    @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   119
                    public void checkPermission(Permission perm) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   120
                        if (isJvmciPermission(perm)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   121
                            super.checkPermission(perm);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   122
                        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   123
                    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   124
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   125
                    @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   126
                    public void checkPropertyAccess(String key) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   127
                        if (key.startsWith(JVMCI_PROP_START)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   128
                            super.checkPropertyAccess(key);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   129
                        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   130
                    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
                };
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   132
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   133
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   134
            private boolean isJvmciPermission(Permission perm) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
                String name = perm.getName();
33183
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   136
                boolean isJvmciRuntime = perm instanceof RuntimePermission
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   137
                        && (JVMCI_SERVICES.equals(name)
33183
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   138
                            || name.startsWith(JVMCI_RT_PERM_START));
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   139
                boolean isJvmciProperty = perm instanceof PropertyPermission
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   140
                        && name.startsWith(JVMCI_PROP_START);
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   141
                return isJvmciRuntime || isJvmciProperty;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   142
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   143
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   144
            @Override
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   145
            public Class<? extends Throwable> getExpectedException() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   146
                return AccessControlException.class;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   147
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   148
        };
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   149
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   150
        public void run() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   151
            System.setSecurityManager(getSecurityManager());
33183
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   152
            Consumer<Throwable> exceptionCheck = e -> {
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   153
                if (e == null) {
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   154
                    if (getExpectedException() != null) {
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   155
                        String message = name() + ": Didn't get expected exception "
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   156
                                + getExpectedException();
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   157
                        throw new AssertionError(message);
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   158
                    }
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   159
                } else {
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   160
                    String message = name() + ": Got unexpected exception "
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   161
                            + e.getClass().getSimpleName();
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   162
                    if (getExpectedException() == null){
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   163
                        throw new AssertionError(message, e);
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   164
                    }
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   165
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   166
                    Throwable t = e;
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   167
                    while (t.getCause() != null) {
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   168
                        t = t.getCause();
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   169
                    }
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   170
                    if (!getExpectedException().isAssignableFrom(t.getClass())) {
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   171
                        message += " instead of " + getExpectedException()
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   172
                                .getSimpleName();
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   173
                        throw new AssertionError(message, e);
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   174
                    }
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   175
                }
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   176
            };
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   177
            Utils.runAndCheckException(() -> {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   178
                try {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   179
                    // CompilerToVM::<cinit> provokes CompilerToVM::<init>
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   180
                    Class.forName("jdk.vm.ci.hotspot.CompilerToVMHelper");
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   181
                } catch (ClassNotFoundException e) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   182
                    throw new Error("TESTBUG : " + e, e);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   183
                }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33183
diff changeset
   184
            }, exceptionCheck);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   185
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   186
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   187
        public SecurityManager getSecurityManager() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   188
            return null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   189
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   190
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   191
        public Class<? extends Throwable> getExpectedException() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   192
            return null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   193
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   194
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   195
        private static final String JVMCI_RT_PERM_START
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   196
                = "accessClassInPackage.jdk.vm.ci";
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   197
        private static final String JVMCI_SERVICES = "jvmciServices";
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   198
        private static final String JVMCI_PROP_START = "jvmci.";
33183
1ee801e82dda 8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents: 33160
diff changeset
   199
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   200
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   201
}