author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 14948 | 6a2008d8e9ba |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
1 |
/* |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
4 |
* |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
10 |
* |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
15 |
* accompanied this code). |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
16 |
* |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
20 |
* |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
23 |
* questions. |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
24 |
*/ |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
25 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
26 |
/* |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
27 |
* @test |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
28 |
* @bug 7153958 |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
29 |
* @summary add constant pool reference to class containing inlined constants |
14948
6a2008d8e9ba
8004976: test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java can fail
vromero
parents:
14721
diff
changeset
|
30 |
* @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java |
14721
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
31 |
* @run main CPoolRefClassContainingInlinedCts |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
32 |
*/ |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
33 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.ClassFile; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
36 |
import com.sun.tools.classfile.ConstantPool.CPInfo; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
37 |
import com.sun.tools.classfile.ConstantPoolException; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
38 |
import java.io.File; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
39 |
import java.io.IOException; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
40 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
41 |
import static pkg.ClassToBeStaticallyImported.staticField; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
42 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
43 |
public class CPoolRefClassContainingInlinedCts { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
44 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
45 |
public static void main(String args[]) throws Exception { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
46 |
new CPoolRefClassContainingInlinedCts().run(); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
47 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
48 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
49 |
void run() throws Exception { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
50 |
checkReferences(); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
51 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
52 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
53 |
int numberOfReferencedClassesToBeChecked = 0; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
54 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
55 |
void checkClassName(String className) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
56 |
switch (className) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
57 |
case "SimpleAssignClass" : case "BinaryExpClass": |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
58 |
case "UnaryExpClass" : case "CastClass": |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
59 |
case "ParensClass" : case "CondClass": |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
60 |
case "IfClass" : case "pkg/ClassToBeStaticallyImported": |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
61 |
numberOfReferencedClassesToBeChecked++; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
62 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
63 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
64 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
65 |
void checkReferences() throws IOException, ConstantPoolException { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
66 |
File testClasses = new File(System.getProperty("test.classes")); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
67 |
File file = new File(testClasses, |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
68 |
CPoolRefClassContainingInlinedCts.class.getName() + ".class"); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
69 |
ClassFile classFile = ClassFile.read(file); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
70 |
int i = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
71 |
CPInfo cpInfo; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
72 |
while (i < classFile.constant_pool.size()) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
73 |
cpInfo = classFile.constant_pool.get(i); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
74 |
if (cpInfo instanceof CONSTANT_Class_info) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
75 |
checkClassName(((CONSTANT_Class_info)cpInfo).getName()); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
76 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
77 |
i += cpInfo.size(); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
78 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
79 |
if (numberOfReferencedClassesToBeChecked != 8) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
80 |
throw new AssertionError("Class reference missing in the constant pool"); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
81 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
82 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
83 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
84 |
private int assign = SimpleAssignClass.x; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
85 |
private int binary = BinaryExpClass.x + 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
86 |
private int unary = -UnaryExpClass.x; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
87 |
private int cast = (int)CastClass.x; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
88 |
private int parens = (ParensClass.x); |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
89 |
private int cond = (CondClass.x == 1) ? 1 : 2; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
90 |
private static int ifConstant; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
91 |
private static int importStatic; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
92 |
static { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
93 |
if (IfClass.x == 1) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
94 |
ifConstant = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
95 |
} else { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
96 |
ifConstant = 2; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
97 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
98 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
99 |
static { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
100 |
if (staticField == 1) { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
101 |
importStatic = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
102 |
} else { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
103 |
importStatic = 2; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
104 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
105 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
106 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
107 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
108 |
class SimpleAssignClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
109 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
110 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
111 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
112 |
class BinaryExpClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
113 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
114 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
115 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
116 |
class UnaryExpClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
117 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
118 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
119 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
120 |
class CastClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
121 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
122 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
123 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
124 |
class ParensClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
125 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
126 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
127 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
128 |
class CondClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
129 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
130 |
} |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
131 |
|
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
132 |
class IfClass { |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
133 |
public static final int x = 1; |
071e3587f212
7153958: add constant pool reference to class containing inlined constants
vromero
parents:
diff
changeset
|
134 |
} |