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