1 /*
2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #include "precompiled.hpp"
26 #include "gc/shared/stringdedup/stringDedupStat.hpp"
27 #include "logging/log.hpp"
28 
StringDedupStat()29 StringDedupStat::StringDedupStat() :
30   _inspected(0),
31   _skipped(0),
32   _hashed(0),
33   _known(0),
34   _new(0),
35   _new_bytes(0),
36   _deduped(0),
37   _deduped_bytes(0),
38   _idle(0),
39   _exec(0),
40   _block(0),
41   _start_concurrent(0.0),
42   _end_concurrent(0.0),
43   _start_phase(0.0),
44   _idle_elapsed(0.0),
45   _exec_elapsed(0.0),
46   _block_elapsed(0.0) {
47 }
48 
add(const StringDedupStat * const stat)49 void StringDedupStat::add(const StringDedupStat* const stat) {
50   _inspected           += stat->_inspected;
51   _skipped             += stat->_skipped;
52   _hashed              += stat->_hashed;
53   _known               += stat->_known;
54   _new                 += stat->_new;
55   _new_bytes           += stat->_new_bytes;
56   _deduped             += stat->_deduped;
57   _deduped_bytes       += stat->_deduped_bytes;
58   _idle                += stat->_idle;
59   _exec                += stat->_exec;
60   _block               += stat->_block;
61   _idle_elapsed        += stat->_idle_elapsed;
62   _exec_elapsed        += stat->_exec_elapsed;
63   _block_elapsed       += stat->_block_elapsed;
64 }
65 
print_start(const StringDedupStat * last_stat)66 void StringDedupStat::print_start(const StringDedupStat* last_stat) {
67   log_info(gc, stringdedup)(
68      "Concurrent String Deduplication (" STRDEDUP_TIME_FORMAT ")",
69      STRDEDUP_TIME_PARAM(last_stat->_start_concurrent));
70 }
71 
print_end(const StringDedupStat * last_stat,const StringDedupStat * total_stat)72 void StringDedupStat::print_end(const StringDedupStat* last_stat, const StringDedupStat* total_stat) {
73   double total_deduped_bytes_percent = 0.0;
74 
75   if (total_stat->_new_bytes > 0) {
76     // Avoid division by zero
77     total_deduped_bytes_percent = percent_of(total_stat->_deduped_bytes, total_stat->_new_bytes);
78   }
79 
80   log_info(gc, stringdedup)(
81     "Concurrent String Deduplication "
82     STRDEDUP_BYTES_FORMAT_NS "->" STRDEDUP_BYTES_FORMAT_NS "(" STRDEDUP_BYTES_FORMAT_NS ") "
83     "avg " STRDEDUP_PERCENT_FORMAT_NS " "
84     "(" STRDEDUP_TIME_FORMAT ", " STRDEDUP_TIME_FORMAT ") " STRDEDUP_TIME_FORMAT_MS,
85     STRDEDUP_BYTES_PARAM(last_stat->_new_bytes),
86     STRDEDUP_BYTES_PARAM(last_stat->_new_bytes - last_stat->_deduped_bytes),
87     STRDEDUP_BYTES_PARAM(last_stat->_deduped_bytes),
88     total_deduped_bytes_percent,
89     STRDEDUP_TIME_PARAM(last_stat->_start_concurrent),
90     STRDEDUP_TIME_PARAM(last_stat->_end_concurrent),
91     STRDEDUP_TIME_PARAM_MS(last_stat->_exec_elapsed));
92 }
93 
reset()94 void StringDedupStat::reset() {
95   _inspected = 0;
96   _skipped = 0;
97   _hashed = 0;
98   _known = 0;
99   _new = 0;
100   _new_bytes = 0;
101   _deduped = 0;
102   _deduped_bytes = 0;
103   _idle = 0;
104   _exec = 0;
105   _block = 0;
106   _start_concurrent = 0.0;
107   _end_concurrent = 0.0;
108   _start_phase = 0.0;
109   _idle_elapsed = 0.0;
110   _exec_elapsed = 0.0;
111   _block_elapsed = 0.0;
112 }
113 
print_statistics(bool total) const114 void StringDedupStat::print_statistics(bool total) const {
115   double skipped_percent             = percent_of(_skipped, _inspected);
116   double hashed_percent              = percent_of(_hashed, _inspected);
117   double known_percent               = percent_of(_known, _inspected);
118   double new_percent                 = percent_of(_new, _inspected);
119   double deduped_percent             = percent_of(_deduped, _new);
120   double deduped_bytes_percent       = percent_of(_deduped_bytes, _new_bytes);
121 /*
122   double deduped_young_percent       = percent_of(stat._deduped_young, stat._deduped);
123   double deduped_young_bytes_percent = percent_of(stat._deduped_young_bytes, stat._deduped_bytes);
124   double deduped_old_percent         = percent_of(stat._deduped_old, stat._deduped);
125   double deduped_old_bytes_percent   = percent_of(stat._deduped_old_bytes, stat._deduped_bytes);
126 */
127   if (total) {
128     log_debug(gc, stringdedup)(
129       "  Total Exec: " UINTX_FORMAT "/" STRDEDUP_TIME_FORMAT_MS
130       ", Idle: " UINTX_FORMAT "/" STRDEDUP_TIME_FORMAT_MS
131       ", Blocked: " UINTX_FORMAT "/" STRDEDUP_TIME_FORMAT_MS,
132       _exec, STRDEDUP_TIME_PARAM_MS(_exec_elapsed),
133       _idle, STRDEDUP_TIME_PARAM_MS(_idle_elapsed),
134       _block, STRDEDUP_TIME_PARAM_MS(_block_elapsed));
135   } else {
136     log_debug(gc, stringdedup)(
137       "  Last Exec: " STRDEDUP_TIME_FORMAT_MS
138       ", Idle: " STRDEDUP_TIME_FORMAT_MS
139       ", Blocked: " UINTX_FORMAT "/" STRDEDUP_TIME_FORMAT_MS,
140       STRDEDUP_TIME_PARAM_MS(_exec_elapsed),
141       STRDEDUP_TIME_PARAM_MS(_idle_elapsed),
142       _block, STRDEDUP_TIME_PARAM_MS(_block_elapsed));
143   }
144   log_debug(gc, stringdedup)("    Inspected:    " STRDEDUP_OBJECTS_FORMAT, _inspected);
145   log_debug(gc, stringdedup)("      Skipped:    " STRDEDUP_OBJECTS_FORMAT "(" STRDEDUP_PERCENT_FORMAT ")", _skipped, skipped_percent);
146   log_debug(gc, stringdedup)("      Hashed:     " STRDEDUP_OBJECTS_FORMAT "(" STRDEDUP_PERCENT_FORMAT ")", _hashed, hashed_percent);
147   log_debug(gc, stringdedup)("      Known:      " STRDEDUP_OBJECTS_FORMAT "(" STRDEDUP_PERCENT_FORMAT ")", _known, known_percent);
148   log_debug(gc, stringdedup)("      New:        " STRDEDUP_OBJECTS_FORMAT "(" STRDEDUP_PERCENT_FORMAT ") " STRDEDUP_BYTES_FORMAT,
149                              _new, new_percent, STRDEDUP_BYTES_PARAM(_new_bytes));
150   log_debug(gc, stringdedup)("    Deduplicated: " STRDEDUP_OBJECTS_FORMAT "(" STRDEDUP_PERCENT_FORMAT ") " STRDEDUP_BYTES_FORMAT "(" STRDEDUP_PERCENT_FORMAT ")",
151                              _deduped, deduped_percent, STRDEDUP_BYTES_PARAM(_deduped_bytes), deduped_bytes_percent);
152 }
153