Path: blob/master/runtime/compiler/x/codegen/J9AheadOfTimeCompile.cpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2021 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 "codegen/AheadOfTimeCompile.hpp"23#include "env/FrontEnd.hpp"24#include "codegen/Instruction.hpp"25#include "compile/AOTClassInfo.hpp"26#include "compile/Compilation.hpp"27#include "compile/ResolvedMethod.hpp"28#include "compile/VirtualGuard.hpp"29#include "env/CHTable.hpp"30#include "env/ClassLoaderTable.hpp"31#include "env/CompilerEnv.hpp"32#include "env/SharedCache.hpp"33#include "env/jittypes.h"34#include "env/VMJ9.h"35#include "il/Node.hpp"36#include "il/Node_inlines.hpp"37#include "il/SymbolReference.hpp"38#include "ras/DebugCounter.hpp"39#include "runtime/CodeCacheConfig.hpp"40#include "runtime/CodeCacheManager.hpp"41#include "runtime/RelocationRuntime.hpp"42#include "runtime/RelocationRecord.hpp"43#include "runtime/SymbolValidationManager.hpp"4445#define NON_HELPER 0x004647void J9::X86::AheadOfTimeCompile::processRelocations()48{49TR::Compilation *comp = _cg->comp();5051// calculate the amount of memory needed to hold the relocation data52TR_J9VMBase *fej9 = (TR_J9VMBase *)(_cg->fe());5354if (comp->target().is64Bit()55&& TR::CodeCacheManager::instance()->codeCacheConfig().needsMethodTrampolines()56&& _cg->getPicSlotCount())57{58_cg->addExternalRelocation(new (_cg->trHeapMemory()) TR::ExternalRelocation(NULL,59(uint8_t *)(uintptr_t)_cg->getPicSlotCount(),60TR_PicTrampolines, _cg),61__FILE__,62__LINE__,63NULL);64}656667for (auto aotIterator = _cg->getExternalRelocationList().begin(); aotIterator != _cg->getExternalRelocationList().end(); ++aotIterator)68(*aotIterator)->addExternalRelocation(_cg);6970TR::IteratedExternalRelocation *r;71for (r = self()->getAOTRelocationTargets().getFirst();72r != NULL;73r = r->getNext())74{75self()->addToSizeOfAOTRelocations(r->getSizeOfRelocationData());76}7778// now allocate the memory size of all iterated relocations + the header (total length field)7980// Note that when using the SymbolValidationManager, the well-known classes81// must be checked even if no explicit records were generated, since they82// might be responsible for the lack of records.83bool useSVM = comp->getOption(TR_UseSymbolValidationManager);84if (self()->getSizeOfAOTRelocations() != 0 || useSVM)85{86// It would be more straightforward to put the well-known classes offset87// in the AOT method header, but that would use space for AOT bodies that88// don't use the SVM. TODO: Move it once SVM takes over?89int wellKnownClassesOffsetSize = useSVM ? SIZEPOINTER : 0;90uintptr_t reloBufferSize =91self()->getSizeOfAOTRelocations() + SIZEPOINTER + wellKnownClassesOffsetSize;92uint8_t *relocationDataCursor = self()->setRelocationData(93fej9->allocateRelocationData(comp, reloBufferSize));94// set up the size for the region95*(uintptr_t *)relocationDataCursor = reloBufferSize;96relocationDataCursor += SIZEPOINTER;9798if (useSVM)99{100TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();101void *offsets = const_cast<void *>(svm->wellKnownClassChainOffsets());102uintptr_t *wkcOffsetAddr = (uintptr_t *)relocationDataCursor;103*wkcOffsetAddr = self()->offsetInSharedCacheFromPointer(fej9->sharedCache(), offsets);104#if defined(J9VM_OPT_JITSERVER)105self()->addWellKnownClassesSerializationRecord(svm->aotCacheWellKnownClassesRecord(), wkcOffsetAddr);106#endif /* defined(J9VM_OPT_JITSERVER) */107relocationDataCursor += SIZEPOINTER;108}109110// set up pointers for each iterated relocation and initialize header111TR::IteratedExternalRelocation *s;112for (s = self()->getAOTRelocationTargets().getFirst();113s != 0;114s = s->getNext())115{116s->setRelocationData(relocationDataCursor);117s->initializeRelocation(_cg);118relocationDataCursor += s->getSizeOfRelocationData();119}120}121}122123bool124J9::X86::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,125TR_RelocationTarget *reloTarget,126TR_RelocationRecord *reloRecord,127uint8_t targetKind)128{129bool platformSpecificReloInitialized = true;130131switch (targetKind)132{133case TR_PicTrampolines:134{135TR_RelocationRecordPicTrampolines *ptRecord = reinterpret_cast<TR_RelocationRecordPicTrampolines *>(reloRecord);136137TR_ASSERT(self()->comp()->target().is64Bit(), "TR_PicTrampolines not supported on 32-bit");138uint32_t numTrampolines = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress()));139ptRecord->setNumTrampolines(reloTarget, numTrampolines);140}141break;142143default:144platformSpecificReloInitialized = false;145}146147return platformSpecificReloInitialized;148}149150151152