hotspot/test/runtime/lambda-features/TestInterfaceInit.java
author coleenp
Wed, 05 Apr 2017 01:11:25 +0000
changeset 46363 b53de34a044c
parent 41705 332239c052cc
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     1
/*
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     4
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     8
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    13
 * accompanied this code).
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    14
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    18
 *
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    21
 * questions.
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    22
 */
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    23
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    24
/*
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    25
 * @test
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    26
 * @bug 8034275
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    27
 * @bug 8098557
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    28
 * @summary [JDK 8u40] Test interface init: only for interfaces declaring default methods, when subclass inits
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    29
 * @run main TestInterfaceInit
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    30
 */
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    31
import java.util.List;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    32
import java.util.Arrays;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    33
import java.util.ArrayList;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    34
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    35
public class TestInterfaceInit {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    36
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    37
   static List<Class<?>> cInitOrder = new ArrayList<>();
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    38
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    39
   // Declares a default method and initializes
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    40
   interface I {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    41
       boolean v = TestInterfaceInit.out(I.class);
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    42
        default void ix() {}
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    43
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    44
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    45
   // Declares a default method and initializes
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    46
   interface J extends I {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    47
       boolean v = TestInterfaceInit.out(J.class);
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    48
       default void jx() {}
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    49
   }
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    50
   // No default method, has an abstract method, does not initialize
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    51
   interface JN extends J {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    52
       boolean v = TestInterfaceInit.out(JN.class);
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    53
       public abstract void jnx();
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    54
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    55
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    56
   // Declares a default method and initializes
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    57
   interface K extends I {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    58
       boolean v = TestInterfaceInit.out(K.class);
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    59
        default void kx() {}
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    60
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    61
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    62
   // No default method, has a static method, does not initialize
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    63
   interface KN extends K {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    64
       boolean v = TestInterfaceInit.out(KN.class);
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    65
       static void knx() {}
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    66
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    67
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    68
   interface L extends JN, KN {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    69
       boolean v = TestInterfaceInit.out(L.class);
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    70
        default void lx() {}
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    71
   }
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    72
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    73
   static class ChildClass implements JN, KN {
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    74
       boolean v = TestInterfaceInit.out(ChildClass.class);
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    75
       public void jnx() {}
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    76
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    77
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    78
   public static void main(String[] args) {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    79
       // Trigger initialization
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    80
       boolean v = L.v;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    81
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    82
       List<Class<?>> expectedCInitOrder = Arrays.asList(L.class);
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    83
       if (!cInitOrder.equals(expectedCInitOrder)) {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    84
         throw new RuntimeException(String.format("Class initialization array %s not equal to expected array %s", cInitOrder, expectedCInitOrder));
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    85
       }
34303
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    86
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    87
       ChildClass myC = new ChildClass();
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    88
       boolean w = myC.v;
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    89
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    90
       expectedCInitOrder = Arrays.asList(L.class,I.class,J.class,K.class,ChildClass.class);
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    91
       if (!cInitOrder.equals(expectedCInitOrder)) {
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    92
         throw new RuntimeException(String.format("Class initialization array %s not equal to expected array %s", cInitOrder, expectedCInitOrder));
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    93
       }
9e271398a718 8098557: Only init superintf if subclass, not sub interface inits.
acorn
parents: 27402
diff changeset
    94
27402
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    95
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    96
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    97
   static boolean out(Class c) {
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    98
       System.out.println("#: initializing " + c.getName());
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
    99
       cInitOrder.add(c);
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
   100
       return true;
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
   101
   }
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
   102
5c4675ddc00c 8043275: Fix interface initialization for default methods.
acorn
parents:
diff changeset
   103
}