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.amd64; 024 025import jdk.internal.jvmci.amd64.*; 026import jdk.internal.jvmci.code.*; 027import jdk.internal.jvmci.code.CallingConvention.*; 028import jdk.internal.jvmci.hotspot.*; 029import jdk.internal.jvmci.meta.*; 030import jdk.internal.jvmci.service.*; 031 032import com.oracle.graal.asm.*; 033import com.oracle.graal.asm.amd64.*; 034import com.oracle.graal.asm.amd64.AMD64Assembler.*; 035import com.oracle.graal.compiler.common.spi.*; 036import com.oracle.graal.hotspot.meta.*; 037import com.oracle.graal.lir.asm.*; 038import com.oracle.graal.lir.framemap.*; 039import com.oracle.graal.truffle.*; 040import com.oracle.graal.truffle.hotspot.*; 041 042@ServiceProvider(OptimizedCallTargetInstrumentationFactory.class) 043public class AMD64OptimizedCallTargetInstrumentationFactory implements OptimizedCallTargetInstrumentationFactory { 044 045 public CompilationResultBuilder createBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, FrameContext frameContext, 046 CompilationResult compilationResult) { 047 return new OptimizedCallTargetInstrumentation(codeCache, foreignCalls, frameMap, asm, frameContext, compilationResult) { 048 @Override 049 protected void injectTailCallCode(HotSpotVMConfig config, HotSpotRegistersProvider registers) { 050 @SuppressWarnings("hiding") 051 AMD64MacroAssembler asm = (AMD64MacroAssembler) this.asm; 052 Register thisRegister = codeCache.getRegisterConfig().getCallingConventionRegisters(Type.JavaCall, Kind.Object)[0]; 053 Register spillRegister = AMD64.r10; // TODO(mg): fix me 054 Label doProlog = new Label(); 055 056 AMD64Address codeBlobAddress = new AMD64Address(thisRegister, getFieldOffset("address", InstalledCode.class)); 057 asm.movq(spillRegister, codeBlobAddress); 058 asm.cmpq(spillRegister, 0); 059 asm.jcc(ConditionFlag.Equal, doProlog); 060 061 AMD64Address verifiedEntryPointAddress = new AMD64Address(spillRegister, config.nmethodEntryOffset); 062 asm.movq(spillRegister, verifiedEntryPointAddress); 063 asm.jmp(spillRegister); 064 065 asm.bind(doProlog); 066 } 067 }; 068 } 069 070 public void setInstrumentedMethod(ResolvedJavaMethod method) { 071 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; 072 hsMethod.setNotInlineable(); 073 } 074 075 public String getArchitecture() { 076 return "AMD64"; 077 } 078}