src/share/vm/gc_implementation/shared/gcTimer.hpp

Thu, 19 Jun 2014 13:31:14 +0200

author
brutisso
date
Thu, 19 Jun 2014 13:31:14 +0200
changeset 6904
0982ec23da03
parent 6131
86e6d691f2e1
child 6876
710a3c8b516e
permissions
-rw-r--r--

8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
Reviewed-by: jwilhelm, ehelin, tschatzl

sla@5237 1 /*
sla@5237 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
sla@5237 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
sla@5237 4 *
sla@5237 5 * This code is free software; you can redistribute it and/or modify it
sla@5237 6 * under the terms of the GNU General Public License version 2 only, as
sla@5237 7 * published by the Free Software Foundation.
sla@5237 8 *
sla@5237 9 * This code is distributed in the hope that it will be useful, but WITHOUT
sla@5237 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
sla@5237 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
sla@5237 12 * version 2 for more details (a copy is included in the LICENSE file that
sla@5237 13 * accompanied this code).
sla@5237 14 *
sla@5237 15 * You should have received a copy of the GNU General Public License version
sla@5237 16 * 2 along with this work; if not, write to the Free Software Foundation,
sla@5237 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
sla@5237 18 *
sla@5237 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
sla@5237 20 * or visit www.oracle.com if you need additional information or have any
sla@5237 21 * questions.
sla@5237 22 *
sla@5237 23 */
sla@5237 24
sla@5237 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP
sla@5237 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP
sla@5237 27
sla@5237 28 #include "memory/allocation.hpp"
sla@5237 29 #include "prims/jni_md.h"
sla@5237 30 #include "utilities/macros.hpp"
mgronlun@6131 31 #include "utilities/ticks.hpp"
sla@5237 32
sla@5237 33 class ConcurrentPhase;
sla@5237 34 class GCPhase;
sla@5237 35 class PausePhase;
sla@5237 36
sla@5237 37 template <class E> class GrowableArray;
sla@5237 38
sla@5237 39 class PhaseVisitor {
sla@5237 40 public:
sla@5237 41 virtual void visit(GCPhase* phase) = 0;
sla@5237 42 virtual void visit(PausePhase* phase) { visit((GCPhase*)phase); }
sla@5237 43 virtual void visit(ConcurrentPhase* phase) { visit((GCPhase*)phase); }
sla@5237 44 };
sla@5237 45
sla@5237 46 class GCPhase {
sla@5237 47 const char* _name;
sla@5237 48 int _level;
mgronlun@6131 49 Ticks _start;
mgronlun@6131 50 Ticks _end;
sla@5237 51
sla@5237 52 public:
sla@5237 53 void set_name(const char* name) { _name = name; }
mgronlun@6131 54 const char* name() const { return _name; }
sla@5237 55
mgronlun@6131 56 int level() const { return _level; }
sla@5237 57 void set_level(int level) { _level = level; }
sla@5237 58
mgronlun@6131 59 const Ticks start() const { return _start; }
mgronlun@6131 60 void set_start(const Ticks& time) { _start = time; }
sla@5237 61
mgronlun@6131 62 const Ticks end() const { return _end; }
mgronlun@6131 63 void set_end(const Ticks& time) { _end = time; }
sla@5237 64
sla@5237 65 virtual void accept(PhaseVisitor* visitor) = 0;
sla@5237 66 };
sla@5237 67
sla@5237 68 class PausePhase : public GCPhase {
sla@5237 69 public:
sla@5237 70 void accept(PhaseVisitor* visitor) {
sla@5237 71 visitor->visit(this);
sla@5237 72 }
sla@5237 73 };
sla@5237 74
sla@5237 75 class ConcurrentPhase : public GCPhase {
sla@5237 76 void accept(PhaseVisitor* visitor) {
sla@5237 77 visitor->visit(this);
sla@5237 78 }
sla@5237 79 };
sla@5237 80
sla@5237 81 class PhasesStack {
sla@5237 82 public:
sla@5237 83 // FIXME: Temporary set to 5 (used to be 4), since Reference processing needs it.
sla@5237 84 static const int PHASE_LEVELS = 5;
sla@5237 85
sla@5237 86 private:
sla@5237 87 int _phase_indices[PHASE_LEVELS];
sla@5237 88 int _next_phase_level;
sla@5237 89
sla@5237 90 public:
sla@5237 91 PhasesStack() { clear(); }
sla@5237 92 void clear();
sla@5237 93
sla@5237 94 void push(int phase_index);
sla@5237 95 int pop();
sla@5237 96 int count() const;
sla@5237 97 };
sla@5237 98
sla@5237 99 class TimePartitions {
sla@5237 100 static const int INITIAL_CAPACITY = 10;
sla@5237 101
sla@5237 102 // Currently we only support pause phases.
sla@5237 103 GrowableArray<PausePhase>* _phases;
sla@5237 104 PhasesStack _active_phases;
sla@5237 105
mgronlun@6131 106 Tickspan _sum_of_pauses;
mgronlun@6131 107 Tickspan _longest_pause;
sla@5237 108
sla@5237 109 public:
sla@5237 110 TimePartitions();
sla@5237 111 ~TimePartitions();
sla@5237 112 void clear();
sla@5237 113
mgronlun@6131 114 void report_gc_phase_start(const char* name, const Ticks& time);
mgronlun@6131 115 void report_gc_phase_end(const Ticks& time);
sla@5237 116
sla@5237 117 int num_phases() const;
sla@5237 118 GCPhase* phase_at(int index) const;
sla@5237 119
mgronlun@6131 120 const Tickspan sum_of_pauses() const { return _sum_of_pauses; }
mgronlun@6131 121 const Tickspan longest_pause() const { return _longest_pause; }
sla@5237 122
sla@5237 123 bool has_active_phases();
sla@5237 124 private:
sla@5237 125 void update_statistics(GCPhase* phase);
sla@5237 126 };
sla@5237 127
sla@5237 128 class PhasesIterator {
sla@5237 129 public:
sla@5237 130 virtual bool has_next() = 0;
sla@5237 131 virtual GCPhase* next() = 0;
sla@5237 132 };
sla@5237 133
sla@5237 134 class GCTimer : public ResourceObj {
sla@5237 135 NOT_PRODUCT(friend class GCTimerTest;)
sla@5237 136 protected:
mgronlun@6131 137 Ticks _gc_start;
mgronlun@6131 138 Ticks _gc_end;
sla@5237 139 TimePartitions _time_partitions;
sla@5237 140
sla@5237 141 public:
mgronlun@6131 142 virtual void register_gc_start(const Ticks& time = Ticks::now());
mgronlun@6131 143 virtual void register_gc_end(const Ticks& time = Ticks::now());
sla@5237 144
mgronlun@6131 145 void register_gc_phase_start(const char* name, const Ticks& time);
mgronlun@6131 146 void register_gc_phase_end(const Ticks& time);
sla@5237 147
mgronlun@6131 148 const Ticks gc_start() const { return _gc_start; }
mgronlun@6131 149 const Ticks gc_end() const { return _gc_end; }
sla@5237 150
sla@5237 151 TimePartitions* time_partitions() { return &_time_partitions; }
sla@5237 152
sla@5237 153 protected:
mgronlun@6131 154 void register_gc_pause_start(const char* name, const Ticks& time = Ticks::now());
mgronlun@6131 155 void register_gc_pause_end(const Ticks& time = Ticks::now());
sla@5237 156 };
sla@5237 157
sla@5237 158 class STWGCTimer : public GCTimer {
sla@5237 159 public:
mgronlun@6131 160 virtual void register_gc_start(const Ticks& time = Ticks::now());
mgronlun@6131 161 virtual void register_gc_end(const Ticks& time = Ticks::now());
sla@5237 162 };
sla@5237 163
sla@5237 164 class ConcurrentGCTimer : public GCTimer {
sla@5237 165 public:
mgronlun@6131 166 void register_gc_pause_start(const char* name);
mgronlun@6131 167 void register_gc_pause_end();
sla@5237 168 };
sla@5237 169
sla@5237 170 class TimePartitionPhasesIterator {
sla@5237 171 TimePartitions* _time_partitions;
sla@5237 172 int _next;
sla@5237 173
sla@5237 174 public:
sla@5237 175 TimePartitionPhasesIterator(TimePartitions* time_partitions) : _time_partitions(time_partitions), _next(0) { }
sla@5237 176
sla@5237 177 virtual bool has_next();
sla@5237 178 virtual GCPhase* next();
sla@5237 179 };
sla@5237 180
sla@5237 181
sla@5237 182 /////////////// Unit tests ///////////////
sla@5237 183
sla@5237 184 #ifndef PRODUCT
sla@5237 185
sla@5237 186 class GCTimerAllTest {
sla@5237 187 public:
sla@5237 188 static void all();
sla@5237 189 };
sla@5237 190
sla@5237 191 #endif
sla@5237 192
sla@5237 193 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP

mercurial