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