Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/Tgc.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2019 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
27
#include <string.h>
28
29
#include "GCExtensions.hpp"
30
#include "TgcExtensions.hpp"
31
32
#include "j9consts.h"
33
#include "j9port.h"
34
#include "j9protos.h"
35
#include "modronopt.h"
36
#include "TgcAllocation.hpp"
37
#include "TgcAllocationContext.hpp"
38
#include "TgcBacktrace.hpp"
39
#if defined(J9VM_GC_HEAP_CARD_TABLE)
40
#include "TgcCardCleaning.hpp"
41
#endif /* defined(J9VM_GC_HEAP_CARD_TABLE) */
42
#if defined(J9VM_GC_MODRON_STANDARD) && defined(J9VM_GC_MODRON_COMPACTION)
43
#include "TgcCompaction.hpp"
44
#endif /* J9VM_GC_MODRON_STANDARD && J9VM_GC_MODRON_COMPACTION */
45
#if defined(OMR_GC_MODRON_CONCURRENT_MARK)
46
#include "TgcConcurrent.hpp"
47
#include "TgcConcurrentcardcleaning.hpp"
48
#endif /* OMR_GC_MODRON_CONCURRENT_MARK */
49
#include "TgcDump.hpp"
50
#include "TgcExclusiveaccess.hpp"
51
#include "TgcFreelist.hpp"
52
#include "TgcExcessivegc.hpp"
53
#include "TgcHeap.hpp"
54
#if defined(J9VM_GC_MODRON_STANDARD)
55
#include "TgcFreeListSummary.hpp"
56
#include "TgcLargeAllocation.hpp"
57
#endif /* defined(J9VM_GC_MODRON_STANDARD) */
58
#if defined(J9VM_GC_VLHGC)
59
#include "TgcIntelligentCompact.hpp"
60
#include "TgcInterRegionReferences.hpp"
61
#include "TgcInterRegionRememberedSet.hpp"
62
#include "TgcInterRegionRememberedSetDemographics.hpp"
63
#include "TgcCopyForward.hpp"
64
#include "TgcDynamicCollectionSet.hpp"
65
#include "TgcProjectedStats.hpp"
66
#include "TgcWriteOnceCompaction.hpp"
67
#include "TgcWriteOnceCompactTiming.hpp"
68
#endif /* defined(J9VM_GC_VLHGC) */
69
#include "TgcParallel.hpp"
70
#include "TgcRootScanner.hpp"
71
#if defined(J9VM_GC_MODRON_SCAVENGER)
72
#include "TgcScavenger.hpp"
73
#endif /* J9VM_GC_MODRON_SCAVENGER */
74
#include "TgcTerse.hpp"
75
76
bool
77
tgcInstantiateExtensions(J9JavaVM *javaVM)
78
{
79
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
80
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
81
82
if(NULL == tgcExtensions) {
83
tgcExtensions = MM_TgcExtensions::newInstance(extensions);
84
if (NULL == tgcExtensions) {
85
return false;
86
}
87
extensions->tgcExtensions = tgcExtensions;
88
}
89
return true;
90
}
91
92
/**
93
* Consume arguments found in the -Xtgc: (tgc_colon) argument list.
94
* @return true if parsing was successful, 0 otherwise.
95
*/
96
bool
97
tgcParseArgs(J9JavaVM *javaVM, char *optArg)
98
{
99
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
100
101
/* TODO: how should we handle initialization error? */
102
char *scan_start = optArg;
103
char *scan_limit = optArg + strlen(optArg);
104
char *error_scan;
105
PORT_ACCESS_FROM_JAVAVM(javaVM);
106
107
if(!tgcInstantiateExtensions(javaVM)) {
108
return false;
109
}
110
111
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
112
113
while (scan_start < scan_limit) {
114
/* ignore separators */
115
try_scan(&scan_start, ",");
116
117
error_scan = scan_start;
118
119
if (try_scan(&scan_start, "file=")) {
120
char *filename = scan_to_delim(PORTLIB, &scan_start, ',');
121
if (NULL != filename) {
122
tgcExtensions->setOutputFile(filename);
123
j9mem_free_memory(filename);
124
continue;
125
}
126
}
127
128
if (try_scan(&scan_start, "backtrace")) {
129
tgcExtensions->_backtraceRequested = true;
130
continue;
131
}
132
133
if (try_scan(&scan_start, "compaction")) {
134
tgcExtensions->_compactionRequested = true;
135
continue;
136
}
137
138
if (try_scan(&scan_start, "concurrent")) {
139
tgcExtensions->_concurrentRequested = true;
140
continue;
141
}
142
143
if (try_scan(&scan_start, "cardcleaning")) {
144
tgcExtensions->_cardCleaningRequested = true;
145
continue;
146
}
147
148
if (try_scan(&scan_start, "dump")) {
149
tgcExtensions->_dumpRequested = true;
150
continue;
151
}
152
153
if (try_scan(&scan_start, "exclusiveaccess")) {
154
tgcExtensions->_exclusiveAccessRequested = true;
155
continue;
156
}
157
158
if (try_scan(&scan_start, "excessivegc")) {
159
tgcExtensions->_excessiveGCRequested = true;
160
continue;
161
}
162
163
if (try_scan(&scan_start, "freeListSummary")) {
164
tgcExtensions->_freeListSummaryRequested = true;
165
continue;
166
}
167
168
if (try_scan(&scan_start, "freeList")) {
169
tgcExtensions->_freeListRequested = true;
170
continue;
171
}
172
173
if (try_scan(&scan_start, "heap")) {
174
tgcExtensions->_heapRequested = true;
175
continue;
176
}
177
178
if (try_scan(&scan_start, "parallel")) {
179
tgcExtensions->_parallelRequested = true;
180
continue;
181
}
182
183
if (try_scan(&scan_start, "rootscantime")) {
184
tgcExtensions->_rootScannerRequested = true;
185
continue;
186
}
187
188
if (try_scan(&scan_start, "rememberedSetCardList")) {
189
tgcExtensions->_interRegionRememberedSetRequested = true;
190
continue;
191
}
192
193
if (try_scan(&scan_start, "rememberedSetDemographics")) {
194
tgcExtensions->_interRegionRememberedSetDemographicsRequested = true;
195
continue;
196
}
197
198
if (try_scan(&scan_start, "numa")) {
199
tgcExtensions->_numaRequested = true;
200
continue;
201
}
202
203
if (try_scan(&scan_start, "allocationContext")) {
204
tgcExtensions->_allocationContextRequested = true;
205
continue;
206
}
207
208
if (try_scan(&scan_start, "intelligentCompact")) {
209
tgcExtensions->_intelligentCompactRequested = true;
210
continue;
211
}
212
213
if (try_scan(&scan_start, "dynamicCollectionSet")) {
214
tgcExtensions->_dynamicCollectionSetRequested = true;
215
continue;
216
}
217
218
if (try_scan(&scan_start, "projectedStats")) {
219
tgcExtensions->_projectedStatsRequested = true;
220
continue;
221
}
222
223
if (try_scan(&scan_start, "writeOnceCompactTiming")) {
224
tgcExtensions->_writeOnceCompactTimingRequested = true;
225
continue;
226
}
227
228
if (try_scan(&scan_start, "copyForward")) {
229
tgcExtensions->_copyForwardRequested = true;
230
continue;
231
}
232
233
if (try_scan(&scan_start, "interRegionReferences")) {
234
tgcExtensions->_interRegionReferencesRequested = true;
235
continue;
236
}
237
238
if (try_scan(&scan_start, "scavengerSurvivalStats")) {
239
tgcExtensions->_scavengerSurvivalStatsRequested = true;
240
continue;
241
}
242
243
if (try_scan(&scan_start, "scavengerMemoryStats")) {
244
tgcExtensions->_scavengerMemoryStatsRequested = true;
245
continue;
246
}
247
248
if (try_scan(&scan_start, "scavenger")) {
249
tgcExtensions->_scavengerRequested = true;
250
tgcExtensions->_scavengerSurvivalStatsRequested = true;
251
tgcExtensions->_scavengerMemoryStatsRequested = true;
252
continue;
253
}
254
255
if (try_scan(&scan_start, "terse")) {
256
tgcExtensions->_terseRequested = true;
257
continue;
258
}
259
260
if (try_scan(&scan_start, "allocation")) {
261
tgcExtensions->_allocationRequested = true;
262
continue;
263
}
264
265
if (try_scan(&scan_start, "largeAllocationVerbose")) {
266
tgcExtensions->_largeAllocationVerboseRequested = true;
267
continue;
268
}
269
270
if (try_scan(&scan_start, "largeAllocation")) {
271
tgcExtensions->_largeAllocationRequested = true;
272
continue;
273
}
274
275
/* Couldn't find a match for arguments */
276
scan_failed(PORTLIB, "GC", error_scan);
277
return false;
278
}
279
280
return true;
281
}
282
283
bool
284
tgcInitializeRequestedOptions(J9JavaVM *javaVM)
285
{
286
bool result = true;
287
288
#if (defined(J9VM_GC_MODRON_STANDARD) || defined(J9VM_GC_VLHGC) || defined(J9VM_GC_SEGREGATED_HEAP))
289
290
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
291
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(extensions);
292
293
/* StandardGC, VLHGC , and Segregated heap options*/
294
if (extensions->isStandardGC() || extensions->isVLHGC() || extensions->isSegregatedHeap()) {
295
if (tgcExtensions->_heapRequested) {
296
result = result && tgcHeapInitialize(javaVM);
297
}
298
299
if (tgcExtensions->_rootScannerRequested) {
300
result = result && tgcRootScannerInitialize(javaVM);
301
}
302
}
303
304
/* StandardGC and VLHGC both options*/
305
if (extensions->isStandardGC() || extensions->isVLHGC()) {
306
if (tgcExtensions->_backtraceRequested) {
307
result = result && tgcBacktraceInitialize(javaVM);
308
}
309
310
if (tgcExtensions->_dumpRequested) {
311
result = result && tgcDumpInitialize(javaVM);
312
}
313
314
if (tgcExtensions->_exclusiveAccessRequested) {
315
result = result && tgcExclusiveAccessInitialize(javaVM);
316
}
317
318
if (tgcExtensions->_excessiveGCRequested) {
319
result = result && tgcExcessiveGCInitialize(javaVM);
320
}
321
322
if (tgcExtensions->_freeListRequested) {
323
result = result && tgcFreeListInitialize(javaVM);
324
}
325
326
if (tgcExtensions->_parallelRequested) {
327
result = result && tgcParallelInitialize(javaVM);
328
}
329
330
if (tgcExtensions->_terseRequested) {
331
result = result && tgcTerseInitialize(javaVM);
332
}
333
334
if (tgcExtensions->_allocationRequested) {
335
result = result && tgcAllocationInitialize(javaVM);
336
}
337
338
if (tgcExtensions->_largeAllocationVerboseRequested || tgcExtensions->_largeAllocationRequested) {
339
result = result && tgcLargeAllocationInitialize(javaVM);
340
}
341
342
if (tgcExtensions->_numaRequested) {
343
result = result && tgcNumaInitialize(javaVM);
344
}
345
}
346
347
/* StandardGC only options */
348
if (extensions->isStandardGC()) {
349
#if defined(J9VM_GC_MODRON_STANDARD)
350
#if defined(J9VM_GC_MODRON_COMPACTION)
351
if (tgcExtensions->_compactionRequested) {
352
result = result && tgcCompactionInitialize(javaVM);
353
}
354
#endif /* J9VM_GC_MODRON_COMPACTION */
355
if (tgcExtensions->_concurrentRequested) {
356
result = result && tgcConcurrentInitialize(javaVM);
357
}
358
359
if (tgcExtensions->_cardCleaningRequested) {
360
result = result && tgcConcurrentCardCleaningInitialize(javaVM);
361
}
362
363
if (tgcExtensions->_freeListSummaryRequested) {
364
result = result && tgcFreeListSummaryInitialize(javaVM);
365
}
366
367
if (tgcExtensions->_scavengerSurvivalStatsRequested) {
368
result = result && tgcScavengerSurvivalStatsInitialize(javaVM);
369
}
370
371
if (tgcExtensions->_scavengerMemoryStatsRequested) {
372
result = result && tgcScavengerMemoryStatsInitialize(javaVM);
373
}
374
375
if (tgcExtensions->_scavengerRequested) {
376
result = result && tgcScavengerInitialize(javaVM);
377
}
378
#endif /* defined(J9VM_GC_MODRON_STANDARD) */
379
}
380
381
/* VLHGC only options */
382
if (extensions->isVLHGC()) {
383
#if defined(J9VM_GC_VLHGC)
384
if (tgcExtensions->_compactionRequested) {
385
result = result && tgcWriteOnceCompactionInitialize(javaVM);
386
}
387
388
if (tgcExtensions->_cardCleaningRequested) {
389
result = result && tgcCardCleaningInitialize(javaVM);
390
}
391
392
if (tgcExtensions->_interRegionRememberedSetRequested) {
393
result = result && tgcInterRegionRememberedSetInitialize(javaVM);
394
}
395
396
if (tgcExtensions->_interRegionRememberedSetDemographicsRequested) {
397
result = result && tgcInterRegionRememberedSetDemographicsInitialize(javaVM);
398
}
399
400
if (tgcExtensions->_allocationContextRequested) {
401
result = result && tgcAllocationContextInitialize(javaVM);
402
}
403
#if defined(J9VM_GC_MODRON_COMPACTION)
404
if (tgcExtensions->_intelligentCompactRequested) {
405
result = result && tgcIntelligentCompactInitialize(javaVM);
406
}
407
#endif /* J9VM_GC_MODRON_COMPACTION */
408
if (tgcExtensions->_dynamicCollectionSetRequested) {
409
result = result && tgcDynamicCollectionSetInitialize(javaVM);
410
}
411
412
if (tgcExtensions->_projectedStatsRequested) {
413
result = result && tgcProjectedStatsInitialize(javaVM);
414
}
415
#if defined(J9VM_GC_MODRON_COMPACTION)
416
if (tgcExtensions->_writeOnceCompactTimingRequested) {
417
result = result && tgcWriteOnceCompactTimingInitialize(javaVM);
418
}
419
#endif /* J9VM_GC_MODRON_COMPACTION */
420
if (tgcExtensions->_copyForwardRequested) {
421
result = result && tgcCopyForwardInitialize(javaVM);
422
}
423
424
if (tgcExtensions->_interRegionReferencesRequested) {
425
result = result && tgcInterRegionReferencesInitialize(javaVM);
426
}
427
428
#endif /* J9VM_GC_VLHGC */
429
}
430
431
432
#endif /* defined(J9VM_GC_MODRON_STANDARD) || defined(J9VM_GC_VLHGC) || defined(J9VM_GC_SEGREGATED_HEAP) */
433
434
return result;
435
}
436
437
/**
438
* @todo Provide function documentation
439
*/
440
void
441
tgcTearDownExtensions(J9JavaVM *javaVM)
442
{
443
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
444
445
if (NULL != extensions->tgcExtensions) {
446
if (extensions->isVLHGC()) {
447
#if defined(J9VM_GC_VLHGC)
448
tgcInterRegionRememberedSetTearDown(javaVM);
449
tgcInterRegionRememberedSetDemographicsTearDown(javaVM);
450
tgcDynamicCollectionSetTearDown(javaVM);
451
tgcInterRegionReferencesTearDown(javaVM);
452
#endif /* J9VM_GC_VLHGC */
453
}
454
MM_TgcExtensions::getExtensions(extensions)->kill(extensions);
455
extensions->tgcExtensions = NULL;
456
}
457
}
458
459
/**
460
* @todo Provide function documentation
461
*/
462
void
463
tgcPrintClass(J9JavaVM *javaVM, J9Class* clazz)
464
{
465
J9ROMClass* romClass;
466
J9UTF8* utf;
467
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(javaVM);
468
469
/* TODO: In Sov, if the class is char[], the string is printed instead of the class name */
470
romClass = clazz->romClass;
471
if(romClass->modifiers & J9AccClassArray) {
472
J9ArrayClass* arrayClass = (J9ArrayClass*) clazz;
473
UDATA arity = arrayClass->arity;
474
utf = J9ROMCLASS_CLASSNAME(arrayClass->leafComponentType->romClass);
475
476
tgcExtensions->printf("%.*s", (UDATA)J9UTF8_LENGTH(utf), J9UTF8_DATA(utf));
477
while(arity--) {
478
tgcExtensions->printf("[]");
479
}
480
} else {
481
utf = J9ROMCLASS_CLASSNAME(romClass);
482
tgcExtensions->printf("%.*s", (UDATA)J9UTF8_LENGTH(utf), J9UTF8_DATA(utf));
483
}
484
return;
485
}
486
487