2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2013-12-24 11:48:39 -08:00
|
|
|
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
2008-06-05 15:57:56 -07:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2008-06-05 15:57:56 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_SPARSEPRT_HPP
|
|
|
|
#define SHARE_VM_GC_IMPLEMENTATION_G1_SPARSEPRT_HPP
|
|
|
|
|
|
|
|
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
|
|
|
|
#include "gc_implementation/g1/heapRegion.hpp"
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "memory/cardTableModRefBS.hpp"
|
|
|
|
#include "runtime/mutex.hpp"
|
|
|
|
#include "utilities/globalDefinitions.hpp"
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// Sparse remembered set for a heap region (the "owning" region). Maps
|
|
|
|
// indices of other regions to short sequences of cards in the other region
|
|
|
|
// that might contain pointers into the owner region.
|
|
|
|
|
|
|
|
// These tables only expand while they are accessed in parallel --
|
|
|
|
// deletions may be done in single-threaded code. This allows us to allow
|
|
|
|
// unsynchronized reads/iterations, as long as expansions caused by
|
|
|
|
// insertions only enqueue old versions for deletions, but do not delete
|
|
|
|
// old versions synchronously.
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class SparsePRTEntry: public CHeapObj<mtGC> {
|
2008-06-05 15:57:56 -07:00
|
|
|
public:
|
|
|
|
enum SomePublicConstants {
|
2010-02-11 15:52:19 -08:00
|
|
|
NullEntry = -1,
|
|
|
|
UnrollFactor = 4
|
2008-06-05 15:57:56 -07:00
|
|
|
};
|
|
|
|
private:
|
2009-06-11 17:19:33 -07:00
|
|
|
RegionIdx_t _region_ind;
|
|
|
|
int _next_index;
|
2010-02-11 15:52:19 -08:00
|
|
|
CardIdx_t _cards[1];
|
|
|
|
// WARNING: Don't put any data members beyond this line. Card array has, in fact, variable length.
|
|
|
|
// It should always be the last data member.
|
2008-06-05 15:57:56 -07:00
|
|
|
public:
|
2010-02-11 15:52:19 -08:00
|
|
|
// Returns the size of the entry, used for entry allocation.
|
|
|
|
static size_t size() { return sizeof(SparsePRTEntry) + sizeof(CardIdx_t) * (cards_num() - 1); }
|
|
|
|
// Returns the size of the card array.
|
|
|
|
static int cards_num() {
|
|
|
|
// The number of cards should be a multiple of 4, because that's our current
|
|
|
|
// unrolling factor.
|
|
|
|
static const int s = MAX2<int>(G1RSetSparseRegionEntries & ~(UnrollFactor - 1), UnrollFactor);
|
|
|
|
return s;
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Set the region_ind to the given value, and delete all cards.
|
2009-06-11 17:19:33 -07:00
|
|
|
inline void init(RegionIdx_t region_ind);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
RegionIdx_t r_ind() const { return _region_ind; }
|
2008-06-05 15:57:56 -07:00
|
|
|
bool valid_entry() const { return r_ind() >= 0; }
|
2009-06-11 17:19:33 -07:00
|
|
|
void set_r_ind(RegionIdx_t rind) { _region_ind = rind; }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
int next_index() const { return _next_index; }
|
|
|
|
int* next_index_addr() { return &_next_index; }
|
|
|
|
void set_next_index(int ni) { _next_index = ni; }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Returns "true" iff the entry contains the given card index.
|
2009-06-11 17:19:33 -07:00
|
|
|
inline bool contains_card(CardIdx_t card_index) const;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Returns the number of non-NULL card entries.
|
|
|
|
inline int num_valid_cards() const;
|
|
|
|
|
|
|
|
// Requires that the entry not contain the given card index. If there is
|
|
|
|
// space available, add the given card index to the entry and return
|
|
|
|
// "true"; otherwise, return "false" to indicate that the entry is full.
|
|
|
|
enum AddCardResult {
|
|
|
|
overflow,
|
|
|
|
found,
|
|
|
|
added
|
|
|
|
};
|
2009-06-11 17:19:33 -07:00
|
|
|
inline AddCardResult add_card(CardIdx_t card_index);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Copy the current entry's cards into "cards".
|
2009-06-11 17:19:33 -07:00
|
|
|
inline void copy_cards(CardIdx_t* cards) const;
|
2008-06-05 15:57:56 -07:00
|
|
|
// Copy the current entry's cards into the "_card" array of "e."
|
|
|
|
inline void copy_cards(SparsePRTEntry* e) const;
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
inline CardIdx_t card(int i) const { return _cards[i]; }
|
2008-06-05 15:57:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class RSHashTable : public CHeapObj<mtGC> {
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
friend class RSHashTableIter;
|
|
|
|
|
|
|
|
enum SomePrivateConstants {
|
|
|
|
NullEntry = -1
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t _capacity;
|
|
|
|
size_t _capacity_mask;
|
|
|
|
size_t _occupied_entries;
|
|
|
|
size_t _occupied_cards;
|
|
|
|
|
|
|
|
SparsePRTEntry* _entries;
|
2009-06-11 17:19:33 -07:00
|
|
|
int* _buckets;
|
|
|
|
int _free_region;
|
|
|
|
int _free_list;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Requires that the caller hold a lock preventing parallel modifying
|
|
|
|
// operations, and that the the table be less than completely full. If
|
|
|
|
// an entry for "region_ind" is already in the table, finds it and
|
|
|
|
// returns its address; otherwise returns "NULL."
|
2009-06-11 17:19:33 -07:00
|
|
|
SparsePRTEntry* entry_for_region_ind(RegionIdx_t region_ind) const;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Requires that the caller hold a lock preventing parallel modifying
|
|
|
|
// operations, and that the the table be less than completely full. If
|
|
|
|
// an entry for "region_ind" is already in the table, finds it and
|
|
|
|
// returns its address; otherwise allocates, initializes, inserts and
|
|
|
|
// returns a new entry for "region_ind".
|
2009-06-11 17:19:33 -07:00
|
|
|
SparsePRTEntry* entry_for_region_ind_create(RegionIdx_t region_ind);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Returns the index of the next free entry in "_entries".
|
2009-06-11 17:19:33 -07:00
|
|
|
int alloc_entry();
|
2008-06-05 15:57:56 -07:00
|
|
|
// Declares the entry "fi" to be free. (It must have already been
|
|
|
|
// deleted from any bucket lists.
|
2009-06-11 17:19:33 -07:00
|
|
|
void free_entry(int fi);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
RSHashTable(size_t capacity);
|
|
|
|
~RSHashTable();
|
|
|
|
|
|
|
|
// Attempts to ensure that the given card_index in the given region is in
|
|
|
|
// the sparse table. If successful (because the card was already
|
|
|
|
// present, or because it was successfullly added) returns "true".
|
|
|
|
// Otherwise, returns "false" to indicate that the addition would
|
|
|
|
// overflow the entry for the region. The caller must transfer these
|
|
|
|
// entries to a larger-capacity representation.
|
2009-06-11 17:19:33 -07:00
|
|
|
bool add_card(RegionIdx_t region_id, CardIdx_t card_index);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool get_cards(RegionIdx_t region_id, CardIdx_t* cards);
|
2010-02-11 15:52:19 -08:00
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool delete_entry(RegionIdx_t region_id);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool contains_card(RegionIdx_t region_id, CardIdx_t card_index) const;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
void add_entry(SparsePRTEntry* e);
|
|
|
|
|
2010-02-11 15:52:19 -08:00
|
|
|
SparsePRTEntry* get_entry(RegionIdx_t region_id);
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
size_t capacity() const { return _capacity; }
|
|
|
|
size_t capacity_mask() const { return _capacity_mask; }
|
|
|
|
size_t occupied_entries() const { return _occupied_entries; }
|
|
|
|
size_t occupied_cards() const { return _occupied_cards; }
|
|
|
|
size_t mem_size() const;
|
|
|
|
|
2010-02-11 15:52:19 -08:00
|
|
|
SparsePRTEntry* entry(int i) const { return (SparsePRTEntry*)((char*)_entries + SparsePRTEntry::size() * i); }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
void print();
|
|
|
|
};
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
// ValueObj because will be embedded in HRRS iterator.
|
2009-02-10 18:39:09 +03:00
|
|
|
class RSHashTableIter VALUE_OBJ_CLASS_SPEC {
|
2009-06-11 17:19:33 -07:00
|
|
|
int _tbl_ind; // [-1, 0.._rsht->_capacity)
|
|
|
|
int _bl_ind; // [-1, 0.._rsht->_capacity)
|
2010-02-11 15:52:19 -08:00
|
|
|
short _card_ind; // [0..SparsePRTEntry::cards_num())
|
2009-06-11 17:19:33 -07:00
|
|
|
RSHashTable* _rsht;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
// If the bucket list pointed to by _bl_ind contains a card, sets
|
|
|
|
// _bl_ind to the index of that entry, and returns the card.
|
|
|
|
// Otherwise, returns SparseEntry::NullEntry.
|
|
|
|
CardIdx_t find_first_card_in_list();
|
|
|
|
|
|
|
|
// Computes the proper card index for the card whose offset in the
|
|
|
|
// current region (as indicated by _bl_ind) is "ci".
|
|
|
|
// This is subject to errors when there is iteration concurrent with
|
|
|
|
// modification, but these errors should be benign.
|
|
|
|
size_t compute_card_ind(CardIdx_t ci);
|
|
|
|
|
|
|
|
public:
|
2013-04-18 10:09:23 -07:00
|
|
|
RSHashTableIter(RSHashTable* rsht) :
|
|
|
|
_tbl_ind(RSHashTable::NullEntry), // So that first increment gets to 0.
|
2009-06-11 17:19:33 -07:00
|
|
|
_bl_ind(RSHashTable::NullEntry),
|
2010-02-11 15:52:19 -08:00
|
|
|
_card_ind((SparsePRTEntry::cards_num() - 1)),
|
2013-04-18 10:09:23 -07:00
|
|
|
_rsht(rsht) {}
|
2009-06-11 17:19:33 -07:00
|
|
|
|
|
|
|
bool has_next(size_t& card_index);
|
|
|
|
};
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// Concurrent accesss to a SparsePRT must be serialized by some external
|
|
|
|
// mutex.
|
|
|
|
|
|
|
|
class SparsePRTIter;
|
2011-01-25 17:58:19 -05:00
|
|
|
class SparsePRTCleanupTask;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2009-02-10 18:39:09 +03:00
|
|
|
class SparsePRT VALUE_OBJ_CLASS_SPEC {
|
2011-01-25 17:58:19 -05:00
|
|
|
friend class SparsePRTCleanupTask;
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// Iterations are done on the _cur hash table, since they only need to
|
|
|
|
// see entries visible at the start of a collection pause.
|
|
|
|
// All other operations are done using the _next hash table.
|
|
|
|
RSHashTable* _cur;
|
|
|
|
RSHashTable* _next;
|
|
|
|
|
|
|
|
HeapRegion* _hr;
|
|
|
|
|
|
|
|
enum SomeAdditionalPrivateConstants {
|
|
|
|
InitialCapacity = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
void expand();
|
|
|
|
|
|
|
|
bool _expanded;
|
|
|
|
|
|
|
|
bool expanded() { return _expanded; }
|
|
|
|
void set_expanded(bool b) { _expanded = b; }
|
|
|
|
|
|
|
|
SparsePRT* _next_expanded;
|
|
|
|
|
|
|
|
SparsePRT* next_expanded() { return _next_expanded; }
|
|
|
|
void set_next_expanded(SparsePRT* nxt) { _next_expanded = nxt; }
|
|
|
|
|
2011-01-25 17:58:19 -05:00
|
|
|
bool should_be_on_expanded_list();
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
static SparsePRT* _head_expanded_list;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SparsePRT(HeapRegion* hr);
|
|
|
|
|
|
|
|
~SparsePRT();
|
|
|
|
|
|
|
|
size_t occupied() const { return _next->occupied_cards(); }
|
|
|
|
size_t mem_size() const;
|
|
|
|
|
|
|
|
// Attempts to ensure that the given card_index in the given region is in
|
|
|
|
// the sparse table. If successful (because the card was already
|
|
|
|
// present, or because it was successfullly added) returns "true".
|
|
|
|
// Otherwise, returns "false" to indicate that the addition would
|
|
|
|
// overflow the entry for the region. The caller must transfer these
|
|
|
|
// entries to a larger-capacity representation.
|
2009-06-11 17:19:33 -07:00
|
|
|
bool add_card(RegionIdx_t region_id, CardIdx_t card_index);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// If the table hold an entry for "region_ind", Copies its
|
|
|
|
// cards into "cards", which must be an array of length at least
|
2010-02-11 15:52:19 -08:00
|
|
|
// "SparePRTEntry::cards_num()", and returns "true"; otherwise,
|
|
|
|
// returns "false".
|
2009-06-11 17:19:33 -07:00
|
|
|
bool get_cards(RegionIdx_t region_ind, CardIdx_t* cards);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2010-02-11 15:52:19 -08:00
|
|
|
// Return the pointer to the entry associated with the given region.
|
|
|
|
SparsePRTEntry* get_entry(RegionIdx_t region_ind);
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// If there is an entry for "region_ind", removes it and return "true";
|
|
|
|
// otherwise returns "false."
|
2009-06-11 17:19:33 -07:00
|
|
|
bool delete_entry(RegionIdx_t region_ind);
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// Clear the table, and reinitialize to initial capacity.
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
// Ensure that "_cur" and "_next" point to the same table.
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
// Clean up all tables on the expanded list. Called single threaded.
|
|
|
|
static void cleanup_all();
|
2009-03-07 11:07:36 -05:00
|
|
|
RSHashTable* cur() const { return _cur; }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
static void add_to_expanded_list(SparsePRT* sprt);
|
|
|
|
static SparsePRT* get_from_expanded_list();
|
|
|
|
|
2011-01-25 17:58:19 -05:00
|
|
|
// The purpose of these three methods is to help the GC workers
|
|
|
|
// during the cleanup pause to recreate the expanded list, purging
|
|
|
|
// any tables from it that belong to regions that are freed during
|
|
|
|
// cleanup (if we don't purge those tables, there is a race that
|
|
|
|
// causes various crashes; see CR 7014261).
|
|
|
|
//
|
|
|
|
// We chose to recreate the expanded list, instead of purging
|
|
|
|
// entries from it by iterating over it, to avoid this serial phase
|
|
|
|
// at the end of the cleanup pause.
|
|
|
|
//
|
|
|
|
// The three methods below work as follows:
|
|
|
|
// * reset_for_cleanup_tasks() : Nulls the expanded list head at the
|
|
|
|
// start of the cleanup pause.
|
|
|
|
// * do_cleanup_work() : Called by the cleanup workers for every
|
|
|
|
// region that is not free / is being freed by the cleanup
|
|
|
|
// pause. It creates a list of expanded tables whose head / tail
|
|
|
|
// are on the thread-local SparsePRTCleanupTask object.
|
|
|
|
// * finish_cleanup_task() : Called by the cleanup workers after
|
|
|
|
// they complete their cleanup task. It adds the local list into
|
|
|
|
// the global expanded list. It assumes that the
|
|
|
|
// ParGCRareEvent_lock is being held to ensure MT-safety.
|
|
|
|
static void reset_for_cleanup_tasks();
|
|
|
|
void do_cleanup_work(SparsePRTCleanupTask* sprt_cleanup_task);
|
|
|
|
static void finish_cleanup_task(SparsePRTCleanupTask* sprt_cleanup_task);
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool contains_card(RegionIdx_t region_id, CardIdx_t card_index) const {
|
2008-06-05 15:57:56 -07:00
|
|
|
return _next->contains_card(region_id, card_index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-15 17:26:56 -04:00
|
|
|
class SparsePRTIter: public RSHashTableIter {
|
2008-06-05 15:57:56 -07:00
|
|
|
public:
|
2013-04-18 10:09:23 -07:00
|
|
|
SparsePRTIter(const SparsePRT* sprt) :
|
|
|
|
RSHashTableIter(sprt->cur()) {}
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
bool has_next(size_t& card_index) {
|
|
|
|
return RSHashTableIter::has_next(card_index);
|
|
|
|
}
|
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2011-01-25 17:58:19 -05:00
|
|
|
// This allows each worker during a cleanup pause to create a
|
|
|
|
// thread-local list of sparse tables that have been expanded and need
|
|
|
|
// to be processed at the beginning of the next GC pause. This lists
|
|
|
|
// are concatenated into the single expanded list at the end of the
|
|
|
|
// cleanup pause.
|
|
|
|
class SparsePRTCleanupTask VALUE_OBJ_CLASS_SPEC {
|
|
|
|
private:
|
|
|
|
SparsePRT* _head;
|
|
|
|
SparsePRT* _tail;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SparsePRTCleanupTask() : _head(NULL), _tail(NULL) { }
|
|
|
|
|
|
|
|
void add(SparsePRT* sprt);
|
|
|
|
SparsePRT* head() { return _head; }
|
|
|
|
SparsePRT* tail() { return _tail; }
|
|
|
|
};
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_SPARSEPRT_HPP
|