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