Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/TgcRootScanner.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2021 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 "TgcRootScanner.hpp"
27
28
#include "EnvironmentBase.hpp"
29
#include "GCExtensions.hpp"
30
#include "TgcExtensions.hpp"
31
#include "VMThreadListIterator.hpp"
32
33
static void printRootScannerStats(OMR_VMThread *omrVMThread);
34
static void tgcHookGCEnd(J9HookInterface** hook, UDATA eventNumber, void* eventData, void* userData);
35
36
/**
37
* XML attribute names corresponding to entities in the root scanner enumeration.
38
*
39
* @ref RootScannerEntity
40
*/
41
const static char *attributeNames[] = {
42
"unknown", /* RootScannerEntity_None */
43
"scavengerememberedset", /* RootScannerEntity_ScavengeRememberedSet */
44
"classes", /* RootScannerEntity_Classes */
45
"vmclassslots", /* RootScannerEntity_VMClassSlots */
46
"permanentclasses", /* RootScannerEntity_PermanentClasses */
47
"classloaders", /* RootScannerEntity_ClassLoaders */
48
"threads", /* RootScannerEntity_Threads */
49
"finalizableobjects", /* RootScannerEntity_FinalizableObjects */
50
"unfinalizedobjects", /* RootScannerEntity_UnfinalizedObjects */
51
"ownablesynchronizerobjects", /* RootScannerEntity_OwnableSynchronizerObjects */
52
"stringtable", /* RootScannerEntity_StringTable */
53
"jniglobalrefs", /* RootScannerEntity_JNIGlobalReferences */
54
"jniweakglobalrefs", /* RootScannerEntity_JNIWeakGlobalReferences */
55
"debuggerrefs", /* RootScannerEntity_DebuggerReferences */
56
"debuggerclassrefs", /* RootScannerEntity_DebuggerClassReferences */
57
"monitorrefs", /* RootScannerEntity_MonitorReferences */
58
"weakrefs", /* RootScannerEntity_WeakReferenceObjects */
59
"softrefs", /* RootScannerEntity_SoftReferenceObjects */
60
"phantomrefs", /* RootScannerEntity_PhantomReferenceObjects */
61
"jvmtiobjecttagtables", /* RootScannerEntity_JVMTIObjectTagTables */
62
"noncollectableobjects", /* RootScannerEntity_NonCollectableObjects */
63
"rememberedset", /* RootScannerEntity_RememberedSet */
64
"memoryareaobjects", /* RootScannerEntity_MemoryAreaObjects */
65
"metronomerememberedset", /* RootScannerEntity_MetronomeRememberedSet */
66
"classescomplete", /* RootScannerEntity_ClassesComplete */
67
"weakrefscomplete", /* RootScannerEntity_WeakReferenceObjectsComplete */
68
"softrefscomplete", /* RootScannerEntity_SoftReferenceObjectsComplete */
69
"phantomrefscomplete", /* RootScannerEntity_PhantomReferenceObjectsComplete */
70
"unfinalizedobjectscomplete", /* RootScannerEntity_UnfinalizedObjectsComplete */
71
"ownablesynchronizerobjectscomplete", /* RootScannerEntity_OwnableSynchronizerObjectsComplete */
72
"monitorlookupcaches", /* RootScannerEntity_MonitorLookupCaches */
73
"monitorlookupcachescomplete", /* RootScannerEntity_MonitorLookupCachesComplete */
74
"monitorreferenceobjectscomplete", /* RootScannerEntity_MonitorReferenceObjectsComplete */
75
"doubleMappedObjects", /* RootScannerEntity_DoubleMappedObjects */
76
};
77
78
bool
79
tgcRootScannerInitialize(J9JavaVM *javaVM)
80
{
81
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
82
83
if (!extensions->rootScannerStatsEnabled) {
84
extensions->rootScannerStatsEnabled = true;
85
86
J9HookInterface** mmOmrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
87
(*mmOmrHooks)->J9HookRegisterWithCallSite(mmOmrHooks, J9HOOK_MM_OMR_LOCAL_GC_END, tgcHookGCEnd, OMR_GET_CALLSITE(), NULL);
88
(*mmOmrHooks)->J9HookRegisterWithCallSite(mmOmrHooks, J9HOOK_MM_OMR_GLOBAL_GC_END, tgcHookGCEnd, OMR_GET_CALLSITE(), NULL);
89
}
90
91
return true;
92
}
93
94
static void
95
printRootScannerStats(OMR_VMThread *omrVMThread)
96
{
97
J9VMThread *currentThread = (J9VMThread *)MM_EnvironmentBase::getEnvironment(omrVMThread)->getLanguageVMThread();
98
PORT_ACCESS_FROM_JAVAVM(currentThread->javaVM);
99
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(currentThread->javaVM);
100
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(currentThread);
101
char timestamp[32];
102
U_64 entityScanTimeTotal[RootScannerEntity_Count] = { 0 };
103
J9VMThread *thread;
104
105
/* print only if at least one thread reported stats on at least one of its roots */
106
if (extensions->rootScannerStatsUsed) {
107
OMRPORT_ACCESS_FROM_J9PORT(PORTLIB);
108
omrstr_ftime_ex(timestamp, sizeof(timestamp), "%b %d %H:%M:%S %Y", j9time_current_time_millis(), OMRSTR_FTIME_FLAG_LOCAL);
109
tgcExtensions->printf("<scan timestamp=\"%s\">\n", timestamp);
110
111
GC_VMThreadListIterator threadIterator(currentThread);
112
while (NULL != (thread = threadIterator.nextVMThread())) {
113
MM_EnvironmentBase* env = MM_EnvironmentBase::getEnvironment(thread->omrVMThread);
114
115
/* print stats for this thread only if it reported stats on at least one of its roots */
116
if (((GC_WORKER_THREAD == env->getThreadType()) || (thread == currentThread)) && env->_rootScannerStats._statsUsed) {
117
tgcExtensions->printf("\t<thread id=\"%zu\"", env->getWorkerID());
118
119
/* Scan collected entity data and print attribute/value pairs for entities that have
120
* collected data. Skip RootScannerEntity_None, located at index 0. */
121
for (UDATA entityIndex = 1; entityIndex < RootScannerEntity_Count; entityIndex++) {
122
if (0 != env->_rootScannerStats._entityScanTime[entityIndex]) {
123
U_64 scanTime = j9time_hires_delta(0, env->_rootScannerStats._entityScanTime[entityIndex], J9PORT_TIME_DELTA_IN_MICROSECONDS);
124
125
tgcExtensions->printf(" %s=\"%llu.%03.3llu\"",
126
attributeNames[entityIndex],
127
scanTime / 1000,
128
scanTime % 1000);
129
130
entityScanTimeTotal[entityIndex] += env->_rootScannerStats._entityScanTime[entityIndex];
131
}
132
}
133
134
if (extensions->isMetronomeGC()) {
135
tgcExtensions->printf(" maxincrementtime=\"%llu.%03.3llu\" maxincremententity=\"%s\"",
136
env->_rootScannerStats._maxIncrementTime / 1000,
137
env->_rootScannerStats._maxIncrementTime % 1000,
138
attributeNames[env->_rootScannerStats._maxIncrementEntity]);
139
}
140
141
tgcExtensions->printf("/>\n");
142
143
/* Clear root scanner statistics collected for this thread, so data printed during
144
* this pass will not be duplicated */
145
env->_rootScannerStats.clear();
146
}
147
}
148
149
/* Print totals for each root scanner entity */
150
tgcExtensions->printf("\t<total");
151
for (UDATA entityIndex = 1; entityIndex < RootScannerEntity_Count; entityIndex++) {
152
if (0 != entityScanTimeTotal[entityIndex]) {
153
U_64 scanTime = j9time_hires_delta(0, entityScanTimeTotal[entityIndex], J9PORT_TIME_DELTA_IN_MICROSECONDS);
154
155
tgcExtensions->printf(" %s=\"%llu.%03.3llu\"",
156
attributeNames[entityIndex],
157
scanTime / 1000,
158
scanTime % 1000);
159
}
160
}
161
162
tgcExtensions->printf("/>\n</scan>\n");
163
extensions->rootScannerStatsUsed = false;
164
}
165
}
166
167
static void
168
tgcHookGCEnd(J9HookInterface** hook, UDATA eventNumber, void* eventData, void* userData)
169
{
170
MM_GCCycleEndEvent* event = (MM_GCCycleEndEvent*) eventData;
171
172
printRootScannerStats(event->omrVMThread);
173
}
174
175