001/* 002 * Copyright (c) 2013, 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 com.oracle.graal.truffle.hotspot.sparc; 024 025import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; 026import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; 027import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; 028import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; 029import static jdk.internal.jvmci.code.CallingConvention.Type.*; 030import static jdk.internal.jvmci.meta.Kind.*; 031import static jdk.internal.jvmci.sparc.SPARC.CPUFeature.*; 032import jdk.internal.jvmci.code.*; 033import jdk.internal.jvmci.hotspot.*; 034import jdk.internal.jvmci.meta.*; 035import jdk.internal.jvmci.service.*; 036 037import com.oracle.graal.asm.*; 038import com.oracle.graal.asm.sparc.*; 039import com.oracle.graal.asm.sparc.SPARCMacroAssembler.*; 040import com.oracle.graal.compiler.common.spi.*; 041import com.oracle.graal.hotspot.meta.*; 042import com.oracle.graal.lir.asm.*; 043import com.oracle.graal.lir.framemap.*; 044import com.oracle.graal.truffle.*; 045import com.oracle.graal.truffle.hotspot.*; 046 047@ServiceProvider(OptimizedCallTargetInstrumentationFactory.class) 048public class SPARCOptimizedCallTargetInstumentationFactory implements OptimizedCallTargetInstrumentationFactory { 049 050 public CompilationResultBuilder createBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, FrameContext frameContext, 051 CompilationResult compilationResult) { 052 return new OptimizedCallTargetInstrumentation(codeCache, foreignCalls, frameMap, asm, frameContext, compilationResult) { 053 @Override 054 protected void injectTailCallCode(HotSpotVMConfig config, HotSpotRegistersProvider registers) { 055 @SuppressWarnings("hiding") 056 SPARCMacroAssembler asm = (SPARCMacroAssembler) this.asm; 057 try (ScratchRegister scratch = asm.getScratchRegister()) { 058 Register thisRegister = codeCache.getRegisterConfig().getCallingConventionRegisters(JavaCall, Object)[0]; 059 Register spillRegister = scratch.getRegister(); 060 Label doProlog = new Label(); 061 SPARCAddress codeBlobAddress = new SPARCAddress(thisRegister, getFieldOffset("address", InstalledCode.class)); 062 SPARCAddress verifiedEntryPointAddress = new SPARCAddress(spillRegister, config.nmethodEntryOffset); 063 064 asm.ldx(codeBlobAddress, spillRegister); 065 if (asm.hasFeature(CBCOND)) { 066 asm.cbcondx(Equal, spillRegister, 0, doProlog); 067 } else { 068 asm.cmp(spillRegister, 0); 069 asm.bpcc(Equal, NOT_ANNUL, doProlog, Xcc, PREDICT_NOT_TAKEN); 070 asm.nop(); 071 } 072 asm.ldx(verifiedEntryPointAddress, spillRegister); // in delay slot 073 asm.jmp(spillRegister); 074 asm.nop(); 075 asm.bind(doProlog); 076 } 077 } 078 }; 079 } 080 081 public void setInstrumentedMethod(ResolvedJavaMethod method) { 082 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; 083 hsMethod.setNotInlineable(); 084 } 085 086 public String getArchitecture() { 087 return "SPARC"; 088 } 089}