test/hotspot/jtreg/runtime/linkResolver/TestDeletedMethod.java
changeset 52066 49a21be61dcd
equal deleted inserted replaced
52065:dea8a62cdfc3 52066:49a21be61dcd
       
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    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  * @test
       
    26  * @bug 8211065
       
    27  * @summary Test that deleting a subclass method implementation results in
       
    28  * execution of a superclass implementation - if it is accessible.
       
    29  * @compile TestDeletedMethod.java
       
    30  * @compile TestDeletedMethod_Sub.jcod TestDeletedMethod_Super.jcod
       
    31  * @run main/othervm -XX:+RelaxAccessControlCheck TestDeletedMethod
       
    32  */
       
    33 
       
    34 // The access control relaxation was originally done to ensure an assertion
       
    35 // in the nestmate logic would not trigger unintentionally because it
       
    36 // assumed only nestmates could be involved. The assertion no longer exists
       
    37 // but we keep the test as a non-nestmate version of the situation.
       
    38 
       
    39 /* package */ class TestDeletedMethod_Super {
       
    40     public static final int ID = 2;
       
    41     private static int m() {
       
    42         System.out.println("Super.m");
       
    43         return ID;
       
    44     }
       
    45 }
       
    46 
       
    47 /* package */ class TestDeletedMethod_Sub extends TestDeletedMethod_Super {
       
    48     public static final int ID = 1;
       
    49     // At runtime this implementation is not present
       
    50     private static int m() {
       
    51         System.out.println("Sub.m");
       
    52         return ID;
       
    53     }
       
    54     public static int test() {
       
    55         return TestDeletedMethod_Sub.m();
       
    56     }
       
    57 }
       
    58 
       
    59 public class TestDeletedMethod {
       
    60     public static void main(String[] args) {
       
    61         int x = TestDeletedMethod_Sub.test();
       
    62         if (x != TestDeletedMethod_Super.ID)
       
    63             throw new RuntimeException("Wrong method invoked: " + x);
       
    64     }
       
    65 }