Path: blob/master/runtime/gc_trace/TgcFreelist.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 "mmhook.h"25#include "j9port.h"26#include "modronopt.h"2728#include "GCExtensions.hpp"29#include "Heap.hpp"30#include "HeapStats.hpp"31#include "TgcExtensions.hpp"3233/**34* @todo Provide function documentation35*/36static void37printFreeListStats(J9JavaVM *javaVM)38{39MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);40MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);41TgcFreeListExtensions *freeListExtensions = &tgcExtensions->_freeList;42UDATA freeCount, deferredCount, nonTlhAllocCount;43#if defined(J9VM_GC_THREAD_LOCAL_HEAP)44UDATA tlhAllocCount;45#endif /* J9VM_GC_THREAD_LOCAL_HEAP */4647MM_AllocationStats *allocStats = &extensions->allocationStats;4849/* Gather statistics on all allocations since last collection from memory pools */50MM_HeapStats stats;51MM_Heap *heap = extensions->heap;52/* Gather statistics on all allocations since last collection from memory pools */53heap->mergeHeapStats(&stats); /* Assume active */5455freeCount = stats._activeFreeEntryCount;56deferredCount = stats._inactiveFreeEntryCount;57#if defined(J9VM_GC_THREAD_LOCAL_HEAP)58tlhAllocCount = allocStats->_tlhRefreshCountFresh + allocStats->_tlhRefreshCountReused;59#endif /* J9VM_GC_THREAD_LOCAL_HEAP */60nonTlhAllocCount = allocStats->_allocationCount;6162tgcExtensions->printf(" *%zu* free %5zu\n", freeListExtensions->gcCount, freeCount);63tgcExtensions->printf(" *%zu* deferred %5zu\n", freeListExtensions->gcCount, deferredCount);64tgcExtensions->printf("total %5zu\n", freeCount + deferredCount);6566#if defined(J9VM_GC_THREAD_LOCAL_HEAP)67/* Calculate total allocated since last collection */68UDATA totalAllocatedTLHBytes = allocStats->tlhBytesAllocated();69UDATA totalAllocatedBytes = totalAllocatedTLHBytes + allocStats->_allocationBytes;70UDATA tlhPercent = (tlhAllocCount > 0 && totalAllocatedBytes > 0) ?71(UDATA) (((U_64)totalAllocatedTLHBytes * 100) / (U_64)totalAllocatedBytes) : 0;7273tgcExtensions->printf("<Alloc TLH: count %zu, size %zu, percent %zu, discard %zu >\n",74tlhAllocCount,75tlhAllocCount ? (totalAllocatedTLHBytes / tlhAllocCount) : (UDATA)0,76tlhAllocCount ? tlhPercent : (UDATA)0,77tlhAllocCount ? allocStats->_tlhDiscardedBytes : (UDATA)078);79tgcExtensions->printf("< non-TLH: count %zu, search %zu, size %zu, discard %zu>\n",80#else81tgcExtensions->printf("<non-TLH: count %zu, search %zu, size %zu, discard %zu>\n",82#endif /* J9VM_GC_THREAD_LOCAL_HEAP */83nonTlhAllocCount,84nonTlhAllocCount ? (allocStats->_allocationSearchCount / nonTlhAllocCount) : (UDATA)0,85nonTlhAllocCount ? (allocStats->_allocationBytes / nonTlhAllocCount) : (UDATA)0,86nonTlhAllocCount ? allocStats->_discardedBytes : (UDATA)087);88}8990/**91* @todo Provide function documentation92*/93static void94tgcHookGcStart(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)95{96J9JavaVM* javaVM = (J9JavaVM*)userData;97MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);98MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);99TgcFreeListExtensions *freeListExtensions = &tgcExtensions->_freeList;100101freeListExtensions->gcCount += 1;102printFreeListStats(javaVM);103}104105/**106* @todo Provide function documentation107*/108bool109tgcFreeListInitialize(J9JavaVM *javaVM)110{111MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);112bool result = true;113114J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);115(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_GLOBAL_GC_START, tgcHookGcStart, OMR_GET_CALLSITE(), javaVM);116(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_LOCAL_GC_START, tgcHookGcStart, OMR_GET_CALLSITE(), javaVM);117118return result;119}120121122