Path: blob/master/runtime/compiler/x/codegen/J9LinkageUtils.cpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include "codegen/Linkage_inlines.hpp"23#include "codegen/RealRegister.hpp"24#include "codegen/Register.hpp"25#include "codegen/CodeGenerator.hpp"26#include "il/LabelSymbol.hpp"27#include "il/MethodSymbol.hpp"28#include "il/Node.hpp"29#include "il/Node_inlines.hpp"30#include "il/RegisterMappedSymbol.hpp"31#include "il/ResolvedMethodSymbol.hpp"32#include "il/StaticSymbol.hpp"33#include "il/Symbol.hpp"34#include "codegen/X86Instruction.hpp"35#include "x/codegen/J9LinkageUtils.hpp"36#include "env/VMJ9.h"37#include "codegen/Machine.hpp"38#include "x/codegen/IA32LinkageUtils.hpp"39#include "compile/ResolvedMethod.hpp"40#include "env/CompilerEnv.hpp"41#include "env/VMJ9.h"4243namespace TR44{4546// can be commoned47void J9LinkageUtils::cleanupReturnValue(48TR::Node *callNode,49TR::Register *linkageReturnReg,50TR::Register *targetReg,51TR::CodeGenerator *cg)52{53if (!callNode->getOpCode().isFloatingPoint())54{55// Native and JNI methods may not return a full register in some cases so we need to get the declared56// type so that we sign and zero extend the narrower integer return types properly.57//58TR::InstOpCode::Mnemonic op;59TR::ResolvedMethodSymbol *callSymbol = callNode->getSymbol()->castToResolvedMethodSymbol();60TR_ResolvedMethod *resolvedMethod = callSymbol->getResolvedMethod();61TR::Compilation *comp = cg->comp();6263bool isUnsigned = resolvedMethod->returnTypeIsUnsigned();64switch (resolvedMethod->returnType())65{66case TR::Int8:67if (isUnsigned)68{69op = comp->target().is64Bit() ? TR::InstOpCode::MOVZXReg8Reg1 : TR::InstOpCode::MOVZXReg4Reg1;70}71else72{73op = comp->target().is64Bit() ? TR::InstOpCode::MOVSXReg8Reg1 : TR::InstOpCode::MOVSXReg4Reg1;74}75break;76case TR::Int16:77if (isUnsigned)78{79op = comp->target().is64Bit() ? TR::InstOpCode::MOVZXReg8Reg2 : TR::InstOpCode::MOVZXReg4Reg2;80}81else82{83op = comp->target().is64Bit() ? TR::InstOpCode::MOVSXReg8Reg2 : TR::InstOpCode::MOVSXReg4Reg2;84}85break;86default:87// TR::Address, TR_[US]Int64, TR_[US]Int3288//89op = (linkageReturnReg != targetReg) ? TR::InstOpCode::MOVRegReg() : TR::InstOpCode::bad;90break;91}9293if (op != TR::InstOpCode::bad)94generateRegRegInstruction(op, callNode, targetReg, linkageReturnReg, cg);95}96}9798void J9LinkageUtils::switchToMachineCStack(TR::Node *callNode, TR::CodeGenerator *cg)99{100TR_J9VMBase *fej9 = (TR_J9VMBase *)(cg->fe());101TR::RealRegister *espReal = cg->machine()->getRealRegister(TR::RealRegister::esp);102TR::Register *vmThreadReg = cg->getMethodMetaDataRegister();103104// Squirrel Java SP away into VM thread.105//106generateMemRegInstruction(TR::InstOpCode::SMemReg(),107callNode,108generateX86MemoryReference(vmThreadReg, fej9->thisThreadGetJavaSPOffset(), cg),109espReal,110cg);111112// Load machine SP from VM thread.113//114generateRegMemInstruction(TR::InstOpCode::LRegMem(),115callNode,116espReal,117generateX86MemoryReference(vmThreadReg, fej9->thisThreadGetMachineSPOffset(), cg),118cg);119}120121void J9LinkageUtils::switchToJavaStack(TR::Node *callNode, TR::CodeGenerator *cg)122{123TR_J9VMBase *fej9 = (TR_J9VMBase *)(cg->fe());124TR::RealRegister *espReal = cg->machine()->getRealRegister(TR::RealRegister::esp);125TR::Register *vmThreadReg = cg->getMethodMetaDataRegister();126127// Load up the java sp so we have the callout frame on top of the java stack.128//129generateRegMemInstruction(130TR::InstOpCode::LRegMem(),131callNode,132espReal,133generateX86MemoryReference(vmThreadReg, cg->fej9()->thisThreadGetJavaSPOffset(), cg),134cg);135136// Add DF check on return of JNI/System call137if (cg->canEmitBreakOnDFSet())138generateBreakOnDFSet(cg);139}140141}142143144