src/hotspot/share/gc/g1/sparsePRT.hpp
changeset 55510 3e31a8beaae4
parent 55148 0dab93cb3b0c
child 58679 9c3209ff7550
equal deleted inserted replaced
55509:d58442b8abc1 55510:3e31a8beaae4
    36 // Sparse remembered set for a heap region (the "owning" region).  Maps
    36 // Sparse remembered set for a heap region (the "owning" region).  Maps
    37 // indices of other regions to short sequences of cards in the other region
    37 // indices of other regions to short sequences of cards in the other region
    38 // that might contain pointers into the owner region.
    38 // that might contain pointers into the owner region.
    39 
    39 
    40 class SparsePRTEntry: public CHeapObj<mtGC> {
    40 class SparsePRTEntry: public CHeapObj<mtGC> {
    41 private:
    41 public:
    42   // The type of a card entry.
    42   // The type of a card entry.
    43   typedef uint16_t card_elem_t;
    43   typedef uint16_t card_elem_t;
    44 
    44 
       
    45 private:
    45   // We need to make sizeof(SparsePRTEntry) an even multiple of maximum member size,
    46   // We need to make sizeof(SparsePRTEntry) an even multiple of maximum member size,
    46   // in order to force correct alignment that could otherwise cause SIGBUS errors
    47   // in order to force correct alignment that could otherwise cause SIGBUS errors
    47   // when reading the member variables. This calculates the minimum number of card
    48   // when reading the member variables. This calculates the minimum number of card
    48   // array elements required to get that alignment.
    49   // array elements required to get that alignment.
    49   static const size_t card_array_alignment = sizeof(int) / sizeof(card_elem_t);
    50   static const size_t card_array_alignment = sizeof(int) / sizeof(card_elem_t);
    94   inline AddCardResult add_card(CardIdx_t card_index);
    95   inline AddCardResult add_card(CardIdx_t card_index);
    95 
    96 
    96   // Copy the current entry's cards into the "_card" array of "e."
    97   // Copy the current entry's cards into the "_card" array of "e."
    97   inline void copy_cards(SparsePRTEntry* e) const;
    98   inline void copy_cards(SparsePRTEntry* e) const;
    98 
    99 
       
   100   card_elem_t* cards() { return _cards; }
       
   101 
    99   inline CardIdx_t card(int i) const {
   102   inline CardIdx_t card(int i) const {
   100     assert(i >= 0, "must be nonnegative");
   103     assert(i >= 0, "must be nonnegative");
   101     assert(i < cards_num(), "range checking");
   104     assert(i < cards_num(), "range checking");
   102     return (CardIdx_t)_cards[i];
   105     return (CardIdx_t)_cards[i];
   103   }
   106   }
   104 };
   107 };
   105 
   108 
   106 class RSHashTable : public CHeapObj<mtGC> {
   109 class RSHashTable : public CHeapObj<mtGC> {
   107 
   110 
   108   friend class RSHashTableIter;
   111   friend class RSHashTableIter;
   109 
   112   friend class RSHashTableBucketIter;
   110 
   113 
   111   // Inverse maximum hash table occupancy used.
   114   // Inverse maximum hash table occupancy used.
   112   static float TableOccupancyFactor;
   115   static float TableOccupancyFactor;
   113 
   116 
   114   size_t _num_entries;
   117   size_t _num_entries;
   207     _rsht(rsht) {}
   210     _rsht(rsht) {}
   208 
   211 
   209   bool has_next(size_t& card_index);
   212   bool has_next(size_t& card_index);
   210 };
   213 };
   211 
   214 
       
   215 // This is embedded in HRRS iterator.
       
   216 class RSHashTableBucketIter {
       
   217   int _tbl_ind;         // [-1, 0.._rsht->_capacity)
       
   218   int _bl_ind;          // [-1, 0.._rsht->_capacity)
       
   219 
       
   220   RSHashTable* _rsht;
       
   221 
       
   222 public:
       
   223   RSHashTableBucketIter(RSHashTable* rsht) :
       
   224     _tbl_ind(0),
       
   225     _bl_ind(rsht->_buckets[_tbl_ind]),
       
   226     _rsht(rsht) { }
       
   227 
       
   228   bool has_next(SparsePRTEntry*& entry);
       
   229 };
       
   230 
   212 // Concurrent access to a SparsePRT must be serialized by some external mutex.
   231 // Concurrent access to a SparsePRT must be serialized by some external mutex.
   213 
   232 
   214 class SparsePRTIter;
   233 class SparsePRTIter;
   215 
   234 
   216 class SparsePRT {
   235 class SparsePRT {
   217   friend class SparsePRTIter;
   236   friend class SparsePRTIter;
       
   237   friend class SparsePRTBucketIter;
   218 
   238 
   219   RSHashTable* _table;
   239   RSHashTable* _table;
   220 
   240 
   221   static const size_t InitialCapacity = 8;
   241   static const size_t InitialCapacity = 8;
   222 
   242 
   260   bool has_next(size_t& card_index) {
   280   bool has_next(size_t& card_index) {
   261     return RSHashTableIter::has_next(card_index);
   281     return RSHashTableIter::has_next(card_index);
   262   }
   282   }
   263 };
   283 };
   264 
   284 
       
   285 class SparsePRTBucketIter: public RSHashTableBucketIter {
       
   286 public:
       
   287   SparsePRTBucketIter(const SparsePRT* sprt) :
       
   288     RSHashTableBucketIter(sprt->_table) {}
       
   289 
       
   290   bool has_next(SparsePRTEntry*& entry) {
       
   291     return RSHashTableBucketIter::has_next(entry);
       
   292   }
       
   293 };
       
   294 
   265 #endif // SHARE_GC_G1_SPARSEPRT_HPP
   295 #endif // SHARE_GC_G1_SPARSEPRT_HPP