Path: blob/master/runtime/gc_trace_standard/TgcCompaction.cpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2020 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 "mmhook.h"26#include "gcutils.h"27#include "j9port.h"28#include "modronopt.h"29#include "j9modron.h"3031#include <math.h>3233#if defined(J9VM_GC_MODRON_COMPACTION)3435#include "EnvironmentBase.hpp"36#include "GCExtensions.hpp"37#include "CompactStats.hpp"38#include "TgcExtensions.hpp"39#include "VMThreadListIterator.hpp"4041/**42* Function called by a hook when the compaction is done.43*44* @param env The environment of the background thread45*/46static void47tgcHookCompactEnd(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)48{49MM_CompactEndEvent* event = (MM_CompactEndEvent*)eventData;50OMR_VMThread *omrVMThread = event->omrVMThread;51J9VMThread *vmThread = (J9VMThread *)MM_EnvironmentBase::getEnvironment(omrVMThread)->getLanguageVMThread();52MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(omrVMThread->_vm);53MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(vmThread);54J9VMThread *walkThread;55PORT_ACCESS_FROM_VMC(vmThread);56CompactReason reason = extensions->globalGCStats.compactStats._compactReason;57UDATA gcCount = extensions->globalGCStats.gcCount;5859tgcExtensions->printf("Compact(%zu): reason = %zu (%s)\n", gcCount, reason, getCompactionReasonAsString(reason));6061UDATA movedObjectsTotal = 0;62UDATA movedObjectsMin = UDATA_MAX;63UDATA movedObjectsMax = 0;6465UDATA movedBytesTotal = 0;66UDATA movedBytesMin = UDATA_MAX;67UDATA movedBytesMax = 0;6869UDATA fixupTotal = 0;70UDATA fixupMin = UDATA_MAX;71UDATA fixupMax = 0;7273UDATA threadCount = 0;7475/* walk the threads first to determine some of the stats -- we need these for the standard deviation */76GC_VMThreadListIterator compactionThreadListIterator(vmThread);77while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {78MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(walkThread->omrVMThread);79if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {80MM_CompactStats *stats = &env->_compactStats;8182movedObjectsTotal += stats->_movedObjects;83movedObjectsMin = OMR_MIN(stats->_movedObjects, movedObjectsMin);84movedObjectsMax = OMR_MAX(stats->_movedObjects, movedObjectsMax);8586movedBytesTotal += stats->_movedBytes;87movedBytesMin = OMR_MIN(stats->_movedBytes, movedBytesMin);88movedBytesMax = OMR_MAX(stats->_movedBytes, movedBytesMax);8990fixupTotal += stats->_fixupObjects;91fixupMin = OMR_MIN(stats->_fixupObjects, fixupMin);92fixupMax = OMR_MAX(stats->_fixupObjects, fixupMax);9394threadCount += 1;95}96}9798double movedObjectsMean = (double)movedObjectsTotal / (double)threadCount;99double movedBytesMean = (double)movedBytesTotal / (double)threadCount;100double fixupMean = (double)fixupTotal / (double)threadCount;101102double movedObjectsSquareSum = 0.0;103double movedBytesSquareSum = 0.0;104double fixupSquareSum = 0.0;105106compactionThreadListIterator = GC_VMThreadListIterator(vmThread);107while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {108/* TODO: Are we guaranteed to get the threads in the right order? */109MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(walkThread->omrVMThread);110if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {111MM_CompactStats *stats = &env->_compactStats;112UDATA workerID = env->getWorkerID();113114tgcExtensions->printf("Compact(%zu): Thread %zu, setup stage: %llu ms.\n",115gcCount, workerID, j9time_hires_delta(stats->_setupStartTime, stats->_setupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));116tgcExtensions->printf("Compact(%zu): Thread %zu, move stage: handled %zu objects in %llu ms, bytes moved %zu.\n",117gcCount, workerID, stats->_movedObjects,118j9time_hires_delta(stats->_moveStartTime, stats->_moveEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS), stats->_movedBytes);119tgcExtensions->printf("Compact(%zu): Thread %zu, fixup stage: handled %zu objects in %zu ms, root fixup time %zu ms.\n",120gcCount, workerID, stats->_fixupObjects,121j9time_hires_delta(stats->_fixupStartTime, stats->_fixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS),122j9time_hires_delta(stats->_rootFixupStartTime, stats->_rootFixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));123124double movedObjectsDelta = (double)stats->_movedObjects - movedObjectsMean;125movedObjectsSquareSum += movedObjectsDelta * movedObjectsDelta;126double movedBytesDelta = (double)stats->_movedBytes - movedBytesMean;127movedBytesSquareSum += movedBytesDelta * movedBytesDelta;128double fixupDelta = (double)stats->_fixupObjects - fixupMean;129fixupSquareSum += fixupDelta * fixupDelta;130}131}132133tgcExtensions->printf("Compact(%zu): Summary, move stage: handled %zu (min=%zu, max=%zu, stddev=%.2f) objects, bytes moved %zu (min=%zu, max=%zu, stddev=%.2f).\n",134gcCount,135movedObjectsTotal, movedObjectsMin, movedObjectsMax, sqrt(movedObjectsSquareSum / threadCount),136movedBytesTotal, movedBytesMin, movedBytesMax, sqrt(movedBytesSquareSum / threadCount));137tgcExtensions->printf("Compact(%zu): Summary, fixup stage: handled %zu (min=%zu, max=%zu, stddev=%.2f) objects.\n",138gcCount,139fixupTotal, fixupMin, fixupMax, sqrt(fixupSquareSum / threadCount));140141}142143144/**145* Initialize compaction tgc tracing.146* Initializes the TgcCompactionExtensions object associated with concurrent tgc tracing. Attaches hooks147* to the appropriate functions handling events used by concurrent tgc tracing.148*/149bool150tgcCompactionInitialize(J9JavaVM *javaVM)151{152MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);153bool result = true;154155J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);156(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_COMPACT_END, tgcHookCompactEnd, OMR_GET_CALLSITE(), NULL);157158return result;159}160161#endif /* J9VM_GC_MODRON_COMPACTION */162163164165