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