Path: blob/master/runtime/compiler/arm/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 "codegen/ARMAOTRelocation.hpp"24#include "compile/SymbolReferenceTable.hpp"25#include "codegen/CodeGenerator.hpp"26#include "env/FrontEnd.hpp"27#include "codegen/Instruction.hpp"28#include "compile/AOTClassInfo.hpp"29#include "compile/Compilation.hpp"30#include "compile/ResolvedMethod.hpp"31#include "compile/VirtualGuard.hpp"32#include "env/CHTable.hpp"33#include "env/ClassLoaderTable.hpp"34#include "env/SharedCache.hpp"35#include "env/jittypes.h"36#include "env/VMJ9.h"37#include "il/LabelSymbol.hpp"38#include "il/Node.hpp"39#include "il/Node_inlines.hpp"40#include "il/StaticSymbol.hpp"41#include "il/SymbolReference.hpp"42#include "runtime/RelocationRuntime.hpp"43#include "runtime/RelocationRecord.hpp"4445#define NON_HELPER 04647J9::ARM::AheadOfTimeCompile::AheadOfTimeCompile(TR::CodeGenerator *cg)48: J9::AheadOfTimeCompile(NULL, cg->comp()),49_cg(cg),50_relocationList(self()->trMemory())51{52}5354void J9::ARM::AheadOfTimeCompile::processRelocations()55{56TR_J9VMBase *fej9 = (TR_J9VMBase *)(self()->cg()->fe());57ListIterator<TR::ARMRelocation> iterator(&self()->getRelocationList());58TR::ARMRelocation *relocation;59TR::IteratedExternalRelocation *r;6061for (relocation=iterator.getFirst();62relocation!=NULL;63relocation=iterator.getNext())64{65relocation->mapRelocation(self()->cg());66}6768for (auto aotIterator = self()->cg()->getExternalRelocationList().begin(); aotIterator != self()->cg()->getExternalRelocationList().end(); ++aotIterator)69{70(*aotIterator)->addExternalRelocation(self()->cg());71}7273for (r = self()->getAOTRelocationTargets().getFirst();74r != NULL;75r = r->getNext())76{77self()->addToSizeOfAOTRelocations(r->getSizeOfRelocationData());78}7980// now allocate the memory size of all iterated relocations + the header (total length field)8182if (self()->getSizeOfAOTRelocations() != 0)83{84uint8_t *relocationDataCursor = self()->setRelocationData(fej9->allocateRelocationData(self()->comp(), self()->getSizeOfAOTRelocations() + 4));8586// set up the size for the region87*(uint32_t *)relocationDataCursor = self()->getSizeOfAOTRelocations() + 4;88relocationDataCursor += 4;8990// set up pointers for each iterated relocation and initialize header91TR::IteratedExternalRelocation *s;92for (s = self()->getAOTRelocationTargets().getFirst();93s != NULL;94s = s->getNext())95{96s->setRelocationData(relocationDataCursor);97s->initializeRelocation(_cg);98relocationDataCursor += s->getSizeOfRelocationData();99}100}101}102103bool104J9::ARM::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,105TR_RelocationTarget *reloTarget,106TR_RelocationRecord *reloRecord,107uint8_t targetKind)108{109bool platformSpecificReloInitialized = true;110TR::Compilation* comp = self()->comp();111TR_J9VMBase *fej9 = comp->fej9();112TR_SharedCache *sharedCache = fej9->sharedCache();113uint8_t * aotMethodCodeStart = (uint8_t *) comp->getRelocatableMethodCodeStart();114115switch (targetKind)116{117case TR_MethodObject:118{119TR_RelocationRecordMethodObject *moRecord = reinterpret_cast<TR_RelocationRecordMethodObject *>(reloRecord);120TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();121122TR::SymbolReference *symRef = reinterpret_cast<TR::SymbolReference *>(recordInfo->data1);123uintptr_t inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(symRef->getOwningMethod(comp)->constantPool(), recordInfo->data2);124uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(recordInfo->data3));125126TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");127128moRecord->setInlinedSiteIndex(reloTarget, reinterpret_cast<uintptr_t>(inlinedSiteIndex));129moRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(symRef->getOwningMethod(comp)->constantPool()));130moRecord->setReloFlags(reloTarget, flags);131}132break;133134case TR_ClassAddress:135{136TR_RelocationRecordClassAddress *caRecord = reinterpret_cast<TR_RelocationRecordClassAddress *>(reloRecord);137TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();138139TR::SymbolReference *symRef = reinterpret_cast<TR::SymbolReference *>(recordInfo->data1);140uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(recordInfo->data2);141uint8_t flags = static_cast<uint8_t>(recordInfo->data3);142143void *constantPool = symRef->getOwningMethod(comp)->constantPool();144inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(constantPool, inlinedSiteIndex);145146TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");147caRecord->setReloFlags(reloTarget, flags);148caRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);149caRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(constantPool));150caRecord->setCpIndex(reloTarget, symRef->getCPIndex());151}152break;153154case TR_DataAddress:155{156TR_RelocationRecordDataAddress *daRecord = reinterpret_cast<TR_RelocationRecordDataAddress *>(reloRecord);157TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation*) relocation->getTargetAddress();158159TR::SymbolReference *symRef = reinterpret_cast<TR::SymbolReference *>(recordInfo->data1);160uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(recordInfo->data2);161uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(recordInfo->data3));162163void *constantPool = symRef->getOwningMethod(comp)->constantPool();164inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(constantPool, inlinedSiteIndex);165166TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");167daRecord->setReloFlags(reloTarget, flags);168daRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);169daRecord->setConstantPool(reloTarget, reinterpret_cast<uintptr_t>(constantPool));170daRecord->setCpIndex(reloTarget, symRef->getCPIndex());171daRecord->setOffset(reloTarget, symRef->getOffset());172}173break;174175case TR_FixedSequenceAddress2:176{177TR_RelocationRecordWithOffset *rwoRecord = reinterpret_cast<TR_RelocationRecordWithOffset *>(reloRecord);178uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));179180TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");181rwoRecord->setReloFlags(reloTarget, flags);182183uintptr_t offset = relocation->getTargetAddress()184? static_cast<uintptr_t>(relocation->getTargetAddress() - aotMethodCodeStart)185: 0x0;186187rwoRecord->setOffset(reloTarget, offset);188}189break;190191case TR_BodyInfoAddressLoad:192{193TR_RelocationRecord *rRecord = reinterpret_cast<TR_RelocationRecord *>(reloRecord);194195uint8_t flags = flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));196TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");197rRecord->setReloFlags(reloTarget, flags);198}199break;200201case TR_RamMethodSequence:202{203TR_RelocationRecordRamSequence *rsRecord = reinterpret_cast<TR_RelocationRecordRamSequence *>(reloRecord);204uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));205206TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");207rsRecord->setReloFlags(reloTarget, flags);208209// Skip Offset210}211break;212213case TR_GlobalValue:214case TR_HCR:215{216TR_RelocationRecordWithOffset *rwoRecord = reinterpret_cast<TR_RelocationRecordWithOffset *>(reloRecord);217218uintptr_t gv = reinterpret_cast<uintptr_t>(relocation->getTargetAddress());219uint8_t flags = static_cast<uint8_t>(reinterpret_cast<uintptr_t>(relocation->getTargetAddress2()));220221TR_ASSERT((flags & RELOCATION_CROSS_PLATFORM_FLAGS_MASK) == 0, "reloFlags bits overlap cross-platform flags bits\n");222rwoRecord->setReloFlags(reloTarget, flags);223rwoRecord->setOffset(reloTarget, gv);224}225break;226227case TR_ArbitraryClassAddress:228{229TR_RelocationRecordArbitraryClassAddress *acaRecord = reinterpret_cast<TR_RelocationRecordArbitraryClassAddress *>(reloRecord);230231// ExternalRelocation data is as expected for TR_ClassAddress232TR_RelocationRecordInformation *recordInfo = (TR_RelocationRecordInformation *)relocation->getTargetAddress();233234auto symRef = (TR::SymbolReference *)recordInfo->data1;235auto sym = symRef->getSymbol()->castToStaticSymbol();236auto j9class = (TR_OpaqueClassBlock *)sym->getStaticAddress();237// flags stored in data3 are currently unused238uintptr_t inlinedSiteIndex = self()->findCorrectInlinedSiteIndex(symRef->getOwningMethod(comp)->constantPool(), recordInfo->data2);239240uintptr_t classChainIdentifyingLoaderOffsetInSharedCache = sharedCache->getClassChainOffsetIdentifyingLoader(j9class);241const AOTCacheClassChainRecord *classChainRecord = NULL;242uintptr_t classChainOffsetInSharedCache = self()->getClassChainOffset(j9class, classChainRecord);243244acaRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);245acaRecord->setClassChainIdentifyingLoaderOffsetInSharedCache(reloTarget, classChainIdentifyingLoaderOffsetInSharedCache,246self(), classChainRecord);247acaRecord->setClassChainForInlinedMethod(reloTarget, classChainOffsetInSharedCache, self(), classChainRecord);248}249break;250251default:252platformSpecificReloInitialized = false;253}254255return platformSpecificReloInitialized;256}257258259