CPoolRefClassContainingInlinedCts.java revision 2942:08092deced3f
143809Sjkh/* 243809Sjkh * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 343809Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 443809Sjkh * 543809Sjkh * This code is free software; you can redistribute it and/or modify it 643809Sjkh * under the terms of the GNU General Public License version 2 only, as 743809Sjkh * published by the Free Software Foundation. Oracle designates this 843809Sjkh * particular file as subject to the "Classpath" exception as provided 943809Sjkh * by Oracle in the LICENSE file that accompanied this code. 1059674Ssheldonh * 1159674Ssheldonh * This code is distributed in the hope that it will be useful, but WITHOUT 1259674Ssheldonh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1354949Ssheldonh * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1443809Sjkh * version 2 for more details (a copy is included in the LICENSE file that 1543809Sjkh * accompanied this code). 1650472Speter * 1743809Sjkh * You should have received a copy of the GNU General Public License version 1843809Sjkh * 2 along with this work; if not, write to the Free Software Foundation, 1948290Sjseger * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2043809Sjkh * 2143809Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2243809Sjkh * or visit www.oracle.com if you need additional information or have any 2348785Siwasaki * questions. 2448785Siwasaki */ 2548785Siwasaki 2643809Sjkh/* 2743809Sjkh * @test 2854041Simp * @bug 7153958 2943809Sjkh * @summary add constant pool reference to class containing inlined constants 3048554Shosokawa * @modules jdk.jdeps/com.sun.tools.classfile 3158979Siwasaki * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java 3243809Sjkh * @run main CPoolRefClassContainingInlinedCts 3343809Sjkh */ 3443809Sjkh 3543809Sjkhimport com.sun.tools.classfile.ClassFile; 3643809Sjkhimport com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; 3743809Sjkhimport com.sun.tools.classfile.ConstantPool.CPInfo; 3843809Sjkhimport com.sun.tools.classfile.ConstantPoolException; 3964749Sjhbimport java.io.File; 4048880Sjkhimport java.io.IOException; 4143809Sjkh 4248842Sjkhimport static pkg.ClassToBeStaticallyImported.staticField; 4348842Sjkh 4443809Sjkhpublic class CPoolRefClassContainingInlinedCts { 4545542Sdes 4643809Sjkh public static void main(String args[]) throws Exception { 4743809Sjkh new CPoolRefClassContainingInlinedCts().run(); 4860103Sache } 4957014Spaul 5061961Sdillon void run() throws Exception { 5161961Sdillon checkReferences(); 5261961Sdillon } 5361961Sdillon 5444990Sbrian int numberOfReferencedClassesToBeChecked = 0; 5543809Sjkh 5644990Sbrian void checkClassName(String className) { 5743809Sjkh switch (className) { 5849785Sobrien case "SimpleAssignClass" : case "BinaryExpClass": 5949783Sobrien case "UnaryExpClass" : case "CastClass": 6049704Sobrien case "ParensClass" : case "CondClass": 6160977Swilko case "IfClass" : case "pkg/ClassToBeStaticallyImported": 6260977Swilko numberOfReferencedClassesToBeChecked++; 6351209Sdes } 6460685Swollman } 6551224Sdes 6649603Sdes void checkReferences() throws IOException, ConstantPoolException { 6749603Sdes File testClasses = new File(System.getProperty("test.classes")); 6848687Speter File file = new File(testClasses, 6943809Sjkh CPoolRefClassContainingInlinedCts.class.getName() + ".class"); 7043809Sjkh ClassFile classFile = ClassFile.read(file); 7157860Sshin int i = 1; 7264677Ssheldonh CPInfo cpInfo; 7343809Sjkh while (i < classFile.constant_pool.size()) { 7443809Sjkh cpInfo = classFile.constant_pool.get(i); 7543809Sjkh if (cpInfo instanceof CONSTANT_Class_info) { 7643809Sjkh checkClassName(((CONSTANT_Class_info)cpInfo).getName()); 7743809Sjkh } 7843809Sjkh i += cpInfo.size(); 7943809Sjkh } 8053665Salfred if (numberOfReferencedClassesToBeChecked != 8) { 8149110Sbrian throw new AssertionError("Class reference missing in the constant pool"); 8249110Sbrian } 8349110Sbrian } 8450193Sbrian 8549110Sbrian private int assign = SimpleAssignClass.x; 8664471Sbrian private int binary = BinaryExpClass.x + 1; 8749110Sbrian private int unary = -UnaryExpClass.x; 8843809Sjkh private int cast = (int)CastClass.x; 8943809Sjkh private int parens = (ParensClass.x); 9058400Sbillf private int cond = (CondClass.x == 1) ? 1 : 2; 9163980Seivind private static int ifConstant; 9248697Ssheldonh private static int importStatic; 9343809Sjkh static { 9443809Sjkh if (IfClass.x == 1) { 9543809Sjkh ifConstant = 1; 9643809Sjkh } else { 9743809Sjkh ifConstant = 2; 9843809Sjkh } 9943809Sjkh } 10043809Sjkh static { 10143809Sjkh if (staticField == 1) { 10243809Sjkh importStatic = 1; 10343809Sjkh } else { 10443809Sjkh importStatic = 2; 10543809Sjkh } 10643809Sjkh } 10743809Sjkh} 10843809Sjkh 10952283Sobrienclass SimpleAssignClass { 11043809Sjkh public static final int x = 1; 11143809Sjkh} 11243809Sjkh 11343809Sjkhclass BinaryExpClass { 11443809Sjkh public static final int x = 1; 11543809Sjkh} 11653158Sache 11743809Sjkhclass UnaryExpClass { 11863773Sasmodai public static final int x = 1; 11943809Sjkh} 12058710Sdillon 12143809Sjkhclass CastClass { 12243809Sjkh public static final int x = 1; 12363980Seivind} 12444668Sjfitz 12543809Sjkhclass ParensClass { 12643809Sjkh public static final int x = 1; 12743809Sjkh} 12843809Sjkh 12943809Sjkhclass CondClass { 13043809Sjkh public static final int x = 1; 13143809Sjkh} 13243809Sjkh 13353611Sbrianclass IfClass { 13453611Sbrian public static final int x = 1; 13553611Sbrian} 13653611Sbrian