Path: blob/master/runtime/compiler/codegen/J9AheadOfTimeCompile.hpp
6000 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#ifndef J9_AHEADOFTIMECOMPILE_HPP23#define J9_AHEADOFTIMECOMPILE_HPP2425#ifndef J9_AHEADOFTIMECOMPILE_CONNECTOR26#define J9_AHEADOFTIMECOMPILE_CONNECTOR27namespace J9 { class AheadOfTimeCompile; }28namespace J9 { typedef J9::AheadOfTimeCompile AheadOfTimeCompileConnector; }29#endif // J9_AHEADOFTIMECOMPILE_CONNECTOR3031#include "codegen/OMRAheadOfTimeCompile.hpp"32#include "runtime/RelocationRecord.hpp"3334#include <stdint.h>35#include "env/jittypes.h"3637namespace TR { class Compilation; }38class AOTCacheRecord;39class AOTCacheClassChainRecord;40class AOTCacheWellKnownClassesRecord;414243namespace J944{4546class OMR_EXTENSIBLE AheadOfTimeCompile : public OMR::AheadOfTimeCompileConnector47{48public:49static const size_t SIZEPOINTER = sizeof(uintptr_t);5051AheadOfTimeCompile(uint32_t *headerSizeMap, TR::Compilation *c) :52OMR::AheadOfTimeCompileConnector(headerSizeMap, c)53{54}5556/**57* @brief Gets the class chain offset for a given RAMClass. Calls TR_SharedCache::rememberClass()58* and fails the compilation if the class chain cannot be created.59*60* @param[in] classToRemember the RAMClass to get the class chain offset for61* @param[out] classChainRecord pointer to the AOT cache class chain record corresponding to the class chain, if this62* is an out-of-process compilation that will be stored in JITServerAOT cache;63* ignored for local compilations and out-of-process compilations not stored in AOT cache64* @return class chain SCC offset65*/66uintptr_t getClassChainOffset(TR_OpaqueClassBlock *classToRemember, const AOTCacheClassChainRecord *&classChainRecord);6768uintptr_t findCorrectInlinedSiteIndex(void *constantPool, uintptr_t currentInlinedSiteIndex);6970#if defined(J9VM_OPT_JITSERVER)71/**72* @brief Adds an AOT cache class record corresponding to a ROMClass SCC offset73* if this out-of-process compilation will be stored in AOT cache.74*75* The resulting AOT cache class record is the root class record of the class chain record.76*77* @param classChainRecord pointer to the AOT cache class chain record for the class78* @param romClassOffsetAddr pointer to the binary relocation record field that stores the ROMClass SCC offset79*/80void addClassSerializationRecord(const AOTCacheClassChainRecord *classChainRecord, const uintptr_t *romClassOffsetAddr);8182/**83* @brief Adds an AOT cache class record corresponding to a ROMClass SCC offset84* if this out-of-process compilation will be stored in AOT cache.85*86* The AOT cache class record is looked up in the client session or created87* on demand, possibly requesting missing information from the client.88*89* @param ramClass the RAMClass that the ROMClass SCC offset is for90* @param romClassOffsetAddr pointer to the binary relocation record field that stores the ROMClass SCC offset91*/92void addClassSerializationRecord(TR_OpaqueClassBlock *ramClass, const uintptr_t *romClassOffsetAddr);9394/**95* @brief Adds an AOT cache method record corresponding to a ROMMethod SCC offset96* if this out-of-process compilation will be stored in AOT cache.97*98* The AOT cache method record is looked up in the client session or created99* on demand, possibly requesting missing information from the client.100*101* @param method the RAMMethod that the ROMMethod SCC offset is for102* @param definingClass RAMClass for the defining class of the method103* @param romMethodOffsetAddr pointer to the binary relocation record field that stores the ROMMethod SCC offset104*/105void addMethodSerializationRecord(J9Method *method, TR_OpaqueClassBlock *definingClass, const uintptr_t *romMethodOffsetAddr);106107/**108* @brief Adds an AOT cache class chain record corresponding to a class chain SCC109* offset if this out-of-process compilation will be stored in AOT cache.110*111* @param classChainRecord pointer to the AOT cache class chain record112* @param classChainOffsetAddr pointer to the binary relocation record field that stores the class chain SCC offset113*/114void addClassChainSerializationRecord(const AOTCacheClassChainRecord *classChainRecord, const uintptr_t *classChainOffsetAddr);115116/**117* @brief Adds an AOT cache class loader record corresponding to a class chain SCC offset identifying118* a class loader if this out-of-process compilation will be stored in AOT cache.119*120* The resulting AOT cache class loader record is the class loader record of the root class of the class chain.121* Note that while the AOT cache class chain record passed to this method is the one for the class being122* remembered, i.e. the same as the one passed to addClassChainSerializationRecord(), the AOT cache record123* associated with this SCC offset is the one identifying the class loader of the class being remembered.124* The JITServer AOT cache identifies class loaders by the name of the first loaded class (not by its class125* chain), hence the AOT cache class loader records are a distinct type from the class chain records.126*127* @param classChainRecord pointer to the AOT cache class chain record for the class128* whose loader is identified by the class chain SCC offset129* @param loaderChainOffsetAddr pointer to the binary relocation record field that stores130* the class chain SCC offset identifying the class loader131*/132void addClassLoaderSerializationRecord(const AOTCacheClassChainRecord *classChainRecord, const uintptr_t *loaderChainOffsetAddr);133134/**135* @brief Adds an AOT cache well-known classes record corresponding to a well-known classes136* SCC offset if this out-of-process compilation will be stored in AOT cache.137*138* @param wkcRecord pointer to the AOT cache well-known classes record139* @param wkcOffsetAddr pointer to the binary relocation record field that stores the well-known classes SCC offset140*/141void addWellKnownClassesSerializationRecord(const AOTCacheWellKnownClassesRecord *wkcRecord, const uintptr_t *wkcOffsetAddr);142#endif /* defined(J9VM_OPT_JITSERVER) */143144void dumpRelocationData();145uint8_t* dumpRelocationHeaderData(uint8_t *cursor, bool isVerbose);146147/**148* @brief Initializes the relocation record header.149*150* @param relocation pointer to the iterated external relocation151* @return pointer into the buffer right after the fields of the header (ie the offsets section)152*/153virtual uint8_t *initializeAOTRelocationHeader(TR::IteratedExternalRelocation *relocation);154155/**156* @brief Initialization of relocation record headers for whom data for the fields are acquired157* in a manner that is specific to a particular platform. This is the default implementation.158*159* @param relocation pointer to the iterated external relocation160* @param reloTarget pointer to the TR_RelocationTarget object161* @param reloRecord pointer to the TR_RelocationRecord object162* @param targetKind the TR_ExternalRelocationTargetKind enum value163*164* @return true if a platform specific relocation record header was initialized; false otherwise165*/166bool initializePlatformSpecificAOTRelocationHeader(TR::IteratedExternalRelocation *relocation, TR_RelocationTarget *reloTarget, TR_RelocationRecord *reloRecord, uint8_t targetKind)167{ return false; }168169static void interceptAOTRelocation(TR::ExternalRelocation *relocation);170171uint32_t getSizeOfAOTRelocationHeader(TR_ExternalRelocationTargetKind k) { return TR_RelocationRecord::getSizeOfAOTRelocationHeader(k); }172uint32_t *setAOTRelocationKindToHeaderSizeMap(uint32_t *p) { TR_ASSERT_FATAL(false, "Should not be called!\n"); return 0; }173174/**175* Return true if an ExternalRelocation of kind TR_ClassAddress is expected176* to contain a pointer to TR_RelocationRecordInformation.177*/178static bool classAddressUsesReloRecordInfo() { return false; }179180protected:181182#if defined(J9VM_OPT_JITSERVER)183/**184* @brief Associates an AOT cache record with the corresponding SCC offset stored in AOT relocation data.185*186* If this is an out-of-process compilation that will be stored in JITServer AOT cache, computes the offset into187* AOT relocation data and calls Compilation::addSerializationRecord(record, offset), otherwise does nothing.188*189* @param record pointer to the AOT cache record to be added to this compilation190* @param sccOffsetAddr pointer to the binary relocation record field that stores the SCC offset191*/192void addSerializationRecord(const AOTCacheRecord *record, const uintptr_t *sccOffsetAddr);193#endif /* defined(J9VM_OPT_JITSERVER) */194195/**196* @brief TR_J9SharedCache::offsetInSharedCacheFrom* asserts if the pointer197* passed in does not exist in the SCC. Under HCR, when an agent redefines198* a class, it causes the J9Class pointer to stay the same, but the199* J9ROMClass pointer changes. This means that if the compiler has a200* reference to a J9Class who J9ROMClass was in the SCC at one point in the201* compilation, it may no longer be so at another point in the compilation.202*203* This means that the compilation is no longer valid and should be aborted.204* Even if there isn't an abort during the compilation, at the end of the205* compilation, the compiler will fail the compile if such a redefinition206* occurred.207*208* Calling TR_J9SharedCache::offsetInSharedCacheFromPointer after such a209* redefinition could result in an assert. Therefore, this method exists as210* a wrapper around TR_J9SharedCache::isROMClassInSharedCache which doesn't211* assert and conveniently, updates the location referred to by the cacheOffset212* pointer passed in as a parameter.213*214* If the ptr isn't in the SCC, then the current method will abort the215* compilation. If the ptr is in the SCC, then the cacheOffset will be updated.216*217* @param sharedCache pointer to the TR_SharedCache object218* @param romClass J9ROMClass * whose offset in the SCC is required219* @return The offset into the SCC of romClass220*/221uintptr_t offsetInSharedCacheFromROMClass(TR_SharedCache *sharedCache, J9ROMClass *romClass);222223/**224* @brief Same circumstance as offsetInSharedCacheFromROMClass above225*226* @param sharedCache pointer to the TR_SharedCache object227* @param romMethod J9ROMMethod * whose offset in the SCC is required228* @return The offset into the SCC of romMethod229*/230uintptr_t offsetInSharedCacheFromROMMethod(TR_SharedCache *sharedCache, J9ROMMethod *romMethod);231232/**233* @brief Wrapper around TR_J9SharedCache::offsetInSharedCacheFromPointer for234* consistency with the above APIs235*236* @param sharedCache pointer to the TR_SharedCache object237* @param ptr pointer whose offset in the SCC is required238* @return The offset into the SCC of ptr239*/240uintptr_t offsetInSharedCacheFromPointer(TR_SharedCache *sharedCache, void *ptr);241242/**243* @brief Initialization of relocation record headers for whom data for the fields are acquired244* in a manner that is common on all platforms245*246* @param relocation pointer to the iterated external relocation247* @param reloTarget pointer to the TR_RelocationTarget object248* @param reloRecord pointer to the associated TR_RelocationRecord API object249* @param kind the TR_ExternalRelocationTargetKind enum value250*/251void initializeCommonAOTRelocationHeader(TR::IteratedExternalRelocation *relocation, TR_RelocationTarget *reloTarget, TR_RelocationRecord *reloRecord, uint8_t kind);252};253254}255256#endif // TR_J9AHEADOFTIMECOMPILE_HPP257258259