-
Notifications
You must be signed in to change notification settings - Fork 748
/
Copy pathMetronomeDelegate.cpp
1720 lines (1520 loc) · 65.8 KB
/
MetronomeDelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright IBM Corp. and others 2019
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "MetronomeDelegate.hpp"
#if defined(J9VM_GC_REALTIME)
#include "omr.h"
#include "ClassHeapIterator.hpp"
#include "ClassLoaderIterator.hpp"
#include "ClassLoaderLinkedListIterator.hpp"
#include "ClassLoaderManager.hpp"
#include "ClassLoaderSegmentIterator.hpp"
#if JAVA_SPEC_VERSION >= 24
#include "ContinuationSlotIterator.hpp"
#endif /* JAVA_SPEC_VERSION >= 24 */
#include "EnvironmentRealtime.hpp"
#include "FinalizableClassLoaderBuffer.hpp"
#include "FinalizableObjectBuffer.hpp"
#include "FinalizableReferenceBuffer.hpp"
#include "FinalizeListManager.hpp"
#include "FinalizerSupport.hpp"
#include "GCExtensionsBase.hpp"
#include "Heap.hpp"
#include "HeapRegionDescriptorRealtime.hpp"
#include "MetronomeAlarmThread.hpp"
#include "JNICriticalRegion.hpp"
#include "OwnableSynchronizerObjectList.hpp"
#include "OwnableSynchronizerObjectBufferRealtime.hpp"
#include "ContinuationObjectList.hpp"
#include "ContinuationObjectBufferRealtime.hpp"
#include "VMHelpers.hpp"
#include "RealtimeAccessBarrier.hpp"
#include "RealtimeGC.hpp"
#include "RealtimeMarkingScheme.hpp"
#include "RealtimeMarkingSchemeRootMarker.hpp"
#include "RealtimeMarkingSchemeRootClearer.hpp"
#include "RealtimeMarkTask.hpp"
#include "RealtimeRootScanner.hpp"
#include "ReferenceObjectBufferRealtime.hpp"
#include "ReferenceObjectList.hpp"
#include "Scheduler.hpp"
#include "UnfinalizedObjectBufferRealtime.hpp"
#include "UnfinalizedObjectList.hpp"
void
MM_MetronomeDelegate::yieldWhenRequested(MM_EnvironmentBase *env)
{
MM_GCExtensionsBase *ext = env->getExtensions();
UDATA accessMask;
MM_Scheduler *sched = (MM_Scheduler *)ext->dispatcher;
if (sched->_mode != MM_Scheduler::MUTATOR) {
MM_JNICriticalRegion::releaseAccess((J9VMThread *)env->getOmrVMThread()->_language_vmthread, &accessMask);
while (sched->_mode != MM_Scheduler::MUTATOR) {
omrthread_sleep(10);
}
MM_JNICriticalRegion::reacquireAccess((J9VMThread *)env->getOmrVMThread()->_language_vmthread, accessMask);
}
}
/**
* C entrypoint for the newly created alarm thread.
*/
int J9THREAD_PROC
MM_MetronomeDelegate::metronomeAlarmThreadWrapper(void *userData)
{
MM_MetronomeAlarmThread *alarmThread = (MM_MetronomeAlarmThread *)userData;
J9JavaVM *javaVM = (J9JavaVM *)alarmThread->getScheduler()->_extensions->getOmrVM()->_language_vm;
PORT_ACCESS_FROM_JAVAVM(javaVM);
uintptr_t rc;
j9sig_protect(MM_MetronomeDelegate::signalProtectedFunction, (void *)userData,
javaVM->internalVMFunctions->structuredSignalHandlerVM, javaVM,
J9PORT_SIG_FLAG_SIGALLSYNC | J9PORT_SIG_FLAG_MAY_CONTINUE_EXECUTION,
&rc);
omrthread_monitor_enter(alarmThread->_mutex);
alarmThread->_alarmThreadActive = MM_MetronomeAlarmThread::ALARM_THREAD_SHUTDOWN;
omrthread_monitor_notify(alarmThread->_mutex);
omrthread_exit(alarmThread->_mutex);
return 0;
}
uintptr_t
MM_MetronomeDelegate::signalProtectedFunction(J9PortLibrary *privatePortLibrary, void *userData)
{
MM_MetronomeAlarmThread *alarmThread = (MM_MetronomeAlarmThread *)userData;
J9JavaVM *javaVM = (J9JavaVM *)alarmThread->getScheduler()->_extensions->getOmrVM()->_language_vm;
J9VMThread *vmThread = NULL;
MM_EnvironmentRealtime *env = NULL;
if (JNI_OK != (javaVM->internalVMFunctions->attachSystemDaemonThread(javaVM, &vmThread, "GC Alarm"))) {
return 0;
}
env = MM_EnvironmentRealtime::getEnvironment(vmThread->omrVMThread);
alarmThread->run(env);
javaVM->internalVMFunctions->DetachCurrentThread((JavaVM *)javaVM);
return 0;
}
void
MM_MetronomeDelegate::clearGCStats()
{
_extensions->markJavaStats.clear();
}
void
MM_MetronomeDelegate::clearGCStatsEnvironment(MM_EnvironmentRealtime *env)
{
env->_markStats.clear();
env->getGCEnvironment()->_markJavaStats.clear();
env->_workPacketStats.clear();
}
void
MM_MetronomeDelegate::mergeGCStats(MM_EnvironmentRealtime *env)
{
GC_Environment *gcEnv = env->getGCEnvironment();
MM_GlobalGCStats *finalGCStats= &_extensions->globalGCStats;
finalGCStats->markStats.merge(&env->_markStats);
_extensions->markJavaStats.merge(&gcEnv->_markJavaStats);
finalGCStats->workPacketStats.merge(&env->_workPacketStats);
}
uintptr_t
MM_MetronomeDelegate::getSplitArraysProcessed(MM_EnvironmentRealtime *env)
{
GC_Environment *gcEnv = env->getGCEnvironment();
return gcEnv->_markJavaStats.splitArraysProcessed;
}
bool
MM_MetronomeDelegate::initialize(MM_EnvironmentBase *env)
{
_scheduler = _realtimeGC->_sched;
_markingScheme = _realtimeGC->getMarkingScheme();
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
_unmarkedImpliesClasses = false;
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
_unmarkedImpliesCleared = false;
_unmarkedImpliesStringsCleared = false;
/* allocate and initialize the global reference object lists */
if (!allocateAndInitializeReferenceObjectLists(env)){
return false;
}
/* allocate and initialize the global unfinalized object lists */
if (!allocateAndInitializeUnfinalizedObjectLists(env)) {
return false;
}
/* allocate and initialize the global ownable synchronizer object lists */
if (!allocateAndInitializeOwnableSynchronizerObjectLists(env)) {
return false;
}
/* allocate and initialize the global continuation object lists */
if (!allocateAndInitializeContinuationObjectLists(env)) {
return false;
}
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
if (!_extensions->dynamicClassUnloadingThresholdForced) {
_extensions->dynamicClassUnloadingThreshold = 1;
}
if (!_extensions->dynamicClassUnloadingKickoffThresholdForced) {
_extensions->dynamicClassUnloadingKickoffThreshold = 0;
}
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
/* Create the appropriate access barrier for Metronome */
MM_RealtimeAccessBarrier *accessBarrier = NULL;
accessBarrier = allocateAccessBarrier(env);
if (NULL == accessBarrier) {
return false;
}
_extensions->accessBarrier = (MM_ObjectAccessBarrier *)accessBarrier;
_javaVM->realtimeHeapMapBasePageRounded = _markingScheme->_markMap->getHeapMapBaseRegionRounded();
_javaVM->realtimeHeapMapBits = _markingScheme->_markMap->getHeapMapBits();
return true;
}
bool
MM_MetronomeDelegate::allocateAndInitializeReferenceObjectLists(MM_EnvironmentBase *env)
{
const UDATA listCount = getReferenceObjectListCount(env);
Assert_MM_true(0 < listCount);
_extensions->referenceObjectLists = (MM_ReferenceObjectList *)env->getForge()->allocate((sizeof(MM_ReferenceObjectList) *listCount), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL == _extensions->referenceObjectLists) {
return false;
}
for (UDATA index = 0; index < listCount; index++) {
new (&_extensions->referenceObjectLists[index]) MM_ReferenceObjectList();
}
return true;
}
bool
MM_MetronomeDelegate::allocateAndInitializeUnfinalizedObjectLists(MM_EnvironmentBase *env)
{
const UDATA listCount = getUnfinalizedObjectListCount(env);
Assert_MM_true(0 < listCount);
MM_UnfinalizedObjectList *unfinalizedObjectLists = (MM_UnfinalizedObjectList *)env->getForge()->allocate((sizeof(MM_UnfinalizedObjectList) *listCount), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL == unfinalizedObjectLists) {
return false;
}
for (UDATA index = 0; index < listCount; index++) {
new(&unfinalizedObjectLists[index]) MM_UnfinalizedObjectList();
/* add each list to the global list. we need to maintain the doubly linked list
* to ensure uniformity with SE/Balanced.
*/
MM_UnfinalizedObjectList *previousUnfinalizedObjectList = (0 == index) ? NULL : &unfinalizedObjectLists[index - 1];
MM_UnfinalizedObjectList *nextUnfinalizedObjectList = ((listCount - 1) == index) ? NULL : &unfinalizedObjectLists[index + 1];
unfinalizedObjectLists[index].setNextList(nextUnfinalizedObjectList);
unfinalizedObjectLists[index].setPreviousList(previousUnfinalizedObjectList);
}
_extensions->unfinalizedObjectLists = unfinalizedObjectLists;
return true;
}
bool
MM_MetronomeDelegate::allocateAndInitializeOwnableSynchronizerObjectLists(MM_EnvironmentBase *env)
{
const UDATA listCount = getOwnableSynchronizerObjectListCount(env);
Assert_MM_true(0 < listCount);
MM_OwnableSynchronizerObjectList *ownableSynchronizerObjectLists = (MM_OwnableSynchronizerObjectList *)env->getForge()->allocate((sizeof(MM_OwnableSynchronizerObjectList) *listCount), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL == ownableSynchronizerObjectLists) {
return false;
}
for (UDATA index = 0; index < listCount; index++) {
new(&ownableSynchronizerObjectLists[index]) MM_OwnableSynchronizerObjectList();
/* add each list to the global list. we need to maintain the doubly linked list
* to ensure uniformity with SE/Balanced.
*/
MM_OwnableSynchronizerObjectList *previousOwnableSynchronizerObjectList = (0 == index) ? NULL : &ownableSynchronizerObjectLists[index - 1];
MM_OwnableSynchronizerObjectList *nextOwnableSynchronizerObjectList = ((listCount - 1) == index) ? NULL : &ownableSynchronizerObjectLists[index + 1];
ownableSynchronizerObjectLists[index].setNextList(nextOwnableSynchronizerObjectList);
ownableSynchronizerObjectLists[index].setPreviousList(previousOwnableSynchronizerObjectList);
}
_extensions->setOwnableSynchronizerObjectLists(ownableSynchronizerObjectLists);
return true;
}
bool
MM_MetronomeDelegate::allocateAndInitializeContinuationObjectLists(MM_EnvironmentBase *env)
{
const UDATA listCount = getContinuationObjectListCount(env);
Assert_MM_true(0 < listCount);
MM_ContinuationObjectList *continuationObjectLists = (MM_ContinuationObjectList *)env->getForge()->allocate((sizeof(MM_ContinuationObjectList) *listCount), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
if (NULL == continuationObjectLists) {
return false;
}
for (UDATA index = 0; index < listCount; index++) {
new(&continuationObjectLists[index]) MM_ContinuationObjectList();
/* add each list to the global list. we need to maintain the doubly linked list
* to ensure uniformity with SE/Balanced.
*/
MM_ContinuationObjectList *previousContinuationObjectList = (0 == index) ? NULL : &continuationObjectLists[index - 1];
MM_ContinuationObjectList *nextContinuationObjectList = ((listCount - 1) == index) ? NULL : &continuationObjectLists[index + 1];
continuationObjectLists[index].setNextList(nextContinuationObjectList);
continuationObjectLists[index].setPreviousList(previousContinuationObjectList);
}
_extensions->setContinuationObjectLists(continuationObjectLists);
return true;
}
void
MM_MetronomeDelegate::tearDown(MM_EnvironmentBase *env)
{
if (NULL != _extensions->referenceObjectLists) {
env->getForge()->free(_extensions->referenceObjectLists);
_extensions->referenceObjectLists = NULL;
}
if (NULL != _extensions->unfinalizedObjectLists) {
env->getForge()->free(_extensions->unfinalizedObjectLists);
_extensions->unfinalizedObjectLists = NULL;
}
if (NULL != _extensions->getOwnableSynchronizerObjectLists()) {
env->getForge()->free(_extensions->getOwnableSynchronizerObjectLists());
_extensions->setOwnableSynchronizerObjectLists(NULL);
}
if (NULL != _extensions->getContinuationObjectLists()) {
env->getForge()->free(_extensions->getContinuationObjectLists());
_extensions->setContinuationObjectLists(NULL);
}
if (NULL != _extensions->accessBarrier) {
_extensions->accessBarrier->kill(env);
_extensions->accessBarrier = NULL;
}
_javaVM->realtimeHeapMapBits = NULL;
}
void
MM_MetronomeDelegate::mainSetupForGC(MM_EnvironmentBase *env)
{
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
/* Set the dynamic class unloading flag based on command line and runtime state */
switch (_extensions->dynamicClassUnloading) {
case MM_GCExtensions::DYNAMIC_CLASS_UNLOADING_NEVER:
_extensions->runtimeCheckDynamicClassUnloading = false;
break;
case MM_GCExtensions::DYNAMIC_CLASS_UNLOADING_ALWAYS:
_extensions->runtimeCheckDynamicClassUnloading = true;
break;
case MM_GCExtensions::DYNAMIC_CLASS_UNLOADING_ON_CLASS_LOADER_CHANGES:
_extensions->runtimeCheckDynamicClassUnloading = (_extensions->aggressive || _extensions->classLoaderManager->isTimeForClassUnloading(env));
break;
default:
break;
}
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
#if defined(J9VM_GC_FINALIZATION)
_finalizationRequired = false;
#endif /* J9VM_GC_FINALIZATION */
}
void
MM_MetronomeDelegate::mainCleanupAfterGC(MM_EnvironmentBase *env)
{
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
/* flush the dead class segments if their size exceeds the CacheSize mark.
* Heap fixup should have been completed in this cycle.
*/
if (_extensions->classLoaderManager->reclaimableMemory() > _extensions->deadClassLoaderCacheSize) {
Trc_MM_FlushUndeadSegments_Entry(env->getLanguageVMThread(), "Non-zero reclaimable memory available");
_extensions->classLoaderManager->flushUndeadSegments(env);
Trc_MM_FlushUndeadSegments_Exit(env->getLanguageVMThread());
}
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
}
void
MM_MetronomeDelegate::incrementalCollectStart(MM_EnvironmentRealtime *env)
{
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
_dynamicClassUnloadingEnabled = ((_extensions->runtimeCheckDynamicClassUnloading != 0) ? true : false);
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
}
void
MM_MetronomeDelegate::incrementalCollect(MM_EnvironmentRealtime *env)
{
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
PORT_ACCESS_FROM_ENVIRONMENT(env);
_dynamicClassUnloadingEnabled = ((_extensions->runtimeCheckDynamicClassUnloading != 0) ? true : false);
if (_extensions->runtimeCheckDynamicClassUnloading != 0) {
MM_ClassUnloadStats *classUnloadStats = &_extensions->globalGCStats.classUnloadStats;
_realtimeGC->setCollectorUnloadingClassLoaders();
reportClassUnloadingStart(env);
classUnloadStats->_startTime = j9time_hires_clock();
unloadDeadClassLoaders(env);
classUnloadStats->_endTime = j9time_hires_clock();
reportClassUnloadingEnd(env);
/* If there was dynamic class unloading checks during the run, record the new number of class
* loaders last seen during a DCU pass
*/
_extensions->classLoaderManager->setLastUnloadNumOfClassLoaders();
_extensions->classLoaderManager->setLastUnloadNumOfAnonymousClasses();
}
/* Handling of classes done. Return back to "mark if necessary" mode */
_unmarkedImpliesClasses = false;
/* Clear the appropriate flags of all classLoaders */
GC_ClassLoaderIterator classLoaderIterator(_javaVM->classLoaderBlocks);
J9ClassLoader *classLoader;
while((classLoader = classLoaderIterator.nextSlot()) != NULL) {
classLoader->gcFlags &= ~J9_GC_CLASS_LOADER_SCANNED;
}
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
/* If the J9VM_DEBUG_ATTRIBUTE_ALLOW_USER_HEAP_WALK flag is set,
* or if we are about to unload classes and free class memory segments
* then fix the heap so that it can be walked by debugging tools
*/
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
bool fixupForClassUnload = (_extensions->classLoaderManager->reclaimableMemory() > _extensions->deadClassLoaderCacheSize);
#else /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
bool fixupForClassUnload = false;
#endif /* defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING) */
if (J9VM_DEBUG_ATTRIBUTE_ALLOW_USER_HEAP_WALK == (((J9JavaVM *)env->getLanguageVM())->requiredDebugAttributes & J9VM_DEBUG_ATTRIBUTE_ALLOW_USER_HEAP_WALK)
|| fixupForClassUnload) {
_realtimeGC->_fixHeapForWalk = true;
}
}
void
MM_MetronomeDelegate::doAuxiliaryGCWork(MM_EnvironmentBase *env)
{
#if defined(J9VM_GC_FINALIZATION)
if (isFinalizationRequired()) {
omrthread_monitor_enter(_javaVM->finalizeMainMonitor);
_javaVM->finalizeMainFlags |= J9_FINALIZE_FLAGS_MAIN_WAKE_UP;
omrthread_monitor_notify_all(_javaVM->finalizeMainMonitor);
omrthread_monitor_exit(_javaVM->finalizeMainMonitor);
}
#endif /* J9VM_GC_FINALIZATION */
}
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
void
MM_MetronomeDelegate::processDyingClasses(MM_EnvironmentRealtime *env, UDATA *classUnloadCountResult, UDATA *anonymousClassUnloadCountResult, UDATA *classLoaderUnloadCountResult, J9ClassLoader **classLoaderUnloadListResult)
{
J9ClassLoader *classLoader = NULL;
J9VMThread *vmThread = (J9VMThread *)env->getLanguageVMThread();
UDATA classUnloadCount = 0;
UDATA anonymousClassUnloadCount = 0;
UDATA classLoaderUnloadCount = 0;
J9ClassLoader *unloadLink = NULL;
J9Class *classUnloadList = NULL;
J9Class *anonymousClassUnloadList = NULL;
/*
* Verify that boolean array class has been marked. Assertion is done to ensure correctness
* of an optimization in ClassIteratorClassSlots that only checks booleanArrayClass Interfaces
* since all array claseses share the same ITable.
*/
Assert_MM_true(_markingScheme->isMarked(_javaVM->booleanArrayClass->classObject));
/*
* Walk anonymous classes and set unmarked as dying
*
* Do this walk before classloaders to be unloaded walk to create list of anonymous classes to be unloaded and use it
* as sublist to continue to build general list of classes to be unloaded
*
* Anonymous classes suppose to be allocated one per segment
* This is not relevant here however becomes important at segment removal time
*/
anonymousClassUnloadList = addDyingClassesToList(env, _javaVM->anonClassLoader, false, anonymousClassUnloadList, &anonymousClassUnloadCount);
/* class unload list includes anonymous class unload list */
classUnloadList = anonymousClassUnloadList;
classUnloadCount += anonymousClassUnloadCount;
GC_ClassLoaderLinkedListIterator classLoaderIterator(env, _extensions->classLoaderManager);
while (NULL != (classLoader = (J9ClassLoader *)classLoaderIterator.nextSlot())) {
if (0 == (classLoader->gcFlags & J9_GC_CLASS_LOADER_DEAD)) {
Assert_MM_true(NULL == classLoader->unloadLink);
if (_markingScheme->isMarked(classLoader->classLoaderObject) ) {
classLoader->gcFlags &= ~J9_GC_CLASS_LOADER_SCANNED;
} else {
/* Anonymous classloader should not be unloaded */
Assert_MM_true(0 == (classLoader->flags & J9CLASSLOADER_ANON_CLASS_LOADER));
classLoaderUnloadCount += 1;
classLoader->gcFlags |= J9_GC_CLASS_LOADER_DEAD;
/* add this loader to the linked list of loaders being unloaded in this cycle */
classLoader->unloadLink = unloadLink;
unloadLink = classLoader;
classUnloadList = addDyingClassesToList(env, classLoader, true, classUnloadList, &classUnloadCount);
}
}
yieldFromClassUnloading(env);
}
if (0 != classUnloadCount) {
/* Call classes unload hook */
TRIGGER_J9HOOK_VM_CLASSES_UNLOAD(_javaVM->hookInterface, vmThread, classUnloadCount, classUnloadList);
yieldFromClassUnloading(env);
}
if (0 != anonymousClassUnloadCount) {
/* Call anonymous classes unload hook */
TRIGGER_J9HOOK_VM_ANON_CLASSES_UNLOAD(_javaVM->hookInterface, vmThread, anonymousClassUnloadCount, anonymousClassUnloadList);
yieldFromClassUnloading(env);
}
if (0 != classLoaderUnloadCount) {
/* Call classloader unload hook */
TRIGGER_J9HOOK_VM_CLASS_LOADERS_UNLOAD(_javaVM->hookInterface, vmThread, unloadLink);
yieldFromClassUnloading(env);
}
/* Ensure that the VM has an accurate anonymous class count */
_javaVM->anonClassCount -= anonymousClassUnloadCount;
*classUnloadCountResult = classUnloadCount;
*anonymousClassUnloadCountResult = anonymousClassUnloadCount;
*classLoaderUnloadCountResult = classLoaderUnloadCount;
*classLoaderUnloadListResult = unloadLink;
}
J9Class *
MM_MetronomeDelegate::addDyingClassesToList(MM_EnvironmentRealtime *env, J9ClassLoader *classLoader, bool setAll, J9Class *classUnloadListStart, UDATA *classUnloadCountResult)
{
J9VMThread *vmThread = (J9VMThread *)env->getLanguageVMThread();
J9Class *classUnloadList = classUnloadListStart;
UDATA classUnloadCount = 0;
if (NULL != classLoader) {
GC_ClassLoaderSegmentIterator segmentIterator(classLoader, MEMORY_TYPE_RAM_CLASS);
J9MemorySegment *segment = NULL;
while (NULL != (segment = segmentIterator.nextSegment())) {
GC_ClassHeapIterator classHeapIterator(_javaVM, segment);
J9Class *clazz = NULL;
while (NULL != (clazz = classHeapIterator.nextClass())) {
J9CLASS_EXTENDED_FLAGS_CLEAR(clazz, J9ClassGCScanned);
J9Object *classObject = clazz->classObject;
if (setAll || !_markingScheme->isMarked(classObject)) {
/* with setAll all classes must be unmarked */
Assert_MM_true(!_markingScheme->isMarked(classObject));
classUnloadCount += 1;
/* Remove the class from the subclass traversal list */
_extensions->classLoaderManager->removeFromSubclassHierarchy(env, clazz);
/* Mark class as dying */
clazz->classDepthAndFlags |= J9AccClassDying;
/* Call class unload hook */
Trc_MM_cleanUpClassLoadersStart_triggerClassUnload(env->getLanguageVMThread(),clazz,
(UDATA) J9UTF8_LENGTH(J9ROMCLASS_CLASSNAME(clazz->romClass)),
J9UTF8_DATA(J9ROMCLASS_CLASSNAME(clazz->romClass)));
TRIGGER_J9HOOK_VM_CLASS_UNLOAD(_javaVM->hookInterface, vmThread, clazz);
/* add class to dying anonymous classes link list */
clazz->gcLink = classUnloadList;
classUnloadList = clazz;
}
}
}
}
*classUnloadCountResult += classUnloadCount;
return classUnloadList;
}
/**
* Free classloaders which are being unloaded during this GC cycle. Also remove all
* dead classes from the traversal list.
* @note the traversal code belongs in its own function or possibly processDyingClasses
* or possible processDyingClasses. It is currently here for historic reasons.
*
* @param deadClassLoaders Linked list of classloaders dying during this GC cycle
*/
void
MM_MetronomeDelegate::processUnlinkedClassLoaders(MM_EnvironmentBase *envModron, J9ClassLoader *deadClassLoaders)
{
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envModron);
J9ClassLoader *unloadLink = deadClassLoaders;
J9VMThread *vmThread = (J9VMThread *)env->getLanguageVMThread();
J9JavaVM *javaVM = (J9JavaVM *)env->getLanguageVM();
/* Remove dead classes from the traversal list (if necessary) */
J9Class *jlObject = J9VMJAVALANGOBJECT_OR_NULL(javaVM);
J9Class *previousClass = jlObject;
J9Class *nextClass = (NULL != jlObject) ? jlObject->subclassTraversalLink : jlObject;
while ((NULL != nextClass) && (jlObject != nextClass)) {
if (J9CLASS_FLAGS(nextClass) & J9AccClassDying) {
while ((NULL != nextClass->subclassTraversalLink) && (jlObject != nextClass) && (J9CLASS_FLAGS(nextClass) & 0x08000000)) {
nextClass = nextClass->subclassTraversalLink;
}
previousClass->subclassTraversalLink = nextClass;
}
previousClass = nextClass;
nextClass = nextClass->subclassTraversalLink;
/* TODO CRGTMP Do we need to yield here? Is yielding safe? */
}
/* Free memory for dead classloaders */
while (NULL != unloadLink) {
J9ClassLoader *nextUnloadLink = unloadLink->unloadLink;
_javaVM->internalVMFunctions->freeClassLoader(unloadLink, _javaVM, vmThread, 1);
unloadLink = nextUnloadLink;
yieldFromClassUnloading(env);
}
}
void
MM_MetronomeDelegate::updateClassUnloadStats(MM_EnvironmentBase *env, UDATA classUnloadCount, UDATA anonymousClassUnloadCount, UDATA classLoaderUnloadCount)
{
MM_ClassUnloadStats *classUnloadStats = &_extensions->globalGCStats.classUnloadStats;
/* TODO CRGTMP move global stats into super class implementation once it is created */
classUnloadStats->updateUnloadedCounters(anonymousClassUnloadCount, classUnloadCount, classLoaderUnloadCount);
/* Record increment stats */
_extensions->globalGCStats.metronomeStats.classesUnloadedCount = classUnloadCount;
_extensions->globalGCStats.metronomeStats.anonymousClassesUnloadedCount = anonymousClassUnloadCount;
_extensions->globalGCStats.metronomeStats.classLoaderUnloadedCount = classLoaderUnloadCount;
}
/**
* Unload classcloaders that are no longer referenced. If the classloader has shared
* libraries open place it on the finalize queue instead of freeing it.
*
*/
void
MM_MetronomeDelegate::unloadDeadClassLoaders(MM_EnvironmentBase *envModron)
{
MM_EnvironmentRealtime *env = MM_EnvironmentRealtime::getEnvironment(envModron);
J9ClassLoader *unloadLink = NULL;
UDATA classUnloadCount = 0;
UDATA anonymousClassUnloadCount = 0;
UDATA classLoaderUnloadCount = 0;
J9ClassLoader *classLoadersUnloadedList = NULL;
J9MemorySegment *reclaimedSegments = NULL;
/* set the vmState whilst we're unloading classes */
UDATA vmState = env->pushVMstate(OMRVMSTATE_GC_CLEANING_METADATA);
lockClassUnloadMonitor(env);
processDyingClasses(env, &classUnloadCount, &anonymousClassUnloadCount, &classLoaderUnloadCount, &classLoadersUnloadedList);
if (0 < anonymousClassUnloadCount) {
/* cleanup segments in anonymous classloader */
_extensions->classLoaderManager->cleanUpSegmentsInAnonymousClassLoader(env, &reclaimedSegments);
/* enqueue all the segments we just salvaged from the anonymous classloader for delayed free */
_extensions->classLoaderManager->enqueueUndeadClassSegments(reclaimedSegments);
}
yieldFromClassUnloading(env);
GC_FinalizableClassLoaderBuffer buffer(_extensions);
while (NULL != classLoadersUnloadedList) {
/* fetch the next loader immediately, since we will re-use the unloadLink in this loop */
J9ClassLoader* classLoader = classLoadersUnloadedList;
classLoadersUnloadedList = classLoader->unloadLink;
Assert_MM_true(0 == (classLoader->gcFlags & J9_GC_CLASS_LOADER_SCANNED));
Assert_MM_true(J9_GC_CLASS_LOADER_DEAD == (classLoader->gcFlags & J9_GC_CLASS_LOADER_DEAD));
Assert_MM_true(0 == (classLoader->gcFlags & (J9_GC_CLASS_LOADER_UNLOADING | J9_GC_CLASS_LOADER_ENQ_UNLOAD)));
/* Class loader died this collection, so do cleanup work */
reclaimedSegments = NULL;
/* Perform classLoader-specific clean up work, including freeing the classLoader's class hash table and
* class path entries.
*/
_javaVM->internalVMFunctions->cleanUpClassLoader((J9VMThread *)env->getLanguageVMThread(), classLoader);
/* free any ROM classes now and enqueue any RAM classes */
_extensions->classLoaderManager->cleanUpSegmentsAlongClassLoaderLink(_javaVM, classLoader->classSegments, &reclaimedSegments);
/* we are taking responsibility for cleaning these here so free them */
classLoader->classSegments = NULL;
/* enqueue all the segments we just salvaged from the dead class loaders for delayed free (this work was historically attributed in the unload end operation so it goes after the timer start) */
_extensions->classLoaderManager->enqueueUndeadClassSegments(reclaimedSegments);
/* Remove this classloader slot */
_extensions->classLoaderManager->unlinkClassLoader(classLoader);
#if defined(J9VM_GC_FINALIZATION)
/* Determine if the classLoader needs to be enqueued for finalization (for shared library unloading),
* otherwise add it to the list of classLoaders to be unloaded by cleanUpClassLoadersEnd.
*/
if (((NULL != classLoader->sharedLibraries)
&& (0 != pool_numElements(classLoader->sharedLibraries)))
|| (_extensions->fvtest_forceFinalizeClassLoaders)) {
/* Attempt to enqueue the class loader for the finalizer */
buffer.add(env, classLoader);
classLoader->gcFlags |= J9_GC_CLASS_LOADER_ENQ_UNLOAD;
_finalizationRequired = true;
} else
#endif /* J9VM_GC_FINALIZATION */
{
/* Add the classLoader to the list of classLoaders to unloaded by cleanUpClassLoadersEnd */
classLoader->unloadLink = unloadLink;
unloadLink = classLoader;
}
yieldFromClassUnloading(env);
}
buffer.flush(env);
updateClassUnloadStats(env, classUnloadCount, anonymousClassUnloadCount, classLoaderUnloadCount);
processUnlinkedClassLoaders(env, unloadLink);
unlockClassUnloadMonitor(env);
env->popVMstate(vmState);
}
/**
* Check to see if it is time to yield. If it is time to yield the GC
* must release the classUnloadMonitor before yielding. Once the GC
* comes back from the yield it is required to acquire the classUnloadMonitor
* again.
*/
void
MM_MetronomeDelegate::yieldFromClassUnloading(MM_EnvironmentRealtime *env)
{
if (_realtimeGC->shouldYield(env)) {
unlockClassUnloadMonitor(env);
_realtimeGC->yield(env);
lockClassUnloadMonitor(env);
}
}
/**
* The GC is required to hold the classUnloadMonitor while it is unloading classes.
* This will ensure that the JIT will abort and ongoing compilations
*/
void
MM_MetronomeDelegate::lockClassUnloadMonitor(MM_EnvironmentRealtime *env)
{
/* Grab the classUnloadMonitor so that the JIT and the GC will not interfere with each other */
if (!_javaVM->isClassUnloadMutexHeldForRedefinition) {
#if defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR)
if (0 != omrthread_rwmutex_try_enter_write(_javaVM->classUnloadMutex)) {
#else /* defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR) */
if (0 != omrthread_monitor_try_enter(_javaVM->classUnloadMutex)) {
#endif /* defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR) */
/* Failed acquire the monitor so interrupt the JIT. This will allow the GC
* to continue unloading classes.
*/
TRIGGER_J9HOOK_MM_INTERRUPT_COMPILATION(_extensions->hookInterface, (J9VMThread *)env->getLanguageVMThread());
#if defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR)
omrthread_rwmutex_enter_write(_javaVM->classUnloadMutex);
#else /* defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR) */
omrthread_monitor_enter(_javaVM->classUnloadMutex);
#endif /* defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR) */
}
}
}
/**
* Release the classUnloadMonitor. This will allow the JIT to compile new methods.
*/
void
MM_MetronomeDelegate::unlockClassUnloadMonitor(MM_EnvironmentRealtime *env)
{
if (!_javaVM->isClassUnloadMutexHeldForRedefinition) {
#if defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR)
omrthread_rwmutex_exit_write(_javaVM->classUnloadMutex);
#else /* defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR) */
omrthread_monitor_exit(_javaVM->classUnloadMutex);
#endif /* defined(J9VM_JIT_CLASS_UNLOAD_RWMONITOR) */
}
}
void
MM_MetronomeDelegate::reportClassUnloadingStart(MM_EnvironmentBase *env)
{
PORT_ACCESS_FROM_ENVIRONMENT(env);
Trc_MM_ClassUnloadingStart(env->getLanguageVMThread());
TRIGGER_J9HOOK_MM_PRIVATE_CLASS_UNLOADING_START(
_extensions->privateHookInterface,
env->getOmrVMThread(),
j9time_hires_clock(),
J9HOOK_MM_PRIVATE_CLASS_UNLOADING_START);
}
void
MM_MetronomeDelegate::reportClassUnloadingEnd(MM_EnvironmentBase *env)
{
PORT_ACCESS_FROM_ENVIRONMENT(env);
MM_ClassUnloadStats *classUnloadStats = &_extensions->globalGCStats.classUnloadStats;
Trc_MM_ClassUnloadingEnd(env->getLanguageVMThread(),
classUnloadStats->_classLoaderUnloadedCount,
classUnloadStats->_classesUnloadedCount);
TRIGGER_J9HOOK_MM_CLASS_UNLOADING_END(
_extensions->hookInterface,
(J9VMThread *)env->getLanguageVMThread(),
j9time_hires_clock(),
J9HOOK_MM_CLASS_UNLOADING_END,
classUnloadStats->_endTime - classUnloadStats->_startTime,
classUnloadStats->_classLoaderUnloadedCount,
classUnloadStats->_classesUnloadedCount,
classUnloadStats->_classUnloadMutexQuiesceTime,
classUnloadStats->_endSetupTime - classUnloadStats->_startSetupTime,
classUnloadStats->_endScanTime - classUnloadStats->_startScanTime,
classUnloadStats->_endPostTime - classUnloadStats->_startPostTime);
}
#endif /* J9VM_GC_DYNAMIC_CLASS_UNLOADING */
void
MM_MetronomeDelegate::reportSyncGCEnd(MM_EnvironmentBase *env)
{
OMRPORT_ACCESS_FROM_ENVIRONMENT(env);
UDATA approximateFreeMemorySize = _extensions->heap->getApproximateActiveFreeMemorySize();
#if defined(OMR_GC_DYNAMIC_CLASS_UNLOADING)
MM_ClassUnloadStats *classUnloadStats = &_extensions->globalGCStats.classUnloadStats;
UDATA classLoaderUnloadCount = classUnloadStats->_classLoaderUnloadedCount;
UDATA classUnloadCount = classUnloadStats->_classesUnloadedCount;
UDATA anonymousClassUnloadCount = classUnloadStats->_anonymousClassesUnloadedCount;
#else /* defined(OMR_GC_DYNAMIC_CLASS_UNLOADING) */
UDATA classLoaderUnloadCount = 0;
UDATA classUnloadCount = 0;
UDATA anonymousClassUnloadCount = 0;
#endif /* defined(OMR_GC_DYNAMIC_CLASS_UNLOADING) */
UDATA weakReferenceCount = _extensions->markJavaStats._weakReferenceStats._cleared;
UDATA softReferenceCount = _extensions->markJavaStats._softReferenceStats._cleared;
UDATA maxSoftReferenceAge = _extensions->getMaxSoftReferenceAge();
UDATA softReferenceAge = _extensions->getDynamicMaxSoftReferenceAge();
UDATA phantomReferenceCount = _extensions->markJavaStats._phantomReferenceStats._cleared;
UDATA finalizerCount = _extensions->globalGCStats.metronomeStats.getWorkPacketOverflowCount();
UDATA packetOverflowCount = _extensions->globalGCStats.metronomeStats.getWorkPacketOverflowCount();
UDATA objectOverflowCount = _extensions->globalGCStats.metronomeStats.getObjectOverflowCount();
Trc_MM_SynchGCEnd(env->getLanguageVMThread(),
approximateFreeMemorySize,
0,
classLoaderUnloadCount,
classUnloadCount,
weakReferenceCount,
softReferenceCount,
maxSoftReferenceAge,
softReferenceAge,
phantomReferenceCount,
finalizerCount,
packetOverflowCount,
objectOverflowCount
);
TRIGGER_J9HOOK_MM_PRIVATE_METRONOME_SYNCHRONOUS_GC_END(_extensions->privateHookInterface,
env->getOmrVMThread(), omrtime_hires_clock(),
J9HOOK_MM_PRIVATE_METRONOME_SYNCHRONOUS_GC_END,
approximateFreeMemorySize,
0,
classLoaderUnloadCount,
classUnloadCount,
anonymousClassUnloadCount,
weakReferenceCount,
softReferenceCount,
maxSoftReferenceAge,
softReferenceAge,
phantomReferenceCount,
finalizerCount,
packetOverflowCount,
objectOverflowCount
);
}
/**
* Factory method for creating the access barrier. Note that the default realtime access barrier
* doesn't handle the RTSJ checks.
*/
MM_RealtimeAccessBarrier*
MM_MetronomeDelegate::allocateAccessBarrier(MM_EnvironmentBase *env)
{
return MM_RealtimeAccessBarrier::newInstance(env);
}
/**
* Iterates over all threads and enables the double barrier for each thread by setting the
* remembered set fragment index to the reserved index.
*/
void
MM_MetronomeDelegate::enableDoubleBarrier(MM_EnvironmentBase *env)
{
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
MM_RealtimeAccessBarrier* realtimeAccessBarrier = (MM_RealtimeAccessBarrier*)extensions->accessBarrier;
GC_VMThreadListIterator vmThreadListIterator(_javaVM);
/* First, enable the global double barrier flag so new threads will have the double barrier enabled. */
realtimeAccessBarrier->setDoubleBarrierActive();
while (J9VMThread* thread = vmThreadListIterator.nextVMThread()) {
/* Second, enable the double barrier on all threads individually. */
realtimeAccessBarrier->setDoubleBarrierActiveOnThread(MM_EnvironmentBase::getEnvironment(thread->omrVMThread));
}
}
/**
* Disables the double barrier for the specified thread.
*/
void
MM_MetronomeDelegate::disableDoubleBarrierOnThread(MM_EnvironmentBase *env, OMR_VMThread *vmThread)
{
/* This gets called on a per thread basis as threads get scanned. */
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
MM_RealtimeAccessBarrier* realtimeAccessBarrier = (MM_RealtimeAccessBarrier *)extensions->accessBarrier;
realtimeAccessBarrier->setDoubleBarrierInactiveOnThread(MM_EnvironmentBase::getEnvironment(vmThread));
}
/**
* Disables the global double barrier flag. This should be called after all threads have been scanned
* and disableDoubleBarrierOnThread has been called on each of them.
*/
void
MM_MetronomeDelegate::disableDoubleBarrier(MM_EnvironmentBase *env)
{
/* The enabling of the double barrier must traverse all threads, but the double barrier gets disabled
* on a per thread basis as threads get scanned, so no need to traverse all threads in this method.
*/
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);
MM_RealtimeAccessBarrier *realtimeAccessBarrier = (MM_RealtimeAccessBarrier *)extensions->accessBarrier;
realtimeAccessBarrier->setDoubleBarrierInactive();
}
#if defined(J9VM_GC_DYNAMIC_CLASS_UNLOADING)
/**
* Walk all class loaders marking their classes if the classLoader object has been
* marked.
*
* @return true if any classloaders/classes are marked, false otherwise
*/
bool
MM_MetronomeDelegate::doClassTracing(MM_EnvironmentRealtime *env)
{
J9ClassLoader *classLoader;
bool didWork = false;
MM_GCExtensions* extensions = MM_GCExtensions::getExtensions(env);
GC_ClassLoaderLinkedListIterator classLoaderIterator(env, extensions->classLoaderManager);
while ((classLoader = (J9ClassLoader *)classLoaderIterator.nextSlot()) != NULL) {
if (0 == (classLoader->gcFlags & J9_GC_CLASS_LOADER_DEAD)) {
if (J9CLASSLOADER_ANON_CLASS_LOADER == (classLoader->flags & J9CLASSLOADER_ANON_CLASS_LOADER)) {
/* Anonymous classloader should be scanned on level of classes every time */
GC_ClassLoaderSegmentIterator segmentIterator(classLoader, MEMORY_TYPE_RAM_CLASS);
J9MemorySegment *segment = NULL;
while (NULL != (segment = segmentIterator.nextSegment())) {
GC_ClassHeapIterator classHeapIterator(_javaVM, segment);
J9Class *clazz = NULL;
while (NULL != (clazz = classHeapIterator.nextClass())) {
if ((0 == (J9CLASS_EXTENDED_FLAGS(clazz) & J9ClassGCScanned)) && _markingScheme->isMarked(clazz->classObject)) {
J9CLASS_EXTENDED_FLAGS_SET(clazz, J9ClassGCScanned);
/* Scan class */
GC_ClassIterator objectSlotIterator(env, clazz);
volatile j9object_t *objectSlotPtr = NULL;
while ((objectSlotPtr = objectSlotIterator.nextSlot()) != NULL) {
didWork |= _markingScheme->markObject(env, *objectSlotPtr);
}
GC_ClassIteratorClassSlots classSlotIterator(_javaVM, clazz);
J9Class *classPtr;
while (NULL != (classPtr = classSlotIterator.nextSlot())) {
didWork |= markClass(env, classPtr);
}
}
}
_realtimeGC->condYield(env, 0);
}
} else {
/* Check if the class loader has not been scanned but the class loader is live */
if (!(classLoader->gcFlags & J9_GC_CLASS_LOADER_SCANNED) && _markingScheme->isMarked((J9Object *)classLoader->classLoaderObject)) {
/* Flag the class loader as being scanned */
classLoader->gcFlags |= J9_GC_CLASS_LOADER_SCANNED;
GC_ClassLoaderSegmentIterator segmentIterator(classLoader, MEMORY_TYPE_RAM_CLASS);
J9MemorySegment *segment = NULL;
J9Class *clazz;
while (NULL != (segment = segmentIterator.nextSegment())) {
GC_ClassHeapIterator classHeapIterator(_javaVM, segment);
while (NULL != (clazz = classHeapIterator.nextClass())) {
/* Scan class */
GC_ClassIterator objectSlotIterator(env, clazz);
volatile j9object_t *objectSlotPtr = NULL;
while ((objectSlotPtr = objectSlotIterator.nextSlot()) != NULL) {
didWork |= _markingScheme->markObject(env, *objectSlotPtr);
}
GC_ClassIteratorClassSlots classSlotIterator(_javaVM, clazz);
J9Class *classPtr;
while (NULL != (classPtr = classSlotIterator.nextSlot())) {