Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/TgcCardCleaning.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 "TgcCardCleaning.hpp"
27
28
#if defined(J9VM_GC_HEAP_CARD_TABLE)
29
30
#include "EnvironmentBase.hpp"
31
#include "GCExtensions.hpp"
32
#include "TgcExtensions.hpp"
33
#include "VMThreadListIterator.hpp"
34
35
static void printCardCleaningStats(OMR_VMThread *omrVMThread);
36
static void tgcHookGlobalGcCycleEnd(J9HookInterface** hook, UDATA eventNumber, void* eventData, void* userData);
37
38
UDATA
39
tgcCardCleaningInitialize(J9JavaVM *javaVM)
40
{
41
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
42
43
J9HookInterface** mmOmrHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
44
(*mmOmrHooks)->J9HookRegisterWithCallSite(mmOmrHooks, J9HOOK_MM_OMR_GC_CYCLE_END, tgcHookGlobalGcCycleEnd, OMR_GET_CALLSITE(), NULL);
45
46
return 0;
47
}
48
49
static void
50
printCardCleaningStats(OMR_VMThread *omrVMThread)
51
{
52
J9VMThread *currentThread = (J9VMThread *)MM_EnvironmentBase::getEnvironment(omrVMThread)->getLanguageVMThread();
53
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(currentThread);
54
PORT_ACCESS_FROM_VMC(currentThread);
55
OMRPORT_ACCESS_FROM_J9PORT(PORTLIB);
56
char timestamp[32];
57
58
U_64 totalTime = 0;
59
UDATA totalCardsCleaned = 0;
60
61
omrstr_ftime_ex(timestamp, sizeof(timestamp), "%b %d %H:%M:%S %Y", j9time_current_time_millis(), OMRSTR_FTIME_FLAG_LOCAL);
62
tgcExtensions->printf("<cardcleaning timestamp=\"%s\">\n", timestamp);
63
64
GC_VMThreadListIterator threadIterator(currentThread);
65
J9VMThread* thread = NULL;
66
while (NULL != (thread = threadIterator.nextVMThread())) {
67
MM_EnvironmentBase* env = MM_EnvironmentBase::getEnvironment(thread->omrVMThread);
68
69
if ((GC_WORKER_THREAD == env->getThreadType()) || (thread == currentThread)) {
70
U_64 cleanTimeInMicros = j9time_hires_delta(0, env->_cardCleaningStats._cardCleaningTime, J9PORT_TIME_DELTA_IN_MICROSECONDS);
71
tgcExtensions->printf("\t<thread id=\"%zu\" cardcleaningtime=\"%llu.%03.3llu\" cardscleaned=\"%zu\" />\n",
72
env->getWorkerID(),
73
cleanTimeInMicros / 1000,
74
cleanTimeInMicros % 1000,
75
env->_cardCleaningStats._cardsCleaned);
76
77
totalTime += env->_cardCleaningStats._cardCleaningTime;
78
totalCardsCleaned += env->_cardCleaningStats._cardsCleaned;
79
80
/* Clear card cleaning statistics collected for this thread, so data printed during this pass will not be duplicated */
81
env->_cardCleaningStats.clear();
82
}
83
}
84
85
/* Print totals for each root scanner entity */
86
U_64 totalTimeInMicros = j9time_hires_delta(0, totalTime, J9PORT_TIME_DELTA_IN_MICROSECONDS);
87
tgcExtensions->printf("\t<total cardcleaningtime=\"%llu.%03.3llu\" cardscleaned=\"%zu\" />\n",
88
totalTimeInMicros / 1000,
89
totalTimeInMicros % 1000,
90
totalCardsCleaned);
91
92
tgcExtensions->printf("</cardcleaning>\n");
93
}
94
95
static void
96
tgcHookGlobalGcCycleEnd(J9HookInterface** hook, UDATA eventNumber, void* eventData, void* userData)
97
{
98
MM_GCCycleEndEvent* event = (MM_GCCycleEndEvent*) eventData;
99
100
printCardCleaningStats(event->omrVMThread);
101
}
102
103
#endif /* defined(J9VM_GC_HEAP_CARD_TABLE) */
104
105