Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/TgcFreelist.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2017 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
#include "j9.h"
24
#include "j9cfg.h"
25
#include "mmhook.h"
26
#include "j9port.h"
27
#include "modronopt.h"
28
29
#include "GCExtensions.hpp"
30
#include "Heap.hpp"
31
#include "HeapStats.hpp"
32
#include "TgcExtensions.hpp"
33
34
/**
35
* @todo Provide function documentation
36
*/
37
static void
38
printFreeListStats(J9JavaVM *javaVM)
39
{
40
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
41
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
42
TgcFreeListExtensions *freeListExtensions = &tgcExtensions->_freeList;
43
UDATA freeCount, deferredCount, nonTlhAllocCount;
44
#if defined(J9VM_GC_THREAD_LOCAL_HEAP)
45
UDATA tlhAllocCount;
46
#endif /* J9VM_GC_THREAD_LOCAL_HEAP */
47
48
MM_AllocationStats *allocStats = &extensions->allocationStats;
49
50
/* Gather statistics on all allocations since last collection from memory pools */
51
MM_HeapStats stats;
52
MM_Heap *heap = extensions->heap;
53
/* Gather statistics on all allocations since last collection from memory pools */
54
heap->mergeHeapStats(&stats); /* Assume active */
55
56
freeCount = stats._activeFreeEntryCount;
57
deferredCount = stats._inactiveFreeEntryCount;
58
#if defined(J9VM_GC_THREAD_LOCAL_HEAP)
59
tlhAllocCount = allocStats->_tlhRefreshCountFresh + allocStats->_tlhRefreshCountReused;
60
#endif /* J9VM_GC_THREAD_LOCAL_HEAP */
61
nonTlhAllocCount = allocStats->_allocationCount;
62
63
tgcExtensions->printf(" *%zu* free %5zu\n", freeListExtensions->gcCount, freeCount);
64
tgcExtensions->printf(" *%zu* deferred %5zu\n", freeListExtensions->gcCount, deferredCount);
65
tgcExtensions->printf("total %5zu\n", freeCount + deferredCount);
66
67
#if defined(J9VM_GC_THREAD_LOCAL_HEAP)
68
/* Calculate total allocated since last collection */
69
UDATA totalAllocatedTLHBytes = allocStats->tlhBytesAllocated();
70
UDATA totalAllocatedBytes = totalAllocatedTLHBytes + allocStats->_allocationBytes;
71
UDATA tlhPercent = (tlhAllocCount > 0 && totalAllocatedBytes > 0) ?
72
(UDATA) (((U_64)totalAllocatedTLHBytes * 100) / (U_64)totalAllocatedBytes) : 0;
73
74
tgcExtensions->printf("<Alloc TLH: count %zu, size %zu, percent %zu, discard %zu >\n",
75
tlhAllocCount,
76
tlhAllocCount ? (totalAllocatedTLHBytes / tlhAllocCount) : (UDATA)0,
77
tlhAllocCount ? tlhPercent : (UDATA)0,
78
tlhAllocCount ? allocStats->_tlhDiscardedBytes : (UDATA)0
79
);
80
tgcExtensions->printf("< non-TLH: count %zu, search %zu, size %zu, discard %zu>\n",
81
#else
82
tgcExtensions->printf("<non-TLH: count %zu, search %zu, size %zu, discard %zu>\n",
83
#endif /* J9VM_GC_THREAD_LOCAL_HEAP */
84
nonTlhAllocCount,
85
nonTlhAllocCount ? (allocStats->_allocationSearchCount / nonTlhAllocCount) : (UDATA)0,
86
nonTlhAllocCount ? (allocStats->_allocationBytes / nonTlhAllocCount) : (UDATA)0,
87
nonTlhAllocCount ? allocStats->_discardedBytes : (UDATA)0
88
);
89
}
90
91
/**
92
* @todo Provide function documentation
93
*/
94
static void
95
tgcHookGcStart(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
96
{
97
J9JavaVM* javaVM = (J9JavaVM*)userData;
98
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
99
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
100
TgcFreeListExtensions *freeListExtensions = &tgcExtensions->_freeList;
101
102
freeListExtensions->gcCount += 1;
103
printFreeListStats(javaVM);
104
}
105
106
/**
107
* @todo Provide function documentation
108
*/
109
bool
110
tgcFreeListInitialize(J9JavaVM *javaVM)
111
{
112
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
113
bool result = true;
114
115
J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
116
(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_GLOBAL_GC_START, tgcHookGcStart, OMR_GET_CALLSITE(), javaVM);
117
(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_LOCAL_GC_START, tgcHookGcStart, OMR_GET_CALLSITE(), javaVM);
118
119
return result;
120
}
121
122