vromero@1432: /* vromero@1432: * Copyright (c) 2012, 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@1432: * @bug 7153958 vromero@1432: * @summary add constant pool reference to class containing inlined constants vromero@1451: * @compile pkg/ClassToBeStaticallyImported.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@1432: import static pkg.ClassToBeStaticallyImported.staticField; 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@1432: case "SimpleAssignClass" : case "BinaryExpClass": vromero@1432: case "UnaryExpClass" : case "CastClass": vromero@1432: case "ParensClass" : case "CondClass": vromero@1432: case "IfClass" : case "pkg/ClassToBeStaticallyImported": 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@1432: if (numberOfReferencedClassesToBeChecked != 8) { vromero@1432: throw new AssertionError("Class reference missing in the constant pool"); vromero@1432: } vromero@1432: } vromero@1432: vromero@1432: private int assign = SimpleAssignClass.x; vromero@1432: private int binary = BinaryExpClass.x + 1; vromero@1432: private int unary = -UnaryExpClass.x; vromero@1432: private int cast = (int)CastClass.x; vromero@1432: private int parens = (ParensClass.x); vromero@1432: private int cond = (CondClass.x == 1) ? 1 : 2; vromero@1432: private static int ifConstant; vromero@1432: private static int importStatic; vromero@1432: static { vromero@1432: if (IfClass.x == 1) { vromero@1432: ifConstant = 1; vromero@1432: } else { vromero@1432: ifConstant = 2; vromero@1432: } vromero@1432: } vromero@1432: static { vromero@1432: if (staticField == 1) { vromero@1432: importStatic = 1; vromero@1432: } else { vromero@1432: importStatic = 2; vromero@1432: } vromero@1432: } vromero@1432: } vromero@1432: vromero@1432: class SimpleAssignClass { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@1432: class BinaryExpClass { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@1432: class UnaryExpClass { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@1432: class CastClass { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@1432: class ParensClass { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@1432: class CondClass { vromero@1432: public static final int x = 1; vromero@1432: } vromero@1432: vromero@1432: class IfClass { vromero@1432: public static final int x = 1; vromero@1432: }