Path: blob/master/runtime/gc_trace/TgcCardCleaning.cpp
5985 views
/*******************************************************************************1* Copyright (c) 1991, 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#include "j9.h"23#include "j9cfg.h"24#include "mmhook.h"25#include "TgcCardCleaning.hpp"2627#if defined(J9VM_GC_HEAP_CARD_TABLE)2829#include "EnvironmentBase.hpp"30#include "GCExtensions.hpp"31#include "TgcExtensions.hpp"32#include "VMThreadListIterator.hpp"3334static void printCardCleaningStats(OMR_VMThread *omrVMThread);35static void tgcHookGlobalGcCycleEnd(J9HookInterface** hook, UDATA eventNumber, void* eventData, void* userData);3637UDATA38tgcCardCleaningInitialize(J9JavaVM *javaVM)39{40MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);4142J9HookInterface** mmOmrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);43(*mmOmrHooks)->J9HookRegisterWithCallSite(mmOmrHooks, J9HOOK_MM_OMR_GC_CYCLE_END, tgcHookGlobalGcCycleEnd, OMR_GET_CALLSITE(), NULL);4445return 0;46}4748static void49printCardCleaningStats(OMR_VMThread *omrVMThread)50{51J9VMThread *currentThread = (J9VMThread *)MM_EnvironmentBase::getEnvironment(omrVMThread)->getLanguageVMThread();52MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(currentThread);53PORT_ACCESS_FROM_VMC(currentThread);54OMRPORT_ACCESS_FROM_J9PORT(PORTLIB);55char timestamp[32];5657U_64 totalTime = 0;58UDATA totalCardsCleaned = 0;5960omrstr_ftime_ex(timestamp, sizeof(timestamp), "%b %d %H:%M:%S %Y", j9time_current_time_millis(), OMRSTR_FTIME_FLAG_LOCAL);61tgcExtensions->printf("<cardcleaning timestamp=\"%s\">\n", timestamp);6263GC_VMThreadListIterator threadIterator(currentThread);64J9VMThread* thread = NULL;65while (NULL != (thread = threadIterator.nextVMThread())) {66MM_EnvironmentBase* env = MM_EnvironmentBase::getEnvironment(thread->omrVMThread);6768if ((GC_WORKER_THREAD == env->getThreadType()) || (thread == currentThread)) {69U_64 cleanTimeInMicros = j9time_hires_delta(0, env->_cardCleaningStats._cardCleaningTime, J9PORT_TIME_DELTA_IN_MICROSECONDS);70tgcExtensions->printf("\t<thread id=\"%zu\" cardcleaningtime=\"%llu.%03.3llu\" cardscleaned=\"%zu\" />\n",71env->getWorkerID(),72cleanTimeInMicros / 1000,73cleanTimeInMicros % 1000,74env->_cardCleaningStats._cardsCleaned);7576totalTime += env->_cardCleaningStats._cardCleaningTime;77totalCardsCleaned += env->_cardCleaningStats._cardsCleaned;7879/* Clear card cleaning statistics collected for this thread, so data printed during this pass will not be duplicated */80env->_cardCleaningStats.clear();81}82}8384/* Print totals for each root scanner entity */85U_64 totalTimeInMicros = j9time_hires_delta(0, totalTime, J9PORT_TIME_DELTA_IN_MICROSECONDS);86tgcExtensions->printf("\t<total cardcleaningtime=\"%llu.%03.3llu\" cardscleaned=\"%zu\" />\n",87totalTimeInMicros / 1000,88totalTimeInMicros % 1000,89totalCardsCleaned);9091tgcExtensions->printf("</cardcleaning>\n");92}9394static void95tgcHookGlobalGcCycleEnd(J9HookInterface** hook, UDATA eventNumber, void* eventData, void* userData)96{97MM_GCCycleEndEvent* event = (MM_GCCycleEndEvent*) eventData;9899printCardCleaningStats(event->omrVMThread);100}101102#endif /* defined(J9VM_GC_HEAP_CARD_TABLE) */103104105