Path: blob/master/runtime/gc_trace/TgcBacktrace.cpp
5985 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 "mmhook.h"26#include "j9port.h"27#include "modronopt.h"2829#include "GCExtensions.hpp"30#include "TgcExtensions.hpp"3132/**33* @todo Provide function documentation34*/35static void36printVMThreadInformation(J9VMThread *vmThread)37{38MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(vmThread);39char *threadName = getOMRVMThreadName(vmThread->omrVMThread);40if (threadName) {41tgcExtensions->printf("\"%s\" (0x%p)\n", threadName, vmThread->osThread);42}43releaseOMRVMThreadName(vmThread->omrVMThread);44}4546/**47* Print J9VMThread information at local garbage collection.48* Hooked by: J9HOOK_MM_OMR_LOCAL_GC_START49*/50static void51tgcHookLocalGcStart(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)52{53MM_LocalGCStartEvent* event = (MM_LocalGCStartEvent*)eventData;54printVMThreadInformation((J9VMThread *)event->currentThread->_language_vmthread);55}5657/**58* @todo Provide function documentation59*/60static void61tgcHookGlobalGcStart(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)62{63MM_GlobalGCStartEvent* event = (MM_GlobalGCStartEvent*)eventData;64printVMThreadInformation((J9VMThread*)event->currentThread->_language_vmthread);65}6667/**68* Initialize MM_TgcExtensions object fields.69* Initialize the backtrace fields of the MM_TgcExtensions object.70*/71bool72tgcBacktraceInitialize(J9JavaVM *javaVM)73{74MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);75bool result = true;7677J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);78(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_LOCAL_GC_START, tgcHookLocalGcStart, OMR_GET_CALLSITE(), NULL);79(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_GLOBAL_GC_START, tgcHookGlobalGcStart, OMR_GET_CALLSITE(), NULL);8081return result;82}838485