Path: blob/master/runtime/compiler/control/CompilationController.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2018 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 COMPILATIONCONTROLLER_INCL23#define COMPILATIONCONTROLLER_INCL2425#include "compile/CompilationTypes.hpp"26#include "control/OptimizationPlan.hpp"27#include "runtime/CodeCacheManager.hpp"28#include "env/VMJ9.h"2930class TR_OptimizationPlan;31struct TR_MethodToBeCompiled;3233int32_t printTruncatedSignature(char *sigBuf, int32_t bufLen, J9Method *j9method);3435extern "C" {36int32_t returnIprofilerState();37}3839//--------------------------- TR_MethodEvent ----------------------------40class TR_MethodEvent41{42public:43enum { InvalidEvent=0,44InterpreterCounterTripped,45InterpretedMethodSample,46JittedMethodSample,47MethodBodyInvalidated,48NewInstanceImpl,49ShareableMethodHandleThunk,50CustomMethodHandleThunk,51OtherRecompilationTrigger,52JitCompilationInducedByDLT,53HWPRecompilationTrigger,54NumEvents // must be the last one55};56int32_t _eventType;57J9Method * _j9method;58void * _oldStartPC;59void * _samplePC;60J9VMThread * _vmThread;61J9Class * _classNeedingThunk; // for newInstanceImpl62TR_Hotness _nextOptLevel; // Used for HWP-based recompilation63};646566//-------------------------TR::DefaultCompilationStrategy ----------------------67namespace TR68{69class DefaultCompilationStrategy : public TR::CompilationStrategy70{71public:72TR_PERSISTENT_ALLOC(TR_Memory::PersistentInfo);73DefaultCompilationStrategy();74TR_OptimizationPlan *processEvent(TR_MethodEvent *event, bool *newPlanCreated);75TR_OptimizationPlan *processInterpreterSample(TR_MethodEvent *event);76TR_OptimizationPlan *processJittedSample(TR_MethodEvent *event);77TR_OptimizationPlan *processHWPSample(TR_MethodEvent *event);78TR_Hotness getInitialOptLevel(J9Method *j9method);79bool adjustOptimizationPlan(TR_MethodToBeCompiled *entry, int32_t optLevelAdjustment);80void beforeCodeGen(TR_OptimizationPlan *plan, TR::Recompilation *recomp);81void postCompilation(TR_OptimizationPlan *plan, TR::Recompilation *recomp);82void shutdown();83virtual bool enableSwitchToProfiling() { return !TR::CodeCacheManager::instance()->almostOutOfCodeCache(); }84private:85// statistics regarding the events it receives86unsigned _statEventType[TR_MethodEvent::NumEvents];87};88} // namespace TR8990//----------------------- TR::ThresholdCompilationStrategy ---------------------91namespace TR92{9394class ThresholdCompilationStrategy : public TR::CompilationStrategy95{96public:97TR_PERSISTENT_ALLOC(TR_Memory::PersistentInfo); // Do I need this ?98ThresholdCompilationStrategy();99TR_OptimizationPlan *processEvent(TR_MethodEvent *event, bool *newPlanCreated);100TR_OptimizationPlan *processJittedSample(TR_MethodEvent *event);101TR_Hotness getInitialOptLevel();102int32_t getSamplesNeeded(TR_Hotness optLevel) { TR_ASSERT(_samplesNeededToMoveTo[optLevel] >= 0, "must be valid entry"); return _samplesNeededToMoveTo[optLevel]; }103bool getPerformInstrumentation(TR_Hotness optLevel) { return _performInstrumentation[optLevel]; }104TR_Hotness getNextOptLevel(TR_Hotness curOptLevel) { TR_ASSERT(_nextLevel[curOptLevel] != unknownHotness, "must be valid opt level"); return _nextLevel[curOptLevel]; }105106private:107TR_Hotness _nextLevel[numHotnessLevels+1];108int32_t _samplesNeededToMoveTo[numHotnessLevels+1];109bool _performInstrumentation[numHotnessLevels+1];110};111} // namespace TR112#endif // ifndef COMPILATIONCONTROLLER_INCL113114115