test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java

Mon, 16 Oct 2017 16:07:48 +0800

author
aoqi
date
Mon, 16 Oct 2017 16:07:48 +0800
changeset 2893
ca5783d9a597
parent 2810
1b59f823d630
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

merge

aoqi@0 1 /*
vromero@2810 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 /*
aoqi@0 27 * @test
vromero@2810 28 * @bug 7153958 8073372
aoqi@0 29 * @summary add constant pool reference to class containing inlined constants
vromero@2810 30 * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java
aoqi@0 31 * @run main CPoolRefClassContainingInlinedCts
aoqi@0 32 */
aoqi@0 33
aoqi@0 34 import com.sun.tools.classfile.ClassFile;
aoqi@0 35 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
aoqi@0 36 import com.sun.tools.classfile.ConstantPool.CPInfo;
aoqi@0 37 import com.sun.tools.classfile.ConstantPoolException;
aoqi@0 38 import java.io.File;
aoqi@0 39 import java.io.IOException;
aoqi@0 40
vromero@2810 41 import static pkg.ClassToBeStaticallyImportedA.staticFieldA;
vromero@2810 42 import static pkg.ClassToBeStaticallyImportedB.staticFieldB;
aoqi@0 43
aoqi@0 44 public class CPoolRefClassContainingInlinedCts {
aoqi@0 45
aoqi@0 46 public static void main(String args[]) throws Exception {
aoqi@0 47 new CPoolRefClassContainingInlinedCts().run();
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 void run() throws Exception {
aoqi@0 51 checkReferences();
aoqi@0 52 }
aoqi@0 53
aoqi@0 54 int numberOfReferencedClassesToBeChecked = 0;
aoqi@0 55
aoqi@0 56 void checkClassName(String className) {
aoqi@0 57 switch (className) {
vromero@2810 58 case "SimpleAssignClassA" : case "BinaryExpClassA":
vromero@2810 59 case "UnaryExpClassA" : case "CastClassA":
vromero@2810 60 case "ParensClassA" : case "CondClassA":
vromero@2810 61 case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA":
vromero@2810 62 case "SimpleAssignClassB" : case "BinaryExpClassB":
vromero@2810 63 case "UnaryExpClassB" : case "CastClassB":
vromero@2810 64 case "ParensClassB" : case "CondClassB":
vromero@2810 65 case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB":
aoqi@0 66 numberOfReferencedClassesToBeChecked++;
aoqi@0 67 }
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 void checkReferences() throws IOException, ConstantPoolException {
aoqi@0 71 File testClasses = new File(System.getProperty("test.classes"));
aoqi@0 72 File file = new File(testClasses,
aoqi@0 73 CPoolRefClassContainingInlinedCts.class.getName() + ".class");
aoqi@0 74 ClassFile classFile = ClassFile.read(file);
aoqi@0 75 int i = 1;
aoqi@0 76 CPInfo cpInfo;
aoqi@0 77 while (i < classFile.constant_pool.size()) {
aoqi@0 78 cpInfo = classFile.constant_pool.get(i);
aoqi@0 79 if (cpInfo instanceof CONSTANT_Class_info) {
aoqi@0 80 checkClassName(((CONSTANT_Class_info)cpInfo).getName());
aoqi@0 81 }
aoqi@0 82 i += cpInfo.size();
aoqi@0 83 }
vromero@2810 84 if (numberOfReferencedClassesToBeChecked != 16) {
aoqi@0 85 throw new AssertionError("Class reference missing in the constant pool");
aoqi@0 86 }
aoqi@0 87 }
aoqi@0 88
vromero@2810 89 private int assignA = SimpleAssignClassA.x;
vromero@2810 90 private int binaryA = BinaryExpClassA.x + 1;
vromero@2810 91 private int unaryA = -UnaryExpClassA.x;
vromero@2810 92 private int castA = (int)CastClassA.x;
vromero@2810 93 private int parensA = (ParensClassA.x);
vromero@2810 94 private int condA = (CondClassA.x == 1) ? 1 : 2;
vromero@2810 95 private static int ifConstantA;
vromero@2810 96 private static int importStaticA;
aoqi@0 97 static {
vromero@2810 98 if (IfClassA.x == 1) {
vromero@2810 99 ifConstantA = 1;
aoqi@0 100 } else {
vromero@2810 101 ifConstantA = 2;
aoqi@0 102 }
aoqi@0 103 }
aoqi@0 104 static {
vromero@2810 105 if (staticFieldA == 1) {
vromero@2810 106 importStaticA = 1;
aoqi@0 107 } else {
vromero@2810 108 importStaticA = 2;
vromero@2810 109 }
vromero@2810 110 }
vromero@2810 111
vromero@2810 112 // now as final constants
vromero@2810 113 private static final int assignB = SimpleAssignClassB.x;
vromero@2810 114 private static final int binaryB = BinaryExpClassB.x + 1;
vromero@2810 115 private static final int unaryB = -UnaryExpClassB.x;
vromero@2810 116 private static final int castB = (int)CastClassB.x;
vromero@2810 117 private static final int parensB = (ParensClassB.x);
vromero@2810 118 private static final int condB = (CondClassB.x == 1) ? 1 : 2;
vromero@2810 119 private static final int ifConstantB;
vromero@2810 120 private static final int importStaticB;
vromero@2810 121 static {
vromero@2810 122 if (IfClassB.x == 1) {
vromero@2810 123 ifConstantB = 1;
vromero@2810 124 } else {
vromero@2810 125 ifConstantB = 2;
vromero@2810 126 }
vromero@2810 127 }
vromero@2810 128 static {
vromero@2810 129 if (staticFieldB == 1) {
vromero@2810 130 importStaticB = 1;
vromero@2810 131 } else {
vromero@2810 132 importStaticB = 2;
aoqi@0 133 }
aoqi@0 134 }
aoqi@0 135 }
aoqi@0 136
vromero@2810 137 class SimpleAssignClassA {
aoqi@0 138 public static final int x = 1;
aoqi@0 139 }
aoqi@0 140
vromero@2810 141 class SimpleAssignClassB {
aoqi@0 142 public static final int x = 1;
aoqi@0 143 }
aoqi@0 144
vromero@2810 145 class BinaryExpClassA {
aoqi@0 146 public static final int x = 1;
aoqi@0 147 }
aoqi@0 148
vromero@2810 149 class BinaryExpClassB {
aoqi@0 150 public static final int x = 1;
aoqi@0 151 }
aoqi@0 152
vromero@2810 153 class UnaryExpClassA {
aoqi@0 154 public static final int x = 1;
aoqi@0 155 }
aoqi@0 156
vromero@2810 157 class UnaryExpClassB {
aoqi@0 158 public static final int x = 1;
aoqi@0 159 }
aoqi@0 160
vromero@2810 161 class CastClassA {
aoqi@0 162 public static final int x = 1;
aoqi@0 163 }
vromero@2810 164
vromero@2810 165 class CastClassB {
vromero@2810 166 public static final int x = 1;
vromero@2810 167 }
vromero@2810 168
vromero@2810 169 class ParensClassA {
vromero@2810 170 public static final int x = 1;
vromero@2810 171 }
vromero@2810 172
vromero@2810 173 class ParensClassB {
vromero@2810 174 public static final int x = 1;
vromero@2810 175 }
vromero@2810 176
vromero@2810 177 class CondClassA {
vromero@2810 178 public static final int x = 1;
vromero@2810 179 }
vromero@2810 180
vromero@2810 181 class CondClassB {
vromero@2810 182 public static final int x = 1;
vromero@2810 183 }
vromero@2810 184
vromero@2810 185 class IfClassA {
vromero@2810 186 public static final int x = 1;
vromero@2810 187 }
vromero@2810 188
vromero@2810 189 class IfClassB {
vromero@2810 190 public static final int x = 1;
vromero@2810 191 }

mercurial