author | coleenp |
Wed, 05 Apr 2017 01:11:25 +0000 | |
changeset 46363 | b53de34a044c |
parent 42031 | 55dc92f033b9 |
permissions | -rw-r--r-- |
41293
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
1 |
/* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
4 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
8 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
14 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
18 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
21 |
* questions. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
22 |
* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
23 |
*/ |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
24 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
25 |
/* |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
26 |
* @test |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
27 |
* @bug 8163969 |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
28 |
* @summary Test interface initialization states and when certain interfaces are initialized |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
29 |
* in the presence of initialization errors. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
30 |
* @run main InterfaceInitializationStates |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
31 |
*/ |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
32 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
33 |
import java.util.List; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
34 |
import java.util.Arrays; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
36 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
37 |
public class InterfaceInitializationStates { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
38 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
39 |
static List<Class<?>> cInitOrder = new ArrayList<>(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
40 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
41 |
// K interface with a default method has an initialization error |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
42 |
interface K { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
43 |
boolean v = InterfaceInitializationStates.out(K.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
44 |
static final Object CONST = InterfaceInitializationStates.someMethod(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
45 |
default int method() { return 2; } |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
46 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
47 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
48 |
// I is initialized when CONST is used, and doesn't trigger initialization of K, |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
49 |
// I also doesn't get an initialization error just because K has an initialization error. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
50 |
interface I extends K { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
51 |
boolean v = InterfaceInitializationStates.out(I.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
52 |
static final Object CONST = InterfaceInitializationStates.someMethod(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
53 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
54 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
55 |
// L can be fully initialized even though it extends an interface that has an |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
56 |
// initialization error |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
57 |
interface L extends K { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
58 |
boolean v = InterfaceInitializationStates.out(L.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
59 |
default void lx() {} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
60 |
static void func() { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
61 |
System.out.println("Calling function on interface with bad super interface."); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
62 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
63 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
64 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
65 |
// Another interface needing initialization. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
66 |
// Initialization of this interface does not occur with ClassLIM because K throws |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
67 |
// an initialization error, so the interface initialization is abandoned |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
68 |
interface M { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
69 |
boolean v = InterfaceInitializationStates.out(M.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
70 |
default void mx() {} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
71 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
72 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
73 |
static class ClassLIM implements L, I, M { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
74 |
boolean v = InterfaceInitializationStates.out(ClassLIM.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
75 |
int callMethodInK() { return method(); } |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
76 |
static { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
77 |
// Since interface initialization of K fails, this should never be called |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
78 |
System.out.println("Initializing C, but L is still good"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
79 |
L.func(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
80 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
81 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
82 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
83 |
// Finally initialize M |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
84 |
static class ClassM implements M { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
85 |
boolean v = InterfaceInitializationStates.out(ClassM.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
86 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
87 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
88 |
// Iunlinked is testing initialization like interface I, except interface I is linked when |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
89 |
// ClassLIM is linked. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
90 |
// Iunlinked is not linked already when K gets an initialization error. Linking Iunlinked |
42031
55dc92f033b9
8166203: NoClassDefFoundError should not be thrown if class is in_error_state at link time
iklam
parents:
41293
diff
changeset
|
91 |
// should succeed because it does not depend on the initialization state of K for linking. |
41293
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
92 |
interface Iunlinked extends K { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
93 |
boolean v = InterfaceInitializationStates.out(Iunlinked.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
94 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
95 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
96 |
// More tests. What happens if we use K for parameters and return types? |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
97 |
// K is a symbolic reference in the constant pool and the initialization error only |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
98 |
// matters when it's used. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
99 |
interface Iparams { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
100 |
boolean v = InterfaceInitializationStates.out(Iparams.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
101 |
K the_k = null; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
102 |
K m(K k); // abstract |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
103 |
default K method() { return new K(){}; } |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
104 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
105 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
106 |
static class ClassIparams implements Iparams { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
107 |
boolean v = InterfaceInitializationStates.out(ClassIparams.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
108 |
public K m(K k) { return k; } |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
109 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
110 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
111 |
public static void main(java.lang.String[] unused) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
112 |
// The rule this tests is the last sentence of JLS 12.4.1: |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
113 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
114 |
// When a class is initialized, its superclasses are initialized (if they have not |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
115 |
// been previously initialized), as well as any superinterfaces (s8.1.5) that declare any |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
116 |
// default methods (s9.4.3) (if they have not been previously initialized). Initialization |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
117 |
// of an interface does not, of itself, cause initialization of any of its superinterfaces. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
118 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
119 |
// Trigger initialization. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
120 |
// Now L is fully_initialized even though K should |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
121 |
// throw an error during initialization. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
122 |
boolean v = L.v; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
123 |
L.func(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
124 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
125 |
try { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
126 |
ClassLIM c = new ClassLIM(); // is K initialized, with a perfectly good L in the middle |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
127 |
// was bug: this used to succeed and be able to callMethodInK(). |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
128 |
throw new RuntimeException("FAIL exception not thrown for class"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
129 |
} catch (ExceptionInInitializerError e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
130 |
System.out.println("ExceptionInInitializerError thrown as expected"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
131 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
132 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
133 |
// Test that K already has initialization error so gets ClassNotFoundException because |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
134 |
// initialization was attempted with ClassLIM. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
135 |
try { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
136 |
Class.forName("InterfaceInitializationStates$K", true, InterfaceInitializationStates.class.getClassLoader()); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
137 |
throw new RuntimeException("FAIL exception not thrown for forName(K)"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
138 |
} catch(ClassNotFoundException e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
139 |
throw new RuntimeException("ClassNotFoundException should not be thrown"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
140 |
} catch(NoClassDefFoundError e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
141 |
System.out.println("NoClassDefFoundError thrown as expected"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
142 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
143 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
144 |
new ClassM(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
145 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
146 |
// Initialize I, which doesn't cause K (super interface) to be initialized. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
147 |
// Since the initialization of I does _not_ cause K to be initialized, it does |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
148 |
// not get NoClassDefFoundError because K is erroneous. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
149 |
// But the initialization of I throws RuntimeException, so we expect |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
150 |
// ExceptionInInitializerError. |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
151 |
try { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
152 |
Object ii = I.CONST; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
153 |
throw new RuntimeException("FAIL exception not thrown for I's initialization"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
154 |
} catch (ExceptionInInitializerError e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
155 |
System.out.println("ExceptionInInitializerError as expected"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
156 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
157 |
|
42031
55dc92f033b9
8166203: NoClassDefFoundError should not be thrown if class is in_error_state at link time
iklam
parents:
41293
diff
changeset
|
158 |
// Initialize Iunlinked. No exception should be thrown even if K |
41293
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
159 |
// (its super interface) is in initialization_error state. |
42031
55dc92f033b9
8166203: NoClassDefFoundError should not be thrown if class is in_error_state at link time
iklam
parents:
41293
diff
changeset
|
160 |
boolean bb = Iunlinked.v; |
41293
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
161 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
162 |
// This should be okay |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
163 |
boolean value = Iparams.v; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
164 |
System.out.println("value is " + value); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
165 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
166 |
ClassIparams p = new ClassIparams(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
167 |
try { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
168 |
// Now we get an error because K got an initialization_error |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
169 |
K kk = p.method(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
170 |
throw new RuntimeException("FAIL exception not thrown for calling method for K"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
171 |
} catch(NoClassDefFoundError e) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
172 |
System.out.println("NoClassDefFoundError thrown as expected"); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
173 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
174 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
175 |
// Check expected class initialization order |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
176 |
List<Class<?>> expectedCInitOrder = Arrays.asList(L.class, K.class, M.class, ClassM.class, |
42031
55dc92f033b9
8166203: NoClassDefFoundError should not be thrown if class is in_error_state at link time
iklam
parents:
41293
diff
changeset
|
177 |
I.class, Iunlinked.class, Iparams.class, |
41293
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
178 |
ClassIparams.class); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
179 |
if (!cInitOrder.equals(expectedCInitOrder)) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
180 |
throw new RuntimeException( |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
181 |
String.format("Class initialization array %s not equal to expected array %s", |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
182 |
cInitOrder, expectedCInitOrder)); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
183 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
184 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
185 |
|
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
186 |
static boolean out(Class c) { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
187 |
System.out.println("#: initializing " + c.getName()); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
188 |
cInitOrder.add(c); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
189 |
return true; |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
190 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
191 |
static Object someMethod() { |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
192 |
throw new RuntimeException(); |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
193 |
} |
871b2f487dc0
8163969: Cyclic interface initialization causes JVM crash
coleenp
parents:
diff
changeset
|
194 |
} |