Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.hpp
38921 views
/*1* Copyright (c) 2005, 2014, 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#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP25#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP2627#include "memory/memRegion.hpp"28#include "oops/oop.hpp"29#include "utilities/bitMap.hpp"3031class ParMarkBitMapClosure;32class PSVirtualSpace;3334class ParMarkBitMap: public CHeapObj<mtGC>35{36public:37typedef BitMap::idx_t idx_t;3839// Values returned by the iterate() methods.40enum IterationStatus { incomplete, complete, full, would_overflow };4142inline ParMarkBitMap();43bool initialize(MemRegion covered_region);4445// Atomically mark an object as live.46bool mark_obj(HeapWord* addr, size_t size);47inline bool mark_obj(oop obj, int size);4849// Return whether the specified begin or end bit is set.50inline bool is_obj_beg(idx_t bit) const;51inline bool is_obj_end(idx_t bit) const;5253// Traditional interface for testing whether an object is marked or not (these54// test only the begin bits).55inline bool is_marked(idx_t bit) const;56inline bool is_marked(HeapWord* addr) const;57inline bool is_marked(oop obj) const;5859inline bool is_unmarked(idx_t bit) const;60inline bool is_unmarked(HeapWord* addr) const;61inline bool is_unmarked(oop obj) const;6263// Convert sizes from bits to HeapWords and back. An object that is n bits64// long will be bits_to_words(n) words long. An object that is m words long65// will take up words_to_bits(m) bits in the bitmap.66inline static size_t bits_to_words(idx_t bits);67inline static idx_t words_to_bits(size_t words);6869// Return the size in words of an object given a begin bit and an end bit, or70// the equivalent beg_addr and end_addr.71inline size_t obj_size(idx_t beg_bit, idx_t end_bit) const;72inline size_t obj_size(HeapWord* beg_addr, HeapWord* end_addr) const;7374// Return the size in words of the object (a search is done for the end bit).75inline size_t obj_size(idx_t beg_bit) const;76inline size_t obj_size(HeapWord* addr) const;7778// Apply live_closure to each live object that lies completely within the79// range [live_range_beg, live_range_end). This is used to iterate over the80// compacted region of the heap. Return values:81//82// incomplete The iteration is not complete. The last object that83// begins in the range does not end in the range;84// closure->source() is set to the start of that object.85//86// complete The iteration is complete. All objects in the range87// were processed and the closure is not full;88// closure->source() is set one past the end of the range.89//90// full The closure is full; closure->source() is set to one91// past the end of the last object processed.92//93// would_overflow The next object in the range would overflow the closure;94// closure->source() is set to the start of that object.95IterationStatus iterate(ParMarkBitMapClosure* live_closure,96idx_t range_beg, idx_t range_end) const;97inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,98HeapWord* range_beg,99HeapWord* range_end) const;100101// Apply live closure as above and additionally apply dead_closure to all dead102// space in the range [range_beg, dead_range_end). Note that dead_range_end103// must be >= range_end. This is used to iterate over the dense prefix.104//105// This method assumes that if the first bit in the range (range_beg) is not106// marked, then dead space begins at that point and the dead_closure is107// applied. Thus callers must ensure that range_beg is not in the middle of a108// live object.109IterationStatus iterate(ParMarkBitMapClosure* live_closure,110ParMarkBitMapClosure* dead_closure,111idx_t range_beg, idx_t range_end,112idx_t dead_range_end) const;113inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,114ParMarkBitMapClosure* dead_closure,115HeapWord* range_beg,116HeapWord* range_end,117HeapWord* dead_range_end) const;118119// Return the number of live words in the range [beg_addr, end_obj) due to120// objects that start in the range. If a live object extends onto the range,121// the caller must detect and account for any live words due to that object.122// If a live object extends beyond the end of the range, only the words within123// the range are included in the result. The end of the range must be a live object,124// which is the case when updating pointers. This allows a branch to be removed125// from inside the loop.126size_t live_words_in_range(HeapWord* beg_addr, oop end_obj) const;127128inline HeapWord* region_start() const;129inline HeapWord* region_end() const;130inline size_t region_size() const;131inline size_t size() const;132133size_t reserved_byte_size() const { return _reserved_byte_size; }134135// Convert a heap address to/from a bit index.136inline idx_t addr_to_bit(HeapWord* addr) const;137inline HeapWord* bit_to_addr(idx_t bit) const;138139// Return the bit index of the first marked object that begins (or ends,140// respectively) in the range [beg, end). If no object is found, return end.141inline idx_t find_obj_beg(idx_t beg, idx_t end) const;142inline idx_t find_obj_end(idx_t beg, idx_t end) const;143144inline HeapWord* find_obj_beg(HeapWord* beg, HeapWord* end) const;145inline HeapWord* find_obj_end(HeapWord* beg, HeapWord* end) const;146147// Clear a range of bits or the entire bitmap (both begin and end bits are148// cleared).149inline void clear_range(idx_t beg, idx_t end);150151// Return the number of bits required to represent the specified number of152// HeapWords, or the specified region.153static inline idx_t bits_required(size_t words);154static inline idx_t bits_required(MemRegion covered_region);155156void print_on_error(outputStream* st) const {157st->print_cr("Marking Bits: (ParMarkBitMap*) " PTR_FORMAT, p2i(this));158_beg_bits.print_on_error(st, " Begin Bits: ");159_end_bits.print_on_error(st, " End Bits: ");160}161162#ifdef ASSERT163void verify_clear() const;164inline void verify_bit(idx_t bit) const;165inline void verify_addr(HeapWord* addr) const;166#endif // #ifdef ASSERT167168private:169// Each bit in the bitmap represents one unit of 'object granularity.' Objects170// are double-word aligned in 32-bit VMs, but not in 64-bit VMs, so the 32-bit171// granularity is 2, 64-bit is 1.172static inline size_t obj_granularity() { return size_t(MinObjAlignment); }173static inline int obj_granularity_shift() { return LogMinObjAlignment; }174175HeapWord* _region_start;176size_t _region_size;177BitMap _beg_bits;178BitMap _end_bits;179PSVirtualSpace* _virtual_space;180size_t _reserved_byte_size;181};182183inline ParMarkBitMap::ParMarkBitMap():184_beg_bits(), _end_bits(), _region_start(NULL), _region_size(0), _virtual_space(NULL), _reserved_byte_size(0)185{ }186187inline void ParMarkBitMap::clear_range(idx_t beg, idx_t end)188{189_beg_bits.clear_range(beg, end);190_end_bits.clear_range(beg, end);191}192193inline ParMarkBitMap::idx_t194ParMarkBitMap::bits_required(size_t words)195{196// Need two bits (one begin bit, one end bit) for each unit of 'object197// granularity' in the heap.198return words_to_bits(words * 2);199}200201inline ParMarkBitMap::idx_t202ParMarkBitMap::bits_required(MemRegion covered_region)203{204return bits_required(covered_region.word_size());205}206207inline HeapWord*208ParMarkBitMap::region_start() const209{210return _region_start;211}212213inline HeapWord*214ParMarkBitMap::region_end() const215{216return region_start() + region_size();217}218219inline size_t220ParMarkBitMap::region_size() const221{222return _region_size;223}224225inline size_t226ParMarkBitMap::size() const227{228return _beg_bits.size();229}230231inline bool ParMarkBitMap::is_obj_beg(idx_t bit) const232{233return _beg_bits.at(bit);234}235236inline bool ParMarkBitMap::is_obj_end(idx_t bit) const237{238return _end_bits.at(bit);239}240241inline bool ParMarkBitMap::is_marked(idx_t bit) const242{243return is_obj_beg(bit);244}245246inline bool ParMarkBitMap::is_marked(HeapWord* addr) const247{248return is_marked(addr_to_bit(addr));249}250251inline bool ParMarkBitMap::is_marked(oop obj) const252{253return is_marked((HeapWord*)obj);254}255256inline bool ParMarkBitMap::is_unmarked(idx_t bit) const257{258return !is_marked(bit);259}260261inline bool ParMarkBitMap::is_unmarked(HeapWord* addr) const262{263return !is_marked(addr);264}265266inline bool ParMarkBitMap::is_unmarked(oop obj) const267{268return !is_marked(obj);269}270271inline size_t272ParMarkBitMap::bits_to_words(idx_t bits)273{274return bits << obj_granularity_shift();275}276277inline ParMarkBitMap::idx_t278ParMarkBitMap::words_to_bits(size_t words)279{280return words >> obj_granularity_shift();281}282283inline size_t ParMarkBitMap::obj_size(idx_t beg_bit, idx_t end_bit) const284{285DEBUG_ONLY(verify_bit(beg_bit);)286DEBUG_ONLY(verify_bit(end_bit);)287return bits_to_words(end_bit - beg_bit + 1);288}289290inline size_t291ParMarkBitMap::obj_size(HeapWord* beg_addr, HeapWord* end_addr) const292{293DEBUG_ONLY(verify_addr(beg_addr);)294DEBUG_ONLY(verify_addr(end_addr);)295return pointer_delta(end_addr, beg_addr) + obj_granularity();296}297298inline size_t ParMarkBitMap::obj_size(idx_t beg_bit) const299{300const idx_t end_bit = _end_bits.get_next_one_offset_inline(beg_bit, size());301assert(is_marked(beg_bit), "obj not marked");302assert(end_bit < size(), "end bit missing");303return obj_size(beg_bit, end_bit);304}305306inline size_t ParMarkBitMap::obj_size(HeapWord* addr) const307{308return obj_size(addr_to_bit(addr));309}310311inline ParMarkBitMap::IterationStatus312ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,313HeapWord* range_beg,314HeapWord* range_end) const315{316return iterate(live_closure, addr_to_bit(range_beg), addr_to_bit(range_end));317}318319inline ParMarkBitMap::IterationStatus320ParMarkBitMap::iterate(ParMarkBitMapClosure* live_closure,321ParMarkBitMapClosure* dead_closure,322HeapWord* range_beg,323HeapWord* range_end,324HeapWord* dead_range_end) const325{326return iterate(live_closure, dead_closure,327addr_to_bit(range_beg), addr_to_bit(range_end),328addr_to_bit(dead_range_end));329}330331inline bool332ParMarkBitMap::mark_obj(oop obj, int size)333{334return mark_obj((HeapWord*)obj, (size_t)size);335}336337inline BitMap::idx_t338ParMarkBitMap::addr_to_bit(HeapWord* addr) const339{340DEBUG_ONLY(verify_addr(addr);)341return words_to_bits(pointer_delta(addr, region_start()));342}343344inline HeapWord*345ParMarkBitMap::bit_to_addr(idx_t bit) const346{347DEBUG_ONLY(verify_bit(bit);)348return region_start() + bits_to_words(bit);349}350351inline ParMarkBitMap::idx_t352ParMarkBitMap::find_obj_beg(idx_t beg, idx_t end) const353{354return _beg_bits.get_next_one_offset_inline_aligned_right(beg, end);355}356357inline ParMarkBitMap::idx_t358ParMarkBitMap::find_obj_end(idx_t beg, idx_t end) const359{360return _end_bits.get_next_one_offset_inline_aligned_right(beg, end);361}362363inline HeapWord*364ParMarkBitMap::find_obj_beg(HeapWord* beg, HeapWord* end) const365{366const idx_t beg_bit = addr_to_bit(beg);367const idx_t end_bit = addr_to_bit(end);368const idx_t search_end = BitMap::word_align_up(end_bit);369const idx_t res_bit = MIN2(find_obj_beg(beg_bit, search_end), end_bit);370return bit_to_addr(res_bit);371}372373inline HeapWord*374ParMarkBitMap::find_obj_end(HeapWord* beg, HeapWord* end) const375{376const idx_t beg_bit = addr_to_bit(beg);377const idx_t end_bit = addr_to_bit(end);378const idx_t search_end = BitMap::word_align_up(end_bit);379const idx_t res_bit = MIN2(find_obj_end(beg_bit, search_end), end_bit);380return bit_to_addr(res_bit);381}382383#ifdef ASSERT384inline void ParMarkBitMap::verify_bit(idx_t bit) const {385// Allow one past the last valid bit; useful for loop bounds.386assert(bit <= _beg_bits.size(), "bit out of range");387}388389inline void ParMarkBitMap::verify_addr(HeapWord* addr) const {390// Allow one past the last valid address; useful for loop bounds.391assert(addr >= region_start(),392err_msg("addr too small, addr: " PTR_FORMAT " region start: " PTR_FORMAT, p2i(addr), p2i(region_start())));393assert(addr <= region_end(),394err_msg("addr too big, addr: " PTR_FORMAT " region end: " PTR_FORMAT, p2i(addr), p2i(region_end())));395}396#endif // #ifdef ASSERT397398#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARMARKBITMAP_HPP399400401