test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java

Wed, 14 Nov 2018 10:18:25 -0800

author
diazhou
date
Wed, 14 Nov 2018 10:18:25 -0800
changeset 3762
7909abb85562
parent 2810
1b59f823d630
child 2893
ca5783d9a597
permissions
-rw-r--r--

Added tag jdk8u201-b04 for changeset a7f48b9dfb82

vromero@1432 1 /*
vromero@2810 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
vromero@1432 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
vromero@1432 4 *
vromero@1432 5 * This code is free software; you can redistribute it and/or modify it
vromero@1432 6 * under the terms of the GNU General Public License version 2 only, as
vromero@1432 7 * published by the Free Software Foundation. Oracle designates this
vromero@1432 8 * particular file as subject to the "Classpath" exception as provided
vromero@1432 9 * by Oracle in the LICENSE file that accompanied this code.
vromero@1432 10 *
vromero@1432 11 * This code is distributed in the hope that it will be useful, but WITHOUT
vromero@1432 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
vromero@1432 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
vromero@1432 14 * version 2 for more details (a copy is included in the LICENSE file that
vromero@1432 15 * accompanied this code).
vromero@1432 16 *
vromero@1432 17 * You should have received a copy of the GNU General Public License version
vromero@1432 18 * 2 along with this work; if not, write to the Free Software Foundation,
vromero@1432 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
vromero@1432 20 *
vromero@1432 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
vromero@1432 22 * or visit www.oracle.com if you need additional information or have any
vromero@1432 23 * questions.
vromero@1432 24 */
vromero@1432 25
vromero@1432 26 /*
vromero@1432 27 * @test
vromero@2810 28 * @bug 7153958 8073372
vromero@1432 29 * @summary add constant pool reference to class containing inlined constants
vromero@2810 30 * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java
vromero@1432 31 * @run main CPoolRefClassContainingInlinedCts
vromero@1432 32 */
vromero@1432 33
vromero@1432 34 import com.sun.tools.classfile.ClassFile;
vromero@1432 35 import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info;
vromero@1432 36 import com.sun.tools.classfile.ConstantPool.CPInfo;
vromero@1432 37 import com.sun.tools.classfile.ConstantPoolException;
vromero@1432 38 import java.io.File;
vromero@1432 39 import java.io.IOException;
vromero@1432 40
vromero@2810 41 import static pkg.ClassToBeStaticallyImportedA.staticFieldA;
vromero@2810 42 import static pkg.ClassToBeStaticallyImportedB.staticFieldB;
vromero@1432 43
vromero@1432 44 public class CPoolRefClassContainingInlinedCts {
vromero@1432 45
vromero@1432 46 public static void main(String args[]) throws Exception {
vromero@1432 47 new CPoolRefClassContainingInlinedCts().run();
vromero@1432 48 }
vromero@1432 49
vromero@1432 50 void run() throws Exception {
vromero@1432 51 checkReferences();
vromero@1432 52 }
vromero@1432 53
vromero@1432 54 int numberOfReferencedClassesToBeChecked = 0;
vromero@1432 55
vromero@1432 56 void checkClassName(String className) {
vromero@1432 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":
vromero@1432 66 numberOfReferencedClassesToBeChecked++;
vromero@1432 67 }
vromero@1432 68 }
vromero@1432 69
vromero@1432 70 void checkReferences() throws IOException, ConstantPoolException {
vromero@1432 71 File testClasses = new File(System.getProperty("test.classes"));
vromero@1432 72 File file = new File(testClasses,
vromero@1432 73 CPoolRefClassContainingInlinedCts.class.getName() + ".class");
vromero@1432 74 ClassFile classFile = ClassFile.read(file);
vromero@1432 75 int i = 1;
vromero@1432 76 CPInfo cpInfo;
vromero@1432 77 while (i < classFile.constant_pool.size()) {
vromero@1432 78 cpInfo = classFile.constant_pool.get(i);
vromero@1432 79 if (cpInfo instanceof CONSTANT_Class_info) {
vromero@1432 80 checkClassName(((CONSTANT_Class_info)cpInfo).getName());
vromero@1432 81 }
vromero@1432 82 i += cpInfo.size();
vromero@1432 83 }
vromero@2810 84 if (numberOfReferencedClassesToBeChecked != 16) {
vromero@1432 85 throw new AssertionError("Class reference missing in the constant pool");
vromero@1432 86 }
vromero@1432 87 }
vromero@1432 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;
vromero@1432 97 static {
vromero@2810 98 if (IfClassA.x == 1) {
vromero@2810 99 ifConstantA = 1;
vromero@1432 100 } else {
vromero@2810 101 ifConstantA = 2;
vromero@1432 102 }
vromero@1432 103 }
vromero@1432 104 static {
vromero@2810 105 if (staticFieldA == 1) {
vromero@2810 106 importStaticA = 1;
vromero@1432 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;
vromero@1432 133 }
vromero@1432 134 }
vromero@1432 135 }
vromero@1432 136
vromero@2810 137 class SimpleAssignClassA {
vromero@1432 138 public static final int x = 1;
vromero@1432 139 }
vromero@1432 140
vromero@2810 141 class SimpleAssignClassB {
vromero@1432 142 public static final int x = 1;
vromero@1432 143 }
vromero@1432 144
vromero@2810 145 class BinaryExpClassA {
vromero@1432 146 public static final int x = 1;
vromero@1432 147 }
vromero@1432 148
vromero@2810 149 class BinaryExpClassB {
vromero@1432 150 public static final int x = 1;
vromero@1432 151 }
vromero@1432 152
vromero@2810 153 class UnaryExpClassA {
vromero@1432 154 public static final int x = 1;
vromero@1432 155 }
vromero@1432 156
vromero@2810 157 class UnaryExpClassB {
vromero@1432 158 public static final int x = 1;
vromero@1432 159 }
vromero@1432 160
vromero@2810 161 class CastClassA {
vromero@1432 162 public static final int x = 1;
vromero@1432 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