1 /*
   2  * Copyright (c) 2012, 2016, 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.common.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.common.InitTimer;
  34 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
  35 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
  36 import jdk.vm.ci.hotspot.HotSpotJVMCIBackendFactory;
  37 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
  38 import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider;
  39 import jdk.vm.ci.hotspot.HotSpotStackIntrospection;
  40 import jdk.vm.ci.runtime.JVMCIBackend;
  41 import jdk.vm.ci.sparc.SPARC;
  42 import jdk.vm.ci.sparc.SPARC.CPUFeature;
  43 
  44 public class SPARCHotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory {
  45 
  46     private static TargetDescription createTarget(SPARCHotSpotVMConfig config) {
  47         final int stackFrameAlignment = 16;
  48         final int implicitNullCheckLimit = 4096;
  49         final boolean inlineObjects = false;
  50         Architecture arch = new SPARC(computeFeatures(config));
  51         return new TargetDescription(arch, true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects);
  52     }
  53 
  54     protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntime runtime, TargetDescription target, RegisterConfig regConfig) {
  55         return new HotSpotCodeCacheProvider(runtime, target, regConfig);
  56     }
  57 
  58     private static EnumSet<CPUFeature> computeFeatures(SPARCHotSpotVMConfig config) {
  59         EnumSet<CPUFeature> features = EnumSet.noneOf(CPUFeature.class);
  60 
  61         if ((config.vmVersionFeatures & 1L << config.sparc_ADI) != 0) {
  62             features.add(CPUFeature.ADI);
  63         }
  64         if ((config.vmVersionFeatures & 1L << config.sparc_AES) != 0) {
  65             features.add(CPUFeature.AES);
  66         }
  67         if ((config.vmVersionFeatures & 1L << config.sparc_BLK_INIT) != 0) {
  68             features.add(CPUFeature.BLK_INIT);
  69         }
  70         if ((config.vmVersionFeatures & 1L << config.sparc_CAMELLIA) != 0) {
  71             features.add(CPUFeature.CAMELLIA);
  72         }
  73         if ((config.vmVersionFeatures & 1L << config.sparc_CBCOND) != 0) {
  74             features.add(CPUFeature.CBCOND);
  75         }
  76         if ((config.vmVersionFeatures & 1L << config.sparc_CRC32C) != 0) {
  77             features.add(CPUFeature.CRC32C);
  78         }
  79         if ((config.vmVersionFeatures & 1L << config.sparc_DES) != 0) {
  80             features.add(CPUFeature.DES);
  81         }
  82         if ((config.vmVersionFeatures & 1L << config.sparc_DICTUNP) != 0) {
  83             features.add(CPUFeature.DICTUNP);
  84         }
  85         if ((config.vmVersionFeatures & 1L << config.sparc_FMAF) != 0) {
  86             features.add(CPUFeature.FMAF);
  87         }
  88         if ((config.vmVersionFeatures & 1L << config.sparc_FPCMPSHL) != 0) {
  89             features.add(CPUFeature.FPCMPSHL);
  90         }
  91         if ((config.vmVersionFeatures & 1L << config.sparc_HPC) != 0) {
  92             features.add(CPUFeature.HPC);
  93         }
  94         if ((config.vmVersionFeatures & 1L << config.sparc_IMA) != 0) {
  95             features.add(CPUFeature.IMA);
  96         }
  97         if ((config.vmVersionFeatures & 1L << config.sparc_KASUMI) != 0) {
  98             features.add(CPUFeature.KASUMI);
  99         }
 100         if ((config.vmVersionFeatures & 1L << config.sparc_MD5) != 0) {
 101             features.add(CPUFeature.MD5);
 102         }
 103         if ((config.vmVersionFeatures & 1L << config.sparc_MME) != 0) {
 104             features.add(CPUFeature.MME);
 105         }
 106         if ((config.vmVersionFeatures & 1L << config.sparc_MONT) != 0) {
 107             features.add(CPUFeature.MONT);
 108         }
 109         if ((config.vmVersionFeatures & 1L << config.sparc_MPMUL) != 0) {
 110             features.add(CPUFeature.MPMUL);
 111         }
 112         if ((config.vmVersionFeatures & 1L << config.sparc_MWAIT) != 0) {
 113             features.add(CPUFeature.MWAIT);
 114         }
 115         if ((config.vmVersionFeatures & 1L << config.sparc_PAUSE) != 0) {
 116             features.add(CPUFeature.PAUSE);
 117         }
 118         if ((config.vmVersionFeatures & 1L << config.sparc_PAUSE_NSEC) != 0) {
 119             features.add(CPUFeature.PAUSE_NSEC);
 120         }
 121         if ((config.vmVersionFeatures & 1L << config.sparc_POPC) != 0) {
 122             features.add(CPUFeature.POPC);
 123         }
 124         if ((config.vmVersionFeatures & 1L << config.sparc_RLE) != 0) {
 125             features.add(CPUFeature.RLE);
 126         }
 127         if ((config.vmVersionFeatures & 1L << config.sparc_SHA1) != 0) {
 128             features.add(CPUFeature.SHA1);
 129         }
 130         if ((config.vmVersionFeatures & 1L << config.sparc_SHA256) != 0) {
 131             features.add(CPUFeature.SHA256);
 132         }
 133         if ((config.vmVersionFeatures & 1L << config.sparc_SHA3) != 0) {
 134             features.add(CPUFeature.SHA3);
 135         }
 136         if ((config.vmVersionFeatures & 1L << config.sparc_SHA512) != 0) {
 137             features.add(CPUFeature.SHA512);
 138         }
 139         if ((config.vmVersionFeatures & 1L << config.sparc_SPARC5) != 0) {
 140             features.add(CPUFeature.SPARC5);
 141         }
 142         if ((config.vmVersionFeatures & 1L << config.sparc_SPARC5B) != 0) {
 143             features.add(CPUFeature.SPARC5B);
 144         }
 145         if ((config.vmVersionFeatures & 1L << config.sparc_SPARC6) != 0) {
 146             features.add(CPUFeature.SPARC6);
 147         }
 148         if ((config.vmVersionFeatures & 1L << config.sparc_V9) != 0) {
 149             features.add(CPUFeature.V9);
 150         }
 151         if ((config.vmVersionFeatures & 1L << config.sparc_VAMASK) != 0) {
 152             features.add(CPUFeature.VAMASK);
 153         }
 154         if ((config.vmVersionFeatures & 1L << config.sparc_VIS1) != 0) {
 155             features.add(CPUFeature.VIS1);
 156         }
 157         if ((config.vmVersionFeatures & 1L << config.sparc_VIS2) != 0) {
 158             features.add(CPUFeature.VIS2);
 159         }
 160         if ((config.vmVersionFeatures & 1L << config.sparc_VIS3) != 0) {
 161             features.add(CPUFeature.VIS3);
 162         }
 163         if ((config.vmVersionFeatures & 1L << config.sparc_VIS3B) != 0) {
 164             features.add(CPUFeature.VIS3B);
 165         }
 166         if ((config.vmVersionFeatures & 1L << config.sparc_VIS3C) != 0) {
 167             features.add(CPUFeature.VIS3C);
 168         }
 169         if ((config.vmVersionFeatures & 1L << config.sparc_XMONT) != 0) {
 170             features.add(CPUFeature.XMONT);
 171         }
 172         if ((config.vmVersionFeatures & 1L << config.sparc_XMPMUL) != 0) {
 173             features.add(CPUFeature.XMPMUL);
 174         }
 175 
 176         if ((config.vmVersionFeatures & 1L << config.sparc_BLK_ZEROING) != 0) {
 177             features.add(CPUFeature.BLK_ZEROING);
 178         }
 179         if ((config.vmVersionFeatures & 1L << config.sparc_FAST_BIS) != 0) {
 180             features.add(CPUFeature.FAST_BIS);
 181         }
 182         if ((config.vmVersionFeatures & 1L << config.sparc_FAST_CMOVE) != 0) {
 183             features.add(CPUFeature.FAST_CMOVE);
 184         }
 185         if ((config.vmVersionFeatures & 1L << config.sparc_FAST_IDIV) != 0) {
 186             features.add(CPUFeature.FAST_IDIV);
 187         }
 188         if ((config.vmVersionFeatures & 1L << config.sparc_FAST_IND_BR) != 0) {
 189             features.add(CPUFeature.FAST_IND_BR);
 190         }
 191         if ((config.vmVersionFeatures & 1L << config.sparc_FAST_LD) != 0) {
 192             features.add(CPUFeature.FAST_LD);
 193         }
 194         if ((config.vmVersionFeatures & 1L << config.sparc_FAST_RDPC) != 0) {
 195             features.add(CPUFeature.FAST_RDPC);
 196         }
 197 
 198         return features;
 199     }
 200 
 201     @Override
 202     public String getArchitecture() {
 203         return "SPARC";
 204     }
 205 
 206     @Override
 207     public String toString() {
 208         return "JVMCIBackend:" + getArchitecture();
 209     }
 210 
 211     @Override
 212     @SuppressWarnings("try")
 213     public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntime runtime, JVMCIBackend host) {
 214         assert host == null;
 215         SPARCHotSpotVMConfig config = new SPARCHotSpotVMConfig(runtime.getConfigStore());
 216         TargetDescription target = createTarget(config);
 217 
 218         HotSpotMetaAccessProvider metaAccess = new HotSpotMetaAccessProvider(runtime);
 219         RegisterConfig regConfig = new SPARCHotSpotRegisterConfig(target, config.useCompressedOops);
 220         HotSpotCodeCacheProvider codeCache = createCodeCache(runtime, target, regConfig);
 221         HotSpotConstantReflectionProvider constantReflection = new HotSpotConstantReflectionProvider(runtime);
 222         StackIntrospection stackIntrospection = new HotSpotStackIntrospection(runtime);
 223         try (InitTimer rt = timer("instantiate backend")) {
 224             return createBackend(metaAccess, codeCache, constantReflection, stackIntrospection);
 225         }
 226     }
 227 
 228     protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, HotSpotConstantReflectionProvider constantReflection,
 229                     StackIntrospection stackIntrospection) {
 230         return new JVMCIBackend(metaAccess, codeCache, constantReflection, stackIntrospection);
 231     }
 232 }