33 #include "oops/markWord.hpp"
34 #include "oops/oop.hpp"
35 #include "runtime/timer.hpp"
36 #include "utilities/growableArray.hpp"
37 #include "utilities/stack.hpp"
38
39 class DataLayout;
40 class SerialOldTracer;
41 class STWGCTimer;
42
43 // MarkSweep takes care of global mark-compact garbage collection for a
44 // GenCollectedHeap using a four-phase pointer forwarding algorithm. All
45 // generations are assumed to support marking; those that can also support
46 // compaction.
47 //
48 // Class unloading will only occur when a full gc is invoked.
49
50 // declared at end
51 class PreservedMark;
52 class MarkAndPushClosure;
53 class AdjustPointerClosure;
54
55 class MarkSweep : AllStatic {
56 //
57 // Inline closure decls
58 //
59 class FollowRootClosure: public BasicOopIterateClosure {
60 public:
61 virtual void do_oop(oop* p);
62 virtual void do_oop(narrowOop* p);
63 };
64
65 class FollowStackClosure: public VoidClosure {
66 public:
67 virtual void do_void();
68 };
69
70 // Used for java/lang/ref handling
71 class IsAliveClosure: public BoolObjectClosure {
72 public:
73 virtual bool do_object_b(oop p);
74 };
75
76 class KeepAliveClosure: public OopClosure {
77 protected:
78 template <class T> void do_oop_work(T* p);
79 public:
80 virtual void do_oop(oop* p);
81 virtual void do_oop(narrowOop* p);
82 };
83
84 //
85 // Friend decls
86 //
87 friend class AdjustPointerClosure;
88 friend class KeepAliveClosure;
89
90 //
91 // Vars
92 //
93 protected:
94 // Total invocations of a MarkSweep collection
95 static uint _total_invocations;
96
97 // Traversal stacks used during phase1
98 static Stack<oop, mtGC> _marking_stack;
99 static Stack<ObjArrayTask, mtGC> _objarray_stack;
100
101 // Space for storing/restoring mark word
102 static Stack<PreservedMark, mtGC> _preserved_overflow_stack;
103 static size_t _preserved_count;
104 static size_t _preserved_count_max;
105 static PreservedMark* _preserved_marks;
106
107 static AlwaysTrueClosure _always_true_closure;
108 static ReferenceProcessor* _ref_processor;
109
110 static STWGCTimer* _gc_timer;
111 static SerialOldTracer* _gc_tracer;
112
113 static StringDedup::Requests* _string_dedup_requests;
114
115 // Non public closures
116 static KeepAliveClosure keep_alive;
117
118 public:
119 static void initialize();
120
121 // Public closures
122 static IsAliveClosure is_alive;
123 static FollowRootClosure follow_root_closure;
124 static MarkAndPushClosure mark_and_push_closure;
125 static FollowStackClosure follow_stack_closure;
126 static CLDToOopClosure follow_cld_closure;
127 static AdjustPointerClosure adjust_pointer_closure;
128 static CLDToOopClosure adjust_cld_closure;
129
130 // Accessors
131 static uint total_invocations() { return _total_invocations; }
132
133 // Reference Processing
134 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
135
136 static STWGCTimer* gc_timer() { return _gc_timer; }
137 static SerialOldTracer* gc_tracer() { return _gc_tracer; }
138
139 static void preserve_mark(oop p, markWord mark);
140 // Save the mark word so it can be restored later
141 static void adjust_marks(); // Adjust the pointers in the preserved marks table
142 static void restore_marks(); // Restore the marks that we saved in preserve_mark
143
144 static size_t adjust_pointers(oop obj);
145
146 static void follow_stack(); // Empty marking stack.
147
148 template <class T> static inline void adjust_pointer(T* p);
149
150 // Check mark and maybe push on marking stack
151 template <class T> static void mark_and_push(T* p);
152
153 private:
154 // Call backs for marking
155 static void mark_object(oop obj);
156 // Mark pointer and follow contents. Empty marking stack afterwards.
157 template <class T> static inline void follow_root(T* p);
158
159 static inline void push_objarray(oop obj, size_t index);
160
161 static void follow_object(oop obj);
162
163 static void follow_array(objArrayOop array);
164
165 static void follow_array_chunk(objArrayOop array, int index);
166 };
167
168 class MarkAndPushClosure: public ClaimMetadataVisitingOopIterateClosure {
169 public:
170 MarkAndPushClosure(int claim) : ClaimMetadataVisitingOopIterateClosure(claim) {}
171
172 template <typename T> void do_oop_work(T* p);
173 virtual void do_oop( oop* p);
174 virtual void do_oop(narrowOop* p);
175
176 void set_ref_discoverer(ReferenceDiscoverer* rd) {
177 set_ref_discoverer_internal(rd);
178 }
179 };
180
181 class AdjustPointerClosure: public BasicOopIterateClosure {
182 public:
183 template <typename T> void do_oop_work(T* p);
184 virtual void do_oop(oop* p);
185 virtual void do_oop(narrowOop* p);
186 virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }
187 };
188
189 class PreservedMark {
190 private:
191 oop _obj;
192 markWord _mark;
193
194 public:
195 PreservedMark(oop obj, markWord mark) : _obj(obj), _mark(mark) {}
196 void adjust_pointer();
197 void restore();
198 };
199
200 #endif // SHARE_GC_SERIAL_MARKSWEEP_HPP
|
33 #include "oops/markWord.hpp"
34 #include "oops/oop.hpp"
35 #include "runtime/timer.hpp"
36 #include "utilities/growableArray.hpp"
37 #include "utilities/stack.hpp"
38
39 class DataLayout;
40 class SerialOldTracer;
41 class STWGCTimer;
42
43 // MarkSweep takes care of global mark-compact garbage collection for a
44 // GenCollectedHeap using a four-phase pointer forwarding algorithm. All
45 // generations are assumed to support marking; those that can also support
46 // compaction.
47 //
48 // Class unloading will only occur when a full gc is invoked.
49
50 // declared at end
51 class PreservedMark;
52 class MarkAndPushClosure;
53
54 class MarkSweep : AllStatic {
55 //
56 // Inline closure decls
57 //
58 class FollowRootClosure: public BasicOopIterateClosure {
59 public:
60 virtual void do_oop(oop* p);
61 virtual void do_oop(narrowOop* p);
62 };
63
64 class FollowStackClosure: public VoidClosure {
65 public:
66 virtual void do_void();
67 };
68
69 // Used for java/lang/ref handling
70 class IsAliveClosure: public BoolObjectClosure {
71 public:
72 virtual bool do_object_b(oop p);
73 };
74
75 class KeepAliveClosure: public OopClosure {
76 protected:
77 template <class T> void do_oop_work(T* p);
78 public:
79 virtual void do_oop(oop* p);
80 virtual void do_oop(narrowOop* p);
81 };
82
83 //
84 // Friend decls
85 //
86 friend class KeepAliveClosure;
87
88 //
89 // Vars
90 //
91 protected:
92 // Total invocations of a MarkSweep collection
93 static uint _total_invocations;
94
95 // Traversal stacks used during phase1
96 static Stack<oop, mtGC> _marking_stack;
97 static Stack<ObjArrayTask, mtGC> _objarray_stack;
98
99 // Space for storing/restoring mark word
100 static Stack<PreservedMark, mtGC> _preserved_overflow_stack;
101 static size_t _preserved_count;
102 static size_t _preserved_count_max;
103 static PreservedMark* _preserved_marks;
104
105 static AlwaysTrueClosure _always_true_closure;
106 static ReferenceProcessor* _ref_processor;
107
108 static STWGCTimer* _gc_timer;
109 static SerialOldTracer* _gc_tracer;
110
111 static StringDedup::Requests* _string_dedup_requests;
112
113 // Non public closures
114 static KeepAliveClosure keep_alive;
115
116 public:
117 static void initialize();
118
119 // Public closures
120 static IsAliveClosure is_alive;
121 static FollowRootClosure follow_root_closure;
122 static MarkAndPushClosure mark_and_push_closure;
123 static FollowStackClosure follow_stack_closure;
124 static CLDToOopClosure follow_cld_closure;
125
126 // Accessors
127 static uint total_invocations() { return _total_invocations; }
128
129 // Reference Processing
130 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
131
132 static STWGCTimer* gc_timer() { return _gc_timer; }
133 static SerialOldTracer* gc_tracer() { return _gc_tracer; }
134
135 static void preserve_mark(oop p, markWord mark);
136 // Save the mark word so it can be restored later
137 static void adjust_marks(); // Adjust the pointers in the preserved marks table
138 static void restore_marks(); // Restore the marks that we saved in preserve_mark
139
140 template <bool ALT_FWD>
141 static size_t adjust_pointers(oop obj);
142
143 static void follow_stack(); // Empty marking stack.
144
145 template <bool ALT_FWD, class T>
146 static void adjust_pointer(T* p);
147
148 // Check mark and maybe push on marking stack
149 template <class T> static void mark_and_push(T* p);
150
151 private:
152 template <bool ALT_FWD>
153 static void adjust_marks_impl();
154
155 // Call backs for marking
156 static void mark_object(oop obj);
157 // Mark pointer and follow contents. Empty marking stack afterwards.
158 template <class T> static inline void follow_root(T* p);
159
160 static inline void push_objarray(oop obj, size_t index);
161
162 static void follow_object(oop obj);
163
164 static void follow_array(objArrayOop array);
165
166 static void follow_array_chunk(objArrayOop array, int index);
167 };
168
169 class MarkAndPushClosure: public ClaimMetadataVisitingOopIterateClosure {
170 public:
171 MarkAndPushClosure(int claim) : ClaimMetadataVisitingOopIterateClosure(claim) {}
172
173 template <typename T> void do_oop_work(T* p);
174 virtual void do_oop( oop* p);
175 virtual void do_oop(narrowOop* p);
176
177 void set_ref_discoverer(ReferenceDiscoverer* rd) {
178 set_ref_discoverer_internal(rd);
179 }
180 };
181
182 template <bool ALT_FWD>
183 class AdjustPointerClosure: public BasicOopIterateClosure {
184 public:
185 template <typename T> void do_oop_work(T* p);
186 virtual void do_oop(oop* p);
187 virtual void do_oop(narrowOop* p);
188 virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }
189 };
190
191 class PreservedMark {
192 private:
193 oop _obj;
194 markWord _mark;
195
196 public:
197 PreservedMark(oop obj, markWord mark) : _obj(obj), _mark(mark) {}
198 template <bool ALT_FWD>
199 void adjust_pointer();
200 void restore();
201 };
202
203 #endif // SHARE_GC_SERIAL_MARKSWEEP_HPP
|