Path: blob/master/runtime/gc_trace/TgcExcessivegc.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 "j9port.h"26#include "modronopt.h"27#include "mmhook.h"2829#include "GCExtensions.hpp"30#include "EnvironmentBase.hpp"31#include "TgcExtensions.hpp"3233/**34* Check for excessive GC.35* Function called by a hook when the collector checks for excessive GC36*37*/38static void39tgcHookExcessiveGCCheckGCActivity(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)40{41MM_ExcessiveGCCheckGCActivityEvent* event = (MM_ExcessiveGCCheckGCActivityEvent *)eventData;42MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(event->currentThread);4344tgcExtensions->printf("\texcessiveGC: gcid=\"%zu\" intimems=\"%llu.%03.3llu\" outtimems=\"%llu.%03.3llu\" percent=\"%2.2f\" averagepercent=\"%2.2f\" \n",45event->gcCount,46event->gcInTime / 1000,47event->gcInTime % 1000,48event->gcOutTime / 1000,49event->gcOutTime % 1000,50event->newGCPercent,51event->averageGCPercent);52}5354/**55* Excessive GC raised.56* Function called by a hook when the collector raises excessive GC condition.57*58*/59static void60tgcHookExcessiveGCCheckFreeSpace(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)61{62MM_ExcessiveGCCheckFreeSpaceEvent* event = (MM_ExcessiveGCCheckFreeSpaceEvent *)eventData;63MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(event->currentThread);6465tgcExtensions->printf("\texcessiveGC: gcid=\"%zu\" percentreclaimed=\"%2.2f\" freedelta=\"%zu\" activesize=\"%zu\" currentsize=\"%zu\" maxiumumsize=\"%zu\" \n",66event->gcCount,67event->reclaimedPercent,68event->freeMemoryDelta,69event->activeHeapSize,70event->currentHeapSize,71event->maximumHeapSize);72}7374/**75* Excessive GC raised.76* Function called by a hook when the collector raises excessive GC condition.77*78*/79static void80tgcHookExcessiveGCRaised(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)81{82MM_ExcessiveGCRaisedEvent* event = (MM_ExcessiveGCRaisedEvent *)eventData;83MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions((J9VMThread*)(event->currentThread->_language_vmthread));8485tgcExtensions->printf("\texcessiveGC: gcid=\"%zu\" percentreclaimed=\"%2.2f\" minimum=\"%2.2f\" excessive gc raised \n",86event->gcCount,87event->reclaimedPercent,88event->triggerPercent);89}9091/**92* Initialize excessive tgc tracing.93* Initializes the TgcExcessiveGCExtensions object associated with excessive GC tgc tracing. Attaches hooks94* to the appropriate functions handling events used by excessive GC tgc tracing.95*/96bool97tgcExcessiveGCInitialize(J9JavaVM *javaVM)98{99MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);100bool result = true;101102J9HookInterface** privateHooks = J9_HOOK_INTERFACE(extensions->privateHookInterface);103J9HookInterface** publicHooks = J9_HOOK_INTERFACE(extensions->hookInterface);104J9HookInterface** omrPublicHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);105(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_EXCESSIVEGC_CHECK_GC_ACTIVITY, tgcHookExcessiveGCCheckGCActivity, OMR_GET_CALLSITE(), NULL);106(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_EXCESSIVEGC_CHECK_FREE_SPACE, tgcHookExcessiveGCCheckFreeSpace, OMR_GET_CALLSITE(), NULL);107(*publicHooks)->J9HookRegisterWithCallSite(omrPublicHooks, J9HOOK_MM_OMR_EXCESSIVEGC_RAISED, tgcHookExcessiveGCRaised, OMR_GET_CALLSITE(), NULL);108109return result;110}111112113