Path: blob/master/runtime/gc_trace/TgcAllocation.cpp
5985 views
/*******************************************************************************1* Copyright (c) 1991, 2017 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 "j9port.h"25#include "modronopt.h"26#include "mmhook.h"2728#include "EnvironmentBase.hpp"29#include "GCExtensions.hpp"30#include "VMThreadListIterator.hpp"31#include "TLHAllocationInterface.hpp"32#include "TgcExtensions.hpp"33#include "TgcAllocation.hpp"34#include "HeapStats.hpp"3536static void37tgcAllocationPrintStats(OMR_VMThread* omrVMThread)38{39MM_GCExtensions *ext = MM_GCExtensions::getExtensions(omrVMThread);40MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(ext);4142MM_AllocationStats *allocStats = &ext->allocationStats;4344tgcExtensions->printf("---------- Allocation Statistics ----------\n");45#if defined(J9VM_GC_THREAD_LOCAL_HEAP)46UDATA tlhRefreshCountTotal = allocStats->_tlhRefreshCountFresh + allocStats->_tlhRefreshCountReused;47UDATA tlhAllocatedTotal = allocStats->tlhBytesAllocated();48tgcExtensions->printf("TLH Refresh Count Total: %12zu\n", tlhRefreshCountTotal);49tgcExtensions->printf("TLH Refresh Count Fresh: %12zu\n", allocStats->_tlhRefreshCountFresh);50tgcExtensions->printf("TLH Refresh Count Reused: %12zu\n", allocStats->_tlhRefreshCountReused);51tgcExtensions->printf("TLH Refresh Bytes Total: %12zu\n", tlhAllocatedTotal);52tgcExtensions->printf("TLH Refresh Bytes Fresh: %12zu\n", allocStats->_tlhAllocatedFresh);53tgcExtensions->printf("TLH Discarded Bytes: %12zu\n", allocStats->_tlhDiscardedBytes);54tgcExtensions->printf("TLH Refresh Bytes Reused: %12zu\n", allocStats->_tlhAllocatedReused);55tgcExtensions->printf("TLH Requested Bytes: %12zu\n", allocStats->_tlhRequestedBytes);56tgcExtensions->printf("TLH Max Abandoned List Length: %12zu\n", allocStats->_tlhMaxAbandonedListSize);57#endif /* defined (J9VM_GC_THREAD_LOCAL_HEAP) */58tgcExtensions->printf("Normal Allocated Count: %12zu\n", allocStats->_allocationCount);59tgcExtensions->printf("Normal Allocated Bytes: %12zu\n", allocStats->_allocationBytes);60}6162static void63tgcHookAllocationGlobalPrintStats(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)64{65MM_GlobalGCStartEvent* event = (MM_GlobalGCStartEvent*)eventData;66tgcAllocationPrintStats(event->currentThread);67}6869static void70tgcHookAllocationLocalPrintStats(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)71{72MM_LocalGCStartEvent* event = (MM_LocalGCStartEvent*)eventData;73tgcAllocationPrintStats(event->currentThread);74}7576bool77tgcAllocationInitialize(J9JavaVM *javaVM)78{79MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);80bool result = true;8182J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);83(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_GLOBAL_GC_START, tgcHookAllocationGlobalPrintStats, OMR_GET_CALLSITE(), NULL);84(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_LOCAL_GC_START, tgcHookAllocationLocalPrintStats, OMR_GET_CALLSITE(), NULL);8586return result;87}888990