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