hotspot/src/share/vm/memory/cardTableRS.hpp
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 179 59e3abf83f72
child 670 ddf3e9583f2f
child 1374 4c24294029a9
permissions -rw-r--r--
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
class Space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
class OopsInGenClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
class DirtyCardToOopClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// This kind of "GenRemSet" uses a card table both as shared data structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// for a mod ref barrier set and for the rem set information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
class CardTableRS: public GenRemSet {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  // Below are private classes used in impl.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  friend class VerifyCTSpaceClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  friend class ClearNoncleanCardWrapper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static jbyte clean_card_val() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    return CardTableModRefBS::clean_card;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  card_is_dirty_wrt_gen_iter(jbyte cv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  CardTableModRefBSForCTRS _ct_bs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  void verify_space(Space* s, HeapWord* gen_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  enum ExtendedCardValue {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    youngergen_card   = CardTableModRefBS::CT_MR_BS_last_reserved + 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // These are for parallel collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // There are three P (parallel) youngergen card values.  In general, this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    // needs to be more than the number of generations (including the perm
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // gen) that might have younger_refs_do invoked on them separately.  So
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    // if we add more gens, we have to add more values.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    youngergenP1_card  = CardTableModRefBS::CT_MR_BS_last_reserved + 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    youngergenP2_card  = CardTableModRefBS::CT_MR_BS_last_reserved + 3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    youngergenP3_card  = CardTableModRefBS::CT_MR_BS_last_reserved + 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    cur_youngergen_and_prev_nonclean_card =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      CardTableModRefBS::CT_MR_BS_last_reserved + 5
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // An array that contains, for each generation, the card table value last
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // used as the current value for a younger_refs_do iteration of that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // portion of the table.  (The perm gen is index 0; other gens are at
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // their level plus 1.  They youngest gen is in the table, but will
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // always have the value "clean_card".)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  jbyte* _last_cur_val_in_gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  jbyte _cur_youngergen_card_val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  jbyte cur_youngergen_card_val() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    return _cur_youngergen_card_val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  void set_cur_youngergen_card_val(jbyte v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    _cur_youngergen_card_val = v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  bool is_prev_youngergen_card_val(jbyte v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    return
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      youngergen_card <= v &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      v < cur_youngergen_and_prev_nonclean_card &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      v != _cur_youngergen_card_val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Return a youngergen_card_value that is not currently in use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  jbyte find_unused_youngergenP_card_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  CardTableRS(MemRegion whole_heap, int max_covered_regions);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // *** GenRemSet functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  GenRemSet::Name rs_kind() { return GenRemSet::CardTable; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  CardTableRS* as_CardTableRS() { return this; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  CardTableModRefBS* ct_bs() { return &_ct_bs; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // Override.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void prepare_for_younger_refs_iterate(bool parallel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Card table entries are cleared before application; "blk" is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // responsible for dirtying if the oop is still older-to-younger after
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // closure application.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  void younger_refs_iterate(Generation* g, OopsInGenClosure* blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 179
diff changeset
   109
  void inline_write_ref_field_gc(void* field, oop new_val) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    jbyte* byte = _ct_bs.byte_for(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    *byte = youngergen_card;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 179
diff changeset
   113
  void write_ref_field_gc_work(void* field, oop new_val) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    inline_write_ref_field_gc(field, new_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Override.  Might want to devirtualize this in the same fashion as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // above.  Ensures that the value of the card for field says that it's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // a younger card in the current collection.
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 179
diff changeset
   120
  virtual void write_ref_field_gc_par(void* field, oop new_val);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void resize_covered_region(MemRegion new_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  bool is_aligned(HeapWord* addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    return _ct_bs.is_card_aligned(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void verify();
179
59e3abf83f72 6624765: Guarantee failure "Unexpected dirty card found"
jmasa
parents: 1
diff changeset
   129
  void verify_aligned_region_empty(MemRegion mr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  void clear(MemRegion mr) { _ct_bs.clear(mr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  void clear_into_younger(Generation* gen, bool clear_perm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void invalidate(MemRegion mr) { _ct_bs.invalidate(mr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  void invalidate_or_clear(Generation* gen, bool younger, bool perm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  static uintx ct_max_alignment_constraint() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    return CardTableModRefBS::ct_max_alignment_constraint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  jbyte* byte_for(void* p)     { return _ct_bs.byte_for(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  jbyte* byte_after(void* p)   { return _ct_bs.byte_after(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  HeapWord* addr_for(jbyte* p) { return _ct_bs.addr_for(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  bool is_prev_nonclean_card_val(jbyte v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    return
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      youngergen_card <= v &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      v <= cur_youngergen_and_prev_nonclean_card &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      v != _cur_youngergen_card_val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  static bool youngergen_may_have_been_dirty(jbyte cv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
};