author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 21711 | 1118b43b5111 |
child 30846 | 2b3f379840f0 |
permissions | -rw-r--r-- |
14046 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
14046 | 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. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
17799 | 26 |
* @bug 7194586 8003280 8006694 8010404 |
14547 | 27 |
* @summary Add lambda tests |
28 |
* Add back-end support for invokedynamic |
|
15384
5a8d00abf076
8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents:
15040
diff
changeset
|
29 |
* temporarily workaround combo tests are causing time out in several platforms |
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
30 |
* @library ../lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
31 |
* @modules jdk.compiler/com.sun.tools.classfile |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
34 |
* jdk.compiler/com.sun.tools.javac.jvm |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
35 |
* jdk.compiler/com.sun.tools.javac.tree |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
21711
diff
changeset
|
36 |
* jdk.compiler/com.sun.tools.javac.util |
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
37 |
* @build JavacTestingAbstractThreadedTest |
15384
5a8d00abf076
8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents:
15040
diff
changeset
|
38 |
* @run main/othervm TestInvokeDynamic |
14046 | 39 |
*/ |
40 |
||
15384
5a8d00abf076
8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents:
15040
diff
changeset
|
41 |
// use /othervm to avoid jtreg timeout issues (CODETOOLS-7900047) |
5a8d00abf076
8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents:
15040
diff
changeset
|
42 |
// see JDK-8006746 |
5a8d00abf076
8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents:
15040
diff
changeset
|
43 |
|
17799 | 44 |
import java.io.File; |
45 |
import java.net.URI; |
|
46 |
import java.util.ArrayList; |
|
47 |
import java.util.Arrays; |
|
48 |
import java.util.Locale; |
|
49 |
||
50 |
import javax.tools.Diagnostic; |
|
51 |
import javax.tools.JavaFileObject; |
|
52 |
import javax.tools.SimpleJavaFileObject; |
|
53 |
||
14046 | 54 |
import com.sun.source.tree.MethodInvocationTree; |
55 |
import com.sun.source.tree.MethodTree; |
|
56 |
import com.sun.source.util.TaskEvent; |
|
57 |
import com.sun.source.util.TaskListener; |
|
58 |
import com.sun.source.util.TreeScanner; |
|
59 |
||
60 |
import com.sun.tools.classfile.Attribute; |
|
61 |
import com.sun.tools.classfile.BootstrapMethods_attribute; |
|
62 |
import com.sun.tools.classfile.ClassFile; |
|
63 |
import com.sun.tools.classfile.Code_attribute; |
|
64 |
import com.sun.tools.classfile.ConstantPool.*; |
|
65 |
import com.sun.tools.classfile.Instruction; |
|
16807
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
66 |
import com.sun.tools.classfile.LineNumberTable_attribute; |
14046 | 67 |
import com.sun.tools.classfile.Method; |
68 |
||
69 |
import com.sun.tools.javac.api.JavacTaskImpl; |
|
70 |
import com.sun.tools.javac.code.Symbol; |
|
71 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
|
72 |
import com.sun.tools.javac.code.Symtab; |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
73 |
import com.sun.tools.javac.code.Types; |
14046 | 74 |
import com.sun.tools.javac.jvm.Pool; |
75 |
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; |
|
76 |
import com.sun.tools.javac.tree.JCTree.JCMethodDecl; |
|
77 |
import com.sun.tools.javac.tree.JCTree.JCIdent; |
|
78 |
import com.sun.tools.javac.util.Context; |
|
79 |
import com.sun.tools.javac.util.Names; |
|
80 |
||
81 |
import static com.sun.tools.javac.jvm.ClassFile.*; |
|
82 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
83 |
public class TestInvokeDynamic |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
84 |
extends JavacTestingAbstractThreadedTest |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
85 |
implements Runnable { |
14046 | 86 |
|
87 |
enum StaticArgumentKind { |
|
88 |
STRING("Hello!", "String", "Ljava/lang/String;") { |
|
89 |
@Override |
|
90 |
boolean check(CPInfo cpInfo) throws Exception { |
|
91 |
return (cpInfo instanceof CONSTANT_String_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
92 |
((CONSTANT_String_info)cpInfo).getString() |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
93 |
.equals(value); |
14046 | 94 |
} |
95 |
}, |
|
96 |
CLASS(null, "Class<?>", "Ljava/lang/Class;") { |
|
97 |
@Override |
|
98 |
boolean check(CPInfo cpInfo) throws Exception { |
|
99 |
return (cpInfo instanceof CONSTANT_Class_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
100 |
((CONSTANT_Class_info)cpInfo).getName() |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
101 |
.equals("java/lang/String"); |
14046 | 102 |
} |
103 |
}, |
|
104 |
INTEGER(1, "int", "I") { |
|
105 |
@Override |
|
106 |
boolean check(CPInfo cpInfo) throws Exception { |
|
107 |
return (cpInfo instanceof CONSTANT_Integer_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
108 |
((CONSTANT_Integer_info)cpInfo).value == |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
109 |
((Integer)value).intValue(); |
14046 | 110 |
} |
111 |
}, |
|
112 |
LONG(1L, "long", "J") { |
|
113 |
@Override |
|
114 |
boolean check(CPInfo cpInfo) throws Exception { |
|
115 |
return (cpInfo instanceof CONSTANT_Long_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
116 |
((CONSTANT_Long_info)cpInfo).value == |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
117 |
((Long)value).longValue(); |
14046 | 118 |
} |
119 |
}, |
|
120 |
FLOAT(1.0f, "float", "F") { |
|
121 |
@Override |
|
122 |
boolean check(CPInfo cpInfo) throws Exception { |
|
123 |
return (cpInfo instanceof CONSTANT_Float_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
124 |
((CONSTANT_Float_info)cpInfo).value == |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
125 |
((Float)value).floatValue(); |
14046 | 126 |
} |
127 |
}, |
|
128 |
DOUBLE(1.0, "double","D") { |
|
129 |
@Override |
|
130 |
boolean check(CPInfo cpInfo) throws Exception { |
|
131 |
return (cpInfo instanceof CONSTANT_Double_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
132 |
((CONSTANT_Double_info)cpInfo).value == |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
133 |
((Double)value).doubleValue(); |
14046 | 134 |
} |
135 |
}, |
|
136 |
METHOD_HANDLE(null, "MethodHandle", "Ljava/lang/invoke/MethodHandle;") { |
|
137 |
@Override |
|
138 |
boolean check(CPInfo cpInfo) throws Exception { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
139 |
if (!(cpInfo instanceof CONSTANT_MethodHandle_info)) |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
140 |
return false; |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
141 |
CONSTANT_MethodHandle_info handleInfo = |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
142 |
(CONSTANT_MethodHandle_info)cpInfo; |
14046 | 143 |
return handleInfo.getCPRefInfo().getClassName().equals("Array") && |
144 |
handleInfo.reference_kind == RefKind.REF_invokeVirtual && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
145 |
handleInfo.getCPRefInfo() |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
146 |
.getNameAndTypeInfo().getName().equals("clone") && |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
147 |
handleInfo.getCPRefInfo() |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
148 |
.getNameAndTypeInfo().getType().equals("()Ljava/lang/Object;"); |
14046 | 149 |
} |
150 |
}, |
|
151 |
METHOD_TYPE(null, "MethodType", "Ljava/lang/invoke/MethodType;") { |
|
152 |
@Override |
|
153 |
boolean check(CPInfo cpInfo) throws Exception { |
|
154 |
return (cpInfo instanceof CONSTANT_MethodType_info) && |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
155 |
((CONSTANT_MethodType_info)cpInfo).getType() |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
156 |
.equals("()Ljava/lang/Object;"); |
14046 | 157 |
} |
158 |
}; |
|
159 |
||
160 |
Object value; |
|
161 |
String sourceTypeStr; |
|
162 |
String bytecodeTypeStr; |
|
163 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
164 |
StaticArgumentKind(Object value, String sourceTypeStr, |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
165 |
String bytecodeTypeStr) { |
14046 | 166 |
this.value = value; |
167 |
this.sourceTypeStr = sourceTypeStr; |
|
168 |
this.bytecodeTypeStr = bytecodeTypeStr; |
|
169 |
} |
|
170 |
||
171 |
abstract boolean check(CPInfo cpInfo) throws Exception; |
|
172 |
||
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
173 |
Object getValue(Symtab syms, Names names, Types types) { |
14046 | 174 |
switch (this) { |
175 |
case STRING: |
|
176 |
case INTEGER: |
|
177 |
case LONG: |
|
178 |
case FLOAT: |
|
179 |
case DOUBLE: |
|
180 |
return value; |
|
181 |
case CLASS: |
|
182 |
return syms.stringType.tsym; |
|
183 |
case METHOD_HANDLE: |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
184 |
return new Pool.MethodHandle(REF_invokeVirtual, |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
185 |
syms.arrayCloneMethod, types); |
14046 | 186 |
case METHOD_TYPE: |
187 |
return syms.arrayCloneMethod.type; |
|
188 |
default: |
|
189 |
throw new AssertionError(); |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
enum StaticArgumentsArity { |
|
195 |
ZERO(0), |
|
196 |
ONE(1), |
|
197 |
TWO(2), |
|
198 |
THREE(3); |
|
199 |
||
200 |
int arity; |
|
201 |
||
202 |
StaticArgumentsArity(int arity) { |
|
203 |
this.arity = arity; |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
public static void main(String... args) throws Exception { |
|
208 |
for (StaticArgumentsArity arity : StaticArgumentsArity.values()) { |
|
209 |
if (arity.arity == 0) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
210 |
pool.execute(new TestInvokeDynamic(arity)); |
14046 | 211 |
} else { |
212 |
for (StaticArgumentKind sak1 : StaticArgumentKind.values()) { |
|
213 |
if (arity.arity == 1) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
214 |
pool.execute(new TestInvokeDynamic(arity, sak1)); |
14046 | 215 |
} else { |
216 |
for (StaticArgumentKind sak2 : StaticArgumentKind.values()) { |
|
217 |
if (arity.arity == 2) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
218 |
pool.execute(new TestInvokeDynamic(arity, sak1, sak2)); |
14046 | 219 |
} else { |
220 |
for (StaticArgumentKind sak3 : StaticArgumentKind.values()) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
221 |
pool.execute( |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
222 |
new TestInvokeDynamic(arity, sak1, sak2, sak3)); |
14046 | 223 |
} |
224 |
} |
|
225 |
} |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
229 |
} |
|
230 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
231 |
checkAfterExec(); |
14046 | 232 |
} |
233 |
||
234 |
StaticArgumentsArity arity; |
|
235 |
StaticArgumentKind[] saks; |
|
236 |
DiagChecker dc; |
|
237 |
||
238 |
TestInvokeDynamic(StaticArgumentsArity arity, StaticArgumentKind... saks) { |
|
239 |
this.arity = arity; |
|
240 |
this.saks = saks; |
|
241 |
dc = new DiagChecker(); |
|
242 |
} |
|
243 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
244 |
public void run() { |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
245 |
int id = checkCount.incrementAndGet(); |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
246 |
JavaSource source = new JavaSource(id); |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
247 |
JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, fm.get(), dc, |
16807
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
248 |
Arrays.asList("-g"), null, Arrays.asList(source)); |
14046 | 249 |
Context context = ct.getContext(); |
250 |
Symtab syms = Symtab.instance(context); |
|
251 |
Names names = Names.instance(context); |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
252 |
Types types = Types.instance(context); |
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
253 |
ct.addTaskListener(new Indifier(syms, names, types)); |
14046 | 254 |
try { |
255 |
ct.generate(); |
|
256 |
} catch (Throwable t) { |
|
257 |
t.printStackTrace(); |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
258 |
throw new AssertionError( |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
259 |
String.format("Error thrown when compiling following code\n%s", |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
260 |
source.source)); |
14046 | 261 |
} |
262 |
if (dc.diagFound) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
263 |
throw new AssertionError( |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
264 |
String.format("Diags found when compiling following code\n%s\n\n%s", |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
265 |
source.source, dc.printDiags())); |
14046 | 266 |
} |
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
267 |
verifyBytecode(id); |
14046 | 268 |
} |
269 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
270 |
void verifyBytecode(int id) { |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
271 |
File compiledTest = new File(String.format("Test%d.class", id)); |
14046 | 272 |
try { |
273 |
ClassFile cf = ClassFile.read(compiledTest); |
|
274 |
Method testMethod = null; |
|
275 |
for (Method m : cf.methods) { |
|
276 |
if (m.getName(cf.constant_pool).equals("test")) { |
|
277 |
testMethod = m; |
|
278 |
break; |
|
279 |
} |
|
280 |
} |
|
281 |
if (testMethod == null) { |
|
282 |
throw new Error("Test method not found"); |
|
283 |
} |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
284 |
Code_attribute ea = |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
285 |
(Code_attribute)testMethod.attributes.get(Attribute.Code); |
14046 | 286 |
if (testMethod == null) { |
287 |
throw new Error("Code attribute for test() method not found"); |
|
288 |
} |
|
289 |
||
290 |
int bsmIdx = -1; |
|
291 |
||
292 |
for (Instruction i : ea.getInstructions()) { |
|
293 |
if (i.getMnemonic().equals("invokedynamic")) { |
|
294 |
CONSTANT_InvokeDynamic_info indyInfo = |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
295 |
(CONSTANT_InvokeDynamic_info)cf |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
296 |
.constant_pool.get(i.getShort(1)); |
14046 | 297 |
bsmIdx = indyInfo.bootstrap_method_attr_index; |
298 |
if (!indyInfo.getNameAndTypeInfo().getType().equals("()V")) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
299 |
throw new |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
300 |
AssertionError("type mismatch for CONSTANT_InvokeDynamic_info"); |
14046 | 301 |
} |
302 |
} |
|
303 |
} |
|
304 |
if (bsmIdx == -1) { |
|
305 |
throw new Error("Missing invokedynamic in generated code"); |
|
306 |
} |
|
307 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
308 |
BootstrapMethods_attribute bsm_attr = |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
309 |
(BootstrapMethods_attribute)cf |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
310 |
.getAttribute(Attribute.BootstrapMethods); |
14046 | 311 |
if (bsm_attr.bootstrap_method_specifiers.length != 1) { |
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
312 |
throw new Error("Bad number of method specifiers " + |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
313 |
"in BootstrapMethods attribute"); |
14046 | 314 |
} |
315 |
BootstrapMethods_attribute.BootstrapMethodSpecifier bsm_spec = |
|
316 |
bsm_attr.bootstrap_method_specifiers[0]; |
|
317 |
||
318 |
if (bsm_spec.bootstrap_arguments.length != arity.arity) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
319 |
throw new Error("Bad number of static invokedynamic args " + |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
320 |
"in BootstrapMethod attribute"); |
14046 | 321 |
} |
322 |
||
323 |
int count = 0; |
|
324 |
for (StaticArgumentKind sak : saks) { |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
325 |
if (!sak.check(cf.constant_pool |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
326 |
.get(bsm_spec.bootstrap_arguments[count]))) { |
14046 | 327 |
throw new Error("Bad static argument value " + sak); |
328 |
} |
|
329 |
count++; |
|
330 |
} |
|
331 |
||
332 |
CONSTANT_MethodHandle_info bsm_handle = |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
333 |
(CONSTANT_MethodHandle_info)cf.constant_pool |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
334 |
.get(bsm_spec.bootstrap_method_ref); |
14046 | 335 |
|
336 |
if (bsm_handle.reference_kind != RefKind.REF_invokeStatic) { |
|
337 |
throw new Error("Bad kind on boostrap method handle"); |
|
338 |
} |
|
339 |
||
340 |
CONSTANT_Methodref_info bsm_ref = |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
341 |
(CONSTANT_Methodref_info)cf.constant_pool |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
342 |
.get(bsm_handle.reference_index); |
14046 | 343 |
|
344 |
if (!bsm_ref.getClassInfo().getName().equals("Bootstrap")) { |
|
345 |
throw new Error("Bad owner of boostrap method"); |
|
346 |
} |
|
347 |
||
348 |
if (!bsm_ref.getNameAndTypeInfo().getName().equals("bsm")) { |
|
349 |
throw new Error("Bad boostrap method name"); |
|
350 |
} |
|
351 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
352 |
if (!bsm_ref.getNameAndTypeInfo() |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
353 |
.getType().equals(asBSMSignatureString())) { |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
354 |
throw new Error("Bad boostrap method type" + |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
355 |
bsm_ref.getNameAndTypeInfo().getType() + " " + |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
356 |
asBSMSignatureString()); |
14046 | 357 |
} |
16807
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
358 |
|
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
359 |
LineNumberTable_attribute lnt = |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
360 |
(LineNumberTable_attribute)ea.attributes.get(Attribute.LineNumberTable); |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
361 |
|
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
362 |
if (lnt == null) { |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
363 |
throw new Error("No LineNumberTable attribute"); |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
364 |
} |
21711
1118b43b5111
8027142: Invokedynamic instructions don't get line number table entries
jlahoda
parents:
17799
diff
changeset
|
365 |
if (lnt.line_number_table_length != 3) { |
16807
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
366 |
throw new Error("Wrong number of entries in LineNumberTable"); |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
367 |
} |
14046 | 368 |
} catch (Exception e) { |
369 |
e.printStackTrace(); |
|
370 |
throw new Error("error reading " + compiledTest +": " + e); |
|
371 |
} |
|
372 |
} |
|
373 |
||
374 |
String asBSMSignatureString() { |
|
375 |
StringBuilder buf = new StringBuilder(); |
|
376 |
buf.append("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;"); |
|
377 |
for (StaticArgumentKind sak : saks) { |
|
378 |
buf.append(sak.bytecodeTypeStr); |
|
379 |
} |
|
380 |
buf.append(")Ljava/lang/invoke/CallSite;"); |
|
381 |
return buf.toString(); |
|
382 |
} |
|
383 |
||
384 |
class JavaSource extends SimpleJavaFileObject { |
|
385 |
||
386 |
static final String source_template = "import java.lang.invoke.*;\n" + |
|
387 |
"class Bootstrap {\n" + |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
388 |
" public static CallSite bsm(MethodHandles.Lookup lookup, " + |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
389 |
"String name, MethodType methodType #SARGS) {\n" + |
14046 | 390 |
" return null;\n" + |
391 |
" }\n" + |
|
392 |
"}\n" + |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
393 |
"class Test#ID {\n" + |
14046 | 394 |
" void m() { }\n" + |
16807
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
395 |
" void test() {\n" + |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
396 |
" Object o = this; // marker statement \n" + |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
397 |
" m();\n" + |
b442b47d3ae9
8010404: Lambda debugging: redundant LineNumberTable entry for lambda capture
mcimadamore
parents:
15384
diff
changeset
|
398 |
" }\n" + |
14046 | 399 |
"}"; |
400 |
||
401 |
String source; |
|
402 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
403 |
JavaSource(int id) { |
14046 | 404 |
super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); |
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
405 |
source = source_template.replace("#SARGS", asSignatureString()) |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
406 |
.replace("#ID", String.valueOf(id)); |
14046 | 407 |
} |
408 |
||
409 |
@Override |
|
410 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
|
411 |
return source; |
|
412 |
} |
|
413 |
||
414 |
String asSignatureString() { |
|
415 |
int count = 0; |
|
416 |
StringBuilder buf = new StringBuilder(); |
|
417 |
for (StaticArgumentKind sak : saks) { |
|
418 |
buf.append(","); |
|
419 |
buf.append(sak.sourceTypeStr); |
|
420 |
buf.append(' '); |
|
421 |
buf.append(String.format("x%d", count++)); |
|
422 |
} |
|
423 |
return buf.toString(); |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
class Indifier extends TreeScanner<Void, Void> implements TaskListener { |
|
428 |
||
429 |
MethodSymbol bsm; |
|
430 |
Symtab syms; |
|
431 |
Names names; |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
432 |
Types types; |
14046 | 433 |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
434 |
Indifier(Symtab syms, Names names, Types types) { |
14046 | 435 |
this.syms = syms; |
436 |
this.names = names; |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
437 |
this.types = types; |
14046 | 438 |
} |
439 |
||
440 |
@Override |
|
441 |
public void started(TaskEvent e) { |
|
442 |
//do nothing |
|
443 |
} |
|
444 |
||
445 |
@Override |
|
446 |
public void finished(TaskEvent e) { |
|
447 |
if (e.getKind() == TaskEvent.Kind.ANALYZE) { |
|
448 |
scan(e.getCompilationUnit(), null); |
|
449 |
} |
|
450 |
} |
|
451 |
||
452 |
@Override |
|
453 |
public Void visitMethodInvocation(MethodInvocationTree node, Void p) { |
|
454 |
super.visitMethodInvocation(node, p); |
|
455 |
JCMethodInvocation apply = (JCMethodInvocation)node; |
|
456 |
JCIdent ident = (JCIdent)apply.meth; |
|
457 |
Symbol oldSym = ident.sym; |
|
458 |
if (!oldSym.isConstructor()) { |
|
459 |
Object[] staticArgs = new Object[arity.arity]; |
|
460 |
for (int i = 0; i < arity.arity ; i++) { |
|
14949
45f43822bbde
8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents:
14547
diff
changeset
|
461 |
staticArgs[i] = saks[i].getValue(syms, names, types); |
14046 | 462 |
} |
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
463 |
ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
464 |
oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs); |
14046 | 465 |
} |
466 |
return null; |
|
467 |
} |
|
468 |
||
469 |
@Override |
|
470 |
public Void visitMethod(MethodTree node, Void p) { |
|
471 |
super.visitMethod(node, p); |
|
472 |
if (node.getName().toString().equals("bsm")) { |
|
473 |
bsm = ((JCMethodDecl)node).sym; |
|
474 |
} |
|
475 |
return null; |
|
476 |
} |
|
477 |
} |
|
478 |
||
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
479 |
static class DiagChecker |
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
480 |
implements javax.tools.DiagnosticListener<JavaFileObject> { |
14046 | 481 |
|
482 |
boolean diagFound; |
|
483 |
ArrayList<String> diags = new ArrayList<>(); |
|
484 |
||
485 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
|
486 |
diags.add(diagnostic.getMessage(Locale.getDefault())); |
|
487 |
diagFound = true; |
|
488 |
} |
|
489 |
||
490 |
String printDiags() { |
|
491 |
StringBuilder buf = new StringBuilder(); |
|
492 |
for (String s : diags) { |
|
493 |
buf.append(s); |
|
494 |
buf.append("\n"); |
|
495 |
} |
|
496 |
return buf.toString(); |
|
497 |
} |
|
498 |
} |
|
15040
99fd9483d3f0
8005167: execution time of combo tests in javac should be improved
vromero
parents:
14949
diff
changeset
|
499 |
|
14046 | 500 |
} |