Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/TgcNuma.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2020 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
#include "j9.h"
25
#include "j9cfg.h"
26
#include "j9port.h"
27
#include "Tgc.hpp"
28
#include "mmhook.h"
29
30
#if defined(J9VM_GC_VLHGC)
31
#include "EnvironmentBase.hpp"
32
#include "GCExtensions.hpp"
33
#include "Heap.hpp"
34
#include "HeapRegionIterator.hpp"
35
#include "HeapRegionDescriptor.hpp"
36
#include "TgcExtensions.hpp"
37
#include "VMThreadListIterator.hpp"
38
39
/**
40
* Report NUMA statistics prior to a collection
41
*/
42
static void
43
tgcHookReportNumaStatistics(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
44
{
45
MM_GlobalGCStartEvent* event = (MM_GlobalGCStartEvent*)eventData;
46
J9VMThread* vmThread = (J9VMThread*)event->currentThread->_language_vmthread;
47
J9JavaVM *javaVM = vmThread->javaVM;
48
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
49
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
50
TgcNumaExtensions *numaExtensions = &tgcExtensions->_numa;
51
52
/*
53
* Initialize the extensions if they haven't been initialized yet
54
*/
55
if (NULL == numaExtensions->nodeData) {
56
UDATA maxNode = extensions->_numaManager.getMaximumNodeNumber();
57
UDATA dataSizeInBytes = (maxNode + 1) * sizeof(TgcNumaExtensions::NumaNodeData);
58
MM_Forge *forge = extensions->getForge();
59
60
numaExtensions->numaNodes = maxNode;
61
numaExtensions->nodeData = (TgcNumaExtensions::NumaNodeData*)forge->allocate(dataSizeInBytes, MM_AllocationCategory::DIAGNOSTIC, J9_GET_CALLSITE());
62
}
63
64
if (NULL != numaExtensions->nodeData) {
65
memset(numaExtensions->nodeData, 0, (numaExtensions->numaNodes + 1) * sizeof(TgcNumaExtensions::NumaNodeData));
66
67
/*
68
* Count threads
69
*/
70
GC_VMThreadListIterator threadIterator(vmThread);
71
J9VMThread * walkThread = NULL;
72
while (NULL != (walkThread = threadIterator.nextVMThread())) {
73
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(walkThread->omrVMThread);
74
75
UDATA threadNode = 0;
76
UDATA nodeCount = 1;
77
if ((0 != omrthread_numa_get_node_affinity(walkThread->osThread, &threadNode, &nodeCount)) || (0 == nodeCount)) {
78
threadNode = 0;
79
}
80
numaExtensions->nodeData[threadNode].threads += 1;
81
82
if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {
83
numaExtensions->nodeData[threadNode].gcThreads += 1;
84
}
85
}
86
87
/*
88
* Count regions
89
*/
90
MM_HeapRegionManager *regionManager = extensions->heap->getHeapRegionManager();
91
GC_HeapRegionIterator regionIterator(regionManager, MM_HeapRegionDescriptor::MANAGED);
92
MM_HeapRegionDescriptor *region = NULL;
93
while (NULL != (region = regionIterator.nextRegion())) {
94
UDATA regionNode = extensions->_numaManager.getJ9NodeNumber(region->getNumaNode());
95
if (region->isCommitted()) {
96
numaExtensions->nodeData[regionNode].committedRegions += 1;
97
}
98
if (region->getRegionType() == MM_HeapRegionDescriptor::FREE) {
99
numaExtensions->nodeData[regionNode].freeRegions += 1;
100
}
101
numaExtensions->nodeData[regionNode].totalRegions += 1;
102
}
103
104
/*
105
* Report results
106
*/
107
for (UDATA i = 0; i <= numaExtensions->numaNodes; i++) {
108
tgcExtensions->printf(
109
"NUMA node %zu has %zu regions (%zu committed, %zu free) %zu threads (%zu GC threads)\n",
110
i,
111
numaExtensions->nodeData[i].totalRegions,
112
numaExtensions->nodeData[i].committedRegions,
113
numaExtensions->nodeData[i].freeRegions,
114
numaExtensions->nodeData[i].threads,
115
numaExtensions->nodeData[i].gcThreads);
116
}
117
}
118
}
119
120
121
/**
122
* Initialize NUMA tgc tracing.
123
* Attaches hooks to the appropriate functions handling events used by NUMA tgc tracing.
124
*/
125
bool
126
tgcNumaInitialize(J9JavaVM *javaVM)
127
{
128
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
129
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
130
bool result = true;
131
132
tgcExtensions->_numa.numaNodes = 0;
133
tgcExtensions->_numa.nodeData = NULL;
134
135
J9HookInterface** hooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
136
(*hooks)->J9HookRegisterWithCallSite(hooks, J9HOOK_MM_OMR_GLOBAL_GC_START, tgcHookReportNumaStatistics, OMR_GET_CALLSITE(), NULL);
137
(*hooks)->J9HookRegisterWithCallSite(hooks, J9HOOK_MM_OMR_LOCAL_GC_START, tgcHookReportNumaStatistics, OMR_GET_CALLSITE(), NULL);
138
(*hooks)->J9HookRegisterWithCallSite(hooks, J9HOOK_MM_OMR_LOCAL_GC_END, tgcHookReportNumaStatistics, OMR_GET_CALLSITE(), NULL);
139
140
return result;
141
}
142
143
#endif /* J9VM_GC_VLHGC */
144
145