src/hotspot/share/gc/shared/cardTable.hpp
author tschatzl
Wed, 13 Mar 2019 21:01:56 +0100
changeset 54110 f4f0dce5d0bb
parent 53244 9807daeb47c4
child 55510 3e31a8beaae4
permissions -rw-r--r--
8220301: Remove jbyte use in CardTable Summary: Use CardTable::CardValue aliased to uint8_t instead. Reviewed-by: kbarrett, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49488
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4902
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49488
diff changeset
    25
#ifndef SHARE_GC_SHARED_CARDTABLE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49488
diff changeset
    26
#define SHARE_GC_SHARED_CARDTABLE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    27
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    28
#include "memory/allocation.hpp"
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    29
#include "memory/memRegion.hpp"
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    30
#include "oops/oopsHierarchy.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    31
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6187
diff changeset
    32
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    33
class CardTable: public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  friend class VMStructs;
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    35
public:
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    36
  typedef uint8_t CardValue;
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    37
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    38
  // All code generators assume that the size of a card table entry is one byte.
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    39
  // They need to be updated to reflect any change to this.
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    40
  // This code can typically be found by searching for the byte_map_base() method.
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    41
  STATIC_ASSERT(sizeof(CardValue) == 1);
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    42
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    43
protected:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // The declaration order of these const fields is important; see the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // constructor before changing.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    46
  const bool      _scanned_concurrently;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  const MemRegion _whole_heap;       // the region covered by the card table
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 24424
diff changeset
    48
  size_t          _guard_index;      // index of very last element in the card
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                                     // table; it is set to a guard value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                                     // (last_card) and should never be modified
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 24424
diff changeset
    51
  size_t          _last_valid_index; // index of the last valid element
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  const size_t    _page_size;        // page size used when mapping _byte_map
26160
aba6b01cb988 8038423: G1: Decommit memory within heap
tschatzl
parents: 24424
diff changeset
    53
  size_t          _byte_map_size;    // in bytes
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    54
  CardValue*      _byte_map;         // the card marking array
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
    55
  CardValue*      _byte_map_base;
