11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/metadataOnStackMark.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "gc/g1/bufferingOopClosure.hpp"
32 #include "gc/g1/g1Allocator.inline.hpp"
33 #include "gc/g1/g1CollectedHeap.inline.hpp"
34 #include "gc/g1/g1CollectionSet.hpp"
35 #include "gc/g1/g1CollectorPolicy.hpp"
36 #include "gc/g1/g1CollectorState.hpp"
37 #include "gc/g1/g1ConcurrentRefine.hpp"
38 #include "gc/g1/g1ConcurrentRefineThread.hpp"
39 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
40 #include "gc/g1/g1EvacStats.inline.hpp"
41 #include "gc/g1/g1FullCollector.hpp"
42 #include "gc/g1/g1GCPhaseTimes.hpp"
43 #include "gc/g1/g1HeapSizingPolicy.hpp"
44 #include "gc/g1/g1HeapTransition.hpp"
45 #include "gc/g1/g1HeapVerifier.hpp"
46 #include "gc/g1/g1HotCardCache.hpp"
47 #include "gc/g1/g1MemoryPool.hpp"
48 #include "gc/g1/g1OopClosures.inline.hpp"
49 #include "gc/g1/g1ParScanThreadState.inline.hpp"
50 #include "gc/g1/g1Policy.hpp"
51 #include "gc/g1/g1RegionToSpaceMapper.hpp"
1821 }
1822
1823 size_t G1CollectedHeap::capacity() const {
1824 return _hrm.length() * HeapRegion::GrainBytes;
1825 }
1826
1827 size_t G1CollectedHeap::unused_committed_regions_in_bytes() const {
1828 return _hrm.total_free_bytes();
1829 }
1830
1831 void G1CollectedHeap::iterate_hcc_closure(CardTableEntryClosure* cl, uint worker_i) {
1832 _hot_card_cache->drain(cl, worker_i);
1833 }
1834
1835 void G1CollectedHeap::iterate_dirty_card_closure(CardTableEntryClosure* cl, uint worker_i) {
1836 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1837 size_t n_completed_buffers = 0;
1838 while (dcqs.apply_closure_during_gc(cl, worker_i)) {
1839 n_completed_buffers++;
1840 }
1841 g1_policy()->phase_times()->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, n_completed_buffers);
1842 dcqs.clear_n_completed_buffers();
1843 assert(!dcqs.completed_buffers_exist_dirty(), "Completed buffers exist!");
1844 }
1845
1846 // Computes the sum of the storage used by the various regions.
1847 size_t G1CollectedHeap::used() const {
1848 size_t result = _summary_bytes_used + _allocator->used_in_alloc_regions();
1849 if (_archive_allocator != NULL) {
1850 result += _archive_allocator->used();
1851 }
1852 return result;
1853 }
1854
1855 size_t G1CollectedHeap::used_unlocked() const {
1856 return _summary_bytes_used;
1857 }
1858
1859 class SumUsedClosure: public HeapRegionClosure {
1860 size_t _used;
1861 public:
3110 _n_workers(n_workers)
3111 {}
3112
3113 void work(uint worker_id) {
3114 if (worker_id >= _n_workers) return; // no work needed this round
3115
3116 double start_sec = os::elapsedTime();
3117 _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::GCWorkerStart, worker_id, start_sec);
3118
3119 {
3120 ResourceMark rm;
3121 HandleMark hm;
3122
3123 ReferenceProcessor* rp = _g1h->ref_processor_stw();
3124
3125 G1ParScanThreadState* pss = _pss->state_for_worker(worker_id);
3126 pss->set_ref_processor(rp);
3127
3128 double start_strong_roots_sec = os::elapsedTime();
3129
3130 _root_processor->evacuate_roots(pss->closures(), worker_id);
3131
3132 // We pass a weak code blobs closure to the remembered set scanning because we want to avoid
3133 // treating the nmethods visited to act as roots for concurrent marking.
3134 // We only want to make sure that the oops in the nmethods are adjusted with regard to the
3135 // objects copied by the current evacuation.
3136 _g1h->g1_rem_set()->oops_into_collection_set_do(pss,
3137 pss->closures()->weak_codeblobs(),
3138 worker_id);
3139
3140 double strong_roots_sec = os::elapsedTime() - start_strong_roots_sec;
3141
3142 double term_sec = 0.0;
3143 size_t evac_term_attempts = 0;
3144 {
3145 double start = os::elapsedTime();
3146 G1ParEvacuateFollowersClosure evac(_g1h, pss, _queues, &_terminator);
3147 evac.do_void();
3148
3149 evac_term_attempts = evac.term_attempts();
3150 term_sec = evac.term_time();
3151 double elapsed_sec = os::elapsedTime() - start;
3152 _g1h->g1_policy()->phase_times()->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_id, elapsed_sec - term_sec);
3153 _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::Termination, worker_id, term_sec);
3154 _g1h->g1_policy()->phase_times()->record_thread_work_item(G1GCPhaseTimes::Termination, worker_id, evac_term_attempts);
3155 }
3156
3157 assert(pss->queue_is_empty(), "should be empty");
3158
3159 if (log_is_enabled(Debug, gc, task, stats)) {
3160 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
3161 size_t lab_waste;
3162 size_t lab_undo_waste;
3163 pss->waste(lab_waste, lab_undo_waste);
3164 _g1h->print_termination_stats(worker_id,
3165 (os::elapsedTime() - start_sec) * 1000.0, /* elapsed time */
3166 strong_roots_sec * 1000.0, /* strong roots time */
3167 term_sec * 1000.0, /* evac term time */
3168 evac_term_attempts, /* evac term attempts */
3169 lab_waste, /* alloc buffer waste */
3170 lab_undo_waste /* undo waste */
3171 );
3172 }
3173
3174 // Close the inner scope so that the ResourceMark and HandleMark
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/metadataOnStackMark.hpp"
27 #include "classfile/stringTable.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "code/codeCache.hpp"
30 #include "code/icBuffer.hpp"
31 #include "gc/g1/g1Allocator.inline.hpp"
32 #include "gc/g1/g1CollectedHeap.inline.hpp"
33 #include "gc/g1/g1CollectionSet.hpp"
34 #include "gc/g1/g1CollectorPolicy.hpp"
35 #include "gc/g1/g1CollectorState.hpp"
36 #include "gc/g1/g1ConcurrentRefine.hpp"
37 #include "gc/g1/g1ConcurrentRefineThread.hpp"
38 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
39 #include "gc/g1/g1EvacStats.inline.hpp"
40 #include "gc/g1/g1FullCollector.hpp"
41 #include "gc/g1/g1GCPhaseTimes.hpp"
42 #include "gc/g1/g1HeapSizingPolicy.hpp"
43 #include "gc/g1/g1HeapTransition.hpp"
44 #include "gc/g1/g1HeapVerifier.hpp"
45 #include "gc/g1/g1HotCardCache.hpp"
46 #include "gc/g1/g1MemoryPool.hpp"
47 #include "gc/g1/g1OopClosures.inline.hpp"
48 #include "gc/g1/g1ParScanThreadState.inline.hpp"
49 #include "gc/g1/g1Policy.hpp"
50 #include "gc/g1/g1RegionToSpaceMapper.hpp"
1820 }
1821
1822 size_t G1CollectedHeap::capacity() const {
1823 return _hrm.length() * HeapRegion::GrainBytes;
1824 }
1825
1826 size_t G1CollectedHeap::unused_committed_regions_in_bytes() const {
1827 return _hrm.total_free_bytes();
1828 }
1829
1830 void G1CollectedHeap::iterate_hcc_closure(CardTableEntryClosure* cl, uint worker_i) {
1831 _hot_card_cache->drain(cl, worker_i);
1832 }
1833
1834 void G1CollectedHeap::iterate_dirty_card_closure(CardTableEntryClosure* cl, uint worker_i) {
1835 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1836 size_t n_completed_buffers = 0;
1837 while (dcqs.apply_closure_during_gc(cl, worker_i)) {
1838 n_completed_buffers++;
1839 }
1840 g1_policy()->phase_times()->record_thread_work_item(G1GCPhaseTimes::UpdateRS, worker_i, n_completed_buffers, G1GCPhaseTimes::UpdateRSProcessedBuffers);
1841 dcqs.clear_n_completed_buffers();
1842 assert(!dcqs.completed_buffers_exist_dirty(), "Completed buffers exist!");
1843 }
1844
1845 // Computes the sum of the storage used by the various regions.
1846 size_t G1CollectedHeap::used() const {
1847 size_t result = _summary_bytes_used + _allocator->used_in_alloc_regions();
1848 if (_archive_allocator != NULL) {
1849 result += _archive_allocator->used();
1850 }
1851 return result;
1852 }
1853
1854 size_t G1CollectedHeap::used_unlocked() const {
1855 return _summary_bytes_used;
1856 }
1857
1858 class SumUsedClosure: public HeapRegionClosure {
1859 size_t _used;
1860 public:
3109 _n_workers(n_workers)
3110 {}
3111
3112 void work(uint worker_id) {
3113 if (worker_id >= _n_workers) return; // no work needed this round
3114
3115 double start_sec = os::elapsedTime();
3116 _g1h->g1_policy()->phase_times()->record_time_secs(G1GCPhaseTimes::GCWorkerStart, worker_id, start_sec);
3117
3118 {
3119 ResourceMark rm;
3120 HandleMark hm;
3121
3122 ReferenceProcessor* rp = _g1h->ref_processor_stw();
3123
3124 G1ParScanThreadState* pss = _pss->state_for_worker(worker_id);
3125 pss->set_ref_processor(rp);
3126
3127 double start_strong_roots_sec = os::elapsedTime();
3128
3129 _root_processor->evacuate_roots(pss, pss->closures(), worker_id);
3130
3131 // We pass a weak code blobs closure to the remembered set scanning because we want to avoid
3132 // treating the nmethods visited to act as roots for concurrent marking.
3133 // We only want to make sure that the oops in the nmethods are adjusted with regard to the
3134 // objects copied by the current evacuation.
3135 _g1h->g1_rem_set()->oops_into_collection_set_do(pss, worker_id);
3136
3137 double strong_roots_sec = os::elapsedTime() - start_strong_roots_sec;
3138
3139 double term_sec = 0.0;
3140 size_t evac_term_attempts = 0;
3141 {
3142 double start = os::elapsedTime();
3143 G1ParEvacuateFollowersClosure evac(_g1h, pss, _queues, &_terminator);
3144 evac.do_void();
3145
3146 evac_term_attempts = evac.term_attempts();
3147 term_sec = evac.term_time();
3148 double elapsed_sec = os::elapsedTime() - start;
3149
3150 G1GCPhaseTimes* p = _g1h->g1_policy()->phase_times();
3151 p->add_time_secs(G1GCPhaseTimes::ObjCopy, worker_id, elapsed_sec - term_sec);
3152 p->record_time_secs(G1GCPhaseTimes::Termination, worker_id, term_sec);
3153 p->record_thread_work_item(G1GCPhaseTimes::Termination, worker_id, evac_term_attempts);
3154 }
3155
3156 assert(pss->queue_is_empty(), "should be empty");
3157
3158 if (log_is_enabled(Debug, gc, task, stats)) {
3159 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
3160 size_t lab_waste;
3161 size_t lab_undo_waste;
3162 pss->waste(lab_waste, lab_undo_waste);
3163 _g1h->print_termination_stats(worker_id,
3164 (os::elapsedTime() - start_sec) * 1000.0, /* elapsed time */
3165 strong_roots_sec * 1000.0, /* strong roots time */
3166 term_sec * 1000.0, /* evac term time */
3167 evac_term_attempts, /* evac term attempts */
3168 lab_waste, /* alloc buffer waste */
3169 lab_undo_waste /* undo waste */
3170 );
3171 }
3172
3173 // Close the inner scope so that the ResourceMark and HandleMark
|