Fri, 24 Apr 2020 03:58:51 +0100
Merge
1 /*
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.
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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 /*
27 * @test
28 * @bug 7153958 8073372
29 * @summary add constant pool reference to class containing inlined constants
30 * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java
31 * @run main CPoolRefClassContainingInlinedCts
32 */
34 import com.sun.tools.classfile.ClassFile;
35 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
36 import com.sun.tools.classfile.ConstantPool.CPInfo;
37 import com.sun.tools.classfile.ConstantPoolException;
38 import java.io.File;
39 import java.io.IOException;
41 import static pkg.ClassToBeStaticallyImportedA.staticFieldA;
42 import static pkg.ClassToBeStaticallyImportedB.staticFieldB;
44 public class CPoolRefClassContainingInlinedCts {
46 public static void main(String args[]) throws Exception {
47 new CPoolRefClassContainingInlinedCts().run();
48 }
50 void run() throws Exception {
51 checkReferences();
52 }
54 int numberOfReferencedClassesToBeChecked = 0;
56 void checkClassName(String className) {
57 switch (className) {
58 case "SimpleAssignClassA" : case "BinaryExpClassA":
59 case "UnaryExpClassA" : case "CastClassA":
60 case "ParensClassA" : case "CondClassA":
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":
66 numberOfReferencedClassesToBeChecked++;
67 }
68 }
70 void checkReferences() throws IOException, ConstantPoolException {
71 File testClasses = new File(System.getProperty("test.classes"));
72 File file = new File(testClasses,
73 CPoolRefClassContainingInlinedCts.class.getName() + ".class");
74 ClassFile classFile = ClassFile.read(file);
75 int i = 1;
76 CPInfo cpInfo;
77 while (i < classFile.constant_pool.size()) {
78 cpInfo = classFile.constant_pool.get(i);
79 if (cpInfo instanceof CONSTANT_Class_info) {
80 checkClassName(((CONSTANT_Class_info)cpInfo).getName());
81 }
82 i += cpInfo.size();
83 }
84 if (numberOfReferencedClassesToBeChecked != 16) {
85 throw new AssertionError("Class reference missing in the constant pool");
86 }
87 }
89 private int assignA = SimpleAssignClassA.x;
90 private int binaryA = BinaryExpClassA.x + 1;
91 private int unaryA = -UnaryExpClassA.x;
92 private int castA = (int)CastClassA.x;
93 private int parensA = (ParensClassA.x);
94 private int condA = (CondClassA.x == 1) ? 1 : 2;
95 private static int ifConstantA;
96 private static int importStaticA;
97 static {
98 if (IfClassA.x == 1) {
99 ifConstantA = 1;
100 } else {
101 ifConstantA = 2;
102 }
103 }
104 static {
105 if (staticFieldA == 1) {
106 importStaticA = 1;
107 } else {
108 importStaticA = 2;
109 }
110 }
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;
133 }
134 }
135 }
137 class SimpleAssignClassA {
138 public static final int x = 1;
139 }
141 class SimpleAssignClassB {
142 public static final int x = 1;
143 }
145 class BinaryExpClassA {
146 public static final int x = 1;
147 }
149 class BinaryExpClassB {
150 public static final int x = 1;
151 }
153 class UnaryExpClassA {
154 public static final int x = 1;
155 }
157 class UnaryExpClassB {
158 public static final int x = 1;
159 }
161 class CastClassA {
162 public static final int x = 1;
163 }
165 class CastClassB {
166 public static final int x = 1;
167 }
169 class ParensClassA {
170 public static final int x = 1;
171 }
173 class ParensClassB {
174 public static final int x = 1;
175 }
177 class CondClassA {
178 public static final int x = 1;
179 }
181 class CondClassB {
182 public static final int x = 1;
183 }
185 class IfClassA {
186 public static final int x = 1;
187 }
189 class IfClassB {
190 public static final int x = 1;
191 }