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 */ 25 26 /* 27 * @test 28 * @bug 7153958 29 * @summary add constant pool reference to class containing inlined constants 30 * @modules jdk.jdeps/com.sun.tools.classfile 31 * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java 32 * @run main CPoolRefClassContainingInlinedCts 33 */ 34 35 import com.sun.tools.classfile.ClassFile; 36 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; 37 import com.sun.tools.classfile.ConstantPool.CPInfo; 38 import com.sun.tools.classfile.ConstantPoolException; 39 import java.io.File; 40 import java.io.IOException; 41 42 import static pkg.ClassToBeStaticallyImported.staticField; 43 44 public class CPoolRefClassContainingInlinedCts { 45 46 public static void main(String args[]) throws Exception { 47 new CPoolRefClassContainingInlinedCts().run(); 48 } 49 50 void run() throws Exception { 51 checkReferences(); 52 } 53 54 int numberOfReferencedClassesToBeChecked = 0; 55 56 void checkClassName(String className) { 57 switch (className) { 58 case "SimpleAssignClass" : case "BinaryExpClass": 59 case "UnaryExpClass" : case "CastClass": 60 case "ParensClass" : case "CondClass": 61 case "IfClass" : case "pkg/ClassToBeStaticallyImported": 62 numberOfReferencedClassesToBeChecked++; 63 } 64 } 65 66 void checkReferences() throws IOException, ConstantPoolException { 67 File testClasses = new File(System.getProperty("test.classes")); 68 File file = new File(testClasses, 69 CPoolRefClassContainingInlinedCts.class.getName() + ".class"); 70 ClassFile classFile = ClassFile.read(file); 71 int i = 1; 72 CPInfo cpInfo; 73 while (i < classFile.constant_pool.size()) { 74 cpInfo = classFile.constant_pool.get(i); 75 if (cpInfo instanceof CONSTANT_Class_info) { 76 checkClassName(((CONSTANT_Class_info)cpInfo).getName()); 77 } 78 i += cpInfo.size(); 79 } 80 if (numberOfReferencedClassesToBeChecked != 8) { 81 throw new AssertionError("Class reference missing in the constant pool"); 82 } 83 } 84 85 private int assign = SimpleAssignClass.x; 86 private int binary = BinaryExpClass.x + 1; 87 private int unary = -UnaryExpClass.x; 88 private int cast = (int)CastClass.x; 89 private int parens = (ParensClass.x); 90 private int cond = (CondClass.x == 1) ? 1 : 2; 91 private static int ifConstant; 92 private static int importStatic; 93 static { 94 if (IfClass.x == 1) { 95 ifConstant = 1; 96 } else { 97 ifConstant = 2; 98 } 99 } 100 static { 101 if (staticField == 1) { 102 importStatic = 1; 103 } else { 104 importStatic = 2; 105 } 106 } 107 } 108 109 class SimpleAssignClass { 110 public static final int x = 1; 111 } 112 113 class BinaryExpClass { 114 public static final int x = 1; 115 } 116 117 class UnaryExpClass { 118 public static final int x = 1; 119 } 120 121 class CastClass { 122 public static final int x = 1; 123 } 124 125 class ParensClass { 126 public static final int x = 1; 127 } 128 129 class CondClass { 130 public static final int x = 1; 131 } 132 133 class IfClass { 134 public static final int x = 1; 135 }