1 /* 2 * Copyright (c) 2013, 2016, 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 static org.graalvm.compiler.core.GraalCompiler.compileGraph; 26 import static org.graalvm.compiler.core.common.GraalOptions.OptAssumptions; 27 import static org.junit.Assert.assertNotNull; 28 import jdk.vm.ci.code.site.Call; 29 import jdk.vm.ci.code.site.Infopoint; 30 import jdk.vm.ci.code.site.InfopointReason; 31 import jdk.vm.ci.meta.ResolvedJavaMethod; 32 33 import org.junit.Test; 34 35 import org.graalvm.compiler.code.CompilationResult; 36 import org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory; 37 import org.graalvm.compiler.nodes.FullInfopointNode; 38 import org.graalvm.compiler.nodes.StructuredGraph; 39 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 40 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; 41 import org.graalvm.compiler.phases.OptimisticOptimizations; 42 import org.graalvm.compiler.phases.PhaseSuite; 43 import org.graalvm.compiler.phases.tiers.HighTierContext; 44 45 /** 46 * Test that infopoints in {@link CompilationResult}s have correctly assigned reasons. 47 */ 48 public class InfopointReasonTest extends GraalCompilerTest { 49 50 public static final String[] STRINGS = new String[]{"world", "everyone", "you"}; 51 52 public String testMethod() { 53 StringBuilder sb = new StringBuilder("Hello "); 54 for (String s : STRINGS) { 55 sb.append(s).append(", "); 56 } 57 sb.replace(sb.length() - 2, sb.length(), "!"); 58 return sb.toString(); 59 } 60 61 @Test 62 public void callInfopoints() { 63 final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod"); 64 final StructuredGraph graph = parseEager(method, AllowAssumptions.YES); 65 final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, graph.getProfilingInfo(), 66 getSuites(), getLIRSuites(), new CompilationResult(), CompilationResultBuilderFactory.Default); 67 for (Infopoint sp : cr.getInfopoints()) { 68 assertNotNull(sp.reason); 69 if (sp instanceof Call) { 70 assertDeepEquals(InfopointReason.CALL, sp.reason); 71 } 72 } 73 } 74 75 @Test 76 public void lineInfopoints() { 77 final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod"); 78 final StructuredGraph graph = parseDebug(method, AllowAssumptions.from(OptAssumptions.getValue())); 79 int graphLineSPs = 0; 80 for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) { 81 if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) { 82 ++graphLineSPs; 83 } 84 } 85 assertTrue(graphLineSPs > 0); 86 PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true)); 87 final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), getSuites(), 88 getLIRSuites(), new CompilationResult(), CompilationResultBuilderFactory.Default); 89 int lineSPs = 0; 90 for (Infopoint sp : cr.getInfopoints()) { 91 assertNotNull(sp.reason); 92 if (sp.reason == InfopointReason.BYTECODE_POSITION) { 93 ++lineSPs; 94 } 95 } 96 assertTrue(lineSPs > 0); 97 } 98 99 }