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