Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/TgcDump.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2019 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 "j9port.h"
27
#include "modronopt.h"
28
#include "Tgc.hpp"
29
#include "HeapIteratorAPI.h"
30
31
#include "GCExtensions.hpp"
32
#include "TgcExtensions.hpp"
33
34
static jvmtiIterationControl dump_heapIteratorCallback(J9JavaVM* vm, J9MM_IterateHeapDescriptor* heapDesc, void* userData);
35
static jvmtiIterationControl dump_spaceIteratorCallback(J9JavaVM* vm, J9MM_IterateSpaceDescriptor* spaceDesc, void* userData);
36
static jvmtiIterationControl dump_regionIteratorCallback(J9JavaVM* vm, J9MM_IterateRegionDescriptor* regionDesc, void* userData);
37
static jvmtiIterationControl dump_objectIteratorCallback(J9JavaVM* vm, J9MM_IterateObjectDescriptor* objectDesc, void *userData);
38
39
typedef struct DumpObjectsIteratorCallbackUserData {
40
bool previousObjectWasFreeSpace; /* was the previous object free space or a live object? */
41
UDATA gcCount; /* GC identifier */
42
} DumpObjectsIteratorCallbackUserData;
43
44
45
/**
46
* @todo Provide function documentation
47
*/
48
static void
49
tgcHookGlobalGcSweepEnd(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
50
{
51
MM_SweepEndEvent* event = (MM_SweepEndEvent*)eventData;
52
J9VMThread *vmThread = static_cast<J9VMThread *>(event->currentThread->_language_vmthread);
53
J9JavaVM* javaVM = vmThread->javaVM;
54
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(event->currentThread);
55
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
56
57
UDATA gcCount = 0;
58
59
if (extensions->isStandardGC() || extensions->isMetronomeGC()) {
60
#if defined(J9VM_GC_MODRON_STANDARD) || defined(J9VM_GC_REALTIME)
61
gcCount = extensions->globalGCStats.gcCount;
62
if (extensions->isStandardGC()) {
63
#if defined(J9VM_GC_MODRON_SCAVENGER)
64
gcCount += extensions->scavengerStats._gcCount;
65
#endif /* J9VM_GC_MODRON_SCAVENGER */
66
}
67
#endif /* J9VM_GC_MODRON_STANDARD || J9VM_GC_REALTIME */
68
}
69
if (extensions->isVLHGC()) {
70
#if defined(J9VM_GC_VLHGC)
71
gcCount += extensions->globalVLHGCStats.gcCount;
72
#endif /* J9VM_GC_VLHGC */
73
}
74
75
tgcExtensions->printf("<GC(%zu) Dumping Middleware Heap free blocks\n", gcCount);
76
77
DumpObjectsIteratorCallbackUserData iteratorData;
78
iteratorData.gcCount = gcCount;
79
iteratorData.previousObjectWasFreeSpace = false;
80
javaVM->memoryManagerFunctions->j9mm_iterate_heaps(javaVM, javaVM->portLibrary, 0, dump_heapIteratorCallback, &iteratorData);
81
}
82
83
static jvmtiIterationControl
84
dump_heapIteratorCallback(J9JavaVM* vm, J9MM_IterateHeapDescriptor* heapDesc, void* userData)
85
{
86
vm->memoryManagerFunctions->j9mm_iterate_spaces(vm, vm->portLibrary, heapDesc, 0, dump_spaceIteratorCallback, userData);
87
return JVMTI_ITERATION_CONTINUE;
88
}
89
90
static jvmtiIterationControl
91
dump_spaceIteratorCallback(J9JavaVM* vm, J9MM_IterateSpaceDescriptor* spaceDesc, void* userData)
92
{
93
vm->memoryManagerFunctions->j9mm_iterate_regions(vm, vm->portLibrary, spaceDesc, 0, dump_regionIteratorCallback, userData);
94
return JVMTI_ITERATION_CONTINUE;
95
}
96
97
static jvmtiIterationControl
98
dump_regionIteratorCallback(J9JavaVM* vm, J9MM_IterateRegionDescriptor* regionDesc, void* userData)
99
{
100
DumpObjectsIteratorCallbackUserData* castUserData = (DumpObjectsIteratorCallbackUserData*)userData;
101
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(vm);
102
103
castUserData->previousObjectWasFreeSpace = false;
104
105
vm->memoryManagerFunctions->j9mm_iterate_region_objects(vm, vm->portLibrary, regionDesc, j9mm_iterator_flag_include_holes, dump_objectIteratorCallback, castUserData);
106
107
/* If the last object in the region was free space, the line was not terminated */
108
if (castUserData->previousObjectWasFreeSpace) {
109
tgcExtensions->printf(">\n");
110
}
111
112
return JVMTI_ITERATION_CONTINUE;
113
}
114
115
static jvmtiIterationControl
116
dump_objectIteratorCallback(J9JavaVM* vm, J9MM_IterateObjectDescriptor* objectDesc, void *userData)
117
{
118
DumpObjectsIteratorCallbackUserData* castUserData = (DumpObjectsIteratorCallbackUserData*)userData;
119
bool isFreeSpace = false;
120
UDATA freeSpaceByteSize = 0;
121
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(vm);
122
123
/* Determine whether or not the object is dead, and get its size. Since the object heap iterator
124
* doesn't consult the mark map, a "live" object may actually be a dead object in a chunk that wasn't
125
* large enough to make the free list.
126
*/
127
128
if (FALSE == objectDesc->isObject) {
129
isFreeSpace = true;
130
freeSpaceByteSize = objectDesc->size;
131
} else if (!(vm->memoryManagerFunctions->j9gc_ext_is_marked(vm, objectDesc->object))) {
132
isFreeSpace = true;
133
freeSpaceByteSize = objectDesc->size;
134
}
135
136
/* Print the next object after free space, and in any case, terminate the line */
137
if (castUserData->previousObjectWasFreeSpace) {
138
if (!isFreeSpace) {
139
tgcExtensions->printf(" -- x%p ", objectDesc->size);
140
tgcPrintClass(vm, J9GC_J9OBJECT_CLAZZ_VM(objectDesc->object, vm));
141
}
142
tgcExtensions->printf(">\n");
143
}
144
145
if (isFreeSpace) {
146
tgcExtensions->printf("<GC(%zu) %p freelen=x%p", castUserData->gcCount, objectDesc->id, freeSpaceByteSize);
147
}
148
149
castUserData->previousObjectWasFreeSpace = isFreeSpace;
150
151
return JVMTI_ITERATION_CONTINUE;
152
}
153
154
/**
155
* @todo Provide function documentation
156
*/
157
bool
158
tgcDumpInitialize(J9JavaVM *javaVM)
159
{
160
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
161
bool result = true;
162
163
J9HookInterface** privateHooks = J9_HOOK_INTERFACE(extensions->privateHookInterface);
164
(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_SWEEP_END, tgcHookGlobalGcSweepEnd, OMR_GET_CALLSITE(), NULL);
165
166
return result;
167
}
168
169