Path: blob/master/runtime/compiler/compile/J9Compilation.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 TR_J9_COMPILATIONBASE_INCL23#define TR_J9_COMPILATIONBASE_INCL2425/*26* The following #define and typedef must appear before any #includes in this file27*/28#ifndef TR_J9_COMPILATIONBASE_CONNECTOR29#define TR_J9_COMPILATIONBASE_CONNECTOR30namespace J9 { class Compilation; }31namespace J9 { typedef J9::Compilation CompilationConnector; }32#endif3334#include "compile/OMRCompilation.hpp"3536#include "compile/CompilationTypes.hpp"37#include "control/Options.hpp"38#include "control/Options_inlines.hpp"39#include "infra/Statistics.hpp"40#include "env/CompilerEnv.hpp"41#include "env/OMRMemory.hpp"42#include "compile/AOTClassInfo.hpp"43#include "runtime/SymbolValidationManager.hpp"44#if defined(J9VM_OPT_JITSERVER)45#include "env/PersistentCollections.hpp"46#endif /* defined(J9VM_OPT_JITSERVER) */474849class TR_AOTGuardSite;50class TR_FrontEnd;51class TR_ResolvedMethod;52class TR_OptimizationPlan;53class TR_J9VMBase;54class TR_ValueProfileInfoManager;55class TR_BranchProfileInfoManager;56class TR_MethodBranchProfileInfo;57class TR_ExternalValueProfileInfo;58class TR_J9VM;59class TR_AccessedProfileInfo;60class TR_RelocationRuntime;61namespace TR { class IlGenRequest; }62#ifdef J9VM_OPT_JITSERVER63struct SerializedRuntimeAssumption;64class ClientSessionData;65class AOTCacheRecord;66#endif /* defined(J9VM_OPT_JITSERVER) */6768#define COMPILATION_AOT_HAS_INVOKEHANDLE -969#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_FATAL_ERROR -1070#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_INSUFFICIENT_SPACE -1171#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_ERROR_INBINARYENCODING -1272#define COMPILATION_RESERVE_RESOLVED_TRAMPOLINE_ERROR -1373#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_FATAL_ERROR -1474#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_INSUFFICIENT_SPACE -1575#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_ERROR_INBINARYENCODING -1676#define COMPILATION_RESERVE_UNRESOLVED_TRAMPOLINE_ERROR -1777#define COMPILATION_RESERVE_NTRAMPOLINES_INSUFFICIENT_SPACE -1878#define COMPILATION_RESERVE_NTRAMPOLINES_ERROR_INBINARYENCODING -1979#define COMPILATION_AOT_RELOCATION_FAILED -20808182namespace J983{8485class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector86{87public:8889TR_ALLOC(TR_Memory::Compilation)9091Compilation(92int32_t compThreadId,93J9VMThread *j9VMThread,94TR_FrontEnd *,95TR_ResolvedMethod *,96TR::IlGenRequest &,97TR::Options &,98TR::Region &heapMemoryRegion,99TR_Memory *,100TR_OptimizationPlan *optimizationPlan,101TR_RelocationRuntime *reloRuntime,102TR::Environment *target = NULL);103104~Compilation();105106TR_J9VMBase *fej9();107TR_J9VM *fej9vm();108109static void allocateCompYieldStatsMatrix();110111static TR_Stats **_compYieldStatsMatrix;112113void updateCompYieldStatistics(TR_CallingContext callingContext);114115bool getUpdateCompYieldStats() { return _updateCompYieldStats; }116117void printCompYieldStats();118119uint64_t getMaxYieldInterval() { return _maxYieldInterval; }120121static const char * getContextName(TR_CallingContext context);122123static void printCompYieldStatsMatrix();124125static void printEntryName(int32_t, int32_t);126127bool getNeedsClassLookahead() {return _needsClassLookahead;}128129void setNeedsClassLookahead(bool b) {_needsClassLookahead = b;}130131bool hasBlockFrequencyInfo();132133bool isShortRunningMethod(int32_t callerIndex);134135int32_t getDltBcIndex() { return (uint32_t)_dltBcIndex;}136void setDltBcIndex(int32_t ix) { _dltBcIndex=ix;}137138int32_t *getDltSlotDescription() { return _dltSlotDescription;}139void setDltSlotDescription(int32_t *ds) { _dltSlotDescription = ds;}140141void *getReservedDataCache() { return _reservedDataCache; }142void setReservedDataCache(void *dataCache) { _reservedDataCache = dataCache; }143144uint32_t getTotalNeededDataCacheSpace() { return _totalNeededDataCacheSpace; }145void incrementTotalNeededDataCacheSpace(uint32_t size) { _totalNeededDataCacheSpace += size; }146147void * getAotMethodDataStart() const { return _aotMethodDataStart; }148void setAotMethodDataStart(void *p) { _aotMethodDataStart = p; }149150TR_AOTMethodHeader * getAotMethodHeaderEntry();151152TR::Node *findNullChkInfo(TR::Node *node);153154bool isAlignStackMaps() { return J9::Compilation::target().cpu.isARM(); }155156void changeOptLevel(TR_Hotness);157158// For replay159void *getCurMethodMetadata() {return _curMethodMetadata;}160void setCurMethodMetadata(void *m) {_curMethodMetadata = m;}161162void setGetImplInlineable(bool b) { _getImplInlineable = b; }163bool getGetImplInlineable() { return _getImplInlineable; }164165//for converters166bool canTransformConverterMethod(TR::RecognizedMethod method);167bool isConverterMethod(TR::RecognizedMethod method);168169bool useCompressedPointers();170bool useAnchors();171172bool isRecompilationEnabled();173174bool isJProfilingCompilation();175176bool pendingPushLivenessDuringIlgen();177178TR::list<TR_ExternalValueProfileInfo*> &getExternalVPInfos() { return _externalVPInfoList; }179180TR_ValueProfileInfoManager *getValueProfileInfoManager() { return _vpInfoManager;}181void setValueProfileInfoManager(TR_ValueProfileInfoManager * mgr) { _vpInfoManager = mgr; }182183TR_BranchProfileInfoManager *getBranchProfileInfoManager() { return _bpInfoManager;}184void setBranchProfileInfoManager(TR_BranchProfileInfoManager * mgr) { _bpInfoManager = mgr; }185186TR::list<TR_MethodBranchProfileInfo*> &getMethodBranchInfos() { return _methodBranchInfoList; }187188// See if the allocation of an object of the class can be inlined.189bool canAllocateInlineClass(TR_OpaqueClassBlock *clazz);190191// See if it is OK to remove an allocation node to e.g. merge it with others192// or allocate it locally on a stack frame.193// If so, return the allocation size. Otherwise return 0.194// The second argument is the returned class information.195//196int32_t canAllocateInlineOnStack(TR::Node* node, TR_OpaqueClassBlock* &classInfo);197int32_t canAllocateInline(TR::Node* node, TR_OpaqueClassBlock* &classInfo);198199TR::KnownObjectTable *getOrCreateKnownObjectTable();200void freeKnownObjectTable();201202bool compileRelocatableCode();203204bool compilePortableCode();205206int32_t maxInternalPointers();207208bool compilationShouldBeInterrupted(TR_CallingContext);209210/* Heuristic Region APIs211*212* Heuristic Regions denotes regions where decisions213* within the region do not need to be remembered. In relocatable compiles,214* when the compiler requests some information via front end query,215* it's possible that the front end might walk a data structure,216* looking at several different possible answers before finally deciding217* on one. For a relocatable compile, only the final answer is important.218* Thus, a heuristic region is used to ignore all of the intermediate219* steps in determining the final answer.220*/221void enterHeuristicRegion();222void exitHeuristicRegion();223224/* Used to ensure that a implementer chosen for inlining is valid under225* AOT.226*/227bool validateTargetToBeInlined(TR_ResolvedMethod *implementer);228229void reportILGeneratorPhase();230void reportAnalysisPhase(uint8_t id);231void reportOptimizationPhase(OMR::Optimizations);232void reportOptimizationPhaseForSnap(OMR::Optimizations);233234CompilationPhase saveCompilationPhase();235void restoreCompilationPhase(CompilationPhase phase);236237/**238* \brief239* Answers whether the fact that a method has not been executed yet implies240* that the method is cold.241*242* \return243* true if the fact that a method has not been executed implies it is cold;244* false otherwise245*/246bool notYetRunMeansCold();247248// --------------------------------------------------------------------------249// Hardware profiling250//251bool HWProfileDone() { return _doneHWProfile;}252void setHWProfileDone(bool val) {_doneHWProfile = val;}253254void addHWPInstruction(TR::Instruction *instruction,255TR_HWPInstructionInfo::type instructionType,256void *data = NULL);257void addHWPCallInstruction(TR::Instruction *instruction, bool indirectCall = false, TR::Instruction *prev = NULL);258void addHWPReturnInstruction(TR::Instruction *instruction);259void addHWPValueProfileInstruction(TR::Instruction *instruction);260void addHWPBCMap(TR_HWPBytecodePCToIAMap map) { _hwpBCMap.add(map); }261TR_Array<TR_HWPInstructionInfo> *getHWPInstructions() { return &_hwpInstructions; }262TR_Array<TR_HWPBytecodePCToIAMap> *getHWPBCMap() { return &_hwpBCMap; }263264bool verifyCompressedRefsAnchors(bool anchorize);265void verifyCompressedRefsAnchors();266267void verifyCompressedRefsAnchors(TR::Node *parent, TR::Node *node,268TR::TreeTop *tt, vcount_t visitCount);269void verifyCompressedRefsAnchors(TR::Node *parent, TR::Node *node,270TR::TreeTop *tt, vcount_t visitCount,271TR::list<TR_Pair<TR::Node, TR::TreeTop> *> &nodesList);272273// CodeGenerator?274TR::list<TR_AOTGuardSite*> *getAOTGuardPatchSites() { return _aotGuardPatchSites; }275TR_AOTGuardSite *addAOTNOPSite();276277TR::list<TR_VirtualGuardSite*> *getSideEffectGuardPatchSites() { return &_sideEffectGuardPatchSites; }278TR_VirtualGuardSite *addSideEffectNOPSite();279280TR_CHTable *getCHTable() const { return _transientCHTable; }281282// Inliner283using OMR::CompilationConnector::incInlineDepth;284bool incInlineDepth(TR::ResolvedMethodSymbol *, TR_ByteCodeInfo &, int32_t cpIndex, TR::SymbolReference *callSymRef, bool directCall, TR_PrexArgInfo *argInfo = 0);285286bool isGeneratedReflectionMethod(TR_ResolvedMethod *method);287288TR_ExternalRelocationTargetKind getReloTypeForMethodToBeInlined(TR_VirtualGuardSelection *guard, TR::Node *callNode, TR_OpaqueClassBlock *receiverClass);289290// cache J9 VM pointers291TR_OpaqueClassBlock *getObjectClassPointer();292TR_OpaqueClassBlock *getRunnableClassPointer();293TR_OpaqueClassBlock *getStringClassPointer();294TR_OpaqueClassBlock *getSystemClassPointer();295TR_OpaqueClassBlock *getReferenceClassPointer();296TR_OpaqueClassBlock *getJITHelpersClassPointer();297TR_OpaqueClassBlock *getClassClassPointer(bool isVettedForAOT = false);298299// Monitors300TR_Array<List<TR::RegisterMappedSymbol> * > & getMonitorAutos() { return _monitorAutos; }301void addMonitorAuto(TR::RegisterMappedSymbol *, int32_t callerIndex);302void addAsMonitorAuto(TR::SymbolReference* symRef, bool dontAddIfDLT);303TR::list<TR::SymbolReference*> * getMonitorAutoSymRefsInCompiledMethod() { return &_monitorAutoSymRefsInCompiledMethod; }304305// OSR Guard Redefinition Classes306void addClassForOSRRedefinition(TR_OpaqueClassBlock *clazz);307TR_Array<TR_OpaqueClassBlock*> *getClassesForOSRRedefinition() { return &_classForOSRRedefinition; }308309void addClassForStaticFinalFieldModification(TR_OpaqueClassBlock *clazz);310TR_Array<TR_OpaqueClassBlock*> *getClassesForStaticFinalFieldModification() { return &_classForStaticFinalFieldModification; }311312TR::list<TR::AOTClassInfo*>* _aotClassInfo;313314J9VMThread *j9VMThread() { return _j9VMThread; }315316// cache profile information317TR_AccessedProfileInfo *getProfileInfo() { return _profileInfo; }318319// Flag to test whether early stages of JProfiling ran320void setSkippedJProfilingBlock(bool b = true) { _skippedJProfilingBlock = b; }321bool getSkippedJProfilingBlock() { return _skippedJProfilingBlock; }322323//324bool supportsQuadOptimization();325326TR_RelocationRuntime *reloRuntime() { return _reloRuntime; }327328bool incompleteOptimizerSupportForReadWriteBarriers();329330#if defined(J9VM_OPT_JITSERVER)331static bool isOutOfProcessCompilation() { return _outOfProcessCompilation; } // server side332static void setOutOfProcessCompilation() { _outOfProcessCompilation = true; }333334bool isRemoteCompilation() const { return _remoteCompilation; } // client side335void setRemoteCompilation() { _remoteCompilation = true; }336337TR::list<SerializedRuntimeAssumption *> &getSerializedRuntimeAssumptions() { return _serializedRuntimeAssumptions; }338339ClientSessionData *getClientData() const { return _clientData; }340void setClientData(ClientSessionData *clientData) { _clientData = clientData; }341342JITServer::ServerStream *getStream() const { return _stream; }343void setStream(JITServer::ServerStream *stream) { _stream = stream; }344345void switchToPerClientMemory() { _trMemory = _perClientMemory; }346void switchToGlobalMemory() { _trMemory = &_globalMemory; }347348TR::list<TR_OpaqueMethodBlock *> &getMethodsRequiringTrampolines() { return _methodsRequiringTrampolines; }349350bool isDeserializedAOTMethod() const { return _deserializedAOTMethod; }351void setDeserializedAOTMethod(bool deserialized) { _deserializedAOTMethod = deserialized; }352353bool isDeserializedAOTMethodUsingSVM() const { return _deserializedAOTMethodUsingSVM; }354void setDeserializedAOTMethodUsingSVM(bool usingSVM) { _deserializedAOTMethodUsingSVM = usingSVM; }355356bool isAOTCacheStore() const { return _aotCacheStore; }357void setAOTCacheStore(bool store) { _aotCacheStore = store; }358359Vector<std::pair<const AOTCacheRecord *, uintptr_t>> &getSerializationRecords() { return _serializationRecords; }360// Adds an AOT cache record and the corresponding offset into AOT relocation data to the list that361// will be used when the result of this out-of-process compilation is serialized and stored in362// JITServer AOT cache. If record is NULL, fails serialization by setting _aotCacheStore to false.363void addSerializationRecord(const AOTCacheRecord *record, uintptr_t reloDataOffset);364#endif /* defined(J9VM_OPT_JITSERVER) */365366TR::SymbolValidationManager *getSymbolValidationManager() { return _symbolValidationManager; }367368// Flag to record if any optimization has prohibited OSR over a range of trees369void setOSRProhibitedOverRangeOfTrees() { _osrProhibitedOverRangeOfTrees = true; }370bool isOSRProhibitedOverRangeOfTrees() { return _osrProhibitedOverRangeOfTrees; }371372private:373enum CachedClassPointerId374{375OBJECT_CLASS_POINTER,376RUNNABLE_CLASS_POINTER,377STRING_CLASS_POINTER,378SYSTEM_CLASS_POINTER,379REFERENCE_CLASS_POINTER,380JITHELPERS_CLASS_POINTER,381CACHED_CLASS_POINTER_COUNT,382};383384TR_OpaqueClassBlock *getCachedClassPointer(CachedClassPointerId which);385386J9VMThread *_j9VMThread;387388bool _doneHWProfile;389TR_Array<TR_HWPInstructionInfo> _hwpInstructions;390TR_Array<TR_HWPBytecodePCToIAMap> _hwpBCMap;391392bool _updateCompYieldStats;393394uint64_t _hiresTimeForPreviousCallingContext;395396TR_CallingContext _previousCallingContext;397398uint64_t _maxYieldInterval;399400TR_CallingContext _sourceContextForMaxYieldInterval;401402TR_CallingContext _destinationContextForMaxYieldInterval;403404static uint64_t _maxYieldIntervalS;405406static TR_CallingContext _sourceContextForMaxYieldIntervalS;407408static TR_CallingContext _destinationContextForMaxYieldIntervalS;409410bool _needsClassLookahead;411412uint16_t _dltBcIndex;413414int32_t * _dltSlotDescription;415416void * _reservedDataCache;417418uint32_t _totalNeededDataCacheSpace;419420void * _aotMethodDataStart; // used at relocation time421422void * _curMethodMetadata;423424bool _getImplInlineable;425426TR_ValueProfileInfoManager *_vpInfoManager;427428TR_BranchProfileInfoManager *_bpInfoManager;429430TR::list<TR_MethodBranchProfileInfo*> _methodBranchInfoList;431TR::list<TR_ExternalValueProfileInfo*> _externalVPInfoList;432TR::list<TR_AOTGuardSite*>* _aotGuardPatchSites;433TR::list<TR_VirtualGuardSite*> _sideEffectGuardPatchSites;434435// cache VM pointers436TR_OpaqueClassBlock *_cachedClassPointers[CACHED_CLASS_POINTER_COUNT];437438TR_OpaqueClassBlock *_aotClassClassPointer;439bool _aotClassClassPointerInitialized;440441TR_Array<List<TR::RegisterMappedSymbol> *> _monitorAutos;442TR::list<TR::SymbolReference*> _monitorAutoSymRefsInCompiledMethod;443444TR_Array<TR_OpaqueClassBlock*> _classForOSRRedefinition;445// Classes that have their static final fields folded and need assumptions446TR_Array<TR_OpaqueClassBlock*> _classForStaticFinalFieldModification;447448// cache profile information449TR_AccessedProfileInfo *_profileInfo;450451bool _skippedJProfilingBlock;452453TR_RelocationRuntime *_reloRuntime;454455#if defined(J9VM_OPT_JITSERVER)456// This list contains assumptions created during the compilation at the JITServer457// It needs to be sent to the client at the end of compilation458TR::list<SerializedRuntimeAssumption *> _serializedRuntimeAssumptions;459// The following flag is set when this compilation is performed in a460// VM that does not have the runtime part (server side in JITServer)461static bool _outOfProcessCompilation;462// The following flag is set when a request to complete this compilation463// has been sent to a remote VM (client side in JITServer)464bool _remoteCompilation;465// Client session data for the client that requested this out-of-process466// compilation (at the JITServer); unused (always NULL) at the client side467ClientSessionData *_clientData;468// Server stream used by this out-of-process compilation; always NULL at the client469JITServer::ServerStream *_stream;470471TR_Memory *_perClientMemory;472TR_Memory _globalMemory;473// This list contains RAM method pointers of resolved methods474// that require method trampolines.475// It needs to be sent to the client at the end of compilation476// so that trampolines can be reserved there.477TR::list<TR_OpaqueMethodBlock *> _methodsRequiringTrampolines;478479// True if this remote compilation resulted in deserializing an AOT method480// received from the JITServer AOT cache; always false at the server481bool _deserializedAOTMethod;482// True if this deserialized AOT method received from the483// JITServer AOT cache uses SVM; always false at the server484bool _deserializedAOTMethodUsingSVM;485// True if the result of this out-of-process compilation will be486// stored in JITServer AOT cache; always false at the client487bool _aotCacheStore;488// List of AOT cache records and corresponding offsets into AOT relocation data that will489// be used to store the result of this compilation in AOT cache; always empty at the client490Vector<std::pair<const AOTCacheRecord *, uintptr_t>> _serializationRecords;491#endif /* defined(J9VM_OPT_JITSERVER) */492493TR::SymbolValidationManager *_symbolValidationManager;494bool _osrProhibitedOverRangeOfTrees;495};496497}498499#endif500501502