Path: blob/master/runtime/compiler/aarch64/codegen/J9AheadOfTimeCompile.cpp
6004 views
/*******************************************************************************1* Copyright (c) 2019, 2022 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 "codegen/CodeGenerator.hpp"24#include "il/Node_inlines.hpp"25#include "il/StaticSymbol.hpp"26#include "runtime/RelocationRuntime.hpp"27#include "runtime/RelocationRecord.hpp"2829J9::ARM64::AheadOfTimeCompile::AheadOfTimeCompile(TR::CodeGenerator *cg) :30J9::AheadOfTimeCompile(NULL, cg->comp()),31_cg(cg)32{33}3435void J9::ARM64::AheadOfTimeCompile::processRelocations()36{37TR::Compilation *comp = self()->comp();38TR_J9VMBase *fej9 = (TR_J9VMBase *)(_cg->fe());39TR::IteratedExternalRelocation *r;4041for (auto aotIterator = _cg->getExternalRelocationList().begin(); aotIterator != _cg->getExternalRelocationList().end(); ++aotIterator)42{43(*aotIterator)->addExternalRelocation(_cg);44}4546for (r = getAOTRelocationTargets().getFirst(); r != NULL; r = r->getNext())47{48addToSizeOfAOTRelocations(r->getSizeOfRelocationData());49}5051// now allocate the memory size of all iterated relocations + the header (total length field)5253// Note that when using the SymbolValidationManager, the well-known classes54// must be checked even if no explicit records were generated, since they55// might be responsible for the lack of records.56bool useSVM = comp->getOption(TR_UseSymbolValidationManager);5758if (self()->getSizeOfAOTRelocations() != 0 || useSVM)59{60// It would be more straightforward to put the well-known classes offset61// in the AOT method header, but that would use space for AOT bodies that62// don't use the SVM.63int wellKnownClassesOffsetSize = useSVM ? SIZEPOINTER : 0;64uintptr_t reloBufferSize =65self()->getSizeOfAOTRelocations() + SIZEPOINTER + wellKnownClassesOffsetSize;66uint8_t *relocationDataCursor =67self()->setRelocationData(fej9->allocateRelocationData(comp, reloBufferSize));6869// set up the size for the region70*(uintptr_t *)relocationDataCursor = reloBufferSize;71relocationDataCursor += SIZEPOINTER;7273if (useSVM)74{75TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();76void *offsets = const_cast<void *>(svm->wellKnownClassChainOffsets());77uintptr_t *wkcOffsetAddr = (uintptr_t *)relocationDataCursor;78*wkcOffsetAddr = self()->offsetInSharedCacheFromPointer(fej9->sharedCache(), offsets);79#if defined(J9VM_OPT_JITSERVER)80self()->addWellKnownClassesSerializationRecord(svm->aotCacheWellKnownClassesRecord(), wkcOffsetAddr);81#endif /* defined(J9VM_OPT_JITSERVER) */82relocationDataCursor += SIZEPOINTER;83}8485// set up pointers for each iterated relocation and initialize header86TR::IteratedExternalRelocation *s;87for (s = getAOTRelocationTargets().getFirst(); s != NULL; s = s->getNext())88{89s->setRelocationData(relocationDataCursor);90s->initializeRelocation(_cg);91relocationDataCursor += s->getSizeOfRelocationData();92}93}94}9596bool97J9::ARM64::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,98TR_RelocationTarget *reloTarget,99TR_RelocationRecord *reloRecord,100uint8_t targetKind)101{102bool platformSpecificReloInitialized = true;103104switch (targetKind)105{106case TR_DiscontiguousSymbolFromManager:107{108TR_RelocationRecordDiscontiguousSymbolFromManager *dsfmRecord = reinterpret_cast<TR_RelocationRecordDiscontiguousSymbolFromManager *>(reloRecord);109110uint8_t *symbol = (uint8_t *)relocation->getTargetAddress();111uint16_t symbolID = self()->comp()->getSymbolValidationManager()->getSymbolIDFromValue(static_cast<void *>(symbol));112113uint16_t symbolType = (uint16_t)(uintptr_t)relocation->getTargetAddress2();114115dsfmRecord->setSymbolID(reloTarget, symbolID);116dsfmRecord->setSymbolType(reloTarget, static_cast<TR::SymbolType>(symbolType));117}118break;119120case TR_HCR:121{122TR_RelocationRecordHCR *hcrRecord = reinterpret_cast<TR_RelocationRecordHCR *>(reloRecord);123124uintptr_t gv = reinterpret_cast<uintptr_t>(relocation->getTargetAddress());125uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));126127TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");128hcrRecord->setReloFlags(reloTarget, flags);129hcrRecord->setOffset(reloTarget, gv);130}131break;132133default:134platformSpecificReloInitialized = false;135}136137return platformSpecificReloInitialized;138}139140141142