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