/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "gc_implementation/g1/sparsePRT.hpp"
// Remembered set for a heap region. Represent a set of "cards" that
// contain pointers into the owner heap region. Cards are defined somewhat
// abstractly, in terms of what the "BlockOffsetTable" in use can parse.
class G1CollectedHeap;
class G1BlockOffsetSharedArray;
class HeapRegion;
class HeapRegionRemSetIterator;
class PerRegionTable;
class SparsePRT;
// Essentially a wrapper around SparsePRTCleanupTask. See
// sparsePRT.hpp for more details.
};
// The "_coarse_map" is a bitmap with one bit for each region, where set
// bits indicate that the corresponding region may contain some pointer
// into the owning region.
// The "_fine_grain_entries" array is an open hash table of PerRegionTables
// (PRTs), indicating regions for which we're keeping the RS as a set of
// cards. The strategy is to cap the size of the fine-grain table,
// deleting an entry and setting the corresponding coarse-grained bit when
// we would overflow this cap.
// We use a mixture of locking and lock-free techniques here. We allow
// threads to locate PRTs without locking, but threads attempting to alter
// a bucket list obtain a lock. This means that any failing attempt to
// find a PRT must be retried with the lock. It might seem dangerous that
// a read can find a PRT that is concurrently deleted. This is all right,
// because:
//
// 1) We only actually free PRT's at safe points (though we reuse them at
// other times).
// 2) We find PRT's in an attempt to add entries. If a PRT is deleted,
// it's _coarse_map bit is set, so the that we were attempting to add
// is represented. If a deleted PRT is re-used, a thread adding a bit,
// thinking the PRT is for a different region, does no harm.
friend class HeapRegionRemSetIterator;
// These are protected by "_m".
// The fine grain remembered sets are doubly linked together using
// their 'next' and 'prev' fields.
// This allows fast bulk freeing of all the fine grain remembered
// set entries, and fast finding of all of them without iterating
// over the _fine_grain_regions table.
// Used to sample a subset of the fine grain PRTs to determine which
// PRT to evict and coarsen.
// These are static after init.
// Requires "prt" to be the first element of the bucket list appropriate
// for "hr". If this list contains an entry for "hr", return it,
// otherwise return "NULL".
// Find, delete, and return a candidate PerRegionTable, if any exists,
// adding the deleted region to the coarse bitmap. Requires the caller
// to hold _m, and the fine-grain table to be full.
// If a PRT for "hr" is in the bucket list indicated by "ind" (which must
// be the correct index for "hr"), delete it and return true; else return
// false.
// Indexed by thread X heap region, to minimize thread contention.
static int** _from_card_cache;
public:
// For now. Could "expand" some tables in the future, so that this made
// sense.
// Removes any entries shown by the given bitmaps to contain only dead
// objects.
// Not const because it takes a lock.
size_t occ_coarse() const;
size_t occ_sparse() const;
// Returns size in bytes.
// Not const because it takes a lock.
static size_t static_mem_size();
static size_t fl_mem_size();
void clear();
// Specifically clear the from_card_cache.
void clear_fcc();
// "from_hr" is being cleared; remove any entries from it.
// Declare the heap size (in # of regions) to the OtherRegionsTable.
// (Uses it to initialize from_card_cache).
// Declares that only regions i s.t. 0 <= i < new_n_regs are in use.
// Make sure any entries for higher regions are invalid.
static void print_from_card_cache();
};
friend class VMStructs;
friend class HeapRegionRemSetIterator;
public:
enum Event {
};
private:
// Unused unless G1RecordHRRSOops is true.
static int _n_recorded;
static int* _recorded_event_index;
static int _n_recorded_events;
public:
HeapRegion* hr);
static int num_par_rem_sets();
static void setup_remset_size();
return _other_regions.hr();
}
return _other_regions.occupied();
}
return _other_regions.occ_fine();
}
return _other_regions.occ_coarse();
}
return _other_regions.occ_sparse();
}
// Used in the sequential case.
}
// Used in the parallel case.
}
// Removes any entries shown by the given bitmaps to contain only dead
// objects.
// The region is being reclaimed; clear its remset, and any mention of
// entries for this region in other remsets.
void clear();
// Attempt to claim the region. Returns true iff this call caused an
// atomic transition from Unclaimed to Claimed.
bool claim_iter();
// Sets the iteration state to "complete".
void set_iter_complete();
// Returns "true" iff the region's iteration is complete.
bool iter_is_complete();
// Support for claiming blocks of cards during iteration
// Claim the next block of cards
do {
current = iter_claimed();
return current;
}
void reset_for_par_iteration();
bool verify_ready_for_par_iteration() {
}
// Initialize the given iterator to iterate over this rem set.
// The actual # of bytes this hr_remset takes up.
return _other_regions.mem_size()
// This correction is necessary because the above includes the second
// part.
+ sizeof(this) - sizeof(OtherRegionsTable);
}
// Returns the memory occupancy of all static data structures associated
// with remembered sets.
return OtherRegionsTable::static_mem_size();
}
// Returns the memory occupancy of all free_list data structures associated
// with remembered sets.
return OtherRegionsTable::fl_mem_size();
}
}
void print() const;
// Called during a stop-world phase to perform any deferred cleanups.
static void cleanup();
// Declare the heap size (in # of regions) to the HeapRegionRemSet(s).
// (Uses it to initialize from_card_cache).
}
// Declares that only regions i s.t. 0 <= i < new_n_regs are in use.
}
#ifndef PRODUCT
static void print_from_card_cache() {
}
#endif
static void print_recorded();
// These are wrappers for the similarly-named methods on
// SparsePRT. Look at sparsePRT.hpp for more details.
static void reset_for_cleanup_tasks();
// Run unit tests.
#ifndef PRODUCT
static void test();
#endif
};
// The region over which we're iterating.
// Local caching of HRRS fields.
// The number yielded since initialization.
// If true we're iterating over the coarse table; if false the fine
// table.
enum IterState {
Fine,
};
// In both kinds of iteration, heap offset of first card of current
// region.
// Card offset within cur region.
// Coarse table iteration fields:
// Current region index;
// Fine table iteration fields:
// Index of bucket-list we're working on.
int _fine_array_index;
// Per Region Table we're doing within current bucket list.
void fine_find_next_non_null_prt();
bool fine_has_next();
public:
// We require an iterator to be initialized before use, so the
// constructor does little.
// If there remains one or more cards to be yielded, returns true and
// sets "card_index" to one of those cards (which is then considered
// yielded.) Otherwise, returns false (and leaves "card_index"
// undefined.)
}
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONREMSET_HPP