comparison src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 4093:6071e0581859

7111795: G1: Various cleanups identified during walk through of changes for 6484965 Summary: Various cleanups and formatting changes identified during a code walk through of the changes for 6484965 ("G1: piggy-back liveness accounting phase on marking"). Reviewed-by: brutisso, tonyp
author johnc
date Fri, 18 Nov 2011 12:27:10 -0800
parents 8aae2050e83e
children bca17e38de00
comparison
equal deleted inserted replaced
4092:b5a5f30c483d 4093:6071e0581859
42 #include "runtime/java.hpp" 42 #include "runtime/java.hpp"
43 43
44 // 44 //
45 // CMS Bit Map Wrapper 45 // CMS Bit Map Wrapper
46 46
47 CMBitMapRO::CMBitMapRO(ReservedSpace rs, int shifter): 47 CMBitMapRO::CMBitMapRO(ReservedSpace rs, int shifter) :
48 _bm((uintptr_t*)NULL,0), 48 _bm((uintptr_t*)NULL,0),
49 _shifter(shifter) { 49 _shifter(shifter) {
50 _bmStartWord = (HeapWord*)(rs.base()); 50 _bmStartWord = (HeapWord*)(rs.base());
51 _bmWordSize = rs.size()/HeapWordSize; // rs.size() is in bytes 51 _bmWordSize = rs.size()/HeapWordSize; // rs.size() is in bytes
52 ReservedSpace brs(ReservedSpace::allocation_align_size_up( 52 ReservedSpace brs(ReservedSpace::allocation_align_size_up(
1528 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1, 1528 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1,
1529 int worker_num, 1529 int worker_num,
1530 FreeRegionList* local_cleanup_list, 1530 FreeRegionList* local_cleanup_list,
1531 OldRegionSet* old_proxy_set, 1531 OldRegionSet* old_proxy_set,
1532 HumongousRegionSet* humongous_proxy_set, 1532 HumongousRegionSet* humongous_proxy_set,
1533 HRRSCleanupTask* hrrs_cleanup_task); 1533 HRRSCleanupTask* hrrs_cleanup_task) :
1534 _g1(g1), _worker_num(worker_num),
1535 _max_live_bytes(0), _regions_claimed(0),
1536 _freed_bytes(0),
1537 _claimed_region_time(0.0), _max_region_time(0.0),
1538 _local_cleanup_list(local_cleanup_list),
1539 _old_proxy_set(old_proxy_set),
1540 _humongous_proxy_set(humongous_proxy_set),
1541 _hrrs_cleanup_task(hrrs_cleanup_task) { }
1542
1534 size_t freed_bytes() { return _freed_bytes; } 1543 size_t freed_bytes() { return _freed_bytes; }
1535 1544
1536 bool doHeapRegion(HeapRegion *r); 1545 bool doHeapRegion(HeapRegion *hr) {
1546 // We use a claim value of zero here because all regions
1547 // were claimed with value 1 in the FinalCount task.
1548 hr->reset_gc_time_stamp();
1549 if (!hr->continuesHumongous()) {
1550 double start = os::elapsedTime();
1551 _regions_claimed++;
1552 hr->note_end_of_marking();
1553 _max_live_bytes += hr->max_live_bytes();
1554 _g1->free_region_if_empty(hr,
1555 &_freed_bytes,
1556 _local_cleanup_list,
1557 _old_proxy_set,
1558 _humongous_proxy_set,
1559 _hrrs_cleanup_task,
1560 true /* par */);
1561 double region_time = (os::elapsedTime() - start);
1562 _claimed_region_time += region_time;
1563 if (region_time > _max_region_time) {
1564 _max_region_time = region_time;
1565 }
1566 }
1567 return false;
1568 }
1537 1569
1538 size_t max_live_bytes() { return _max_live_bytes; } 1570 size_t max_live_bytes() { return _max_live_bytes; }
1539 size_t regions_claimed() { return _regions_claimed; } 1571 size_t regions_claimed() { return _regions_claimed; }
1540 double claimed_region_time_sec() { return _claimed_region_time; } 1572 double claimed_region_time_sec() { return _claimed_region_time; }
1541 double max_region_time_sec() { return _max_region_time; } 1573 double max_region_time_sec() { return _max_region_time; }
1641 _g1rs->scrub(_region_bm, _card_bm); 1673 _g1rs->scrub(_region_bm, _card_bm);
1642 } 1674 }
1643 } 1675 }
1644 1676
1645 }; 1677 };
1646
1647 G1NoteEndOfConcMarkClosure::
1648 G1NoteEndOfConcMarkClosure(G1CollectedHeap* g1,
1649 int worker_num,
1650 FreeRegionList* local_cleanup_list,
1651 OldRegionSet* old_proxy_set,
1652 HumongousRegionSet* humongous_proxy_set,
1653 HRRSCleanupTask* hrrs_cleanup_task)
1654 : _g1(g1), _worker_num(worker_num),
1655 _max_live_bytes(0), _regions_claimed(0),
1656 _freed_bytes(0),
1657 _claimed_region_time(0.0), _max_region_time(0.0),
1658 _local_cleanup_list(local_cleanup_list),
1659 _old_proxy_set(old_proxy_set),
1660 _humongous_proxy_set(humongous_proxy_set),
1661 _hrrs_cleanup_task(hrrs_cleanup_task) { }
1662
1663 bool G1NoteEndOfConcMarkClosure::doHeapRegion(HeapRegion *hr) {
1664 // We use a claim value of zero here because all regions
1665 // were claimed with value 1 in the FinalCount task.
1666 hr->reset_gc_time_stamp();
1667 if (!hr->continuesHumongous()) {
1668 double start = os::elapsedTime();
1669 _regions_claimed++;
1670 hr->note_end_of_marking();
1671 _max_live_bytes += hr->max_live_bytes();
1672 _g1->free_region_if_empty(hr,
1673 &_freed_bytes,
1674 _local_cleanup_list,
1675 _old_proxy_set,
1676 _humongous_proxy_set,
1677 _hrrs_cleanup_task,
1678 true /* par */);
1679 double region_time = (os::elapsedTime() - start);
1680 _claimed_region_time += region_time;
1681 if (region_time > _max_region_time) {
1682 _max_region_time = region_time;
1683 }
1684 }
1685 return false;
1686 }
1687 1678
1688 void ConcurrentMark::cleanup() { 1679 void ConcurrentMark::cleanup() {
1689 // world is stopped at this checkpoint 1680 // world is stopped at this checkpoint
1690 assert(SafepointSynchronize::is_at_safepoint(), 1681 assert(SafepointSynchronize::is_at_safepoint(),
1691 "world should be stopped"); 1682 "world should be stopped");
1989 // workers. Using a CMTask (and its embedded local data structures) 1980 // workers. Using a CMTask (and its embedded local data structures)
1990 // avoids that potential interference. 1981 // avoids that potential interference.
1991 class G1CMParKeepAliveAndDrainClosure: public OopClosure { 1982 class G1CMParKeepAliveAndDrainClosure: public OopClosure {
1992 ConcurrentMark* _cm; 1983 ConcurrentMark* _cm;
1993 CMTask* _task; 1984 CMTask* _task;
1994 CMBitMap* _bitMap;
1995 int _ref_counter_limit; 1985 int _ref_counter_limit;
1996 int _ref_counter; 1986 int _ref_counter;
1997 public: 1987 public:
1998 G1CMParKeepAliveAndDrainClosure(ConcurrentMark* cm, 1988 G1CMParKeepAliveAndDrainClosure(ConcurrentMark* cm, CMTask* task) :
1999 CMTask* task, 1989 _cm(cm), _task(task),
2000 CMBitMap* bitMap) : 1990 _ref_counter_limit(G1RefProcDrainInterval) {
2001 _cm(cm), _task(task), _bitMap(bitMap),
2002 _ref_counter_limit(G1RefProcDrainInterval)
2003 {
2004 assert(_ref_counter_limit > 0, "sanity"); 1991 assert(_ref_counter_limit > 0, "sanity");
2005 _ref_counter = _ref_counter_limit; 1992 _ref_counter = _ref_counter_limit;
2006 } 1993 }
2007 1994
2008 virtual void do_oop(narrowOop* p) { do_oop_work(p); } 1995 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
2089 2076
2090 class G1CMRefProcTaskExecutor: public AbstractRefProcTaskExecutor { 2077 class G1CMRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
2091 private: 2078 private:
2092 G1CollectedHeap* _g1h; 2079 G1CollectedHeap* _g1h;
2093 ConcurrentMark* _cm; 2080 ConcurrentMark* _cm;
2094 CMBitMap* _bitmap;
2095 WorkGang* _workers; 2081 WorkGang* _workers;
2096 int _active_workers; 2082 int _active_workers;
2097 2083
2098 public: 2084 public:
2099 G1CMRefProcTaskExecutor(G1CollectedHeap* g1h, 2085 G1CMRefProcTaskExecutor(G1CollectedHeap* g1h,
2100 ConcurrentMark* cm, 2086 ConcurrentMark* cm,
2101 CMBitMap* bitmap,
2102 WorkGang* workers, 2087 WorkGang* workers,
2103 int n_workers) : 2088 int n_workers) :
2104 _g1h(g1h), _cm(cm), _bitmap(bitmap), 2089 _g1h(g1h), _cm(cm),
2105 _workers(workers), _active_workers(n_workers) 2090 _workers(workers), _active_workers(n_workers) { }
2106 { }
2107 2091
2108 // Executes the given task using concurrent marking worker threads. 2092 // Executes the given task using concurrent marking worker threads.
2109 virtual void execute(ProcessTask& task); 2093 virtual void execute(ProcessTask& task);
2110 virtual void execute(EnqueueTask& task); 2094 virtual void execute(EnqueueTask& task);
2111 }; 2095 };
2113 class G1CMRefProcTaskProxy: public AbstractGangTask { 2097 class G1CMRefProcTaskProxy: public AbstractGangTask {
2114 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; 2098 typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
2115 ProcessTask& _proc_task; 2099 ProcessTask& _proc_task;
2116 G1CollectedHeap* _g1h; 2100 G1CollectedHeap* _g1h;
2117 ConcurrentMark* _cm; 2101 ConcurrentMark* _cm;
2118 CMBitMap* _bitmap;
2119 2102
2120 public: 2103 public:
2121 G1CMRefProcTaskProxy(ProcessTask& proc_task, 2104 G1CMRefProcTaskProxy(ProcessTask& proc_task,
2122 G1CollectedHeap* g1h, 2105 G1CollectedHeap* g1h,
2123 ConcurrentMark* cm, 2106 ConcurrentMark* cm) :
2124 CMBitMap* bitmap) :
2125 AbstractGangTask("Process reference objects in parallel"), 2107 AbstractGangTask("Process reference objects in parallel"),
2126 _proc_task(proc_task), _g1h(g1h), _cm(cm), _bitmap(bitmap) 2108 _proc_task(proc_task), _g1h(g1h), _cm(cm) { }
2127 {}
2128 2109
2129 virtual void work(int i) { 2110 virtual void work(int i) {
2130 CMTask* marking_task = _cm->task(i); 2111 CMTask* marking_task = _cm->task(i);
2131 G1CMIsAliveClosure g1_is_alive(_g1h); 2112 G1CMIsAliveClosure g1_is_alive(_g1h);
2132 G1CMParKeepAliveAndDrainClosure g1_par_keep_alive(_cm, marking_task, _bitmap); 2113 G1CMParKeepAliveAndDrainClosure g1_par_keep_alive(_cm, marking_task);
2133 G1CMParDrainMarkingStackClosure g1_par_drain(_cm, marking_task); 2114 G1CMParDrainMarkingStackClosure g1_par_drain(_cm, marking_task);
2134 2115
2135 _proc_task.work(i, g1_is_alive, g1_par_keep_alive, g1_par_drain); 2116 _proc_task.work(i, g1_is_alive, g1_par_keep_alive, g1_par_drain);
2136 } 2117 }
2137 }; 2118 };
2138 2119
2139 void G1CMRefProcTaskExecutor::execute(ProcessTask& proc_task) { 2120 void G1CMRefProcTaskExecutor::execute(ProcessTask& proc_task) {
2140 assert(_workers != NULL, "Need parallel worker threads."); 2121 assert(_workers != NULL, "Need parallel worker threads.");
2141 2122
2142 G1CMRefProcTaskProxy proc_task_proxy(proc_task, _g1h, _cm, _bitmap); 2123 G1CMRefProcTaskProxy proc_task_proxy(proc_task, _g1h, _cm);
2143 2124
2144 // We need to reset the phase for each task execution so that 2125 // We need to reset the phase for each task execution so that
2145 // the termination protocol of CMTask::do_marking_step works. 2126 // the termination protocol of CMTask::do_marking_step works.
2146 _cm->set_phase(_active_workers, false /* concurrent */); 2127 _cm->set_phase(_active_workers, false /* concurrent */);
2147 _g1h->set_par_threads(_active_workers); 2128 _g1h->set_par_threads(_active_workers);
2154 EnqueueTask& _enq_task; 2135 EnqueueTask& _enq_task;
2155 2136
2156 public: 2137 public:
2157 G1CMRefEnqueueTaskProxy(EnqueueTask& enq_task) : 2138 G1CMRefEnqueueTaskProxy(EnqueueTask& enq_task) :
2158 AbstractGangTask("Enqueue reference objects in parallel"), 2139 AbstractGangTask("Enqueue reference objects in parallel"),
2159 _enq_task(enq_task) 2140 _enq_task(enq_task) { }
2160 { }
2161 2141
2162 virtual void work(int i) { 2142 virtual void work(int i) {
2163 _enq_task.work(i); 2143 _enq_task.work(i);
2164 } 2144 }
2165 }; 2145 };
2208 // We use the work gang from the G1CollectedHeap and we utilize all 2188 // We use the work gang from the G1CollectedHeap and we utilize all
2209 // the worker threads. 2189 // the worker threads.
2210 int active_workers = g1h->workers() ? g1h->workers()->total_workers() : 1; 2190 int active_workers = g1h->workers() ? g1h->workers()->total_workers() : 1;
2211 active_workers = MAX2(MIN2(active_workers, (int)_max_task_num), 1); 2191 active_workers = MAX2(MIN2(active_workers, (int)_max_task_num), 1);
2212 2192
2213 G1CMRefProcTaskExecutor par_task_executor(g1h, this, nextMarkBitMap(), 2193 G1CMRefProcTaskExecutor par_task_executor(g1h, this,
2214 g1h->workers(), active_workers); 2194 g1h->workers(), active_workers);
2215 2195
2216 if (rp->processing_is_mt()) { 2196 if (rp->processing_is_mt()) {
2217 // Set the degree of MT here. If the discovery is done MT, there 2197 // Set the degree of MT here. If the discovery is done MT, there
2218 // may have been a different number of threads doing the discovery 2198 // may have been a different number of threads doing the discovery
3062 i++; 3042 i++;
3063 CompleteMarkingInCSHRClosure cmplt(this); 3043 CompleteMarkingInCSHRClosure cmplt(this);
3064 g1h->collection_set_iterate(&cmplt); 3044 g1h->collection_set_iterate(&cmplt);
3065 if (cmplt.completed()) break; 3045 if (cmplt.completed()) break;
3066 } 3046 }
3047
3048 ClearMarksInHRClosure clr(nextMarkBitMap());
3049 g1h->collection_set_iterate(&clr);
3050
3067 double end_time = os::elapsedTime(); 3051 double end_time = os::elapsedTime();
3068 double elapsed_time_ms = (end_time - start) * 1000.0; 3052 double elapsed_time_ms = (end_time - start) * 1000.0;
3069 g1h->g1_policy()->record_mark_closure_time(elapsed_time_ms); 3053 g1h->g1_policy()->record_mark_closure_time(elapsed_time_ms);
3070
3071 ClearMarksInHRClosure clr(nextMarkBitMap());
3072 g1h->collection_set_iterate(&clr);
3073 } 3054 }
3074 3055
3075 // The next two methods deal with the following optimisation. Some 3056 // The next two methods deal with the following optimisation. Some
3076 // objects are gray by being marked and located above the finger. If 3057 // objects are gray by being marked and located above the finger. If
3077 // they are copied, during an evacuation pause, below the finger then 3058 // they are copied, during an evacuation pause, below the finger then