1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/shared/gcTimer.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,193 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "prims/jni_md.h" 1.33 +#include "utilities/macros.hpp" 1.34 +#include "utilities/ticks.hpp" 1.35 + 1.36 +class ConcurrentPhase; 1.37 +class GCPhase; 1.38 +class PausePhase; 1.39 + 1.40 +template <class E> class GrowableArray; 1.41 + 1.42 +class PhaseVisitor { 1.43 + public: 1.44 + virtual void visit(GCPhase* phase) = 0; 1.45 + virtual void visit(PausePhase* phase) { visit((GCPhase*)phase); } 1.46 + virtual void visit(ConcurrentPhase* phase) { visit((GCPhase*)phase); } 1.47 +}; 1.48 + 1.49 +class GCPhase { 1.50 + const char* _name; 1.51 + int _level; 1.52 + Ticks _start; 1.53 + Ticks _end; 1.54 + 1.55 + public: 1.56 + void set_name(const char* name) { _name = name; } 1.57 + const char* name() const { return _name; } 1.58 + 1.59 + int level() const { return _level; } 1.60 + void set_level(int level) { _level = level; } 1.61 + 1.62 + const Ticks start() const { return _start; } 1.63 + void set_start(const Ticks& time) { _start = time; } 1.64 + 1.65 + const Ticks end() const { return _end; } 1.66 + void set_end(const Ticks& time) { _end = time; } 1.67 + 1.68 + virtual void accept(PhaseVisitor* visitor) = 0; 1.69 +}; 1.70 + 1.71 +class PausePhase : public GCPhase { 1.72 + public: 1.73 + void accept(PhaseVisitor* visitor) { 1.74 + visitor->visit(this); 1.75 + } 1.76 +}; 1.77 + 1.78 +class ConcurrentPhase : public GCPhase { 1.79 + void accept(PhaseVisitor* visitor) { 1.80 + visitor->visit(this); 1.81 + } 1.82 +}; 1.83 + 1.84 +class PhasesStack { 1.85 + public: 1.86 + // FIXME: Temporary set to 5 (used to be 4), since Reference processing needs it. 1.87 + static const int PHASE_LEVELS = 5; 1.88 + 1.89 + private: 1.90 + int _phase_indices[PHASE_LEVELS]; 1.91 + int _next_phase_level; 1.92 + 1.93 + public: 1.94 + PhasesStack() { clear(); } 1.95 + void clear(); 1.96 + 1.97 + void push(int phase_index); 1.98 + int pop(); 1.99 + int count() const; 1.100 +}; 1.101 + 1.102 +class TimePartitions { 1.103 + static const int INITIAL_CAPACITY = 10; 1.104 + 1.105 + // Currently we only support pause phases. 1.106 + GrowableArray<PausePhase>* _phases; 1.107 + PhasesStack _active_phases; 1.108 + 1.109 + Tickspan _sum_of_pauses; 1.110 + Tickspan _longest_pause; 1.111 + 1.112 + public: 1.113 + TimePartitions(); 1.114 + ~TimePartitions(); 1.115 + void clear(); 1.116 + 1.117 + void report_gc_phase_start(const char* name, const Ticks& time); 1.118 + void report_gc_phase_end(const Ticks& time); 1.119 + 1.120 + int num_phases() const; 1.121 + GCPhase* phase_at(int index) const; 1.122 + 1.123 + const Tickspan sum_of_pauses() const { return _sum_of_pauses; } 1.124 + const Tickspan longest_pause() const { return _longest_pause; } 1.125 + 1.126 + bool has_active_phases(); 1.127 + private: 1.128 + void update_statistics(GCPhase* phase); 1.129 +}; 1.130 + 1.131 +class PhasesIterator { 1.132 + public: 1.133 + virtual bool has_next() = 0; 1.134 + virtual GCPhase* next() = 0; 1.135 +}; 1.136 + 1.137 +class GCTimer : public ResourceObj { 1.138 + NOT_PRODUCT(friend class GCTimerTest;) 1.139 + protected: 1.140 + Ticks _gc_start; 1.141 + Ticks _gc_end; 1.142 + TimePartitions _time_partitions; 1.143 + 1.144 + public: 1.145 + virtual void register_gc_start(const Ticks& time = Ticks::now()); 1.146 + virtual void register_gc_end(const Ticks& time = Ticks::now()); 1.147 + 1.148 + void register_gc_phase_start(const char* name, const Ticks& time); 1.149 + void register_gc_phase_end(const Ticks& time); 1.150 + 1.151 + const Ticks gc_start() const { return _gc_start; } 1.152 + const Ticks gc_end() const { return _gc_end; } 1.153 + 1.154 + TimePartitions* time_partitions() { return &_time_partitions; } 1.155 + 1.156 + protected: 1.157 + void register_gc_pause_start(const char* name, const Ticks& time = Ticks::now()); 1.158 + void register_gc_pause_end(const Ticks& time = Ticks::now()); 1.159 +}; 1.160 + 1.161 +class STWGCTimer : public GCTimer { 1.162 + public: 1.163 + virtual void register_gc_start(const Ticks& time = Ticks::now()); 1.164 + virtual void register_gc_end(const Ticks& time = Ticks::now()); 1.165 +}; 1.166 + 1.167 +class ConcurrentGCTimer : public GCTimer { 1.168 + public: 1.169 + void register_gc_pause_start(const char* name); 1.170 + void register_gc_pause_end(); 1.171 +}; 1.172 + 1.173 +class TimePartitionPhasesIterator { 1.174 + TimePartitions* _time_partitions; 1.175 + int _next; 1.176 + 1.177 + public: 1.178 + TimePartitionPhasesIterator(TimePartitions* time_partitions) : _time_partitions(time_partitions), _next(0) { } 1.179 + 1.180 + virtual bool has_next(); 1.181 + virtual GCPhase* next(); 1.182 +}; 1.183 + 1.184 + 1.185 +/////////////// Unit tests /////////////// 1.186 + 1.187 +#ifndef PRODUCT 1.188 + 1.189 +class GCTimerAllTest { 1.190 + public: 1.191 + static void all(); 1.192 +}; 1.193 + 1.194 +#endif 1.195 + 1.196 +#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP