test/hotspot/jtreg/runtime/Nestmates/privateConstructors/TestInvokeSpecial.java
author dholmes
Sat, 23 Jun 2018 01:32:41 -0400
changeset 50735 2f2af62dfac7
permissions -rw-r--r--
8010319: Implementation of JEP 181: Nest-Based Access Control Reviewed-by: alanb, psandoz, mchung, coleenp, acorn, mcimadamore, forax, jlahoda, sspitsyn, abuckley Contributed-by: alex.buckley@oracle.com, maurizio.mimadamore@oracle.com, mandy.chung@oracle.com, tobias.hartmann@oracle.com, david.holmes@oracle.com, vladimir.x.ivanov@oracle.com, karen.kinnear@oracle.com, vladimir.kozlov@oracle.com, john.r.rose@oracle.com, daniel.smith@oracle.com, serguei.spitsyn@oracle.com, kumardotsrinivasan@gmail.com, boris.ulasevich@bell-sw.com
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
/*
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    26
 * @bug 8046171
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    27
 * @summary Test access to private constructors between nestmates and nest-host
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    28
 *          using different flavours of named nested types that will
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    29
 *          generate invokespecial for the calls. The -Xcomp run is a special
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    30
 *          regression test for a compiler assertion that would fire when
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    31
 *          "loading" a nest-host class.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    32
 * @run main TestInvokeSpecial
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    33
 * @run main/othervm -Xcomp TestInvokeSpecial
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    34
 */
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    35
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    36
public class TestInvokeSpecial {
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
    // All constructors are private to ensure nestmate access checks apply
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
    // All doConstruct methods are public so they don't involve invoke_special
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    41
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    42
    private TestInvokeSpecial() {}
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
    // The various nestmates
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 interface StaticIface {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    47
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    48
        // Methods that will access private constructors of nestmates.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    49
        // The arg is a dummy for overloading purposes
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
        default void doConstruct(TestInvokeSpecial o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    52
            Object obj = new TestInvokeSpecial();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    53
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    54
        default void doConstruct(InnerNested o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    55
            Object obj = new TestInvokeSpecial().new InnerNested();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    56
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    57
        default void doConstruct(StaticNested o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    58
            Object obj = new StaticNested();
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
        default void doConstruct(StaticIface o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    61
            Object obj = new StaticIface() {};
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    62
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    63
    }
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
    static class StaticNested {
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
        private StaticNested() {}
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    68
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    69
        // Methods that will access private constructors of nestmates.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    70
        // The arg is a dummy for overloading purposes
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    71
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    72
        public void doConstruct(TestInvokeSpecial o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    73
            Object obj = new TestInvokeSpecial();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    74
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    75
        public void doConstruct(InnerNested o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    76
            Object obj = new TestInvokeSpecial().new InnerNested();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    77
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    78
        public void doConstruct(StaticNested o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    79
            Object obj = new StaticNested();
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
        public void doConstruct(StaticIface o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    82
            Object obj = new StaticIface() {};
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    83
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    84
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    85
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    86
    class InnerNested {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    87
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    88
        private InnerNested() {}
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
        // Methods that will access private constructors of nestmates.
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    91
        // The arg is a dummy for overloading purposes
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    92
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    93
        public void doConstruct(TestInvokeSpecial o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    94
            Object obj = new TestInvokeSpecial();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    95
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    96
        public void doConstruct(InnerNested o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    97
            Object obj = new TestInvokeSpecial().new InnerNested();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    98
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
    99
        public void doConstruct(StaticNested o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   100
            Object obj = new StaticNested();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   101
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   102
        public void doConstruct(StaticIface o) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   103
            Object obj = new StaticIface() {};
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   104
        }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   105
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   106
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   107
    public static void main(String[] args) {
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   108
        // These initial constructions test nest-host access
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   109
        TestInvokeSpecial o = new TestInvokeSpecial();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   110
        StaticNested s = new StaticNested();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   111
        InnerNested i = o.new InnerNested();
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   112
        StaticIface intf = new StaticIface() {};
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
        s.doConstruct(o);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   115
        s.doConstruct(i);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   116
        s.doConstruct(s);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   117
        s.doConstruct(intf);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   118
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   119
        i.doConstruct(o);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   120
        i.doConstruct(i);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   121
        i.doConstruct(s);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   122
        i.doConstruct(intf);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   123
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   124
        intf.doConstruct(o);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   125
        intf.doConstruct(i);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   126
        intf.doConstruct(s);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   127
        intf.doConstruct(intf);
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   128
    }
2f2af62dfac7 8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
diff changeset
   129
}