1 /* 2 * Copyright (c) 2014, 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 24 25 package org.graalvm.compiler.hotspot.test; 26 27 import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID; 28 29 import java.util.List; 30 31 import jdk.internal.vm.compiler.collections.EconomicMap; 32 import org.graalvm.compiler.api.test.Graal; 33 import org.graalvm.compiler.core.test.GraalCompilerTest; 34 import org.graalvm.compiler.debug.DebugContext; 35 import org.graalvm.compiler.hotspot.HotSpotGraalCompiler; 36 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; 37 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 38 import org.graalvm.compiler.nodes.StructuredGraph; 39 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; 40 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 41 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; 42 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Binding; 43 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin; 44 import org.graalvm.compiler.options.OptionValues; 45 import org.graalvm.compiler.runtime.RuntimeProvider; 46 import org.junit.Test; 47 48 import jdk.vm.ci.hotspot.HotSpotVMConfigStore; 49 import jdk.vm.ci.hotspot.VMIntrinsicMethod; 50 import jdk.vm.ci.meta.ResolvedJavaMethod; 51 import jdk.vm.ci.runtime.JVMCI; 52 53 /** 54 * Exercise the compilation of intrinsic method substitutions. 55 */ 56 public class TestIntrinsicCompiles extends GraalCompilerTest { 57 58 @Test 59 @SuppressWarnings("try") 60 public void test() throws ClassNotFoundException { 61 HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) JVMCI.getRuntime().getCompiler(); 62 HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class); 63 HotSpotProviders providers = rt.getHostBackend().getProviders(); 64 Plugins graphBuilderPlugins = providers.getGraphBuilderPlugins(); 65 InvocationPlugins invocationPlugins = graphBuilderPlugins.getInvocationPlugins(); 66 67 EconomicMap<String, List<Binding>> bindings = invocationPlugins.getBindings(true); 68 HotSpotVMConfigStore store = rt.getVMConfig().getStore(); 69 List<VMIntrinsicMethod> intrinsics = store.getIntrinsics(); 70 OptionValues options = getInitialOptions(); 71 DebugContext debug = getDebugContext(options); 72 for (VMIntrinsicMethod intrinsic : intrinsics) { 73 InvocationPlugin plugin = CheckGraalIntrinsics.findPlugin(bindings, intrinsic); 74 if (plugin != null) { 75 if (plugin instanceof MethodSubstitutionPlugin) { 76 ResolvedJavaMethod method = CheckGraalIntrinsics.resolveIntrinsic(getMetaAccess(), intrinsic); 77 if (!method.isNative()) { 78 StructuredGraph graph = compiler.getIntrinsicGraph(method, providers, INVALID_COMPILATION_ID, options, debug); 79 getCode(method, graph); 80 } 81 } 82 } 83 } 84 } 85 }