# HG changeset patch # User tschatzl # Date 1508751985 -7200 # Node ID 4cfcb7be49842911ca4a02c4f0b4c48bdc4b45c9 # Parent c84eeb55c55e7a1773c69a36f183e9c55d6da7d1 8189666: Replace various inlined percentage calculations with global percent_of() Reviewed-by: sjohanss, sangheki diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1ConcurrentMark.cpp --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -2996,11 +2996,11 @@ G1PPRL_SUM_MB_FORMAT("code-roots"), bytes_to_mb(_total_capacity_bytes), bytes_to_mb(_total_used_bytes), - perc(_total_used_bytes, _total_capacity_bytes), + percent_of(_total_used_bytes, _total_capacity_bytes), bytes_to_mb(_total_prev_live_bytes), - perc(_total_prev_live_bytes, _total_capacity_bytes), + percent_of(_total_prev_live_bytes, _total_capacity_bytes), bytes_to_mb(_total_next_live_bytes), - perc(_total_next_live_bytes, _total_capacity_bytes), + percent_of(_total_next_live_bytes, _total_capacity_bytes), bytes_to_mb(_total_remset_bytes), bytes_to_mb(_total_strong_code_roots_bytes)); } diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1ConcurrentMark.hpp --- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp Mon Oct 23 11:46:25 2017 +0200 @@ -850,14 +850,6 @@ // Accumulator for strong code roots memory size size_t _total_strong_code_roots_bytes; - static double perc(size_t val, size_t total) { - if (total == 0) { - return 0.0; - } else { - return 100.0 * ((double) val / (double) total); - } - } - static double bytes_to_mb(size_t val) { return (double) val / (double) M; } diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1DefaultPolicy.cpp --- a/src/hotspot/share/gc/g1/g1DefaultPolicy.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1DefaultPolicy.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -1005,11 +1005,7 @@ } double G1DefaultPolicy::reclaimable_bytes_perc(size_t reclaimable_bytes) const { - // Returns the given amount of reclaimable bytes (that represents - // the amount of reclaimable space still to be collected) as a - // percentage of the current heap capacity. - size_t capacity_bytes = _g1->capacity(); - return (double) reclaimable_bytes * 100.0 / (double) capacity_bytes; + return percent_of(reclaimable_bytes, _g1->capacity()); } void G1DefaultPolicy::maybe_start_marking() { diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1DefaultPolicy.hpp --- a/src/hotspot/share/gc/g1/g1DefaultPolicy.hpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1DefaultPolicy.hpp Mon Oct 23 11:46:25 2017 +0200 @@ -238,6 +238,9 @@ uint calc_min_old_cset_length() const; uint calc_max_old_cset_length() const; + // Returns the given amount of reclaimable bytes (that represents + // the amount of reclaimable space still to be collected) as a + // percentage of the current heap capacity. double reclaimable_bytes_perc(size_t reclaimable_bytes) const; jlong collection_pause_end_millis() { return _collection_pause_end_millis; } diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1IHOPControl.cpp --- a/src/hotspot/share/gc/g1/g1IHOPControl.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1IHOPControl.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -57,7 +57,7 @@ log_debug(gc, ihop)("Basic information (value update), threshold: " SIZE_FORMAT "B (%1.2f), target occupancy: " SIZE_FORMAT "B, current occupancy: " SIZE_FORMAT "B, " "recent allocation size: " SIZE_FORMAT "B, recent allocation duration: %1.2fms, recent old gen allocation rate: %1.2fB/s, recent marking phase length: %1.2fms", cur_conc_mark_start_threshold, - cur_conc_mark_start_threshold * 100.0 / _target_occupancy, + percent_of(cur_conc_mark_start_threshold, _target_occupancy), _target_occupancy, G1CollectedHeap::heap()->used(), _last_allocated_bytes, diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1StringDedupStat.cpp --- a/src/hotspot/share/gc/g1/g1StringDedupStat.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1StringDedupStat.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -82,7 +82,7 @@ if (total_stat._new_bytes > 0) { // Avoid division by zero - total_deduped_bytes_percent = (double)total_stat._deduped_bytes / (double)total_stat._new_bytes * 100.0; + total_deduped_bytes_percent = percent_of(total_stat._deduped_bytes, total_stat._new_bytes); } log_info(gc, stringdedup)( @@ -100,48 +100,16 @@ } void G1StringDedupStat::print_statistics(const G1StringDedupStat& stat, bool total) { - double young_percent = 0.0; - double old_percent = 0.0; - double skipped_percent = 0.0; - double hashed_percent = 0.0; - double known_percent = 0.0; - double new_percent = 0.0; - double deduped_percent = 0.0; - double deduped_bytes_percent = 0.0; - double deduped_young_percent = 0.0; - double deduped_young_bytes_percent = 0.0; - double deduped_old_percent = 0.0; - double deduped_old_bytes_percent = 0.0; - - if (stat._inspected > 0) { - // Avoid division by zero - skipped_percent = (double)stat._skipped / (double)stat._inspected * 100.0; - hashed_percent = (double)stat._hashed / (double)stat._inspected * 100.0; - known_percent = (double)stat._known / (double)stat._inspected * 100.0; - new_percent = (double)stat._new / (double)stat._inspected * 100.0; - } - - if (stat._new > 0) { - // Avoid division by zero - deduped_percent = (double)stat._deduped / (double)stat._new * 100.0; - } - - if (stat._deduped > 0) { - // Avoid division by zero - deduped_young_percent = (double)stat._deduped_young / (double)stat._deduped * 100.0; - deduped_old_percent = (double)stat._deduped_old / (double)stat._deduped * 100.0; - } - - if (stat._new_bytes > 0) { - // Avoid division by zero - deduped_bytes_percent = (double)stat._deduped_bytes / (double)stat._new_bytes * 100.0; - } - - if (stat._deduped_bytes > 0) { - // Avoid division by zero - deduped_young_bytes_percent = (double)stat._deduped_young_bytes / (double)stat._deduped_bytes * 100.0; - deduped_old_bytes_percent = (double)stat._deduped_old_bytes / (double)stat._deduped_bytes * 100.0; - } + double skipped_percent = percent_of(stat._skipped, stat._inspected); + double hashed_percent = percent_of(stat._hashed, stat._inspected); + double known_percent = percent_of(stat._known, stat._inspected); + double new_percent = percent_of(stat._new, stat._inspected); + double deduped_percent = percent_of(stat._deduped, stat._new); + double deduped_bytes_percent = percent_of(stat._deduped_bytes, stat._new_bytes); + double deduped_young_percent = percent_of(stat._deduped_young, stat._deduped); + double deduped_young_bytes_percent = percent_of(stat._deduped_young_bytes, stat._deduped_bytes); + double deduped_old_percent = percent_of(stat._deduped_old, stat._deduped); + double deduped_old_bytes_percent = percent_of(stat._deduped_old_bytes, stat._deduped_bytes); if (total) { log_debug(gc, stringdedup)( diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/g1/g1StringDedupTable.cpp --- a/src/hotspot/share/gc/g1/g1StringDedupTable.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/g1/g1StringDedupTable.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -616,7 +616,7 @@ G1_STRDEDUP_BYTES_PARAM(_table->_size * sizeof(G1StringDedupEntry*) + (_table->_entries + _entry_cache->size()) * sizeof(G1StringDedupEntry))); log.debug(" Size: " SIZE_FORMAT ", Min: " SIZE_FORMAT ", Max: " SIZE_FORMAT, _table->_size, _min_size, _max_size); log.debug(" Entries: " UINTX_FORMAT ", Load: " G1_STRDEDUP_PERCENT_FORMAT_NS ", Cached: " UINTX_FORMAT ", Added: " UINTX_FORMAT ", Removed: " UINTX_FORMAT, - _table->_entries, (double)_table->_entries / (double)_table->_size * 100.0, _entry_cache->size(), _entries_added, _entries_removed); + _table->_entries, percent_of(_table->_entries, _table->_size), _entry_cache->size(), _entries_added, _entries_removed); log.debug(" Resize Count: " UINTX_FORMAT ", Shrink Threshold: " UINTX_FORMAT "(" G1_STRDEDUP_PERCENT_FORMAT_NS "), Grow Threshold: " UINTX_FORMAT "(" G1_STRDEDUP_PERCENT_FORMAT_NS ")", _resize_count, _table->_shrink_threshold, _shrink_load_factor * 100.0, _table->_grow_threshold, _grow_load_factor * 100.0); log.debug(" Rehash Count: " UINTX_FORMAT ", Rehash Threshold: " UINTX_FORMAT ", Hash Seed: 0x%x", _rehash_count, _rehash_threshold, _table->_hash_seed); diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp --- a/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -275,8 +275,7 @@ Thread* thrd = myThread(); size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste; size_t alloc = _number_of_refills * _desired_size; - double waste_percent = alloc == 0 ? 0.0 : - 100.0 * waste / alloc; + double waste_percent = percent_of(waste, alloc); size_t tlab_used = Universe::heap()->tlab_used(thrd); log.trace("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]" " desired_size: " SIZE_FORMAT "KB" @@ -416,8 +415,7 @@ } size_t waste = _total_gc_waste + _total_slow_refill_waste + _total_fast_refill_waste; - double waste_percent = _total_allocation == 0 ? 0.0 : - 100.0 * waste / _total_allocation; + double waste_percent = percent_of(waste, _total_allocation); log.debug("TLAB totals: thrds: %d refills: %d max: %d" " slow allocs: %d max %d waste: %4.1f%%" " gc: " SIZE_FORMAT "B max: " SIZE_FORMAT "B" diff -r c84eeb55c55e -r 4cfcb7be4984 src/hotspot/share/memory/metaspaceShared.cpp --- a/src/hotspot/share/memory/metaspaceShared.cpp Mon Oct 23 11:46:12 2017 +0200 +++ b/src/hotspot/share/memory/metaspaceShared.cpp Mon Oct 23 11:46:25 2017 +0200 @@ -157,16 +157,9 @@ return !is_packed() && _base != NULL; } - double perc(size_t used, size_t total) const { - if (total == 0) { - total = 1; - } - return used / double(total) * 100.0; - } - void print(size_t total_bytes) const { tty->print_cr("%-3s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT, - _name, used(), perc(used(), total_bytes), reserved(), perc(used(), reserved()), p2i(_base)); + _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()), p2i(_base)); } void print_out_of_space_msg(const char* failing_region, size_t needed_bytes) { tty->print("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d", @@ -906,9 +899,9 @@ int count = ro_count + rw_count; int bytes = ro_bytes + rw_bytes; - double ro_perc = 100.0 * double(ro_bytes) / double(ro_all); - double rw_perc = 100.0 * double(rw_bytes) / double(rw_all); - double perc = 100.0 * double(bytes) / double(ro_all + rw_all); + double ro_perc = percent_of(ro_bytes, ro_all); + double rw_perc = percent_of(rw_bytes, rw_all); + double perc = percent_of(bytes, ro_all + rw_all); info_stream.print_cr(fmt_stats, name, ro_count, ro_bytes, ro_perc, @@ -924,9 +917,9 @@ int all_count = all_ro_count + all_rw_count; int all_bytes = all_ro_bytes + all_rw_bytes; - double all_ro_perc = 100.0 * double(all_ro_bytes) / double(ro_all); - double all_rw_perc = 100.0 * double(all_rw_bytes) / double(rw_all); - double all_perc = 100.0 * double(all_bytes) / double(ro_all + rw_all); + double all_ro_perc = percent_of(all_ro_bytes, ro_all); + double all_rw_perc = percent_of(all_rw_bytes, rw_all); + double all_perc = percent_of(all_bytes, ro_all + rw_all); info_stream.print_cr("%s", sep); info_stream.print_cr(fmt_stats, "Total", @@ -1427,7 +1420,7 @@ _od_region.used() + _total_string_region_size + _total_open_archive_region_size; - const double total_u_perc = total_bytes / double(total_reserved) * 100.0; + const double total_u_perc = percent_of(total_bytes, total_reserved); _mc_region.print(total_reserved); _rw_region.print(total_reserved);