test/hotspot/jtreg/runtime/Nestmates/privateMethods/TestInvokeErrors.java
author hseigel
Wed, 20 Feb 2019 13:21:36 -0500
changeset 53853 7ca9e625d6b2
parent 52066 49a21be61dcd
child 54607 b6db97903b69
permissions -rw-r--r--
8214719: Deprecate -Xverify:none option Summary: Deprecate -Xverify:none and -noverify and remove them from tests Reviewed-by: dholmes, mikael
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     1
/*
53853
7ca9e625d6b2 8214719: Deprecate -Xverify:none option
hseigel
parents: 52066
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     4
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     8
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    13
 * accompanied this code).
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    14
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    18
 *
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    21
 * questions.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    22
 */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    23
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    24
/*
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    25
 * @test
52066
49a21be61dcd 8211065: Private method check in linkResolver is incorrect
dholmes
parents: 50735
diff changeset
    26
 * @bug 8046171 8211065
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    27
 * @summary Setup nestmate calls to private methods then use
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    28
 *          modified jcod classes to introduce errors. Test with
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    29
 *          and without verification enabled
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    30
 * @compile TestInvokeErrors.java
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    31
 * @compile MissingMethod.jcod
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    32
 *          MissingMethodWithSuper.jcod
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    33
 *          MissingNestHost.jcod
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    34
 * @run main TestInvokeErrors true
53853
7ca9e625d6b2 8214719: Deprecate -Xverify:none option
hseigel
parents: 52066
diff changeset
    35
 * @run main/othervm -XX:-BytecodeVerificationRemote -XX:-BytecodeVerificationLocal TestInvokeErrors false
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    36
 */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    37
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    38
public class TestInvokeErrors {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    39
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    40
    static class Nested {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    41
        private void priv_invoke() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    42
            System.out.println("Nested::priv_invoke");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    43
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    44
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    45
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    46
    static class MissingMethod {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    47
        // jcod version will rename this method to not_priv_invoke
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    48
        private void priv_invoke() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    49
            System.out.println("MissingMethod::priv_invoke");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    50
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    51
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    52
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    53
    static class MissingMethodWithSuper extends Nested {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    54
        // jcod version will rename this method to not_priv_invoke
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    55
        private void priv_invoke() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    56
            System.out.println("MissingMethodWithSuper::priv_invoke");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    57
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    58
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    59
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    60
    static class MissingNestHost {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    61
        // jcod version will change NestHost to a non-existent class
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    62
        private void priv_invoke() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    63
            System.out.println("MissingNestHost::priv_invoke");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    64
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    65
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    66
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    67
    // Helper class adds a level of indirection to avoid the main class
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    68
    // failing verification if these tests are written directly in main.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    69
    // That can only happen if using invokespecial for nestmate invocation.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    70
    static class Helper {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    71
        static void doTest() {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    72
            try {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    73
                MissingNestHost m = new MissingNestHost();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    74
                m.priv_invoke();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    75
                throw new Error("Unexpected success invoking MissingNestHost.priv_invoke");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    76
            }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    77
            catch (NoClassDefFoundError ncdfe) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    78
                System.out.println("Got expected exception:" + ncdfe);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    79
            }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    80
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    81
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    82
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    83
    public static void main(String[] args) throws Throwable {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    84
        // some errors change depending on whether they are caught by the
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    85
        // verifier first
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    86
        boolean verifying = Boolean.parseBoolean(args[0]);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    87
        System.out.println("Verification is " +
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    88
                           (verifying ? "enabled" : "disabled"));
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    89
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    90
        try {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    91
            MissingMethod m = new MissingMethod();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    92
            m.priv_invoke();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    93
            throw new Error("Unexpected success invoking MissingMethod.priv_invoke");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    94
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    95
        catch (NoSuchMethodError nsme) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    96
            System.out.println("Got expected exception:" + nsme);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    97
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    98
52066
49a21be61dcd 8211065: Private method check in linkResolver is incorrect
dholmes
parents: 50735
diff changeset
    99
        // This test was revised to expect successful invocation of the
49a21be61dcd 8211065: Private method check in linkResolver is incorrect
dholmes
parents: 50735
diff changeset
   100
        // super class method - see JDK-8211065
49a21be61dcd 8211065: Private method check in linkResolver is incorrect
dholmes
parents: 50735
diff changeset
   101
        MissingMethodWithSuper m = new MissingMethodWithSuper();
49a21be61dcd 8211065: Private method check in linkResolver is incorrect
dholmes
parents: 50735
diff changeset
   102
        m.priv_invoke();
50735
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   103
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   104
        // Verification of Helper will trigger the nestmate access check failure
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   105
        try {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   106
            Helper.doTest();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   107
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   108
        catch (NoClassDefFoundError ncdfe) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   109
            if (verifying)
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   110
                System.out.println("Got expected exception:" + ncdfe);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   111
            else
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   112
                throw new Error("Unexpected error loading Helper class with verification disabled");
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   113
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   114
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   115
}