aoqi@0: /* aoqi@0: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "gc_implementation/g1/concurrentG1Refine.hpp" aoqi@0: #include "gc_implementation/g1/concurrentG1RefineThread.hpp" aoqi@0: #include "gc_implementation/g1/heapRegion.hpp" aoqi@0: #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1RemSet.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1RemSetSummary.hpp" aoqi@0: #include "gc_implementation/g1/heapRegionRemSet.hpp" aoqi@0: #include "runtime/thread.inline.hpp" aoqi@0: aoqi@0: class GetRSThreadVTimeClosure : public ThreadClosure { aoqi@0: private: aoqi@0: G1RemSetSummary* _summary; aoqi@0: uint _counter; aoqi@0: aoqi@0: public: aoqi@0: GetRSThreadVTimeClosure(G1RemSetSummary * summary) : ThreadClosure(), _summary(summary), _counter(0) { aoqi@0: assert(_summary != NULL, "just checking"); aoqi@0: } aoqi@0: aoqi@0: virtual void do_thread(Thread* t) { aoqi@0: ConcurrentG1RefineThread* crt = (ConcurrentG1RefineThread*) t; aoqi@0: _summary->set_rs_thread_vtime(_counter, crt->vtime_accum()); aoqi@0: _counter++; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: void G1RemSetSummary::update() { aoqi@0: _num_refined_cards = remset()->conc_refine_cards(); aoqi@0: DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); aoqi@0: _num_processed_buf_mutator = dcqs.processed_buffers_mut(); aoqi@0: _num_processed_buf_rs_threads = dcqs.processed_buffers_rs_thread(); aoqi@0: aoqi@0: _num_coarsenings = HeapRegionRemSet::n_coarsenings(); aoqi@0: aoqi@0: ConcurrentG1Refine * cg1r = G1CollectedHeap::heap()->concurrent_g1_refine(); aoqi@0: if (_rs_threads_vtimes != NULL) { aoqi@0: GetRSThreadVTimeClosure p(this); aoqi@0: cg1r->worker_threads_do(&p); aoqi@0: } aoqi@0: set_sampling_thread_vtime(cg1r->sampling_thread()->vtime_accum()); aoqi@0: } aoqi@0: aoqi@0: void G1RemSetSummary::set_rs_thread_vtime(uint thread, double value) { aoqi@0: assert(_rs_threads_vtimes != NULL, "just checking"); aoqi@0: assert(thread < _num_vtimes, "just checking"); aoqi@0: _rs_threads_vtimes[thread] = value; aoqi@0: } aoqi@0: aoqi@0: double G1RemSetSummary::rs_thread_vtime(uint thread) const { aoqi@0: assert(_rs_threads_vtimes != NULL, "just checking"); aoqi@0: assert(thread < _num_vtimes, "just checking"); aoqi@0: return _rs_threads_vtimes[thread]; aoqi@0: } aoqi@0: aoqi@0: void G1RemSetSummary::initialize(G1RemSet* remset) { aoqi@0: assert(_rs_threads_vtimes == NULL, "just checking"); aoqi@0: assert(remset != NULL, "just checking"); aoqi@0: aoqi@0: _remset = remset; aoqi@0: _num_vtimes = ConcurrentG1Refine::thread_num(); aoqi@0: _rs_threads_vtimes = NEW_C_HEAP_ARRAY(double, _num_vtimes, mtGC); aoqi@0: memset(_rs_threads_vtimes, 0, sizeof(double) * _num_vtimes); aoqi@0: aoqi@0: update(); aoqi@0: } aoqi@0: aoqi@0: void G1RemSetSummary::set(G1RemSetSummary* other) { aoqi@0: assert(other != NULL, "just checking"); aoqi@0: assert(remset() == other->remset(), "just checking"); aoqi@0: assert(_num_vtimes == other->_num_vtimes, "just checking"); aoqi@0: aoqi@0: _num_refined_cards = other->num_concurrent_refined_cards(); aoqi@0: aoqi@0: _num_processed_buf_mutator = other->num_processed_buf_mutator(); aoqi@0: _num_processed_buf_rs_threads = other->num_processed_buf_rs_threads(); aoqi@0: aoqi@0: _num_coarsenings = other->_num_coarsenings; aoqi@0: aoqi@0: memcpy(_rs_threads_vtimes, other->_rs_threads_vtimes, sizeof(double) * _num_vtimes); aoqi@0: aoqi@0: set_sampling_thread_vtime(other->sampling_thread_vtime()); aoqi@0: } aoqi@0: aoqi@0: void G1RemSetSummary::subtract_from(G1RemSetSummary* other) { aoqi@0: assert(other != NULL, "just checking"); aoqi@0: assert(remset() == other->remset(), "just checking"); aoqi@0: assert(_num_vtimes == other->_num_vtimes, "just checking"); aoqi@0: aoqi@0: _num_refined_cards = other->num_concurrent_refined_cards() - _num_refined_cards; aoqi@0: aoqi@0: _num_processed_buf_mutator = other->num_processed_buf_mutator() - _num_processed_buf_mutator; aoqi@0: _num_processed_buf_rs_threads = other->num_processed_buf_rs_threads() - _num_processed_buf_rs_threads; aoqi@0: aoqi@0: _num_coarsenings = other->num_coarsenings() - _num_coarsenings; aoqi@0: aoqi@0: for (uint i = 0; i < _num_vtimes; i++) { aoqi@0: set_rs_thread_vtime(i, other->rs_thread_vtime(i) - rs_thread_vtime(i)); aoqi@0: } aoqi@0: aoqi@0: _sampling_thread_vtime = other->sampling_thread_vtime() - _sampling_thread_vtime; aoqi@0: } aoqi@0: aoqi@0: static double percent_of(size_t numerator, size_t denominator) { aoqi@0: if (denominator != 0) { aoqi@0: return (double)numerator / denominator * 100.0f; aoqi@0: } else { aoqi@0: return 0.0f; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static size_t round_to_K(size_t value) { aoqi@0: return value / K; aoqi@0: } aoqi@0: aoqi@0: class RegionTypeCounter VALUE_OBJ_CLASS_SPEC { aoqi@0: private: aoqi@0: const char* _name; aoqi@0: aoqi@0: size_t _rs_mem_size; aoqi@0: size_t _cards_occupied; aoqi@0: size_t _amount; aoqi@0: aoqi@0: size_t _code_root_mem_size; aoqi@0: size_t _code_root_elems; aoqi@0: aoqi@0: double rs_mem_size_percent_of(size_t total) { aoqi@0: return percent_of(_rs_mem_size, total); aoqi@0: } aoqi@0: aoqi@0: double cards_occupied_percent_of(size_t total) { aoqi@0: return percent_of(_cards_occupied, total); aoqi@0: } aoqi@0: aoqi@0: double code_root_mem_size_percent_of(size_t total) { aoqi@0: return percent_of(_code_root_mem_size, total); aoqi@0: } aoqi@0: aoqi@0: double code_root_elems_percent_of(size_t total) { aoqi@0: return percent_of(_code_root_elems, total); aoqi@0: } aoqi@0: aoqi@0: size_t amount() const { return _amount; } aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: RegionTypeCounter(const char* name) : _name(name), _rs_mem_size(0), _cards_occupied(0), aoqi@0: _amount(0), _code_root_mem_size(0), _code_root_elems(0) { } aoqi@0: aoqi@0: void add(size_t rs_mem_size, size_t cards_occupied, size_t code_root_mem_size, aoqi@0: size_t code_root_elems) { aoqi@0: _rs_mem_size += rs_mem_size; aoqi@0: _cards_occupied += cards_occupied; aoqi@0: _code_root_mem_size += code_root_mem_size; aoqi@0: _code_root_elems += code_root_elems; aoqi@0: _amount++; aoqi@0: } aoqi@0: aoqi@0: size_t rs_mem_size() const { return _rs_mem_size; } aoqi@0: size_t cards_occupied() const { return _cards_occupied; } aoqi@0: aoqi@0: size_t code_root_mem_size() const { return _code_root_mem_size; } aoqi@0: size_t code_root_elems() const { return _code_root_elems; } aoqi@0: aoqi@0: void print_rs_mem_info_on(outputStream * out, size_t total) { aoqi@0: out->print_cr(" "SIZE_FORMAT_W(8)"K (%5.1f%%) by "SIZE_FORMAT" %s regions", aoqi@0: round_to_K(rs_mem_size()), rs_mem_size_percent_of(total), amount(), _name); aoqi@0: } aoqi@0: aoqi@0: void print_cards_occupied_info_on(outputStream * out, size_t total) { aoqi@0: out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) entries by "SIZE_FORMAT" %s regions", aoqi@0: cards_occupied(), cards_occupied_percent_of(total), amount(), _name); aoqi@0: } aoqi@0: aoqi@0: void print_code_root_mem_info_on(outputStream * out, size_t total) { aoqi@0: out->print_cr(" "SIZE_FORMAT_W(8)"K (%5.1f%%) by "SIZE_FORMAT" %s regions", aoqi@0: round_to_K(code_root_mem_size()), code_root_mem_size_percent_of(total), amount(), _name); aoqi@0: } aoqi@0: aoqi@0: void print_code_root_elems_info_on(outputStream * out, size_t total) { aoqi@0: out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) elements by "SIZE_FORMAT" %s regions", aoqi@0: code_root_elems(), code_root_elems_percent_of(total), amount(), _name); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: class HRRSStatsIter: public HeapRegionClosure { aoqi@0: private: aoqi@0: RegionTypeCounter _young; aoqi@0: RegionTypeCounter _humonguous; aoqi@0: RegionTypeCounter _free; aoqi@0: RegionTypeCounter _old; aoqi@0: RegionTypeCounter _all; aoqi@0: aoqi@0: size_t _max_rs_mem_sz; aoqi@0: HeapRegion* _max_rs_mem_sz_region; aoqi@0: aoqi@0: size_t total_rs_mem_sz() const { return _all.rs_mem_size(); } aoqi@0: size_t total_cards_occupied() const { return _all.cards_occupied(); } aoqi@0: aoqi@0: size_t max_rs_mem_sz() const { return _max_rs_mem_sz; } aoqi@0: HeapRegion* max_rs_mem_sz_region() const { return _max_rs_mem_sz_region; } aoqi@0: aoqi@0: size_t _max_code_root_mem_sz; aoqi@0: HeapRegion* _max_code_root_mem_sz_region; aoqi@0: aoqi@0: size_t total_code_root_mem_sz() const { return _all.code_root_mem_size(); } aoqi@0: size_t total_code_root_elems() const { return _all.code_root_elems(); } aoqi@0: aoqi@0: size_t max_code_root_mem_sz() const { return _max_code_root_mem_sz; } aoqi@0: HeapRegion* max_code_root_mem_sz_region() const { return _max_code_root_mem_sz_region; } aoqi@0: aoqi@0: public: aoqi@0: HRRSStatsIter() : _all("All"), _young("Young"), _humonguous("Humonguous"), aoqi@0: _free("Free"), _old("Old"), _max_code_root_mem_sz_region(NULL), _max_rs_mem_sz_region(NULL), aoqi@0: _max_rs_mem_sz(0), _max_code_root_mem_sz(0) aoqi@0: {} aoqi@0: aoqi@0: bool doHeapRegion(HeapRegion* r) { aoqi@0: HeapRegionRemSet* hrrs = r->rem_set(); aoqi@0: aoqi@0: // HeapRegionRemSet::mem_size() includes the aoqi@0: // size of the strong code roots aoqi@0: size_t rs_mem_sz = hrrs->mem_size(); aoqi@0: if (rs_mem_sz > _max_rs_mem_sz) { aoqi@0: _max_rs_mem_sz = rs_mem_sz; aoqi@0: _max_rs_mem_sz_region = r; aoqi@0: } aoqi@0: size_t occupied_cards = hrrs->occupied(); aoqi@0: size_t code_root_mem_sz = hrrs->strong_code_roots_mem_size(); aoqi@0: if (code_root_mem_sz > max_code_root_mem_sz()) { aoqi@0: _max_code_root_mem_sz_region = r; aoqi@0: } aoqi@0: size_t code_root_elems = hrrs->strong_code_roots_list_length(); aoqi@0: aoqi@0: RegionTypeCounter* current = NULL; aoqi@0: if (r->is_young()) { aoqi@0: current = &_young; aoqi@0: } else if (r->isHumongous()) { aoqi@0: current = &_humonguous; aoqi@0: } else if (r->is_empty()) { aoqi@0: current = &_free; aoqi@0: } else { aoqi@0: current = &_old; aoqi@0: } aoqi@0: current->add(rs_mem_sz, occupied_cards, code_root_mem_sz, code_root_elems); aoqi@0: _all.add(rs_mem_sz, occupied_cards, code_root_mem_sz, code_root_elems); aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void print_summary_on(outputStream* out) { aoqi@0: RegionTypeCounter* counters[] = { &_young, &_humonguous, &_free, &_old, NULL }; aoqi@0: aoqi@0: out->print_cr("\n Current rem set statistics"); aoqi@0: out->print_cr(" Total per region rem sets sizes = "SIZE_FORMAT"K." aoqi@0: " Max = "SIZE_FORMAT"K.", aoqi@0: round_to_K(total_rs_mem_sz()), round_to_K(max_rs_mem_sz())); aoqi@0: for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { aoqi@0: (*current)->print_rs_mem_info_on(out, total_rs_mem_sz()); aoqi@0: } aoqi@0: aoqi@0: out->print_cr(" Static structures = "SIZE_FORMAT"K," aoqi@0: " free_lists = "SIZE_FORMAT"K.", aoqi@0: round_to_K(HeapRegionRemSet::static_mem_size()), aoqi@0: round_to_K(HeapRegionRemSet::fl_mem_size())); aoqi@0: aoqi@0: out->print_cr(" "SIZE_FORMAT" occupied cards represented.", aoqi@0: total_cards_occupied()); aoqi@0: for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { aoqi@0: (*current)->print_cards_occupied_info_on(out, total_cards_occupied()); aoqi@0: } aoqi@0: aoqi@0: // Largest sized rem set region statistics aoqi@0: HeapRegionRemSet* rem_set = max_rs_mem_sz_region()->rem_set(); aoqi@0: out->print_cr(" Region with largest rem set = "HR_FORMAT", " aoqi@0: "size = "SIZE_FORMAT "K, occupied = "SIZE_FORMAT"K.", aoqi@0: HR_FORMAT_PARAMS(max_rs_mem_sz_region()), aoqi@0: round_to_K(rem_set->mem_size()), aoqi@0: round_to_K(rem_set->occupied())); aoqi@0: aoqi@0: // Strong code root statistics aoqi@0: HeapRegionRemSet* max_code_root_rem_set = max_code_root_mem_sz_region()->rem_set(); aoqi@0: out->print_cr(" Total heap region code root sets sizes = "SIZE_FORMAT"K." aoqi@0: " Max = "SIZE_FORMAT"K.", aoqi@0: round_to_K(total_code_root_mem_sz()), aoqi@0: round_to_K(max_code_root_rem_set->strong_code_roots_mem_size())); aoqi@0: for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { aoqi@0: (*current)->print_code_root_mem_info_on(out, total_code_root_mem_sz()); aoqi@0: } aoqi@0: aoqi@0: out->print_cr(" "SIZE_FORMAT" code roots represented.", aoqi@0: total_code_root_elems()); aoqi@0: for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { aoqi@0: (*current)->print_code_root_elems_info_on(out, total_code_root_elems()); aoqi@0: } aoqi@0: aoqi@0: out->print_cr(" Region with largest amount of code roots = "HR_FORMAT", " aoqi@0: "size = "SIZE_FORMAT "K, num_elems = "SIZE_FORMAT".", aoqi@0: HR_FORMAT_PARAMS(max_code_root_mem_sz_region()), aoqi@0: round_to_K(max_code_root_rem_set->strong_code_roots_mem_size()), aoqi@0: round_to_K(max_code_root_rem_set->strong_code_roots_list_length())); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: void G1RemSetSummary::print_on(outputStream* out) { aoqi@0: out->print_cr("\n Recent concurrent refinement statistics"); aoqi@0: out->print_cr(" Processed "SIZE_FORMAT" cards", aoqi@0: num_concurrent_refined_cards()); aoqi@0: out->print_cr(" Of "SIZE_FORMAT" completed buffers:", num_processed_buf_total()); aoqi@0: out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) by concurrent RS threads.", aoqi@0: num_processed_buf_total(), aoqi@0: percent_of(num_processed_buf_rs_threads(), num_processed_buf_total())); aoqi@0: out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) by mutator threads.", aoqi@0: num_processed_buf_mutator(), aoqi@0: percent_of(num_processed_buf_mutator(), num_processed_buf_total())); aoqi@0: out->print_cr(" Did "SIZE_FORMAT" coarsenings.", num_coarsenings()); aoqi@0: out->print_cr(" Concurrent RS threads times (s)"); aoqi@0: out->print(" "); aoqi@0: for (uint i = 0; i < _num_vtimes; i++) { aoqi@0: out->print(" %5.2f", rs_thread_vtime(i)); aoqi@0: } aoqi@0: out->cr(); aoqi@0: out->print_cr(" Concurrent sampling threads times (s)"); aoqi@0: out->print_cr(" %5.2f", sampling_thread_vtime()); aoqi@0: aoqi@0: HRRSStatsIter blk; aoqi@0: G1CollectedHeap::heap()->heap_region_iterate(&blk); aoqi@0: blk.print_summary_on(out); aoqi@0: }