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