Path: blob/master/runtime/compiler/x/codegen/ForceRecompilationSnippet.cpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2020 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 "x/codegen/ForceRecompilationSnippet.hpp"2324#include "codegen/Relocation.hpp"25#include "env/CompilerEnv.hpp"26#include "env/IO.hpp"27#include "env/OMRMemory.hpp"28#include "env/jittypes.h"29#include "env/VMJ9.h"30#include "il/LabelSymbol.hpp"31#include "il/MethodSymbol.hpp"32#include "il/Node.hpp"33#include "il/Node_inlines.hpp"34#include "il/RegisterMappedSymbol.hpp"35#include "il/ResolvedMethodSymbol.hpp"36#include "il/StaticSymbol.hpp"37#include "il/Symbol.hpp"38#include "runtime/CodeCacheManager.hpp"39#include "x/codegen/X86Recompilation.hpp"4041// TODO: Combine this with TR::X86RecompilationSnippet42// TODO: This class should be named TR::X86InduceRecompilationSnippet4344uint8_t *TR::X86ForceRecompilationSnippet::emitSnippetBody()45{46TR_J9VMBase *fej9 = (TR_J9VMBase *)(cg()->fe());47uint8_t *buffer = cg()->getBinaryBufferCursor();48getSnippetLabel()->setCodeLocation(buffer);4950TR::SymbolReference *helper = cg()->symRefTab()->findOrCreateRuntimeHelper(cg()->comp()->target().is64Bit()? TR_AMD64induceRecompilation : TR_IA32induceRecompilation);51intptr_t helperAddress = (intptr_t)helper->getMethodAddress();52*buffer++ = 0xe8; // CallImm453if (NEEDS_TRAMPOLINE(helperAddress, buffer+4, cg()))54{55helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(helper->getReferenceNumber(), (void *)buffer);56TR_ASSERT(IS_32BIT_RIP(helperAddress, buffer+4), "Local helper trampoline should be reachable directly.\n");57}58*(int32_t *)buffer = ((uint8_t*)helperAddress - buffer) - 4;5960cg()->addExternalRelocation(new (cg()->trHeapMemory())61TR::ExternalRelocation(62buffer,63(uint8_t *)helper,64TR_HelperAddress, cg()),65__FILE__, __LINE__, getNode());6667buffer += 4;6869uint8_t *bufferBase = buffer;7071buffer = genRestartJump(buffer);7273// Offset to the startPC. We don't store the startPC itself, because on74// AMD64 that would require 4 more bytes.75//76*(uint32_t *)buffer = (uint32_t)(cg()->getCodeStart() - bufferBase);77buffer += 4;7879return buffer;80}818283void84TR_Debug::print(TR::FILE *pOutFile, TR::X86ForceRecompilationSnippet * snippet)85{86if (pOutFile == NULL)87return;8889uint8_t *bufferPos = snippet->getSnippetLabel()->getCodeLocation();90printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, getName(snippet));9192TR::SymbolReference *helper = _cg->getSymRef(_comp->target().is64Bit()? TR_AMD64induceRecompilation : TR_IA32induceRecompilation);93intptr_t helperAddress = (intptr_t)helper->getMethodAddress();94printPrefix(pOutFile, NULL, bufferPos, 5);95trfprintf(pOutFile, "call\t%s \t%s Helper Address = " POINTER_PRINTF_FORMAT,96getName(helper),97commentString(),98helperAddress);99bufferPos += 5;100101uint8_t *offsetBase = bufferPos;102103printPrefix(pOutFile, NULL, bufferPos, 5);104printLabelInstruction(pOutFile, "jmp", snippet->getRestartLabel());105bufferPos += 5;106107printPrefix(pOutFile, NULL, bufferPos, 4);108trfprintf(pOutFile, "%s \t%s%08x%s\t\t%s Offset to startPC",109ddString(),110hexPrefixString(),111_cg->getCodeStart() - offsetBase,112hexSuffixString(),113commentString());114bufferPos += 4;115}116117118uint32_t TR::X86ForceRecompilationSnippet::getLength(int32_t estimatedSnippetStart)119{120return 14;121}122123124