Path: blob/master/runtime/gc_verbose_handler_realtime/VerboseHandlerOutputRealtime.hpp
5985 views
/*******************************************************************************1* Copyright (c) 1991, 2020 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#if !defined(VERBOSEHANDLEROUTPUTREALTIME_HPP_)23#define VERBOSEHANDLEROUTPUTREALTIME_HPP_2425#include "j9.h"26#include "j9cfg.h"27#include "j9modron.h"28#include "mmhook.h"29#include "mmprivatehook.h"3031#include "VerboseHandlerOutput.hpp"32#include "GCExtensions.hpp"3334class MM_EnvironmentBase;3536class MM_VerboseHandlerOutputRealtime : public MM_VerboseHandlerOutput37{38private:39U_64 _verboseInitTimeStamp;4041/* Data for increments */42U_64 _heartbeatStartTime;43U_64 _incrementStartTime;4445UDATA _incrementCount;4647U_64 _maxIncrementTime;48U_64 _maxIncrementStartTime;49U_64 _minIncrementTime;50U_64 _totalIncrementTime;5152U_64 _maxHeapFree;53U_64 _minHeapFree;54U_64 _totalHeapFree;5556UDATA _classLoadersUnloadedTotal; /**< Sum of _classLoadersUnloaded from all events between two heartbeat verbose gc reports */57UDATA _classesUnloadedTotal; /**< Sum of _classesUnloaded from all events between two heartbeat verbose gc reports */58UDATA _anonymousClassesUnloadedTotal; /**< Sum of _anonymousClassesUnloaded from all events between two heartbeat verbose gc reports */5960UDATA _weakReferenceClearCountTotal; /**< Number of weak references between two heartbeats (total of all quantas) */61UDATA _softReferenceClearCountTotal; /**< Number of soft references between two heartbeats (total of all quantas) */62UDATA _softReferenceThreshold; /**< the max soft reference threshold */63UDATA _dynamicSoftReferenceThreshold; /**< the dynamic soft reference threshold */64UDATA _phantomReferenceClearCountTotal; /**< Number of phantom references between two heartbeats (total of all quantas) */6566UDATA _finalizableCountTotal; /**< Number of finalizable objects between two heartbeats (total of all quantas) */6768UDATA _workPacketOverflowCountTotal; /**< Sum of _workPacketCount from all events between two heartbeat verbose gc reports */69UDATA _objectOverflowCountTotal; /**< Sum of _objectOverflowCount from all events between two heartbeat verbose gc reports */7071UDATA _nonDeterministicSweepTotal; /**< Number of non deterministic sweeps between two heartbeats (total of all quantas) */72UDATA _nonDeterministicSweepConsecutiveMax; /**< The maximum of all longest streaks, between two heartbeats */73U_64 _nonDeterministicSweepDelayMax; /**< The longest delay caused by non deterministic sweep among all allocs between two heartbeats */7475U_64 _maxExclusiveAccessTime; /**< The maximum time (of all events of the chain) GC main thread spent stopping mutators */76U_64 _minExclusiveAccessTime; /**< The minimum time (of all events of the chain) GC main thread spent stopping mutators */77U_64 _totalExclusiveAccessTime; /**< The average time (of all events of the chain) GC main thread spent stopping mutators */7879UDATA _maxStartPriority; /**< The maximum start priority of all increments in the event chain. Only used for the last event in the chain. */80UDATA _minStartPriority; /**< The minimum start priority of all increments in the event chain. Only used for the last event in the chain. */8182typedef enum {83INACTIVE = 0,84PRE_COLLECT,85MARK,86CLASS_UNLOAD,87SWEEP,88POST_COLLECT89} GCPhase;9091GCPhase _gcPhase; /**< Current GC phase. */92GCPhase _previousGCPhase; /**< The GC phase at the start of the current increment. Different from the current gcPhase if current increment spans across more than one gc phase. */9394/* Data for sync GC*/95bool _syncGCTriggered; /**< Have we in a sync GC cycle right now? */96U_64 _syncGCStartTime; /**< The start time of a sync GC */97GCReason _syncGCReason; /**< The code for cause of the sync GC */98UDATA _syncGCReasonParameter; /**< Additional info for the sync GC */99U_64 _syncGCExclusiveAccessTime; /**< The exclusive access time of a sync GC */100UDATA _syncGCStartHeapFree; /**< The free heap at the start of a sync GC */101UDATA _syncGCStartImmortalFree; /**< The free immortal space at the start of a sync GC */102UDATA _syncGCStartClassLoadersUnloaded; /**< The unloaded class loader count at the start of a sync GC */103UDATA _syncGCStartClassesUnloaded; /**< The unloaded class count at the start of a sync GC */104UDATA _syncGCStartAnonymousClassesUnloaded; /**< The unloaded anonymous class count at the start of a sync GC */105106protected:107J9HookInterface** _mmHooks; /**< Pointers to the Hook interface */108109public:110111private:112void resetHeartbeatStats()113{114_heartbeatStartTime = 0;115_incrementStartTime = 0;116_incrementCount = 0;117_maxIncrementTime = 0;118_maxIncrementStartTime = 0;119_minIncrementTime = (U_64)-1;120_totalIncrementTime = 0;121_maxHeapFree = 0;122_minHeapFree = (UDATA)-1;123_totalHeapFree = 0;124_classLoadersUnloadedTotal = 0;125_classesUnloadedTotal = 0;126_anonymousClassesUnloadedTotal = 0;127_weakReferenceClearCountTotal = 0;128_softReferenceClearCountTotal = 0;129_dynamicSoftReferenceThreshold = 0;130_softReferenceThreshold = 0;131_phantomReferenceClearCountTotal = 0;132_finalizableCountTotal = 0;133_workPacketOverflowCountTotal = 0;134_objectOverflowCountTotal = 0;135_nonDeterministicSweepTotal = 0;136_nonDeterministicSweepConsecutiveMax = 0;137_nonDeterministicSweepDelayMax = 0;138_maxExclusiveAccessTime = 0;139_minExclusiveAccessTime = (UDATA)-1;140_totalExclusiveAccessTime = 0;141_maxStartPriority = 0;142_minStartPriority = (UDATA)-1;143}144145void resetSyncGCStats()146{147_syncGCTriggered = false;148_syncGCStartTime = 0;149_syncGCReason = UNKOWN_REASON;150_syncGCReasonParameter = 0;151_syncGCExclusiveAccessTime = 0;152_syncGCStartHeapFree = 0;153_syncGCStartImmortalFree = 0;154_syncGCStartClassLoadersUnloaded = 0;155_syncGCStartClassesUnloaded = 0;156_syncGCStartAnonymousClassesUnloaded = 0;157}158159const char *160getGCPhaseAsString(GCPhase gcPhase)161{162switch(gcPhase) {163case PRE_COLLECT:164return "precollect";165case MARK:166return "mark";167case CLASS_UNLOAD:168return "classunload";169case SWEEP:170return "sweep";171case POST_COLLECT:172return "postcollect";173default:174return "unknown";175}176}177178/**179* Answers whether the current increment spans more than one GC phase.180*/181bool182incrementStartsInPreviousGCPhase()183{184return (_gcPhase != _previousGCPhase);185}186187protected:188189/**190* Answer a string representation of a given cycle type.191* @param[IN] cycle type192* @return string representing the human readable "type" of the cycle.193*/194virtual const char *getCycleType(UDATA type);195virtual void outputInitializedInnerStanza(MM_EnvironmentBase *env, MM_VerboseBuffer *buffer);196197MM_VerboseHandlerOutputRealtime(MM_GCExtensions *extensions) :198MM_VerboseHandlerOutput(extensions),199_verboseInitTimeStamp(0),200_heartbeatStartTime(0),201_incrementStartTime(0),202_incrementCount(0),203_maxIncrementTime(0),204_maxIncrementStartTime(0),205_minIncrementTime((U_64)-1),206_totalIncrementTime(0),207_maxHeapFree(0),208_minHeapFree((UDATA)-1),209_totalHeapFree(0),210_classLoadersUnloadedTotal(0),211_classesUnloadedTotal(0),212_anonymousClassesUnloadedTotal(0),213_weakReferenceClearCountTotal(0),214_softReferenceClearCountTotal(0),215_softReferenceThreshold(0),216_dynamicSoftReferenceThreshold(0),217_phantomReferenceClearCountTotal(0),218_finalizableCountTotal(0),219_workPacketOverflowCountTotal(0),220_objectOverflowCountTotal(0),221_nonDeterministicSweepTotal(0),222_nonDeterministicSweepConsecutiveMax(0),223_nonDeterministicSweepDelayMax(0),224_maxExclusiveAccessTime(0),225_minExclusiveAccessTime((UDATA)-1),226_totalExclusiveAccessTime(0),227_maxStartPriority(0),228_minStartPriority((UDATA)-1),229_gcPhase(INACTIVE),230_previousGCPhase(INACTIVE),231_syncGCTriggered(false),232_syncGCStartTime(0),233_syncGCReason(UNKOWN_REASON),234_syncGCReasonParameter(0),235_syncGCExclusiveAccessTime(0),236_syncGCStartHeapFree(0),237_syncGCStartImmortalFree(0),238_syncGCStartClassLoadersUnloaded(0),239_syncGCStartClassesUnloaded(0),240_syncGCStartAnonymousClassesUnloaded(0),241_mmHooks(NULL)242{};243244virtual bool initialize(MM_EnvironmentBase *env, MM_VerboseManager *manager);245virtual void tearDown(MM_EnvironmentBase *env);246247virtual bool getThreadName(char *buf, UDATA bufLen, OMR_VMThread *vmThread);248virtual void writeVmArgs(MM_EnvironmentBase* env, MM_VerboseBuffer* buffer);249250public:251static MM_VerboseHandlerOutput *newInstance(MM_EnvironmentBase *env, MM_VerboseManager *manager);252253void handleCycleStart(J9HookInterface** hook, UDATA eventNum, void* eventData);254void handleCycleEnd(J9HookInterface** hook, UDATA eventNum, void* eventData);255256void handleEvent(MM_MetronomeIncrementStartEvent* eventData);257void handleEvent(MM_MetronomeIncrementEndEvent* eventData);258void handleEvent(MM_MetronomeSynchronousGCStartEvent* eventData);259void handleEvent(MM_MetronomeSynchronousGCEndEvent* eventData);260void handleEvent(MM_MarkStartEvent* eventData);261void handleEvent(MM_MarkEndEvent* eventData);262void handleEvent(MM_SweepStartEvent* eventData);263void handleEvent(MM_SweepEndEvent* eventData);264void handleEvent(MM_ClassUnloadingStartEvent* eventData);265void handleEvent(MM_ClassUnloadingEndEvent* eventData);266void handleEvent(MM_OutOfMemoryEvent* eventData);267void handleEvent(MM_UtilizationTrackerOverflowEvent* eventData);268void handleEvent(MM_NonMonotonicTimeEvent* eventData);269270void writeHeartbeatData(MM_EnvironmentBase* env, U_64 timestamp);271void writeHeartbeatDataAndResetHeartbeatStats(MM_EnvironmentBase* env, U_64 timestamp);272273virtual void enableVerbose();274virtual void disableVerbose();275};276277#endif /* VERBOSEHANDLEROUTPUTREALTIME_HPP_ */278279280