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