Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace_vlhgc/TgcWriteOnceCompaction.cpp
5986 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 "EnvironmentVLHGC.hpp"
37
#include "GCExtensions.hpp"
38
#include "CompactVLHGCStats.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
CompactReason reason = extensions->globalGCStats.compactStats._compactReason;
57
UDATA gcCount = extensions->globalGCStats.gcCount;
58
59
PORT_ACCESS_FROM_VMC(vmThread);
60
61
tgcExtensions->printf("Compact(%zu): reason = %zu (%s)\n", gcCount, reason, getCompactionReasonAsString(reason));
62
63
UDATA movedObjectsTotal = 0;
64
UDATA movedObjectsMin = UDATA_MAX;
65
UDATA movedObjectsMax = 0;
66
67
UDATA movedBytesTotal = 0;
68
UDATA movedBytesMin = UDATA_MAX;
69
UDATA movedBytesMax = 0;
70
71
UDATA fixupTotal = 0;
72
UDATA fixupMin = UDATA_MAX;
73
UDATA fixupMax = 0;
74
75
UDATA threadCount = 0;
76
77
/* walk the threads first to determine some of the stats -- we need these for the standard deviation */
78
GC_VMThreadListIterator compactionThreadListIterator(vmThread);
79
while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {
80
MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment(walkThread);
81
if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {
82
MM_CompactVLHGCStats *stats = &env->_compactVLHGCStats;
83
84
movedObjectsTotal += stats->_movedObjects;
85
movedObjectsMin = OMR_MIN(stats->_movedObjects, movedObjectsMin);
86
movedObjectsMax = OMR_MAX(stats->_movedObjects, movedObjectsMax);
87
88
movedBytesTotal += stats->_movedBytes;
89
movedBytesMin = OMR_MIN(stats->_movedBytes, movedBytesMin);
90
movedBytesMax = OMR_MAX(stats->_movedBytes, movedBytesMax);
91
92
fixupTotal += stats->_fixupObjects;
93
fixupMin = OMR_MIN(stats->_fixupObjects, fixupMin);
94
fixupMax = OMR_MAX(stats->_fixupObjects, fixupMax);
95
96
threadCount += 1;
97
}
98
}
99
100
double movedObjectsMean = (double)movedObjectsTotal / (double)threadCount;
101
double movedBytesMean = (double)movedBytesTotal / (double)threadCount;
102
double fixupMean = (double)fixupTotal / (double)threadCount;
103
104
double movedObjectsSquareSum = 0.0;
105
double movedBytesSquareSum = 0.0;
106
double fixupSquareSum = 0.0;
107
108
compactionThreadListIterator = GC_VMThreadListIterator(vmThread);
109
while ((walkThread = compactionThreadListIterator.nextVMThread()) != NULL) {
110
/* TODO: Are we guaranteed to get the threads in the right order? */
111
MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment(walkThread);
112
if ((walkThread == vmThread) || (env->getThreadType() == GC_WORKER_THREAD)) {
113
MM_CompactVLHGCStats *stats = &env->_compactVLHGCStats;
114
UDATA workerID = env->getWorkerID();
115
116
tgcExtensions->printf("Compact(%zu): Thread %zu, setup stage: %llu ms.\n",
117
gcCount, workerID, j9time_hires_delta(stats->_setupStartTime, stats->_setupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));
118
tgcExtensions->printf("Compact(%zu): Thread %zu, move stage: handled %zu objects in %llu ms, bytes moved %zu.\n",
119
gcCount, workerID, stats->_movedObjects,
120
j9time_hires_delta(stats->_moveStartTime, stats->_moveEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS), stats->_movedBytes);
121
tgcExtensions->printf("Compact(%zu): Thread %zu, fixup stage: handled %zu objects in %zu ms, root fixup time %zu ms.\n",
122
gcCount, workerID, stats->_fixupObjects,
123
j9time_hires_delta(stats->_fixupStartTime, stats->_fixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS),
124
j9time_hires_delta(stats->_rootFixupStartTime, stats->_rootFixupEndTime, J9PORT_TIME_DELTA_IN_MILLISECONDS));
125
126
double movedObjectsDelta = (double)stats->_movedObjects - movedObjectsMean;
127
movedObjectsSquareSum += movedObjectsDelta * movedObjectsDelta;
128
double movedBytesDelta = (double)stats->_movedBytes - movedBytesMean;
129
movedBytesSquareSum += movedBytesDelta * movedBytesDelta;
130
double fixupDelta = (double)stats->_fixupObjects - fixupMean;
131
fixupSquareSum += fixupDelta * fixupDelta;
132
}
133
}
134
135
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",
136
gcCount,
137
movedObjectsTotal, movedObjectsMin, movedObjectsMax, sqrt(movedObjectsSquareSum / threadCount),
138
movedBytesTotal, movedBytesMin, movedBytesMax, sqrt(movedBytesSquareSum / threadCount));
139
tgcExtensions->printf("Compact(%zu): Summary, fixup stage: handled %zu (min=%zu, max=%zu, stddev=%.2f) objects.\n",
140
gcCount,
141
fixupTotal, fixupMin, fixupMax, sqrt(fixupSquareSum / threadCount));
142
143
}
144
145
146
/**
147
* Initialize compaction tgc tracing.
148
* Initializes the TgcCompactionExtensions object associated with concurrent tgc tracing. Attaches hooks
149
* to the appropriate functions handling events used by concurrent tgc tracing.
150
*/
151
bool
152
tgcWriteOnceCompactionInitialize(J9JavaVM *javaVM)
153
{
154
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
155
bool result = true;
156
157
J9HookInterface** omrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
158
(*omrHooks)->J9HookRegisterWithCallSite(omrHooks, J9HOOK_MM_OMR_COMPACT_END, tgcHookCompactEnd, OMR_GET_CALLSITE(), NULL);
159
160
return result;
161
}
162
163
#endif /* J9VM_GC_MODRON_COMPACTION */
164
165
166