Path: blob/master/runtime/gc_trace_vlhgc/TgcProjectedStats.cpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2017 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* 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-exception21*******************************************************************************/2223#include "j9.h"24#include "j9cfg.h"25#include "j9port.h"26#include "Tgc.hpp"27#include "mmhook.h"2829#include <string.h>3031#include "Base.hpp"32#include "CollectionSetDelegate.hpp"33#include "CompactGroupManager.hpp"34#include "CompactGroupPersistentStats.hpp"35#include "EnvironmentVLHGC.hpp"36#include "GCExtensions.hpp"37#include "TgcExtensions.hpp"38#include "HeapRegionIteratorVLHGC.hpp"39#include "HeapRegionDescriptorVLHGC.hpp"40#include "HeapRegionManager.hpp"4142static void reportCompactGroupStats(MM_EnvironmentVLHGC *env);43static void decayPrintValue(MM_EnvironmentVLHGC *env, UDATA value);44static void printPercentage(MM_EnvironmentVLHGC *env, double value);45static void reportAverageAbsoluteDeviationForCompactGroups(MM_EnvironmentVLHGC *env);4647static void48decayPrintValue(MM_EnvironmentVLHGC *env, UDATA value)49{50MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(MM_GCExtensions::getExtensions(env));5152char unitTable[] = { 'b', 'k', 'm', 'g', 't', 'p', 'e' };53char *units = &(unitTable[0]);54UDATA result = value;55UDATA remainder = 0;5657while(result >= 1024) {58remainder = result % 1024;59result /= 1024;60units += 1;61}6263if(result >= 100) {64tgcExtensions->printf("%4zu%c", result, *units);65} else if (result >= 10) {66UDATA decimal = (remainder * 10) / 1024;67tgcExtensions->printf("%2zu.%1.1zu%c", result, decimal, *units);68} else {69if(0 == result) {70tgcExtensions->printf(" 0");71} else {72UDATA decimal = (remainder * 100) / 1024;73tgcExtensions->printf("%1zu.%2.2zu%c", result, decimal, *units);74}75}76}7778static void79printPercentage(MM_EnvironmentVLHGC *env, double value)80{81MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(MM_GCExtensions::getExtensions(env));8283tgcExtensions->printf("%4zu%%", (UDATA)(100.0 * value));84}8586/**87* Report dynamic collection set statistics for PGC.88*/89static void90tgcHookReportProjectedStatsStatistics(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)91{92MM_VlhgcGarbageCollectCompletedEvent* event = (MM_VlhgcGarbageCollectCompletedEvent*)eventData;93MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment(event->currentThread);94MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);95MM_CompactGroupPersistentStats *persistentStats = extensions->compactGroupPersistentStats;9697MM_CompactGroupPersistentStats::deriveProjectedLiveBytesStats(env, persistentStats);9899reportCompactGroupStats(env);100reportAverageAbsoluteDeviationForCompactGroups(env);101}102103/* Calculate the absolute deviation of the regions in every compact group */104static void105reportAverageAbsoluteDeviationForCompactGroups(MM_EnvironmentVLHGC *env)106{107MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);108MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);109MM_HeapRegionManager *heapRegionManager = extensions->getHeap()->getHeapRegionManager();110MM_CompactGroupPersistentStats *persistentStats = extensions->compactGroupPersistentStats;111UDATA regionSize = heapRegionManager->getRegionSize();112UDATA compactGroupCount = MM_CompactGroupManager::getCompactGroupMaxCount(env);113UDATA totalAbsoluteDeviation = 0;114UDATA totalRegionCount = 0;115116tgcExtensions->printf("\nCmpt Grp ");117for(UDATA tableIndex = 0; tableIndex <= extensions->tarokRegionMaxAge; tableIndex++) {118tgcExtensions->printf(" %5zu", tableIndex);119}120121tgcExtensions->printf(" all");122123tgcExtensions->printf("\n ");124for(UDATA tableIndex = 0; tableIndex <= extensions->tarokRegionMaxAge; tableIndex++) {125tgcExtensions->printf("------");126}127128129130for(UDATA compactGroupIndex = 0; compactGroupIndex < compactGroupCount; compactGroupIndex++) {131if (MM_CompactGroupManager::getRegionAgeFromGroup(env, compactGroupIndex) == 0) {132tgcExtensions->printf("\nAvAbDv ");133UDATA allocationContextNumber = MM_CompactGroupManager::getAllocationContextNumberFromGroup(env, compactGroupIndex);134if (0 == allocationContextNumber) {135tgcExtensions->printf(" ");136} else {137tgcExtensions->printf("AC%2zu", allocationContextNumber);138}139}140141UDATA liveBytesAbsoluteDeviation = persistentStats[compactGroupIndex]._liveBytesAbsoluteDeviation;142UDATA regionCount = persistentStats[compactGroupIndex]._regionCount;143144if (0 != regionCount) {145double averageAbsoluteDeviation = (double)liveBytesAbsoluteDeviation / (double)regionCount;146double averageAbsoluteDeviationInRegionSize = averageAbsoluteDeviation / regionSize;147148totalAbsoluteDeviation += liveBytesAbsoluteDeviation;149totalRegionCount += regionCount;150151tgcExtensions->printf(" %.3f", averageAbsoluteDeviationInRegionSize);152} else {153tgcExtensions->printf(" NoRgn");154}155}156157if (0 != totalRegionCount) {158double totalAverageAbsoluteDeviation = (double)totalAbsoluteDeviation / (double)totalRegionCount;159double totalAverageAbsoluteDeviationInRegionSize = totalAverageAbsoluteDeviation / (double)regionSize;160tgcExtensions->printf(" %.3f", totalAverageAbsoluteDeviationInRegionSize);161} else {162tgcExtensions->printf(" NoRgn");163}164165tgcExtensions->printf("\n");166/* TODO: show distribution of regions vs their deviations */167}168169170static void171reportCompactGroupStats(MM_EnvironmentVLHGC *env)172{173MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);174MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);175MM_CompactGroupPersistentStats *persistentStats = extensions->compactGroupPersistentStats;176UDATA compactGroupCount = MM_CompactGroupManager::getCompactGroupMaxCount(env);177178/*179* Dump statistics to the TTY.180*/181tgcExtensions->printf("\n ");182for(UDATA tableIndex = 0; tableIndex <= extensions->tarokRegionMaxAge; tableIndex++) {183tgcExtensions->printf(" %5zu", tableIndex);184}185186tgcExtensions->printf("\n ");187for(UDATA tableIndex = 0; tableIndex <= extensions->tarokRegionMaxAge; tableIndex++) {188tgcExtensions->printf("------");189}190191for(UDATA compactGroupIndex = 0; compactGroupIndex < compactGroupCount; compactGroupIndex++) {192if (MM_CompactGroupManager::getRegionAgeFromGroup(env, compactGroupIndex) == 0) {193tgcExtensions->printf("\nPrLvB ");194UDATA allocationContextNumber = MM_CompactGroupManager::getAllocationContextNumberFromGroup(env, compactGroupIndex);195if (0 == allocationContextNumber) {196tgcExtensions->printf(" ");197} else {198tgcExtensions->printf("AC%2zu", allocationContextNumber);199}200201}202tgcExtensions->printf(" ");203decayPrintValue(env, persistentStats[compactGroupIndex]._projectedLiveBytes);204}205for(UDATA compactGroupIndex = 0; compactGroupIndex < compactGroupCount; compactGroupIndex++) {206if (MM_CompactGroupManager::getRegionAgeFromGroup(env, compactGroupIndex) == 0) {207tgcExtensions->printf("\nPrISR ");208UDATA allocationContextNumber = MM_CompactGroupManager::getAllocationContextNumberFromGroup(env, compactGroupIndex);209if (0 == allocationContextNumber) {210tgcExtensions->printf(" ");211} else {212tgcExtensions->printf("AC%2zu", allocationContextNumber);213}214}215tgcExtensions->printf(" ");216printPercentage(env, persistentStats[compactGroupIndex]._projectedInstantaneousSurvivalRate);217}218219tgcExtensions->printf("\n");220221}222223/**224* Initialize dynamic collection set tgc tracing.225* Attaches hooks to the appropriate functions handling events used by dynamic collection set tgc tracing.226*/227bool228tgcProjectedStatsInitialize(J9JavaVM *javaVM)229{230bool result = true;231MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);232233J9HookInterface** privateHooks = J9_HOOK_INTERFACE(extensions->privateHookInterface);234if (0 != (*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_VLHGC_GARBAGE_COLLECT_COMPLETED, tgcHookReportProjectedStatsStatistics, OMR_GET_CALLSITE(), NULL)) {235result = false;236}237238return result;239}240241242243244