Path: blob/master/runtime/compiler/z/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#pragma csect(CODE,"TRJ9ZAOTComp#C")23#pragma csect(STATIC,"TRJ9ZAOTComp#S")24#pragma csect(TEST,"TRJ9ZAOTComp#T")2526#include "codegen/AheadOfTimeCompile.hpp"27#include "codegen/CodeGenerator.hpp"28#include "env/FrontEnd.hpp"29#include "compile/AOTClassInfo.hpp"30#include "compile/Compilation.hpp"31#include "compile/ResolvedMethod.hpp"32#include "compile/VirtualGuard.hpp"33#include "env/CHTable.hpp"34#include "env/CompilerEnv.hpp"35#include "env/ClassLoaderTable.hpp"36#include "env/SharedCache.hpp"37#include "env/jittypes.h"38#include "env/VMJ9.h"39#include "il/LabelSymbol.hpp"40#include "il/Node.hpp"41#include "il/Node_inlines.hpp"42#include "il/StaticSymbol.hpp"43#include "il/SymbolReference.hpp"44#include "runtime/RelocationRuntime.hpp"45#include "runtime/RelocationRecord.hpp"4647#define WIDE_OFFSETS 0x8048#define EIP_RELATIVE 0x4049#define ORDERED_PAIR 0x2050#define NON_HELPER 05152J9::Z::AheadOfTimeCompile::AheadOfTimeCompile(TR::CodeGenerator *cg)53: J9::AheadOfTimeCompile(NULL, cg->comp()),54_relocationList(getTypedAllocator<TR::S390Relocation*>(cg->comp()->allocator())),55_cg(cg)56{57}5859void J9::Z::AheadOfTimeCompile::processRelocations()60{61TR::Compilation *comp = self()->comp();62TR_J9VMBase *fej9 = (TR_J9VMBase *)(_cg->fe());63TR::IteratedExternalRelocation *r;6465for (auto iterator = self()->getRelocationList().begin();66iterator != self()->getRelocationList().end();67++iterator)68{69(*iterator)->mapRelocation(_cg);70}7172for (auto aotIterator = _cg->getExternalRelocationList().begin(); aotIterator != _cg->getExternalRelocationList().end(); ++aotIterator)73(*aotIterator)->addExternalRelocation(_cg);7475for (r = self()->getAOTRelocationTargets().getFirst();76r != NULL;77r = r->getNext())78{79self()->addToSizeOfAOTRelocations(r->getSizeOfRelocationData());80}8182// now allocate the memory size of all iterated relocations + the header (total length field)8384// Note that when using the SymbolValidationManager, the well-known classes85// must be checked even if no explicit records were generated, since they86// might be responsible for the lack of records.87bool useSVM = comp->getOption(TR_UseSymbolValidationManager);88if (self()->getSizeOfAOTRelocations() != 0 || useSVM)89{90// It would be more straightforward to put the well-known classes offset91// in the AOT method header, but that would use space for AOT bodies that92// don't use the SVM. TODO: Move it once SVM takes over?93int wellKnownClassesOffsetSize = useSVM ? SIZEPOINTER : 0;94uintptr_t reloBufferSize =95self()->getSizeOfAOTRelocations() + SIZEPOINTER + wellKnownClassesOffsetSize;96uint8_t *relocationDataCursor = self()->setRelocationData(97fej9->allocateRelocationData(comp, reloBufferSize));98// set up the size for the region99*(uintptr_t *)relocationDataCursor = reloBufferSize;100relocationDataCursor += SIZEPOINTER;101102if (useSVM)103{104TR::SymbolValidationManager *svm = comp->getSymbolValidationManager();105void *offsets = const_cast<void *>(svm->wellKnownClassChainOffsets());106uintptr_t *wkcOffsetAddr = (uintptr_t *)relocationDataCursor;107*wkcOffsetAddr = self()->offsetInSharedCacheFromPointer(fej9->sharedCache(), offsets);108#if defined(J9VM_OPT_JITSERVER)109self()->addWellKnownClassesSerializationRecord(svm->aotCacheWellKnownClassesRecord(), wkcOffsetAddr);110#endif /* defined(J9VM_OPT_JITSERVER) */111relocationDataCursor += SIZEPOINTER;112}113114// set up pointers for each iterated relocation and initialize header115TR::IteratedExternalRelocation *s;116for (s = self()->getAOTRelocationTargets().getFirst();117s != NULL;118s = s->getNext())119{120s->setRelocationData(relocationDataCursor);121s->initializeRelocation(_cg);122relocationDataCursor += s->getSizeOfRelocationData();123}124}125}126127bool128J9::Z::AheadOfTimeCompile::initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation,129TR_RelocationTarget *reloTarget,130TR_RelocationRecord *reloRecord,131uint8_t targetKind)132{133bool platformSpecificReloInitialized = true;134135switch (targetKind)136{137case TR_EmitClass:138{139TR_RelocationRecordEmitClass *ecRecord = reinterpret_cast<TR_RelocationRecordEmitClass *>(reloRecord);140141TR_ByteCodeInfo *bcInfo = reinterpret_cast<TR_ByteCodeInfo *>(relocation->getTargetAddress());142int32_t bcIndex = bcInfo->getByteCodeIndex();143uintptr_t inlinedSiteIndex = reinterpret_cast<uintptr_t>(relocation->getTargetAddress2());144145ecRecord->setInlinedSiteIndex(reloTarget, inlinedSiteIndex);146ecRecord->setBCIndex(reloTarget, bcIndex);147}148break;149150default:151platformSpecificReloInitialized = false;152}153154return platformSpecificReloInitialized;155}156157158159