author | vromero |
Tue, 03 Apr 2018 23:58:52 -0400 | |
changeset 49518 | d0ff431a596e |
parent 47350 | d65c3b21081c |
permissions | -rw-r--r-- |
18386 | 1 |
/* |
49518
d0ff431a596e
8198314: javac hidden options violate standard syntax for options
vromero
parents:
47350
diff
changeset
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
18386 | 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 |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
26 |
* @bug 8013576 8129962 |
18386 | 27 |
* @summary Add stat support to LambdaToMethod |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
28 |
* @library /tools/javac/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
18386
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.code |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.comp |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.javac.tree |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
18386
diff
changeset
|
34 |
* jdk.compiler/com.sun.tools.javac.util |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
35 |
* @build combo.ComboTestHelper |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
36 |
* @run main TestLambdaToMethodStats |
18386 | 37 |
*/ |
38 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
39 |
import java.io.IOException; |
18386 | 40 |
|
41 |
import javax.tools.Diagnostic; |
|
42 |
import javax.tools.JavaFileObject; |
|
43 |
||
44 |
import com.sun.tools.javac.api.ClientCodeWrapper; |
|
45 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
46 |
import com.sun.tools.javac.util.List; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
47 |
import combo.ComboInstance; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
48 |
import combo.ComboParameter; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
49 |
import combo.ComboTask.Result; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
50 |
import combo.ComboTestHelper; |
18386 | 51 |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
52 |
public class TestLambdaToMethodStats extends ComboInstance<TestLambdaToMethodStats> { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
53 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
54 |
enum ExprKind implements ComboParameter { |
18386 | 55 |
LAMBDA("()->null"), |
56 |
MREF1("this::g"), |
|
57 |
MREF2("this::h"); |
|
58 |
||
59 |
String exprStr; |
|
60 |
||
61 |
ExprKind(String exprStr) { |
|
62 |
this.exprStr = exprStr; |
|
63 |
} |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
64 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
65 |
@Override |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
66 |
public String expand(String optParameter) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
67 |
return exprStr; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
68 |
} |
18386 | 69 |
} |
70 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
71 |
enum TargetKind implements ComboParameter { |
18386 | 72 |
IMPLICIT(""), |
73 |
SERIALIZABLE("(A & java.io.Serializable)"); |
|
74 |
||
75 |
String targetStr; |
|
76 |
||
77 |
TargetKind(String targetStr) { |
|
78 |
this.targetStr = targetStr; |
|
79 |
} |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
80 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
81 |
@Override |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
82 |
public String expand(String optParameter) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
83 |
return targetStr; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
84 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
85 |
} |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
86 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
87 |
enum DiagnosticKind { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
88 |
LAMBDA_STAT("compiler.note.lambda.stat", true, false), |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
89 |
MREF_STAT("compiler.note.mref.stat", false, false), |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
90 |
MREF_STAT1("compiler.note.mref.stat.1", false, true); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
91 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
92 |
String code; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
93 |
boolean lambda; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
94 |
boolean bridge; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
95 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
96 |
DiagnosticKind(String code, boolean lambda, boolean bridge) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
97 |
this.code = code; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
98 |
this.lambda = lambda; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
99 |
this.bridge = bridge; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
100 |
} |
18386 | 101 |
} |
102 |
||
103 |
public static void main(String... args) throws Exception { |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
104 |
new ComboTestHelper<TestLambdaToMethodStats>() |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
105 |
.withDimension("EXPR", (x, expr) -> x.ek = expr, ExprKind.values()) |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
106 |
.withDimension("CAST", (x, target) -> x.tk = target, TargetKind.values()) |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
107 |
.run(TestLambdaToMethodStats::new); |
18386 | 108 |
} |
109 |
||
110 |
ExprKind ek; |
|
111 |
TargetKind tk; |
|
112 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
113 |
String template = "interface A {\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
114 |
" Object o();\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
115 |
"}\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
116 |
"class Test {\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
117 |
" A a = #{CAST}#{EXPR};\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
118 |
" Object g() { return null; }\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
119 |
" Object h(Object... o) { return null; }\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
120 |
"}"; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
121 |
|
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
122 |
@Override |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
123 |
public void doWork() throws IOException { |
47350
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47216
diff
changeset
|
124 |
newCompilationTask() |
49518
d0ff431a596e
8198314: javac hidden options violate standard syntax for options
vromero
parents:
47350
diff
changeset
|
125 |
.withOption("--debug=dumpLambdaToMethodStats") |
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
126 |
.withSourceFromTemplate(template) |
47350
d65c3b21081c
8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents:
47216
diff
changeset
|
127 |
.generate(this::check); |
18386 | 128 |
} |
129 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
130 |
void check(Result<?> res) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
131 |
DiagnosticKind diag = null; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
132 |
boolean altMetafactory = false; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
133 |
for (DiagnosticKind dk : DiagnosticKind.values()) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
134 |
List<Diagnostic<? extends JavaFileObject>> jcDiag = res.diagnosticsForKey(dk.code); |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
135 |
if (jcDiag.nonEmpty()) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
136 |
diag = dk; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
137 |
ClientCodeWrapper.DiagnosticSourceUnwrapper dsu = |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
138 |
(ClientCodeWrapper.DiagnosticSourceUnwrapper)jcDiag.head; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
139 |
altMetafactory = (Boolean)dsu.d.getArgs()[0]; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
140 |
break; |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
141 |
} |
18386 | 142 |
} |
143 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
144 |
if (diag == null) { |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
145 |
fail("No diagnostic found; " + res.compilationInfo()); |
18386 | 146 |
} |
147 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
148 |
boolean error = diag.lambda != |
18386 | 149 |
(ek == ExprKind.LAMBDA); |
150 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
151 |
error |= diag.bridge != |
18386 | 152 |
(ek == ExprKind.MREF2); |
153 |
||
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
154 |
error |= altMetafactory != |
18386 | 155 |
(tk == TargetKind.SERIALIZABLE); |
156 |
||
157 |
if (error) { |
|
32454
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
158 |
fail("Bad stat diagnostic found for source\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
159 |
"lambda = " + diag.lambda + "\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
160 |
"bridge = " + diag.bridge + "\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
161 |
"altMF = " + altMetafactory + "\n" + |
b0ac04e0fefe
8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents:
30730
diff
changeset
|
162 |
res.compilationInfo()); |
18386 | 163 |
} |
164 |
} |
|
165 |
} |