1 /*
   2  * Copyright (c) 2013, 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.hotspot.meta;
  26 
  27 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  28 import org.graalvm.compiler.core.common.spi.ConstantFieldProvider;
  29 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  30 import org.graalvm.compiler.hotspot.word.HotSpotWordTypes;
  31 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
  32 import org.graalvm.compiler.nodes.spi.LoweringProvider;
  33 import org.graalvm.compiler.nodes.spi.Replacements;
  34 import org.graalvm.compiler.phases.tiers.SuitesProvider;
  35 import org.graalvm.compiler.phases.util.Providers;
  36 
  37 import jdk.vm.ci.code.CodeCacheProvider;
  38 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
  39 import jdk.vm.ci.meta.ConstantReflectionProvider;
  40 import jdk.vm.ci.meta.MetaAccessProvider;
  41 
  42 /**
  43  * Extends {@link Providers} to include a number of extra capabilities used by the HotSpot parts of
  44  * the compiler.
  45  */
  46 public class HotSpotProviders extends Providers {
  47 
  48     private final SuitesProvider suites;
  49     private final HotSpotRegistersProvider registers;
  50     private final SnippetReflectionProvider snippetReflection;
  51     private final HotSpotWordTypes wordTypes;
  52     private final Plugins graphBuilderPlugins;
  53     private final HotSpotGCProvider gc;
  54 
  55     public HotSpotProviders(MetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, ConstantReflectionProvider constantReflection, ConstantFieldProvider constantField,
  56                     HotSpotForeignCallsProvider foreignCalls, LoweringProvider lowerer, Replacements replacements, SuitesProvider suites, HotSpotRegistersProvider registers,
  57                     SnippetReflectionProvider snippetReflection, HotSpotWordTypes wordTypes, Plugins graphBuilderPlugins, HotSpotGCProvider gc) {
  58         super(metaAccess, codeCache, constantReflection, constantField, foreignCalls, lowerer, replacements, new HotSpotStampProvider(), gc);
  59         this.suites = suites;
  60         this.registers = registers;
  61         this.snippetReflection = snippetReflection;
  62         this.wordTypes = wordTypes;
  63         this.graphBuilderPlugins = graphBuilderPlugins;
  64         this.gc = gc;
  65     }
  66 
  67     @Override
  68     public HotSpotCodeCacheProvider getCodeCache() {
  69         return (HotSpotCodeCacheProvider) super.getCodeCache();
  70     }
  71 
  72     @Override
  73     public HotSpotForeignCallsProvider getForeignCalls() {
  74         return (HotSpotForeignCallsProvider) super.getForeignCalls();
  75     }
  76 
  77     public SuitesProvider getSuites() {
  78         return suites;
  79     }
  80 
  81     public HotSpotRegistersProvider getRegisters() {
  82         return registers;
  83     }
  84 
  85     public SnippetReflectionProvider getSnippetReflection() {
  86         return snippetReflection;
  87     }
  88 
  89     public Plugins getGraphBuilderPlugins() {
  90         return graphBuilderPlugins;
  91     }
  92 
  93     public HotSpotWordTypes getWordTypes() {
  94         return wordTypes;
  95     }
  96 
  97     @Override
  98     public HotSpotGCProvider getGC() {
  99         return gc;
 100     }
 101 
 102     @Override
 103     public Providers copyWith(MetaAccessProvider substitution) {
 104         return new HotSpotProviders(substitution, getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(), getSuites(),
 105                         getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 106     }
 107 
 108     @Override
 109     public Providers copyWith(CodeCacheProvider substitution) {
 110         return new HotSpotProviders(getMetaAccess(), (HotSpotCodeCacheProvider) substitution, getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(),
 111                         getSuites(), getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 112     }
 113 
 114     @Override
 115     public Providers copyWith(ConstantReflectionProvider substitution) {
 116         return new HotSpotProviders(getMetaAccess(), getCodeCache(), substitution, getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(), getSuites(),
 117                         getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 118     }
 119 
 120     @Override
 121     public Providers copyWith(ConstantFieldProvider substitution) {
 122         return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), substitution, getForeignCalls(), getLowerer(), getReplacements(), getSuites(),
 123                         getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 124     }
 125 
 126     @Override
 127     public Providers copyWith(ForeignCallsProvider substitution) {
 128         return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), (HotSpotForeignCallsProvider) substitution, getLowerer(), getReplacements(),
 129                         getSuites(), getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 130     }
 131 
 132     @Override
 133     public Providers copyWith(LoweringProvider substitution) {
 134         return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), substitution, getReplacements(), getSuites(),
 135                         getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 136     }
 137 
 138     @Override
 139     public Providers copyWith(Replacements substitution) {
 140         return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), substitution, getSuites(),
 141                         getRegisters(), getSnippetReflection(), getWordTypes(), getGraphBuilderPlugins(), getGC());
 142     }
 143 
 144     public Providers copyWith(Plugins substitution) {
 145         return new HotSpotProviders(getMetaAccess(), getCodeCache(), getConstantReflection(), getConstantFieldProvider(), getForeignCalls(), getLowerer(), getReplacements(), getSuites(),
 146                         getRegisters(), getSnippetReflection(), getWordTypes(), substitution, getGC());
 147     }
 148 }