comparison src/share/vm/memory/genMarkSweep.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents d2a62e0f25eb
children 8966c2d65d96
comparison
equal deleted inserted replaced
6724:36d1d483d5d6 6725:da91efe96a93
76 _ref_processor = rp; 76 _ref_processor = rp;
77 rp->setup_policy(clear_all_softrefs); 77 rp->setup_policy(clear_all_softrefs);
78 78
79 TraceTime t1(GCCauseString("Full GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, gclog_or_tty); 79 TraceTime t1(GCCauseString("Full GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, gclog_or_tty);
80 80
81 // When collecting the permanent generation methodOops may be moving, 81 // When collecting the permanent generation Method*s may be moving,
82 // so we either have to flush all bcp data or convert it into bci. 82 // so we either have to flush all bcp data or convert it into bci.
83 CodeCache::gc_prologue(); 83 CodeCache::gc_prologue();
84 Threads::gc_prologue(); 84 Threads::gc_prologue();
85 85
86 // Increment the invocation count for the permanent generation, since it is 86 // Increment the invocation count
87 // implicitly collected whenever we do a full mark sweep collection. 87 _total_invocations++;
88 gch->perm_gen()->stat_record()->invocations++;
89 88
90 // Capture heap size before collection for printing. 89 // Capture heap size before collection for printing.
91 size_t gch_prev_used = gch->used(); 90 size_t gch_prev_used = gch->used();
92 91
93 // Some of the card table updates below assume that the perm gen is 92 // Some of the card table updates below assume that the perm gen is
96 "All generations are being collected, ergo perm gen too."); 95 "All generations are being collected, ergo perm gen too.");
97 96
98 // Capture used regions for each generation that will be 97 // Capture used regions for each generation that will be
99 // subject to collection, so that card table adjustments can 98 // subject to collection, so that card table adjustments can
100 // be made intelligently (see clear / invalidate further below). 99 // be made intelligently (see clear / invalidate further below).
101 gch->save_used_regions(level, true /* perm */); 100 gch->save_used_regions(level);
102 101
103 allocate_stacks(); 102 allocate_stacks();
104 103
105 mark_sweep_phase1(level, clear_all_softrefs); 104 mark_sweep_phase1(level, clear_all_softrefs);
106 105
147 GenRemSet* rs = gch->rem_set(); 146 GenRemSet* rs = gch->rem_set();
148 // Clear/invalidate below make use of the "prev_used_regions" saved earlier. 147 // Clear/invalidate below make use of the "prev_used_regions" saved earlier.
149 if (all_empty) { 148 if (all_empty) {
150 // We've evacuated all generations below us. 149 // We've evacuated all generations below us.
151 Generation* g = gch->get_gen(level); 150 Generation* g = gch->get_gen(level);
152 rs->clear_into_younger(g, true /* perm */); 151 rs->clear_into_younger(g);
153 } else { 152 } else {
154 // Invalidate the cards corresponding to the currently used 153 // Invalidate the cards corresponding to the currently used
155 // region and clear those corresponding to the evacuated region 154 // region and clear those corresponding to the evacuated region
156 // of all generations just collected (i.e. level and younger). 155 // of all generations just collected (i.e. level and younger).
157 rs->invalidate_or_clear(gch->get_gen(level), 156 rs->invalidate_or_clear(gch->get_gen(level),
158 true /* younger */, 157 true /* younger */);
159 true /* perm */);
160 } 158 }
161 159
162 Threads::gc_epilogue(); 160 Threads::gc_epilogue();
163 CodeCache::gc_epilogue(); 161 CodeCache::gc_epilogue();
164 JvmtiExport::gc_epilogue(); 162 JvmtiExport::gc_epilogue();
236 234
237 _preserved_mark_stack.clear(true); 235 _preserved_mark_stack.clear(true);
238 _preserved_oop_stack.clear(true); 236 _preserved_oop_stack.clear(true);
239 _marking_stack.clear(); 237 _marking_stack.clear();
240 _objarray_stack.clear(true); 238 _objarray_stack.clear(true);
241 _revisit_klass_stack.clear(true);
242 _revisit_mdo_stack.clear(true);
243 239
244 #ifdef VALIDATE_MARK_SWEEP 240 #ifdef VALIDATE_MARK_SWEEP
245 if (ValidateMarkSweep) { 241 if (ValidateMarkSweep) {
246 delete _root_refs_stack; 242 delete _root_refs_stack;
247 delete _other_refs_stack; 243 delete _other_refs_stack;
259 bool clear_all_softrefs) { 255 bool clear_all_softrefs) {
260 // Recursively traverse all live objects and mark them 256 // Recursively traverse all live objects and mark them
261 TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty); 257 TraceTime tm("phase 1", PrintGC && Verbose, true, gclog_or_tty);
262 trace(" 1"); 258 trace(" 1");
263 259
264 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false)); 260 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking());
265 261
266 GenCollectedHeap* gch = GenCollectedHeap::heap(); 262 GenCollectedHeap* gch = GenCollectedHeap::heap();
267 263
268 // Because follow_root_closure is created statically, cannot 264 // Because follow_root_closure is created statically, cannot
269 // use OopsInGenClosure constructor which takes a generation, 265 // use OopsInGenClosure constructor which takes a generation,
270 // as the Universe has not been created when the static constructors 266 // as the Universe has not been created when the static constructors
271 // are run. 267 // are run.
272 follow_root_closure.set_orig_generation(gch->get_gen(level)); 268 follow_root_closure.set_orig_generation(gch->get_gen(level));
273 269
270 // Need new claim bits before marking starts.
271 ClassLoaderDataGraph::clear_claimed_marks();
272
274 gch->gen_process_strong_roots(level, 273 gch->gen_process_strong_roots(level,
275 false, // Younger gens are not roots. 274 false, // Younger gens are not roots.
276 true, // activate StrongRootsScope 275 true, // activate StrongRootsScope
277 true, // Collecting permanent generation. 276 false, // not scavenging
278 SharedHeap::SO_SystemClasses, 277 SharedHeap::SO_SystemClasses,
279 &follow_root_closure, 278 &follow_root_closure,
280 true, // walk code active on stacks 279 true, // walk code active on stacks
281 &follow_root_closure); 280 &follow_root_closure,
281 &follow_klass_closure);
282 282
283 // Process reference objects found during marking 283 // Process reference objects found during marking
284 { 284 {
285 ref_processor()->setup_policy(clear_all_softrefs); 285 ref_processor()->setup_policy(clear_all_softrefs);
286 ref_processor()->process_discovered_references( 286 ref_processor()->process_discovered_references(
293 // Follow code cache roots 293 // Follow code cache roots
294 CodeCache::do_unloading(&is_alive, &keep_alive, purged_class); 294 CodeCache::do_unloading(&is_alive, &keep_alive, purged_class);
295 follow_stack(); // Flush marking stack 295 follow_stack(); // Flush marking stack
296 296
297 // Update subklass/sibling/implementor links of live klasses 297 // Update subklass/sibling/implementor links of live klasses
298 follow_weak_klass_links(); 298 Klass::clean_weak_klass_links(&is_alive);
299 assert(_marking_stack.is_empty(), "just drained");
300
301 // Visit memoized MDO's and clear any unmarked weak refs
302 follow_mdo_weak_refs();
303 assert(_marking_stack.is_empty(), "just drained"); 299 assert(_marking_stack.is_empty(), "just drained");
304 300
305 // Visit interned string tables and delete unmarked oops 301 // Visit interned string tables and delete unmarked oops
306 StringTable::unlink(&is_alive); 302 StringTable::unlink(&is_alive);
307 // Clean up unreferenced symbols in symbol table. 303 // Clean up unreferenced symbols in symbol table.
314 void GenMarkSweep::mark_sweep_phase2() { 310 void GenMarkSweep::mark_sweep_phase2() {
315 // Now all live objects are marked, compute the new object addresses. 311 // Now all live objects are marked, compute the new object addresses.
316 312
317 // It is imperative that we traverse perm_gen LAST. If dead space is 313 // It is imperative that we traverse perm_gen LAST. If dead space is
318 // allowed a range of dead object may get overwritten by a dead int 314 // allowed a range of dead object may get overwritten by a dead int
319 // array. If perm_gen is not traversed last a klassOop may get 315 // array. If perm_gen is not traversed last a Klass* may get
320 // overwritten. This is fine since it is dead, but if the class has dead 316 // overwritten. This is fine since it is dead, but if the class has dead
321 // instances we have to skip them, and in order to find their size we 317 // instances we have to skip them, and in order to find their size we
322 // need the klassOop! 318 // need the Klass*!
323 // 319 //
324 // It is not required that we traverse spaces in the same order in 320 // It is not required that we traverse spaces in the same order in
325 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops 321 // phase2, phase3 and phase4, but the ValidateMarkSweep live oops
326 // tracking expects us to do so. See comment under phase4. 322 // tracking expects us to do so. See comment under phase4.
327 323
328 GenCollectedHeap* gch = GenCollectedHeap::heap(); 324 GenCollectedHeap* gch = GenCollectedHeap::heap();
329 Generation* pg = gch->perm_gen();
330 325
331 TraceTime tm("phase 2", PrintGC && Verbose, true, gclog_or_tty); 326 TraceTime tm("phase 2", PrintGC && Verbose, true, gclog_or_tty);
332 trace("2"); 327 trace("2");
333 328
334 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false)); 329 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking());
335 330
336 gch->prepare_for_compaction(); 331 gch->prepare_for_compaction();
337
338 VALIDATE_MARK_SWEEP_ONLY(_live_oops_index_at_perm = _live_oops_index);
339 CompactPoint perm_cp(pg, NULL, NULL);
340 pg->prepare_for_compaction(&perm_cp);
341 } 332 }
342 333
343 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure { 334 class GenAdjustPointersClosure: public GenCollectedHeap::GenClosure {
344 public: 335 public:
345 void do_generation(Generation* gen) { 336 void do_generation(Generation* gen) {
347 } 338 }
348 }; 339 };
349 340
350 void GenMarkSweep::mark_sweep_phase3(int level) { 341 void GenMarkSweep::mark_sweep_phase3(int level) {
351 GenCollectedHeap* gch = GenCollectedHeap::heap(); 342 GenCollectedHeap* gch = GenCollectedHeap::heap();
352 Generation* pg = gch->perm_gen();
353 343
354 // Adjust the pointers to reflect the new locations 344 // Adjust the pointers to reflect the new locations
355 TraceTime tm("phase 3", PrintGC && Verbose, true, gclog_or_tty); 345 TraceTime tm("phase 3", PrintGC && Verbose, true, gclog_or_tty);
356 trace("3"); 346 trace("3");
357 347
358 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false)); 348 // Need new claim bits for the pointer adjustment tracing.
359 349 ClassLoaderDataGraph::clear_claimed_marks();
360 // Needs to be done before the system dictionary is adjusted. 350
361 pg->pre_adjust_pointers(); 351 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking());
362 352
363 // Because the two closures below are created statically, cannot 353 // Because the two closures below are created statically, cannot
364 // use OopsInGenClosure constructor which takes a generation, 354 // use OopsInGenClosure constructor which takes a generation,
365 // as the Universe has not been created when the static constructors 355 // as the Universe has not been created when the static constructors
366 // are run. 356 // are run.
368 adjust_pointer_closure.set_orig_generation(gch->get_gen(level)); 358 adjust_pointer_closure.set_orig_generation(gch->get_gen(level));
369 359
370 gch->gen_process_strong_roots(level, 360 gch->gen_process_strong_roots(level,
371 false, // Younger gens are not roots. 361 false, // Younger gens are not roots.
372 true, // activate StrongRootsScope 362 true, // activate StrongRootsScope
373 true, // Collecting permanent generation. 363 false, // not scavenging
374 SharedHeap::SO_AllClasses, 364 SharedHeap::SO_AllClasses,
375 &adjust_root_pointer_closure, 365 &adjust_root_pointer_closure,
376 false, // do not walk code 366 false, // do not walk code
377 &adjust_root_pointer_closure); 367 &adjust_root_pointer_closure,
368 &adjust_klass_closure);
378 369
379 // Now adjust pointers in remaining weak roots. (All of which should 370 // Now adjust pointers in remaining weak roots. (All of which should
380 // have been cleared if they pointed to non-surviving objects.) 371 // have been cleared if they pointed to non-surviving objects.)
381 CodeBlobToOopClosure adjust_code_pointer_closure(&adjust_pointer_closure, 372 CodeBlobToOopClosure adjust_code_pointer_closure(&adjust_pointer_closure,
382 /*do_marking=*/ false); 373 /*do_marking=*/ false);
385 &adjust_pointer_closure); 376 &adjust_pointer_closure);
386 377
387 adjust_marks(); 378 adjust_marks();
388 GenAdjustPointersClosure blk; 379 GenAdjustPointersClosure blk;
389 gch->generation_iterate(&blk, true); 380 gch->generation_iterate(&blk, true);
390 pg->adjust_pointers();
391 } 381 }
392 382
393 class GenCompactClosure: public GenCollectedHeap::GenClosure { 383 class GenCompactClosure: public GenCollectedHeap::GenClosure {
394 public: 384 public:
395 void do_generation(Generation* gen) { 385 void do_generation(Generation* gen) {
400 void GenMarkSweep::mark_sweep_phase4() { 390 void GenMarkSweep::mark_sweep_phase4() {
401 // All pointers are now adjusted, move objects accordingly 391 // All pointers are now adjusted, move objects accordingly
402 392
403 // It is imperative that we traverse perm_gen first in phase4. All 393 // It is imperative that we traverse perm_gen first in phase4. All
404 // classes must be allocated earlier than their instances, and traversing 394 // classes must be allocated earlier than their instances, and traversing
405 // perm_gen first makes sure that all klassOops have moved to their new 395 // perm_gen first makes sure that all Klass*s have moved to their new
406 // location before any instance does a dispatch through it's klass! 396 // location before any instance does a dispatch through it's klass!
407 397
408 // The ValidateMarkSweep live oops tracking expects us to traverse spaces 398 // The ValidateMarkSweep live oops tracking expects us to traverse spaces
409 // in the same order in phase2, phase3 and phase4. We don't quite do that 399 // in the same order in phase2, phase3 and phase4. We don't quite do that
410 // here (perm_gen first rather than last), so we tell the validate code 400 // here (perm_gen first rather than last), so we tell the validate code
411 // to use a higher index (saved from phase2) when verifying perm_gen. 401 // to use a higher index (saved from phase2) when verifying perm_gen.
412 GenCollectedHeap* gch = GenCollectedHeap::heap(); 402 GenCollectedHeap* gch = GenCollectedHeap::heap();
413 Generation* pg = gch->perm_gen();
414 403
415 TraceTime tm("phase 4", PrintGC && Verbose, true, gclog_or_tty); 404 TraceTime tm("phase 4", PrintGC && Verbose, true, gclog_or_tty);
416 trace("4"); 405 trace("4");
417 406
418 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(true)); 407 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking());
419
420 pg->compact();
421
422 VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
423 408
424 GenCompactClosure blk; 409 GenCompactClosure blk;
425 gch->generation_iterate(&blk, true); 410 gch->generation_iterate(&blk, true);
426 411
427 VALIDATE_MARK_SWEEP_ONLY(compaction_complete()); 412 VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
428 413 }
429 pg->post_compact(); // Shared spaces verification.
430 }