src/share/vm/gc_implementation/g1/sparsePRT.hpp

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 984
fe3d7c11b4b7
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

     1 /*
     2  * Copyright 2001-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // Sparse remembered set for a heap region (the "owning" region).  Maps
    26 // indices of other regions to short sequences of cards in the other region
    27 // that might contain pointers into the owner region.
    29 // These tables only expand while they are accessed in parallel --
    30 // deletions may be done in single-threaded code.  This allows us to allow
    31 // unsynchronized reads/iterations, as long as expansions caused by
    32 // insertions only enqueue old versions for deletions, but do not delete
    33 // old versions synchronously.
    36 class SparsePRTEntry: public CHeapObj {
    37 public:
    38   enum SomePublicConstants {
    39     CardsPerEntry = (short)4,
    40     NullEntry = (short)-1,
    41     DeletedEntry = (short)-2
    42   };
    44 private:
    45   short _region_ind;
    46   short _next_index;
    47   short _cards[CardsPerEntry];
    49 public:
    51   // Set the region_ind to the given value, and delete all cards.
    52   inline void init(short region_ind);
    54   short r_ind() const { return _region_ind; }
    55   bool valid_entry() const { return r_ind() >= 0; }
    56   void set_r_ind(short rind) { _region_ind = rind; }
    58   short next_index() const { return _next_index; }
    59   short* next_index_addr() { return &_next_index; }
    60   void set_next_index(short ni) { _next_index = ni; }
    62   // Returns "true" iff the entry contains the given card index.
    63   inline bool contains_card(short card_index) const;
    65   // Returns the number of non-NULL card entries.
    66   inline int num_valid_cards() const;
    68   // Requires that the entry not contain the given card index.  If there is
    69   // space available, add the given card index to the entry and return
    70   // "true"; otherwise, return "false" to indicate that the entry is full.
    71   enum AddCardResult {
    72     overflow,
    73     found,
    74     added
    75   };
    76   inline AddCardResult add_card(short card_index);
    78   // Copy the current entry's cards into "cards".
    79   inline void copy_cards(short* cards) const;
    80   // Copy the current entry's cards into the "_card" array of "e."
    81   inline void copy_cards(SparsePRTEntry* e) const;
    83   inline short card(int i) const { return _cards[i]; }
    84 };
    87 class RSHashTable : public CHeapObj {
    89   friend class RSHashTableIter;
    91   enum SomePrivateConstants {
    92     NullEntry = -1
    93   };
    95   size_t _capacity;
    96   size_t _capacity_mask;
    97   size_t _occupied_entries;
    98   size_t _occupied_cards;
   100   SparsePRTEntry* _entries;
   101   short* _buckets;
   102   short  _free_region;
   103   short  _free_list;
   105   static RSHashTable* _head_deleted_list;
   106   RSHashTable* _next_deleted;
   107   RSHashTable* next_deleted() { return _next_deleted; }
   108   void set_next_deleted(RSHashTable* rsht) { _next_deleted = rsht; }
   109   bool _deleted;
   110   void set_deleted(bool b) { _deleted = b; }
   112   // Requires that the caller hold a lock preventing parallel modifying
   113   // operations, and that the the table be less than completely full.  If
   114   // an entry for "region_ind" is already in the table, finds it and
   115   // returns its address; otherwise returns "NULL."
   116   SparsePRTEntry* entry_for_region_ind(short region_ind) const;
   118   // Requires that the caller hold a lock preventing parallel modifying
   119   // operations, and that the the table be less than completely full.  If
   120   // an entry for "region_ind" is already in the table, finds it and
   121   // returns its address; otherwise allocates, initializes, inserts and
   122   // returns a new entry for "region_ind".
   123   SparsePRTEntry* entry_for_region_ind_create(short region_ind);
   125   // Returns the index of the next free entry in "_entries".
   126   short alloc_entry();
   127   // Declares the entry "fi" to be free.  (It must have already been
   128   // deleted from any bucket lists.
   129   void free_entry(short fi);
   131 public:
   132   RSHashTable(size_t capacity);
   133   ~RSHashTable();
   135   // Attempts to ensure that the given card_index in the given region is in
   136   // the sparse table.  If successful (because the card was already
   137   // present, or because it was successfullly added) returns "true".
   138   // Otherwise, returns "false" to indicate that the addition would
   139   // overflow the entry for the region.  The caller must transfer these
   140   // entries to a larger-capacity representation.
   141   bool add_card(short region_id, short card_index);
   143   bool get_cards(short region_id, short* cards);
   144   bool delete_entry(short region_id);
   146   bool contains_card(short region_id, short card_index) const;
   148   void add_entry(SparsePRTEntry* e);
   150   void clear();
   152   size_t capacity() const      { return _capacity;       }
   153   size_t capacity_mask() const { return _capacity_mask;  }
   154   size_t occupied_entries() const { return _occupied_entries; }
   155   size_t occupied_cards() const   { return _occupied_cards;   }
   156   size_t mem_size() const;
   157   bool deleted() { return _deleted; }
   159   SparsePRTEntry* entry(int i) const { return &_entries[i]; }
   161   void print();
   163   static void add_to_deleted_list(RSHashTable* rsht);
   164   static RSHashTable* get_from_deleted_list();
   167 };
   169   // ValueObj because will be embedded in HRRS iterator.
   170 class RSHashTableIter VALUE_OBJ_CLASS_SPEC {
   171     short _tbl_ind;
   172     short _bl_ind;
   173     short _card_ind;
   174     RSHashTable* _rsht;
   175     size_t _heap_bot_card_ind;
   177     enum SomePrivateConstants {
   178       CardsPerRegion = HeapRegion::GrainBytes >> CardTableModRefBS::card_shift
   179     };
   181     // If the bucket list pointed to by _bl_ind contains a card, sets
   182     // _bl_ind to the index of that entry, and returns the card.
   183     // Otherwise, returns SparseEntry::NullEnty.
   184     short find_first_card_in_list();
   185     // Computes the proper card index for the card whose offset in the
   186     // current region (as indicated by _bl_ind) is "ci".
   187     // This is subject to errors when there is iteration concurrent with
   188     // modification, but these errors should be benign.
   189     size_t compute_card_ind(short ci);
   191   public:
   192     RSHashTableIter(size_t heap_bot_card_ind) :
   193       _tbl_ind(RSHashTable::NullEntry),
   194       _bl_ind(RSHashTable::NullEntry),
   195       _card_ind((SparsePRTEntry::CardsPerEntry-1)),
   196       _rsht(NULL),
   197       _heap_bot_card_ind(heap_bot_card_ind)
   198     {}
   200     void init(RSHashTable* rsht) {
   201       _rsht = rsht;
   202       _tbl_ind = -1; // So that first increment gets to 0.
   203       _bl_ind = RSHashTable::NullEntry;
   204       _card_ind = (SparsePRTEntry::CardsPerEntry-1);
   205     }
   207     bool has_next(size_t& card_index);
   209   };
   211 // Concurrent accesss to a SparsePRT must be serialized by some external
   212 // mutex.
   214 class SparsePRTIter;
   216 class SparsePRT VALUE_OBJ_CLASS_SPEC {
   217   //  Iterations are done on the _cur hash table, since they only need to
   218   //  see entries visible at the start of a collection pause.
   219   //  All other operations are done using the _next hash table.
   220   RSHashTable* _cur;
   221   RSHashTable* _next;
   223   HeapRegion* _hr;
   225   enum SomeAdditionalPrivateConstants {
   226     InitialCapacity = 16
   227   };
   229   void expand();
   231   bool _expanded;
   233   bool expanded() { return _expanded; }
   234   void set_expanded(bool b) { _expanded = b; }
   236   SparsePRT* _next_expanded;
   238   SparsePRT* next_expanded() { return _next_expanded; }
   239   void set_next_expanded(SparsePRT* nxt) { _next_expanded = nxt; }
   242   static SparsePRT* _head_expanded_list;
   244 public:
   245   SparsePRT(HeapRegion* hr);
   247   ~SparsePRT();
   249   size_t occupied() const { return _next->occupied_cards(); }
   250   size_t mem_size() const;
   252   // Attempts to ensure that the given card_index in the given region is in
   253   // the sparse table.  If successful (because the card was already
   254   // present, or because it was successfullly added) returns "true".
   255   // Otherwise, returns "false" to indicate that the addition would
   256   // overflow the entry for the region.  The caller must transfer these
   257   // entries to a larger-capacity representation.
   258   bool add_card(short region_id, short card_index);
   260   // If the table hold an entry for "region_ind",  Copies its
   261   // cards into "cards", which must be an array of length at least
   262   // "CardsPerEntry", and returns "true"; otherwise, returns "false".
   263   bool get_cards(short region_ind, short* cards);
   265   // If there is an entry for "region_ind", removes it and return "true";
   266   // otherwise returns "false."
   267   bool delete_entry(short region_ind);
   269   // Clear the table, and reinitialize to initial capacity.
   270   void clear();
   272   // Ensure that "_cur" and "_next" point to the same table.
   273   void cleanup();
   275   // Clean up all tables on the expanded list.  Called single threaded.
   276   static void cleanup_all();
   277   RSHashTable* next() const { return _next; }
   280   void init_iterator(SparsePRTIter* sprt_iter);
   282   static void add_to_expanded_list(SparsePRT* sprt);
   283   static SparsePRT* get_from_expanded_list();
   285   bool contains_card(short region_id, short card_index) const {
   286     return _next->contains_card(region_id, card_index);
   287   }
   289 #if 0
   290   void verify_is_cleared();
   291   void print();
   292 #endif
   293 };
   296 class SparsePRTIter: public /* RSHashTable:: */RSHashTableIter {
   297 public:
   298   SparsePRTIter(size_t heap_bot_card_ind) :
   299     /* RSHashTable:: */RSHashTableIter(heap_bot_card_ind)
   300   {}
   302   void init(const SparsePRT* sprt) {
   303     RSHashTableIter::init(sprt->next());
   304   }
   305   bool has_next(size_t& card_index) {
   306     return RSHashTableIter::has_next(card_index);
   307   }
   308 };

mercurial