src/share/vm/gc_implementation/g1/heapRegion.cpp

changeset 7647
80ac3ee51955
parent 7366
e8bf410d5e23
child 7654
36c7518fd486
equal deleted inserted replaced
7646:5743a702da65 7647:80ac3ee51955
336 G1OffsetTableContigSpace::initialize(mr, clear_space, mangle_space); 336 G1OffsetTableContigSpace::initialize(mr, clear_space, mangle_space);
337 337
338 _orig_end = mr.end(); 338 _orig_end = mr.end();
339 hr_clear(false /*par*/, false /*clear_space*/); 339 hr_clear(false /*par*/, false /*clear_space*/);
340 set_top(bottom()); 340 set_top(bottom());
341 record_top_and_timestamp(); 341 record_timestamp();
342 } 342 }
343 343
344 CompactibleSpace* HeapRegion::next_compaction_space() const { 344 CompactibleSpace* HeapRegion::next_compaction_space() const {
345 return G1CollectedHeap::heap()->next_compaction_region(this); 345 return G1CollectedHeap::heap()->next_compaction_region(this);
346 } 346 }
424 } 424 }
425 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 425 G1CollectedHeap* g1h = G1CollectedHeap::heap();
426 426
427 // If we're within a stop-world GC, then we might look at a card in a 427 // If we're within a stop-world GC, then we might look at a card in a
428 // GC alloc region that extends onto a GC LAB, which may not be 428 // GC alloc region that extends onto a GC LAB, which may not be
429 // parseable. Stop such at the "saved_mark" of the region. 429 // parseable. Stop such at the "scan_top" of the region.
430 if (g1h->is_gc_active()) { 430 if (g1h->is_gc_active()) {
431 mr = mr.intersection(used_region_at_save_marks()); 431 mr = mr.intersection(MemRegion(bottom(), scan_top()));
432 } else { 432 } else {
433 mr = mr.intersection(used_region()); 433 mr = mr.intersection(used_region());
434 } 434 }
435 if (mr.is_empty()) return NULL; 435 if (mr.is_empty()) return NULL;
436 // Otherwise, find the obj that extends onto mr.start(). 436 // Otherwise, find the obj that extends onto mr.start().
978 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go 978 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
979 // away eventually. 979 // away eventually.
980 980
981 void G1OffsetTableContigSpace::clear(bool mangle_space) { 981 void G1OffsetTableContigSpace::clear(bool mangle_space) {
982 set_top(bottom()); 982 set_top(bottom());
983 set_saved_mark_word(bottom()); 983 _scan_top = bottom();
984 CompactibleSpace::clear(mangle_space); 984 CompactibleSpace::clear(mangle_space);
985 reset_bot(); 985 reset_bot();
986 } 986 }
987 987
988 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) { 988 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
1010 HeapWord* end) { 1010 HeapWord* end) {
1011 _offsets.alloc_block(start, end); 1011 _offsets.alloc_block(start, end);
1012 return _offsets.threshold(); 1012 return _offsets.threshold();
1013 } 1013 }
1014 1014
1015 HeapWord* G1OffsetTableContigSpace::saved_mark_word() const { 1015 HeapWord* G1OffsetTableContigSpace::scan_top() const {
1016 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1016 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1017 assert( _gc_time_stamp <= g1h->get_gc_time_stamp(), "invariant" );
1018 HeapWord* local_top = top(); 1017 HeapWord* local_top = top();
1019 OrderAccess::loadload(); 1018 OrderAccess::loadload();
1020 if (_gc_time_stamp < g1h->get_gc_time_stamp()) { 1019 const unsigned local_time_stamp = _gc_time_stamp;
1020 assert(local_time_stamp <= g1h->get_gc_time_stamp(), "invariant");
1021 if (local_time_stamp < g1h->get_gc_time_stamp()) {
1021 return local_top; 1022 return local_top;
1022 } else { 1023 } else {
1023 return Space::saved_mark_word(); 1024 return _scan_top;
1024 } 1025 }
1025 } 1026 }
1026 1027
1027 void G1OffsetTableContigSpace::record_top_and_timestamp() { 1028 void G1OffsetTableContigSpace::record_timestamp() {
1028 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 1029 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1029 unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp(); 1030 unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp();
1030 1031
1031 if (_gc_time_stamp < curr_gc_time_stamp) { 1032 if (_gc_time_stamp < curr_gc_time_stamp) {
1032 // The order of these is important, as another thread might be 1033 // Setting the time stamp here tells concurrent readers to look at
1033 // about to start scanning this region. If it does so after 1034 // scan_top to know the maximum allowed address to look at.
1034 // set_saved_mark and before _gc_time_stamp = ..., then the latter 1035
1035 // will be false, and it will pick up top() as the high water mark 1036 // scan_top should be bottom for all regions except for the
1036 // of region. If it does so after _gc_time_stamp = ..., then it 1037 // retained old alloc region which should have scan_top == top
1037 // will pick up the right saved_mark_word() as the high water mark 1038 HeapWord* st = _scan_top;
1038 // of the region. Either way, the behaviour will be correct. 1039 guarantee(st == _bottom || st == _top, "invariant");
1039 Space::set_saved_mark_word(top()); 1040
1040 OrderAccess::storestore();
1041 _gc_time_stamp = curr_gc_time_stamp; 1041 _gc_time_stamp = curr_gc_time_stamp;
1042 // No need to do another barrier to flush the writes above. If 1042 }
1043 // this is called in parallel with other threads trying to 1043 }
1044 // allocate into the region, the caller should call this while 1044
1045 // holding a lock and when the lock is released the writes will be 1045 void G1OffsetTableContigSpace::record_retained_region() {
1046 // flushed. 1046 // scan_top is the maximum address where it's safe for the next gc to
1047 } 1047 // scan this region.
1048 _scan_top = top();
1048 } 1049 }
1049 1050
1050 void G1OffsetTableContigSpace::safe_object_iterate(ObjectClosure* blk) { 1051 void G1OffsetTableContigSpace::safe_object_iterate(ObjectClosure* blk) {
1051 object_iterate(blk); 1052 object_iterate(blk);
1052 } 1053 }
1078 } 1079 }
1079 1080
1080 void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) { 1081 void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
1081 CompactibleSpace::initialize(mr, clear_space, mangle_space); 1082 CompactibleSpace::initialize(mr, clear_space, mangle_space);
1082 _top = bottom(); 1083 _top = bottom();
1084 _scan_top = bottom();
1085 set_saved_mark_word(NULL);
1083 reset_bot(); 1086 reset_bot();
1084 } 1087 }
1085 1088

mercurial