Path: blob/master/runtime/compiler/p/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 "p/codegen/ForceRecompilationSnippet.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::PPCForceRecompilationSnippet::emitSnippetBody()45{46uint8_t *buffer = cg()->getBinaryBufferCursor();47TR::SymbolReference *induceRecompilationSymRef = cg()->symRefTab()->findOrCreateRuntimeHelper(TR_PPCinduceRecompilation);48intptr_t startPC = (intptr_t)((uint8_t*)cg()->getCodeStart());4950getSnippetLabel()->setCodeLocation(buffer);5152TR::RegisterDependencyConditions *deps = _doneLabel->getInstruction()->getDependencyConditions();53TR::RealRegister *startPCReg = cg()->machine()->getRealRegister(deps->getPostConditions()->getRegisterDependency(0)->getRealRegister());5455TR::InstOpCode opcode;5657if (cg()->comp()->target().is64Bit())58{59// put jit entry point address in startPCReg60uint32_t hhval, hlval, lhval, llval;61hhval = startPC >> 48 & 0xffff;62hlval = (startPC >>32) & 0xffff;63lhval = (startPC >>16) & 0xffff;64llval = startPC & 0xffff;6566opcode.setOpCodeValue(TR::InstOpCode::lis);67buffer = opcode.copyBinaryToBuffer(buffer);68startPCReg->setRegisterFieldRS((uint32_t *)buffer);69*(uint32_t *)buffer |= hhval;70buffer += PPC_INSTRUCTION_LENGTH;7172opcode.setOpCodeValue(TR::InstOpCode::ori);73buffer = opcode.copyBinaryToBuffer(buffer);74startPCReg->setRegisterFieldRT((uint32_t *)buffer);75startPCReg->setRegisterFieldRA((uint32_t *)buffer);76*(uint32_t *)buffer |= hlval;77buffer += PPC_INSTRUCTION_LENGTH;7879opcode.setOpCodeValue(TR::InstOpCode::rldicr);80buffer = opcode.copyBinaryToBuffer(buffer);81startPCReg->setRegisterFieldRA((uint32_t *)buffer);82startPCReg->setRegisterFieldRS((uint32_t *)buffer);83// SH = 32;84*(uint32_t *)buffer |= ((32 & 0x1f) << 11) | ((32 & 0x20) >> 4);85// ME = 3286*(uint32_t *)buffer |= 0x3e << 5;87buffer += PPC_INSTRUCTION_LENGTH;8889opcode.setOpCodeValue(TR::InstOpCode::oris);90buffer = opcode.copyBinaryToBuffer(buffer);91startPCReg->setRegisterFieldRA((uint32_t *)buffer);92startPCReg->setRegisterFieldRS((uint32_t *)buffer);93*(uint32_t *)buffer |= lhval;94buffer += PPC_INSTRUCTION_LENGTH;9596opcode.setOpCodeValue(TR::InstOpCode::ori);97buffer = opcode.copyBinaryToBuffer(buffer);98startPCReg->setRegisterFieldRA((uint32_t *)buffer);99startPCReg->setRegisterFieldRS((uint32_t *)buffer);100*(uint32_t *)buffer |= llval;101buffer += PPC_INSTRUCTION_LENGTH;102}103else104{105// put jit entry point address in startPCReg106opcode.setOpCodeValue(TR::InstOpCode::lis);107buffer = opcode.copyBinaryToBuffer(buffer);108startPCReg->setRegisterFieldRS((uint32_t *)buffer);109*(uint32_t *)buffer |= (uint32_t) (startPC >> 16 & 0xffff);110buffer += PPC_INSTRUCTION_LENGTH;111112opcode.setOpCodeValue(TR::InstOpCode::ori);113buffer = opcode.copyBinaryToBuffer(buffer);114startPCReg->setRegisterFieldRT((uint32_t *)buffer);115startPCReg->setRegisterFieldRA((uint32_t *)buffer);116*(uint32_t *)buffer |= (uint32_t) (startPC & 0xffff);117buffer += PPC_INSTRUCTION_LENGTH;118}119120intptr_t helperAddress = (intptr_t)induceRecompilationSymRef->getMethodAddress();121if (cg()->directCallRequiresTrampoline(helperAddress, (intptr_t)buffer))122{123helperAddress = TR::CodeCacheManager::instance()->findHelperTrampoline(induceRecompilationSymRef->getReferenceNumber(), (void *)buffer);124TR_ASSERT_FATAL(cg()->comp()->target().cpu.isTargetWithinIFormBranchRange(helperAddress, (intptr_t)buffer),125"Helper address is out of range");126}127128// b distance129*(int32_t *)buffer = 0x48000000 | ((helperAddress - (intptr_t)buffer) & 0x03ffffff);130131cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(buffer,(uint8_t *)induceRecompilationSymRef,TR_HelperAddress, cg()),132__FILE__,133__LINE__,134getNode());135136buffer += PPC_INSTRUCTION_LENGTH;137138return buffer;139}140141void142TR_Debug::print(TR::FILE *pOutFile, TR::PPCForceRecompilationSnippet * snippet)143{144uint8_t *cursor = snippet->getSnippetLabel()->getCodeLocation();145146TR::RegisterDependencyConditions *deps = snippet->getDoneLabel()->getInstruction()->getDependencyConditions();147TR::RealRegister *startPCReg = _cg->machine()->getRealRegister(deps->getPostConditions()->getRegisterDependency(0)->getRealRegister());148149printSnippetLabel(pOutFile, snippet->getSnippetLabel(), cursor, "EDO Recompilation Snippet");150151int32_t value;152153if (_comp->target().is64Bit())154{155printPrefix(pOutFile, NULL, cursor, 4);156value = *((int32_t *) cursor) & 0x0ffff;157trfprintf(pOutFile, "lis \t%s, 0x%p\t; Load jit entry point address", getName(startPCReg),value );158cursor += 4;159160printPrefix(pOutFile, NULL, cursor, 4);161value = *((int32_t *) cursor) & 0x0ffff;162trfprintf(pOutFile, "ori \t%s, %s, 0x%p\t;", getName(startPCReg), getName(startPCReg), value);163cursor += 4;164165printPrefix(pOutFile, NULL, cursor, 4);166trfprintf(pOutFile, "rldicr \t%s, %s, 32, 31\t;", getName(startPCReg), getName(startPCReg));167cursor += 4;168169printPrefix(pOutFile, NULL, cursor, 4);170value = *((int32_t *) cursor) & 0x0ffff;171trfprintf(pOutFile, "oris \t%s, %s, 0x%p\t;", getName(startPCReg),getName(startPCReg), value );172cursor += 4;173174printPrefix(pOutFile, NULL, cursor, 4);175value = *((int32_t *) cursor) & 0x0ffff;176trfprintf(pOutFile, "ori \t%s, %s, 0x%p\t;", getName(startPCReg), getName(startPCReg), value);177cursor += 4;178}179else180{181printPrefix(pOutFile, NULL, cursor, 4);182value = *((int32_t *) cursor) & 0x0ffff;183trfprintf(pOutFile, "lis \t%s, 0x%p\t; Load jit entry point address", getName(startPCReg),value );184cursor += 4;185186printPrefix(pOutFile, NULL, cursor, 4);187value = *((int32_t *) cursor) & 0x0ffff;188trfprintf(pOutFile, "ori \t%s, %s, 0x%p\t;", getName(startPCReg), getName(startPCReg), value);189cursor += 4;190}191192char *info = "";193if (isBranchToTrampoline(_cg->getSymRef(TR_PPCinduceRecompilation), cursor, value))194info = " Through trampoline";195196printPrefix(pOutFile, NULL, cursor, 4);197value = *((int32_t *) cursor) & 0x03fffffc;198value = (value << 6) >> 6; // sign extend199trfprintf(pOutFile, "b \t" POINTER_PRINTF_FORMAT "\t; %s%s", (intptr_t)cursor + value, getName(_cg->getSymRef(TR_PPCinduceRecompilation)), info);200cursor += 4;201}202203uint32_t TR::PPCForceRecompilationSnippet::getLength(int32_t estimatedSnippetStart)204{205return(cg()->comp()->target().is64Bit() ? 6*PPC_INSTRUCTION_LENGTH : 3*PPC_INSTRUCTION_LENGTH);206}207208209