Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp
38920 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"26#include "gc_implementation/parallelScavenge/psParallelCompact.hpp"27#include "oops/oop.inline.hpp"28#include "runtime/os.hpp"29#include "utilities/bitMap.inline.hpp"30#include "services/memTracker.hpp"31#ifdef TARGET_OS_FAMILY_linux32# include "os_linux.inline.hpp"33#endif34#ifdef TARGET_OS_FAMILY_solaris35# include "os_solaris.inline.hpp"36#endif37#ifdef TARGET_OS_FAMILY_windows38# include "os_windows.inline.hpp"39#endif40#ifdef TARGET_OS_FAMILY_aix41# include "os_aix.inline.hpp"42#endif43#ifdef TARGET_OS_FAMILY_bsd44# include "os_bsd.inline.hpp"45#endif4647bool48ParMarkBitMap::initialize(MemRegion covered_region)49{50const idx_t bits = bits_required(covered_region);51// The bits will be divided evenly between two bitmaps; each of them should be52// an integral number of words.53assert(bits % (BitsPerWord * 2) == 0, "region size unaligned");5455const size_t words = bits / BitsPerWord;56const size_t raw_bytes = words * sizeof(idx_t);57const size_t page_sz = os::page_size_for_region_aligned(raw_bytes, 10);58const size_t granularity = os::vm_allocation_granularity();59_reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity));6061const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 :62MAX2(page_sz, granularity);63ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0);64os::trace_page_sizes("par bitmap", raw_bytes, raw_bytes, page_sz,65rs.base(), rs.size());6667MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);6869_virtual_space = new PSVirtualSpace(rs, page_sz);70if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) {71_region_start = covered_region.start();72_region_size = covered_region.word_size();73BitMap::bm_word_t* map = (BitMap::bm_word_t*)_virtual_space->reserved_low_addr();74_beg_bits.set_map(map);75_beg_bits.set_size(bits / 2);76_end_bits.set_map(map + words / 2);77_end_bits.set_size(bits / 2);78return true;79}8081_region_start = 0;82_region_size = 0;83if (_virtual_space != NULL) {84delete _virtual_space;85_virtual_space = NULL;86// Release memory reserved in the space.87rs.release();88}89return false;90}9192#ifdef ASSERT93extern size_t mark_bitmap_count;94extern size_t mark_bitmap_size;95#endif // #ifdef ASSERT9697bool98ParMarkBitMap::mark_obj(HeapWord* addr, size_t size)99{100const idx_t beg_bit = addr_to_bit(addr);101if (_beg_bits.par_set_bit(beg_bit)) {102const idx_t end_bit = addr_to_bit(addr + size - 1);103bool end_bit_ok = _end_bits.par_set_bit(end_bit);104assert(end_bit_ok, "concurrency problem");105DEBUG_ONLY(Atomic::inc_ptr(&mark_bitmap_count));106DEBUG_ONLY(Atomic::add_ptr(size, &mark_bitmap_size));107return true;108}109return false;110}111112size_t ParMarkBitMap::live_words_in_range(HeapWord* beg_addr, oop end_obj) const113{114assert(beg_addr <= (HeapWord*)end_obj, "bad range");115assert(is_marked(end_obj), "end_obj must be live");116117idx_t live_bits = 0;118119// The bitmap routines require the right boundary to be word-aligned.120const idx_t end_bit = addr_to_bit((HeapWord*)end_obj);121const idx_t range_end = BitMap::word_align_up(end_bit);122123idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end);124while (beg_bit < end_bit) {125idx_t tmp_end = find_obj_end(beg_bit, range_end);126assert(tmp_end < end_bit, "missing end bit");127live_bits += tmp_end - beg_bit + 1;128beg_bit = find_obj_beg(tmp_end + 1, range_end);129}130return bits_to_words(live_bits);131}132133ParMarkBitMap::IterationStatus134ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,135idx_t range_beg, idx_t range_end) const136{137DEBUG_ONLY(verify_bit(range_beg);)138DEBUG_ONLY(verify_bit(range_end);)139assert(range_beg <= range_end, "live range invalid");140141// The bitmap routines require the right boundary to be word-aligned.142const idx_t search_end = BitMap::word_align_up(range_end);143144idx_t cur_beg = find_obj_beg(range_beg, search_end);145while (cur_beg < range_end) {146const idx_t cur_end = find_obj_end(cur_beg, search_end);147if (cur_end >= range_end) {148// The obj ends outside the range.149live_closure->set_source(bit_to_addr(cur_beg));150return incomplete;151}152153const size_t size = obj_size(cur_beg, cur_end);154IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);155if (status != incomplete) {156assert(status == would_overflow || status == full, "sanity");157return status;158}159160// Successfully processed the object; look for the next object.161cur_beg = find_obj_beg(cur_end + 1, search_end);162}163164live_closure->set_source(bit_to_addr(range_end));165return complete;166}167168ParMarkBitMap::IterationStatus169ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,170ParMarkBitMapClosure* dead_closure,171idx_t range_beg, idx_t range_end,172idx_t dead_range_end) const173{174DEBUG_ONLY(verify_bit(range_beg);)175DEBUG_ONLY(verify_bit(range_end);)176DEBUG_ONLY(verify_bit(dead_range_end);)177assert(range_beg <= range_end, "live range invalid");178assert(range_end <= dead_range_end, "dead range invalid");179180// The bitmap routines require the right boundary to be word-aligned.181const idx_t live_search_end = BitMap::word_align_up(range_end);182const idx_t dead_search_end = BitMap::word_align_up(dead_range_end);183184idx_t cur_beg = range_beg;185if (range_beg < range_end && is_unmarked(range_beg)) {186// The range starts with dead space. Look for the next object, then fill.187cur_beg = find_obj_beg(range_beg + 1, dead_search_end);188const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);189const size_t size = obj_size(range_beg, dead_space_end);190dead_closure->do_addr(bit_to_addr(range_beg), size);191}192193while (cur_beg < range_end) {194const idx_t cur_end = find_obj_end(cur_beg, live_search_end);195if (cur_end >= range_end) {196// The obj ends outside the range.197live_closure->set_source(bit_to_addr(cur_beg));198return incomplete;199}200201const size_t size = obj_size(cur_beg, cur_end);202IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);203if (status != incomplete) {204assert(status == would_overflow || status == full, "sanity");205return status;206}207208// Look for the start of the next object.209const idx_t dead_space_beg = cur_end + 1;210cur_beg = find_obj_beg(dead_space_beg, dead_search_end);211if (cur_beg > dead_space_beg) {212// Found dead space; compute the size and invoke the dead closure.213const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);214const size_t size = obj_size(dead_space_beg, dead_space_end);215dead_closure->do_addr(bit_to_addr(dead_space_beg), size);216}217}218219live_closure->set_source(bit_to_addr(range_end));220return complete;221}222223#ifdef ASSERT224void ParMarkBitMap::verify_clear() const225{226const idx_t* const beg = (const idx_t*)_virtual_space->committed_low_addr();227const idx_t* const end = (const idx_t*)_virtual_space->committed_high_addr();228for (const idx_t* p = beg; p < end; ++p) {229assert(*p == 0, "bitmap not clear");230}231}232#endif // #ifdef ASSERT233234235