Mercurial > hg > graal-compiler
annotate test/runtime/lambda-features/TestInterfaceInit.java @ 20576:90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
Reviewed-by: dcubed, coleenp
author | acorn |
---|---|
date | Fri, 24 Oct 2014 12:29:08 -0700 |
parents | |
children |
rev | line source |
---|---|
20576
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
1 /* |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
4 * |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
8 * |
90257dfad6e3
8043275: 8u40 backport: 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 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
90257dfad6e3
8043275: 8u40 backport: 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 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
13 * accompanied this code). |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
14 * |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
18 * |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
21 * questions. |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
22 * |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
23 */ |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
24 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
25 /* |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
26 * @test |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
27 * @bug 8034275 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
28 * @summary [JDK 8u40] Test interface initialization: only for interfaces declaring default methods |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
29 * @run main TestInterfaceInit |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
30 */ |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
31 import java.util.List; |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
32 import java.util.Arrays; |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
33 import java.util.ArrayList; |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
34 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
35 public class TestInterfaceInit { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
36 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
37 static List<Class<?>> cInitOrder = new ArrayList<>(); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
38 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
39 // Declares a default method and initializes |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
40 interface I { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
41 boolean v = TestInterfaceInit.out(I.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
42 default void x() {} |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
43 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
44 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
45 // Declares a default method and initializes |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
46 interface J extends I { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
47 boolean v = TestInterfaceInit.out(J.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
48 default void x() {} |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
49 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
50 // No default method, does not initialize |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
51 interface JN extends J { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
52 boolean v = TestInterfaceInit.out(JN.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
53 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
54 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
55 // Declares a default method and initializes |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
56 interface K extends I { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
57 boolean v = TestInterfaceInit.out(K.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
58 default void x() {} |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
59 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
60 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
61 // No default method, does not initialize |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
62 interface KN extends K { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
63 boolean v = TestInterfaceInit.out(KN.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
64 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
65 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
66 interface L extends JN, KN { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
67 boolean v = TestInterfaceInit.out(L.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
68 default void x() {} |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
69 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
70 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
71 public static void main(String[] args) { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
72 // Trigger initialization |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
73 boolean v = L.v; |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
74 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
75 List<Class<?>> expectedCInitOrder = Arrays.asList(I.class,J.class,K.class,L.class); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
76 if (!cInitOrder.equals(expectedCInitOrder)) { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
77 throw new RuntimeException(String.format("Class initialization array %s not equal to expected array %s", cInitOrder, expectedCInitOrder)); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
78 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
79 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
80 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
81 static boolean out(Class c) { |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
82 System.out.println("#: initializing " + c.getName()); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
83 cInitOrder.add(c); |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
84 return true; |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
85 } |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
86 |
90257dfad6e3
8043275: 8u40 backport: Fix interface initialization for default methods.
acorn
parents:
diff
changeset
|
87 } |