Path: blob/master/runtime/compiler/env/J9PersistentInfo.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_PERSISTENTINFO_HPP23#define J9_PERSISTENTINFO_HPP2425#ifndef J9_PERSISTENTINFO_CONNECTOR26#define J9_PERSISTENTINFO_CONNECTOR27namespace J9 { class PersistentInfo; }28namespace J9 { typedef J9::PersistentInfo PersistentInfoConnector; }29#endif3031#include "env/OMRPersistentInfo.hpp"32#include "env/RuntimeAssumptionTable.hpp"3334#include <stdint.h>35#if defined(J9VM_OPT_JITSERVER)36#include <string>37#endif /* defined(J9VM_OPT_JITSERVER) */38#include "env/jittypes.h"3940class TR_FrontEnd;41class TR_PersistentMemory;42class TR_PersistentCHTable;43class TR_PersistentClassLoaderTable;44class TR_J2IThunkTable;45namespace J9 { class Options; }4647enum JitStates {48UNDEFINED_STATE = 0,49IDLE_STATE,50STARTUP_STATE,51RAMPUP_STATE,52STEADY_STATE,53DEEPSTEADY_STATE,54};5556enum IprofilerStates {57IPROFILING_STATE_ON = 1,58IPROFILING_STATE_GOING_OFF,59IPROFILING_STATE_OFF,60};6162#if defined(J9VM_OPT_JITSERVER)63namespace JITServer64{65enum RemoteCompilationModes66{67NONE = 0,68CLIENT,69SERVER,70};7172enum ServerMemoryState73{74VERY_LOW = 0,75LOW,76NORMAL,77};7879enum ServerActiveThreadsState80{81VERY_HIGH_THREAD = 0,82HIGH_THREAD,83NORMAL_THREAD,84};8586enum CompThreadActivationPolicy87{88// Order is important, we use comparison operators89// on policy states and for indexing into the name array90SUSPEND = 0,91MAINTAIN,92SUBDUE,93AGGRESSIVE,94};9596static const char *compThreadActivationPolicyNames[] = {97"SUSPEND",98"MAINTAIN",99"SUBDUE",100"AGGRESSIVE",101};102}103#endif /* defined(J9VM_OPT_JITSERVER) */104105#define MAX_SUPERCLASSES (20000)106namespace J9107{108109class PersistentInfo : public OMR::PersistentInfoConnector110{111friend class J9::Options;112113public:114115PersistentInfo(TR_PersistentMemory *pm) :116#pragma warning( suppress : 4351 )117_paddingBefore(),118_countForRecompile(0),119_numLoadedClasses(0),120_classLoadingPhase(false),121_inlinerTemporarilyRestricted(false),122_elapsedTime(0),123_unloadedClassAddresses(NULL),124_unloadedMethodAddresses(NULL),125_runtimeAssumptionTable(),126_persistentCHTable(NULL),127_visitedSuperClasses(NULL),128_numVisitedSuperClasses(0),129_tooManySuperClasses(false),130_persistentClassLoaderTable(NULL),131_GCwillBlockOnClassUnloadMonitor(false),132_timeGCwillBlockOnClassUnloadMonitorWasSet(0),133_numUnloadedClasses(0),134_classLoadingPhaseGracePeriod(0),135_startTime(0),136_globalClassUnloadID(0),137_externalStartupEndedSignal(false),138_disableFurtherCompilation(false),139_loadFactor(1),140_jitState(STARTUP_STATE),141_jitStateChangeSampleCount(0),142_jitTotalSampleCount(0),143_jitSampleCountWhenActiveStateEntered(0),144_jitSampleCountWhenStartupStateEntered(0),145_jitSampleCountWhenStartupStateExited(0),146_vmTotalCpuTimeWhenStartupStateEntered(0),147_vmTotalCpuTimeWhenStartupStateExited(0),148_inliningAggressiveness(100),149_lastTimeSamplerThreadEnteredIdle(0),150_lastTimeSamplerThreadEnteredDeepIdle(0),151_lastTimeSamplerThreadWasSuspended(0),152_lastTimeThreadsWereActive(0),153_gcMapCheckEventHandleKey(0),154_statNumGCRBodies(0),155_statNumGCRSaves(0),156_invokeExactJ2IThunkTable(NULL),157_gpuInitMonitor(NULL),158_runtimeInstrumentationEnabled(false),159_runtimeInstrumentationRecompilationEnabled(false),160#if defined(J9VM_OPT_JITSERVER)161_JITServerAddress("localhost"),162_JITServerPort(38400),163_socketTimeoutMs(2000),164_clientUID(0),165_JITServerUseAOTCache(false),166_requireJITServer(false),167_localSyncCompiles(false),168_JITServerAOTCacheName(),169#endif /* defined(J9VM_OPT_JITSERVER) */170OMR::PersistentInfoConnector(pm)171{}172173void setPersistentClassLoaderTable(TR_PersistentClassLoaderTable *table) { _persistentClassLoaderTable = table; }174TR_PersistentClassLoaderTable *getPersistentClassLoaderTable() { return _persistentClassLoaderTable; }175176TR_OpaqueClassBlock **getVisitedSuperClasses() { return _visitedSuperClasses; }177void clearVisitedSuperClasses() { _tooManySuperClasses = false; _numVisitedSuperClasses = 0; }178void setVisitedSuperClasses(TR_OpaqueClassBlock **v) { _visitedSuperClasses = v; }179bool tooManySuperClasses() { return _tooManySuperClasses; }180void setTooManySuperClasses(bool b) { _tooManySuperClasses = b; }181int32_t getNumVisitedSuperClasses() {return _numVisitedSuperClasses; }182void setNumVisitedSuperClasses(int32_t n) {_numVisitedSuperClasses = n; }183void addSuperClass(TR_OpaqueClassBlock *c)184{185if (_visitedSuperClasses && _numVisitedSuperClasses < MAX_SUPERCLASSES)186_visitedSuperClasses[_numVisitedSuperClasses++] = c;187else188_tooManySuperClasses = true;189}190191bool GCwillBlockOnClassUnloadMonitor() { return _GCwillBlockOnClassUnloadMonitor; }192void setGCwillBlockOnClassUnloadMonitor() { _GCwillBlockOnClassUnloadMonitor = true; _timeGCwillBlockOnClassUnloadMonitorWasSet = _elapsedTime;}193void resetGCwillBlockOnClassUnloadMonitor() { _GCwillBlockOnClassUnloadMonitor = false; }194195bool ensureUnloadedAddressSetsAreInitialized();196void addUnloadedClass(TR_OpaqueClassBlock *clazz, uintptr_t startAddress, uint32_t size);197bool isUnloadedClass(void *v, bool yesIReallyDontCareAboutHCR); // You probably want isObsoleteClass198bool isInUnloadedMethod(uintptr_t address);199int32_t getNumUnloadedClasses() const { return _numUnloadedClasses; }200TR_AddressSet* getUnloadedClassAddresses() const { return _unloadedClassAddresses; }201202void incNumLoadedClasses() {_numLoadedClasses++;}203204int32_t getClassLoadingPhaseGracePeriod() { return _classLoadingPhaseGracePeriod; }205void setClassLoadingPhaseGracePeriod(int32_t val) { _classLoadingPhaseGracePeriod = val; }206207uint64_t getStartTime() const { return _startTime;}208void setStartTime(uint64_t t) {_startTime = t;}209210void setElapsedTime(uint64_t t) {_elapsedTime = t;}211void updateElapsedTime(uint64_t t) {_elapsedTime += t;}212213int32_t getGlobalClassUnloadID() const {return _globalClassUnloadID;}214void incGlobalClassUnloadID() {_globalClassUnloadID++;}215216bool getExternalStartupEndedSignal() const { return _externalStartupEndedSignal; }217void setExternalStartupEndedSignal(bool b) { _externalStartupEndedSignal = b; }218219bool isObsoleteClass(void *v, TR_FrontEnd *fe);220TR_PseudoRandomNumbersListElement *advanceCurPseudoRandomNumbersListElem();221222bool getDisableFurtherCompilation() const { return _disableFurtherCompilation; }223void setDisableFurtherCompilation(bool b) { _disableFurtherCompilation = b; }224225uint32_t getLoadFactor() const { return _loadFactor; }226void setLoadFactor(uint32_t f) { _loadFactor = f; }227228uint8_t getJitState() const { return _jitState; }229void setJitState(uint8_t v) { _jitState = v; }230231void setJitStateChangeSampleCount(uint32_t t) {_jitStateChangeSampleCount = t;}232uint32_t getJitStateChangeSampleCount() const { return _jitStateChangeSampleCount;}233234uint32_t getJitTotalSampleCount() const { return _jitTotalSampleCount; }235void incJitTotalSampleCount() { _jitTotalSampleCount++; }236237void setJitSampleCountWhenStartupStateEntered(uint32_t n) { _jitSampleCountWhenStartupStateEntered = n; }238uint32_t getJitSampleCountWhenStartupStateEntered() const { return _jitSampleCountWhenStartupStateEntered; }239240void setJitSampleCountWhenStartupStateExited(uint32_t n) { _jitSampleCountWhenStartupStateExited = n; }241uint32_t getJitSampleCountWhenStartupStateExited() const { return _jitSampleCountWhenStartupStateExited; }242243void setJitSampleCountWhenActiveStateEntered(uint32_t n) { _jitSampleCountWhenActiveStateEntered = n; }244uint32_t getJitSampleCountWhenActiveStateEntered() const { return _jitSampleCountWhenActiveStateEntered; }245246void setVmTotalCpuTimeWhenStartupStateEntered(int64_t n) { _vmTotalCpuTimeWhenStartupStateEntered = n; }247int64_t getVmTotalCpuTimeWhenStartupStateEntered() const { return _vmTotalCpuTimeWhenStartupStateEntered; }248249void setVmTotalCpuTimeWhenStartupStateExited(int64_t n) { _vmTotalCpuTimeWhenStartupStateExited = n; }250int64_t getVmTotalCpuTimeWhenStartupStateExited() const { return _vmTotalCpuTimeWhenStartupStateExited; }251252void setInliningAggressiveness(int32_t n) { _inliningAggressiveness = n; }253int32_t getInliningAggressiveness() const { return _inliningAggressiveness; }254255uint64_t getLastTimeSamplerThreadEnteredIdle() const { return _lastTimeSamplerThreadEnteredIdle; }256void setLastTimeSamplerThreadEnteredIdle(uint64_t t) { _lastTimeSamplerThreadEnteredIdle = t; }257258uint64_t getLastTimeSamplerThreadEnteredDeepIdle() const { return _lastTimeSamplerThreadEnteredDeepIdle; }259void setLastTimeSamplerThreadEnteredDeepIdle(uint64_t t) { _lastTimeSamplerThreadEnteredDeepIdle = t; }260261uint64_t getLastTimeThreadsWereActive() const { return _lastTimeThreadsWereActive; }262void setLastTimeThreadsWereActive(uint64_t t) { _lastTimeThreadsWereActive = t; }263264uint64_t getLastTimeSamplerThreadWasSuspended() const { return _lastTimeSamplerThreadWasSuspended; }265void setLastTimeSamplerThreadWasSuspended(uint64_t t) { _lastTimeSamplerThreadWasSuspended = t; }266267void setGCMapCheckEventHandle(uint32_t handle) {_gcMapCheckEventHandleKey = handle;}268uint32_t getGCMapCheckEventHandle() {return _gcMapCheckEventHandleKey;}269270int32_t getNumGCRBodies() const { return _statNumGCRBodies; }271int32_t getNumGCRSaves() const { return _statNumGCRSaves; }272273void incNumGCRBodies() { _statNumGCRBodies++; }274void incNumGCRSaves() { _statNumGCRSaves++; }275276TR_J2IThunkTable *getInvokeExactJ2IThunkTable(){ return _invokeExactJ2IThunkTable; } // NULL if the platform needs no thunks, so J2I helpers can be called directly277void setInvokeExactJ2IThunkTable(TR_J2IThunkTable *table){ _invokeExactJ2IThunkTable = table; }278279280TR_PersistentCHTable * getPersistentCHTable();281void setPersistentCHTable(TR_PersistentCHTable *table);282283TR_RuntimeAssumptionTable *getRuntimeAssumptionTable() { return &_runtimeAssumptionTable; }284285286TR::Monitor * getGpuInitializationMonitor() { return _gpuInitMonitor; }287void setGpuInitializationMonitor(TR::Monitor * gpuInitMonitor) {_gpuInitMonitor = gpuInitMonitor;}288289290bool isRuntimeInstrumentationEnabled() { return _runtimeInstrumentationEnabled; }291void setRuntimeInstrumentationEnabled(bool b)292{293_runtimeInstrumentationEnabled = b;294295// If RI is disabled, then the exploitations need to be disabled too296if (b == false)297{298_runtimeInstrumentationRecompilationEnabled = false;299}300}301302bool isRuntimeInstrumentationRecompilationEnabled() { return _runtimeInstrumentationEnabled && _runtimeInstrumentationRecompilationEnabled; }303void setRuntimeInstrumentationRecompilationEnabled(bool b)304{305if (_runtimeInstrumentationEnabled)306_runtimeInstrumentationRecompilationEnabled = b;307else308_runtimeInstrumentationRecompilationEnabled = false;309}310311312bool getInlinerTemporarilyRestricted() const { return _inlinerTemporarilyRestricted; }313void setInlinerTemporarilyRestricted(bool b) { _inlinerTemporarilyRestricted = b; }314315316bool isClassLoadingPhase() const {return _classLoadingPhase;}317void setClassLoadingPhase(bool b) {_classLoadingPhase = b;}318319int32_t getNumLoadedClasses() const { return _numLoadedClasses;}320uint64_t getElapsedTime() const { return _elapsedTime;}321322// these fields are mostly read, rarely written323/* _countForRecompile can be frequently accessed by *application threads*.324* If it is placed on a cache line that frequently gets updated, it will be constantly evicted,325* which can cause a significant performance peanalty.326*/327uint8_t _paddingBefore[128];328int32_t _countForRecompile;329330#if defined(J9VM_OPT_JITSERVER)331static JITServer::RemoteCompilationModes _remoteCompilationMode; // JITServer::NONE, JITServer::CLIENT, JITServer::SERVER332333static JITServer::RemoteCompilationModes getRemoteCompilationMode() { return _remoteCompilationMode; }334const std::string &getJITServerAddress() const { return _JITServerAddress; }335void setJITServerAddress(const char *addr) { _JITServerAddress = addr; }336uint32_t getSocketTimeout() const { return _socketTimeoutMs; }337void setSocketTimeout(uint32_t t) { _socketTimeoutMs = t; }338uint32_t getJITServerPort() const { return _JITServerPort; }339void setJITServerPort(uint32_t port) { _JITServerPort = port; }340uint64_t getClientUID() const { return _clientUID; }341void setClientUID(uint64_t val) { _clientUID = val; }342uint64_t getServerUID() const { return _serverUID; }343void setServerUID(uint64_t val) { _serverUID = val; }344bool getRequireJITServer() const { return _requireJITServer; }345void setRequireJITServer(bool requireJITServer) { _requireJITServer = requireJITServer; }346bool isLocalSyncCompiles() const { return _localSyncCompiles; }347void setLocalSyncCompiles(bool localSyncCompiles) { _localSyncCompiles = localSyncCompiles; }348bool getJITServerUseAOTCache() const { return _JITServerUseAOTCache; }349void setJITServerUseAOTCache(bool use) { _JITServerUseAOTCache = use; }350const std::string &getJITServerAOTCacheName() const { return _JITServerAOTCacheName; }351void setJITServerAOTCacheName(const char *name) { _JITServerAOTCacheName = name; }352#endif /* defined(J9VM_OPT_JITSERVER) */353354private:355TR_AddressSet *_unloadedClassAddresses;356TR_AddressSet *_unloadedMethodAddresses;357358TR_RuntimeAssumptionTable _runtimeAssumptionTable;359TR_PersistentCHTable *_persistentCHTable;360361TR_PersistentClassLoaderTable *_persistentClassLoaderTable;362363// these fields are RW364365TR_OpaqueClassBlock **_visitedSuperClasses;366int32_t _numVisitedSuperClasses;367bool _tooManySuperClasses;368369uint64_t _timeGCwillBlockOnClassUnloadMonitorWasSet; // ms; set by GC; RAS370bool _GCwillBlockOnClassUnloadMonitor;371372int32_t _classLoadingPhaseGracePeriod; // in ms373374uint64_t _startTime; // time when sampling thread started (ms)375376int32_t _numUnloadedClasses;377378int32_t _globalClassUnloadID; // incremented each time GC does a class unload379380bool _externalStartupEndedSignal; // the app will tell us when startup ends381382volatile bool _disableFurtherCompilation;383384uint32_t _loadFactor; // set in samplerThread; increases with active threads, decreases with CPUs385386uint8_t _jitState; // STARTUP IDLE RAMPUP STEADY387388uint32_t _jitTotalSampleCount; // similar to TR::Recompilation::globalSampleCount,389// but always incremented when jitMethodSampleInterrupt is called390391uint32_t _jitStateChangeSampleCount; // caches _jitTotalSampleCount when a state change has occurred392393uint32_t _jitSampleCountWhenActiveStateEntered; // set when we leave IDLE of STARTUP394395uint32_t _jitSampleCountWhenStartupStateEntered; // set when we enter STARTUP from another state396397uint32_t _jitSampleCountWhenStartupStateExited; // set when we exit STARTUP state398399int64_t _vmTotalCpuTimeWhenStartupStateEntered; // set when we enter STARTUP from another state400401int64_t _vmTotalCpuTimeWhenStartupStateExited; // set when we exit STARTUP state402403int32_t _inliningAggressiveness;404405// The following four fields are stored here for RAS purposes (easy access from a debugging session)406//407uint64_t _lastTimeSamplerThreadEnteredIdle; // used by samplerThread408uint64_t _lastTimeSamplerThreadEnteredDeepIdle;409uint64_t _lastTimeSamplerThreadWasSuspended;410uint64_t _lastTimeThreadsWereActive; // used by samplerThread411412uint32_t _gcMapCheckEventHandleKey;413414// Stats for GCR bodies generated and how many times we avoided generating a GCR body415//416int32_t _statNumGCRBodies;417int32_t _statNumGCRSaves;418419TR_J2IThunkTable *_invokeExactJ2IThunkTable;420421TR::Monitor *_gpuInitMonitor;422423bool _runtimeInstrumentationEnabled;424bool _runtimeInstrumentationRecompilationEnabled;425426bool _classLoadingPhase; ///< true, if we detect a large number of classes loaded per second427bool _inlinerTemporarilyRestricted; ///< do not inline when true; used to restrict cold inliner during startup428429volatile uint64_t _elapsedTime; ///< elapsed time as computed by the sampling thread (ms)430///< May need adjustment if sampling thread goes to sleep431432int32_t _numLoadedClasses; ///< always increasing433434#if defined(J9VM_OPT_JITSERVER)435std::string _JITServerAddress;436uint32_t _JITServerPort;437uint32_t _socketTimeoutMs; // timeout for communication sockets used in out-of-process JIT compilation438uint64_t _clientUID;439uint64_t _serverUID; // At the client, this represents the UID of the server the client is connected to440bool _requireJITServer;441bool _localSyncCompiles;442bool _JITServerUseAOTCache;443std::string _JITServerAOTCacheName; // Name of the server AOT cache that this client is using444#endif /* defined(J9VM_OPT_JITSERVER) */445};446447}448449#endif450451452