Mon, 01 Jun 2015 11:07:29 -0700
8073372: Redundant CONSTANT_Class entry not generated for inlined constant
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu May 28 16:46:23 2015 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Mon Jun 01 11:07:29 2015 -0700 1.3 @@ -514,6 +514,10 @@ 1.4 clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); 1.5 } else { 1.6 checkStringConstant(vdef.init.pos(), sym.getConstValue()); 1.7 + /* if the init contains a reference to an external class, add it to the 1.8 + * constant's pool 1.9 + */ 1.10 + vdef.init.accept(classReferenceVisitor); 1.11 } 1.12 } 1.13 break; 1.14 @@ -2431,9 +2435,12 @@ 1.15 && !allowGenerics // no Miranda methods available with generics 1.16 ) 1.17 implementInterfaceMethods(c); 1.18 - cdef.defs = normalizeDefs(cdef.defs, c); 1.19 c.pool = pool; 1.20 pool.reset(); 1.21 + /* method normalizeDefs() can add references to external classes into the constant pool 1.22 + * so it should be called after pool.reset() 1.23 + */ 1.24 + cdef.defs = normalizeDefs(cdef.defs, c); 1.25 generateReferencesToPrunedTree(c, pool); 1.26 Env<GenContext> localEnv = 1.27 new Env<GenContext>(cdef, new GenContext());
2.1 --- a/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Thu May 28 16:46:23 2015 -0700 2.2 +++ b/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java Mon Jun 01 11:07:29 2015 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -25,9 +25,9 @@ 2.11 2.12 /* 2.13 * @test 2.14 - * @bug 7153958 2.15 + * @bug 7153958 8073372 2.16 * @summary add constant pool reference to class containing inlined constants 2.17 - * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java 2.18 + * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java 2.19 * @run main CPoolRefClassContainingInlinedCts 2.20 */ 2.21 2.22 @@ -38,7 +38,8 @@ 2.23 import java.io.File; 2.24 import java.io.IOException; 2.25 2.26 -import static pkg.ClassToBeStaticallyImported.staticField; 2.27 +import static pkg.ClassToBeStaticallyImportedA.staticFieldA; 2.28 +import static pkg.ClassToBeStaticallyImportedB.staticFieldB; 2.29 2.30 public class CPoolRefClassContainingInlinedCts { 2.31 2.32 @@ -54,10 +55,14 @@ 2.33 2.34 void checkClassName(String className) { 2.35 switch (className) { 2.36 - case "SimpleAssignClass" : case "BinaryExpClass": 2.37 - case "UnaryExpClass" : case "CastClass": 2.38 - case "ParensClass" : case "CondClass": 2.39 - case "IfClass" : case "pkg/ClassToBeStaticallyImported": 2.40 + case "SimpleAssignClassA" : case "BinaryExpClassA": 2.41 + case "UnaryExpClassA" : case "CastClassA": 2.42 + case "ParensClassA" : case "CondClassA": 2.43 + case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA": 2.44 + case "SimpleAssignClassB" : case "BinaryExpClassB": 2.45 + case "UnaryExpClassB" : case "CastClassB": 2.46 + case "ParensClassB" : case "CondClassB": 2.47 + case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB": 2.48 numberOfReferencedClassesToBeChecked++; 2.49 } 2.50 } 2.51 @@ -76,59 +81,111 @@ 2.52 } 2.53 i += cpInfo.size(); 2.54 } 2.55 - if (numberOfReferencedClassesToBeChecked != 8) { 2.56 + if (numberOfReferencedClassesToBeChecked != 16) { 2.57 throw new AssertionError("Class reference missing in the constant pool"); 2.58 } 2.59 } 2.60 2.61 - private int assign = SimpleAssignClass.x; 2.62 - private int binary = BinaryExpClass.x + 1; 2.63 - private int unary = -UnaryExpClass.x; 2.64 - private int cast = (int)CastClass.x; 2.65 - private int parens = (ParensClass.x); 2.66 - private int cond = (CondClass.x == 1) ? 1 : 2; 2.67 - private static int ifConstant; 2.68 - private static int importStatic; 2.69 + private int assignA = SimpleAssignClassA.x; 2.70 + private int binaryA = BinaryExpClassA.x + 1; 2.71 + private int unaryA = -UnaryExpClassA.x; 2.72 + private int castA = (int)CastClassA.x; 2.73 + private int parensA = (ParensClassA.x); 2.74 + private int condA = (CondClassA.x == 1) ? 1 : 2; 2.75 + private static int ifConstantA; 2.76 + private static int importStaticA; 2.77 static { 2.78 - if (IfClass.x == 1) { 2.79 - ifConstant = 1; 2.80 + if (IfClassA.x == 1) { 2.81 + ifConstantA = 1; 2.82 } else { 2.83 - ifConstant = 2; 2.84 + ifConstantA = 2; 2.85 } 2.86 } 2.87 static { 2.88 - if (staticField == 1) { 2.89 - importStatic = 1; 2.90 + if (staticFieldA == 1) { 2.91 + importStaticA = 1; 2.92 } else { 2.93 - importStatic = 2; 2.94 + importStaticA = 2; 2.95 + } 2.96 + } 2.97 + 2.98 + // now as final constants 2.99 + private static final int assignB = SimpleAssignClassB.x; 2.100 + private static final int binaryB = BinaryExpClassB.x + 1; 2.101 + private static final int unaryB = -UnaryExpClassB.x; 2.102 + private static final int castB = (int)CastClassB.x; 2.103 + private static final int parensB = (ParensClassB.x); 2.104 + private static final int condB = (CondClassB.x == 1) ? 1 : 2; 2.105 + private static final int ifConstantB; 2.106 + private static final int importStaticB; 2.107 + static { 2.108 + if (IfClassB.x == 1) { 2.109 + ifConstantB = 1; 2.110 + } else { 2.111 + ifConstantB = 2; 2.112 + } 2.113 + } 2.114 + static { 2.115 + if (staticFieldB == 1) { 2.116 + importStaticB = 1; 2.117 + } else { 2.118 + importStaticB = 2; 2.119 } 2.120 } 2.121 } 2.122 2.123 -class SimpleAssignClass { 2.124 +class SimpleAssignClassA { 2.125 public static final int x = 1; 2.126 } 2.127 2.128 -class BinaryExpClass { 2.129 +class SimpleAssignClassB { 2.130 public static final int x = 1; 2.131 } 2.132 2.133 -class UnaryExpClass { 2.134 +class BinaryExpClassA { 2.135 public static final int x = 1; 2.136 } 2.137 2.138 -class CastClass { 2.139 +class BinaryExpClassB { 2.140 public static final int x = 1; 2.141 } 2.142 2.143 -class ParensClass { 2.144 +class UnaryExpClassA { 2.145 public static final int x = 1; 2.146 } 2.147 2.148 -class CondClass { 2.149 +class UnaryExpClassB { 2.150 public static final int x = 1; 2.151 } 2.152 2.153 -class IfClass { 2.154 +class CastClassA { 2.155 public static final int x = 1; 2.156 } 2.157 + 2.158 +class CastClassB { 2.159 + public static final int x = 1; 2.160 +} 2.161 + 2.162 +class ParensClassA { 2.163 + public static final int x = 1; 2.164 +} 2.165 + 2.166 +class ParensClassB { 2.167 + public static final int x = 1; 2.168 +} 2.169 + 2.170 +class CondClassA { 2.171 + public static final int x = 1; 2.172 +} 2.173 + 2.174 +class CondClassB { 2.175 + public static final int x = 1; 2.176 +} 2.177 + 2.178 +class IfClassA { 2.179 + public static final int x = 1; 2.180 +} 2.181 + 2.182 +class IfClassB { 2.183 + public static final int x = 1; 2.184 +}
3.1 --- a/test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java Thu May 28 16:46:23 2015 -0700 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,29 +0,0 @@ 3.4 -/* 3.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 3.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 - * 3.8 - * This code is free software; you can redistribute it and/or modify it 3.9 - * under the terms of the GNU General Public License version 2 only, as 3.10 - * published by the Free Software Foundation. Oracle designates this 3.11 - * particular file as subject to the "Classpath" exception as provided 3.12 - * by Oracle in the LICENSE file that accompanied this code. 3.13 - * 3.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 3.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.17 - * version 2 for more details (a copy is included in the LICENSE file that 3.18 - * accompanied this code). 3.19 - * 3.20 - * You should have received a copy of the GNU General Public License version 3.21 - * 2 along with this work; if not, write to the Free Software Foundation, 3.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.23 - * 3.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.25 - * or visit www.oracle.com if you need additional information or have any 3.26 - * questions. 3.27 - */ 3.28 -package pkg; 3.29 - 3.30 -public class ClassToBeStaticallyImported { 3.31 - public static final int staticField = 1; 3.32 -}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java Mon Jun 01 11:07:29 2015 -0700 4.3 @@ -0,0 +1,29 @@ 4.4 +/* 4.5 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. Oracle designates this 4.11 + * particular file as subject to the "Classpath" exception as provided 4.12 + * by Oracle in the LICENSE file that accompanied this code. 4.13 + * 4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.17 + * version 2 for more details (a copy is included in the LICENSE file that 4.18 + * accompanied this code). 4.19 + * 4.20 + * You should have received a copy of the GNU General Public License version 4.21 + * 2 along with this work; if not, write to the Free Software Foundation, 4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.23 + * 4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.25 + * or visit www.oracle.com if you need additional information or have any 4.26 + * questions. 4.27 + */ 4.28 +package pkg; 4.29 + 4.30 +public class ClassToBeStaticallyImportedA { 4.31 + public static final int staticFieldA = 1; 4.32 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java Mon Jun 01 11:07:29 2015 -0700 5.3 @@ -0,0 +1,29 @@ 5.4 +/* 5.5 + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. Oracle designates this 5.11 + * particular file as subject to the "Classpath" exception as provided 5.12 + * by Oracle in the LICENSE file that accompanied this code. 5.13 + * 5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.17 + * version 2 for more details (a copy is included in the LICENSE file that 5.18 + * accompanied this code). 5.19 + * 5.20 + * You should have received a copy of the GNU General Public License version 5.21 + * 2 along with this work; if not, write to the Free Software Foundation, 5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.23 + * 5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.25 + * or visit www.oracle.com if you need additional information or have any 5.26 + * questions. 5.27 + */ 5.28 +package pkg; 5.29 + 5.30 +public class ClassToBeStaticallyImportedB { 5.31 + public static final int staticFieldB = 1; 5.32 +}