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