1 /*
   2  * Copyright (c) 2014, 2016, 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 #ifndef SHARE_VM_GC_G1_G1STRINGDEDUPSTAT_HPP
  26 #define SHARE_VM_GC_G1_G1STRINGDEDUPSTAT_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/os.hpp"
  30 
  31 // Macros for GC log output formating
  32 #define G1_STRDEDUP_OBJECTS_FORMAT         UINTX_FORMAT_W(12)
  33 #define G1_STRDEDUP_TIME_FORMAT            "%.3fs"
  34 #define G1_STRDEDUP_TIME_PARAM(time)       (time)
  35 #define G1_STRDEDUP_TIME_FORMAT_MS         "%.3fms"
  36 #define G1_STRDEDUP_TIME_PARAM_MS(time)    ((time) * MILLIUNITS)
  37 #define G1_STRDEDUP_PERCENT_FORMAT         "%5.1f%%"
  38 #define G1_STRDEDUP_PERCENT_FORMAT_NS      "%.1f%%"
  39 #define G1_STRDEDUP_BYTES_FORMAT           "%8.1f%s"
  40 #define G1_STRDEDUP_BYTES_FORMAT_NS        "%.1f%s"
  41 #define G1_STRDEDUP_BYTES_PARAM(bytes)     byte_size_in_proper_unit((double)(bytes)), proper_unit_for_byte_size((bytes))
  42 
  43 //
  44 // Statistics gathered by the deduplication thread.
  45 //
  46 class G1StringDedupStat : public StackObj {
  47 private:
  48   // Counters
  49   uintx  _inspected;
  50   uintx  _skipped;
  51   uintx  _hashed;
  52   uintx  _known;
  53   uintx  _new;
  54   uintx  _new_bytes;
  55   uintx  _deduped;
  56   uintx  _deduped_bytes;
  57   uintx  _deduped_young;
  58   uintx  _deduped_young_bytes;
  59   uintx  _deduped_old;
  60   uintx  _deduped_old_bytes;
  61   uintx  _idle;
  62   uintx  _exec;
  63   uintx  _block;
  64 
  65   // Time spent by the deduplication thread in different phases
  66   double _start_concurrent;
  67   double _end_concurrent;
  68   double _start_phase;
  69   double _idle_elapsed;
  70   double _exec_elapsed;
  71   double _block_elapsed;
  72 
  73 public:
  74   G1StringDedupStat();
  75 
  76   void inc_inspected() {
  77     _inspected++;
  78   }
  79 
  80   void inc_skipped() {
  81     _skipped++;
  82   }
  83 
  84   void inc_hashed() {
  85     _hashed++;
  86   }
  87 
  88   void inc_known() {
  89     _known++;
  90   }
  91 
  92   void inc_new(uintx bytes) {
  93     _new++;
  94     _new_bytes += bytes;
  95   }
  96 
  97   void inc_deduped_young(uintx bytes) {
  98     _deduped++;
  99     _deduped_bytes += bytes;
 100     _deduped_young++;
 101     _deduped_young_bytes += bytes;
 102   }
 103 
 104   void inc_deduped_old(uintx bytes) {
 105     _deduped++;
 106     _deduped_bytes += bytes;
 107     _deduped_old++;
 108     _deduped_old_bytes += bytes;
 109   }
 110 
 111   void mark_idle() {
 112     _start_phase = os::elapsedTime();
 113     _idle++;
 114   }
 115 
 116   void mark_exec() {
 117     double now = os::elapsedTime();
 118     _idle_elapsed = now - _start_phase;
 119     _start_phase = now;
 120     _start_concurrent = now;
 121     _exec++;
 122   }
 123 
 124   void mark_block() {
 125     double now = os::elapsedTime();
 126     _exec_elapsed += now - _start_phase;
 127     _start_phase = now;
 128     _block++;
 129   }
 130 
 131   void mark_unblock() {
 132     double now = os::elapsedTime();
 133     _block_elapsed += now - _start_phase;
 134     _start_phase = now;
 135   }
 136 
 137   void mark_done() {
 138     double now = os::elapsedTime();
 139     _exec_elapsed += now - _start_phase;
 140     _end_concurrent = now;
 141   }
 142 
 143   void add(const G1StringDedupStat& stat);
 144 
 145   static void print_start(const G1StringDedupStat& last_stat);
 146   static void print_end(const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat);
 147   static void print_statistics(const G1StringDedupStat& stat, bool total);
 148 };
 149 
 150 #endif // SHARE_VM_GC_G1_G1STRINGDEDUPSTAT_HPP