src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp

changeset 7659
38d6febe66af
parent 7658
c3fcc09c9239
child 7673
c04f46b4abe4
equal deleted inserted replaced
7658:c3fcc09c9239 7659:38d6febe66af
44 #include "gc_implementation/g1/g1MarkSweep.hpp" 44 #include "gc_implementation/g1/g1MarkSweep.hpp"
45 #include "gc_implementation/g1/g1OopClosures.inline.hpp" 45 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
46 #include "gc_implementation/g1/g1ParScanThreadState.inline.hpp" 46 #include "gc_implementation/g1/g1ParScanThreadState.inline.hpp"
47 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp" 47 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
48 #include "gc_implementation/g1/g1RemSet.inline.hpp" 48 #include "gc_implementation/g1/g1RemSet.inline.hpp"
49 #include "gc_implementation/g1/g1RootProcessor.hpp"
49 #include "gc_implementation/g1/g1StringDedup.hpp" 50 #include "gc_implementation/g1/g1StringDedup.hpp"
50 #include "gc_implementation/g1/g1YCTypes.hpp" 51 #include "gc_implementation/g1/g1YCTypes.hpp"
51 #include "gc_implementation/g1/heapRegion.inline.hpp" 52 #include "gc_implementation/g1/heapRegion.inline.hpp"
52 #include "gc_implementation/g1/heapRegionRemSet.hpp" 53 #include "gc_implementation/g1/heapRegionRemSet.hpp"
53 #include "gc_implementation/g1/heapRegionSet.inline.hpp" 54 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
82 // serialized by acquiring the HeapLock. This happens in mem_allocate 83 // serialized by acquiring the HeapLock. This happens in mem_allocate
83 // and allocate_new_tlab, which are the "entry" points to the 84 // and allocate_new_tlab, which are the "entry" points to the
84 // allocation code from the rest of the JVM. (Note that this does not 85 // allocation code from the rest of the JVM. (Note that this does not
85 // apply to TLAB allocation, which is not part of this interface: it 86 // apply to TLAB allocation, which is not part of this interface: it
86 // is done by clients of this interface.) 87 // is done by clients of this interface.)
87
88 // Notes on implementation of parallelism in different tasks.
89 //
90 // G1ParVerifyTask uses heap_region_par_iterate_chunked() for parallelism.
91 // The number of GC workers is passed to heap_region_par_iterate_chunked().
92 // It does use run_task() which sets _n_workers in the task.
93 // G1ParTask executes g1_process_roots() ->
94 // SharedHeap::process_roots() which calls eventually to
95 // CardTableModRefBS::par_non_clean_card_iterate_work() which uses
96 // SequentialSubTasksDone. SharedHeap::process_roots() also
97 // directly uses SubTasksDone (_process_strong_tasks field in SharedHeap).
98 //
99 88
100 // Local to this file. 89 // Local to this file.
101 90
102 class RefineCardTableEntryClosure: public CardTableEntryClosure { 91 class RefineCardTableEntryClosure: public CardTableEntryClosure {
103 bool _concurrent; 92 bool _concurrent;
1852 _into_cset_dirty_card_queue_set(false), 1841 _into_cset_dirty_card_queue_set(false),
1853 _is_alive_closure_cm(this), 1842 _is_alive_closure_cm(this),
1854 _is_alive_closure_stw(this), 1843 _is_alive_closure_stw(this),
1855 _ref_processor_cm(NULL), 1844 _ref_processor_cm(NULL),
1856 _ref_processor_stw(NULL), 1845 _ref_processor_stw(NULL),
1857 _process_strong_tasks(new SubTasksDone(G1H_PS_NumElements)),
1858 _bot_shared(NULL), 1846 _bot_shared(NULL),
1859 _evac_failure_scan_stack(NULL), 1847 _evac_failure_scan_stack(NULL),
1860 _mark_in_progress(false), 1848 _mark_in_progress(false),
1861 _cg1r(NULL), 1849 _cg1r(NULL),
1862 _g1mm(NULL), 1850 _g1mm(NULL),
1886 _gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()), 1874 _gc_timer_cm(new (ResourceObj::C_HEAP, mtGC) ConcurrentGCTimer()),
1887 _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()), 1875 _gc_tracer_stw(new (ResourceObj::C_HEAP, mtGC) G1NewTracer()),
1888 _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) G1OldTracer()) { 1876 _gc_tracer_cm(new (ResourceObj::C_HEAP, mtGC) G1OldTracer()) {
1889 1877
1890 _g1h = this; 1878 _g1h = this;
1891 if (_process_strong_tasks == NULL || !_process_strong_tasks->valid()) {
1892 vm_exit_during_initialization("Failed necessary allocation.");
1893 }
1894 1879
1895 _allocator = G1Allocator::create_allocator(_g1h); 1880 _allocator = G1Allocator::create_allocator(_g1h);
1896 _humongous_object_threshold_in_words = HeapRegion::GrainWords / 2; 1881 _humongous_object_threshold_in_words = HeapRegion::GrainWords / 2;
1897 1882
1898 int n_queues = MAX2((int)ParallelGCThreads, 1); 1883 int n_queues = MAX2((int)ParallelGCThreads, 1);
3301 // system dictionary, class loader data graph, the string table 3286 // system dictionary, class loader data graph, the string table
3302 // and the nmethods in the code cache. 3287 // and the nmethods in the code cache.
3303 G1VerifyCodeRootOopClosure codeRootsCl(this, &rootsCl, vo); 3288 G1VerifyCodeRootOopClosure codeRootsCl(this, &rootsCl, vo);
3304 G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl); 3289 G1VerifyCodeRootBlobClosure blobsCl(&codeRootsCl);
3305 3290
3306 process_all_roots(true, // activate StrongRootsScope 3291 {
3307 SO_AllCodeCache, // roots scanning options 3292 G1RootProcessor root_processor(this);
3308 &rootsCl, 3293 root_processor.process_all_roots(&rootsCl,
3309 &cldCl, 3294 &cldCl,
3310 &blobsCl); 3295 &blobsCl);
3296 }
3311 3297
3312 bool failures = rootsCl.failures() || codeRootsCl.failures(); 3298 bool failures = rootsCl.failures() || codeRootsCl.failures();
3313 3299
3314 if (vo != VerifyOption_G1UseMarkWord) { 3300 if (vo != VerifyOption_G1UseMarkWord) {
3315 // If we're verifying during a full GC then the region sets 3301 // If we're verifying during a full GC then the region sets
4541 } 4527 }
4542 _count++; 4528 _count++;
4543 } 4529 }
4544 }; 4530 };
4545 4531
4546 class G1CodeBlobClosure : public CodeBlobClosure {
4547 class HeapRegionGatheringOopClosure : public OopClosure {
4548 G1CollectedHeap* _g1h;
4549 OopClosure* _work;
4550 nmethod* _nm;
4551
4552 template <typename T>
4553 void do_oop_work(T* p) {
4554 _work->do_oop(p);
4555 T oop_or_narrowoop = oopDesc::load_heap_oop(p);
4556 if (!oopDesc::is_null(oop_or_narrowoop)) {
4557 oop o = oopDesc::decode_heap_oop_not_null(oop_or_narrowoop);
4558 HeapRegion* hr = _g1h->heap_region_containing_raw(o);
4559 assert(!_g1h->obj_in_cs(o) || hr->rem_set()->strong_code_roots_list_contains(_nm), "if o still in CS then evacuation failed and nm must already be in the remset");
4560 hr->add_strong_code_root(_nm);
4561 }
4562 }
4563
4564 public:
4565 HeapRegionGatheringOopClosure(OopClosure* oc) : _g1h(G1CollectedHeap::heap()), _work(oc), _nm(NULL) {}
4566
4567 void do_oop(oop* o) {
4568 do_oop_work(o);
4569 }
4570
4571 void do_oop(narrowOop* o) {
4572 do_oop_work(o);
4573 }
4574
4575 void set_nm(nmethod* nm) {
4576 _nm = nm;
4577 }
4578 };
4579
4580 HeapRegionGatheringOopClosure _oc;
4581 public:
4582 G1CodeBlobClosure(OopClosure* oc) : _oc(oc) {}
4583
4584 void do_code_blob(CodeBlob* cb) {
4585 nmethod* nm = cb->as_nmethod_or_null();
4586 if (nm != NULL) {
4587 if (!nm->test_set_oops_do_mark()) {
4588 _oc.set_nm(nm);
4589 nm->oops_do(&_oc);
4590 nm->fix_oop_relocations();
4591 }
4592 }
4593 }
4594 };
4595
4596 class G1ParTask : public AbstractGangTask { 4532 class G1ParTask : public AbstractGangTask {
4597 protected: 4533 protected:
4598 G1CollectedHeap* _g1h; 4534 G1CollectedHeap* _g1h;
4599 RefToScanQueueSet *_queues; 4535 RefToScanQueueSet *_queues;
4536 G1RootProcessor* _root_processor;
4600 ParallelTaskTerminator _terminator; 4537 ParallelTaskTerminator _terminator;
4601 uint _n_workers; 4538 uint _n_workers;
4602 4539
4603 Mutex _stats_lock; 4540 Mutex _stats_lock;
4604 Mutex* stats_lock() { return &_stats_lock; } 4541 Mutex* stats_lock() { return &_stats_lock; }
4605 4542
4606 public: 4543 public:
4607 G1ParTask(G1CollectedHeap* g1h, RefToScanQueueSet *task_queues) 4544 G1ParTask(G1CollectedHeap* g1h, RefToScanQueueSet *task_queues, G1RootProcessor* root_processor)
4608 : AbstractGangTask("G1 collection"), 4545 : AbstractGangTask("G1 collection"),
4609 _g1h(g1h), 4546 _g1h(g1h),
4610 _queues(task_queues), 4547 _queues(task_queues),
4548 _root_processor(root_processor),
4611 _terminator(0, _queues), 4549 _terminator(0, _queues),
4612 _stats_lock(Mutex::leaf, "parallel G1 stats lock", true) 4550 _stats_lock(Mutex::leaf, "parallel G1 stats lock", true)
4613 {} 4551 {}
4614 4552
4615 RefToScanQueueSet* queues() { return _queues; } 4553 RefToScanQueueSet* queues() { return _queues; }
4619 } 4557 }
4620 4558
4621 ParallelTaskTerminator* terminator() { return &_terminator; } 4559 ParallelTaskTerminator* terminator() { return &_terminator; }
4622 4560
4623 virtual void set_for_termination(int active_workers) { 4561 virtual void set_for_termination(int active_workers) {
4624 // This task calls set_n_termination() in par_non_clean_card_iterate_work() 4562 _root_processor->set_num_workers(active_workers);
4625 // in the young space (_par_seq_tasks) in the G1 heap
4626 // for SequentialSubTasksDone.
4627 // This task also uses SubTasksDone in SharedHeap and G1CollectedHeap
4628 // both of which need setting by set_n_termination().
4629 _g1h->SharedHeap::set_n_termination(active_workers);
4630 _g1h->set_n_termination(active_workers);
4631 terminator()->reset_for_reuse(active_workers); 4563 terminator()->reset_for_reuse(active_workers);
4632 _n_workers = active_workers; 4564 _n_workers = active_workers;
4633 } 4565 }
4634 4566
4635 // Helps out with CLD processing. 4567 // Helps out with CLD processing.
4694 G1ParCopyClosure<G1BarrierNone, G1MarkPromotedFromRoot> scan_mark_weak_root_cl(_g1h, &pss, rp); 4626 G1ParCopyClosure<G1BarrierNone, G1MarkPromotedFromRoot> scan_mark_weak_root_cl(_g1h, &pss, rp);
4695 G1CLDClosure<G1MarkPromotedFromRoot> scan_mark_weak_cld_cl(&scan_mark_weak_root_cl, 4627 G1CLDClosure<G1MarkPromotedFromRoot> scan_mark_weak_cld_cl(&scan_mark_weak_root_cl,
4696 false, // Process all klasses. 4628 false, // Process all klasses.
4697 true); // Need to claim CLDs. 4629 true); // Need to claim CLDs.
4698 4630
4699 G1CodeBlobClosure scan_only_code_cl(&scan_only_root_cl);
4700 G1CodeBlobClosure scan_mark_code_cl(&scan_mark_root_cl);
4701 // IM Weak code roots are handled later.
4702
4703 OopClosure* strong_root_cl; 4631 OopClosure* strong_root_cl;
4704 OopClosure* weak_root_cl; 4632 OopClosure* weak_root_cl;
4705 CLDClosure* strong_cld_cl; 4633 CLDClosure* strong_cld_cl;
4706 CLDClosure* weak_cld_cl; 4634 CLDClosure* weak_cld_cl;
4707 CodeBlobClosure* strong_code_cl; 4635
4636 bool trace_metadata = false;
4708 4637
4709 if (_g1h->g1_policy()->during_initial_mark_pause()) { 4638 if (_g1h->g1_policy()->during_initial_mark_pause()) {
4710 // We also need to mark copied objects. 4639 // We also need to mark copied objects.
4711 strong_root_cl = &scan_mark_root_cl; 4640 strong_root_cl = &scan_mark_root_cl;
4712 strong_cld_cl = &scan_mark_cld_cl; 4641 strong_cld_cl = &scan_mark_cld_cl;
4713 strong_code_cl = &scan_mark_code_cl;
4714 if (ClassUnloadingWithConcurrentMark) { 4642 if (ClassUnloadingWithConcurrentMark) {
4715 weak_root_cl = &scan_mark_weak_root_cl; 4643 weak_root_cl = &scan_mark_weak_root_cl;
4716 weak_cld_cl = &scan_mark_weak_cld_cl; 4644 weak_cld_cl = &scan_mark_weak_cld_cl;
4645 trace_metadata = true;
4717 } else { 4646 } else {
4718 weak_root_cl = &scan_mark_root_cl; 4647 weak_root_cl = &scan_mark_root_cl;
4719 weak_cld_cl = &scan_mark_cld_cl; 4648 weak_cld_cl = &scan_mark_cld_cl;
4720 } 4649 }
4721 } else { 4650 } else {
4722 strong_root_cl = &scan_only_root_cl; 4651 strong_root_cl = &scan_only_root_cl;
4723 weak_root_cl = &scan_only_root_cl; 4652 weak_root_cl = &scan_only_root_cl;
4724 strong_cld_cl = &scan_only_cld_cl; 4653 strong_cld_cl = &scan_only_cld_cl;
4725 weak_cld_cl = &scan_only_cld_cl; 4654 weak_cld_cl = &scan_only_cld_cl;
4726 strong_code_cl = &scan_only_code_cl;
4727 } 4655 }
4728 4656
4729
4730 G1ParPushHeapRSClosure push_heap_rs_cl(_g1h, &pss);
4731
4732 pss.start_strong_roots(); 4657 pss.start_strong_roots();
4733 _g1h->g1_process_roots(strong_root_cl, 4658
4734 weak_root_cl, 4659 _root_processor->evacuate_roots(strong_root_cl,
4735 &push_heap_rs_cl, 4660 weak_root_cl,
4736 strong_cld_cl, 4661 strong_cld_cl,
4737 weak_cld_cl, 4662 weak_cld_cl,
4738 strong_code_cl, 4663 trace_metadata,
4739 worker_id); 4664 worker_id);
4740 4665
4666 G1ParPushHeapRSClosure push_heap_rs_cl(_g1h, &pss);
4667 _root_processor->scan_remembered_sets(&push_heap_rs_cl,
4668 weak_root_cl,
4669 worker_id);
4741 pss.end_strong_roots(); 4670 pss.end_strong_roots();
4742 4671
4743 { 4672 {
4744 double start = os::elapsedTime(); 4673 double start = os::elapsedTime();
4745 G1ParEvacuateFollowersClosure evac(_g1h, &pss, _queues, &_terminator); 4674 G1ParEvacuateFollowersClosure evac(_g1h, &pss, _queues, &_terminator);
4765 // "GC Worker Time". 4694 // "GC Worker Time".
4766 } 4695 }
4767 _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::GCWorkerEnd, worker_id, os::elapsedTime()); 4696 _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::GCWorkerEnd, worker_id, os::elapsedTime());
4768 } 4697 }
4769 }; 4698 };
4770
4771 // *** Common G1 Evacuation Stuff
4772
4773 // This method is run in a GC worker.
4774
4775 void
4776 G1CollectedHeap::
4777 g1_process_roots(OopClosure* scan_non_heap_roots,
4778 OopClosure* scan_non_heap_weak_roots,
4779 G1ParPushHeapRSClosure* scan_rs,
4780 CLDClosure* scan_strong_clds,
4781 CLDClosure* scan_weak_clds,
4782 CodeBlobClosure* scan_strong_code,
4783 uint worker_i) {
4784
4785 // First scan the shared roots.
4786 double ext_roots_start = os::elapsedTime();
4787 double closure_app_time_sec = 0.0;
4788
4789 bool during_im = _g1h->g1_policy()->during_initial_mark_pause();
4790 bool trace_metadata = during_im && ClassUnloadingWithConcurrentMark;
4791
4792 BufferingOopClosure buf_scan_non_heap_roots(scan_non_heap_roots);
4793 BufferingOopClosure buf_scan_non_heap_weak_roots(scan_non_heap_weak_roots);
4794
4795 process_roots(false, // no scoping; this is parallel code
4796 SharedHeap::SO_None,
4797 &buf_scan_non_heap_roots,
4798 &buf_scan_non_heap_weak_roots,
4799 scan_strong_clds,
4800 // Unloading Initial Marks handle the weak CLDs separately.
4801 (trace_metadata ? NULL : scan_weak_clds),
4802 scan_strong_code);
4803
4804 // Now the CM ref_processor roots.
4805 if (!_process_strong_tasks->is_task_claimed(G1H_PS_refProcessor_oops_do)) {
4806 // We need to treat the discovered reference lists of the
4807 // concurrent mark ref processor as roots and keep entries
4808 // (which are added by the marking threads) on them live
4809 // until they can be processed at the end of marking.
4810 ref_processor_cm()->weak_oops_do(&buf_scan_non_heap_roots);
4811 }
4812
4813 if (trace_metadata) {
4814 // Barrier to make sure all workers passed
4815 // the strong CLD and strong nmethods phases.
4816 active_strong_roots_scope()->wait_until_all_workers_done_with_threads(n_par_threads());
4817
4818 // Now take the complement of the strong CLDs.
4819 ClassLoaderDataGraph::roots_cld_do(NULL, scan_weak_clds);
4820 }
4821
4822 // Finish up any enqueued closure apps (attributed as object copy time).
4823 buf_scan_non_heap_roots.done();
4824 buf_scan_non_heap_weak_roots.done();
4825
4826 double obj_copy_time_sec = buf_scan_non_heap_roots.closure_app_seconds()
4827 + buf_scan_non_heap_weak_roots.closure_app_seconds();
4828
4829 g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::ObjCopy, worker_i, obj_copy_time_sec);
4830
4831 double ext_root_time_sec = os::elapsedTime() - ext_roots_start - obj_copy_time_sec;
4832 g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::ExtRootScan, worker_i, ext_root_time_sec);
4833
4834 // During conc marking we have to filter the per-thread SATB buffers
4835 // to make sure we remove any oops into the CSet (which will show up
4836 // as implicitly live).
4837 {
4838 G1GCParPhaseTimesTracker x(g1_policy()->phase_times(), G1GCPhaseTimes::SATBFiltering, worker_i);
4839 if (!_process_strong_tasks->is_task_claimed(G1H_PS_filter_satb_buffers) && mark_in_progress()) {
4840 JavaThread::satb_mark_queue_set().filter_thread_buffers();
4841 }
4842 }
4843
4844 // Now scan the complement of the collection set.
4845 G1CodeBlobClosure scavenge_cs_nmethods(scan_non_heap_weak_roots);
4846
4847 g1_rem_set()->oops_into_collection_set_do(scan_rs, &scavenge_cs_nmethods, worker_i);
4848
4849 _process_strong_tasks->all_tasks_completed();
4850 }
4851 4699
4852 class G1StringSymbolTableUnlinkTask : public AbstractGangTask { 4700 class G1StringSymbolTableUnlinkTask : public AbstractGangTask {
4853 private: 4701 private:
4854 BoolObjectClosure* _is_alive; 4702 BoolObjectClosure* _is_alive;
4855 int _initial_string_table_size; 4703 int _initial_string_table_size;
5834 assert(n_par_threads() == 0, 5682 assert(n_par_threads() == 0,
5835 "Should be the original non-parallel value"); 5683 "Should be the original non-parallel value");
5836 n_workers = 1; 5684 n_workers = 1;
5837 } 5685 }
5838 5686
5839 G1ParTask g1_par_task(this, _task_queues);
5840 5687
5841 init_for_evac_failure(NULL); 5688 init_for_evac_failure(NULL);
5842 5689
5843 rem_set()->prepare_for_younger_refs_iterate(true); 5690 rem_set()->prepare_for_younger_refs_iterate(true);
5844 5691
5845 assert(dirty_card_queue_set().completed_buffers_num() == 0, "Should be empty"); 5692 assert(dirty_card_queue_set().completed_buffers_num() == 0, "Should be empty");
5846 double start_par_time_sec = os::elapsedTime(); 5693 double start_par_time_sec = os::elapsedTime();
5847 double end_par_time_sec; 5694 double end_par_time_sec;
5848 5695
5849 { 5696 {
5850 StrongRootsScope srs(this); 5697 G1RootProcessor root_processor(this);
5698 G1ParTask g1_par_task(this, _task_queues, &root_processor);
5851 // InitialMark needs claim bits to keep track of the marked-through CLDs. 5699 // InitialMark needs claim bits to keep track of the marked-through CLDs.
5852 if (g1_policy()->during_initial_mark_pause()) { 5700 if (g1_policy()->during_initial_mark_pause()) {
5853 ClassLoaderDataGraph::clear_claimed_marks(); 5701 ClassLoaderDataGraph::clear_claimed_marks();
5854 } 5702 }
5855 5703
5866 g1_par_task.work(0); 5714 g1_par_task.work(0);
5867 } 5715 }
5868 end_par_time_sec = os::elapsedTime(); 5716 end_par_time_sec = os::elapsedTime();
5869 5717
5870 // Closing the inner scope will execute the destructor 5718 // Closing the inner scope will execute the destructor
5871 // for the StrongRootsScope object. We record the current 5719 // for the G1RootProcessor object. We record the current
5872 // elapsed time before closing the scope so that time 5720 // elapsed time before closing the scope so that time
5873 // taken for the SRS destructor is NOT included in the 5721 // taken for the destructor is NOT included in the
5874 // reported parallel time. 5722 // reported parallel time.
5875 } 5723 }
5876 5724
5877 G1GCPhaseTimes* phase_times = g1_policy()->phase_times(); 5725 G1GCPhaseTimes* phase_times = g1_policy()->phase_times();
5878 5726

mercurial