2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2019-01-10 15:13:51 -05:00
|
|
|
* Copyright (c) 2001, 2019, 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_GC_G1_SPARSEPRT_HPP
|
|
|
|
#define SHARE_GC_G1_SPARSEPRT_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/g1CollectedHeap.hpp"
|
|
|
|
#include "gc/g1/heapRegion.hpp"
|
2018-03-19 07:38:18 +01:00
|
|
|
#include "gc/shared/cardTableBarrierSet.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "runtime/mutex.hpp"
|
2017-07-05 11:33:17 +02:00
|
|
|
#include "utilities/align.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#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.
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class SparsePRTEntry: public CHeapObj<mtGC> {
|
2008-06-05 15:57:56 -07:00
|
|
|
private:
|
2016-05-10 16:42:14 +02:00
|
|
|
// The type of a card entry.
|
|
|
|
typedef uint16_t card_elem_t;
|
|
|
|
|
|
|
|
// We need to make sizeof(SparsePRTEntry) an even multiple of maximum member size,
|
|
|
|
// in order to force correct alignment that could otherwise cause SIGBUS errors
|
|
|
|
// when reading the member variables. This calculates the minimum number of card
|
|
|
|
// array elements required to get that alignment.
|
|
|
|
static const size_t card_array_alignment = sizeof(int) / sizeof(card_elem_t);
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
RegionIdx_t _region_ind;
|
|
|
|
int _next_index;
|
2016-05-10 16:42:14 +02:00
|
|
|
int _next_null;
|
|
|
|
// The actual cards stored in this array.
|
2010-02-11 15:52:19 -08:00
|
|
|
// 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.
|
2016-05-10 16:42:14 +02:00
|
|
|
card_elem_t _cards[card_array_alignment];
|
|
|
|
|
|
|
|
// Copy the current entry's cards into "cards".
|
|
|
|
inline void copy_cards(card_elem_t* cards) const;
|
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.
|
2016-05-10 16:42:14 +02:00
|
|
|
static size_t size() { return sizeof(SparsePRTEntry) + sizeof(card_elem_t) * (cards_num() - card_array_alignment); }
|
2010-02-11 15:52:19 -08:00
|
|
|
// Returns the size of the card array.
|
|
|
|
static int cards_num() {
|
2017-04-13 09:57:51 +02:00
|
|
|
return align_up((int)G1RSetSparseRegionEntries, (int)card_array_alignment);
|
2010-02-11 15:52:19 -08:00
|
|
|
}
|
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.
|
2016-05-10 16:42:14 +02:00
|
|
|
inline int num_valid_cards() const { return _next_null; }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
// 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 the "_card" array of "e."
|
|
|
|
inline void copy_cards(SparsePRTEntry* e) const;
|
|
|
|
|
2016-05-10 16:42:14 +02:00
|
|
|
inline CardIdx_t card(int i) const {
|
|
|
|
assert(i >= 0, "must be nonnegative");
|
|
|
|
assert(i < cards_num(), "range checking");
|
|
|
|
return (CardIdx_t)_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;
|
|
|
|
|
|
|
|
|
2016-05-10 16:40:09 +02:00
|
|
|
// Inverse maximum hash table occupancy used.
|
|
|
|
static float TableOccupancyFactor;
|
|
|
|
|
|
|
|
size_t _num_entries;
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
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 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();
|
|
|
|
|
2016-05-10 16:42:14 +02:00
|
|
|
static const int NullEntry = -1;
|
|
|
|
|
2016-05-10 16:40:09 +02:00
|
|
|
bool should_expand() const { return _occupied_entries == _num_entries; }
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
// Attempts to ensure that the given card_index in the given region is in
|
|
|
|
// the sparse table. If successful (because the card was already
|
2014-01-23 14:47:23 +01:00
|
|
|
// present, or because it was successfully added) returns "true".
|
2008-06-05 15:57:56 -07:00
|
|
|
// 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 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);
|
|
|
|
|
2014-05-08 10:29:17 +02:00
|
|
|
SparsePRTEntry* get_entry(RegionIdx_t region_id) const;
|
2010-02-11 15:52:19 -08:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
void clear();
|
|
|
|
|
2016-05-10 16:42:14 +02:00
|
|
|
size_t capacity() const { return _capacity; }
|
2008-06-05 15:57:56 -07:00
|
|
|
size_t capacity_mask() const { return _capacity_mask; }
|
|
|
|
size_t occupied_entries() const { return _occupied_entries; }
|
2016-05-10 16:42:14 +02:00
|
|
|
size_t occupied_cards() const { return _occupied_cards; }
|
2008-06-05 15:57:56 -07:00
|
|
|
size_t mem_size() const;
|
2016-05-10 16:40:09 +02:00
|
|
|
// The number of SparsePRTEntry instances available.
|
|
|
|
size_t num_entries() const { return _num_entries; }
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2016-05-10 16:40:09 +02:00
|
|
|
SparsePRTEntry* entry(int i) const {
|
|
|
|
assert(i >= 0 && (size_t)i < _num_entries, "precondition");
|
|
|
|
return (SparsePRTEntry*)((char*)_entries + SparsePRTEntry::size() * i);
|
|
|
|
}
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
void print();
|
|
|
|
};
|
|
|
|
|
2018-03-14 07:27:19 -04:00
|
|
|
// This is embedded in HRRS iterator.
|
|
|
|
class RSHashTableIter {
|
2016-05-10 16:42:14 +02:00
|
|
|
// Return value indicating "invalid/no card".
|
|
|
|
static const int NoCardFound = -1;
|
|
|
|
|
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
|
2016-05-10 16:42:14 +02:00
|
|
|
// _bl_ind to the index of that entry,
|
|
|
|
// Returns the card found if there is, otherwise returns InvalidCard.
|
2009-06-11 17:19:33 -07:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Concurrent access to a SparsePRT must be serialized by some external mutex.
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
class SparsePRTIter;
|
|
|
|
|
2018-03-14 07:27:19 -04:00
|
|
|
class SparsePRT {
|
2018-11-28 11:06:58 +01:00
|
|
|
friend class SparsePRTIter;
|
2011-01-25 17:58:19 -05:00
|
|
|
|
2018-11-28 11:06:58 +01:00
|
|
|
RSHashTable* _table;
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
enum SomeAdditionalPrivateConstants {
|
|
|
|
InitialCapacity = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
void expand();
|
|
|
|
|
|
|
|
public:
|
2018-10-31 13:43:57 +01:00
|
|
|
SparsePRT();
|
2008-06-05 15:57:56 -07:00
|
|
|
~SparsePRT();
|
|
|
|
|
2018-11-28 11:06:58 +01:00
|
|
|
size_t occupied() const { return _table->occupied_cards(); }
|
2008-06-05 15:57:56 -07:00
|
|
|
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
|
2014-01-23 14:47:23 +01:00
|
|
|
// present, or because it was successfully added) returns "true".
|
2008-06-05 15:57:56 -07:00
|
|
|
// 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
|
|
|
|
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();
|
|
|
|
|
2009-06-11 17:19:33 -07:00
|
|
|
bool contains_card(RegionIdx_t region_id, CardIdx_t card_index) const {
|
2018-11-28 11:06:58 +01:00
|
|
|
return _table->contains_card(region_id, card_index);
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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) :
|
2018-11-28 11:06:58 +01:00
|
|
|
RSHashTableIter(sprt->_table) { }
|
2013-04-18 10:09:23 -07:00
|
|
|
|
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
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_GC_G1_SPARSEPRT_HPP
|