1 /*
   2  * Copyright (c) 2013, 2019, 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;
  26 
  27 import org.graalvm.compiler.bytecode.BytecodeProvider;
  28 import org.graalvm.compiler.hotspot.meta.HotSpotGCProvider;
  29 import org.graalvm.compiler.hotspot.meta.HotSpotGraalConstantFieldProvider;
  30 import org.graalvm.compiler.hotspot.meta.HotSpotSnippetReflectionProvider;
  31 import org.graalvm.compiler.hotspot.meta.HotSpotStampProvider;
  32 import org.graalvm.compiler.hotspot.word.HotSpotWordTypes;
  33 import org.graalvm.compiler.phases.tiers.CompilerConfiguration;
  34 import org.graalvm.compiler.phases.util.Providers;
  35 import org.graalvm.compiler.replacements.classfile.ClassfileBytecodeProvider;
  36 
  37 import jdk.vm.ci.code.Architecture;
  38 import jdk.vm.ci.code.TargetDescription;
  39 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
  40 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  41 import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider;
  42 
  43 public abstract class HotSpotBackendFactory {
  44 
  45     protected HotSpotGraalConstantFieldProvider createConstantFieldProvider(GraalHotSpotVMConfig config, HotSpotMetaAccessProvider metaAccess) {
  46         return new HotSpotGraalConstantFieldProvider(config, metaAccess);
  47     }
  48 
  49     protected HotSpotWordTypes createWordTypes(HotSpotMetaAccessProvider metaAccess, TargetDescription target) {
  50         return new HotSpotWordTypes(metaAccess, target.wordJavaKind);
  51     }
  52 
  53     protected HotSpotStampProvider createStampProvider() {
  54         return new HotSpotStampProvider();
  55     }
  56 
  57     protected HotSpotGCProvider createGCProvider(GraalHotSpotVMConfig config) {
  58         return new HotSpotGCProvider(config);
  59     }
  60 
  61     protected HotSpotReplacementsImpl createReplacements(TargetDescription target, Providers p, HotSpotSnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider) {
  62         return new HotSpotReplacementsImpl(p, snippetReflection, bytecodeProvider, target);
  63     }
  64 
  65     protected ClassfileBytecodeProvider createBytecodeProvider(HotSpotMetaAccessProvider metaAccess, HotSpotSnippetReflectionProvider snippetReflection) {
  66         return new ClassfileBytecodeProvider(metaAccess, snippetReflection);
  67     }
  68 
  69     protected HotSpotSnippetReflectionProvider createSnippetReflection(HotSpotGraalRuntimeProvider runtime, HotSpotConstantReflectionProvider constantReflection, HotSpotWordTypes wordTypes) {
  70         return new HotSpotSnippetReflectionProvider(runtime, constantReflection, wordTypes);
  71     }
  72 
  73     /**
  74      * Gets the name of this backend factory. This should not include the {@link #getArchitecture()
  75      * architecture}. The {@link CompilerConfigurationFactory} can select alternative backends based
  76      * on this name.
  77      */
  78     public abstract String getName();
  79 
  80     /**
  81      * Gets the class describing the architecture the backend created by this factory is associated
  82      * with.
  83      */
  84     public abstract Class<? extends Architecture> getArchitecture();
  85 
  86     public abstract HotSpotBackend createBackend(HotSpotGraalRuntimeProvider runtime, CompilerConfiguration compilerConfiguration, HotSpotJVMCIRuntime jvmciRuntime, HotSpotBackend host);
  87 }