3885N/A/*
4539N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3885N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3885N/A *
3885N/A * This code is free software; you can redistribute it and/or modify it
3885N/A * under the terms of the GNU General Public License version 2 only, as
3885N/A * published by the Free Software Foundation.
3885N/A *
3885N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3885N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3885N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3885N/A * version 2 for more details (a copy is included in the LICENSE file that
3885N/A * accompanied this code).
3885N/A *
3885N/A * You should have received a copy of the GNU General Public License version
3885N/A * 2 along with this work; if not, write to the Free Software Foundation,
3885N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3885N/A *
3885N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3885N/A * or visit www.oracle.com if you need additional information or have any
3885N/A * questions.
3885N/A *
3885N/A */
3885N/A
3885N/A
3885N/A#include "precompiled.hpp"
3885N/A#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
3885N/A#include "gc_implementation/g1/g1GCPhaseTimes.hpp"
3885N/A#include "gc_implementation/g1/g1Log.hpp"
3885N/A
3885N/A// Helper class for avoiding interleaved logging
3885N/Aclass LineBuffer: public StackObj {
3885N/A
3885N/Aprivate:
3885N/A static const int BUFFER_LEN = 1024;
3885N/A static const int INDENT_CHARS = 3;
3885N/A char _buffer[BUFFER_LEN];
3885N/A int _indent_level;
3885N/A int _cur;
3885N/A
3885N/A void vappend(const char* format, va_list ap) {
3885N/A int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap);
3885N/A if (res != -1) {
3885N/A _cur += res;
3885N/A } else {
3885N/A DEBUG_ONLY(warning("buffer too small in LineBuffer");)
3885N/A _buffer[BUFFER_LEN -1] = 0;
3885N/A _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again
3885N/A }
3885N/A }
3885N/A
3885N/Apublic:
3885N/A explicit LineBuffer(int indent_level): _indent_level(indent_level), _cur(0) {
3885N/A for (; (_cur < BUFFER_LEN && _cur < (_indent_level * INDENT_CHARS)); _cur++) {
3885N/A _buffer[_cur] = ' ';
3885N/A }
3885N/A }
3885N/A
3885N/A#ifndef PRODUCT
3885N/A ~LineBuffer() {
3885N/A assert(_cur == _indent_level * INDENT_CHARS, "pending data in buffer - append_and_print_cr() not called?");
3885N/A }
3885N/A#endif
3885N/A
3885N/A void append(const char* format, ...) {
3885N/A va_list ap;
3885N/A va_start(ap, format);
3885N/A vappend(format, ap);
3885N/A va_end(ap);
3885N/A }
3885N/A
3885N/A void append_and_print_cr(const char* format, ...) {
3885N/A va_list ap;
3885N/A va_start(ap, format);
3885N/A vappend(format, ap);
3885N/A va_end(ap);
3885N/A gclog_or_tty->print_cr("%s", _buffer);
3885N/A _cur = _indent_level * INDENT_CHARS;
3885N/A }
3885N/A};
3885N/A
3978N/Atemplate <class T>
3978N/Avoid WorkerDataArray<T>::print(int level, const char* title) {
3978N/A if (_length == 1) {
3978N/A // No need for min, max, average and sum for only one worker
3978N/A LineBuffer buf(level);
3978N/A buf.append("[%s: ", title);
3978N/A buf.append(_print_format, _data[0]);
3978N/A buf.append_and_print_cr("]");
3978N/A return;
3978N/A }
3978N/A
3978N/A T min = _data[0];
3978N/A T max = _data[0];
3978N/A T sum = 0;
3978N/A
3978N/A LineBuffer buf(level);
3978N/A buf.append("[%s:", title);
3978N/A for (uint i = 0; i < _length; ++i) {
3978N/A T val = _data[i];
3978N/A min = MIN2(val, min);
3978N/A max = MAX2(val, max);
3978N/A sum += val;
3978N/A if (G1Log::finest()) {
3978N/A buf.append(" ");
3978N/A buf.append(_print_format, val);
3978N/A }
3978N/A }
3978N/A
3978N/A if (G1Log::finest()) {
3978N/A buf.append_and_print_cr("");
3978N/A }
3978N/A
3978N/A double avg = (double)sum / (double)_length;
3978N/A buf.append(" Min: ");
3978N/A buf.append(_print_format, min);
3978N/A buf.append(", Avg: ");
3978N/A buf.append("%.1lf", avg); // Always print average as a double
3978N/A buf.append(", Max: ");
3978N/A buf.append(_print_format, max);
3978N/A buf.append(", Diff: ");
3978N/A buf.append(_print_format, max - min);
3978N/A if (_print_sum) {
3978N/A // for things like the start and end times the sum is not
3978N/A // that relevant
3978N/A buf.append(", Sum: ");
3978N/A buf.append(_print_format, sum);
3978N/A }
3978N/A buf.append_and_print_cr("]");
3978N/A}
3978N/A
3978N/A#ifdef ASSERT
3978N/A
4438N/Atemplate <> const int WorkerDataArray<int>::_uninitialized = -1;
4438N/Atemplate <> const double WorkerDataArray<double>::_uninitialized = -1.0;
4438N/Atemplate <> const size_t WorkerDataArray<size_t>::_uninitialized = (size_t)-1;
4438N/A
3978N/Atemplate <class T>
3978N/Avoid WorkerDataArray<T>::reset() {
3978N/A for (uint i = 0; i < _length; i++) {
4438N/A _data[i] = (T)_uninitialized;
3978N/A }
3978N/A}
3978N/A
3978N/Atemplate <class T>
3978N/Avoid WorkerDataArray<T>::verify() {
3978N/A for (uint i = 0; i < _length; i++) {
4438N/A assert(_data[i] != _uninitialized,
4438N/A err_msg("Invalid data for worker " UINT32_FORMAT ", data: %lf, uninitialized: %lf",
4438N/A i, (double)_data[i], (double)_uninitialized));
3978N/A }
3978N/A}
3978N/A
3978N/A#endif
3978N/A
3885N/AG1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) :
3885N/A _max_gc_threads(max_gc_threads),
3978N/A _last_gc_worker_start_times_ms(_max_gc_threads, "%.1lf", false),
3978N/A _last_ext_root_scan_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_satb_filtering_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_update_rs_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_update_rs_processed_buffers(_max_gc_threads, "%d"),
3978N/A _last_scan_rs_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_obj_copy_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_termination_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_termination_attempts(_max_gc_threads, SIZE_FORMAT),
3978N/A _last_gc_worker_end_times_ms(_max_gc_threads, "%.1lf", false),
3978N/A _last_gc_worker_times_ms(_max_gc_threads, "%.1lf"),
3978N/A _last_gc_worker_other_times_ms(_max_gc_threads, "%.1lf")
3885N/A{
3885N/A assert(max_gc_threads > 0, "Must have some GC threads");
3885N/A}
3885N/A
3978N/Avoid G1GCPhaseTimes::note_gc_start(uint active_gc_threads) {
3885N/A assert(active_gc_threads > 0, "The number of threads must be > 0");
3885N/A assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max nubmer of threads");
3885N/A _active_gc_threads = active_gc_threads;
3885N/A
3978N/A _last_gc_worker_start_times_ms.reset();
3978N/A _last_ext_root_scan_times_ms.reset();
3978N/A _last_satb_filtering_times_ms.reset();
3978N/A _last_update_rs_times_ms.reset();
3978N/A _last_update_rs_processed_buffers.reset();
3978N/A _last_scan_rs_times_ms.reset();
3978N/A _last_obj_copy_times_ms.reset();
3978N/A _last_termination_times_ms.reset();
3978N/A _last_termination_attempts.reset();
3978N/A _last_gc_worker_end_times_ms.reset();
3978N/A _last_gc_worker_times_ms.reset();
3978N/A _last_gc_worker_other_times_ms.reset();
3885N/A}
3885N/A
3978N/Avoid G1GCPhaseTimes::note_gc_end() {
3978N/A _last_gc_worker_start_times_ms.verify();
3978N/A _last_ext_root_scan_times_ms.verify();
3978N/A _last_satb_filtering_times_ms.verify();
3978N/A _last_update_rs_times_ms.verify();
3978N/A _last_update_rs_processed_buffers.verify();
3978N/A _last_scan_rs_times_ms.verify();
3978N/A _last_obj_copy_times_ms.verify();
3978N/A _last_termination_times_ms.verify();
3978N/A _last_termination_attempts.verify();
3978N/A _last_gc_worker_end_times_ms.verify();
3885N/A
4438N/A for (uint i = 0; i < _active_gc_threads; i++) {
4438N/A double worker_time = _last_gc_worker_end_times_ms.get(i) - _last_gc_worker_start_times_ms.get(i);
4438N/A _last_gc_worker_times_ms.set(i, worker_time);
3885N/A
4438N/A double worker_known_time = _last_ext_root_scan_times_ms.get(i) +
4539N/A _last_satb_filtering_times_ms.get(i) +
4539N/A _last_update_rs_times_ms.get(i) +
4539N/A _last_scan_rs_times_ms.get(i) +
4539N/A _last_obj_copy_times_ms.get(i) +
4539N/A _last_termination_times_ms.get(i);
3885N/A
4438N/A double worker_other_time = worker_time - worker_known_time;
4438N/A _last_gc_worker_other_times_ms.set(i, worker_other_time);
4438N/A }
3885N/A
3978N/A _last_gc_worker_times_ms.verify();
3978N/A _last_gc_worker_other_times_ms.verify();
3885N/A}
3885N/A
3885N/Avoid G1GCPhaseTimes::print_stats(int level, const char* str, double value) {
3885N/A LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value);
3885N/A}
3885N/A
3885N/Avoid G1GCPhaseTimes::print_stats(int level, const char* str, double value, int workers) {
3885N/A LineBuffer(level).append_and_print_cr("[%s: %.1lf ms, GC Workers: %d]", str, value, workers);
3885N/A}
3885N/A
3885N/Adouble G1GCPhaseTimes::accounted_time_ms() {
3885N/A // Subtract the root region scanning wait time. It's initialized to
3885N/A // zero at the start of the pause.
3885N/A double misc_time_ms = _root_region_scan_wait_time_ms;
3885N/A
3885N/A misc_time_ms += _cur_collection_par_time_ms;
3885N/A
3885N/A // Now subtract the time taken to fix up roots in generated code
3885N/A misc_time_ms += _cur_collection_code_root_fixup_time_ms;
3885N/A
3885N/A // Subtract the time taken to clean the card table from the
3885N/A // current value of "other time"
3885N/A misc_time_ms += _cur_clear_ct_time_ms;
3885N/A
3885N/A return misc_time_ms;
3885N/A}
3885N/A
3978N/Avoid G1GCPhaseTimes::print(double pause_time_sec) {
3885N/A if (_root_region_scan_wait_time_ms > 0.0) {
3885N/A print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms);
3885N/A }
3885N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
3885N/A print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads);
3978N/A _last_gc_worker_start_times_ms.print(2, "GC Worker Start (ms)");
3978N/A _last_ext_root_scan_times_ms.print(2, "Ext Root Scanning (ms)");
3978N/A if (_last_satb_filtering_times_ms.sum() > 0.0) {
3978N/A _last_satb_filtering_times_ms.print(2, "SATB Filtering (ms)");
3885N/A }
3978N/A _last_update_rs_times_ms.print(2, "Update RS (ms)");
3978N/A _last_update_rs_processed_buffers.print(3, "Processed Buffers");
3978N/A _last_scan_rs_times_ms.print(2, "Scan RS (ms)");
3978N/A _last_obj_copy_times_ms.print(2, "Object Copy (ms)");
3978N/A _last_termination_times_ms.print(2, "Termination (ms)");
3885N/A if (G1Log::finest()) {
3978N/A _last_termination_attempts.print(3, "Termination Attempts");
3885N/A }
3978N/A _last_gc_worker_other_times_ms.print(2, "GC Worker Other (ms)");
3978N/A _last_gc_worker_times_ms.print(2, "GC Worker Total (ms)");
3978N/A _last_gc_worker_end_times_ms.print(2, "GC Worker End (ms)");
3885N/A } else {
3978N/A _last_ext_root_scan_times_ms.print(1, "Ext Root Scanning (ms)");
3978N/A if (_last_satb_filtering_times_ms.sum() > 0.0) {
3978N/A _last_satb_filtering_times_ms.print(1, "SATB Filtering (ms)");
3885N/A }
3978N/A _last_update_rs_times_ms.print(1, "Update RS (ms)");
3978N/A _last_update_rs_processed_buffers.print(2, "Processed Buffers");
3978N/A _last_scan_rs_times_ms.print(1, "Scan RS (ms)");
3978N/A _last_obj_copy_times_ms.print(1, "Object Copy (ms)");
3885N/A }
3885N/A print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms);
3885N/A print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
3978N/A double misc_time_ms = pause_time_sec * MILLIUNITS - accounted_time_ms();
3885N/A print_stats(1, "Other", misc_time_ms);
3978N/A if (_cur_verify_before_time_ms > 0.0) {
3978N/A print_stats(2, "Verify Before", _cur_verify_before_time_ms);
3978N/A }
3885N/A print_stats(2, "Choose CSet",
3885N/A (_recorded_young_cset_choice_time_ms +
3885N/A _recorded_non_young_cset_choice_time_ms));
3885N/A print_stats(2, "Ref Proc", _cur_ref_proc_time_ms);
3885N/A print_stats(2, "Ref Enq", _cur_ref_enq_time_ms);
3885N/A print_stats(2, "Free CSet",
3885N/A (_recorded_young_free_cset_time_ms +
3885N/A _recorded_non_young_free_cset_time_ms));
3978N/A if (_cur_verify_after_time_ms > 0.0) {
3978N/A print_stats(2, "Verify After", _cur_verify_after_time_ms);
3978N/A }
3885N/A}