src/hotspot/share/utilities/tableStatistics.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 54797 c90da1272d7f
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     1
/*
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     4
 *
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     7
 * published by the Free Software Foundation.
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     8
 *
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    13
 * accompanied this code).
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    14
 *
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    18
 *
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    21
 * questions.
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    22
 *
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    23
 */
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    24
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    25
#include "precompiled.hpp"
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    26
#include "runtime/atomic.hpp"
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    27
#include "runtime/os.hpp"
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    28
#include "utilities/debug.hpp"
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    29
#include "utilities/macros.hpp"
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    30
#include "utilities/tableStatistics.hpp"
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    31
#if INCLUDE_JFR
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    32
#include "jfr/jfr.hpp"
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    33
#endif
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    34
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    35
TableRateStatistics::TableRateStatistics() :
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    36
  _added_items(0), _removed_items(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    37
  _time_stamp(0), _seconds_stamp(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    38
  _added_items_stamp(0), _added_items_stamp_prev(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    39
  _removed_items_stamp(0), _removed_items_stamp_prev(0) {}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    40
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    41
TableRateStatistics::~TableRateStatistics() { };
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    42
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    43
void TableRateStatistics::add() {
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    44
#if INCLUDE_JFR
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    45
  if (Jfr::is_recording()) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    46
    Atomic::inc(&_added_items);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    47
  }
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    48
#endif
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    49
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    50
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    51
void TableRateStatistics::remove() {
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    52
#if INCLUDE_JFR
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    53
  if (Jfr::is_recording()) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    54
    Atomic::inc(&_removed_items);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    55
  }
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
    56
#endif
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    57
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    58
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    59
void TableRateStatistics::stamp() {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    60
  jlong now = os::javaTimeNanos();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    61
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    62
  _added_items_stamp_prev = _added_items_stamp;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    63
  _removed_items_stamp_prev = _removed_items_stamp;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    64
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    65
  _added_items_stamp = _added_items;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    66
  _removed_items_stamp = _removed_items;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    67
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    68
  if (_time_stamp == 0) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    69
    _time_stamp = now - 1000000000;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    70
  }
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    71
  jlong diff = (now - _time_stamp);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    72
  _seconds_stamp = (float)diff / 1000000000.0;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    73
  _time_stamp = now;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    74
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    75
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    76
float TableRateStatistics::get_add_rate() {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    77
  return (float)((_added_items_stamp - _added_items_stamp_prev) / _seconds_stamp);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    78
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    79
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    80
float TableRateStatistics::get_remove_rate() {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    81
  return (float)((_removed_items_stamp - _removed_items_stamp_prev) / _seconds_stamp);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    82
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    83
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    84
TableStatistics::TableStatistics() :
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    85
  _literal_bytes(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    86
  _number_of_buckets(0), _number_of_entries(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    87
  _maximum_bucket_size(0), _average_bucket_size(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    88
  _variance_of_bucket_size(0), _stddev_of_bucket_size(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    89
  _bucket_bytes(0), _entry_bytes(0), _total_footprint(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    90
  _bucket_size(0), _entry_size(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    91
  _add_rate(0), _remove_rate(0) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    92
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    93
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    94
TableStatistics::TableStatistics(TableRateStatistics& rate_stats, NumberSeq summary, size_t literal_bytes, size_t bucket_bytes, size_t node_bytes) :
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    95
  _literal_bytes(literal_bytes),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    96
  _number_of_buckets(0), _number_of_entries(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    97
  _maximum_bucket_size(0), _average_bucket_size(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    98
  _variance_of_bucket_size(0), _stddev_of_bucket_size(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
    99
  _bucket_bytes(0), _entry_bytes(0), _total_footprint(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   100
  _bucket_size(0), _entry_size(0),
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   101
  _add_rate(0), _remove_rate(0) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   102
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   103
  _number_of_buckets = summary.num();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   104
  _number_of_entries = summary.sum();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   105
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   106
  _maximum_bucket_size = summary.maximum();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   107
  _average_bucket_size = summary.avg();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   108
  _variance_of_bucket_size = summary.variance();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   109
  _stddev_of_bucket_size = summary.sd();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   110
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   111
  _bucket_bytes = _number_of_buckets * bucket_bytes;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   112
  _entry_bytes = _number_of_entries * node_bytes;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   113
  _total_footprint = _literal_bytes + _bucket_bytes + _entry_bytes;
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   114
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   115
  _bucket_size = (_number_of_buckets <= 0) ? 0 : (_bucket_bytes / _number_of_buckets);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   116
  _entry_size = (_number_of_entries <= 0) ? 0 : (_entry_bytes / _number_of_entries);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   117
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
   118
#if INCLUDE_JFR
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   119
  if (Jfr::is_recording()) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   120
    rate_stats.stamp();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   121
    _add_rate = rate_stats.get_add_rate();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   122
    _remove_rate = rate_stats.get_remove_rate();
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   123
  }
54797
c90da1272d7f 8223599: minimal build fails after JDK-8185525
aoqi
parents: 54764
diff changeset
   124
#endif
54764
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   125
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   126
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   127
TableStatistics::~TableStatistics() { }
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   128
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   129
void TableStatistics::print(outputStream* st, const char *table_name) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   130
  st->print_cr("%s statistics:", table_name);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   131
  st->print_cr("Number of buckets       : %9" PRIuPTR " = %9" PRIuPTR
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   132
               " bytes, each " SIZE_FORMAT,
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   133
              _number_of_buckets, _bucket_bytes, _bucket_size);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   134
  st->print_cr("Number of entries       : %9" PRIuPTR " = %9" PRIuPTR
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   135
               " bytes, each " SIZE_FORMAT,
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   136
               _number_of_entries, _entry_bytes, _entry_size);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   137
  if (_literal_bytes != 0) {
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   138
    float literal_avg = (_number_of_entries <= 0) ? 0 : (_literal_bytes / _number_of_entries);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   139
    st->print_cr("Number of literals      : %9" PRIuPTR " = %9" PRIuPTR
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   140
                 " bytes, avg %7.3f",
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   141
                 _number_of_entries, _literal_bytes, literal_avg);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   142
  }
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   143
  st->print_cr("Total footprint         : %9s = %9" PRIuPTR " bytes", "", _total_footprint);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   144
  st->print_cr("Average bucket size     : %9.3f", _average_bucket_size);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   145
  st->print_cr("Variance of bucket size : %9.3f", _variance_of_bucket_size);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   146
  st->print_cr("Std. dev. of bucket size: %9.3f", _stddev_of_bucket_size);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   147
  st->print_cr("Maximum bucket size     : %9" PRIuPTR, _maximum_bucket_size);
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   148
}
865ec913f916 8185525: Add JFR event for DictionarySizes
gziemski
parents:
diff changeset
   149