Path: blob/master/runtime/compiler/p/codegen/PPCRecompilationSnippet.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 "p/codegen/PPCRecompilationSnippet.hpp"2324#include <stdint.h>25#include "codegen/CodeGenerator.hpp"26#include "codegen/Machine.hpp"27#include "codegen/Relocation.hpp"28#include "env/CompilerEnv.hpp"29#include "env/IO.hpp"30#include "env/jittypes.h"31#include "env/VMJ9.h"32#include "il/LabelSymbol.hpp"33#include "il/MethodSymbol.hpp"34#include "il/Node.hpp"35#include "il/Node_inlines.hpp"36#include "il/RegisterMappedSymbol.hpp"37#include "il/ResolvedMethodSymbol.hpp"38#include "il/StaticSymbol.hpp"39#include "il/Symbol.hpp"40#include "p/codegen/PPCInstruction.hpp"41#include "p/codegen/PPCRecompilation.hpp"42#include "runtime/CodeCacheManager.hpp"4344uint8_t *TR::PPCRecompilationSnippet::emitSnippetBody()45{46uint8_t *buffer = cg()->getBinaryBufferCursor();47TR::Compilation *comp = cg()->comp();48TR::SymbolReference *countingRecompMethodSymRef = cg()->symRefTab()->findOrCreateRuntimeHelper(TR_PPCcountingRecompileMethod);49bool longPrologue = getBranchToSnippet()->getFarRelocation();5051getSnippetLabel()->setCodeLocation(buffer);5253intptr_t helperAddress = (intptr_t)countingRecompMethodSymRef->getMethodAddress();54if (cg()->directCallRequiresTrampoline(helperAddress, (intptr_t)buffer))55{56helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(countingRecompMethodSymRef->getReferenceNumber(), (void *)buffer);57TR_ASSERT_FATAL(comp->target().cpu.isTargetWithinIFormBranchRange(helperAddress, (intptr_t)buffer), "Helper address is out of range");58}5960// bl distance61*(int32_t *)buffer = 0x48000001 | ((helperAddress - (intptr_t)buffer) & 0x03ffffff);62cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(buffer,(uint8_t *)countingRecompMethodSymRef,TR_HelperAddress, cg()),63__FILE__,64__LINE__,65getNode());6667buffer += 4;6869// bodyinfo70uintptr_t valueBits = (uintptr_t)comp->getRecompilationInfo()->getJittedBodyInfo();71*(uintptr_t *)buffer = valueBits;7273buffer += sizeof(uintptr_t);7475// startPC76valueBits = (uintptr_t)cg()->getCodeStart() | (longPrologue?1:0);77*(uintptr_t *)buffer = valueBits;7879return buffer + sizeof(uintptr_t);80}818283void84TR_Debug::print(TR::FILE *pOutFile, TR::PPCRecompilationSnippet * snippet)85{86uint8_t *cursor = snippet->getSnippetLabel()->getCodeLocation();8788printSnippetLabel(pOutFile, snippet->getSnippetLabel(), cursor, "Counting Recompilation Snippet");8990char *info = "";91int32_t distance;92if (isBranchToTrampoline(_cg->getSymRef(TR_PPCcountingRecompileMethod), cursor, distance))93info = " Through trampoline";9495printPrefix(pOutFile, NULL, cursor, 4);96distance = *((int32_t *) cursor) & 0x03fffffc;97distance = (distance << 6) >> 6; // sign extend98trfprintf(pOutFile, "bl \t" POINTER_PRINTF_FORMAT "\t\t;%s", (intptr_t)cursor + distance, info);99cursor += 4;100101// methodInfo102printPrefix(pOutFile, NULL, cursor, 4);103trfprintf(pOutFile, ".long \t0x%08x\t\t;%s", _comp->getRecompilationInfo()->getMethodInfo(), "methodInfo");104cursor += 4;105106// startPC107printPrefix(pOutFile, NULL, cursor, 4);108trfprintf(pOutFile, ".long \t0x%08x\t\t; startPC | longPrologue", _cg->getCodeStart());109}110111112uint32_t TR::PPCRecompilationSnippet::getLength(int32_t estimatedSnippetStart)113{114return(cg()->comp()->target().is64Bit()? 20 : 12);115}116117118