Path: blob/master/runtime/compiler/control/J9Recompilation.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_RECOMPILATION_INCL23#define J9_RECOMPILATION_INCL2425/*26* The following #define and typedef must appear before any #includes in this file27*/28#ifndef J9_RECOMPILATION_CONNECTOR29#define J9_RECOMPILATION_CONNECTOR30namespace J9 { class Recompilation; }31namespace J9 { typedef J9::Recompilation RecompilationConnector; }32#endif3334#include "control/OMRRecompilation.hpp"35#include "control/RecompilationInfo.hpp"36#include <stdint.h>3738namespace TR { class DefaultCompilationStrategy; }39class TR_ValueProfiler;40class TR_RecompilationProfiler;4142namespace J943{4445class Recompilation : public OMR::RecompilationConnector46{47friend class TR::DefaultCompilationStrategy;4849public:5051Recompilation(TR::Compilation *comp);5253void setupMethodInfo();5455void createProfilers();5657TR_PersistentJittedBodyInfo *getJittedBodyInfo() { return _bodyInfo; }58TR_PersistentMethodInfo *getMethodInfo() { return _methodInfo; }59void setMethodInfo(TR_PersistentMethodInfo *methodInfo) { _methodInfo = methodInfo; }60void setJittedBodyInfo(TR_PersistentJittedBodyInfo *bodyInfo) { _bodyInfo = bodyInfo; }6162TR_ValueProfiler * getValueProfiler();63TR_BlockFrequencyProfiler * getBlockFrequencyProfiler();64TR_RecompilationProfiler * getFirstProfiler() { return _profilers.getFirst(); }65void removeProfiler(TR_RecompilationProfiler *rp);6667bool isProfilingCompilation() { return _bodyInfo->getIsProfilingBody(); }6869// for replay70void setIsProfilingCompilation(bool v) { _bodyInfo->setIsProfilingBody(v); }7172TR_PersistentProfileInfo *findOrCreateProfileInfo();73TR_PersistentProfileInfo *getProfileInfo();7475bool useSampling() {return _useSampling;}7677bool switchToProfiling(uint32_t freq, uint32_t count);78bool switchToProfiling();79void switchAwayFromProfiling();8081int32_t getProfilingFrequency();82int32_t getProfilingCount();8384TR::SymbolReference *getCounterSymRef();85void *getCounterAddress() { return _bodyInfo->getCounterAddress(); }8687bool isRecompilation() { return !_firstCompile; }8889void startOfCompilation();90void beforeOptimization();91void beforeCodeGen();92void endOfCompilation();9394bool couldBeCompiledAgain();95bool shouldBeCompiledAgain();9697void preventRecompilation();9899static void shutdown();100101static TR_PersistentJittedBodyInfo *getJittedBodyInfoFromPC(void *startPC);102103static TR_PersistentMethodInfo *getMethodInfoFromPC(void *startPC)104{105TR_PersistentJittedBodyInfo *jbi = getJittedBodyInfoFromPC(startPC);106return jbi? jbi->getMethodInfo() : NULL;107}108109static bool countingSupported() { return _countingSupported; }110static TR_Hotness getNextCompileLevel(void *oldStartPC);111static void methodHasBeenRecompiled(void *oldStartPC, void *newStartPC, TR_FrontEnd *fe);112static void fixUpMethodCode(void *startPC);113114// Recompile the method when convenient115//116static bool induceRecompilation(TR_FrontEnd *fe, void *startPC, bool *queued, TR_OptimizationPlan *optimizationPlan = NULL);117118static bool isAlreadyBeingCompiled(TR_OpaqueMethodBlock *methodInfo, void *startPC, TR_FrontEnd *fe);119static void methodCannotBeRecompiled(void *oldStartPC, TR_FrontEnd *fe);120static void invalidateMethodBody(void *startPC, TR_FrontEnd *fe);121122// Called at runtime to sample a method123//124static void sampleMethod(void *vmThread, TR_FrontEnd *fe, void *startPC, int32_t codeSize, void *samplePC, void *methodInfo, int32_t tickCount);125126static bool isAlreadyPreparedForRecompile(void *startPC);127128virtual TR_PersistentMethodInfo *getExistingMethodInfo(TR_ResolvedMethod *method);129130static int32_t globalSampleCount;131static int32_t hwpGlobalSampleCount;132static int32_t jitGlobalSampleCount;133static int32_t jitRecompilationsInduced;134135#if defined(J9VM_OPT_JITSERVER)136static TR_PersistentJittedBodyInfo * persistentJittedBodyInfoFromString(const std::string &bodyInfoStr, const std::string &methodInfoStr, TR_Memory * trMemory);137static void resetPersistentProfileInfo(TR_PersistentMethodInfo *methodInfo);138#endif /* defined(J9VM_OPT_JITSERVER) */139140protected:141static int32_t limitMethodsCompiled;142static int32_t hotThresholdMethodsCompiled;143static int32_t scorchingThresholdMethodsCompiled;144static bool _countingSupported;145146bool _firstCompile;147bool _useSampling;148bool _doNotCompileAgain;149TR_Hotness _nextLevel;150int32_t _nextCounter;151TR_SingleTimer _timer;152153TR_PersistentMethodInfo *_methodInfo;154TR_PersistentJittedBodyInfo *_bodyInfo;155156TR_LinkHead<TR_RecompilationProfiler> _profilers;157};158}159160161// A way to call induceRecompilation from ASM via jitCallCFunction.162// argsPtr[0] == startPC, argsPtr[1] == vmThread.163// resultPtr is ignored.164//165extern "C" void induceRecompilation_unwrapper(void **argsPtr, void **resultPtr);166167168#endif169170171