Path: blob/master/runtime/compiler/aarch64/codegen/ARM64JNILinkage.hpp
6004 views
/*******************************************************************************1* Copyright (c) 2019, 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#ifndef ARM64_JNILINKAGE_INCL23#define ARM64_JNILINKAGE_INCL2425#include "codegen/ARM64PrivateLinkage.hpp"26#include "codegen/Register.hpp"2728namespace J929{3031namespace ARM6432{3334class JNILinkage : public PrivateLinkage35{36public:3738JNILinkage(TR::CodeGenerator *cg);3940/**41* @brief Builds method arguments42* @param[in] callNode : caller node43* @param[in] dependencies : register dependency conditions44* @return size of arguments45*/46virtual int32_t buildArgs(47TR::Node *callNode,48TR::RegisterDependencyConditions *dependencies);4950/**51* @brief Builds direct dispatch to method52* @param[in] callNode : caller node53* @return register holding return value54*/55virtual TR::Register *buildDirectDispatch(TR::Node *callNode);5657/**58* @brief Builds indirect dispatch to method59* @param[in] callNode : caller node60* @return register holding return value61*/62virtual TR::Register *buildIndirectDispatch(TR::Node *callNode);6364/**65* @brief Builds virtual dispatch to method66* @param[in] callNode : caller node67* @param[in] dependencies : register dependency conditions68* @param[in] argSize : size of arguments69*/70virtual void buildVirtualDispatch(71TR::Node *callNode,72TR::RegisterDependencyConditions *dependencies,73uint32_t argSize);7475private:7677/**78* @brief Releases VM access before calling into JNI method79* @param[in] callNode : caller node80* @param[in] vmThreadReg : vm thread register81* @param[in] scratchReg0 : scratch register82* @param[in] scratchReg1 : scratch register83* @param[in] scratchReg2 : scratch register84* @param[in] scratchReg3 : scratch register85*/86void releaseVMAccess(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *scratchReg1, TR::Register *scratchReg2, TR::Register *scratchReg3);8788/**89* @brief Acquires VM access after returned from JNI method90* @param[in] callNode : caller node91* @param[in] vmThreadReg : vm thread register92* @param[in] scratchReg0 : scratch register93* @param[in] scratchReg1 : scratch register94* @param[in] scratchReg2 : scratch register95*/96void acquireVMAccess(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *scratchReg1, TR::Register *scratchReg2);9798#ifdef J9VM_INTERP_ATOMIC_FREE_JNI99/**100* @brief Releases VM access in a way described in OpenJ9 issue 2576101* @param[in] callNode : caller Node102* @param[in] vmThreadReg : vm thread register103* @param[in] scratchReg0 : scratch register104* @param[in] scratchReg1 : scratch register105*/106void releaseVMAccessAtomicFree(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *scratchReg1);107108/**109* @brief Acquires VM access in a way described in OpenJ9 issue 2576110* @param[in] callNode : caller Node111* @param[in] vmThreadReg : vm thread register112* @param[in] scratchReg0 : scratch register113* @param[in] zeroReg : zero register */114void acquireVMAccessAtomicFree(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *zeroReg);115#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */116117/**118* @brief Builds JNI call out frame119* @param[in] callNode : caller node120* @param[in] isWrapperForJNI : true if the current method is simply a wrapper for the JNI call121* @param[in] returnAddrLabel : label symbol of return address from JNI method122* @param[in] vmThreadReg : vm thread register123* @param[in] javaStackReg : java stack register124* @param[in] scratchReg0 : scratch register125* @param[in] scratchReg1 : scratch register126*/127void buildJNICallOutFrame(TR::Node *callNode, bool isWrapperForJNI,128TR::LabelSymbol *returnAddrLabel, TR::Register *vmThreadReg,129TR::Register *javaStackReg, TR::Register *scratchReg0, TR::Register *scratchReg1);130131/**132* @brief Restores JNI call out frame133* @param[in] callNode : caller node134* @param[in] tearDownJNIFrame : true if we need to clean up ref pool135* @param[in] vmThreadReg : vm thread register136* @param[in] javaStackReg : java stack register137* @param[in] scratchReg : scratch register138*/139void restoreJNICallOutFrame(TR::Node *callNode, bool tearDownJNIFrame, TR::Register *vmThreadReg, TR::Register *javaStackReg, TR::Register *scratchReg);140141/**142* @brief Builds JNI method arguments143* @param[in] callNode : caller node144* @param[in] deps : register dependency conditions145* @param[in] passThread : true if we need to pass vm thread as first parameter146* @param[in] passReceiver : true if we need to pass receiver to the JNI method147* @param[in] killNonVolatileGPRs : true if we need to kill non-volatile GPRs148* @return the total size in bytes allocated on stack for parameter passing149*/150size_t buildJNIArgs(TR::Node *callNode, TR::RegisterDependencyConditions *deps, bool passThread, bool passReceiver, bool killNonVolatileGPRs);151152/**153* @brief Returns register holding resturn value154* @param[in] callNode : caller node155* @param[in] deps : register dependency conditions156* @return register holding return value. Null if return type is void.157*/158TR::Register *getReturnRegisterFromDeps(TR::Node *callNode, TR::RegisterDependencyConditions *deps);159160/**161* @brief Pushes a JNI reference argument162* @param[in] child : argument node163* @return register holding argument164*/165TR::Register *pushJNIReferenceArg(TR::Node *child);166167/**168* @brief Generates a JNI method dispatch instructions169* @param[in] callNode : caller node170* @param[in] isJNIGCPoint : true if the JNI method dispatch is GC point171* @param[in] deps : register dependency conditions172* @param[in] targetAddress : address of JNI method173* @param[in] scratchReg : scratch register174* @return instruction of method dispatch175*/176TR::Instruction *generateMethodDispatch(TR::Node *callNode, bool isJNIGCPoint, TR::RegisterDependencyConditions *deps, uintptr_t targetAddress, TR::Register *scratchReg);177178/**179* @brief Adjusts return value to java semantics180* @param[in] callNode : caller node181* @param[in] wrapRefs : true if the reference is wrapped182* @param[in] returnRegister : register that holds return value183*/184void adjustReturnValue(TR::Node *callNode, bool wrapRefs, TR::Register *returnRegister);185186/**187* @brief Throws exception if it is set in JNI method188* @param[in] callNode : caller node189* @param[in] vmThreadReg : vm thread register190* @param[in] scratchReg : scratch register191*/192void checkForJNIExceptions(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg);193194TR::Linkage *_systemLinkage;195196197198};199200}201202}203204#endif205206207