gcTimer.hpp 4.9 KB
Newer Older
S
sla 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP
#define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP

#include "memory/allocation.hpp"
#include "prims/jni_md.h"
#include "utilities/macros.hpp"
31
#include "utilities/ticks.hpp"
S
sla 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

class ConcurrentPhase;
class GCPhase;
class PausePhase;

template <class E> class GrowableArray;

class PhaseVisitor {
 public:
  virtual void visit(GCPhase* phase) = 0;
  virtual void visit(PausePhase* phase) { visit((GCPhase*)phase); }
  virtual void visit(ConcurrentPhase* phase) { visit((GCPhase*)phase); }
};

class GCPhase {
  const char* _name;
  int _level;
49 50
  Ticks _start;
  Ticks _end;
S
sla 已提交
51 52 53

 public:
  void set_name(const char* name) { _name = name; }
54
  const char* name() const { return _name; }
S
sla 已提交
55

56
  int level() const { return _level; }
S
sla 已提交
57 58
  void set_level(int level) { _level = level; }

59 60
  const Ticks start() const { return _start; }
  void set_start(const Ticks& time) { _start = time; }
S
sla 已提交
61

62 63
  const Ticks end() const { return _end; }
  void set_end(const Ticks& time) { _end = time; }
S
sla 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

  virtual void accept(PhaseVisitor* visitor) = 0;
};

class PausePhase : public GCPhase {
 public:
  void accept(PhaseVisitor* visitor) {
    visitor->visit(this);
  }
};

class ConcurrentPhase : public GCPhase {
  void accept(PhaseVisitor* visitor) {
    visitor->visit(this);
  }
};

class PhasesStack {
 public:
  // FIXME: Temporary set to 5 (used to be 4), since Reference processing needs it.
  static const int PHASE_LEVELS = 5;

 private:
  int _phase_indices[PHASE_LEVELS];
  int _next_phase_level;

 public:
  PhasesStack() { clear(); }
  void clear();

  void push(int phase_index);
  int pop();
  int count() const;
};

class TimePartitions {
  static const int INITIAL_CAPACITY = 10;

  // Currently we only support pause phases.
  GrowableArray<PausePhase>* _phases;
  PhasesStack _active_phases;

106 107
  Tickspan _sum_of_pauses;
  Tickspan _longest_pause;
S
sla 已提交
108 109 110 111 112 113

 public:
  TimePartitions();
  ~TimePartitions();
  void clear();

114 115
  void report_gc_phase_start(const char* name, const Ticks& time);
  void report_gc_phase_end(const Ticks& time);
S
sla 已提交
116 117 118 119

  int num_phases() const;
  GCPhase* phase_at(int index) const;

120 121
  const Tickspan sum_of_pauses() const { return _sum_of_pauses; }
  const Tickspan longest_pause() const { return _longest_pause; }
S
sla 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

  bool has_active_phases();
 private:
  void update_statistics(GCPhase* phase);
};

class PhasesIterator {
 public:
  virtual bool has_next() = 0;
  virtual GCPhase* next() = 0;
};

class GCTimer : public ResourceObj {
  NOT_PRODUCT(friend class GCTimerTest;)
 protected:
137 138
  Ticks _gc_start;
  Ticks _gc_end;
S
sla 已提交
139 140 141
  TimePartitions _time_partitions;

 public:
142 143
  virtual void register_gc_start(const Ticks& time = Ticks::now());
  virtual void register_gc_end(const Ticks& time = Ticks::now());
S
sla 已提交
144

145 146
  void register_gc_phase_start(const char* name, const Ticks& time);
  void register_gc_phase_end(const Ticks& time);
S
sla 已提交
147

148 149
  const Ticks gc_start() const { return _gc_start; }
  const Ticks gc_end() const { return _gc_end; }
S
sla 已提交
150 151 152 153

  TimePartitions* time_partitions() { return &_time_partitions; }

 protected:
154 155
  void register_gc_pause_start(const char* name, const Ticks& time = Ticks::now());
  void register_gc_pause_end(const Ticks& time = Ticks::now());
S
sla 已提交
156 157 158 159
};

class STWGCTimer : public GCTimer {
 public:
160 161
  virtual void register_gc_start(const Ticks& time = Ticks::now());
  virtual void register_gc_end(const Ticks& time = Ticks::now());
S
sla 已提交
162 163 164 165
};

class ConcurrentGCTimer : public GCTimer {
 public:
166 167
  void register_gc_pause_start(const char* name);
  void register_gc_pause_end();
S
sla 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
};

class TimePartitionPhasesIterator {
  TimePartitions* _time_partitions;
  int _next;

 public:
  TimePartitionPhasesIterator(TimePartitions* time_partitions) : _time_partitions(time_partitions), _next(0) { }

  virtual bool has_next();
  virtual GCPhase* next();
};


/////////////// Unit tests ///////////////

#ifndef PRODUCT

class GCTimerAllTest {
 public:
  static void all();
};

#endif

#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP