84
85 // We should save the marks of the currently locked biased monitors.
86 // The marking doesn't preserve the marks of biased objects.
87 BiasedLocking::preserve_marks();
88
89 mark_sweep_phase1(marked_for_unloading, clear_all_softrefs);
90
91 mark_sweep_phase2();
92
93 // Don't add any more derived pointers during phase3
94 COMPILER2_PRESENT(DerivedPointerTable::set_active(false));
95
96 mark_sweep_phase3();
97
98 mark_sweep_phase4();
99
100 GenMarkSweep::restore_marks();
101 BiasedLocking::restore_marks();
102 GenMarkSweep::deallocate_stacks();
103
104 // "free at last gc" is calculated from these.
105 // CHF: cheating for now!!!
106 // Universe::set_heap_capacity_at_last_gc(Universe::heap()->capacity());
107 // Universe::set_heap_used_at_last_gc(Universe::heap()->used());
108
109 CodeCache::gc_epilogue();
110 JvmtiExport::gc_epilogue();
111
112 // refs processing: clean slate
113 GenMarkSweep::_ref_processor = NULL;
114 }
115
116
117 void G1MarkSweep::allocate_stacks() {
118 GenMarkSweep::_preserved_count_max = 0;
119 GenMarkSweep::_preserved_marks = NULL;
120 GenMarkSweep::_preserved_count = 0;
121 }
122
123 void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading,
124 bool clear_all_softrefs) {
125 // Recursively traverse all live objects and mark them
126 GCTraceTime tm("phase 1", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id());
127 GenMarkSweep::trace(" 1");
128
150 &GenMarkSweep::follow_stack_closure,
151 NULL,
152 gc_timer(),
153 gc_tracer()->gc_id());
154 gc_tracer()->report_gc_reference_stats(stats);
155
156
157 // This is the point where the entire marking should have completed.
158 assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");
159
160 // Unload classes and purge the SystemDictionary.
161 bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
162
163 // Unload nmethods.
164 CodeCache::do_unloading(&GenMarkSweep::is_alive, purged_class);
165
166 // Prune dead klasses from subklass/sibling/implementor lists.
167 Klass::clean_weak_klass_links(&GenMarkSweep::is_alive);
168
169 // Delete entries for dead interned string and clean up unreferenced symbols in symbol table.
170 G1CollectedHeap::heap()->unlink_string_and_symbol_table(&GenMarkSweep::is_alive);
171
172 if (VerifyDuringGC) {
173 HandleMark hm; // handle scope
174 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact);
175 Universe::heap()->prepare_for_verify();
176 // Note: we can verify only the heap here. When an object is
177 // marked, the previous value of the mark word (including
178 // identity hash values, ages, etc) is preserved, and the mark
179 // word is set to markOop::marked_value - effectively removing
180 // any hash values from the mark word. These hash values are
181 // used when verifying the dictionaries and so removing them
182 // from the mark word can make verification of the dictionaries
183 // fail. At the end of the GC, the original mark word values
184 // (including hash values) are restored to the appropriate
185 // objects.
186 if (!VerifySilently) {
187 gclog_or_tty->print(" VerifyDuringGC:(full)[Verifying ");
188 }
189 Universe::heap()->verify(VerifySilently, VerifyOption_G1UseMarkWord);
190 if (!VerifySilently) {
191 gclog_or_tty->print_cr("]");
192 }
193 }
194
195 gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
196 }
197
198
199 void G1MarkSweep::mark_sweep_phase2() {
200 // Now all live objects are marked, compute the new object addresses.
201
202 // It is not required that we traverse spaces in the same order in
203 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
204 // tracking expects us to do so. See comment under phase4.
205
206 GCTraceTime tm("phase 2", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id());
207 GenMarkSweep::trace("2");
208
209 prepare_compaction();
|
84
85 // We should save the marks of the currently locked biased monitors.
86 // The marking doesn't preserve the marks of biased objects.
87 BiasedLocking::preserve_marks();
88
89 mark_sweep_phase1(marked_for_unloading, clear_all_softrefs);
90
91 mark_sweep_phase2();
92
93 // Don't add any more derived pointers during phase3
94 COMPILER2_PRESENT(DerivedPointerTable::set_active(false));
95
96 mark_sweep_phase3();
97
98 mark_sweep_phase4();
99
100 GenMarkSweep::restore_marks();
101 BiasedLocking::restore_marks();
102 GenMarkSweep::deallocate_stacks();
103
104 CodeCache::gc_epilogue();
105 JvmtiExport::gc_epilogue();
106
107 // refs processing: clean slate
108 GenMarkSweep::_ref_processor = NULL;
109 }
110
111
112 void G1MarkSweep::allocate_stacks() {
113 GenMarkSweep::_preserved_count_max = 0;
114 GenMarkSweep::_preserved_marks = NULL;
115 GenMarkSweep::_preserved_count = 0;
116 }
117
118 void G1MarkSweep::mark_sweep_phase1(bool& marked_for_unloading,
119 bool clear_all_softrefs) {
120 // Recursively traverse all live objects and mark them
121 GCTraceTime tm("phase 1", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id());
122 GenMarkSweep::trace(" 1");
123
145 &GenMarkSweep::follow_stack_closure,
146 NULL,
147 gc_timer(),
148 gc_tracer()->gc_id());
149 gc_tracer()->report_gc_reference_stats(stats);
150
151
152 // This is the point where the entire marking should have completed.
153 assert(GenMarkSweep::_marking_stack.is_empty(), "Marking should have completed");
154
155 // Unload classes and purge the SystemDictionary.
156 bool purged_class = SystemDictionary::do_unloading(&GenMarkSweep::is_alive);
157
158 // Unload nmethods.
159 CodeCache::do_unloading(&GenMarkSweep::is_alive, purged_class);
160
161 // Prune dead klasses from subklass/sibling/implementor lists.
162 Klass::clean_weak_klass_links(&GenMarkSweep::is_alive);
163
164 // Delete entries for dead interned string and clean up unreferenced symbols in symbol table.
165 g1h->unlink_string_and_symbol_table(&GenMarkSweep::is_alive);
166
167 if (VerifyDuringGC) {
168 HandleMark hm; // handle scope
169 COMPILER2_PRESENT(DerivedPointerTableDeactivate dpt_deact);
170 g1h->prepare_for_verify();
171 // Note: we can verify only the heap here. When an object is
172 // marked, the previous value of the mark word (including
173 // identity hash values, ages, etc) is preserved, and the mark
174 // word is set to markOop::marked_value - effectively removing
175 // any hash values from the mark word. These hash values are
176 // used when verifying the dictionaries and so removing them
177 // from the mark word can make verification of the dictionaries
178 // fail. At the end of the GC, the original mark word values
179 // (including hash values) are restored to the appropriate
180 // objects.
181 if (!VerifySilently) {
182 gclog_or_tty->print(" VerifyDuringGC:(full)[Verifying ");
183 }
184 g1h->verify(VerifySilently, VerifyOption_G1UseMarkWord);
185 if (!VerifySilently) {
186 gclog_or_tty->print_cr("]");
187 }
188 }
189
190 gc_tracer()->report_object_count_after_gc(&GenMarkSweep::is_alive);
191 }
192
193
194 void G1MarkSweep::mark_sweep_phase2() {
195 // Now all live objects are marked, compute the new object addresses.
196
197 // It is not required that we traverse spaces in the same order in
198 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
199 // tracking expects us to do so. See comment under phase4.
200
201 GCTraceTime tm("phase 2", G1Log::fine() && Verbose, true, gc_timer(), gc_tracer()->gc_id());
202 GenMarkSweep::trace("2");
203
204 prepare_compaction();
|