47658
c2b7fb8e5144 8189355: Cleanup of BarrierSet barrier functions
eosterlund
parents: 47216
diff changeset
    56
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int _cur_covered_regions;
47658
c2b7fb8e5144 8189355: Cleanup of BarrierSet barrier functions
eosterlund
parents: 47216
diff changeset
    58
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // The covered regions should be in address order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  MemRegion* _covered;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // The committed regions correspond one-to-one to the covered regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // They represent the card-table memory that has been committed to service
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // the corresponding covered region.  It may be that committed region for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // one covered region corresponds to a larger region because of page-size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // roundings.  Thus, a committed region for one covered region may
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // actually extend onto the card-table space for the next covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  MemRegion* _committed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // The last card is a guard card, and we commit the page for it so
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // we can use the card for verification purposes. We make sure we never
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // uncommit the MemRegion for that page.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  MemRegion _guard_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  inline size_t compute_byte_map_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Finds and return the index of the region, if any, to which the given
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // region would be contiguous.  If none exists, assign a new region and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // returns its index.  Requires that no more than the maximum number of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // covered regions defined in the constructor are ever in use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  int find_covering_region_by_base(HeapWord* base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // Same as above, but finds the region containing the given address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // instead of starting at a given base address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  int find_covering_region_containing(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Returns the leftmost end of a committed region corresponding to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // covered region before covered region "ind", or else "NULL" if "ind" is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // the first covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  HeapWord* largest_prev_committed_end(int ind) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Returns the part of the region mr that doesn't intersect with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // any committed region other than self.  Used to prevent uncommitting
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // regions that are also committed by other regions.  Also protects
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // against uncommitting the guard region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  MemRegion committed_unique_to_self(int self, MemRegion mr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    97
  // Some barrier sets create tables whose elements correspond to parts of
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
    98
  // the heap; the CardTableBarrierSet is an example.  Such barrier sets will
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
    99
  // normally reserve space for such tables, and commit parts of the table
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   100
  // "covering" parts of the heap that are committed. At most one covered
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   101
  // region per generation is needed.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   102
  static const int _max_covered_regions = 2;
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   103
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   104
  enum CardValues {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   105
    clean_card                  = (CardValue)-1,
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   106
    // The mask contains zeros in places for all other values.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   107
    clean_card_mask             = clean_card - 31,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   108
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   109
    dirty_card                  =  0,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   110
    precleaned_card             =  1,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   111
    claimed_card                =  2,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   112
    deferred_card               =  4,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   113
    last_card                   =  8,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   114
    CT_MR_BS_last_reserved      = 16
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   115
  };
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   116
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   117
  // a word's worth (row) of clean card values
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   118
  static const intptr_t clean_card_row = (intptr_t)(-1);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   119
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   120
public:
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   121
  CardTable(MemRegion whole_heap, bool conc_scan);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   122
  virtual ~CardTable();
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   123
  virtual void initialize();
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   124
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
   125
  // The kinds of precision a CardTable may offer.
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   126
  enum PrecisionStyle {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   127
    Precise,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   128
    ObjHeadPreciseArray
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   129
  };
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   130
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   131
  // Tells what style of precision this card table offers.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   132
  PrecisionStyle precision() {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   133
    return ObjHeadPreciseArray; // Only one supported for now.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   134
  }
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   135
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   136
  // *** Barrier set functions.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   137
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   138
  // Initialization utilities; covered_words is the size of the covered region
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   139
  // in, um, words.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   140
  inline size_t cards_required(size_t covered_words) {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   141
    // Add one for a guard card, used to detect errors.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   142
    const size_t words = align_up(covered_words, card_size_in_words);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   143
    return words / card_size_in_words + 1;
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   144
  }
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   145
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   146
  // Dirty the bytes corresponding to "mr" (not all of which must be
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   147
  // covered.)
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   148
  void dirty_MemRegion(MemRegion mr);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   149
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   150
  // Clear (to clean_card) the bytes entirely contained within "mr" (not
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   151
  // all of which must be covered.)
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   152
  void clear_MemRegion(MemRegion mr);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   153
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   154
  // Return true if "p" is at the start of a card.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   155
  bool is_card_aligned(HeapWord* p) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   156
    CardValue* pcard = byte_for(p);
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   157
    return (addr_for(pcard) == p);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   158
  }
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   159
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Mapping from address to card marking array entry
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   161
  CardValue* byte_for(const void* p) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    assert(_whole_heap.contains(p),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   163
           "Attempt to access p = " PTR_FORMAT " out of bounds of "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   164
           " card marking array's _whole_heap = [" PTR_FORMAT "," PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   165
           p2i(p), p2i(_whole_heap.start()), p2i(_whole_heap.end()));
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   166
    CardValue* result = &_byte_map_base[uintptr_t(p) >> card_shift];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    assert(result >= _byte_map && result < _byte_map + _byte_map_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
           "out of bounds accessor for card marking array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // The card table byte one after the card marking array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // entry for argument address. Typically used for higher bounds
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // for loops iterating through the card table.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   175
  CardValue* byte_after(const void* p) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    return byte_for(p) + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
42598
45562c0473fb 8166898: G1SATBCardTableLoggingModRefBS::invalidate() incorrect with whole_heap == true
lmesnik
parents: 37233
diff changeset
   179
  virtual void invalidate(MemRegion mr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  void clear(MemRegion mr);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   181
  void dirty(MemRegion mr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   183
  // Provide read-only access to the card table array.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   184
  const CardValue* byte_for_const(const void* p) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   185
    return byte_for(p);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   186
  }
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   187
  const CardValue* byte_after_const(const void* p) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   188
    return byte_after(p);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   189
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   190
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   191
  // Mapping from card marking array entry to address of first word
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   192
  HeapWord* addr_for(const CardValue* p) const {
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   193
    assert(p >= _byte_map && p < _byte_map + _byte_map_size,
46618
d503911aa948 8178489: Make align functions more type safe and consistent
stefank
parents: 42598
diff changeset
   194
           "out of bounds access to card marking array. p: " PTR_FORMAT
d503911aa948 8178489: Make align functions more type safe and consistent
stefank
parents: 42598
diff changeset
   195
           " _byte_map: " PTR_FORMAT " _byte_map + _byte_map_size: " PTR_FORMAT,
d503911aa948 8178489: Make align functions more type safe and consistent
stefank
parents: 42598
diff changeset
   196
           p2i(p), p2i(_byte_map), p2i(_byte_map + _byte_map_size));
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   197
    size_t delta = pointer_delta(p, _byte_map_base, sizeof(CardValue));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   198
    HeapWord* result = (HeapWord*) (delta << card_shift);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   199
    assert(_whole_heap.contains(result),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   200
           "Returning result = " PTR_FORMAT " out of bounds of "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   201
           " card marking array's _whole_heap = [" PTR_FORMAT "," PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   202
           p2i(result), p2i(_whole_heap.start()), p2i(_whole_heap.end()));
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   203
    return result;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   204
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   205
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // Mapping from address to card marking array index.
1676
d80e69372634 6653214: MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes.
swamyv
parents: 1388
diff changeset
   207
  size_t index_for(void* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    assert(_whole_heap.contains(p),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   209
           "Attempt to access p = " PTR_FORMAT " out of bounds of "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   210
           " card marking array's _whole_heap = [" PTR_FORMAT "," PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32612
diff changeset
   211
           p2i(p), p2i(_whole_heap.start()), p2i(_whole_heap.end()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    return byte_for(p) - _byte_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   215
  CardValue* byte_for_index(const size_t card_index) const {
2142
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 1676
diff changeset
   216
    return _byte_map + card_index;
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 1676
diff changeset
   217
  }
032f4652700c 6720309: G1: don't synchronously update RSet during evacuation pauses
iveresov
parents: 1676
diff changeset
   218
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   219
  // Resize one of the regions covered by the remembered set.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   220
  virtual void resize_covered_region(MemRegion new_region);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   221
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   222
  // *** Card-table-RemSet-specific things.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   223
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   224
  static uintx ct_max_alignment_constraint();
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   225
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   226
  // Apply closure "cl" to the dirty cards containing some part of
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   227
  // MemRegion "mr".
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   228
  void dirty_card_iterate(MemRegion mr, MemRegionClosure* cl);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   229
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   230
  // Return the MemRegion corresponding to the first maximal run
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   231
  // of dirty cards lying completely within MemRegion mr.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   232
  // If reset is "true", then sets those card table entries to the given
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   233
  // value.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   234
  MemRegion dirty_card_range_after_reset(MemRegion mr, bool reset,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   235
                                         int reset_val);
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   236
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   237
  // Constants
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   238
  enum SomePublicConstants {
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   239
    card_shift                  = 9,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   240
    card_size                   = 1 << card_shift,
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   241
    card_size_in_words          = card_size / sizeof(HeapWord)
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   242
  };
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   243
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   244
  static CardValue clean_card_val()          { return clean_card; }
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   245
  static CardValue clean_card_mask_val()     { return clean_card_mask; }
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   246
  static CardValue dirty_card_val()          { return dirty_card; }
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   247
  static CardValue claimed_card_val()        { return claimed_card; }
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   248
  static CardValue precleaned_card_val()     { return precleaned_card; }
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   249
  static CardValue deferred_card_val()       { return deferred_card; }
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   250
  static intptr_t clean_card_row_val()   { return clean_card_row; }
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   251
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   252
  // Card marking array base (adjusted for heap low boundary)
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   253
  // This would be the 0th element of _byte_map, if the heap started at 0x0.
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   254
  // But since the heap starts at some higher address, this points to somewhere
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   255
  // before the beginning of the actual _byte_map.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   256
  CardValue* byte_map_base() const { return _byte_map_base; }
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   257
  bool scanned_concurrently() const { return _scanned_concurrently; }
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   258
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   259
  virtual bool is_in_young(oop obj) const = 0;
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   260
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 49007
diff changeset
   261
  // Print a description of the memory for the card table
12268
f7897aacb9ce 7157141: crash in 64 bit with corrupted oops
never
parents: 12118
diff changeset
   262
  virtual void print_on(outputStream* st) const;
f7897aacb9ce 7157141: crash in 64 bit with corrupted oops
never
parents: 12118
diff changeset
   263
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  void verify_guard();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
9418
32a87dd6b746 7035144: G1: nightly failure: Non-dirty cards in region that should be dirty (failures still exist...)
tonyp
parents: 9336
diff changeset
   267
  // val_equals -> it will check that all cards covered by mr equal val
32a87dd6b746 7035144: G1: nightly failure: Non-dirty cards in region that should be dirty (failures still exist...)
tonyp
parents: 9336
diff changeset
   268
  // !val_equals -> it will check that all cards covered by mr do not equal val
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 53244
diff changeset
   269
  void verify_region(MemRegion mr, CardValue val, bool val_equals) PRODUCT_RETURN;
9418
32a87dd6b746 7035144: G1: nightly failure: Non-dirty cards in region that should be dirty (failures still exist...)
tonyp
parents: 9336
diff changeset
   270
  void verify_not_dirty_region(MemRegion mr) PRODUCT_RETURN;
3695
421cfcc8843c 6841313: G1: dirty cards of survivor regions in parallel
apetrusenko
parents: 3262
diff changeset
   271
  void verify_dirty_region(MemRegion mr) PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49488
diff changeset
   274
#endif // SHARE_GC_SHARED_CARDTABLE_HPP