vromero@1432: /* vromero@2810: * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. vromero@1432: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. vromero@1432: * vromero@1432: * This code is free software; you can redistribute it and/or modify it vromero@1432: * under the terms of the GNU General Public License version 2 only, as vromero@1432: * published by the Free Software Foundation. Oracle designates this vromero@1432: * particular file as subject to the "Classpath" exception as provided vromero@1432: * by Oracle in the LICENSE file that accompanied this code. vromero@1432: * vromero@1432: * This code is distributed in the hope that it will be useful, but WITHOUT vromero@1432: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or vromero@1432: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License vromero@1432: * version 2 for more details (a copy is included in the LICENSE file that vromero@1432: * accompanied this code). vromero@1432: * vromero@1432: * You should have received a copy of the GNU General Public License version vromero@1432: * 2 along with this work; if not, write to the Free Software Foundation, vromero@1432: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. vromero@1432: * vromero@1432: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA vromero@1432: * or visit www.oracle.com if you need additional information or have any vromero@1432: * questions. vromero@1432: */ vromero@1432: vromero@1432: /* vromero@1432: * @test vromero@2810: * @bug 7153958 8073372 vromero@1432: * @summary add constant pool reference to class containing inlined constants vromero@2810: * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java vromero@1432: * @run main CPoolRefClassContainingInlinedCts vromero@1432: */ vromero@1432: vromero@1432: import com.sun.tools.classfile.ClassFile; vromero@1432: import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; vromero@1432: import com.sun.tools.classfile.ConstantPool.CPInfo; vromero@1432: import com.sun.tools.classfile.ConstantPoolException; vromero@1432: import java.io.File; vromero@1432: import java.io.IOException; vromero@1432: vromero@2810: import static pkg.ClassToBeStaticallyImportedA.staticFieldA; vromero@2810: import static pkg.ClassToBeStaticallyImportedB.staticFieldB; vromero@1432: vromero@1432: public class CPoolRefClassContainingInlinedCts { vromero@1432: vromero@1432: public static void main(String args[]) throws Exception { vromero@1432: new CPoolRefClassContainingInlinedCts().run(); vromero@1432: } vromero@1432: vromero@1432: void run() throws Exception { vromero@1432: checkReferences(); vromero@1432: } vromero@1432: vromero@1432: int numberOfReferencedClassesToBeChecked = 0; vromero@1432: vromero@1432: void checkClassName(String className) { vromero@1432: switch (className) { vromero@2810: case "SimpleAssignClassA" : case "BinaryExpClassA": vromero@2810: case "UnaryExpClassA" : case "CastClassA": vromero@2810: case "ParensClassA" : case "CondClassA": vromero@2810: case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA": vromero@2810: case "SimpleAssignClassB" : case "BinaryExpClassB": vromero@2810: case "UnaryExpClassB" : case "CastClassB": vromero@2810: case "ParensClassB" : case "CondClassB": vromero@2810: case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB": vromero@1432: numberOfReferencedClassesToBeChecked++; vromero@1432: } vromero@1432: } vromero@1432: vromero@1432: void checkReferences() throws IOException, ConstantPoolException { vromero@1432: File testClasses = new File(System.getProperty("test.classes")); vromero@1432: File file = new File(testClasses, vromero@1432: CPoolRefClassContainingInlinedCts.class.getName() + ".class"); vromero@1432: ClassFile classFile = ClassFile.read(file); vromero@1432: int i = 1; vromero@1432: CPInfo cpInfo; vromero@1432: while (i < classFile.constant_pool.size()) { vromero@1432: cpInfo = classFile.constant_pool.get(i); vromero@1432: if (cpInfo instanceof CONSTANT_Class_info) { vromero@1432: checkClassName(((CONSTANT_Class_info)cpInfo).getName()); vromero@1432: } vromero@1432: i += cpInfo.size(); vromero@1432: } vromero@2810: if (numberOfReferencedClassesToBeChecked != 16) { vromero@1432: throw new AssertionError("Class reference missing in the constant pool"); vromero@1432: } vromero@1432: } vromero@1432: vromero@2810: private int assignA = SimpleAssignClassA.x; vromero@2810: private int binaryA = BinaryExpClassA.x + 1; vromero@2810: private int unaryA = -UnaryExpClassA.x; vromero@2810: private int castA = (int)CastClassA.x; vromero@2810: private int parensA = (ParensClassA.x); vromero@2810: private int condA = (CondClassA.x == 1) ? 1 : 2; vromero@2810: private static int ifConstantA; vromero@2810: private static int importStaticA; vromero@1432: static { vromero@2810: if (IfClassA.x == 1) { vromero@2810: ifConstantA = 1; vromero@1432: } else { vromero@2810: ifConstantA = 2; vromero@1432: } vromero@1432: } vromero@1432: static { vromero@2810: if (staticFieldA == 1) { vromero@2810: importStaticA = 1; vromero@1432: } else { vromero@2810: importStaticA = 2; vromero@2810: } vromero@2810: } vromero@2810: vromero@2810: // now as final constants vromero@2810: private static final int assignB = SimpleAssignClassB.x; vromero@2810: private static final int binaryB = BinaryExpClassB.x + 1; vromero@2810: private static final int unaryB = -UnaryExpClassB.x; vromero@2810: private static final int castB = (int)CastClassB.x; vromero@2810: private static final int parensB = (ParensClassB.x); vromero@2810: private static final int condB = (CondClassB.x == 1) ? 1 : 2; vromero@2810: private static final int ifConstantB; vromero@2810: private static final int importStaticB; vromero@2810: static { vromero@2810: if (IfClassB.x == 1) { vromero@2810: ifConstantB = 1; vromero@2810: } else { vromero@2810: ifConstantB = 2; vromero@2810: } vromero@2810: } vromero@2810: static { vromero@2810: if (staticFieldB == 1) { vromero@2810: importStaticB = 1; vromero@2810: } else { vromero@2810: importStaticB = 2; vromero@1432: } vromero@1432: } vromero@1432: } vromero@1432: vromero@2810: class SimpleAssignClassA { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@2810: class SimpleAssignClassB { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@2810: class BinaryExpClassA { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@2810: class BinaryExpClassB { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@2810: class UnaryExpClassA { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@2810: class UnaryExpClassB { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@2810: class CastClassA { vromero@1432: public static final int x = 1; vromero@1432: } vromero@2810: vromero@2810: class CastClassB { vromero@2810: public static final int x = 1; vromero@2810: } vromero@2810: vromero@2810: class ParensClassA { vromero@2810: public static final int x = 1; vromero@2810: } vromero@2810: vromero@2810: class ParensClassB { vromero@2810: public static final int x = 1; vromero@2810: } vromero@2810: vromero@2810: class CondClassA { vromero@2810: public static final int x = 1; vromero@2810: } vromero@2810: vromero@2810: class CondClassB { vromero@2810: public static final int x = 1; vromero@2810: } vromero@2810: vromero@2810: class IfClassA { vromero@2810: public static final int x = 1; vromero@2810: } vromero@2810: vromero@2810: class IfClassB { vromero@2810: public static final int x = 1; vromero@2810: }