001/*
002 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.hotspot.sparc;
024
025import static jdk.internal.jvmci.hotspot.InitTimer.*;
026
027import java.util.*;
028
029import jdk.internal.jvmci.code.*;
030import jdk.internal.jvmci.hotspot.*;
031import jdk.internal.jvmci.runtime.*;
032import jdk.internal.jvmci.service.*;
033import jdk.internal.jvmci.sparc.*;
034import jdk.internal.jvmci.sparc.SPARC.*;
035
036@ServiceProvider(HotSpotJVMCIBackendFactory.class)
037public class SPARCHotSpotJVMCIBackendFactory implements HotSpotJVMCIBackendFactory {
038
039    protected Architecture createArchitecture(HotSpotVMConfig config) {
040        return new SPARC(computeFeatures(config));
041    }
042
043    protected TargetDescription createTarget(HotSpotVMConfig config) {
044        final int stackFrameAlignment = 16;
045        final int implicitNullCheckLimit = 4096;
046        final boolean inlineObjects = false;
047        return new TargetDescription(createArchitecture(config), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects);
048    }
049
050    protected HotSpotCodeCacheProvider createCodeCache(HotSpotJVMCIRuntimeProvider runtime, TargetDescription target, RegisterConfig regConfig) {
051        return new HotSpotCodeCacheProvider(runtime, runtime.getConfig(), target, regConfig);
052    }
053
054    protected EnumSet<CPUFeature> computeFeatures(HotSpotVMConfig config) {
055        EnumSet<CPUFeature> features = EnumSet.noneOf(CPUFeature.class);
056        if ((config.sparcFeatures & config.vis1Instructions) != 0) {
057            features.add(CPUFeature.VIS1);
058        }
059        if ((config.sparcFeatures & config.vis2Instructions) != 0) {
060            features.add(CPUFeature.VIS2);
061        }
062        if ((config.sparcFeatures & config.vis3Instructions) != 0) {
063            features.add(CPUFeature.VIS3);
064        }
065        if ((config.sparcFeatures & config.cbcondInstructions) != 0) {
066            features.add(CPUFeature.CBCOND);
067        }
068        return features;
069    }
070
071    public String getArchitecture() {
072        return "SPARC";
073    }
074
075    @Override
076    public String toString() {
077        return getJVMCIRuntimeName() + ":" + getArchitecture();
078    }
079
080    public JVMCIBackend createJVMCIBackend(HotSpotJVMCIRuntimeProvider runtime, JVMCIBackend host) {
081        assert host == null;
082        TargetDescription target = createTarget(runtime.getConfig());
083
084        HotSpotMetaAccessProvider metaAccess = new HotSpotMetaAccessProvider(runtime);
085        RegisterConfig regConfig = new SPARCHotSpotRegisterConfig(target, runtime.getConfig());
086        HotSpotCodeCacheProvider codeCache = createCodeCache(runtime, target, regConfig);
087        HotSpotConstantReflectionProvider constantReflection = new HotSpotConstantReflectionProvider(runtime);
088        try (InitTimer rt = timer("instantiate backend")) {
089            return createBackend(metaAccess, codeCache, constantReflection);
090        }
091    }
092
093    protected JVMCIBackend createBackend(HotSpotMetaAccessProvider metaAccess, HotSpotCodeCacheProvider codeCache, HotSpotConstantReflectionProvider constantReflection) {
094        return new JVMCIBackend(metaAccess, codeCache, constantReflection);
095    }
096
097    public String getJVMCIRuntimeName() {
098        return "basic";
099    }
100}