43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.core.test.inlining;
|
|
26 |
|
52910
|
27 |
import java.util.regex.Pattern;
|
|
28 |
|
49873
|
29 |
import org.graalvm.compiler.core.common.GraalOptions;
|
43972
|
30 |
import org.graalvm.compiler.core.test.GraalCompilerTest;
|
46640
|
31 |
import org.graalvm.compiler.debug.DebugContext;
|
43972
|
32 |
import org.graalvm.compiler.debug.DebugDumpScope;
|
49873
|
33 |
import org.graalvm.compiler.debug.TTY;
|
43972
|
34 |
import org.graalvm.compiler.graph.Node;
|
|
35 |
import org.graalvm.compiler.nodes.FullInfopointNode;
|
|
36 |
import org.graalvm.compiler.nodes.Invoke;
|
|
37 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
38 |
import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
|
46640
|
39 |
import org.graalvm.compiler.nodes.StructuredGraph.Builder;
|
43972
|
40 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
49873
|
41 |
import org.graalvm.compiler.options.OptionValues;
|
43972
|
42 |
import org.graalvm.compiler.phases.OptimisticOptimizations;
|
|
43 |
import org.graalvm.compiler.phases.PhaseSuite;
|
|
44 |
import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
|
|
45 |
import org.graalvm.compiler.phases.tiers.HighTierContext;
|
49873
|
46 |
import org.junit.Assert;
|
46640
|
47 |
import org.junit.Ignore;
|
|
48 |
import org.junit.Test;
|
|
49 |
|
|
50 |
import jdk.vm.ci.code.site.InfopointReason;
|
|
51 |
import jdk.vm.ci.meta.ResolvedJavaMethod;
|
43972
|
52 |
|
|
53 |
public class InliningTest extends GraalCompilerTest {
|
|
54 |
|
|
55 |
@Test
|
|
56 |
public void testInvokeStaticInlining() {
|
|
57 |
assertInlined(getGraph("invokeStaticSnippet", false));
|
|
58 |
assertInlined(getGraph("invokeStaticOnInstanceSnippet", false));
|
|
59 |
}
|
|
60 |
|
|
61 |
@SuppressWarnings("all")
|
|
62 |
public static Boolean invokeStaticSnippet(boolean value) {
|
|
63 |
return Boolean.valueOf(value);
|
|
64 |
}
|
|
65 |
|
|
66 |
@SuppressWarnings({"all", "static"})
|
|
67 |
public static Boolean invokeStaticOnInstanceSnippet(Boolean obj, boolean value) {
|
|
68 |
return obj.valueOf(value);
|
|
69 |
}
|
|
70 |
|
|
71 |
@Test
|
|
72 |
public void testStaticBindableInlining() {
|
|
73 |
assertInlined(getGraph("invokeConstructorSnippet", false));
|
|
74 |
assertInlined(getGraph("invokeFinalMethodSnippet", false));
|
|
75 |
assertInlined(getGraph("invokeMethodOnFinalClassSnippet", false));
|
|
76 |
assertInlined(getGraph("invokeMethodOnStaticFinalFieldSnippet", false));
|
|
77 |
}
|
|
78 |
|
|
79 |
@Ignore("would need read elimination/EA before inlining")
|
|
80 |
@Test
|
|
81 |
public void testDependentStaticBindableInlining() {
|
|
82 |
assertInlined(getGraph("invokeMethodOnFinalFieldSnippet", false));
|
|
83 |
assertInlined(getGraph("invokeMethodOnFieldSnippet", false));
|
|
84 |
}
|
|
85 |
|
|
86 |
@Test
|
|
87 |
public void testStaticBindableInliningIP() {
|
|
88 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeConstructorSnippet", true)));
|
|
89 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeFinalMethodSnippet", true)));
|
|
90 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeMethodOnFinalClassSnippet", true)));
|
|
91 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeMethodOnStaticFinalFieldSnippet", true)));
|
|
92 |
}
|
|
93 |
|
|
94 |
@Ignore("would need read elimination/EA before inlining")
|
|
95 |
@Test
|
|
96 |
public void testDependentStaticBindableInliningIP() {
|
|
97 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeMethodOnFinalFieldSnippet", true)));
|
|
98 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeMethodOnFieldSnippet", true)));
|
|
99 |
}
|
|
100 |
|
|
101 |
@SuppressWarnings("all")
|
|
102 |
public static Object invokeConstructorSnippet(int value) {
|
|
103 |
return new SuperClass(value);
|
|
104 |
}
|
|
105 |
|
|
106 |
@SuppressWarnings("all")
|
|
107 |
public static int invokeFinalMethodSnippet(SuperClass superClass, SubClassA subClassA, FinalSubClass finalSubClass) {
|
|
108 |
return superClass.publicFinalMethod() + subClassA.publicFinalMethod() + finalSubClass.publicFinalMethod() + superClass.protectedFinalMethod() + subClassA.protectedFinalMethod() +
|
|
109 |
finalSubClass.protectedFinalMethod();
|
|
110 |
}
|
|
111 |
|
|
112 |
@SuppressWarnings("all")
|
|
113 |
public static int invokeMethodOnFinalClassSnippet(FinalSubClass finalSubClass) {
|
|
114 |
return finalSubClass.publicFinalMethod() + finalSubClass.publicNotOverriddenMethod() + finalSubClass.publicOverriddenMethod() + finalSubClass.protectedFinalMethod() +
|
|
115 |
finalSubClass.protectedNotOverriddenMethod() + finalSubClass.protectedOverriddenMethod();
|
|
116 |
}
|
|
117 |
|
|
118 |
@SuppressWarnings("all")
|
|
119 |
public static int invokeMethodOnStaticFinalFieldSnippet() {
|
|
120 |
return StaticFinalFields.NumberStaticFinalField.intValue() + StaticFinalFields.SuperClassStaticFinalField.publicOverriddenMethod() +
|
|
121 |
StaticFinalFields.FinalSubClassStaticFinalField.publicOverriddenMethod() + StaticFinalFields.SingleImplementorStaticFinalField.publicOverriddenMethod() +
|
|
122 |
StaticFinalFields.MultipleImplementorsStaticFinalField.publicOverriddenMethod() + StaticFinalFields.SubClassAStaticFinalField.publicOverriddenMethod() +
|
|
123 |
StaticFinalFields.SubClassBStaticFinalField.publicOverriddenMethod() + StaticFinalFields.SubClassCStaticFinalField.publicOverriddenMethod();
|
|
124 |
}
|
|
125 |
|
|
126 |
@SuppressWarnings("all")
|
|
127 |
public static int invokeMethodOnFinalFieldSnippet() {
|
|
128 |
FinalFields fields = new FinalFields();
|
|
129 |
return fields.numberFinalField.intValue() + fields.superClassFinalField.publicOverriddenMethod() + fields.finalSubClassFinalField.publicOverriddenMethod() +
|
|
130 |
fields.singleImplementorFinalField.publicOverriddenMethod() + fields.multipleImplementorsFinalField.publicOverriddenMethod() +
|
|
131 |
fields.subClassAFinalField.publicOverriddenMethod() + fields.subClassBFinalField.publicOverriddenMethod() + fields.subClassCFinalField.publicOverriddenMethod();
|
|
132 |
}
|
|
133 |
|
|
134 |
@SuppressWarnings("all")
|
|
135 |
public static int invokeMethodOnFieldSnippet() {
|
|
136 |
Fields fields = new Fields();
|
|
137 |
return fields.numberField.intValue() + fields.superClassField.publicOverriddenMethod() + fields.finalSubClassField.publicOverriddenMethod() +
|
|
138 |
fields.singleImplementorField.publicOverriddenMethod() + fields.multipleImplementorsField.publicOverriddenMethod() + fields.subClassAField.publicOverriddenMethod() +
|
|
139 |
fields.subClassBField.publicOverriddenMethod() + fields.subClassCField.publicOverriddenMethod();
|
|
140 |
}
|
|
141 |
|
|
142 |
public interface Attributes {
|
|
143 |
|
|
144 |
int getLength();
|
|
145 |
}
|
|
146 |
|
|
147 |
public class NullAttributes implements Attributes {
|
|
148 |
|
|
149 |
@Override
|
|
150 |
public int getLength() {
|
|
151 |
return 0;
|
|
152 |
}
|
|
153 |
|
|
154 |
}
|
|
155 |
|
|
156 |
public class TenAttributes implements Attributes {
|
|
157 |
|
|
158 |
@Override
|
|
159 |
public int getLength() {
|
|
160 |
return 10;
|
|
161 |
}
|
|
162 |
|
|
163 |
}
|
|
164 |
|
|
165 |
public int getAttributesLength(Attributes a) {
|
|
166 |
return a.getLength();
|
|
167 |
}
|
|
168 |
|
|
169 |
@Test
|
|
170 |
public void testGuardedInline() {
|
|
171 |
NullAttributes nullAttributes = new NullAttributes();
|
|
172 |
for (int i = 0; i < 10000; i++) {
|
|
173 |
getAttributesLength(nullAttributes);
|
|
174 |
}
|
|
175 |
getAttributesLength(new TenAttributes());
|
|
176 |
|
|
177 |
test("getAttributesLength", nullAttributes);
|
|
178 |
test("getAttributesLength", (Object) null);
|
|
179 |
}
|
|
180 |
|
|
181 |
@Test
|
|
182 |
public void testClassHierarchyAnalysis() {
|
|
183 |
assertInlined(getGraph("invokeLeafClassMethodSnippet", false));
|
|
184 |
assertInlined(getGraph("invokeConcreteMethodSnippet", false));
|
|
185 |
assertInlined(getGraph("invokeSingleImplementorInterfaceSnippet", false));
|
|
186 |
// assertInlined(getGraph("invokeConcreteInterfaceMethodSnippet", false));
|
|
187 |
|
|
188 |
assertNotInlined(getGraph("invokeOverriddenPublicMethodSnippet", false));
|
|
189 |
assertNotInlined(getGraph("invokeOverriddenProtectedMethodSnippet", false));
|
|
190 |
assertNotInlined(getGraph("invokeOverriddenInterfaceMethodSnippet", false));
|
|
191 |
}
|
|
192 |
|
|
193 |
@Test
|
|
194 |
public void testClassHierarchyAnalysisIP() {
|
|
195 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeLeafClassMethodSnippet", true)));
|
|
196 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeConcreteMethodSnippet", true)));
|
|
197 |
assertManyMethodInfopoints(assertInlined(getGraph("invokeSingleImplementorInterfaceSnippet", true)));
|
|
198 |
//@formatter:off
|
|
199 |
// assertInlineInfopoints(assertInlined(getGraph("invokeConcreteInterfaceMethodSnippet", true)));
|
|
200 |
//@formatter:on
|
|
201 |
|
|
202 |
assertFewMethodInfopoints(assertNotInlined(getGraph("invokeOverriddenPublicMethodSnippet", true)));
|
|
203 |
assertFewMethodInfopoints(assertNotInlined(getGraph("invokeOverriddenProtectedMethodSnippet", true)));
|
|
204 |
assertFewMethodInfopoints(assertNotInlined(getGraph("invokeOverriddenInterfaceMethodSnippet", true)));
|
|
205 |
}
|
|
206 |
|
49873
|
207 |
public static void traceInliningTest() {
|
|
208 |
callTrivial();
|
|
209 |
}
|
|
210 |
|
|
211 |
private static void callTrivial() {
|
|
212 |
callNonTrivial();
|
|
213 |
}
|
|
214 |
|
|
215 |
private static double callNonTrivial() {
|
|
216 |
double x = 0.0;
|
|
217 |
for (int i = 0; i < 10; i++) {
|
|
218 |
x += i * 1.21;
|
|
219 |
}
|
|
220 |
return x;
|
|
221 |
}
|
|
222 |
|
|
223 |
@Test
|
|
224 |
@SuppressWarnings("try")
|
|
225 |
public void testTracing() {
|
|
226 |
OptionValues options = new OptionValues(getInitialOptions(), GraalOptions.TraceInlining, true);
|
|
227 |
StructuredGraph graph;
|
|
228 |
try (TTY.Filter f = new TTY.Filter()) {
|
|
229 |
graph = getGraph("traceInliningTest", options, false);
|
|
230 |
}
|
|
231 |
String inliningTree = graph.getInliningLog().formatAsTree(false);
|
|
232 |
String expectedRegex = "compilation of org.graalvm.compiler.core.test.inlining.InliningTest.traceInliningTest.*: \\R" +
|
|
233 |
" at .*org.graalvm.compiler.core.test.inlining.InliningTest.traceInliningTest.*: <GraphBuilderPhase> org.graalvm.compiler.core.test.inlining.InliningTest.callTrivial.*: yes, inline method\\R" +
|
|
234 |
" at .*org.graalvm.compiler.core.test.inlining.InliningTest.callTrivial.*: .*\\R" +
|
|
235 |
" .*<GraphBuilderPhase> org.graalvm.compiler.core.test.inlining.InliningTest.callNonTrivial.*: .*(.*\\R)*" +
|
|
236 |
" .*<InliningPhase> org.graalvm.compiler.core.test.inlining.InliningTest.callNonTrivial.*: .*(.*\\R)*";
|
|
237 |
Pattern expectedPattern = Pattern.compile(expectedRegex, Pattern.MULTILINE);
|
|
238 |
Assert.assertTrue("Got: " + inliningTree, expectedPattern.matcher(inliningTree).matches());
|
|
239 |
}
|
|
240 |
|
43972
|
241 |
@SuppressWarnings("all")
|
|
242 |
public static int invokeLeafClassMethodSnippet(SubClassA subClassA) {
|
|
243 |
return subClassA.publicFinalMethod() + subClassA.publicNotOverriddenMethod() + subClassA.publicOverriddenMethod();
|
|
244 |
}
|
|
245 |
|
|
246 |
@SuppressWarnings("all")
|
|
247 |
public static int invokeConcreteMethodSnippet(SuperClass superClass) {
|
|
248 |
return superClass.publicNotOverriddenMethod() + superClass.protectedNotOverriddenMethod();
|
|
249 |
}
|
|
250 |
|
|
251 |
@SuppressWarnings("all")
|
|
252 |
public static int invokeSingleImplementorInterfaceSnippet(SingleImplementorInterface testInterface) {
|
|
253 |
return testInterface.publicNotOverriddenMethod() + testInterface.publicOverriddenMethod();
|
|
254 |
}
|
|
255 |
|
|
256 |
@SuppressWarnings("all")
|
|
257 |
public static int invokeConcreteInterfaceMethodSnippet(MultipleImplementorsInterface testInterface) {
|
|
258 |
return testInterface.publicNotOverriddenMethod();
|
|
259 |
}
|
|
260 |
|
|
261 |
@SuppressWarnings("all")
|
|
262 |
public static int invokeOverriddenInterfaceMethodSnippet(MultipleImplementorsInterface testInterface) {
|
|
263 |
return testInterface.publicOverriddenMethod();
|
|
264 |
}
|
|
265 |
|
|
266 |
@SuppressWarnings("all")
|
|
267 |
public static int invokeOverriddenPublicMethodSnippet(SuperClass superClass) {
|
|
268 |
return superClass.publicOverriddenMethod();
|
|
269 |
}
|
|
270 |
|
|
271 |
@SuppressWarnings("all")
|
|
272 |
public static int invokeOverriddenProtectedMethodSnippet(SuperClass superClass) {
|
|
273 |
return superClass.protectedOverriddenMethod();
|
|
274 |
}
|
|
275 |
|
49873
|
276 |
private StructuredGraph getGraph(final String snippet, final boolean eagerInfopointMode) {
|
|
277 |
return getGraph(snippet, null, eagerInfopointMode);
|
|
278 |
}
|
|
279 |
|
43972
|
280 |
@SuppressWarnings("try")
|
49873
|
281 |
private StructuredGraph getGraph(final String snippet, OptionValues options, final boolean eagerInfopointMode) {
|
|
282 |
DebugContext debug = options == null ? getDebugContext() : getDebugContext(options, null, null);
|
46640
|
283 |
try (DebugContext.Scope s = debug.scope("InliningTest", new DebugDumpScope(snippet, true))) {
|
43972
|
284 |
ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
|
46640
|
285 |
Builder builder = builder(method, AllowAssumptions.YES, debug);
|
|
286 |
StructuredGraph graph = eagerInfopointMode ? parse(builder, getDebugGraphBuilderSuite()) : parse(builder, getEagerGraphBuilderSuite());
|
|
287 |
try (DebugContext.Scope s2 = debug.scope("Inlining", graph)) {
|
43972
|
288 |
PhaseSuite<HighTierContext> graphBuilderSuite = eagerInfopointMode
|
|
289 |
? getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true))
|
|
290 |
: getDefaultGraphBuilderSuite();
|
|
291 |
HighTierContext context = new HighTierContext(getProviders(), graphBuilderSuite, OptimisticOptimizations.ALL);
|
46640
|
292 |
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
58877
|
293 |
createCanonicalizerPhase().apply(graph, context);
|
52910
|
294 |
createInliningPhase().apply(graph, context);
|
46640
|
295 |
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
|
58877
|
296 |
createCanonicalizerPhase().apply(graph, context);
|
43972
|
297 |
new DeadCodeEliminationPhase().apply(graph);
|
|
298 |
return graph;
|
|
299 |
}
|
|
300 |
} catch (Throwable e) {
|
46640
|
301 |
throw debug.handle(e);
|
43972
|
302 |
}
|
|
303 |
}
|
|
304 |
|
|
305 |
private static StructuredGraph assertInlined(StructuredGraph graph) {
|
|
306 |
return assertNotInGraph(graph, Invoke.class);
|
|
307 |
}
|
|
308 |
|
|
309 |
private static StructuredGraph assertNotInlined(StructuredGraph graph) {
|
|
310 |
return assertInGraph(graph, Invoke.class);
|
|
311 |
}
|
|
312 |
|
|
313 |
private static StructuredGraph assertNotInGraph(StructuredGraph graph, Class<?> clazz) {
|
|
314 |
for (Node node : graph.getNodes()) {
|
|
315 |
if (clazz.isInstance(node)) {
|
|
316 |
fail(node.toString());
|
|
317 |
}
|
|
318 |
}
|
|
319 |
return graph;
|
|
320 |
}
|
|
321 |
|
|
322 |
private static StructuredGraph assertInGraph(StructuredGraph graph, Class<?> clazz) {
|
|
323 |
for (Node node : graph.getNodes()) {
|
|
324 |
if (clazz.isInstance(node)) {
|
|
325 |
return graph;
|
|
326 |
}
|
|
327 |
}
|
|
328 |
fail("Graph does not contain a node of class " + clazz.getName());
|
|
329 |
return graph;
|
|
330 |
}
|
|
331 |
|
|
332 |
private static int[] countMethodInfopoints(StructuredGraph graph) {
|
|
333 |
int start = 0;
|
|
334 |
int end = 0;
|
|
335 |
for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
|
|
336 |
if (ipn.getReason() == InfopointReason.METHOD_START) {
|
|
337 |
++start;
|
|
338 |
} else if (ipn.getReason() == InfopointReason.METHOD_END) {
|
|
339 |
++end;
|
|
340 |
}
|
|
341 |
}
|
|
342 |
return new int[]{start, end};
|
|
343 |
}
|
|
344 |
|
|
345 |
private static StructuredGraph assertManyMethodInfopoints(StructuredGraph graph) {
|
|
346 |
int[] counts = countMethodInfopoints(graph);
|
|
347 |
if (counts[0] <= 1 || counts[1] <= 1) {
|
|
348 |
fail(String.format("Graph contains too few required method boundary infopoints: %d starts, %d ends.", counts[0], counts[1]));
|
|
349 |
}
|
|
350 |
return graph;
|
|
351 |
}
|
|
352 |
|
|
353 |
private static StructuredGraph assertFewMethodInfopoints(StructuredGraph graph) {
|
|
354 |
int[] counts = countMethodInfopoints(graph);
|
|
355 |
if (counts[0] > 1 || counts[1] > 1) {
|
|
356 |
fail(String.format("Graph contains too many method boundary infopoints: %d starts, %d ends.", counts[0], counts[1]));
|
|
357 |
}
|
|
358 |
return graph;
|
|
359 |
}
|
|
360 |
|
|
361 |
// some interfaces and classes for testing
|
|
362 |
private interface MultipleImplementorsInterface {
|
|
363 |
|
|
364 |
int publicNotOverriddenMethod();
|
|
365 |
|
|
366 |
int publicOverriddenMethod();
|
|
367 |
}
|
|
368 |
|
|
369 |
private interface SingleImplementorInterface {
|
|
370 |
|
|
371 |
int publicNotOverriddenMethod();
|
|
372 |
|
|
373 |
int publicOverriddenMethod();
|
|
374 |
}
|
|
375 |
|
|
376 |
private static class SuperClass implements MultipleImplementorsInterface {
|
|
377 |
|
|
378 |
protected int value;
|
|
379 |
|
|
380 |
SuperClass(int value) {
|
|
381 |
this.value = value;
|
|
382 |
}
|
|
383 |
|
|
384 |
@Override
|
|
385 |
public int publicNotOverriddenMethod() {
|
|
386 |
return value;
|
|
387 |
}
|
|
388 |
|
|
389 |
@Override
|
|
390 |
public int publicOverriddenMethod() {
|
|
391 |
return value;
|
|
392 |
}
|
|
393 |
|
|
394 |
protected int protectedNotOverriddenMethod() {
|
|
395 |
return value;
|
|
396 |
}
|
|
397 |
|
|
398 |
protected int protectedOverriddenMethod() {
|
|
399 |
return value;
|
|
400 |
}
|
|
401 |
|
|
402 |
public final int publicFinalMethod() {
|
|
403 |
return value + 255;
|
|
404 |
}
|
|
405 |
|
|
406 |
protected final int protectedFinalMethod() {
|
|
407 |
return value + 255;
|
|
408 |
}
|
|
409 |
}
|
|
410 |
|
|
411 |
private static class SubClassA extends SuperClass implements SingleImplementorInterface {
|
|
412 |
|
|
413 |
SubClassA(int value) {
|
|
414 |
super(value);
|
|
415 |
}
|
|
416 |
|
|
417 |
@Override
|
|
418 |
public int publicOverriddenMethod() {
|
|
419 |
return value + 2;
|
|
420 |
}
|
|
421 |
|
|
422 |
@Override
|
|
423 |
protected int protectedOverriddenMethod() {
|
|
424 |
return value * 2;
|
|
425 |
}
|
|
426 |
}
|
|
427 |
|
|
428 |
private static class SubClassB extends SuperClass {
|
|
429 |
|
|
430 |
SubClassB(int value) {
|
|
431 |
super(value);
|
|
432 |
}
|
|
433 |
|
|
434 |
@Override
|
|
435 |
public int publicOverriddenMethod() {
|
|
436 |
return value + 3;
|
|
437 |
}
|
|
438 |
|
|
439 |
@Override
|
|
440 |
protected int protectedOverriddenMethod() {
|
|
441 |
return value * 3;
|
|
442 |
}
|
|
443 |
}
|
|
444 |
|
|
445 |
private static class SubClassC extends SuperClass {
|
|
446 |
|
|
447 |
SubClassC(int value) {
|
|
448 |
super(value);
|
|
449 |
}
|
|
450 |
|
|
451 |
@Override
|
|
452 |
public int publicOverriddenMethod() {
|
|
453 |
return value + 4;
|
|
454 |
}
|
|
455 |
|
|
456 |
@Override
|
|
457 |
protected int protectedOverriddenMethod() {
|
|
458 |
return value * 4;
|
|
459 |
}
|
|
460 |
}
|
|
461 |
|
|
462 |
private static final class FinalSubClass extends SuperClass {
|
|
463 |
|
|
464 |
FinalSubClass(int value) {
|
|
465 |
super(value);
|
|
466 |
}
|
|
467 |
|
|
468 |
@Override
|
|
469 |
public int publicOverriddenMethod() {
|
|
470 |
return value + 5;
|
|
471 |
}
|
|
472 |
|
|
473 |
@Override
|
|
474 |
protected int protectedOverriddenMethod() {
|
|
475 |
return value * 5;
|
|
476 |
}
|
|
477 |
}
|
|
478 |
|
|
479 |
private static final class StaticFinalFields {
|
|
480 |
|
51436
|
481 |
private static final Number NumberStaticFinalField = Integer.valueOf(1);
|
43972
|
482 |
private static final SuperClass SuperClassStaticFinalField = new SubClassA(2);
|
|
483 |
private static final FinalSubClass FinalSubClassStaticFinalField = new FinalSubClass(3);
|
|
484 |
private static final SingleImplementorInterface SingleImplementorStaticFinalField = new SubClassA(4);
|
|
485 |
private static final MultipleImplementorsInterface MultipleImplementorsStaticFinalField = new SubClassC(5);
|
|
486 |
private static final SubClassA SubClassAStaticFinalField = new SubClassA(6);
|
|
487 |
private static final SubClassB SubClassBStaticFinalField = new SubClassB(7);
|
|
488 |
private static final SubClassC SubClassCStaticFinalField = new SubClassC(8);
|
|
489 |
}
|
|
490 |
|
|
491 |
private static final class FinalFields {
|
|
492 |
|
51436
|
493 |
private final Number numberFinalField = Integer.valueOf(1);
|
43972
|
494 |
private final SuperClass superClassFinalField = new SubClassA(2);
|
|
495 |
private final FinalSubClass finalSubClassFinalField = new FinalSubClass(3);
|
|
496 |
private final SingleImplementorInterface singleImplementorFinalField = new SubClassA(4);
|
|
497 |
private final MultipleImplementorsInterface multipleImplementorsFinalField = new SubClassC(5);
|
|
498 |
private final SubClassA subClassAFinalField = new SubClassA(6);
|
|
499 |
private final SubClassB subClassBFinalField = new SubClassB(7);
|
|
500 |
private final SubClassC subClassCFinalField = new SubClassC(8);
|
|
501 |
}
|
|
502 |
|
|
503 |
private static final class Fields {
|
|
504 |
|
51436
|
505 |
private Number numberField = Integer.valueOf(1);
|
43972
|
506 |
private SuperClass superClassField = new SubClassA(2);
|
|
507 |
private FinalSubClass finalSubClassField = new FinalSubClass(3);
|
|
508 |
private SingleImplementorInterface singleImplementorField = new SubClassA(4);
|
|
509 |
private MultipleImplementorsInterface multipleImplementorsField = new SubClassC(5);
|
|
510 |
private SubClassA subClassAField = new SubClassA(6);
|
|
511 |
private SubClassB subClassBField = new SubClassB(7);
|
|
512 |
private SubClassC subClassCField = new SubClassC(8);
|
|
513 |
}
|
|
514 |
}
|