/*
* 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/g1CollectedHeap.inline.hpp"
#include "gc_implementation/g1/heapRegion.hpp"
#include "memory/allocation.hpp"
#include "memory/cardTableModRefBS.hpp"
#include "utilities/globalDefinitions.hpp"
// 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.
public:
enum SomePublicConstants {
};
private:
int _next_index;
// 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.
public:
// Returns the size of the entry, used for entry allocation.
// 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.
return s;
}
// Set the region_ind to the given value, and delete all cards.
// Returns "true" iff the entry contains the given card index.
// 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 {
};
// Copy the current entry's cards into "cards".
// Copy the current entry's cards into the "_card" array of "e."
inline void copy_cards(SparsePRTEntry* e) const;
};
friend class RSHashTableIter;
enum SomePrivateConstants {
};
int* _buckets;
int _free_region;
int _free_list;
// 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."
// 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".
// Returns the index of the next free entry in "_entries".
int alloc_entry();
// Declares the entry "fi" to be free. (It must have already been
// deleted from any bucket lists.
void free_entry(int fi);
public:
~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.
void add_entry(SparsePRTEntry* e);
void clear();
SparsePRTEntry* entry(int i) const { return (SparsePRTEntry*)((char*)_entries + SparsePRTEntry::size() * i); }
void print();
};
// ValueObj because will be embedded in HRRS iterator.
// 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.
// 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.
public:
RSHashTableIter() :
}
};
// Concurrent accesss to a SparsePRT must be serialized by some external
// mutex.
class SparsePRTIter;
class SparsePRTCleanupTask;
friend class SparsePRTCleanupTask;
// 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.
};
void expand();
bool _expanded;
bool should_be_on_expanded_list();
public:
~SparsePRT();
// 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.
// If the table hold an entry for "region_ind", Copies its
// cards into "cards", which must be an array of length at least
// "SparePRTEntry::cards_num()", and returns "true"; otherwise,
// returns "false".
// Return the pointer to the entry associated with the given region.
// If there is an entry for "region_ind", removes it and return "true";
// otherwise returns "false."
// 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();
static SparsePRT* get_from_expanded_list();
// 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();
}
};
public:
}
}
};
// 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.
private:
public:
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_SPARSEPRT_HPP