Path: blob/master/runtime/compiler/x/codegen/CallSnippet.hpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2022 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 X86CALLSNIPPET_INCL23#define X86CALLSNIPPET_INCL2425#include "codegen/Snippet.hpp"26#include "codegen/UnresolvedDataSnippet.hpp"2728namespace TR { class CodeGenerator; }29namespace TR { class Instruction; }30namespace TR { class LabelSymbol; }31namespace TR { class MethodSymbol; }32namespace TR { class SymbolReference; }3334namespace TR {3536class X86PicDataSnippet : public TR::Snippet37{38TR::SymbolReference *_methodSymRef;39TR::SymbolReference *_dispatchSymRef;40TR::Instruction *_slotPatchInstruction;41TR::Instruction *_startOfPicInstruction;42TR::LabelSymbol *_doneLabel;43uint8_t *_thunkAddress;44int32_t _numberOfSlots;45bool _isInterface;46bool _hasJ2IThunkInPicData;4748public:4950X86PicDataSnippet(51int32_t numberOfSlots,52TR::Instruction *startOfPicInstruction,53TR::LabelSymbol *snippetLabel,54TR::LabelSymbol *doneLabel,55TR::SymbolReference *methodSymRef,56TR::Instruction *slotPatchInstruction,57uint8_t *thunkAddress,58bool isInterface,59TR::CodeGenerator *cg) :60TR::Snippet(cg, NULL, snippetLabel, true),61_numberOfSlots(numberOfSlots),62_startOfPicInstruction(startOfPicInstruction),63_methodSymRef(methodSymRef),64_doneLabel(doneLabel),65_slotPatchInstruction(slotPatchInstruction),66_isInterface(isInterface),67_dispatchSymRef(NULL),68_thunkAddress(thunkAddress),69_hasJ2IThunkInPicData(shouldEmitJ2IThunkPointer())70{}7172bool isInterface() {return _isInterface;}73int32_t getNumberOfSlots() {return _numberOfSlots;}74bool hasJ2IThunkInPicData() {return _hasJ2IThunkInPicData;}7576TR::SymbolReference *getDispatchSymRef() {return _dispatchSymRef;}77TR::SymbolReference *getMethodSymRef() {return _methodSymRef;}7879TR::LabelSymbol *getDoneLabel() {return _doneLabel;}8081bool forceUnresolvedDispatch()82{83// No need to force unresolved dispatch for interface calls, since those84// are unresolved anyway.85return !isInterface()86&& !((TR_J9VMBase*)(cg()->fe()))->isResolvedVirtualDispatchGuaranteed(cg()->comp());87}8889bool unresolvedDispatch()90{91return _methodSymRef->isUnresolved() || forceUnresolvedDispatch();92}9394uint8_t *encodeConstantPoolInfo(uint8_t *cursor);95uint8_t *encodeJ2IThunkPointer(uint8_t *cursor);9697virtual Kind getKind() { return (_isInterface ? IsIPicData : IsVPicData); }9899virtual uint8_t *emitSnippetBody();100101virtual uint32_t getLength(int32_t estimatedSnippetStart);102103private:104bool shouldEmitJ2IThunkPointer();105};106107class X86CallSnippet : public TR::Snippet108{109public:110111X86CallSnippet(TR::CodeGenerator *cg, TR::Node * n, TR::LabelSymbol * lab, bool isGCSafePoint)112: TR::Snippet(cg, n, lab, isGCSafePoint)113{114_realMethodSymbolReference = NULL;115}116117X86CallSnippet(TR::CodeGenerator *cg, TR::Node * n, TR::LabelSymbol * lab, TR::SymbolReference* realSymRef, bool isGCSafePoint)118: TR::Snippet(cg, n, lab, isGCSafePoint)119{120_realMethodSymbolReference = realSymRef;121}122123virtual Kind getKind() { return IsCall; }124125virtual uint8_t *emitSnippetBody();126127virtual uint32_t getLength(int32_t estimatedSnippetStart);128129TR::SymbolReference *getRealMethodSymbolReference() { return _realMethodSymbolReference; }130131private:132133uint8_t * alignCursorForCodePatching(uint8_t *cursor, bool alignWithNOPs=false);134135TR::SymbolReference * _realMethodSymbolReference;136};137138}139140#endif141142143