1 /*
   2  * Copyright (c) 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.aarch64;
  24 
  25 import static jdk.vm.ci.inittimer.InitTimer.timer;
  26 
  27 import java.util.EnumSet;
  28 
  29 import jdk.vm.ci.aarch64.AArch64;
  30 import jdk.vm.ci.code.Architecture;
  31 import jdk.vm.ci.code.RegisterConfig;
  32 import jdk.vm.ci.code.TargetDescription;
  33 import jdk.vm.ci.code.stack.StackIntrospection;
  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.HotSpotJVMCIRuntimeProvider;
  38 import jdk.vm.ci.hotspot.HotSpotMetaAccessProvider;
  39 import jdk.vm.ci.hotspot.HotSpotStackIntrospection;
  40 import jdk.vm.ci.hotspot.HotSpotVMConfig;
  41 import jdk.vm.ci.inittimer.InitTimer;
  42 import jdk.vm.ci.meta.ConstantReflectionProvider;
  43 import jdk.vm.ci.runtime.JVMCIBackend;
  44 import jdk.vm.ci.service.ServiceProvider;
  45 
  46 @ServiceProvider(HotSpotJVMCIBackendFactory.class)
  47 public class AArch64HotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory {
  48 
  49     protected EnumSet<AArch64.CPUFeature> computeFeatures(@SuppressWarnings("unused") HotSpotVMConfig config) {
  50         // Configure the feature set using the HotSpot flag settings.
  51         EnumSet<AArch64.CPUFeature> features = EnumSet.noneOf(AArch64.CPUFeature.class);
  52         return features;
  53     }
  54 
  55     protected EnumSet<AArch64.Flag> computeFlags(@SuppressWarnings("unused") HotSpotVMConfig config) {
  56         EnumSet<AArch64.Flag> flags = EnumSet.noneOf(AArch64.Flag.class);
  57         return flags;
  58     }
  59 
  60     protected TargetDescription createTarget(HotSpotVMConfig config) {
  61         final int stackFrameAlignment = 16;
  62         final int implicitNullCheckLimit = 4096;
  63         final boolean inlineObjects = true;
  64         Architecture arch = new AArch64(computeFeatures(config), computeFlags(config));
  65         return new TargetDescription(arch, true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects);
  66     }
  67 
  68     protected HotSpotConstantReflectionProvider createConstantReflection(HotSpotJVMCIRuntimeProvider runtime) {
  69         return new HotSpotConstantReflectionProvider(runtime);
  70     }
  71 
  72     protected RegisterConfig createRegisterConfig(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target) {
  73         return new AArch64HotSpotRegisterConfig(target.arch, runtime.getConfig());
  74     }
  75 
  76     protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) {
  77         return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig);
  78     }
  79 
  80     protected HotSpotMetaAccessProvider createMetaAccess(HotSpotJVMCIRuntimeProvider runtime) {
  81         return new HotSpotMetaAccessProvider(runtime);
  82     }
  83 
  84     @Override
  85     public String getArchitecture() {
  86         return "aarch64";
  87     }
  88 
  89     @Override
  90     public String toString() {
  91         return "JVMCIBackend:" + getArchitecture();
  92     }
  93 
  94     @SuppressWarnings("try")
  95     public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) {
  96 
  97         assert host == null;
  98         TargetDescription target = createTarget(runtime.getConfig());
  99 
 100         RegisterConfig regConfig;
 101         HotSpotCodeCacheProvider codeCache;
 102         ConstantReflectionProvider constantReflection;
 103         HotSpotMetaAccessProvider metaAccess;
 104         StackIntrospection stackIntrospection;
 105         try (InitTimer t = timer("create providers")) {
 106             try (InitTimer rt = timer("create MetaAccess provider")) {
 107                 metaAccess = createMetaAccess(runtime);
 108             }
 109             try (InitTimer rt = timer("create RegisterConfig")) {
 110                 regConfig = createRegisterConfig(runtime, target);
 111             }
 112             try (InitTimer rt = timer("create CodeCache provider")) {
 113                 codeCache = createCodeCache(runtime, target, regConfig);
 114             }
 115             try (InitTimer rt = timer("create ConstantReflection provider")) {
 116                 constantReflection = createConstantReflection(runtime);
 117             }
 118             try (InitTimer rt = timer("create StackIntrospection provider")) {
 119                 stackIntrospection = new HotSpotStackIntrospection(runtime);
 120             }
 121         }
 122         try (InitTimer rt = timer("instantiate backend")) {
 123             return createBackend(metaAccess, codeCache, constantReflection, stackIntrospection);
 124         }
 125     }
 126 
 127     protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, ConstantReflectionProvider constantReflection,
 128                     StackIntrospection stackIntrospection) {
 129         return new JVMCIBackend(metaAccess, codeCache, constantReflection, stackIntrospection);
 130     }
 131 }