0N/A/*
1879N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"
1879N/A#include "gc_implementation/parallelScavenge/parMarkBitMap.inline.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psParallelCompact.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#include "utilities/bitMap.inline.hpp"
3863N/A#include "services/memTracker.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "os_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "os_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "os_windows.inline.hpp"
1879N/A#endif
2796N/A#ifdef TARGET_OS_FAMILY_bsd
2796N/A# include "os_bsd.inline.hpp"
2796N/A#endif
0N/A
0N/Abool
0N/AParMarkBitMap::initialize(MemRegion covered_region)
0N/A{
0N/A const idx_t bits = bits_required(covered_region);
0N/A // The bits will be divided evenly between two bitmaps; each of them should be
0N/A // an integral number of words.
0N/A assert(bits % (BitsPerWord * 2) == 0, "region size unaligned");
0N/A
0N/A const size_t words = bits / BitsPerWord;
0N/A const size_t raw_bytes = words * sizeof(idx_t);
0N/A const size_t page_sz = os::page_size_for_region(raw_bytes, raw_bytes, 10);
0N/A const size_t granularity = os::vm_allocation_granularity();
4550N/A _reserved_byte_size = align_size_up(raw_bytes, MAX2(page_sz, granularity));
0N/A
0N/A const size_t rs_align = page_sz == (size_t) os::vm_page_size() ? 0 :
0N/A MAX2(page_sz, granularity);
4550N/A ReservedSpace rs(_reserved_byte_size, rs_align, rs_align > 0);
0N/A os::trace_page_sizes("par bitmap", raw_bytes, raw_bytes, page_sz,
0N/A rs.base(), rs.size());
3863N/A
3863N/A MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
3863N/A
0N/A _virtual_space = new PSVirtualSpace(rs, page_sz);
4550N/A if (_virtual_space != NULL && _virtual_space->expand_by(_reserved_byte_size)) {
0N/A _region_start = covered_region.start();
0N/A _region_size = covered_region.word_size();
0N/A idx_t* map = (idx_t*)_virtual_space->reserved_low_addr();
0N/A _beg_bits.set_map(map);
0N/A _beg_bits.set_size(bits / 2);
0N/A _end_bits.set_map(map + words / 2);
0N/A _end_bits.set_size(bits / 2);
0N/A return true;
0N/A }
0N/A
0N/A _region_start = 0;
0N/A _region_size = 0;
0N/A if (_virtual_space != NULL) {
0N/A delete _virtual_space;
0N/A _virtual_space = NULL;
237N/A // Release memory reserved in the space.
237N/A rs.release();
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/Aextern size_t mark_bitmap_count;
0N/Aextern size_t mark_bitmap_size;
0N/A#endif // #ifdef ASSERT
0N/A
0N/Abool
0N/AParMarkBitMap::mark_obj(HeapWord* addr, size_t size)
0N/A{
0N/A const idx_t beg_bit = addr_to_bit(addr);
0N/A if (_beg_bits.par_set_bit(beg_bit)) {
0N/A const idx_t end_bit = addr_to_bit(addr + size - 1);
0N/A bool end_bit_ok = _end_bits.par_set_bit(end_bit);
0N/A assert(end_bit_ok, "concurrency problem");
0N/A DEBUG_ONLY(Atomic::inc_ptr(&mark_bitmap_count));
0N/A DEBUG_ONLY(Atomic::add_ptr(size, &mark_bitmap_size));
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
0N/Asize_t
0N/AParMarkBitMap::live_words_in_range(HeapWord* beg_addr, HeapWord* end_addr) const
0N/A{
0N/A assert(beg_addr <= end_addr, "bad range");
0N/A
0N/A idx_t live_bits = 0;
0N/A
0N/A // The bitmap routines require the right boundary to be word-aligned.
0N/A const idx_t end_bit = addr_to_bit(end_addr);
0N/A const idx_t range_end = BitMap::word_align_up(end_bit);
0N/A
0N/A idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end);
0N/A while (beg_bit < end_bit) {
0N/A idx_t tmp_end = find_obj_end(beg_bit, range_end);
0N/A if (tmp_end < end_bit) {
0N/A live_bits += tmp_end - beg_bit + 1;
0N/A beg_bit = find_obj_beg(tmp_end + 1, range_end);
0N/A } else {
0N/A live_bits += end_bit - beg_bit; // No + 1 here; end_bit is not counted.
0N/A return bits_to_words(live_bits);
0N/A }
0N/A }
0N/A return bits_to_words(live_bits);
0N/A}
0N/A
0N/Asize_t ParMarkBitMap::live_words_in_range(HeapWord* beg_addr, oop end_obj) const
0N/A{
0N/A assert(beg_addr <= (HeapWord*)end_obj, "bad range");
0N/A assert(is_marked(end_obj), "end_obj must be live");
0N/A
0N/A idx_t live_bits = 0;
0N/A
0N/A // The bitmap routines require the right boundary to be word-aligned.
0N/A const idx_t end_bit = addr_to_bit((HeapWord*)end_obj);
0N/A const idx_t range_end = BitMap::word_align_up(end_bit);
0N/A
0N/A idx_t beg_bit = find_obj_beg(addr_to_bit(beg_addr), range_end);
0N/A while (beg_bit < end_bit) {
0N/A idx_t tmp_end = find_obj_end(beg_bit, range_end);
0N/A assert(tmp_end < end_bit, "missing end bit");
0N/A live_bits += tmp_end - beg_bit + 1;
0N/A beg_bit = find_obj_beg(tmp_end + 1, range_end);
0N/A }
0N/A return bits_to_words(live_bits);
0N/A}
0N/A
0N/AParMarkBitMap::IterationStatus
0N/AParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
0N/A idx_t range_beg, idx_t range_end) const
0N/A{
0N/A DEBUG_ONLY(verify_bit(range_beg);)
0N/A DEBUG_ONLY(verify_bit(range_end);)
0N/A assert(range_beg <= range_end, "live range invalid");
0N/A
0N/A // The bitmap routines require the right boundary to be word-aligned.
0N/A const idx_t search_end = BitMap::word_align_up(range_end);
0N/A
0N/A idx_t cur_beg = find_obj_beg(range_beg, search_end);
0N/A while (cur_beg < range_end) {
0N/A const idx_t cur_end = find_obj_end(cur_beg, search_end);
0N/A if (cur_end >= range_end) {
0N/A // The obj ends outside the range.
0N/A live_closure->set_source(bit_to_addr(cur_beg));
0N/A return incomplete;
0N/A }
0N/A
0N/A const size_t size = obj_size(cur_beg, cur_end);
0N/A IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
0N/A if (status != incomplete) {
0N/A assert(status == would_overflow || status == full, "sanity");
0N/A return status;
0N/A }
0N/A
0N/A // Successfully processed the object; look for the next object.
0N/A cur_beg = find_obj_beg(cur_end + 1, search_end);
0N/A }
0N/A
0N/A live_closure->set_source(bit_to_addr(range_end));
0N/A return complete;
0N/A}
0N/A
0N/AParMarkBitMap::IterationStatus
0N/AParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
0N/A ParMarkBitMapClosure* dead_closure,
0N/A idx_t range_beg, idx_t range_end,
0N/A idx_t dead_range_end) const
0N/A{
0N/A DEBUG_ONLY(verify_bit(range_beg);)
0N/A DEBUG_ONLY(verify_bit(range_end);)
0N/A DEBUG_ONLY(verify_bit(dead_range_end);)
0N/A assert(range_beg <= range_end, "live range invalid");
0N/A assert(range_end <= dead_range_end, "dead range invalid");
0N/A
0N/A // The bitmap routines require the right boundary to be word-aligned.
0N/A const idx_t live_search_end = BitMap::word_align_up(range_end);
0N/A const idx_t dead_search_end = BitMap::word_align_up(dead_range_end);
0N/A
0N/A idx_t cur_beg = range_beg;
0N/A if (range_beg < range_end && is_unmarked(range_beg)) {
0N/A // The range starts with dead space. Look for the next object, then fill.
0N/A cur_beg = find_obj_beg(range_beg + 1, dead_search_end);
0N/A const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);
0N/A const size_t size = obj_size(range_beg, dead_space_end);
0N/A dead_closure->do_addr(bit_to_addr(range_beg), size);
0N/A }
0N/A
0N/A while (cur_beg < range_end) {
0N/A const idx_t cur_end = find_obj_end(cur_beg, live_search_end);
0N/A if (cur_end >= range_end) {
0N/A // The obj ends outside the range.
0N/A live_closure->set_source(bit_to_addr(cur_beg));
0N/A return incomplete;
0N/A }
0N/A
0N/A const size_t size = obj_size(cur_beg, cur_end);
0N/A IterationStatus status = live_closure->do_addr(bit_to_addr(cur_beg), size);
0N/A if (status != incomplete) {
0N/A assert(status == would_overflow || status == full, "sanity");
0N/A return status;
0N/A }
0N/A
0N/A // Look for the start of the next object.
0N/A const idx_t dead_space_beg = cur_end + 1;
0N/A cur_beg = find_obj_beg(dead_space_beg, dead_search_end);
0N/A if (cur_beg > dead_space_beg) {
0N/A // Found dead space; compute the size and invoke the dead closure.
0N/A const idx_t dead_space_end = MIN2(cur_beg - 1, dead_range_end - 1);
0N/A const size_t size = obj_size(dead_space_beg, dead_space_end);
0N/A dead_closure->do_addr(bit_to_addr(dead_space_beg), size);
0N/A }
0N/A }
0N/A
0N/A live_closure->set_source(bit_to_addr(range_end));
0N/A return complete;
0N/A}
0N/A
0N/A#ifndef PRODUCT
0N/Avoid ParMarkBitMap::reset_counters()
0N/A{
0N/A _cas_tries = _cas_retries = _cas_by_another = 0;
0N/A}
0N/A#endif // #ifndef PRODUCT
0N/A
0N/A#ifdef ASSERT
0N/Avoid ParMarkBitMap::verify_clear() const
0N/A{
0N/A const idx_t* const beg = (const idx_t*)_virtual_space->committed_low_addr();
0N/A const idx_t* const end = (const idx_t*)_virtual_space->committed_high_addr();
0N/A for (const idx_t* p = beg; p < end; ++p) {
0N/A assert(*p == 0, "bitmap not clear");
0N/A }
0N/A}
0N/A#endif // #ifdef ASSERT