1 /* |
1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 /* |
26 /* |
27 * @test |
27 * @test |
28 * @bug 7153958 |
28 * @bug 7153958 8073372 |
29 * @summary add constant pool reference to class containing inlined constants |
29 * @summary add constant pool reference to class containing inlined constants |
30 * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java |
30 * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java |
31 * @run main CPoolRefClassContainingInlinedCts |
31 * @run main CPoolRefClassContainingInlinedCts |
32 */ |
32 */ |
33 |
33 |
34 import com.sun.tools.classfile.ClassFile; |
34 import com.sun.tools.classfile.ClassFile; |
35 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; |
35 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; |
36 import com.sun.tools.classfile.ConstantPool.CPInfo; |
36 import com.sun.tools.classfile.ConstantPool.CPInfo; |
37 import com.sun.tools.classfile.ConstantPoolException; |
37 import com.sun.tools.classfile.ConstantPoolException; |
38 import java.io.File; |
38 import java.io.File; |
39 import java.io.IOException; |
39 import java.io.IOException; |
40 |
40 |
41 import static pkg.ClassToBeStaticallyImported.staticField; |
41 import static pkg.ClassToBeStaticallyImportedA.staticFieldA; |
|
42 import static pkg.ClassToBeStaticallyImportedB.staticFieldB; |
42 |
43 |
43 public class CPoolRefClassContainingInlinedCts { |
44 public class CPoolRefClassContainingInlinedCts { |
44 |
45 |
45 public static void main(String args[]) throws Exception { |
46 public static void main(String args[]) throws Exception { |
46 new CPoolRefClassContainingInlinedCts().run(); |
47 new CPoolRefClassContainingInlinedCts().run(); |
52 |
53 |
53 int numberOfReferencedClassesToBeChecked = 0; |
54 int numberOfReferencedClassesToBeChecked = 0; |
54 |
55 |
55 void checkClassName(String className) { |
56 void checkClassName(String className) { |
56 switch (className) { |
57 switch (className) { |
57 case "SimpleAssignClass" : case "BinaryExpClass": |
58 case "SimpleAssignClassA" : case "BinaryExpClassA": |
58 case "UnaryExpClass" : case "CastClass": |
59 case "UnaryExpClassA" : case "CastClassA": |
59 case "ParensClass" : case "CondClass": |
60 case "ParensClassA" : case "CondClassA": |
60 case "IfClass" : case "pkg/ClassToBeStaticallyImported": |
61 case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA": |
|
62 case "SimpleAssignClassB" : case "BinaryExpClassB": |
|
63 case "UnaryExpClassB" : case "CastClassB": |
|
64 case "ParensClassB" : case "CondClassB": |
|
65 case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB": |
61 numberOfReferencedClassesToBeChecked++; |
66 numberOfReferencedClassesToBeChecked++; |
62 } |
67 } |
63 } |
68 } |
64 |
69 |
65 void checkReferences() throws IOException, ConstantPoolException { |
70 void checkReferences() throws IOException, ConstantPoolException { |
74 if (cpInfo instanceof CONSTANT_Class_info) { |
79 if (cpInfo instanceof CONSTANT_Class_info) { |
75 checkClassName(((CONSTANT_Class_info)cpInfo).getName()); |
80 checkClassName(((CONSTANT_Class_info)cpInfo).getName()); |
76 } |
81 } |
77 i += cpInfo.size(); |
82 i += cpInfo.size(); |
78 } |
83 } |
79 if (numberOfReferencedClassesToBeChecked != 8) { |
84 if (numberOfReferencedClassesToBeChecked != 16) { |
80 throw new AssertionError("Class reference missing in the constant pool"); |
85 throw new AssertionError("Class reference missing in the constant pool"); |
81 } |
86 } |
82 } |
87 } |
83 |
88 |
84 private int assign = SimpleAssignClass.x; |
89 private int assignA = SimpleAssignClassA.x; |
85 private int binary = BinaryExpClass.x + 1; |
90 private int binaryA = BinaryExpClassA.x + 1; |
86 private int unary = -UnaryExpClass.x; |
91 private int unaryA = -UnaryExpClassA.x; |
87 private int cast = (int)CastClass.x; |
92 private int castA = (int)CastClassA.x; |
88 private int parens = (ParensClass.x); |
93 private int parensA = (ParensClassA.x); |
89 private int cond = (CondClass.x == 1) ? 1 : 2; |
94 private int condA = (CondClassA.x == 1) ? 1 : 2; |
90 private static int ifConstant; |
95 private static int ifConstantA; |
91 private static int importStatic; |
96 private static int importStaticA; |
92 static { |
97 static { |
93 if (IfClass.x == 1) { |
98 if (IfClassA.x == 1) { |
94 ifConstant = 1; |
99 ifConstantA = 1; |
95 } else { |
100 } else { |
96 ifConstant = 2; |
101 ifConstantA = 2; |
97 } |
102 } |
98 } |
103 } |
99 static { |
104 static { |
100 if (staticField == 1) { |
105 if (staticFieldA == 1) { |
101 importStatic = 1; |
106 importStaticA = 1; |
102 } else { |
107 } else { |
103 importStatic = 2; |
108 importStaticA = 2; |
|
109 } |
|
110 } |
|
111 |
|
112 // now as final constants |
|
113 private static final int assignB = SimpleAssignClassB.x; |
|
114 private static final int binaryB = BinaryExpClassB.x + 1; |
|
115 private static final int unaryB = -UnaryExpClassB.x; |
|
116 private static final int castB = (int)CastClassB.x; |
|
117 private static final int parensB = (ParensClassB.x); |
|
118 private static final int condB = (CondClassB.x == 1) ? 1 : 2; |
|
119 private static final int ifConstantB; |
|
120 private static final int importStaticB; |
|
121 static { |
|
122 if (IfClassB.x == 1) { |
|
123 ifConstantB = 1; |
|
124 } else { |
|
125 ifConstantB = 2; |
|
126 } |
|
127 } |
|
128 static { |
|
129 if (staticFieldB == 1) { |
|
130 importStaticB = 1; |
|
131 } else { |
|
132 importStaticB = 2; |
104 } |
133 } |
105 } |
134 } |
106 } |
135 } |
107 |
136 |
108 class SimpleAssignClass { |
137 class SimpleAssignClassA { |
109 public static final int x = 1; |
138 public static final int x = 1; |
110 } |
139 } |
111 |
140 |
112 class BinaryExpClass { |
141 class SimpleAssignClassB { |
113 public static final int x = 1; |
142 public static final int x = 1; |
114 } |
143 } |
115 |
144 |
116 class UnaryExpClass { |
145 class BinaryExpClassA { |
117 public static final int x = 1; |
146 public static final int x = 1; |
118 } |
147 } |
119 |
148 |
120 class CastClass { |
149 class BinaryExpClassB { |
121 public static final int x = 1; |
150 public static final int x = 1; |
122 } |
151 } |
123 |
152 |
124 class ParensClass { |
153 class UnaryExpClassA { |
125 public static final int x = 1; |
154 public static final int x = 1; |
126 } |
155 } |
127 |
156 |
128 class CondClass { |
157 class UnaryExpClassB { |
129 public static final int x = 1; |
158 public static final int x = 1; |
130 } |
159 } |
131 |
160 |
132 class IfClass { |
161 class CastClassA { |
133 public static final int x = 1; |
162 public static final int x = 1; |
134 } |
163 } |
|
164 |
|
165 class CastClassB { |
|
166 public static final int x = 1; |
|
167 } |
|
168 |
|
169 class ParensClassA { |
|
170 public static final int x = 1; |
|
171 } |
|
172 |
|
173 class ParensClassB { |
|
174 public static final int x = 1; |
|
175 } |
|
176 |
|
177 class CondClassA { |
|
178 public static final int x = 1; |
|
179 } |
|
180 |
|
181 class CondClassB { |
|
182 public static final int x = 1; |
|
183 } |
|
184 |
|
185 class IfClassA { |
|
186 public static final int x = 1; |
|
187 } |
|
188 |
|
189 class IfClassB { |
|
190 public static final int x = 1; |
|
191 } |