Path: blob/master/runtime/compiler/x/codegen/X86Recompilation.hpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2019 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 X86RECOMPILATION_INCL23#define X86RECOMPILATION_INCL2425#include "control/Recompilation.hpp"26#include "control/RecompilationInfo.hpp"27namespace TR { class CodeGenerator; }28class TR_ResolvedMethod;2930// ***************************************************************************31//32// Recompilation Support Runtime methods33//34// Methods headers look different based on the type of compilation: there are35// inherent differences between sampling and counting compilations and yet36// again between counting with profiling and counting without preexistence headers.37//38// The linkage info field contains information about what kind of compilation39// produced this method.40//41// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING42// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING43//44// When changing the prologue or preprologue shape/size, all recompilation-related45// code must be revisited to make sure it is kept consistent.46//47// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING48// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING4950//51// Sampling Compilation52// ====================53//54// If preexistence was not performed on this method, the following is what the55// prologue looks like:56//57// -16 db[3] padding 3 bytes58// -13 call _samplingRecompileMethod <-- immediate field aligned on 4-byte bndry59// -8 dd address of persistent jitted body info60// -4 dd method linkage info and flags61// 0 ?? first instruction of the method (must be atleast 2 bytes)62//63// With preexistence the prologue looks like the following64//65// -24 db padding 1 byte66// -23 mov edi, j9method67// -18 call interpretedCallGlue68// -13 call _samplingRecompileMethod <-- immediate field aligned on 4 byte bndry69// -8 dd address of persistent jitted body info70// -4 dd method linkage info and flags71// 0 ?? first instruction of the method (must be atleast 2 bytes)72//73// The first instruction of the method can be either of the following types74// push ebx (deprecated) used when using ebx as dedicated bp75// (this instruction is forced to be 2 bytes)76// (there is a debug flag in ia32Code that enabled this)77// sub esp, byte default when the stack frame is small78// sub esp, dword default when the stack frame is large79//80// To recompile, the first instruction of the method is overwritten to be a81// jump to the call instruction at (startPC-13).82//83// It is not possible to have a sampling body without recompilation.84//85// Counting Recompilation86// ======================87// The method header looks like the following:88// Without Preexistence89// -8 dd address of persistent jitted body info90// -4 dd method linkage info flags91// startPC + 0 ?? first instruction of the method92//93// With Preexistence94// -20 dw padding 2 bytes95// -18 mov edi, j9method96// -13 call interpreterCallGlue97// -8 dd address of persistent jitted body info98// -4 dd method linkage info flags99// startPC + 0 ?? first instruction of the method100//101// The prologue of the method looks like the following:102// When Profiling103// cmp [recompilationCounter], 0104// jl LrecompSnippet105// Otherwise106// sub [recompilationCounter], 1107// jl LrecompSnippet108//109// recompilationCounter is the first field of persistent jitted body info, so the110// address contained in this instruction and at startPC - 8 is the same.111// (Duplication to minimize the thread safety issues that come up when112// patching the first instruction)113//114// ***************************************************************************115116// We define offsets relative to startPC (ie. the interpreter entry point)117// because that way they are constant.118//119#if defined(TR_TARGET_64BIT)120121# define START_PC_TO_ITR_GLUE_SAMPLING (-21)122# define START_PC_TO_ORIGINAL_ENTRY_BYTES (-19)123# define START_PC_TO_RECOMPILE_SAMPLING (-17)124# define START_PC_TO_ITR_GLUE_COUNTING (-16)125# define START_PC_TO_METHOD_INFO_ADDRESS (-12)126127# define COUNTING_PROLOGUE_SIZE (19)128129# define COUNTING_RECOMPILE_METHOD TR_AMD64countingRecompileMethod130# define SAMPLING_RECOMPILE_METHOD TR_AMD64samplingRecompileMethod131# define COUNTING_PATCH_CALL_SITE TR_AMD64countingPatchCallSite132# define SAMPLING_PATCH_CALL_SITE TR_AMD64samplingPatchCallSite133134#else135136# define START_PC_TO_ITR_GLUE_SAMPLING (-23)137# define START_PC_TO_ITR_GLUE_COUNTING (-18)138# define START_PC_TO_RECOMPILE_SAMPLING (-13)139# define START_PC_TO_METHOD_INFO_ADDRESS (-8)140# define START_PC_TO_ORIGINAL_ENTRY_BYTES (-2)141142# define COUNTING_PROLOGUE_SIZE (13)143144# define COUNTING_RECOMPILE_METHOD TR_IA32countingRecompileMethod145# define SAMPLING_RECOMPILE_METHOD TR_IA32samplingRecompileMethod146# define COUNTING_PATCH_CALL_SITE TR_IA32countingPatchCallSite147# define SAMPLING_PATCH_CALL_SITE TR_IA32samplingPatchCallSite148149#endif150151#define CALL_INSTRUCTION 0xE8152#define TWO_BYTE_JUMP_INSTRUCTION 0xEB153#define SPIN_LOOP_INSTRUCTION 0xFEEB154155156class TR_X86Recompilation : public TR::Recompilation157{158public:159160TR_X86Recompilation(TR::Compilation *);161162static TR::Recompilation * allocate(TR::Compilation *);163164virtual TR_PersistentMethodInfo *getExistingMethodInfo(TR_ResolvedMethod *method);165virtual TR::Instruction *generatePrePrologue();166virtual TR::Instruction *generatePrologue(TR::Instruction *);167virtual void postCompilation();168169TR::CodeGenerator *cg() { return _compilation->cg(); }170171private:172void setMethodReturnInfoBits();173};174175#endif176177178