Path: blob/master/runtime/gc_trace_vlhgc/TgcWriteOnceCompaction.cpp
5986 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 "EnvironmentVLHGC.hpp"36#include "GCExtensions.hpp"37#include "CompactVLHGCStats.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;55CompactReason reason = extensions->globalGCStats.compactStats._compactReason;56UDATA gcCount = extensions->globalGCStats.gcCount;5758PORT_ACCESS_FROM_VMC(vmThread);5960tgcExtensions->printf("Compact(%zu): reason = %zu (%s)\n", gcCount, reason, getCompactionReasonAsString(reason));6162UDATA movedObjectsTotal = 0;63UDATA movedObjectsMin = UDATA_MAX;64UDATA movedObjectsMax = 0;6566UDATA movedBytesTotal = 0;67UDATA movedBytesMin = UDATA_MAX;68UDATA movedBytesMax = 0;6970UDATA fixupTotal = 0;71UDATA fixupMin = UDATA_MAX;72UDATA fixupMax = 0;7374UDATA threadCount = 0;7576/* walk the threads first to determine some of the stats -- we need these for the standard deviation */77GC_VMThreadListIterator compactionThreadListIterator(vmThread);78while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {79MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment(walkThread);80if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {81MM_CompactVLHGCStats *stats = &env->_compactVLHGCStats;8283movedObjectsTotal += stats->_movedObjects;84movedObjectsMin = OMR_MIN(stats->_movedObjects, movedObjectsMin);85movedObjectsMax = OMR_MAX(stats->_movedObjects, movedObjectsMax);8687movedBytesTotal += stats->_movedBytes;88movedBytesMin = OMR_MIN(stats->_movedBytes, movedBytesMin);89movedBytesMax = OMR_MAX(stats->_movedBytes, movedBytesMax);9091fixupTotal += stats->_fixupObjects;92fixupMin = OMR_MIN(stats->_fixupObjects, fixupMin);93fixupMax = OMR_MAX(stats->_fixupObjects, fixupMax);9495threadCount += 1;96}97}9899double movedObjectsMean = (double)movedObjectsTotal / (double)threadCount;100double movedBytesMean = (double)movedBytesTotal / (double)threadCount;101double fixupMean = (double)fixupTotal / (double)threadCount;102103double movedObjectsSquareSum = 0.0;104double movedBytesSquareSum = 0.0;105double fixupSquareSum = 0.0;106107compactionThreadListIterator = GC_VMThreadListIterator(vmThread);108while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {109/* TODO: Are we guaranteed to get the threads in the right order? */110MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment(walkThread);111if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {112MM_CompactVLHGCStats *stats = &env->_compactVLHGCStats;113UDATA workerID = env->getWorkerID();114115tgcExtensions->printf("Compact(%zu): Thread %zu, setup stage: %llu ms.\n",116gcCount, workerID, j9time_hires_delta(stats->_setupStartTime, stats->_setupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));117tgcExtensions->printf("Compact(%zu): Thread %zu, move stage: handled %zu objects in %llu ms, bytes moved %zu.\n",118gcCount, workerID, stats->_movedObjects,119j9time_hires_delta(stats->_moveStartTime, stats->_moveEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS), stats->_movedBytes);120tgcExtensions->printf("Compact(%zu): Thread %zu, fixup stage: handled %zu objects in %zu ms, root fixup time %zu ms.\n",121gcCount, workerID, stats->_fixupObjects,122j9time_hires_delta(stats->_fixupStartTime, stats->_fixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS),123j9time_hires_delta(stats->_rootFixupStartTime, stats->_rootFixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));124125double movedObjectsDelta = (double)stats->_movedObjects - movedObjectsMean;126movedObjectsSquareSum += movedObjectsDelta * movedObjectsDelta;127double movedBytesDelta = (double)stats->_movedBytes - movedBytesMean;128movedBytesSquareSum += movedBytesDelta * movedBytesDelta;129double fixupDelta = (double)stats->_fixupObjects - fixupMean;130fixupSquareSum += fixupDelta * fixupDelta;131}132}133134tgcExtensions->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",135gcCount,136movedObjectsTotal, movedObjectsMin, movedObjectsMax, sqrt(movedObjectsSquareSum / threadCount),137movedBytesTotal, movedBytesMin, movedBytesMax, sqrt(movedBytesSquareSum / threadCount));138tgcExtensions->printf("Compact(%zu): Summary, fixup stage: handled %zu (min=%zu, max=%zu, stddev=%.2f) objects.\n",139gcCount,140fixupTotal, fixupMin, fixupMax, sqrt(fixupSquareSum / threadCount));141142}143144145/**146* Initialize compaction tgc tracing.147* Initializes the TgcCompactionExtensions object associated with concurrent tgc tracing. Attaches hooks148* to the appropriate functions handling events used by concurrent tgc tracing.149*/150bool151tgcWriteOnceCompactionInitialize(J9JavaVM *javaVM)152{153MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);154bool result = true;155156J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);157(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_COMPACT_END, tgcHookCompactEnd, OMR_GET_CALLSITE(), NULL);158159return result;160}161162#endif /* J9VM_GC_MODRON_COMPACTION */163164165166