Path: blob/master/runtime/gc_trace/TgcConcurrent.cpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2018 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 "j9port.h"27#include "modronopt.h"2829#if defined(OMR_GC_MODRON_CONCURRENT_MARK)30#include "GCExtensions.hpp"31#include "EnvironmentBase.hpp"32#include "TgcExtensions.hpp"3334/**35* Concurrent background thread activated.36* Function called by a hook when the concurrent background thread is started.37*38* @param env The environment of the background thread39*/40static void41tgcHookConcurrentBackgroundThreadActivated(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)42{43MM_ConcurrentBackgroundThreadActivatedEvent* event = (MM_ConcurrentBackgroundThreadActivatedEvent*)eventData;44MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(event->currentThread);45MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);46TgcConcurrentExtensions *concurrentExtensions = &tgcExtensions->_concurrent;4748concurrentExtensions->gcCountAtBackgroundThreadActivation =49#if defined(J9VM_GC_MODRON_SCAVENGER)50extensions->scavengerStats._gcCount +51#endif /* J9VM_GC_MODRON_SCAVENGER */52extensions->globalGCStats.gcCount;5354tgcExtensions->printf("<CONCURRENT GC BK thread 0x%08.8zx activated after GC(%zu)>\n",55event->currentThread->_language_vmthread,56concurrentExtensions->gcCountAtBackgroundThreadActivation57);58}5960/**61* Concurrent background thread finished.62* Function called by a hook when the concurrent background thread is finished.63*64* @param env The environment of the background thread65* @param traceTotal The number of bytes traced by the background thread during concurrent mark66*/67static void68tgcHookConcurrentBackgroundThreadFinished(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)69{70MM_ConcurrentBackgroundThreadFinishedEvent* event = (MM_ConcurrentBackgroundThreadFinishedEvent*)eventData;71MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(event->currentThread);72MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);73TgcConcurrentExtensions *concurrentExtensions = &tgcExtensions->_concurrent;7475tgcExtensions->printf("<CONCURRENT GC BK thread 0x%08.8zx (started after GC(%zu)) traced %zu>\n",76event->currentThread->_language_vmthread,77concurrentExtensions->gcCountAtBackgroundThreadActivation,78event->traceTotal79);80}8182/**83* Initialize concurrent tgc tracing.84* Initializes the TgcConcurrentExtensions object associated with concurrent tgc tracing. Attaches hooks85* to the appropriate functions handling events used by concurrent tgc tracing.86*/87bool88tgcConcurrentInitialize(J9JavaVM *javaVM)89{90MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);91bool result = true;9293J9HookInterface** privateHooks = J9_HOOK_INTERFACE(extensions->privateHookInterface);94(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_CONCURRENT_BACKGROUND_THREAD_ACTIVATED, tgcHookConcurrentBackgroundThreadActivated, OMR_GET_CALLSITE(), NULL);95(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_CONCURRENT_BACKGROUND_THREAD_FINISHED, tgcHookConcurrentBackgroundThreadFinished, OMR_GET_CALLSITE(), NULL);9697return result;98}99100#endif /* OMR_GC_MODRON_CONCURRENT_MARK */101102103