Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 3776:23d434c6290d
7055073: G1: code cleanup in the concurrentMark.* files
Summary: Only cosmetic changes to make the concurrentMark.* more consistent, code-style-wise, with the rest of the codebase.
Reviewed-by: johnc, ysr
author | tonyp |
---|---|
date | Mon, 20 Jun 2011 22:03:13 -0400 |
parents | 6747fd0512e0 |
children | 5f6f2615433a |
comparison
equal
deleted
inserted
replaced
3775:f75137faa7fe | 3776:23d434c6290d |
---|---|
68 HeapWord* limit) const { | 68 HeapWord* limit) const { |
69 // First we must round addr *up* to a possible object boundary. | 69 // First we must round addr *up* to a possible object boundary. |
70 addr = (HeapWord*)align_size_up((intptr_t)addr, | 70 addr = (HeapWord*)align_size_up((intptr_t)addr, |
71 HeapWordSize << _shifter); | 71 HeapWordSize << _shifter); |
72 size_t addrOffset = heapWordToOffset(addr); | 72 size_t addrOffset = heapWordToOffset(addr); |
73 if (limit == NULL) limit = _bmStartWord + _bmWordSize; | 73 if (limit == NULL) { |
74 limit = _bmStartWord + _bmWordSize; | |
75 } | |
74 size_t limitOffset = heapWordToOffset(limit); | 76 size_t limitOffset = heapWordToOffset(limit); |
75 size_t nextOffset = _bm.get_next_one_offset(addrOffset, limitOffset); | 77 size_t nextOffset = _bm.get_next_one_offset(addrOffset, limitOffset); |
76 HeapWord* nextAddr = offsetToHeapWord(nextOffset); | 78 HeapWord* nextAddr = offsetToHeapWord(nextOffset); |
77 assert(nextAddr >= addr, "get_next_one postcondition"); | 79 assert(nextAddr >= addr, "get_next_one postcondition"); |
78 assert(nextAddr == limit || isMarked(nextAddr), | 80 assert(nextAddr == limit || isMarked(nextAddr), |
81 } | 83 } |
82 | 84 |
83 HeapWord* CMBitMapRO::getNextUnmarkedWordAddress(HeapWord* addr, | 85 HeapWord* CMBitMapRO::getNextUnmarkedWordAddress(HeapWord* addr, |
84 HeapWord* limit) const { | 86 HeapWord* limit) const { |
85 size_t addrOffset = heapWordToOffset(addr); | 87 size_t addrOffset = heapWordToOffset(addr); |
86 if (limit == NULL) limit = _bmStartWord + _bmWordSize; | 88 if (limit == NULL) { |
89 limit = _bmStartWord + _bmWordSize; | |
90 } | |
87 size_t limitOffset = heapWordToOffset(limit); | 91 size_t limitOffset = heapWordToOffset(limit); |
88 size_t nextOffset = _bm.get_next_zero_offset(addrOffset, limitOffset); | 92 size_t nextOffset = _bm.get_next_zero_offset(addrOffset, limitOffset); |
89 HeapWord* nextAddr = offsetToHeapWord(nextOffset); | 93 HeapWord* nextAddr = offsetToHeapWord(nextOffset); |
90 assert(nextAddr >= addr, "get_next_one postcondition"); | 94 assert(nextAddr >= addr, "get_next_one postcondition"); |
91 assert(nextAddr == limit || !isMarked(nextAddr), | 95 assert(nextAddr == limit || !isMarked(nextAddr), |
175 #endif | 179 #endif |
176 {} | 180 {} |
177 | 181 |
178 void CMMarkStack::allocate(size_t size) { | 182 void CMMarkStack::allocate(size_t size) { |
179 _base = NEW_C_HEAP_ARRAY(oop, size); | 183 _base = NEW_C_HEAP_ARRAY(oop, size); |
180 if (_base == NULL) | 184 if (_base == NULL) { |
181 vm_exit_during_initialization("Failed to allocate " | 185 vm_exit_during_initialization("Failed to allocate " |
182 "CM region mark stack"); | 186 "CM region mark stack"); |
187 } | |
183 _index = 0; | 188 _index = 0; |
184 // QQQQ cast ... | |
185 _capacity = (jint) size; | 189 _capacity = (jint) size; |
186 _oops_do_bound = -1; | 190 _oops_do_bound = -1; |
187 NOT_PRODUCT(_max_depth = 0); | 191 NOT_PRODUCT(_max_depth = 0); |
188 } | 192 } |
189 | 193 |
190 CMMarkStack::~CMMarkStack() { | 194 CMMarkStack::~CMMarkStack() { |
191 if (_base != NULL) FREE_C_HEAP_ARRAY(oop, _base); | 195 if (_base != NULL) { |
196 FREE_C_HEAP_ARRAY(oop, _base); | |
197 } | |
192 } | 198 } |
193 | 199 |
194 void CMMarkStack::par_push(oop ptr) { | 200 void CMMarkStack::par_push(oop ptr) { |
195 while (true) { | 201 while (true) { |
196 if (isFull()) { | 202 if (isFull()) { |
279 | 285 |
280 CMRegionStack::CMRegionStack() : _base(NULL) {} | 286 CMRegionStack::CMRegionStack() : _base(NULL) {} |
281 | 287 |
282 void CMRegionStack::allocate(size_t size) { | 288 void CMRegionStack::allocate(size_t size) { |
283 _base = NEW_C_HEAP_ARRAY(MemRegion, size); | 289 _base = NEW_C_HEAP_ARRAY(MemRegion, size); |
284 if (_base == NULL) | 290 if (_base == NULL) { |
285 vm_exit_during_initialization("Failed to allocate " | 291 vm_exit_during_initialization("Failed to allocate CM region mark stack"); |
286 "CM region mark stack"); | 292 } |
287 _index = 0; | 293 _index = 0; |
288 // QQQQ cast ... | |
289 _capacity = (jint) size; | 294 _capacity = (jint) size; |
290 } | 295 } |
291 | 296 |
292 CMRegionStack::~CMRegionStack() { | 297 CMRegionStack::~CMRegionStack() { |
293 if (_base != NULL) FREE_C_HEAP_ARRAY(oop, _base); | 298 if (_base != NULL) { |
299 FREE_C_HEAP_ARRAY(oop, _base); | |
300 } | |
294 } | 301 } |
295 | 302 |
296 void CMRegionStack::push_lock_free(MemRegion mr) { | 303 void CMRegionStack::push_lock_free(MemRegion mr) { |
297 assert(mr.word_size() > 0, "Precondition"); | 304 assert(mr.word_size() > 0, "Precondition"); |
298 while (true) { | 305 while (true) { |
420 "only grey objects on this stack"); | 427 "only grey objects on this stack"); |
421 // iterate over the oops in this oop, marking and pushing | 428 // iterate over the oops in this oop, marking and pushing |
422 // the ones in CMS generation. | 429 // the ones in CMS generation. |
423 newOop->oop_iterate(cl); | 430 newOop->oop_iterate(cl); |
424 if (yield_after && _cm->do_yield_check()) { | 431 if (yield_after && _cm->do_yield_check()) { |
425 res = false; break; | 432 res = false; |
433 break; | |
426 } | 434 } |
427 } | 435 } |
428 debug_only(_drain_in_progress = false); | 436 debug_only(_drain_in_progress = false); |
429 return res; | 437 return res; |
430 } | 438 } |
491 _remark_times(), _remark_mark_times(), _remark_weak_ref_times(), | 499 _remark_times(), _remark_mark_times(), _remark_weak_ref_times(), |
492 _cleanup_times(), | 500 _cleanup_times(), |
493 _total_counting_time(0.0), | 501 _total_counting_time(0.0), |
494 _total_rs_scrub_time(0.0), | 502 _total_rs_scrub_time(0.0), |
495 | 503 |
496 _parallel_workers(NULL) | 504 _parallel_workers(NULL) { |
497 { | 505 CMVerboseLevel verbose_level = (CMVerboseLevel) G1MarkingVerboseLevel; |
498 CMVerboseLevel verbose_level = | 506 if (verbose_level < no_verbose) { |
499 (CMVerboseLevel) G1MarkingVerboseLevel; | |
500 if (verbose_level < no_verbose) | |
501 verbose_level = no_verbose; | 507 verbose_level = no_verbose; |
502 if (verbose_level > high_verbose) | 508 } |
509 if (verbose_level > high_verbose) { | |
503 verbose_level = high_verbose; | 510 verbose_level = high_verbose; |
511 } | |
504 _verbose_level = verbose_level; | 512 _verbose_level = verbose_level; |
505 | 513 |
506 if (verbose_low()) | 514 if (verbose_low()) { |
507 gclog_or_tty->print_cr("[global] init, heap start = "PTR_FORMAT", " | 515 gclog_or_tty->print_cr("[global] init, heap start = "PTR_FORMAT", " |
508 "heap end = "PTR_FORMAT, _heap_start, _heap_end); | 516 "heap end = "PTR_FORMAT, _heap_start, _heap_end); |
517 } | |
509 | 518 |
510 _markStack.allocate(MarkStackSize); | 519 _markStack.allocate(MarkStackSize); |
511 _regionStack.allocate(G1MarkRegionStackSize); | 520 _regionStack.allocate(G1MarkRegionStackSize); |
512 | 521 |
513 // Create & start a ConcurrentMark thread. | 522 // Create & start a ConcurrentMark thread. |
579 _parallel_marking_threads = MAX2((ParallelGCThreads + 2) / 4, (size_t)1); | 588 _parallel_marking_threads = MAX2((ParallelGCThreads + 2) / 4, (size_t)1); |
580 _sleep_factor = 0.0; | 589 _sleep_factor = 0.0; |
581 _marking_task_overhead = 1.0; | 590 _marking_task_overhead = 1.0; |
582 } | 591 } |
583 | 592 |
584 if (parallel_marking_threads() > 1) | 593 if (parallel_marking_threads() > 1) { |
585 _cleanup_task_overhead = 1.0; | 594 _cleanup_task_overhead = 1.0; |
586 else | 595 } else { |
587 _cleanup_task_overhead = marking_task_overhead(); | 596 _cleanup_task_overhead = marking_task_overhead(); |
597 } | |
588 _cleanup_sleep_factor = | 598 _cleanup_sleep_factor = |
589 (1.0 - cleanup_task_overhead()) / cleanup_task_overhead(); | 599 (1.0 - cleanup_task_overhead()) / cleanup_task_overhead(); |
590 | 600 |
591 #if 0 | 601 #if 0 |
592 gclog_or_tty->print_cr("Marking Threads %d", parallel_marking_threads()); | 602 gclog_or_tty->print_cr("Marking Threads %d", parallel_marking_threads()); |
620 // second one could unnecessarily push regions on the region | 630 // second one could unnecessarily push regions on the region |
621 // stack. This causes the invariant that the region stack is empty | 631 // stack. This causes the invariant that the region stack is empty |
622 // at the beginning of remark to be false. By ensuring that we do | 632 // at the beginning of remark to be false. By ensuring that we do |
623 // not observe heap expansions after marking is complete, then we do | 633 // not observe heap expansions after marking is complete, then we do |
624 // not have this problem. | 634 // not have this problem. |
625 if (!concurrent_marking_in_progress() && !force) | 635 if (!concurrent_marking_in_progress() && !force) return; |
626 return; | |
627 | 636 |
628 MemRegion committed = _g1h->g1_committed(); | 637 MemRegion committed = _g1h->g1_committed(); |
629 assert(committed.start() == _heap_start, "start shouldn't change"); | 638 assert(committed.start() == _heap_start, "start shouldn't change"); |
630 HeapWord* new_end = committed.end(); | 639 HeapWord* new_end = committed.end(); |
631 if (new_end > _heap_end) { | 640 if (new_end > _heap_end) { |
654 assert(_heap_start < _heap_end, "heap bounds should look ok"); | 663 assert(_heap_start < _heap_end, "heap bounds should look ok"); |
655 | 664 |
656 // reset all the marking data structures and any necessary flags | 665 // reset all the marking data structures and any necessary flags |
657 clear_marking_state(); | 666 clear_marking_state(); |
658 | 667 |
659 if (verbose_low()) | 668 if (verbose_low()) { |
660 gclog_or_tty->print_cr("[global] resetting"); | 669 gclog_or_tty->print_cr("[global] resetting"); |
670 } | |
661 | 671 |
662 // We do reset all of them, since different phases will use | 672 // We do reset all of them, since different phases will use |
663 // different number of active threads. So, it's easiest to have all | 673 // different number of active threads. So, it's easiest to have all |
664 // of them ready. | 674 // of them ready. |
665 for (int i = 0; i < (int) _max_task_num; ++i) { | 675 for (int i = 0; i < (int) _max_task_num; ++i) { |
741 HeapWord* end = _nextMarkBitMap->endWord(); | 751 HeapWord* end = _nextMarkBitMap->endWord(); |
742 HeapWord* cur = start; | 752 HeapWord* cur = start; |
743 size_t chunkSize = M; | 753 size_t chunkSize = M; |
744 while (cur < end) { | 754 while (cur < end) { |
745 HeapWord* next = cur + chunkSize; | 755 HeapWord* next = cur + chunkSize; |
746 if (next > end) | 756 if (next > end) { |
747 next = end; | 757 next = end; |
758 } | |
748 MemRegion mr(cur,next); | 759 MemRegion mr(cur,next); |
749 _nextMarkBitMap->clearRange(mr); | 760 _nextMarkBitMap->clearRange(mr); |
750 cur = next; | 761 cur = next; |
751 do_yield_check(); | 762 do_yield_check(); |
752 | 763 |
921 * barrier is one of the last things do_marking_step() does, and it | 932 * barrier is one of the last things do_marking_step() does, and it |
922 * doesn't manipulate any data structures afterwards. | 933 * doesn't manipulate any data structures afterwards. |
923 */ | 934 */ |
924 | 935 |
925 void ConcurrentMark::enter_first_sync_barrier(int task_num) { | 936 void ConcurrentMark::enter_first_sync_barrier(int task_num) { |
926 if (verbose_low()) | 937 if (verbose_low()) { |
927 gclog_or_tty->print_cr("[%d] entering first barrier", task_num); | 938 gclog_or_tty->print_cr("[%d] entering first barrier", task_num); |
939 } | |
928 | 940 |
929 if (concurrent()) { | 941 if (concurrent()) { |
930 ConcurrentGCThread::stsLeave(); | 942 ConcurrentGCThread::stsLeave(); |
931 } | 943 } |
932 _first_overflow_barrier_sync.enter(); | 944 _first_overflow_barrier_sync.enter(); |
934 ConcurrentGCThread::stsJoin(); | 946 ConcurrentGCThread::stsJoin(); |
935 } | 947 } |
936 // at this point everyone should have synced up and not be doing any | 948 // at this point everyone should have synced up and not be doing any |
937 // more work | 949 // more work |
938 | 950 |
939 if (verbose_low()) | 951 if (verbose_low()) { |
940 gclog_or_tty->print_cr("[%d] leaving first barrier", task_num); | 952 gclog_or_tty->print_cr("[%d] leaving first barrier", task_num); |
953 } | |
941 | 954 |
942 // let task 0 do this | 955 // let task 0 do this |
943 if (task_num == 0) { | 956 if (task_num == 0) { |
944 // task 0 is responsible for clearing the global data structures | 957 // task 0 is responsible for clearing the global data structures |
945 // We should be here because of an overflow. During STW we should | 958 // We should be here because of an overflow. During STW we should |
959 // after this, each task should reset its own data structures then | 972 // after this, each task should reset its own data structures then |
960 // then go into the second barrier | 973 // then go into the second barrier |
961 } | 974 } |
962 | 975 |
963 void ConcurrentMark::enter_second_sync_barrier(int task_num) { | 976 void ConcurrentMark::enter_second_sync_barrier(int task_num) { |
964 if (verbose_low()) | 977 if (verbose_low()) { |
965 gclog_or_tty->print_cr("[%d] entering second barrier", task_num); | 978 gclog_or_tty->print_cr("[%d] entering second barrier", task_num); |
979 } | |
966 | 980 |
967 if (concurrent()) { | 981 if (concurrent()) { |
968 ConcurrentGCThread::stsLeave(); | 982 ConcurrentGCThread::stsLeave(); |
969 } | 983 } |
970 _second_overflow_barrier_sync.enter(); | 984 _second_overflow_barrier_sync.enter(); |
971 if (concurrent()) { | 985 if (concurrent()) { |
972 ConcurrentGCThread::stsJoin(); | 986 ConcurrentGCThread::stsJoin(); |
973 } | 987 } |
974 // at this point everything should be re-initialised and ready to go | 988 // at this point everything should be re-initialised and ready to go |
975 | 989 |
976 if (verbose_low()) | 990 if (verbose_low()) { |
977 gclog_or_tty->print_cr("[%d] leaving second barrier", task_num); | 991 gclog_or_tty->print_cr("[%d] leaving second barrier", task_num); |
992 } | |
978 } | 993 } |
979 | 994 |
980 #ifndef PRODUCT | 995 #ifndef PRODUCT |
981 void ForceOverflowSettings::init() { | 996 void ForceOverflowSettings::init() { |
982 _num_remaining = G1ConcMarkForceOverflow; | 997 _num_remaining = G1ConcMarkForceOverflow; |
1011 // pause without CM observing this change. So the assertions below | 1026 // pause without CM observing this change. So the assertions below |
1012 // is a bit conservative; but better than nothing. | 1027 // is a bit conservative; but better than nothing. |
1013 assert(_g1h->g1_committed().contains(addr), | 1028 assert(_g1h->g1_committed().contains(addr), |
1014 "address should be within the heap bounds"); | 1029 "address should be within the heap bounds"); |
1015 | 1030 |
1016 if (!_nextMarkBitMap->isMarked(addr)) | 1031 if (!_nextMarkBitMap->isMarked(addr)) { |
1017 _nextMarkBitMap->parMark(addr); | 1032 _nextMarkBitMap->parMark(addr); |
1033 } | |
1018 } | 1034 } |
1019 | 1035 |
1020 void ConcurrentMark::grayRegionIfNecessary(MemRegion mr) { | 1036 void ConcurrentMark::grayRegionIfNecessary(MemRegion mr) { |
1021 // The objects on the region have already been marked "in bulk" by | 1037 // The objects on the region have already been marked "in bulk" by |
1022 // the caller. We only need to decide whether to push the region on | 1038 // the caller. We only need to decide whether to push the region on |
1023 // the region stack or not. | 1039 // the region stack or not. |
1024 | 1040 |
1025 if (!concurrent_marking_in_progress() || !_should_gray_objects) | 1041 if (!concurrent_marking_in_progress() || !_should_gray_objects) { |
1026 // We're done with marking and waiting for remark. We do not need to | 1042 // We're done with marking and waiting for remark. We do not need to |
1027 // push anything else on the region stack. | 1043 // push anything else on the region stack. |
1028 return; | 1044 return; |
1045 } | |
1029 | 1046 |
1030 HeapWord* finger = _finger; | 1047 HeapWord* finger = _finger; |
1031 | 1048 |
1032 if (verbose_low()) | 1049 if (verbose_low()) { |
1033 gclog_or_tty->print_cr("[global] attempting to push " | 1050 gclog_or_tty->print_cr("[global] attempting to push " |
1034 "region ["PTR_FORMAT", "PTR_FORMAT"), finger is at " | 1051 "region ["PTR_FORMAT", "PTR_FORMAT"), finger is at " |
1035 PTR_FORMAT, mr.start(), mr.end(), finger); | 1052 PTR_FORMAT, mr.start(), mr.end(), finger); |
1053 } | |
1036 | 1054 |
1037 if (mr.start() < finger) { | 1055 if (mr.start() < finger) { |
1038 // The finger is always heap region aligned and it is not possible | 1056 // The finger is always heap region aligned and it is not possible |
1039 // for mr to span heap regions. | 1057 // for mr to span heap regions. |
1040 assert(mr.end() <= finger, "invariant"); | 1058 assert(mr.end() <= finger, "invariant"); |
1044 "region boundaries should fall within the committed space"); | 1062 "region boundaries should fall within the committed space"); |
1045 assert(_heap_start <= mr.start(), | 1063 assert(_heap_start <= mr.start(), |
1046 "region boundaries should fall within the committed space"); | 1064 "region boundaries should fall within the committed space"); |
1047 assert(mr.end() <= _heap_end, | 1065 assert(mr.end() <= _heap_end, |
1048 "region boundaries should fall within the committed space"); | 1066 "region boundaries should fall within the committed space"); |
1049 if (verbose_low()) | 1067 if (verbose_low()) { |
1050 gclog_or_tty->print_cr("[global] region ["PTR_FORMAT", "PTR_FORMAT") " | 1068 gclog_or_tty->print_cr("[global] region ["PTR_FORMAT", "PTR_FORMAT") " |
1051 "below the finger, pushing it", | 1069 "below the finger, pushing it", |
1052 mr.start(), mr.end()); | 1070 mr.start(), mr.end()); |
1071 } | |
1053 | 1072 |
1054 if (!region_stack_push_lock_free(mr)) { | 1073 if (!region_stack_push_lock_free(mr)) { |
1055 if (verbose_low()) | 1074 if (verbose_low()) { |
1056 gclog_or_tty->print_cr("[global] region stack has overflown."); | 1075 gclog_or_tty->print_cr("[global] region stack has overflown."); |
1076 } | |
1057 } | 1077 } |
1058 } | 1078 } |
1059 } | 1079 } |
1060 | 1080 |
1061 void ConcurrentMark::markAndGrayObjectIfNecessary(oop p) { | 1081 void ConcurrentMark::markAndGrayObjectIfNecessary(oop p) { |
1065 HeapWord* addr = (HeapWord*)p; | 1085 HeapWord* addr = (HeapWord*)p; |
1066 if (!_nextMarkBitMap->isMarked(addr)) { | 1086 if (!_nextMarkBitMap->isMarked(addr)) { |
1067 // We definitely need to mark it, irrespective whether we bail out | 1087 // We definitely need to mark it, irrespective whether we bail out |
1068 // because we're done with marking. | 1088 // because we're done with marking. |
1069 if (_nextMarkBitMap->parMark(addr)) { | 1089 if (_nextMarkBitMap->parMark(addr)) { |
1070 if (!concurrent_marking_in_progress() || !_should_gray_objects) | 1090 if (!concurrent_marking_in_progress() || !_should_gray_objects) { |
1071 // If we're done with concurrent marking and we're waiting for | 1091 // If we're done with concurrent marking and we're waiting for |
1072 // remark, then we're not pushing anything on the stack. | 1092 // remark, then we're not pushing anything on the stack. |
1073 return; | 1093 return; |
1094 } | |
1074 | 1095 |
1075 // No OrderAccess:store_load() is needed. It is implicit in the | 1096 // No OrderAccess:store_load() is needed. It is implicit in the |
1076 // CAS done in parMark(addr) above | 1097 // CAS done in parMark(addr) above |
1077 HeapWord* finger = _finger; | 1098 HeapWord* finger = _finger; |
1078 | 1099 |
1079 if (addr < finger) { | 1100 if (addr < finger) { |
1080 if (!mark_stack_push(oop(addr))) { | 1101 if (!mark_stack_push(oop(addr))) { |
1081 if (verbose_low()) | 1102 if (verbose_low()) { |
1082 gclog_or_tty->print_cr("[global] global stack overflow " | 1103 gclog_or_tty->print_cr("[global] global stack overflow " |
1083 "during parMark"); | 1104 "during parMark"); |
1105 } | |
1084 } | 1106 } |
1085 } | 1107 } |
1086 } | 1108 } |
1087 } | 1109 } |
1088 } | 1110 } |
1173 size_t active_workers = MAX2((size_t) 1, parallel_marking_threads()); | 1195 size_t active_workers = MAX2((size_t) 1, parallel_marking_threads()); |
1174 force_overflow_conc()->init(); | 1196 force_overflow_conc()->init(); |
1175 set_phase(active_workers, true /* concurrent */); | 1197 set_phase(active_workers, true /* concurrent */); |
1176 | 1198 |
1177 CMConcurrentMarkingTask markingTask(this, cmThread()); | 1199 CMConcurrentMarkingTask markingTask(this, cmThread()); |
1178 if (parallel_marking_threads() > 0) | 1200 if (parallel_marking_threads() > 0) { |
1179 _parallel_workers->run_task(&markingTask); | 1201 _parallel_workers->run_task(&markingTask); |
1180 else | 1202 } else { |
1181 markingTask.work(0); | 1203 markingTask.work(0); |
1204 } | |
1182 print_stats(); | 1205 print_stats(); |
1183 } | 1206 } |
1184 | 1207 |
1185 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) { | 1208 void ConcurrentMark::checkpointRootsFinal(bool clear_all_soft_refs) { |
1186 // world is stopped at this checkpoint | 1209 // world is stopped at this checkpoint |
1219 if (has_overflown()) { | 1242 if (has_overflown()) { |
1220 // Oops. We overflowed. Restart concurrent marking. | 1243 // Oops. We overflowed. Restart concurrent marking. |
1221 _restart_for_overflow = true; | 1244 _restart_for_overflow = true; |
1222 // Clear the flag. We do not need it any more. | 1245 // Clear the flag. We do not need it any more. |
1223 clear_has_overflown(); | 1246 clear_has_overflown(); |
1224 if (G1TraceMarkStackOverflow) | 1247 if (G1TraceMarkStackOverflow) { |
1225 gclog_or_tty->print_cr("\nRemark led to restart for overflow."); | 1248 gclog_or_tty->print_cr("\nRemark led to restart for overflow."); |
1249 } | |
1226 } else { | 1250 } else { |
1227 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | 1251 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); |
1228 // We're done with marking. | 1252 // We're done with marking. |
1229 // This is the end of the marking cycle, we're expected all | 1253 // This is the end of the marking cycle, we're expected all |
1230 // threads to have SATB queues with active set to true. | 1254 // threads to have SATB queues with active set to true. |
1327 // the humongous regions (in case this changes in the future). | 1351 // the humongous regions (in case this changes in the future). |
1328 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | 1352 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
1329 size_t end_index = index + 1; | 1353 size_t end_index = index + 1; |
1330 while (end_index < g1h->n_regions()) { | 1354 while (end_index < g1h->n_regions()) { |
1331 HeapRegion* chr = g1h->region_at(end_index); | 1355 HeapRegion* chr = g1h->region_at(end_index); |
1332 if (!chr->continuesHumongous()) { | 1356 if (!chr->continuesHumongous()) break; |
1333 break; | |
1334 } | |
1335 end_index += 1; | 1357 end_index += 1; |
1336 } | 1358 } |
1337 _region_bm->par_at_put_range((BitMap::idx_t) index, | 1359 _region_bm->par_at_put_range((BitMap::idx_t) index, |
1338 (BitMap::idx_t) end_index, true); | 1360 (BitMap::idx_t) end_index, true); |
1339 } | 1361 } |
1340 } | 1362 } |
1341 | 1363 |
1342 bool doHeapRegion(HeapRegion* hr) { | 1364 bool doHeapRegion(HeapRegion* hr) { |
1343 if (!_final && _regions_done == 0) | 1365 if (!_final && _regions_done == 0) { |
1344 _start_vtime_sec = os::elapsedVTime(); | 1366 _start_vtime_sec = os::elapsedVTime(); |
1367 } | |
1345 | 1368 |
1346 if (hr->continuesHumongous()) { | 1369 if (hr->continuesHumongous()) { |
1347 // We will ignore these here and process them when their | 1370 // We will ignore these here and process them when their |
1348 // associated "starts humongous" region is processed (see | 1371 // associated "starts humongous" region is processed (see |
1349 // set_bit_for_heap_region()). Note that we cannot rely on their | 1372 // set_bit_for_heap_region()). Note that we cannot rely on their |
1432 // Find the next marked object after this one. | 1455 // Find the next marked object after this one. |
1433 start = _bm->getNextMarkedWordAddress(start + 1, nextTop); | 1456 start = _bm->getNextMarkedWordAddress(start + 1, nextTop); |
1434 _changed = true; | 1457 _changed = true; |
1435 } | 1458 } |
1436 // Handle the last range, if any. | 1459 // Handle the last range, if any. |
1437 if (start_card_num != -1) | 1460 if (start_card_num != -1) { |
1438 mark_card_num_range(start_card_num, last_card_num); | 1461 mark_card_num_range(start_card_num, last_card_num); |
1462 } | |
1439 if (_final) { | 1463 if (_final) { |
1440 // Mark the allocated-since-marking portion... | 1464 // Mark the allocated-since-marking portion... |
1441 HeapWord* tp = hr->top(); | 1465 HeapWord* tp = hr->top(); |
1442 if (nextTop < tp) { | 1466 if (nextTop < tp) { |
1443 start_card_num = | 1467 start_card_num = |
1510 size_t *_used_bytes; | 1534 size_t *_used_bytes; |
1511 BitMap* _region_bm; | 1535 BitMap* _region_bm; |
1512 BitMap* _card_bm; | 1536 BitMap* _card_bm; |
1513 public: | 1537 public: |
1514 G1ParFinalCountTask(G1CollectedHeap* g1h, CMBitMap* bm, | 1538 G1ParFinalCountTask(G1CollectedHeap* g1h, CMBitMap* bm, |
1515 BitMap* region_bm, BitMap* card_bm) : | 1539 BitMap* region_bm, BitMap* card_bm) |
1516 AbstractGangTask("G1 final counting"), _g1h(g1h), | 1540 : AbstractGangTask("G1 final counting"), _g1h(g1h), |
1517 _bm(bm), _region_bm(region_bm), _card_bm(card_bm) | 1541 _bm(bm), _region_bm(region_bm), _card_bm(card_bm) { |
1518 { | 1542 if (ParallelGCThreads > 0) { |
1519 if (ParallelGCThreads > 0) | |
1520 _n_workers = _g1h->workers()->total_workers(); | 1543 _n_workers = _g1h->workers()->total_workers(); |
1521 else | 1544 } else { |
1522 _n_workers = 1; | 1545 _n_workers = 1; |
1546 } | |
1523 _live_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); | 1547 _live_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); |
1524 _used_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); | 1548 _used_bytes = NEW_C_HEAP_ARRAY(size_t, _n_workers); |
1525 } | 1549 } |
1526 | 1550 |
1527 ~G1ParFinalCountTask() { | 1551 ~G1ParFinalCountTask() { |
1702 _humongous_proxy_set, | 1726 _humongous_proxy_set, |
1703 _hrrs_cleanup_task, | 1727 _hrrs_cleanup_task, |
1704 true /* par */); | 1728 true /* par */); |
1705 double region_time = (os::elapsedTime() - start); | 1729 double region_time = (os::elapsedTime() - start); |
1706 _claimed_region_time += region_time; | 1730 _claimed_region_time += region_time; |
1707 if (region_time > _max_region_time) _max_region_time = region_time; | 1731 if (region_time > _max_region_time) { |
1732 _max_region_time = region_time; | |
1733 } | |
1708 } | 1734 } |
1709 return false; | 1735 return false; |
1710 } | 1736 } |
1711 | 1737 |
1712 void ConcurrentMark::cleanup() { | 1738 void ConcurrentMark::cleanup() { |
1961 | 1987 |
1962 template <class T> void do_oop_work(T* p) { | 1988 template <class T> void do_oop_work(T* p) { |
1963 oop obj = oopDesc::load_decode_heap_oop(p); | 1989 oop obj = oopDesc::load_decode_heap_oop(p); |
1964 HeapWord* addr = (HeapWord*)obj; | 1990 HeapWord* addr = (HeapWord*)obj; |
1965 | 1991 |
1966 if (_cm->verbose_high()) | 1992 if (_cm->verbose_high()) { |
1967 gclog_or_tty->print_cr("\t[0] we're looking at location " | 1993 gclog_or_tty->print_cr("\t[0] we're looking at location " |
1968 "*"PTR_FORMAT" = "PTR_FORMAT, | 1994 "*"PTR_FORMAT" = "PTR_FORMAT, |
1969 p, (void*) obj); | 1995 p, (void*) obj); |
1996 } | |
1970 | 1997 |
1971 if (_g1->is_in_g1_reserved(addr) && _g1->is_obj_ill(obj)) { | 1998 if (_g1->is_in_g1_reserved(addr) && _g1->is_obj_ill(obj)) { |
1972 _bitMap->mark(addr); | 1999 _bitMap->mark(addr); |
1973 _cm->mark_stack_push(obj); | 2000 _cm->mark_stack_push(obj); |
1974 } | 2001 } |
2026 virtual void do_oop( oop* p) { do_oop_work(p); } | 2053 virtual void do_oop( oop* p) { do_oop_work(p); } |
2027 | 2054 |
2028 template <class T> void do_oop_work(T* p) { | 2055 template <class T> void do_oop_work(T* p) { |
2029 if (!_cm->has_overflown()) { | 2056 if (!_cm->has_overflown()) { |
2030 oop obj = oopDesc::load_decode_heap_oop(p); | 2057 oop obj = oopDesc::load_decode_heap_oop(p); |
2031 if (_cm->verbose_high()) | 2058 if (_cm->verbose_high()) { |
2032 gclog_or_tty->print_cr("\t[%d] we're looking at location " | 2059 gclog_or_tty->print_cr("\t[%d] we're looking at location " |
2033 "*"PTR_FORMAT" = "PTR_FORMAT, | 2060 "*"PTR_FORMAT" = "PTR_FORMAT, |
2034 _task->task_id(), p, (void*) obj); | 2061 _task->task_id(), p, (void*) obj); |
2062 } | |
2035 | 2063 |
2036 _task->deal_with_reference(obj); | 2064 _task->deal_with_reference(obj); |
2037 _ref_counter--; | 2065 _ref_counter--; |
2038 | 2066 |
2039 if (_ref_counter == 0) { | 2067 if (_ref_counter == 0) { |
2056 false /* do_termination */); | 2084 false /* do_termination */); |
2057 } while (_task->has_aborted() && !_cm->has_overflown()); | 2085 } while (_task->has_aborted() && !_cm->has_overflown()); |
2058 _ref_counter = _ref_counter_limit; | 2086 _ref_counter = _ref_counter_limit; |
2059 } | 2087 } |
2060 } else { | 2088 } else { |
2061 if (_cm->verbose_high()) | 2089 if (_cm->verbose_high()) { |
2062 gclog_or_tty->print_cr("\t[%d] CM Overflow", _task->task_id()); | 2090 gclog_or_tty->print_cr("\t[%d] CM Overflow", _task->task_id()); |
2091 } | |
2063 } | 2092 } |
2064 } | 2093 } |
2065 }; | 2094 }; |
2066 | 2095 |
2067 class G1CMParDrainMarkingStackClosure: public VoidClosure { | 2096 class G1CMParDrainMarkingStackClosure: public VoidClosure { |
2072 _cm(cm), _task(task) | 2101 _cm(cm), _task(task) |
2073 {} | 2102 {} |
2074 | 2103 |
2075 void do_void() { | 2104 void do_void() { |
2076 do { | 2105 do { |
2077 if (_cm->verbose_high()) | 2106 if (_cm->verbose_high()) { |
2078 gclog_or_tty->print_cr("\t[%d] Drain: Calling do marking_step", _task->task_id()); | 2107 gclog_or_tty->print_cr("\t[%d] Drain: Calling do marking_step", |
2108 _task->task_id()); | |
2109 } | |
2079 | 2110 |
2080 // We call CMTask::do_marking_step() to completely drain the local and | 2111 // We call CMTask::do_marking_step() to completely drain the local and |
2081 // global marking stacks. The routine is called in a loop, which we'll | 2112 // global marking stacks. The routine is called in a loop, which we'll |
2082 // exit if there's nothing more to do (i.e. we'completely drained the | 2113 // exit if there's nothing more to do (i.e. we'completely drained the |
2083 // entries that were pushed as a result of applying the | 2114 // entries that were pushed as a result of applying the |
2626 CMGlobalObjectClosure oc(this); | 2657 CMGlobalObjectClosure oc(this); |
2627 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | 2658 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); |
2628 satb_mq_set.set_closure(&oc); | 2659 satb_mq_set.set_closure(&oc); |
2629 | 2660 |
2630 while (satb_mq_set.apply_closure_to_completed_buffer()) { | 2661 while (satb_mq_set.apply_closure_to_completed_buffer()) { |
2631 if (verbose_medium()) | 2662 if (verbose_medium()) { |
2632 gclog_or_tty->print_cr("[global] processed an SATB buffer"); | 2663 gclog_or_tty->print_cr("[global] processed an SATB buffer"); |
2664 } | |
2633 } | 2665 } |
2634 | 2666 |
2635 // no need to check whether we should do this, as this is only | 2667 // no need to check whether we should do this, as this is only |
2636 // called during an evacuation pause | 2668 // called during an evacuation pause |
2637 satb_mq_set.iterate_closure_all_threads(); | 2669 satb_mq_set.iterate_closure_all_threads(); |
2714 | 2746 |
2715 // notice that _finger == end cannot be guaranteed here since, | 2747 // notice that _finger == end cannot be guaranteed here since, |
2716 // someone else might have moved the finger even further | 2748 // someone else might have moved the finger even further |
2717 assert(_finger >= end, "the finger should have moved forward"); | 2749 assert(_finger >= end, "the finger should have moved forward"); |
2718 | 2750 |
2719 if (verbose_low()) | 2751 if (verbose_low()) { |
2720 gclog_or_tty->print_cr("[%d] we were successful with region = " | 2752 gclog_or_tty->print_cr("[%d] we were successful with region = " |
2721 PTR_FORMAT, task_num, curr_region); | 2753 PTR_FORMAT, task_num, curr_region); |
2754 } | |
2722 | 2755 |
2723 if (limit > bottom) { | 2756 if (limit > bottom) { |
2724 if (verbose_low()) | 2757 if (verbose_low()) { |
2725 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is not empty, " | 2758 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is not empty, " |
2726 "returning it ", task_num, curr_region); | 2759 "returning it ", task_num, curr_region); |
2760 } | |
2727 return curr_region; | 2761 return curr_region; |
2728 } else { | 2762 } else { |
2729 assert(limit == bottom, | 2763 assert(limit == bottom, |
2730 "the region limit should be at bottom"); | 2764 "the region limit should be at bottom"); |
2731 if (verbose_low()) | 2765 if (verbose_low()) { |
2732 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is empty, " | 2766 gclog_or_tty->print_cr("[%d] region "PTR_FORMAT" is empty, " |
2733 "returning NULL", task_num, curr_region); | 2767 "returning NULL", task_num, curr_region); |
2768 } | |
2734 // we return NULL and the caller should try calling | 2769 // we return NULL and the caller should try calling |
2735 // claim_region() again. | 2770 // claim_region() again. |
2736 return NULL; | 2771 return NULL; |
2737 } | 2772 } |
2738 } else { | 2773 } else { |
2739 assert(_finger > finger, "the finger should have moved forward"); | 2774 assert(_finger > finger, "the finger should have moved forward"); |
2740 if (verbose_low()) | 2775 if (verbose_low()) { |
2741 gclog_or_tty->print_cr("[%d] somebody else moved the finger, " | 2776 gclog_or_tty->print_cr("[%d] somebody else moved the finger, " |
2742 "global finger = "PTR_FORMAT", " | 2777 "global finger = "PTR_FORMAT", " |
2743 "our finger = "PTR_FORMAT, | 2778 "our finger = "PTR_FORMAT, |
2744 task_num, _finger, finger); | 2779 task_num, _finger, finger); |
2780 } | |
2745 | 2781 |
2746 // read it again | 2782 // read it again |
2747 finger = _finger; | 2783 finger = _finger; |
2748 } | 2784 } |
2749 } | 2785 } |
2783 } | 2819 } |
2784 return false; | 2820 return false; |
2785 } | 2821 } |
2786 | 2822 |
2787 void ConcurrentMark::oops_do(OopClosure* cl) { | 2823 void ConcurrentMark::oops_do(OopClosure* cl) { |
2788 if (_markStack.size() > 0 && verbose_low()) | 2824 if (_markStack.size() > 0 && verbose_low()) { |
2789 gclog_or_tty->print_cr("[global] scanning the global marking stack, " | 2825 gclog_or_tty->print_cr("[global] scanning the global marking stack, " |
2790 "size = %d", _markStack.size()); | 2826 "size = %d", _markStack.size()); |
2827 } | |
2791 // we first iterate over the contents of the mark stack... | 2828 // we first iterate over the contents of the mark stack... |
2792 _markStack.oops_do(cl); | 2829 _markStack.oops_do(cl); |
2793 | 2830 |
2794 for (int i = 0; i < (int)_max_task_num; ++i) { | 2831 for (int i = 0; i < (int)_max_task_num; ++i) { |
2795 OopTaskQueue* queue = _task_queues->queue((int)i); | 2832 OopTaskQueue* queue = _task_queues->queue((int)i); |
2796 | 2833 |
2797 if (queue->size() > 0 && verbose_low()) | 2834 if (queue->size() > 0 && verbose_low()) { |
2798 gclog_or_tty->print_cr("[global] scanning task queue of task %d, " | 2835 gclog_or_tty->print_cr("[global] scanning task queue of task %d, " |
2799 "size = %d", i, queue->size()); | 2836 "size = %d", i, queue->size()); |
2837 } | |
2800 | 2838 |
2801 // ...then over the contents of the all the task queues. | 2839 // ...then over the contents of the all the task queues. |
2802 queue->oops_do(cl); | 2840 queue->oops_do(cl); |
2803 } | 2841 } |
2804 | 2842 |
2866 if (_ms_ind == _ms_size) { | 2904 if (_ms_ind == _ms_size) { |
2867 gclog_or_tty->print_cr("Mark stack is full."); | 2905 gclog_or_tty->print_cr("Mark stack is full."); |
2868 return false; | 2906 return false; |
2869 } | 2907 } |
2870 _ms[_ms_ind] = obj; | 2908 _ms[_ms_ind] = obj; |
2871 if (obj->is_objArray()) _array_ind_stack[_ms_ind] = arr_ind; | 2909 if (obj->is_objArray()) { |
2910 _array_ind_stack[_ms_ind] = arr_ind; | |
2911 } | |
2872 _ms_ind++; | 2912 _ms_ind++; |
2873 return true; | 2913 return true; |
2874 } | 2914 } |
2875 | 2915 |
2876 oop pop() { | 2916 oop pop() { |
2877 if (_ms_ind == 0) return NULL; | 2917 if (_ms_ind == 0) { |
2878 else { | 2918 return NULL; |
2919 } else { | |
2879 _ms_ind--; | 2920 _ms_ind--; |
2880 return _ms[_ms_ind]; | 2921 return _ms[_ms_ind]; |
2881 } | 2922 } |
2882 } | 2923 } |
2883 | 2924 |
3072 // location. There is a tricky situation with the gray objects in | 3113 // location. There is a tricky situation with the gray objects in |
3073 // region stack that are being coped, however. See the comment in | 3114 // region stack that are being coped, however. See the comment in |
3074 // newCSet(). | 3115 // newCSet(). |
3075 | 3116 |
3076 void ConcurrentMark::newCSet() { | 3117 void ConcurrentMark::newCSet() { |
3077 if (!concurrent_marking_in_progress()) | 3118 if (!concurrent_marking_in_progress()) { |
3078 // nothing to do if marking is not in progress | 3119 // nothing to do if marking is not in progress |
3079 return; | 3120 return; |
3121 } | |
3080 | 3122 |
3081 // find what the lowest finger is among the global and local fingers | 3123 // find what the lowest finger is among the global and local fingers |
3082 _min_finger = _finger; | 3124 _min_finger = _finger; |
3083 for (int i = 0; i < (int)_max_task_num; ++i) { | 3125 for (int i = 0; i < (int)_max_task_num; ++i) { |
3084 CMTask* task = _tasks[i]; | 3126 CMTask* task = _tasks[i]; |
3085 HeapWord* task_finger = task->finger(); | 3127 HeapWord* task_finger = task->finger(); |
3086 if (task_finger != NULL && task_finger < _min_finger) | 3128 if (task_finger != NULL && task_finger < _min_finger) { |
3087 _min_finger = task_finger; | 3129 _min_finger = task_finger; |
3130 } | |
3088 } | 3131 } |
3089 | 3132 |
3090 _should_gray_objects = false; | 3133 _should_gray_objects = false; |
3091 | 3134 |
3092 // This fixes a very subtle and fustrating bug. It might be the case | 3135 // This fixes a very subtle and fustrating bug. It might be the case |
3102 // empty during an evacuation pause. So, we make the fix a bit less | 3145 // empty during an evacuation pause. So, we make the fix a bit less |
3103 // conservative and ensure that regions are pushed on the stack, | 3146 // conservative and ensure that regions are pushed on the stack, |
3104 // irrespective whether all collection set regions are below the | 3147 // irrespective whether all collection set regions are below the |
3105 // finger, if the region stack is not empty. This is expected to be | 3148 // finger, if the region stack is not empty. This is expected to be |
3106 // a rare case, so I don't think it's necessary to be smarted about it. | 3149 // a rare case, so I don't think it's necessary to be smarted about it. |
3107 if (!region_stack_empty() || has_aborted_regions()) | 3150 if (!region_stack_empty() || has_aborted_regions()) { |
3108 _should_gray_objects = true; | 3151 _should_gray_objects = true; |
3152 } | |
3109 } | 3153 } |
3110 | 3154 |
3111 void ConcurrentMark::registerCSetRegion(HeapRegion* hr) { | 3155 void ConcurrentMark::registerCSetRegion(HeapRegion* hr) { |
3112 if (!concurrent_marking_in_progress()) | 3156 if (!concurrent_marking_in_progress()) return; |
3113 return; | |
3114 | 3157 |
3115 HeapWord* region_end = hr->end(); | 3158 HeapWord* region_end = hr->end(); |
3116 if (region_end > _min_finger) | 3159 if (region_end > _min_finger) { |
3117 _should_gray_objects = true; | 3160 _should_gray_objects = true; |
3161 } | |
3118 } | 3162 } |
3119 | 3163 |
3120 // Resets the region fields of active CMTasks whose values point | 3164 // Resets the region fields of active CMTasks whose values point |
3121 // into the collection set. | 3165 // into the collection set. |
3122 void ConcurrentMark::reset_active_task_region_fields_in_cset() { | 3166 void ConcurrentMark::reset_active_task_region_fields_in_cset() { |
3213 // the CMS bit map. Called at the first checkpoint. | 3257 // the CMS bit map. Called at the first checkpoint. |
3214 | 3258 |
3215 // We take a break if someone is trying to stop the world. | 3259 // We take a break if someone is trying to stop the world. |
3216 bool ConcurrentMark::do_yield_check(int worker_i) { | 3260 bool ConcurrentMark::do_yield_check(int worker_i) { |
3217 if (should_yield()) { | 3261 if (should_yield()) { |
3218 if (worker_i == 0) | 3262 if (worker_i == 0) { |
3219 _g1h->g1_policy()->record_concurrent_pause(); | 3263 _g1h->g1_policy()->record_concurrent_pause(); |
3264 } | |
3220 cmThread()->yield(); | 3265 cmThread()->yield(); |
3221 if (worker_i == 0) | 3266 if (worker_i == 0) { |
3222 _g1h->g1_policy()->record_concurrent_pause_end(); | 3267 _g1h->g1_policy()->record_concurrent_pause_end(); |
3268 } | |
3223 return true; | 3269 return true; |
3224 } else { | 3270 } else { |
3225 return false; | 3271 return false; |
3226 } | 3272 } |
3227 } | 3273 } |
3235 return _card_bm.at(offset >> CardTableModRefBS::card_shift); | 3281 return _card_bm.at(offset >> CardTableModRefBS::card_shift); |
3236 } | 3282 } |
3237 | 3283 |
3238 bool ConcurrentMark::containing_cards_are_marked(void* start, | 3284 bool ConcurrentMark::containing_cards_are_marked(void* start, |
3239 void* last) { | 3285 void* last) { |
3240 return | 3286 return containing_card_is_marked(start) && |
3241 containing_card_is_marked(start) && | 3287 containing_card_is_marked(last); |
3242 containing_card_is_marked(last); | |
3243 } | 3288 } |
3244 | 3289 |
3245 #ifndef PRODUCT | 3290 #ifndef PRODUCT |
3246 // for debugging purposes | 3291 // for debugging purposes |
3247 void ConcurrentMark::print_finger() { | 3292 void ConcurrentMark::print_finger() { |
3350 assert(hr != NULL, | 3395 assert(hr != NULL, |
3351 "claim_region() should have filtered out continues humongous regions"); | 3396 "claim_region() should have filtered out continues humongous regions"); |
3352 assert(!hr->continuesHumongous(), | 3397 assert(!hr->continuesHumongous(), |
3353 "claim_region() should have filtered out continues humongous regions"); | 3398 "claim_region() should have filtered out continues humongous regions"); |
3354 | 3399 |
3355 if (_cm->verbose_low()) | 3400 if (_cm->verbose_low()) { |
3356 gclog_or_tty->print_cr("[%d] setting up for region "PTR_FORMAT, | 3401 gclog_or_tty->print_cr("[%d] setting up for region "PTR_FORMAT, |
3357 _task_id, hr); | 3402 _task_id, hr); |
3403 } | |
3358 | 3404 |
3359 _curr_region = hr; | 3405 _curr_region = hr; |
3360 _finger = hr->bottom(); | 3406 _finger = hr->bottom(); |
3361 update_region_limit(); | 3407 update_region_limit(); |
3362 } | 3408 } |
3365 HeapRegion* hr = _curr_region; | 3411 HeapRegion* hr = _curr_region; |
3366 HeapWord* bottom = hr->bottom(); | 3412 HeapWord* bottom = hr->bottom(); |
3367 HeapWord* limit = hr->next_top_at_mark_start(); | 3413 HeapWord* limit = hr->next_top_at_mark_start(); |
3368 | 3414 |
3369 if (limit == bottom) { | 3415 if (limit == bottom) { |
3370 if (_cm->verbose_low()) | 3416 if (_cm->verbose_low()) { |
3371 gclog_or_tty->print_cr("[%d] found an empty region " | 3417 gclog_or_tty->print_cr("[%d] found an empty region " |
3372 "["PTR_FORMAT", "PTR_FORMAT")", | 3418 "["PTR_FORMAT", "PTR_FORMAT")", |
3373 _task_id, bottom, limit); | 3419 _task_id, bottom, limit); |
3420 } | |
3374 // The region was collected underneath our feet. | 3421 // The region was collected underneath our feet. |
3375 // We set the finger to bottom to ensure that the bitmap | 3422 // We set the finger to bottom to ensure that the bitmap |
3376 // iteration that will follow this will not do anything. | 3423 // iteration that will follow this will not do anything. |
3377 // (this is not a condition that holds when we set the region up, | 3424 // (this is not a condition that holds when we set the region up, |
3378 // as the region is not supposed to be empty in the first place) | 3425 // as the region is not supposed to be empty in the first place) |
3397 _region_limit = limit; | 3444 _region_limit = limit; |
3398 } | 3445 } |
3399 | 3446 |
3400 void CMTask::giveup_current_region() { | 3447 void CMTask::giveup_current_region() { |
3401 assert(_curr_region != NULL, "invariant"); | 3448 assert(_curr_region != NULL, "invariant"); |
3402 if (_cm->verbose_low()) | 3449 if (_cm->verbose_low()) { |
3403 gclog_or_tty->print_cr("[%d] giving up region "PTR_FORMAT, | 3450 gclog_or_tty->print_cr("[%d] giving up region "PTR_FORMAT, |
3404 _task_id, _curr_region); | 3451 _task_id, _curr_region); |
3452 } | |
3405 clear_region_fields(); | 3453 clear_region_fields(); |
3406 } | 3454 } |
3407 | 3455 |
3408 void CMTask::clear_region_fields() { | 3456 void CMTask::clear_region_fields() { |
3409 // Values for these three fields that indicate that we're not | 3457 // Values for these three fields that indicate that we're not |
3425 } | 3473 } |
3426 | 3474 |
3427 void CMTask::reset(CMBitMap* nextMarkBitMap) { | 3475 void CMTask::reset(CMBitMap* nextMarkBitMap) { |
3428 guarantee(nextMarkBitMap != NULL, "invariant"); | 3476 guarantee(nextMarkBitMap != NULL, "invariant"); |
3429 | 3477 |
3430 if (_cm->verbose_low()) | 3478 if (_cm->verbose_low()) { |
3431 gclog_or_tty->print_cr("[%d] resetting", _task_id); | 3479 gclog_or_tty->print_cr("[%d] resetting", _task_id); |
3480 } | |
3432 | 3481 |
3433 _nextMarkBitMap = nextMarkBitMap; | 3482 _nextMarkBitMap = nextMarkBitMap; |
3434 clear_region_fields(); | 3483 clear_region_fields(); |
3435 assert(_aborted_region.is_empty(), "should have been cleared"); | 3484 assert(_aborted_region.is_empty(), "should have been cleared"); |
3436 | 3485 |
3479 "shouldn't have been called otherwise"); | 3528 "shouldn't have been called otherwise"); |
3480 regular_clock_call(); | 3529 regular_clock_call(); |
3481 } | 3530 } |
3482 | 3531 |
3483 void CMTask::regular_clock_call() { | 3532 void CMTask::regular_clock_call() { |
3484 if (has_aborted()) | 3533 if (has_aborted()) return; |
3485 return; | |
3486 | 3534 |
3487 // First, we need to recalculate the words scanned and refs reached | 3535 // First, we need to recalculate the words scanned and refs reached |
3488 // limits for the next clock call. | 3536 // limits for the next clock call. |
3489 recalculate_limits(); | 3537 recalculate_limits(); |
3490 | 3538 |
3497 } | 3545 } |
3498 | 3546 |
3499 // If we are not concurrent (i.e. we're doing remark) we don't need | 3547 // If we are not concurrent (i.e. we're doing remark) we don't need |
3500 // to check anything else. The other steps are only needed during | 3548 // to check anything else. The other steps are only needed during |
3501 // the concurrent marking phase. | 3549 // the concurrent marking phase. |
3502 if (!concurrent()) | 3550 if (!concurrent()) return; |
3503 return; | |
3504 | 3551 |
3505 // (2) If marking has been aborted for Full GC, then we also abort. | 3552 // (2) If marking has been aborted for Full GC, then we also abort. |
3506 if (_cm->has_aborted()) { | 3553 if (_cm->has_aborted()) { |
3507 set_has_aborted(); | 3554 set_has_aborted(); |
3508 statsOnly( ++_aborted_cm_aborted ); | 3555 statsOnly( ++_aborted_cm_aborted ); |
3511 | 3558 |
3512 double curr_time_ms = os::elapsedVTime() * 1000.0; | 3559 double curr_time_ms = os::elapsedVTime() * 1000.0; |
3513 | 3560 |
3514 // (3) If marking stats are enabled, then we update the step history. | 3561 // (3) If marking stats are enabled, then we update the step history. |
3515 #if _MARKING_STATS_ | 3562 #if _MARKING_STATS_ |
3516 if (_words_scanned >= _words_scanned_limit) | 3563 if (_words_scanned >= _words_scanned_limit) { |
3517 ++_clock_due_to_scanning; | 3564 ++_clock_due_to_scanning; |
3518 if (_refs_reached >= _refs_reached_limit) | 3565 } |
3566 if (_refs_reached >= _refs_reached_limit) { | |
3519 ++_clock_due_to_marking; | 3567 ++_clock_due_to_marking; |
3568 } | |
3520 | 3569 |
3521 double last_interval_ms = curr_time_ms - _interval_start_time_ms; | 3570 double last_interval_ms = curr_time_ms - _interval_start_time_ms; |
3522 _interval_start_time_ms = curr_time_ms; | 3571 _interval_start_time_ms = curr_time_ms; |
3523 _all_clock_intervals_ms.add(last_interval_ms); | 3572 _all_clock_intervals_ms.add(last_interval_ms); |
3524 | 3573 |
3525 if (_cm->verbose_medium()) { | 3574 if (_cm->verbose_medium()) { |
3526 gclog_or_tty->print_cr("[%d] regular clock, interval = %1.2lfms, " | 3575 gclog_or_tty->print_cr("[%d] regular clock, interval = %1.2lfms, " |
3527 "scanned = %d%s, refs reached = %d%s", | 3576 "scanned = %d%s, refs reached = %d%s", |
3528 _task_id, last_interval_ms, | 3577 _task_id, last_interval_ms, |
3529 _words_scanned, | 3578 _words_scanned, |
3530 (_words_scanned >= _words_scanned_limit) ? " (*)" : "", | 3579 (_words_scanned >= _words_scanned_limit) ? " (*)" : "", |
3531 _refs_reached, | 3580 _refs_reached, |
3532 (_refs_reached >= _refs_reached_limit) ? " (*)" : ""); | 3581 (_refs_reached >= _refs_reached_limit) ? " (*)" : ""); |
3533 } | 3582 } |
3534 #endif // _MARKING_STATS_ | 3583 #endif // _MARKING_STATS_ |
3535 | 3584 |
3536 // (4) We check whether we should yield. If we have to, then we abort. | 3585 // (4) We check whether we should yield. If we have to, then we abort. |
3537 if (_cm->should_yield()) { | 3586 if (_cm->should_yield()) { |
3554 | 3603 |
3555 // (6) Finally, we check whether there are enough completed STAB | 3604 // (6) Finally, we check whether there are enough completed STAB |
3556 // buffers available for processing. If there are, we abort. | 3605 // buffers available for processing. If there are, we abort. |
3557 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | 3606 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); |
3558 if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) { | 3607 if (!_draining_satb_buffers && satb_mq_set.process_completed_buffers()) { |
3559 if (_cm->verbose_low()) | 3608 if (_cm->verbose_low()) { |
3560 gclog_or_tty->print_cr("[%d] aborting to deal with pending SATB buffers", | 3609 gclog_or_tty->print_cr("[%d] aborting to deal with pending SATB buffers", |
3561 _task_id); | 3610 _task_id); |
3611 } | |
3562 // we do need to process SATB buffers, we'll abort and restart | 3612 // we do need to process SATB buffers, we'll abort and restart |
3563 // the marking task to do so | 3613 // the marking task to do so |
3564 set_has_aborted(); | 3614 set_has_aborted(); |
3565 statsOnly( ++_aborted_satb ); | 3615 statsOnly( ++_aborted_satb ); |
3566 return; | 3616 return; |
3579 // This is called when we believe that we're going to do an infrequent | 3629 // This is called when we believe that we're going to do an infrequent |
3580 // operation which will increase the per byte scanned cost (i.e. move | 3630 // operation which will increase the per byte scanned cost (i.e. move |
3581 // entries to/from the global stack). It basically tries to decrease the | 3631 // entries to/from the global stack). It basically tries to decrease the |
3582 // scanning limit so that the clock is called earlier. | 3632 // scanning limit so that the clock is called earlier. |
3583 | 3633 |
3584 if (_cm->verbose_medium()) | 3634 if (_cm->verbose_medium()) { |
3585 gclog_or_tty->print_cr("[%d] decreasing limits", _task_id); | 3635 gclog_or_tty->print_cr("[%d] decreasing limits", _task_id); |
3636 } | |
3586 | 3637 |
3587 _words_scanned_limit = _real_words_scanned_limit - | 3638 _words_scanned_limit = _real_words_scanned_limit - |
3588 3 * words_scanned_period / 4; | 3639 3 * words_scanned_period / 4; |
3589 _refs_reached_limit = _real_refs_reached_limit - | 3640 _refs_reached_limit = _real_refs_reached_limit - |
3590 3 * refs_reached_period / 4; | 3641 3 * refs_reached_period / 4; |
3606 // we popped at least one entry from the local queue | 3657 // we popped at least one entry from the local queue |
3607 | 3658 |
3608 statsOnly( ++_global_transfers_to; _local_pops += n ); | 3659 statsOnly( ++_global_transfers_to; _local_pops += n ); |
3609 | 3660 |
3610 if (!_cm->mark_stack_push(buffer, n)) { | 3661 if (!_cm->mark_stack_push(buffer, n)) { |
3611 if (_cm->verbose_low()) | 3662 if (_cm->verbose_low()) { |
3612 gclog_or_tty->print_cr("[%d] aborting due to global stack overflow", _task_id); | 3663 gclog_or_tty->print_cr("[%d] aborting due to global stack overflow", |
3664 _task_id); | |
3665 } | |
3613 set_has_aborted(); | 3666 set_has_aborted(); |
3614 } else { | 3667 } else { |
3615 // the transfer was successful | 3668 // the transfer was successful |
3616 | 3669 |
3617 if (_cm->verbose_medium()) | 3670 if (_cm->verbose_medium()) { |
3618 gclog_or_tty->print_cr("[%d] pushed %d entries to the global stack", | 3671 gclog_or_tty->print_cr("[%d] pushed %d entries to the global stack", |
3619 _task_id, n); | 3672 _task_id, n); |
3673 } | |
3620 statsOnly( int tmp_size = _cm->mark_stack_size(); | 3674 statsOnly( int tmp_size = _cm->mark_stack_size(); |
3621 if (tmp_size > _global_max_size) | 3675 if (tmp_size > _global_max_size) { |
3622 _global_max_size = tmp_size; | 3676 _global_max_size = tmp_size; |
3677 } | |
3623 _global_pushes += n ); | 3678 _global_pushes += n ); |
3624 } | 3679 } |
3625 } | 3680 } |
3626 | 3681 |
3627 // this operation was quite expensive, so decrease the limits | 3682 // this operation was quite expensive, so decrease the limits |
3638 "we should not pop more than the given limit"); | 3693 "we should not pop more than the given limit"); |
3639 if (n > 0) { | 3694 if (n > 0) { |
3640 // yes, we did actually pop at least one entry | 3695 // yes, we did actually pop at least one entry |
3641 | 3696 |
3642 statsOnly( ++_global_transfers_from; _global_pops += n ); | 3697 statsOnly( ++_global_transfers_from; _global_pops += n ); |
3643 if (_cm->verbose_medium()) | 3698 if (_cm->verbose_medium()) { |
3644 gclog_or_tty->print_cr("[%d] popped %d entries from the global stack", | 3699 gclog_or_tty->print_cr("[%d] popped %d entries from the global stack", |
3645 _task_id, n); | 3700 _task_id, n); |
3701 } | |
3646 for (int i = 0; i < n; ++i) { | 3702 for (int i = 0; i < n; ++i) { |
3647 bool success = _task_queue->push(buffer[i]); | 3703 bool success = _task_queue->push(buffer[i]); |
3648 // We only call this when the local queue is empty or under a | 3704 // We only call this when the local queue is empty or under a |
3649 // given target limit. So, we do not expect this push to fail. | 3705 // given target limit. So, we do not expect this push to fail. |
3650 assert(success, "invariant"); | 3706 assert(success, "invariant"); |
3651 } | 3707 } |
3652 | 3708 |
3653 statsOnly( int tmp_size = _task_queue->size(); | 3709 statsOnly( int tmp_size = _task_queue->size(); |
3654 if (tmp_size > _local_max_size) | 3710 if (tmp_size > _local_max_size) { |
3655 _local_max_size = tmp_size; | 3711 _local_max_size = tmp_size; |
3712 } | |
3656 _local_pushes += n ); | 3713 _local_pushes += n ); |
3657 } | 3714 } |
3658 | 3715 |
3659 // this operation was quite expensive, so decrease the limits | 3716 // this operation was quite expensive, so decrease the limits |
3660 decrease_limits(); | 3717 decrease_limits(); |
3661 } | 3718 } |
3662 | 3719 |
3663 void CMTask::drain_local_queue(bool partially) { | 3720 void CMTask::drain_local_queue(bool partially) { |
3664 if (has_aborted()) | 3721 if (has_aborted()) return; |
3665 return; | |
3666 | 3722 |
3667 // Decide what the target size is, depending whether we're going to | 3723 // Decide what the target size is, depending whether we're going to |
3668 // drain it partially (so that other tasks can steal if they run out | 3724 // drain it partially (so that other tasks can steal if they run out |
3669 // of things to do) or totally (at the very end). | 3725 // of things to do) or totally (at the very end). |
3670 size_t target_size; | 3726 size_t target_size; |
3671 if (partially) | 3727 if (partially) { |
3672 target_size = MIN2((size_t)_task_queue->max_elems()/3, GCDrainStackTargetSize); | 3728 target_size = MIN2((size_t)_task_queue->max_elems()/3, GCDrainStackTargetSize); |
3673 else | 3729 } else { |
3674 target_size = 0; | 3730 target_size = 0; |
3731 } | |
3675 | 3732 |
3676 if (_task_queue->size() > target_size) { | 3733 if (_task_queue->size() > target_size) { |
3677 if (_cm->verbose_high()) | 3734 if (_cm->verbose_high()) { |
3678 gclog_or_tty->print_cr("[%d] draining local queue, target size = %d", | 3735 gclog_or_tty->print_cr("[%d] draining local queue, target size = %d", |
3679 _task_id, target_size); | 3736 _task_id, target_size); |
3737 } | |
3680 | 3738 |
3681 oop obj; | 3739 oop obj; |
3682 bool ret = _task_queue->pop_local(obj); | 3740 bool ret = _task_queue->pop_local(obj); |
3683 while (ret) { | 3741 while (ret) { |
3684 statsOnly( ++_local_pops ); | 3742 statsOnly( ++_local_pops ); |
3685 | 3743 |
3686 if (_cm->verbose_high()) | 3744 if (_cm->verbose_high()) { |
3687 gclog_or_tty->print_cr("[%d] popped "PTR_FORMAT, _task_id, | 3745 gclog_or_tty->print_cr("[%d] popped "PTR_FORMAT, _task_id, |
3688 (void*) obj); | 3746 (void*) obj); |
3747 } | |
3689 | 3748 |
3690 assert(_g1h->is_in_g1_reserved((HeapWord*) obj), "invariant" ); | 3749 assert(_g1h->is_in_g1_reserved((HeapWord*) obj), "invariant" ); |
3691 assert(!_g1h->is_on_master_free_list( | 3750 assert(!_g1h->is_on_master_free_list( |
3692 _g1h->heap_region_containing((HeapWord*) obj)), "invariant"); | 3751 _g1h->heap_region_containing((HeapWord*) obj)), "invariant"); |
3693 | 3752 |
3694 scan_object(obj); | 3753 scan_object(obj); |
3695 | 3754 |
3696 if (_task_queue->size() <= target_size || has_aborted()) | 3755 if (_task_queue->size() <= target_size || has_aborted()) { |
3697 ret = false; | 3756 ret = false; |
3698 else | 3757 } else { |
3699 ret = _task_queue->pop_local(obj); | 3758 ret = _task_queue->pop_local(obj); |
3700 } | 3759 } |
3701 | 3760 } |
3702 if (_cm->verbose_high()) | 3761 |
3762 if (_cm->verbose_high()) { | |
3703 gclog_or_tty->print_cr("[%d] drained local queue, size = %d", | 3763 gclog_or_tty->print_cr("[%d] drained local queue, size = %d", |
3704 _task_id, _task_queue->size()); | 3764 _task_id, _task_queue->size()); |
3765 } | |
3705 } | 3766 } |
3706 } | 3767 } |
3707 | 3768 |
3708 void CMTask::drain_global_stack(bool partially) { | 3769 void CMTask::drain_global_stack(bool partially) { |
3709 if (has_aborted()) | 3770 if (has_aborted()) return; |
3710 return; | |
3711 | 3771 |
3712 // We have a policy to drain the local queue before we attempt to | 3772 // We have a policy to drain the local queue before we attempt to |
3713 // drain the global stack. | 3773 // drain the global stack. |
3714 assert(partially || _task_queue->size() == 0, "invariant"); | 3774 assert(partially || _task_queue->size() == 0, "invariant"); |
3715 | 3775 |
3718 // of things to do) or totally (at the very end). Notice that, | 3778 // of things to do) or totally (at the very end). Notice that, |
3719 // because we move entries from the global stack in chunks or | 3779 // because we move entries from the global stack in chunks or |
3720 // because another task might be doing the same, we might in fact | 3780 // because another task might be doing the same, we might in fact |
3721 // drop below the target. But, this is not a problem. | 3781 // drop below the target. But, this is not a problem. |
3722 size_t target_size; | 3782 size_t target_size; |
3723 if (partially) | 3783 if (partially) { |
3724 target_size = _cm->partial_mark_stack_size_target(); | 3784 target_size = _cm->partial_mark_stack_size_target(); |
3725 else | 3785 } else { |
3726 target_size = 0; | 3786 target_size = 0; |
3787 } | |
3727 | 3788 |
3728 if (_cm->mark_stack_size() > target_size) { | 3789 if (_cm->mark_stack_size() > target_size) { |
3729 if (_cm->verbose_low()) | 3790 if (_cm->verbose_low()) { |
3730 gclog_or_tty->print_cr("[%d] draining global_stack, target size %d", | 3791 gclog_or_tty->print_cr("[%d] draining global_stack, target size %d", |
3731 _task_id, target_size); | 3792 _task_id, target_size); |
3793 } | |
3732 | 3794 |
3733 while (!has_aborted() && _cm->mark_stack_size() > target_size) { | 3795 while (!has_aborted() && _cm->mark_stack_size() > target_size) { |
3734 get_entries_from_global_stack(); | 3796 get_entries_from_global_stack(); |
3735 drain_local_queue(partially); | 3797 drain_local_queue(partially); |
3736 } | 3798 } |
3737 | 3799 |
3738 if (_cm->verbose_low()) | 3800 if (_cm->verbose_low()) { |
3739 gclog_or_tty->print_cr("[%d] drained global stack, size = %d", | 3801 gclog_or_tty->print_cr("[%d] drained global stack, size = %d", |
3740 _task_id, _cm->mark_stack_size()); | 3802 _task_id, _cm->mark_stack_size()); |
3803 } | |
3741 } | 3804 } |
3742 } | 3805 } |
3743 | 3806 |
3744 // SATB Queue has several assumptions on whether to call the par or | 3807 // SATB Queue has several assumptions on whether to call the par or |
3745 // non-par versions of the methods. this is why some of the code is | 3808 // non-par versions of the methods. this is why some of the code is |
3746 // replicated. We should really get rid of the single-threaded version | 3809 // replicated. We should really get rid of the single-threaded version |
3747 // of the code to simplify things. | 3810 // of the code to simplify things. |
3748 void CMTask::drain_satb_buffers() { | 3811 void CMTask::drain_satb_buffers() { |
3749 if (has_aborted()) | 3812 if (has_aborted()) return; |
3750 return; | |
3751 | 3813 |
3752 // We set this so that the regular clock knows that we're in the | 3814 // We set this so that the regular clock knows that we're in the |
3753 // middle of draining buffers and doesn't set the abort flag when it | 3815 // middle of draining buffers and doesn't set the abort flag when it |
3754 // notices that SATB buffers are available for draining. It'd be | 3816 // notices that SATB buffers are available for draining. It'd be |
3755 // very counter productive if it did that. :-) | 3817 // very counter productive if it did that. :-) |
3756 _draining_satb_buffers = true; | 3818 _draining_satb_buffers = true; |
3757 | 3819 |
3758 CMObjectClosure oc(this); | 3820 CMObjectClosure oc(this); |
3759 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); | 3821 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); |
3760 if (G1CollectedHeap::use_parallel_gc_threads()) | 3822 if (G1CollectedHeap::use_parallel_gc_threads()) { |
3761 satb_mq_set.set_par_closure(_task_id, &oc); | 3823 satb_mq_set.set_par_closure(_task_id, &oc); |
3762 else | 3824 } else { |
3763 satb_mq_set.set_closure(&oc); | 3825 satb_mq_set.set_closure(&oc); |
3826 } | |
3764 | 3827 |
3765 // This keeps claiming and applying the closure to completed buffers | 3828 // This keeps claiming and applying the closure to completed buffers |
3766 // until we run out of buffers or we need to abort. | 3829 // until we run out of buffers or we need to abort. |
3767 if (G1CollectedHeap::use_parallel_gc_threads()) { | 3830 if (G1CollectedHeap::use_parallel_gc_threads()) { |
3768 while (!has_aborted() && | 3831 while (!has_aborted() && |
3769 satb_mq_set.par_apply_closure_to_completed_buffer(_task_id)) { | 3832 satb_mq_set.par_apply_closure_to_completed_buffer(_task_id)) { |
3770 if (_cm->verbose_medium()) | 3833 if (_cm->verbose_medium()) { |
3771 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); | 3834 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); |
3835 } | |
3772 statsOnly( ++_satb_buffers_processed ); | 3836 statsOnly( ++_satb_buffers_processed ); |
3773 regular_clock_call(); | 3837 regular_clock_call(); |
3774 } | 3838 } |
3775 } else { | 3839 } else { |
3776 while (!has_aborted() && | 3840 while (!has_aborted() && |
3777 satb_mq_set.apply_closure_to_completed_buffer()) { | 3841 satb_mq_set.apply_closure_to_completed_buffer()) { |
3778 if (_cm->verbose_medium()) | 3842 if (_cm->verbose_medium()) { |
3779 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); | 3843 gclog_or_tty->print_cr("[%d] processed an SATB buffer", _task_id); |
3844 } | |
3780 statsOnly( ++_satb_buffers_processed ); | 3845 statsOnly( ++_satb_buffers_processed ); |
3781 regular_clock_call(); | 3846 regular_clock_call(); |
3782 } | 3847 } |
3783 } | 3848 } |
3784 | 3849 |
3785 if (!concurrent() && !has_aborted()) { | 3850 if (!concurrent() && !has_aborted()) { |
3786 // We should only do this during remark. | 3851 // We should only do this during remark. |
3787 if (G1CollectedHeap::use_parallel_gc_threads()) | 3852 if (G1CollectedHeap::use_parallel_gc_threads()) { |
3788 satb_mq_set.par_iterate_closure_all_threads(_task_id); | 3853 satb_mq_set.par_iterate_closure_all_threads(_task_id); |
3789 else | 3854 } else { |
3790 satb_mq_set.iterate_closure_all_threads(); | 3855 satb_mq_set.iterate_closure_all_threads(); |
3856 } | |
3791 } | 3857 } |
3792 | 3858 |
3793 _draining_satb_buffers = false; | 3859 _draining_satb_buffers = false; |
3794 | 3860 |
3795 assert(has_aborted() || | 3861 assert(has_aborted() || |
3796 concurrent() || | 3862 concurrent() || |
3797 satb_mq_set.completed_buffers_num() == 0, "invariant"); | 3863 satb_mq_set.completed_buffers_num() == 0, "invariant"); |
3798 | 3864 |
3799 if (G1CollectedHeap::use_parallel_gc_threads()) | 3865 if (G1CollectedHeap::use_parallel_gc_threads()) { |
3800 satb_mq_set.set_par_closure(_task_id, NULL); | 3866 satb_mq_set.set_par_closure(_task_id, NULL); |
3801 else | 3867 } else { |
3802 satb_mq_set.set_closure(NULL); | 3868 satb_mq_set.set_closure(NULL); |
3869 } | |
3803 | 3870 |
3804 // again, this was a potentially expensive operation, decrease the | 3871 // again, this was a potentially expensive operation, decrease the |
3805 // limits to get the regular clock call early | 3872 // limits to get the regular clock call early |
3806 decrease_limits(); | 3873 decrease_limits(); |
3807 } | 3874 } |
3808 | 3875 |
3809 void CMTask::drain_region_stack(BitMapClosure* bc) { | 3876 void CMTask::drain_region_stack(BitMapClosure* bc) { |
3810 if (has_aborted()) | 3877 if (has_aborted()) return; |
3811 return; | |
3812 | 3878 |
3813 assert(_region_finger == NULL, | 3879 assert(_region_finger == NULL, |
3814 "it should be NULL when we're not scanning a region"); | 3880 "it should be NULL when we're not scanning a region"); |
3815 | 3881 |
3816 if (!_cm->region_stack_empty() || !_aborted_region.is_empty()) { | 3882 if (!_cm->region_stack_empty() || !_aborted_region.is_empty()) { |
3817 if (_cm->verbose_low()) | 3883 if (_cm->verbose_low()) { |
3818 gclog_or_tty->print_cr("[%d] draining region stack, size = %d", | 3884 gclog_or_tty->print_cr("[%d] draining region stack, size = %d", |
3819 _task_id, _cm->region_stack_size()); | 3885 _task_id, _cm->region_stack_size()); |
3886 } | |
3820 | 3887 |
3821 MemRegion mr; | 3888 MemRegion mr; |
3822 | 3889 |
3823 if (!_aborted_region.is_empty()) { | 3890 if (!_aborted_region.is_empty()) { |
3824 mr = _aborted_region; | 3891 mr = _aborted_region; |
3825 _aborted_region = MemRegion(); | 3892 _aborted_region = MemRegion(); |
3826 | 3893 |
3827 if (_cm->verbose_low()) | 3894 if (_cm->verbose_low()) { |
3828 gclog_or_tty->print_cr("[%d] scanning aborted region [ " PTR_FORMAT ", " PTR_FORMAT " )", | 3895 gclog_or_tty->print_cr("[%d] scanning aborted region " |
3829 _task_id, mr.start(), mr.end()); | 3896 "[ " PTR_FORMAT ", " PTR_FORMAT " )", |
3897 _task_id, mr.start(), mr.end()); | |
3898 } | |
3830 } else { | 3899 } else { |
3831 mr = _cm->region_stack_pop_lock_free(); | 3900 mr = _cm->region_stack_pop_lock_free(); |
3832 // it returns MemRegion() if the pop fails | 3901 // it returns MemRegion() if the pop fails |
3833 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); | 3902 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); |
3834 } | 3903 } |
3835 | 3904 |
3836 while (mr.start() != NULL) { | 3905 while (mr.start() != NULL) { |
3837 if (_cm->verbose_medium()) | 3906 if (_cm->verbose_medium()) { |
3838 gclog_or_tty->print_cr("[%d] we are scanning region " | 3907 gclog_or_tty->print_cr("[%d] we are scanning region " |
3839 "["PTR_FORMAT", "PTR_FORMAT")", | 3908 "["PTR_FORMAT", "PTR_FORMAT")", |
3840 _task_id, mr.start(), mr.end()); | 3909 _task_id, mr.start(), mr.end()); |
3910 } | |
3841 | 3911 |
3842 assert(mr.end() <= _cm->finger(), | 3912 assert(mr.end() <= _cm->finger(), |
3843 "otherwise the region shouldn't be on the stack"); | 3913 "otherwise the region shouldn't be on the stack"); |
3844 assert(!mr.is_empty(), "Only non-empty regions live on the region stack"); | 3914 assert(!mr.is_empty(), "Only non-empty regions live on the region stack"); |
3845 if (_nextMarkBitMap->iterate(bc, mr)) { | 3915 if (_nextMarkBitMap->iterate(bc, mr)) { |
3846 assert(!has_aborted(), | 3916 assert(!has_aborted(), |
3847 "cannot abort the task without aborting the bitmap iteration"); | 3917 "cannot abort the task without aborting the bitmap iteration"); |
3848 | 3918 |
3849 // We finished iterating over the region without aborting. | 3919 // We finished iterating over the region without aborting. |
3850 regular_clock_call(); | 3920 regular_clock_call(); |
3851 if (has_aborted()) | 3921 if (has_aborted()) { |
3852 mr = MemRegion(); | 3922 mr = MemRegion(); |
3853 else { | 3923 } else { |
3854 mr = _cm->region_stack_pop_lock_free(); | 3924 mr = _cm->region_stack_pop_lock_free(); |
3855 // it returns MemRegion() if the pop fails | 3925 // it returns MemRegion() if the pop fails |
3856 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); | 3926 statsOnly(if (mr.start() != NULL) ++_region_stack_pops ); |
3857 } | 3927 } |
3858 } else { | 3928 } else { |
3894 mr = MemRegion(); | 3964 mr = MemRegion(); |
3895 } | 3965 } |
3896 _region_finger = NULL; | 3966 _region_finger = NULL; |
3897 } | 3967 } |
3898 | 3968 |
3899 if (_cm->verbose_low()) | 3969 if (_cm->verbose_low()) { |
3900 gclog_or_tty->print_cr("[%d] drained region stack, size = %d", | 3970 gclog_or_tty->print_cr("[%d] drained region stack, size = %d", |
3901 _task_id, _cm->region_stack_size()); | 3971 _task_id, _cm->region_stack_size()); |
3972 } | |
3902 } | 3973 } |
3903 } | 3974 } |
3904 | 3975 |
3905 void CMTask::print_stats() { | 3976 void CMTask::print_stats() { |
3906 gclog_or_tty->print_cr("Marking Stats, task = %d, calls = %d", | 3977 gclog_or_tty->print_cr("Marking Stats, task = %d, calls = %d", |
4097 _has_timed_out = false; | 4168 _has_timed_out = false; |
4098 _draining_satb_buffers = false; | 4169 _draining_satb_buffers = false; |
4099 | 4170 |
4100 ++_calls; | 4171 ++_calls; |
4101 | 4172 |
4102 if (_cm->verbose_low()) | 4173 if (_cm->verbose_low()) { |
4103 gclog_or_tty->print_cr("[%d] >>>>>>>>>> START, call = %d, " | 4174 gclog_or_tty->print_cr("[%d] >>>>>>>>>> START, call = %d, " |
4104 "target = %1.2lfms >>>>>>>>>>", | 4175 "target = %1.2lfms >>>>>>>>>>", |
4105 _task_id, _calls, _time_target_ms); | 4176 _task_id, _calls, _time_target_ms); |
4177 } | |
4106 | 4178 |
4107 // Set up the bitmap and oop closures. Anything that uses them is | 4179 // Set up the bitmap and oop closures. Anything that uses them is |
4108 // eventually called from this method, so it is OK to allocate these | 4180 // eventually called from this method, so it is OK to allocate these |
4109 // statically. | 4181 // statically. |
4110 CMBitMapClosure bitmap_closure(this, _cm, _nextMarkBitMap); | 4182 CMBitMapClosure bitmap_closure(this, _cm, _nextMarkBitMap); |
4157 // through scanning this region. In this case, _finger points to | 4229 // through scanning this region. In this case, _finger points to |
4158 // the address where we last found a marked object. If this is a | 4230 // the address where we last found a marked object. If this is a |
4159 // fresh region, _finger points to start(). | 4231 // fresh region, _finger points to start(). |
4160 MemRegion mr = MemRegion(_finger, _region_limit); | 4232 MemRegion mr = MemRegion(_finger, _region_limit); |
4161 | 4233 |
4162 if (_cm->verbose_low()) | 4234 if (_cm->verbose_low()) { |
4163 gclog_or_tty->print_cr("[%d] we're scanning part " | 4235 gclog_or_tty->print_cr("[%d] we're scanning part " |
4164 "["PTR_FORMAT", "PTR_FORMAT") " | 4236 "["PTR_FORMAT", "PTR_FORMAT") " |
4165 "of region "PTR_FORMAT, | 4237 "of region "PTR_FORMAT, |
4166 _task_id, _finger, _region_limit, _curr_region); | 4238 _task_id, _finger, _region_limit, _curr_region); |
4239 } | |
4167 | 4240 |
4168 // Let's iterate over the bitmap of the part of the | 4241 // Let's iterate over the bitmap of the part of the |
4169 // region that is left. | 4242 // region that is left. |
4170 bitmap_closure.set_scanning_heap_region(true); | 4243 bitmap_closure.set_scanning_heap_region(true); |
4171 if (mr.is_empty() || | 4244 if (mr.is_empty() || |
4217 // given up on the previous one. | 4290 // given up on the previous one. |
4218 // Separated the asserts so that we know which one fires. | 4291 // Separated the asserts so that we know which one fires. |
4219 assert(_curr_region == NULL, "invariant"); | 4292 assert(_curr_region == NULL, "invariant"); |
4220 assert(_finger == NULL, "invariant"); | 4293 assert(_finger == NULL, "invariant"); |
4221 assert(_region_limit == NULL, "invariant"); | 4294 assert(_region_limit == NULL, "invariant"); |
4222 if (_cm->verbose_low()) | 4295 if (_cm->verbose_low()) { |
4223 gclog_or_tty->print_cr("[%d] trying to claim a new region", _task_id); | 4296 gclog_or_tty->print_cr("[%d] trying to claim a new region", _task_id); |
4297 } | |
4224 HeapRegion* claimed_region = _cm->claim_region(_task_id); | 4298 HeapRegion* claimed_region = _cm->claim_region(_task_id); |
4225 if (claimed_region != NULL) { | 4299 if (claimed_region != NULL) { |
4226 // Yes, we managed to claim one | 4300 // Yes, we managed to claim one |
4227 statsOnly( ++_regions_claimed ); | 4301 statsOnly( ++_regions_claimed ); |
4228 | 4302 |
4229 if (_cm->verbose_low()) | 4303 if (_cm->verbose_low()) { |
4230 gclog_or_tty->print_cr("[%d] we successfully claimed " | 4304 gclog_or_tty->print_cr("[%d] we successfully claimed " |
4231 "region "PTR_FORMAT, | 4305 "region "PTR_FORMAT, |
4232 _task_id, claimed_region); | 4306 _task_id, claimed_region); |
4307 } | |
4233 | 4308 |
4234 setup_for_region(claimed_region); | 4309 setup_for_region(claimed_region); |
4235 assert(_curr_region == claimed_region, "invariant"); | 4310 assert(_curr_region == claimed_region, "invariant"); |
4236 } | 4311 } |
4237 // It is important to call the regular clock here. It might take | 4312 // It is important to call the regular clock here. It might take |
4254 // check if the region stack is empty because if a thread is aborting | 4329 // check if the region stack is empty because if a thread is aborting |
4255 // it can push a partially done region back. | 4330 // it can push a partially done region back. |
4256 assert(_cm->out_of_regions(), | 4331 assert(_cm->out_of_regions(), |
4257 "at this point we should be out of regions"); | 4332 "at this point we should be out of regions"); |
4258 | 4333 |
4259 if (_cm->verbose_low()) | 4334 if (_cm->verbose_low()) { |
4260 gclog_or_tty->print_cr("[%d] all regions claimed", _task_id); | 4335 gclog_or_tty->print_cr("[%d] all regions claimed", _task_id); |
4336 } | |
4261 | 4337 |
4262 // Try to reduce the number of available SATB buffers so that | 4338 // Try to reduce the number of available SATB buffers so that |
4263 // remark has less work to do. | 4339 // remark has less work to do. |
4264 drain_satb_buffers(); | 4340 drain_satb_buffers(); |
4265 } | 4341 } |
4279 // check if the region stack is empty because if a thread is aborting | 4355 // check if the region stack is empty because if a thread is aborting |
4280 // it can push a partially done region back. | 4356 // it can push a partially done region back. |
4281 assert(_cm->out_of_regions() && _task_queue->size() == 0, | 4357 assert(_cm->out_of_regions() && _task_queue->size() == 0, |
4282 "only way to reach here"); | 4358 "only way to reach here"); |
4283 | 4359 |
4284 if (_cm->verbose_low()) | 4360 if (_cm->verbose_low()) { |
4285 gclog_or_tty->print_cr("[%d] starting to steal", _task_id); | 4361 gclog_or_tty->print_cr("[%d] starting to steal", _task_id); |
4362 } | |
4286 | 4363 |
4287 while (!has_aborted()) { | 4364 while (!has_aborted()) { |
4288 oop obj; | 4365 oop obj; |
4289 statsOnly( ++_steal_attempts ); | 4366 statsOnly( ++_steal_attempts ); |
4290 | 4367 |
4291 if (_cm->try_stealing(_task_id, &_hash_seed, obj)) { | 4368 if (_cm->try_stealing(_task_id, &_hash_seed, obj)) { |
4292 if (_cm->verbose_medium()) | 4369 if (_cm->verbose_medium()) { |
4293 gclog_or_tty->print_cr("[%d] stolen "PTR_FORMAT" successfully", | 4370 gclog_or_tty->print_cr("[%d] stolen "PTR_FORMAT" successfully", |
4294 _task_id, (void*) obj); | 4371 _task_id, (void*) obj); |
4372 } | |
4295 | 4373 |
4296 statsOnly( ++_steals ); | 4374 statsOnly( ++_steals ); |
4297 | 4375 |
4298 assert(_nextMarkBitMap->isMarked((HeapWord*) obj), | 4376 assert(_nextMarkBitMap->isMarked((HeapWord*) obj), |
4299 "any stolen object should be marked"); | 4377 "any stolen object should be marked"); |
4327 // it can push a partially done region back. | 4405 // it can push a partially done region back. |
4328 // Separated the asserts so that we know which one fires. | 4406 // Separated the asserts so that we know which one fires. |
4329 assert(_cm->out_of_regions(), "only way to reach here"); | 4407 assert(_cm->out_of_regions(), "only way to reach here"); |
4330 assert(_task_queue->size() == 0, "only way to reach here"); | 4408 assert(_task_queue->size() == 0, "only way to reach here"); |
4331 | 4409 |
4332 if (_cm->verbose_low()) | 4410 if (_cm->verbose_low()) { |
4333 gclog_or_tty->print_cr("[%d] starting termination protocol", _task_id); | 4411 gclog_or_tty->print_cr("[%d] starting termination protocol", _task_id); |
4412 } | |
4334 | 4413 |
4335 _termination_start_time_ms = os::elapsedVTime() * 1000.0; | 4414 _termination_start_time_ms = os::elapsedVTime() * 1000.0; |
4336 // The CMTask class also extends the TerminatorTerminator class, | 4415 // The CMTask class also extends the TerminatorTerminator class, |
4337 // hence its should_exit_termination() method will also decide | 4416 // hence its should_exit_termination() method will also decide |
4338 // whether to exit the termination protocol or not. | 4417 // whether to exit the termination protocol or not. |
4366 guarantee(_task_queue->size() == 0, "only way to reach here"); | 4445 guarantee(_task_queue->size() == 0, "only way to reach here"); |
4367 guarantee(!_cm->has_overflown(), "only way to reach here"); | 4446 guarantee(!_cm->has_overflown(), "only way to reach here"); |
4368 guarantee(!_cm->mark_stack_overflow(), "only way to reach here"); | 4447 guarantee(!_cm->mark_stack_overflow(), "only way to reach here"); |
4369 guarantee(!_cm->region_stack_overflow(), "only way to reach here"); | 4448 guarantee(!_cm->region_stack_overflow(), "only way to reach here"); |
4370 | 4449 |
4371 if (_cm->verbose_low()) | 4450 if (_cm->verbose_low()) { |
4372 gclog_or_tty->print_cr("[%d] all tasks terminated", _task_id); | 4451 gclog_or_tty->print_cr("[%d] all tasks terminated", _task_id); |
4452 } | |
4373 } else { | 4453 } else { |
4374 // Apparently there's more work to do. Let's abort this task. It | 4454 // Apparently there's more work to do. Let's abort this task. It |
4375 // will restart it and we can hopefully find more things to do. | 4455 // will restart it and we can hopefully find more things to do. |
4376 | 4456 |
4377 if (_cm->verbose_low()) | 4457 if (_cm->verbose_low()) { |
4378 gclog_or_tty->print_cr("[%d] apparently there is more work to do", _task_id); | 4458 gclog_or_tty->print_cr("[%d] apparently there is more work to do", |
4459 _task_id); | |
4460 } | |
4379 | 4461 |
4380 set_has_aborted(); | 4462 set_has_aborted(); |
4381 statsOnly( ++_aborted_termination ); | 4463 statsOnly( ++_aborted_termination ); |
4382 } | 4464 } |
4383 } | 4465 } |
4410 // marking phase and start iterating over regions. However, in | 4492 // marking phase and start iterating over regions. However, in |
4411 // order to do this we have to make sure that all tasks stop | 4493 // order to do this we have to make sure that all tasks stop |
4412 // what they are doing and re-initialise in a safe manner. We | 4494 // what they are doing and re-initialise in a safe manner. We |
4413 // will achieve this with the use of two barrier sync points. | 4495 // will achieve this with the use of two barrier sync points. |
4414 | 4496 |
4415 if (_cm->verbose_low()) | 4497 if (_cm->verbose_low()) { |
4416 gclog_or_tty->print_cr("[%d] detected overflow", _task_id); | 4498 gclog_or_tty->print_cr("[%d] detected overflow", _task_id); |
4499 } | |
4417 | 4500 |
4418 _cm->enter_first_sync_barrier(_task_id); | 4501 _cm->enter_first_sync_barrier(_task_id); |
4419 // When we exit this sync barrier we know that all tasks have | 4502 // When we exit this sync barrier we know that all tasks have |
4420 // stopped doing marking work. So, it's now safe to | 4503 // stopped doing marking work. So, it's now safe to |
4421 // re-initialise our data structures. At the end of this method, | 4504 // re-initialise our data structures. At the end of this method, |
4434 | 4517 |
4435 if (_cm->verbose_low()) { | 4518 if (_cm->verbose_low()) { |
4436 gclog_or_tty->print_cr("[%d] <<<<<<<<<< ABORTING, target = %1.2lfms, " | 4519 gclog_or_tty->print_cr("[%d] <<<<<<<<<< ABORTING, target = %1.2lfms, " |
4437 "elapsed = %1.2lfms <<<<<<<<<<", | 4520 "elapsed = %1.2lfms <<<<<<<<<<", |
4438 _task_id, _time_target_ms, elapsed_time_ms); | 4521 _task_id, _time_target_ms, elapsed_time_ms); |
4439 if (_cm->has_aborted()) | 4522 if (_cm->has_aborted()) { |
4440 gclog_or_tty->print_cr("[%d] ========== MARKING ABORTED ==========", | 4523 gclog_or_tty->print_cr("[%d] ========== MARKING ABORTED ==========", |
4441 _task_id); | 4524 _task_id); |
4525 } | |
4442 } | 4526 } |
4443 } else { | 4527 } else { |
4444 if (_cm->verbose_low()) | 4528 if (_cm->verbose_low()) { |
4445 gclog_or_tty->print_cr("[%d] <<<<<<<<<< FINISHED, target = %1.2lfms, " | 4529 gclog_or_tty->print_cr("[%d] <<<<<<<<<< FINISHED, target = %1.2lfms, " |
4446 "elapsed = %1.2lfms <<<<<<<<<<", | 4530 "elapsed = %1.2lfms <<<<<<<<<<", |
4447 _task_id, _time_target_ms, elapsed_time_ms); | 4531 _task_id, _time_target_ms, elapsed_time_ms); |
4532 } | |
4448 } | 4533 } |
4449 | 4534 |
4450 _claimed = false; | 4535 _claimed = false; |
4451 } | 4536 } |
4452 | 4537 |