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#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP
1879N/A
1890N/A#include "memory/memRegion.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psVirtualspace.hpp"
1879N/A#include "utilities/bitMap.inline.hpp"
1879N/A
0N/Aclass oopDesc;
0N/Aclass ParMarkBitMapClosure;
0N/A
3863N/Aclass ParMarkBitMap: public CHeapObj<mtGC>
0N/A{
0N/Apublic:
0N/A typedef BitMap::idx_t idx_t;
0N/A
0N/A // Values returned by the iterate() methods.
0N/A enum IterationStatus { incomplete, complete, full, would_overflow };
0N/A
0N/A inline ParMarkBitMap();
0N/A inline ParMarkBitMap(MemRegion covered_region);
0N/A bool initialize(MemRegion covered_region);
0N/A
0N/A // Atomically mark an object as live.
0N/A bool mark_obj(HeapWord* addr, size_t size);
0N/A inline bool mark_obj(oop obj, int size);
0N/A inline bool mark_obj(oop obj);
0N/A
0N/A // Return whether the specified begin or end bit is set.
0N/A inline bool is_obj_beg(idx_t bit) const;
0N/A inline bool is_obj_end(idx_t bit) const;
0N/A
0N/A // Traditional interface for testing whether an object is marked or not (these
0N/A // test only the begin bits).
0N/A inline bool is_marked(idx_t bit) const;
0N/A inline bool is_marked(HeapWord* addr) const;
0N/A inline bool is_marked(oop obj) const;
0N/A
0N/A inline bool is_unmarked(idx_t bit) const;
0N/A inline bool is_unmarked(HeapWord* addr) const;
0N/A inline bool is_unmarked(oop obj) const;
0N/A
0N/A // Convert sizes from bits to HeapWords and back. An object that is n bits
0N/A // long will be bits_to_words(n) words long. An object that is m words long
0N/A // will take up words_to_bits(m) bits in the bitmap.
0N/A inline static size_t bits_to_words(idx_t bits);
0N/A inline static idx_t words_to_bits(size_t words);
0N/A
0N/A // Return the size in words of an object given a begin bit and an end bit, or
0N/A // the equivalent beg_addr and end_addr.
0N/A inline size_t obj_size(idx_t beg_bit, idx_t end_bit) const;
0N/A inline size_t obj_size(HeapWord* beg_addr, HeapWord* end_addr) const;
0N/A
0N/A // Return the size in words of the object (a search is done for the end bit).
0N/A inline size_t obj_size(idx_t beg_bit) const;
0N/A inline size_t obj_size(HeapWord* addr) const;
0N/A inline size_t obj_size(oop obj) const;
0N/A
0N/A // Synonyms for the above.
0N/A size_t obj_size_in_words(oop obj) const { return obj_size((HeapWord*)obj); }
0N/A size_t obj_size_in_words(HeapWord* addr) const { return obj_size(addr); }
0N/A
0N/A // Apply live_closure to each live object that lies completely within the
0N/A // range [live_range_beg, live_range_end). This is used to iterate over the
0N/A // compacted region of the heap. Return values:
0N/A //
0N/A // incomplete The iteration is not complete. The last object that
0N/A // begins in the range does not end in the range;
0N/A // closure->source() is set to the start of that object.
0N/A //
0N/A // complete The iteration is complete. All objects in the range
0N/A // were processed and the closure is not full;
0N/A // closure->source() is set one past the end of the range.
0N/A //
0N/A // full The closure is full; closure->source() is set to one
0N/A // past the end of the last object processed.
0N/A //
0N/A // would_overflow The next object in the range would overflow the closure;
0N/A // closure->source() is set to the start of that object.
0N/A IterationStatus iterate(ParMarkBitMapClosure* live_closure,
0N/A idx_t range_beg, idx_t range_end) const;
0N/A inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,
0N/A HeapWord* range_beg,
0N/A HeapWord* range_end) const;
0N/A
0N/A // Apply live closure as above and additionally apply dead_closure to all dead
0N/A // space in the range [range_beg, dead_range_end). Note that dead_range_end
0N/A // must be >= range_end. This is used to iterate over the dense prefix.
0N/A //
0N/A // This method assumes that if the first bit in the range (range_beg) is not
0N/A // marked, then dead space begins at that point and the dead_closure is
0N/A // applied. Thus callers must ensure that range_beg is not in the middle of a
0N/A // live object.
0N/A IterationStatus 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 inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,
0N/A ParMarkBitMapClosure* dead_closure,
0N/A HeapWord* range_beg,
0N/A HeapWord* range_end,
0N/A HeapWord* dead_range_end) const;
0N/A
0N/A // Return the number of live words in the range [beg_addr, end_addr) due to
0N/A // objects that start in the range. If a live object extends onto the range,
0N/A // the caller must detect and account for any live words due to that object.
0N/A // If a live object extends beyond the end of the range, only the words within
0N/A // the range are included in the result.
0N/A size_t live_words_in_range(HeapWord* beg_addr, HeapWord* end_addr) const;
0N/A
0N/A // Same as the above, except the end of the range must be a live object, which
0N/A // is the case when updating pointers. This allows a branch to be removed
0N/A // from inside the loop.
0N/A size_t live_words_in_range(HeapWord* beg_addr, oop end_obj) const;
0N/A
0N/A inline HeapWord* region_start() const;
0N/A inline HeapWord* region_end() const;
0N/A inline size_t region_size() const;
0N/A inline size_t size() const;
0N/A
4550N/A size_t reserved_byte_size() const { return _reserved_byte_size; }
4550N/A
0N/A // Convert a heap address to/from a bit index.
0N/A inline idx_t addr_to_bit(HeapWord* addr) const;
0N/A inline HeapWord* bit_to_addr(idx_t bit) const;
0N/A
0N/A // Return the bit index of the first marked object that begins (or ends,
0N/A // respectively) in the range [beg, end). If no object is found, return end.
0N/A inline idx_t find_obj_beg(idx_t beg, idx_t end) const;
0N/A inline idx_t find_obj_end(idx_t beg, idx_t end) const;
0N/A
0N/A inline HeapWord* find_obj_beg(HeapWord* beg, HeapWord* end) const;
0N/A inline HeapWord* find_obj_end(HeapWord* beg, HeapWord* end) const;
0N/A
0N/A // Clear a range of bits or the entire bitmap (both begin and end bits are
0N/A // cleared).
0N/A inline void clear_range(idx_t beg, idx_t end);
0N/A inline void clear() { clear_range(0, size()); }
0N/A
0N/A // Return the number of bits required to represent the specified number of
0N/A // HeapWords, or the specified region.
0N/A static inline idx_t bits_required(size_t words);
0N/A static inline idx_t bits_required(MemRegion covered_region);
0N/A static inline idx_t words_required(MemRegion covered_region);
0N/A
0N/A#ifndef PRODUCT
0N/A // CAS statistics.
0N/A size_t cas_tries() { return _cas_tries; }
0N/A size_t cas_retries() { return _cas_retries; }
0N/A size_t cas_by_another() { return _cas_by_another; }
0N/A
0N/A void reset_counters();
0N/A#endif // #ifndef PRODUCT
0N/A
0N/A#ifdef ASSERT
0N/A void verify_clear() const;
0N/A inline void verify_bit(idx_t bit) const;
0N/A inline void verify_addr(HeapWord* addr) const;
0N/A#endif // #ifdef ASSERT
0N/A
0N/Aprivate:
0N/A // Each bit in the bitmap represents one unit of 'object granularity.' Objects
0N/A // are double-word aligned in 32-bit VMs, but not in 64-bit VMs, so the 32-bit
0N/A // granularity is 2, 64-bit is 1.
0N/A static inline size_t obj_granularity() { return size_t(MinObjAlignment); }
808N/A static inline int obj_granularity_shift() { return LogMinObjAlignment; }
0N/A
0N/A HeapWord* _region_start;
0N/A size_t _region_size;
0N/A BitMap _beg_bits;
0N/A BitMap _end_bits;
0N/A PSVirtualSpace* _virtual_space;
4550N/A size_t _reserved_byte_size;
0N/A
0N/A#ifndef PRODUCT
0N/A size_t _cas_tries;
0N/A size_t _cas_retries;
0N/A size_t _cas_by_another;
0N/A#endif // #ifndef PRODUCT
0N/A};
0N/A
0N/Ainline ParMarkBitMap::ParMarkBitMap():
342N/A _beg_bits(),
342N/A _end_bits()
0N/A{
0N/A _region_start = 0;
0N/A _virtual_space = 0;
4550N/A _reserved_byte_size = 0;
0N/A}
0N/A
0N/Ainline ParMarkBitMap::ParMarkBitMap(MemRegion covered_region):
342N/A _beg_bits(),
342N/A _end_bits()
0N/A{
0N/A initialize(covered_region);
0N/A}
0N/A
0N/Ainline void ParMarkBitMap::clear_range(idx_t beg, idx_t end)
0N/A{
0N/A _beg_bits.clear_range(beg, end);
0N/A _end_bits.clear_range(beg, end);
0N/A}
0N/A
0N/Ainline ParMarkBitMap::idx_t
0N/AParMarkBitMap::bits_required(size_t words)
0N/A{
0N/A // Need two bits (one begin bit, one end bit) for each unit of 'object
0N/A // granularity' in the heap.
0N/A return words_to_bits(words * 2);
0N/A}
0N/A
0N/Ainline ParMarkBitMap::idx_t
0N/AParMarkBitMap::bits_required(MemRegion covered_region)
0N/A{
0N/A return bits_required(covered_region.word_size());
0N/A}
0N/A
0N/Ainline ParMarkBitMap::idx_t
0N/AParMarkBitMap::words_required(MemRegion covered_region)
0N/A{
0N/A return bits_required(covered_region) / BitsPerWord;
0N/A}
0N/A
0N/Ainline HeapWord*
0N/AParMarkBitMap::region_start() const
0N/A{
0N/A return _region_start;
0N/A}
0N/A
0N/Ainline HeapWord*
0N/AParMarkBitMap::region_end() const
0N/A{
0N/A return region_start() + region_size();
0N/A}
0N/A
0N/Ainline size_t
0N/AParMarkBitMap::region_size() const
0N/A{
0N/A return _region_size;
0N/A}
0N/A
0N/Ainline size_t
0N/AParMarkBitMap::size() const
0N/A{
0N/A return _beg_bits.size();
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_obj_beg(idx_t bit) const
0N/A{
0N/A return _beg_bits.at(bit);
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_obj_end(idx_t bit) const
0N/A{
0N/A return _end_bits.at(bit);
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_marked(idx_t bit) const
0N/A{
0N/A return is_obj_beg(bit);
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_marked(HeapWord* addr) const
0N/A{
0N/A return is_marked(addr_to_bit(addr));
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_marked(oop obj) const
0N/A{
0N/A return is_marked((HeapWord*)obj);
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_unmarked(idx_t bit) const
0N/A{
0N/A return !is_marked(bit);
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_unmarked(HeapWord* addr) const
0N/A{
0N/A return !is_marked(addr);
0N/A}
0N/A
0N/Ainline bool ParMarkBitMap::is_unmarked(oop obj) const
0N/A{
0N/A return !is_marked(obj);
0N/A}
0N/A
0N/Ainline size_t
0N/AParMarkBitMap::bits_to_words(idx_t bits)
0N/A{
808N/A return bits << obj_granularity_shift();
0N/A}
0N/A
0N/Ainline ParMarkBitMap::idx_t
0N/AParMarkBitMap::words_to_bits(size_t words)
0N/A{
808N/A return words >> obj_granularity_shift();
0N/A}
0N/A
0N/Ainline size_t ParMarkBitMap::obj_size(idx_t beg_bit, idx_t end_bit) const
0N/A{
0N/A DEBUG_ONLY(verify_bit(beg_bit);)
0N/A DEBUG_ONLY(verify_bit(end_bit);)
0N/A return bits_to_words(end_bit - beg_bit + 1);
0N/A}
0N/A
0N/Ainline size_t
0N/AParMarkBitMap::obj_size(HeapWord* beg_addr, HeapWord* end_addr) const
0N/A{
0N/A DEBUG_ONLY(verify_addr(beg_addr);)
0N/A DEBUG_ONLY(verify_addr(end_addr);)
0N/A return pointer_delta(end_addr, beg_addr) + obj_granularity();
0N/A}
0N/A
0N/Ainline size_t ParMarkBitMap::obj_size(idx_t beg_bit) const
0N/A{
342N/A const idx_t end_bit = _end_bits.get_next_one_offset_inline(beg_bit, size());
0N/A assert(is_marked(beg_bit), "obj not marked");
0N/A assert(end_bit < size(), "end bit missing");
0N/A return obj_size(beg_bit, end_bit);
0N/A}
0N/A
0N/Ainline size_t ParMarkBitMap::obj_size(HeapWord* addr) const
0N/A{
0N/A return obj_size(addr_to_bit(addr));
0N/A}
0N/A
0N/Ainline size_t ParMarkBitMap::obj_size(oop obj) const
0N/A{
0N/A return obj_size((HeapWord*)obj);
0N/A}
0N/A
0N/Ainline ParMarkBitMap::IterationStatus
0N/AParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
0N/A HeapWord* range_beg,
0N/A HeapWord* range_end) const
0N/A{
0N/A return iterate(live_closure, addr_to_bit(range_beg), addr_to_bit(range_end));
0N/A}
0N/A
0N/Ainline ParMarkBitMap::IterationStatus
0N/AParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,
0N/A ParMarkBitMapClosure* dead_closure,
0N/A HeapWord* range_beg,
0N/A HeapWord* range_end,
0N/A HeapWord* dead_range_end) const
0N/A{
0N/A return iterate(live_closure, dead_closure,
0N/A addr_to_bit(range_beg), addr_to_bit(range_end),
0N/A addr_to_bit(dead_range_end));
0N/A}
0N/A
0N/Ainline bool
0N/AParMarkBitMap::mark_obj(oop obj, int size)
0N/A{
0N/A return mark_obj((HeapWord*)obj, (size_t)size);
0N/A}
0N/A
0N/Ainline BitMap::idx_t
0N/AParMarkBitMap::addr_to_bit(HeapWord* addr) const
0N/A{
0N/A DEBUG_ONLY(verify_addr(addr);)
0N/A return words_to_bits(pointer_delta(addr, region_start()));
0N/A}
0N/A
0N/Ainline HeapWord*
0N/AParMarkBitMap::bit_to_addr(idx_t bit) const
0N/A{
0N/A DEBUG_ONLY(verify_bit(bit);)
0N/A return region_start() + bits_to_words(bit);
0N/A}
0N/A
0N/Ainline ParMarkBitMap::idx_t
0N/AParMarkBitMap::find_obj_beg(idx_t beg, idx_t end) const
0N/A{
342N/A return _beg_bits.get_next_one_offset_inline_aligned_right(beg, end);
0N/A}
0N/A
0N/Ainline ParMarkBitMap::idx_t
0N/AParMarkBitMap::find_obj_end(idx_t beg, idx_t end) const
0N/A{
342N/A return _end_bits.get_next_one_offset_inline_aligned_right(beg, end);
0N/A}
0N/A
0N/Ainline HeapWord*
0N/AParMarkBitMap::find_obj_beg(HeapWord* beg, HeapWord* end) const
0N/A{
0N/A const idx_t beg_bit = addr_to_bit(beg);
0N/A const idx_t end_bit = addr_to_bit(end);
0N/A const idx_t search_end = BitMap::word_align_up(end_bit);
0N/A const idx_t res_bit = MIN2(find_obj_beg(beg_bit, search_end), end_bit);
0N/A return bit_to_addr(res_bit);
0N/A}
0N/A
0N/Ainline HeapWord*
0N/AParMarkBitMap::find_obj_end(HeapWord* beg, HeapWord* end) const
0N/A{
0N/A const idx_t beg_bit = addr_to_bit(beg);
0N/A const idx_t end_bit = addr_to_bit(end);
0N/A const idx_t search_end = BitMap::word_align_up(end_bit);
0N/A const idx_t res_bit = MIN2(find_obj_end(beg_bit, search_end), end_bit);
0N/A return bit_to_addr(res_bit);
0N/A}
0N/A
0N/A#ifdef ASSERT
0N/Ainline void ParMarkBitMap::verify_bit(idx_t bit) const {
0N/A // Allow one past the last valid bit; useful for loop bounds.
0N/A assert(bit <= _beg_bits.size(), "bit out of range");
0N/A}
0N/A
0N/Ainline void ParMarkBitMap::verify_addr(HeapWord* addr) const {
0N/A // Allow one past the last valid address; useful for loop bounds.
0N/A assert(addr >= region_start(), "addr too small");
0N/A assert(addr <= region_start() + region_size(), "addr too big");
0N/A}
0N/A#endif // #ifdef ASSERT
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP