Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace_standard/TgcCompaction.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 "mmhook.h"
27
#include "gcutils.h"
28
#include "j9port.h"
29
#include "modronopt.h"
30
#include "j9modron.h"
31
32
#include <math.h>
33
34
#if defined(J9VM_GC_MODRON_COMPACTION)
35
36
#include "EnvironmentBase.hpp"
37
#include "GCExtensions.hpp"
38
#include "CompactStats.hpp"
39
#include "TgcExtensions.hpp"
40
#include "VMThreadListIterator.hpp"
41
42
/**
43
* Function called by a hook when the compaction is done.
44
*
45
* @param env The environment of the background thread
46
*/
47
static void
48
tgcHookCompactEnd(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
49
{
50
MM_CompactEndEvent* event = (MM_CompactEndEvent*)eventData;
51
OMR_VMThread *omrVMThread = event->omrVMThread;
52
J9VMThread *vmThread = (J9VMThread *)MM_EnvironmentBase::getEnvironment(omrVMThread)->getLanguageVMThread();
53
MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(omrVMThread->_vm);
54
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(vmThread);
55
J9VMThread *walkThread;
56
PORT_ACCESS_FROM_VMC(vmThread);
57
CompactReason reason = extensions->globalGCStats.compactStats._compactReason;
58
UDATA gcCount = extensions->globalGCStats.gcCount;
59
60
tgcExtensions->printf("Compact(%zu): reason = %zu (%s)\n", gcCount, reason, getCompactionReasonAsString(reason));
61
62
UDATA movedObjectsTotal = 0;
63
UDATA movedObjectsMin = UDATA_MAX;
64
UDATA movedObjectsMax = 0;
65
66
UDATA movedBytesTotal = 0;
67
UDATA movedBytesMin = UDATA_MAX;
68
UDATA movedBytesMax = 0;
69
70
UDATA fixupTotal = 0;
71
UDATA fixupMin = UDATA_MAX;
72
UDATA fixupMax = 0;
73
74
UDATA threadCount = 0;
75
76
/* walk the threads first to determine some of the stats -- we need these for the standard deviation */
77
GC_VMThreadListIterator compactionThreadListIterator(vmThread);
78
while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {
79
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(walkThread->omrVMThread);
80
if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {
81
MM_CompactStats *stats = &env->_compactStats;
82
83
movedObjectsTotal += stats->_movedObjects;
84
movedObjectsMin = OMR_MIN(stats->_movedObjects, movedObjectsMin);
85
movedObjectsMax = OMR_MAX(stats->_movedObjects, movedObjectsMax);
86
87
movedBytesTotal += stats->_movedBytes;
88
movedBytesMin = OMR_MIN(stats->_movedBytes, movedBytesMin);
89
movedBytesMax = OMR_MAX(stats->_movedBytes, movedBytesMax);
90
91
fixupTotal += stats->_fixupObjects;
92
fixupMin = OMR_MIN(stats->_fixupObjects, fixupMin);
93
fixupMax = OMR_MAX(stats->_fixupObjects, fixupMax);
94
95
threadCount += 1;
96
}
97
}
98
99
double movedObjectsMean = (double)movedObjectsTotal / (double)threadCount;
100
double movedBytesMean = (double)movedBytesTotal / (double)threadCount;
101
double fixupMean = (double)fixupTotal / (double)threadCount;
102
103
double movedObjectsSquareSum = 0.0;
104
double movedBytesSquareSum = 0.0;
105
double fixupSquareSum = 0.0;
106
107
compactionThreadListIterator = GC_VMThreadListIterator(vmThread);
108
while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {
109
/* TODO: Are we guaranteed to get the threads in the right order? */
110
MM_EnvironmentBase *env = MM_EnvironmentBase::getEnvironment(walkThread->omrVMThread);
111
if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {
112
MM_CompactStats *stats = &env->_compactStats;
113
UDATA workerID = env->getWorkerID();
114
115
tgcExtensions->printf("Compact(%zu): Thread %zu, setup stage: %llu ms.\n",
116
gcCount, workerID, j9time_hires_delta(stats->_setupStartTime, stats->_setupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));
117
tgcExtensions->printf("Compact(%zu): Thread %zu, move stage: handled %zu objects in %llu ms, bytes moved %zu.\n",
118
gcCount, workerID, stats->_movedObjects,
119
j9time_hires_delta(stats->_moveStartTime, stats->_moveEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS), stats->_movedBytes);
120
tgcExtensions->printf("Compact(%zu): Thread %zu, fixup stage: handled %zu objects in %zu ms, root fixup time %zu ms.\n",
121
gcCount, workerID, stats->_fixupObjects,
122
j9time_hires_delta(stats->_fixupStartTime, stats->_fixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS),
123
j9time_hires_delta(stats->_rootFixupStartTime, stats->_rootFixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));
124
125
double movedObjectsDelta = (double)stats->_movedObjects - movedObjectsMean;
126
movedObjectsSquareSum += movedObjectsDelta * movedObjectsDelta;
127
double movedBytesDelta = (double)stats->_movedBytes - movedBytesMean;
128
movedBytesSquareSum += movedBytesDelta * movedBytesDelta;
129
double fixupDelta = (double)stats->_fixupObjects - fixupMean;
130
fixupSquareSum += fixupDelta * fixupDelta;
131
}
132
}
133
134
tgcExtensions->printf("Compact(%zu): Summary, move stage: handled %zu (min=%zu, max=%zu, stddev=%.2f) objects, bytes moved %zu (min=%zu, max=%zu, stddev=%.2f).\n",
135
gcCount,
136
movedObjectsTotal, movedObjectsMin, movedObjectsMax, sqrt(movedObjectsSquareSum / threadCount),
137
movedBytesTotal, movedBytesMin, movedBytesMax, sqrt(movedBytesSquareSum / threadCount));
138
tgcExtensions->printf("Compact(%zu): Summary, fixup stage: handled %zu (min=%zu, max=%zu, stddev=%.2f) objects.\n",
139
gcCount,
140
fixupTotal, fixupMin, fixupMax, sqrt(fixupSquareSum / threadCount));
141
142
}
143
144
145
/**
146
* Initialize compaction tgc tracing.
147
* Initializes the TgcCompactionExtensions object associated with concurrent tgc tracing. Attaches hooks
148
* to the appropriate functions handling events used by concurrent tgc tracing.
149
*/
150
bool
151
tgcCompactionInitialize(J9JavaVM *javaVM)
152
{
153
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
154
bool result = true;
155
156
J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
157
(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_COMPACT_END, tgcHookCompactEnd, OMR_GET_CALLSITE(), NULL);
158
159
return result;
160
}
161
162
#endif /* J9VM_GC_MODRON_COMPACTION */
163
164
165