src/share/vm/memory/genOopClosures.hpp

changeset 435
a61af66fc99e
child 548
ba764ed4b6f2
equal deleted inserted replaced
-1:000000000000 435:a61af66fc99e
1 /*
2 * Copyright 2001-2007 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 */
24
25 class Generation;
26 class HeapWord;
27 class CardTableRS;
28 class CardTableModRefBS;
29 class DefNewGeneration;
30
31 // Closure for iterating roots from a particular generation
32 // Note: all classes deriving from this MUST call this do_barrier
33 // method at the end of their own do_oop method!
34 // Note: no do_oop defined, this is an abstract class.
35
36 class OopsInGenClosure : public OopClosure {
37 private:
38 Generation* _orig_gen; // generation originally set in ctor
39 Generation* _gen; // generation being scanned
40
41 protected:
42 // Some subtypes need access.
43 HeapWord* _gen_boundary; // start of generation
44 CardTableRS* _rs; // remembered set
45
46 // For assertions
47 Generation* generation() { return _gen; }
48 CardTableRS* rs() { return _rs; }
49
50 // Derived classes that modify oops so that they might be old-to-young
51 // pointers must call the method below.
52 void do_barrier(oop* p);
53
54 public:
55 OopsInGenClosure() : OopClosure(NULL),
56 _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};
57
58 OopsInGenClosure(Generation* gen);
59 void set_generation(Generation* gen);
60
61 void reset_generation() { _gen = _orig_gen; }
62
63 // Problem with static closures: must have _gen_boundary set at some point,
64 // but cannot do this until after the heap is initialized.
65 void set_orig_generation(Generation* gen) {
66 _orig_gen = gen;
67 set_generation(gen);
68 }
69
70 HeapWord* gen_boundary() { return _gen_boundary; }
71 };
72
73 // Closure for scanning DefNewGeneration.
74 //
75 // This closure will perform barrier store calls for ALL
76 // pointers in scanned oops.
77 class ScanClosure: public OopsInGenClosure {
78 protected:
79 DefNewGeneration* _g;
80 HeapWord* _boundary;
81 bool _gc_barrier;
82 public:
83 ScanClosure(DefNewGeneration* g, bool gc_barrier);
84 void do_oop(oop* p);
85 void do_oop_nv(oop* p);
86 bool do_header() { return false; }
87 Prefetch::style prefetch_style() {
88 return Prefetch::do_write;
89 }
90 };
91
92 // Closure for scanning DefNewGeneration.
93 //
94 // This closure only performs barrier store calls on
95 // pointers into the DefNewGeneration. This is less
96 // precise, but faster, than a ScanClosure
97 class FastScanClosure: public OopsInGenClosure {
98 protected:
99 DefNewGeneration* _g;
100 HeapWord* _boundary;
101 bool _gc_barrier;
102 public:
103 FastScanClosure(DefNewGeneration* g, bool gc_barrier);
104 void do_oop(oop* p);
105 void do_oop_nv(oop* p);
106 bool do_header() { return false; }
107 Prefetch::style prefetch_style() {
108 return Prefetch::do_write;
109 }
110 };
111
112 class FilteringClosure: public OopClosure {
113 HeapWord* _boundary;
114 OopClosure* _cl;
115 public:
116 FilteringClosure(HeapWord* boundary, OopClosure* cl) :
117 OopClosure(cl->_ref_processor), _boundary(boundary),
118 _cl(cl) {}
119 void do_oop(oop* p);
120 void do_oop_nv(oop* p) {
121 oop obj = *p;
122 if ((HeapWord*)obj < _boundary && obj != NULL) {
123 _cl->do_oop(p);
124 }
125 }
126 bool do_header() { return false; }
127 };
128
129 // Closure for scanning DefNewGeneration's weak references.
130 // NOTE: very much like ScanClosure but not derived from
131 // OopsInGenClosure -- weak references are processed all
132 // at once, with no notion of which generation they were in.
133 class ScanWeakRefClosure: public OopClosure {
134 protected:
135 DefNewGeneration* _g;
136 HeapWord* _boundary;
137 public:
138 ScanWeakRefClosure(DefNewGeneration* g);
139 void do_oop(oop* p);
140 void do_oop_nv(oop* p);
141 };
142
143 class VerifyOopClosure: public OopClosure {
144 public:
145 void do_oop(oop* p) {
146 guarantee((*p)->is_oop_or_null(), "invalid oop");
147 }
148 static VerifyOopClosure verify_oop;
149 };

mercurial