|
1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
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 package org.graalvm.compiler.core.test; |
|
24 |
|
25 import org.graalvm.compiler.core.common.CompilationIdentifier; |
|
26 import org.graalvm.compiler.core.common.GraalOptions; |
|
27 import org.graalvm.compiler.java.BytecodeParserOptions; |
|
28 import org.graalvm.compiler.nodes.StructuredGraph; |
|
29 import org.graalvm.compiler.options.OptionValues; |
|
30 import org.junit.Assert; |
|
31 import org.junit.Test; |
|
32 |
|
33 import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
34 |
|
35 /** |
|
36 * Tests that the defaults for {@link GraalOptions#TrivialInliningSize} and |
|
37 * {@link BytecodeParserOptions#InlineDuringParsingMaxDepth} prevent explosive graph growth for code |
|
38 * with small recursive methods. |
|
39 */ |
|
40 public class TrivialInliningExplosionTest extends GraalCompilerTest { |
|
41 |
|
42 public static void trivial() { |
|
43 trivial(); |
|
44 trivial(); |
|
45 trivial(); |
|
46 } |
|
47 |
|
48 public static void main() { |
|
49 trivial(); |
|
50 trivial(); |
|
51 trivial(); |
|
52 trivial(); |
|
53 trivial(); |
|
54 trivial(); |
|
55 trivial(); |
|
56 trivial(); |
|
57 trivial(); |
|
58 } |
|
59 |
|
60 private int afterParseSize; |
|
61 |
|
62 @Override |
|
63 protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) { |
|
64 final StructuredGraph graph = super.parseForCompile(method, compilationId, options); |
|
65 this.afterParseSize = graph.getNodeCount(); |
|
66 return graph; |
|
67 } |
|
68 |
|
69 @Test |
|
70 public void test() { |
|
71 ResolvedJavaMethod methodm0 = getResolvedJavaMethod("trivial"); |
|
72 Assert.assertTrue(methodm0.getCodeSize() <= GraalOptions.TrivialInliningSize.getValue(getInitialOptions())); |
|
73 test("main"); |
|
74 int afterCompileSize = lastCompiledGraph.getNodeCount(); |
|
75 |
|
76 // The values of afterParseSize and afterCompileSize when this |
|
77 // test was written were 849 and 848 respectively. |
|
78 Assert.assertTrue(afterParseSize < 2000); |
|
79 Assert.assertTrue(afterCompileSize < 2000); |
|
80 |
|
81 } |
|
82 } |