--- old/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp 2018-03-29 11:10:16.049546226 +0200 +++ new/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp 2018-03-29 11:10:15.782538038 +0200 @@ -529,16 +529,22 @@ } } +static void maybe_clear_bitmap_if_set(G1CMBitMap* bitmap, HeapWord* addr) { + if (bitmap->is_marked(addr)) { + bitmap->clear(addr); + } +} + void G1ConcurrentMark::humongous_object_eagerly_reclaimed(HeapRegion* r) { assert_at_safepoint_on_vm_thread(); - // Need to clear mark bit of the humongous object. - if (_next_mark_bitmap->is_marked(r->bottom())) { - _next_mark_bitmap->clear(r->bottom()); - } + // Need to clear all mark bits of the humongous object. + maybe_clear_bitmap_if_set(_prev_mark_bitmap, r->bottom()); - if (!_g1h->collector_state()->mark_or_rebuild_in_progress()) { - return; + G1CollectorState* collector_state = _g1h->collector_state(); + if (collector_state->mark_or_rebuild_in_progress() || + collector_state->clearing_next_bitmap()) { + maybe_clear_bitmap_if_set(_next_mark_bitmap, r->bottom()); } // Clear any statistics about the region gathered so far.