Path: blob/master/runtime/compiler/x/codegen/RecompilationSnippet.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/RecompilationSnippet.hpp"2324#include "codegen/CodeGenerator.hpp"25#include "codegen/Instruction.hpp"26#include "codegen/Relocation.hpp"27#include "control/Recompilation.hpp"28#include "control/RecompilationInfo.hpp"29#include "env/CompilerEnv.hpp"30#include "env/IO.hpp"31#include "env/jittypes.h"32#include "env/VMJ9.h"33#include "il/LabelSymbol.hpp"34#include "il/MethodSymbol.hpp"35#include "il/Node.hpp"36#include "il/Node_inlines.hpp"37#include "il/RegisterMappedSymbol.hpp"38#include "il/ResolvedMethodSymbol.hpp"39#include "il/StaticSymbol.hpp"40#include "il/Symbol.hpp"41#include "runtime/CodeCacheManager.hpp"4243TR::X86RecompilationSnippet::X86RecompilationSnippet(TR::LabelSymbol *lab,44TR::Node *node,45TR::CodeGenerator *cg)46: TR::Snippet(cg, node, lab, true)47{48setDestination(cg->symRefTab()->findOrCreateRuntimeHelper(cg->comp()->target().is64Bit()? TR_AMD64countingRecompileMethod : TR_IA32countingRecompileMethod));49}5051uint32_t TR::X86RecompilationSnippet::getLength(int32_t estimatedSnippetStart)52{5354return 9;55}56void57TR_Debug::print(TR::FILE *pOutFile, TR::X86RecompilationSnippet * snippet)58{59if (pOutFile == NULL)60return;6162TR::MethodSymbol *recompileSym = snippet->getDestination()->getSymbol()->castToMethodSymbol();6364uint8_t *bufferPos = snippet->getSnippetLabel()->getCodeLocation();6566printSnippetLabel(pOutFile, snippet->getSnippetLabel(), bufferPos, getName(snippet), getName(snippet->getDestination()));6768printPrefix(pOutFile, NULL, bufferPos, 5);69trfprintf(pOutFile, "call\t%s \t\t%s Helper Address = " POINTER_PRINTF_FORMAT,70getName(snippet->getDestination()),71commentString(),72recompileSym->getMethodAddress());73bufferPos += 5;7475printPrefix(pOutFile, NULL, bufferPos, 4);76trfprintf(pOutFile, "%s \t%s%08x%s\t\t%s Offset to startPC",77ddString(),78hexPrefixString(),79_cg->getCodeStart() - bufferPos,80hexSuffixString(),81commentString());82bufferPos += 4;83}84858687uint8_t *TR::X86RecompilationSnippet::emitSnippetBody()88{8990uint8_t *buffer = cg()->getBinaryBufferCursor();91getSnippetLabel()->setCodeLocation(buffer);9293intptr_t helperAddress = (intptr_t)_destination->getMethodAddress();94*buffer++ = 0xe8; // CallImm495if (NEEDS_TRAMPOLINE(helperAddress, buffer+4, cg()))96{97helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(_destination->getReferenceNumber(), (void *)buffer);98TR_ASSERT(IS_32BIT_RIP(helperAddress, buffer+4), "Local helper trampoline should be reachable directly.\n");99}100*(int32_t *)buffer = ((uint8_t*)helperAddress - buffer) - 4;101cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(buffer,102(uint8_t *)_destination,103TR_HelperAddress, cg()),104__FILE__, __LINE__, getNode());105buffer += 4;106107uint8_t *bufferBase = buffer;108109// Offset to the start of the method. This is the instruction that must be110// patched when the new code is built.111//112*(uint32_t *)buffer = (uint32_t)(cg()->getCodeStart() - bufferBase);113buffer += 4;114115return buffer;116}117118119120