Path: blob/master/src/hotspot/share/gc/parallel/parMarkBitMap.hpp
41152 views
/*1* Copyright (c) 2005, 2019, 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_GC_PARALLEL_PARMARKBITMAP_HPP25#define SHARE_GC_PARALLEL_PARMARKBITMAP_HPP2627#include "memory/memRegion.hpp"28#include "oops/oop.hpp"29#include "utilities/bitMap.hpp"3031class ParMarkBitMapClosure;32class PSVirtualSpace;33class ParCompactionManager;3435class ParMarkBitMap: public CHeapObj<mtGC>36{37public:38typedef BitMap::idx_t idx_t;3940// Values returned by the iterate() methods.41enum IterationStatus { incomplete, complete, full, would_overflow };4243inline ParMarkBitMap();44bool initialize(MemRegion covered_region);4546// Atomically mark an object as live.47bool mark_obj(HeapWord* addr, size_t size);48inline bool mark_obj(oop obj, int size);4950// Return whether the specified begin or end bit is set.51inline bool is_obj_beg(idx_t bit) const;52inline bool is_obj_end(idx_t bit) const;5354// Traditional interface for testing whether an object is marked or not (these55// test only the begin bits).56inline bool is_marked(idx_t bit) const;57inline bool is_marked(HeapWord* addr) const;58inline bool is_marked(oop obj) const;5960inline bool is_unmarked(idx_t bit) const;61inline bool is_unmarked(HeapWord* addr) const;62inline bool is_unmarked(oop obj) const;6364// Convert sizes from bits to HeapWords and back. An object that is n bits65// long will be bits_to_words(n) words long. An object that is m words long66// will take up words_to_bits(m) bits in the bitmap.67inline static size_t bits_to_words(idx_t bits);68inline static idx_t words_to_bits(size_t words);6970// Return the size in words of an object given a begin bit and an end bit, or71// the equivalent beg_addr and end_addr.72inline size_t obj_size(idx_t beg_bit, idx_t end_bit) const;73inline size_t obj_size(HeapWord* beg_addr, HeapWord* end_addr) const;7475// Return the size in words of the object (a search is done for the end bit).76inline size_t obj_size(idx_t beg_bit) const;77inline size_t obj_size(HeapWord* addr) const;7879// Apply live_closure to each live object that lies completely within the80// range [live_range_beg, live_range_end). This is used to iterate over the81// compacted region of the heap. Return values:82//83// incomplete The iteration is not complete. The last object that84// begins in the range does not end in the range;85// closure->source() is set to the start of that object.86//87// complete The iteration is complete. All objects in the range88// were processed and the closure is not full;89// closure->source() is set one past the end of the range.90//91// full The closure is full; closure->source() is set to one92// past the end of the last object processed.93//94// would_overflow The next object in the range would overflow the closure;95// closure->source() is set to the start of that object.96IterationStatus iterate(ParMarkBitMapClosure* live_closure,97idx_t range_beg, idx_t range_end) const;98inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,99HeapWord* range_beg,100HeapWord* range_end) const;101102// Apply live closure as above and additionally apply dead_closure to all dead103// space in the range [range_beg, dead_range_end). Note that dead_range_end104// must be >= range_end. This is used to iterate over the dense prefix.105//106// This method assumes that if the first bit in the range (range_beg) is not107// marked, then dead space begins at that point and the dead_closure is108// applied. Thus callers must ensure that range_beg is not in the middle of a109// live object.110IterationStatus iterate(ParMarkBitMapClosure* live_closure,111ParMarkBitMapClosure* dead_closure,112idx_t range_beg, idx_t range_end,113idx_t dead_range_end) const;114inline IterationStatus iterate(ParMarkBitMapClosure* live_closure,115ParMarkBitMapClosure* dead_closure,116HeapWord* range_beg,117HeapWord* range_end,118HeapWord* dead_range_end) const;119120// Return the number of live words in the range [beg_addr, end_obj) due to121// objects that start in the range. If a live object extends onto the range,122// the caller must detect and account for any live words due to that object.123// If a live object extends beyond the end of the range, only the words within124// the range are included in the result. The end of the range must be a live object,125// which is the case when updating pointers. This allows a branch to be removed126// from inside the loop.127size_t live_words_in_range(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const;128129inline HeapWord* region_start() const;130inline HeapWord* region_end() const;131inline size_t region_size() const;132inline size_t size() const;133134size_t reserved_byte_size() const { return _reserved_byte_size; }135136// Convert a heap address to/from a bit index.137inline idx_t addr_to_bit(HeapWord* addr) const;138inline HeapWord* bit_to_addr(idx_t bit) const;139140// Return word-aligned up range_end, which must not be greater than size().141inline idx_t align_range_end(idx_t range_end) const;142143// Return the bit index of the first marked object that begins (or ends,144// respectively) in the range [beg, end). If no object is found, return end.145// end must be word-aligned.146inline idx_t find_obj_beg(idx_t beg, idx_t end) const;147inline idx_t find_obj_end(idx_t beg, idx_t end) const;148149inline HeapWord* find_obj_beg(HeapWord* beg, HeapWord* end) const;150inline HeapWord* find_obj_end(HeapWord* beg, HeapWord* end) const;151152// Clear a range of bits or the entire bitmap (both begin and end bits are153// cleared).154inline void clear_range(idx_t beg, idx_t end);155156// Return the number of bits required to represent the specified number of157// HeapWords, or the specified region.158static inline idx_t bits_required(size_t words);159static inline idx_t bits_required(MemRegion covered_region);160161void print_on_error(outputStream* st) const {162st->print_cr("Marking Bits: (ParMarkBitMap*) " PTR_FORMAT, p2i(this));163_beg_bits.print_on_error(st, " Begin Bits: ");164_end_bits.print_on_error(st, " End Bits: ");165}166167#ifdef ASSERT168void verify_clear() const;169inline void verify_bit(idx_t bit) const;170inline void verify_addr(HeapWord* addr) const;171#endif // #ifdef ASSERT172173private:174size_t live_words_in_range_helper(HeapWord* beg_addr, oop end_obj) const;175176bool is_live_words_in_range_in_cache(ParCompactionManager* cm, HeapWord* beg_addr) const;177size_t live_words_in_range_use_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj) const;178void update_live_words_in_range_cache(ParCompactionManager* cm, HeapWord* beg_addr, oop end_obj, size_t result) const;179180// Each bit in the bitmap represents one unit of 'object granularity.' Objects181// are double-word aligned in 32-bit VMs, but not in 64-bit VMs, so the 32-bit182// granularity is 2, 64-bit is 1.183static inline size_t obj_granularity() { return size_t(MinObjAlignment); }184static inline int obj_granularity_shift() { return LogMinObjAlignment; }185186HeapWord* _region_start;187size_t _region_size;188BitMapView _beg_bits;189BitMapView _end_bits;190PSVirtualSpace* _virtual_space;191size_t _reserved_byte_size;192};193194#endif // SHARE_GC_PARALLEL_PARMARKBITMAP_HPP195196197