--- old/src/hotspot/share/utilities/hashtable.cpp 2019-04-04 14:46:47.000000000 -0500 +++ new/src/hotspot/share/utilities/hashtable.cpp 2019-04-04 14:46:46.000000000 -0500 @@ -191,18 +191,7 @@ } } -// Dump footprint and bucket length statistics -// -// Note: if you create a new subclass of Hashtable, you will need to -// add a new function static int literal_size(MyNewType lit) -// because I can't get template int literal_size(T) to pick the specializations for Symbol and oop. -// -// The StringTable and SymbolTable dumping print how much footprint is used by the String and Symbol -// literals. - -template void Hashtable::print_table_statistics(outputStream* st, - const char *table_name, - T (*literal_load_barrier)(HashtableEntry*)) { +template TableStatistics Hashtable::statistics_calculate(T (*literal_load_barrier)(HashtableEntry*)) { NumberSeq summary; int literal_bytes = 0; for (int i = 0; i < this->table_size(); ++i) { @@ -215,28 +204,19 @@ } summary.add((double)count); } - double num_buckets = summary.num(); - double num_entries = summary.sum(); + return TableStatistics(this->_stats_rate, summary, literal_bytes, sizeof(HashtableBucket), sizeof(HashtableEntry)); +} - int bucket_bytes = (int)num_buckets * sizeof(HashtableBucket); - int entry_bytes = (int)num_entries * sizeof(HashtableEntry); - int total_bytes = literal_bytes + bucket_bytes + entry_bytes; - - int bucket_size = (num_buckets <= 0) ? 0 : (bucket_bytes / num_buckets); - int entry_size = (num_entries <= 0) ? 0 : (entry_bytes / num_entries); - - st->print_cr("%s statistics:", table_name); - st->print_cr("Number of buckets : %9d = %9d bytes, each %d", (int)num_buckets, bucket_bytes, bucket_size); - st->print_cr("Number of entries : %9d = %9d bytes, each %d", (int)num_entries, entry_bytes, entry_size); - if (literal_bytes != 0) { - double literal_avg = (num_entries <= 0) ? 0 : (literal_bytes / num_entries); - st->print_cr("Number of literals : %9d = %9d bytes, avg %7.3f", (int)num_entries, literal_bytes, literal_avg); - } - st->print_cr("Total footprint : %9s = %9d bytes", "", total_bytes); - st->print_cr("Average bucket size : %9.3f", summary.avg()); - st->print_cr("Variance of bucket size : %9.3f", summary.variance()); - st->print_cr("Std. dev. of bucket size: %9.3f", summary.sd()); - st->print_cr("Maximum bucket size : %9d", (int)summary.maximum()); +// Dump footprint and bucket length statistics +// +// Note: if you create a new subclass of Hashtable, you will need to +// add a new function static int literal_size(MyNewType lit) +// because I can't get template int literal_size(T) to pick the specializations for Symbol and oop. +template void Hashtable::print_table_statistics(outputStream* st, + const char *table_name, + T (*literal_load_barrier)(HashtableEntry*)) { + TableStatistics ts = statistics_calculate(literal_load_barrier); + ts.print(st, table_name); } #ifndef PRODUCT