src/share/vm/memory/cardTableRS.hpp

Tue, 13 Apr 2010 13:52:10 -0700

author
jmasa
date
Tue, 13 Apr 2010 13:52:10 -0700
changeset 1822
0bfd3fb24150
parent 791
1ee8caae33af
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes

duke@435 1 /*
xdono@631 2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class Space;
duke@435 26 class OopsInGenClosure;
duke@435 27 class DirtyCardToOopClosure;
duke@435 28
duke@435 29 // This kind of "GenRemSet" uses a card table both as shared data structure
duke@435 30 // for a mod ref barrier set and for the rem set information.
duke@435 31
duke@435 32 class CardTableRS: public GenRemSet {
duke@435 33 friend class VMStructs;
duke@435 34 // Below are private classes used in impl.
duke@435 35 friend class VerifyCTSpaceClosure;
duke@435 36 friend class ClearNoncleanCardWrapper;
duke@435 37
duke@435 38 static jbyte clean_card_val() {
duke@435 39 return CardTableModRefBS::clean_card;
duke@435 40 }
duke@435 41
duke@435 42 static bool
duke@435 43 card_is_dirty_wrt_gen_iter(jbyte cv) {
duke@435 44 return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv);
duke@435 45 }
duke@435 46
ysr@777 47 CardTableModRefBSForCTRS* _ct_bs;
duke@435 48
duke@435 49 virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl);
duke@435 50
duke@435 51 void verify_space(Space* s, HeapWord* gen_start);
duke@435 52
duke@435 53 enum ExtendedCardValue {
duke@435 54 youngergen_card = CardTableModRefBS::CT_MR_BS_last_reserved + 1,
duke@435 55 // These are for parallel collection.
duke@435 56 // There are three P (parallel) youngergen card values. In general, this
duke@435 57 // needs to be more than the number of generations (including the perm
duke@435 58 // gen) that might have younger_refs_do invoked on them separately. So
duke@435 59 // if we add more gens, we have to add more values.
duke@435 60 youngergenP1_card = CardTableModRefBS::CT_MR_BS_last_reserved + 2,
duke@435 61 youngergenP2_card = CardTableModRefBS::CT_MR_BS_last_reserved + 3,
duke@435 62 youngergenP3_card = CardTableModRefBS::CT_MR_BS_last_reserved + 4,
duke@435 63 cur_youngergen_and_prev_nonclean_card =
duke@435 64 CardTableModRefBS::CT_MR_BS_last_reserved + 5
duke@435 65 };
duke@435 66
duke@435 67 // An array that contains, for each generation, the card table value last
duke@435 68 // used as the current value for a younger_refs_do iteration of that
duke@435 69 // portion of the table. (The perm gen is index 0; other gens are at
duke@435 70 // their level plus 1. They youngest gen is in the table, but will
duke@435 71 // always have the value "clean_card".)
duke@435 72 jbyte* _last_cur_val_in_gen;
duke@435 73
duke@435 74 jbyte _cur_youngergen_card_val;
duke@435 75
ysr@777 76 int _regions_to_iterate;
ysr@777 77
duke@435 78 jbyte cur_youngergen_card_val() {
duke@435 79 return _cur_youngergen_card_val;
duke@435 80 }
duke@435 81 void set_cur_youngergen_card_val(jbyte v) {
duke@435 82 _cur_youngergen_card_val = v;
duke@435 83 }
duke@435 84 bool is_prev_youngergen_card_val(jbyte v) {
duke@435 85 return
duke@435 86 youngergen_card <= v &&
duke@435 87 v < cur_youngergen_and_prev_nonclean_card &&
duke@435 88 v != _cur_youngergen_card_val;
duke@435 89 }
duke@435 90 // Return a youngergen_card_value that is not currently in use.
duke@435 91 jbyte find_unused_youngergenP_card_value();
duke@435 92
duke@435 93 public:
duke@435 94 CardTableRS(MemRegion whole_heap, int max_covered_regions);
duke@435 95
duke@435 96 // *** GenRemSet functions.
duke@435 97 GenRemSet::Name rs_kind() { return GenRemSet::CardTable; }
duke@435 98
duke@435 99 CardTableRS* as_CardTableRS() { return this; }
duke@435 100
ysr@777 101 CardTableModRefBS* ct_bs() { return _ct_bs; }
duke@435 102
duke@435 103 // Override.
duke@435 104 void prepare_for_younger_refs_iterate(bool parallel);
duke@435 105
duke@435 106 // Card table entries are cleared before application; "blk" is
duke@435 107 // responsible for dirtying if the oop is still older-to-younger after
duke@435 108 // closure application.
duke@435 109 void younger_refs_iterate(Generation* g, OopsInGenClosure* blk);
duke@435 110
coleenp@548 111 void inline_write_ref_field_gc(void* field, oop new_val) {
ysr@777 112 jbyte* byte = _ct_bs->byte_for(field);
duke@435 113 *byte = youngergen_card;
duke@435 114 }
coleenp@548 115 void write_ref_field_gc_work(void* field, oop new_val) {
duke@435 116 inline_write_ref_field_gc(field, new_val);
duke@435 117 }
duke@435 118
duke@435 119 // Override. Might want to devirtualize this in the same fashion as
duke@435 120 // above. Ensures that the value of the card for field says that it's
duke@435 121 // a younger card in the current collection.
coleenp@548 122 virtual void write_ref_field_gc_par(void* field, oop new_val);
duke@435 123
duke@435 124 void resize_covered_region(MemRegion new_region);
duke@435 125
duke@435 126 bool is_aligned(HeapWord* addr) {
ysr@777 127 return _ct_bs->is_card_aligned(addr);
duke@435 128 }
duke@435 129
duke@435 130 void verify();
jmasa@441 131 void verify_aligned_region_empty(MemRegion mr);
duke@435 132
ysr@777 133 void clear(MemRegion mr) { _ct_bs->clear(mr); }
duke@435 134 void clear_into_younger(Generation* gen, bool clear_perm);
duke@435 135
ysr@777 136 void invalidate(MemRegion mr, bool whole_heap = false) {
ysr@777 137 _ct_bs->invalidate(mr, whole_heap);
ysr@777 138 }
duke@435 139 void invalidate_or_clear(Generation* gen, bool younger, bool perm);
duke@435 140
duke@435 141 static uintx ct_max_alignment_constraint() {
duke@435 142 return CardTableModRefBS::ct_max_alignment_constraint();
duke@435 143 }
duke@435 144
ysr@777 145 jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); }
ysr@777 146 jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); }
ysr@777 147 HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); }
duke@435 148
duke@435 149 bool is_prev_nonclean_card_val(jbyte v) {
duke@435 150 return
duke@435 151 youngergen_card <= v &&
duke@435 152 v <= cur_youngergen_and_prev_nonclean_card &&
duke@435 153 v != _cur_youngergen_card_val;
duke@435 154 }
duke@435 155
duke@435 156 static bool youngergen_may_have_been_dirty(jbyte cv) {
duke@435 157 return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card;
duke@435 158 }
duke@435 159
duke@435 160 };

mercurial