1 /*
   2  * Copyright (c) 2012, 2015, 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 jdk.vm.ci.hotspot.sparc;
  24 
  25 import static jdk.vm.ci.inittimer.InitTimer.timer;
  26 
  27 import java.util.EnumSet;
  28 
  29 import jdk.vm.ci.code.Architecture;
  30 import jdk.vm.ci.code.RegisterConfig;
  31 import jdk.vm.ci.code.TargetDescription;
  32 import jdk.vm.ci.code.stack.StackIntrospection;
  33 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
  34 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
  35 import jdk.vm.ci.hotspot.HotSpotJVMCIBackendFactory;
  36 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider;
  37 import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider;
  38 import jdk.vm.ci.hotspot.HotSpotStackIntrospection;
  39 import jdk.vm.ci.hotspot.HotSpotVMConfig;
  40 import jdk.vm.ci.inittimer.InitTimer;
  41 import jdk.vm.ci.runtime.JVMCIBackend;
  42 import jdk.vm.ci.sparc.SPARC;
  43 import jdk.vm.ci.sparc.SPARC.CPUFeature;
  44 
  45 public class SPARCHotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory {
  46 
  47     protected TargetDescription createTarget(HotSpotVMConfig config) {
  48         final int stackFrameAlignment = 16;
  49         final int implicitNullCheckLimit = 4096;
  50         final boolean inlineObjects = false;
  51         Architecture arch = new SPARC(computeFeatures(config));
  52         return new TargetDescription(arch, true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects);
  53     }
  54 
  55     protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) {
  56         return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig);
  57     }
  58 
  59     protected EnumSet<CPUFeature> computeFeatures(HotSpotVMConfig config) {
  60         EnumSet<CPUFeature> features = EnumSet.noneOf(CPUFeature.class);
  61         if ((config.vmVersionFeatures & config.sparcVis1Instructions) != 0) {
  62             features.add(CPUFeature.VIS1);
  63         }
  64         if ((config.vmVersionFeatures & config.sparcVis2Instructions) != 0) {
  65             features.add(CPUFeature.VIS2);
  66         }
  67         if ((config.vmVersionFeatures & config.sparcVis3Instructions) != 0) {
  68             features.add(CPUFeature.VIS3);
  69         }
  70         if ((config.vmVersionFeatures & config.sparcCbcondInstructions) != 0) {
  71             features.add(CPUFeature.CBCOND);
  72         }
  73         if ((config.vmVersionFeatures & config.sparcV8Instructions) != 0) {
  74             features.add(CPUFeature.V8);
  75         }
  76         if ((config.vmVersionFeatures & config.sparcHardwareMul32) != 0) {
  77             features.add(CPUFeature.HARDWARE_MUL32);
  78         }
  79         if ((config.vmVersionFeatures & config.sparcHardwareDiv32) != 0) {
  80             features.add(CPUFeature.HARDWARE_DIV32);
  81         }
  82         if ((config.vmVersionFeatures & config.sparcHardwareFsmuld) != 0) {
  83             features.add(CPUFeature.HARDWARE_FSMULD);
  84         }
  85         if ((config.vmVersionFeatures & config.sparcHardwarePopc) != 0) {
  86             features.add(CPUFeature.HARDWARE_POPC);
  87         }
  88         if ((config.vmVersionFeatures & config.sparcV9Instructions) != 0) {
  89             features.add(CPUFeature.V9);
  90         }
  91         if ((config.vmVersionFeatures & config.sparcSun4v) != 0) {
  92             features.add(CPUFeature.SUN4V);
  93         }
  94         if ((config.vmVersionFeatures & config.sparcBlkInitInstructions) != 0) {
  95             features.add(CPUFeature.BLK_INIT_INSTRUCTIONS);
  96         }
  97         if ((config.vmVersionFeatures & config.sparcFmafInstructions) != 0) {
  98             features.add(CPUFeature.FMAF);
  99         }
 100         if ((config.vmVersionFeatures & config.sparcFmauInstructions) != 0) {
 101             features.add(CPUFeature.FMAU);
 102         }
 103         if ((config.vmVersionFeatures & config.sparcSparc64Family) != 0) {
 104             features.add(CPUFeature.SPARC64_FAMILY);
 105         }
 106         if ((config.vmVersionFeatures & config.sparcMFamily) != 0) {
 107             features.add(CPUFeature.M_FAMILY);
 108         }
 109         if ((config.vmVersionFeatures & config.sparcTFamily) != 0) {
 110             features.add(CPUFeature.T_FAMILY);
 111         }
 112         if ((config.vmVersionFeatures & config.sparcT1Model) != 0) {
 113             features.add(CPUFeature.T1_MODEL);
 114         }
 115         if ((config.vmVersionFeatures & config.sparcSparc5Instructions) != 0) {
 116             features.add(CPUFeature.SPARC5);
 117         }
 118         if ((config.vmVersionFeatures & config.sparcAesInstructions) != 0) {
 119             features.add(CPUFeature.SPARC64_FAMILY);
 120         }
 121         if ((config.vmVersionFeatures & config.sparcSha1Instruction) != 0) {
 122             features.add(CPUFeature.SHA1);
 123         }
 124         if ((config.vmVersionFeatures & config.sparcSha256Instruction) != 0) {
 125             features.add(CPUFeature.SHA256);
 126         }
 127         if ((config.vmVersionFeatures & config.sparcSha512Instruction) != 0) {
 128             features.add(CPUFeature.SHA512);
 129         }
 130         return features;
 131     }
 132 
 133     @Override
 134     public String getArchitecture() {
 135         return "SPARC";
 136     }
 137 
 138     @Override
 139     public String toString() {
 140         return "JVMCIBackend:" + getArchitecture();
 141     }
 142 
 143     @SuppressWarnings("try")
 144     public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) {
 145         assert host == null;
 146         TargetDescription target = createTarget(runtime.getConfig());
 147 
 148         HotSpotMetaAccessProvider metaAccess = new HotSpotMetaAccessProvider(runtime);
 149         RegisterConfig regConfig = new SPARCHotSpotRegisterConfig(target.arch, runtime.getConfig());
 150         HotSpotCodeCacheProvider codeCache = createCodeCache(runtime, target, regConfig);
 151         HotSpotConstantReflectionProvider constantReflection = new HotSpotConstantReflectionProvider(runtime);
 152         StackIntrospection stackIntrospection = new HotSpotStackIntrospection(runtime);
 153         try (InitTimer rt = timer("instantiate backend")) {
 154             return createBackend(metaAccess, codeCache, constantReflection, stackIntrospection);
 155         }
 156     }
 157 
 158     protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, HotSpotConstantReflectionProvider constantReflection,
 159                     StackIntrospection stackIntrospection) {
 160         return new JVMCIBackend(metaAccess, codeCache, constantReflection, stackIntrospection);
 161     }
 162 }