Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/shared/gcTimer.hpp
38920 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP25#define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP2627#include "memory/allocation.hpp"28#include "prims/jni_md.h"29#include "utilities/macros.hpp"30#include "utilities/ticks.hpp"3132class ConcurrentPhase;33class GCPhase;34class PausePhase;3536template <class E> class GrowableArray;3738class PhaseVisitor {39public:40virtual void visit(GCPhase* phase) = 0;41virtual void visit(PausePhase* phase) { visit((GCPhase*)phase); }42virtual void visit(ConcurrentPhase* phase) { visit((GCPhase*)phase); }43};4445class GCPhase {46const char* _name;47int _level;48Ticks _start;49Ticks _end;5051public:52void set_name(const char* name) { _name = name; }53const char* name() const { return _name; }5455int level() const { return _level; }56void set_level(int level) { _level = level; }5758const Ticks start() const { return _start; }59void set_start(const Ticks& time) { _start = time; }6061const Ticks end() const { return _end; }62void set_end(const Ticks& time) { _end = time; }6364virtual void accept(PhaseVisitor* visitor) = 0;65};6667class PausePhase : public GCPhase {68public:69void accept(PhaseVisitor* visitor) {70visitor->visit(this);71}72};7374class ConcurrentPhase : public GCPhase {75void accept(PhaseVisitor* visitor) {76visitor->visit(this);77}78};7980class PhasesStack {81public:82// FIXME: Temporary set to 5 (used to be 4), since Reference processing needs it.83static const int PHASE_LEVELS = 5;8485private:86int _phase_indices[PHASE_LEVELS];87int _next_phase_level;8889public:90PhasesStack() { clear(); }91void clear();9293void push(int phase_index);94int pop();95int count() const;96};9798class TimePartitions {99static const int INITIAL_CAPACITY = 10;100101// Currently we only support pause phases.102GrowableArray<PausePhase>* _phases;103PhasesStack _active_phases;104105Tickspan _sum_of_pauses;106Tickspan _longest_pause;107108public:109TimePartitions();110~TimePartitions();111void clear();112113void report_gc_phase_start(const char* name, const Ticks& time);114void report_gc_phase_end(const Ticks& time);115116int num_phases() const;117GCPhase* phase_at(int index) const;118119const Tickspan sum_of_pauses() const { return _sum_of_pauses; }120const Tickspan longest_pause() const { return _longest_pause; }121122bool has_active_phases();123private:124void update_statistics(GCPhase* phase);125};126127class PhasesIterator {128public:129virtual bool has_next() = 0;130virtual GCPhase* next() = 0;131};132133class GCTimer : public ResourceObj {134NOT_PRODUCT(friend class GCTimerTest;)135protected:136Ticks _gc_start;137Ticks _gc_end;138TimePartitions _time_partitions;139140public:141virtual void register_gc_start(const Ticks& time = Ticks::now());142virtual void register_gc_end(const Ticks& time = Ticks::now());143144void register_gc_phase_start(const char* name, const Ticks& time);145void register_gc_phase_end(const Ticks& time);146147const Ticks gc_start() const { return _gc_start; }148const Ticks gc_end() const { return _gc_end; }149150TimePartitions* time_partitions() { return &_time_partitions; }151152protected:153void register_gc_pause_start(const char* name, const Ticks& time = Ticks::now());154void register_gc_pause_end(const Ticks& time = Ticks::now());155};156157class STWGCTimer : public GCTimer {158public:159virtual void register_gc_start(const Ticks& time = Ticks::now());160virtual void register_gc_end(const Ticks& time = Ticks::now());161};162163class ConcurrentGCTimer : public GCTimer {164public:165void register_gc_pause_start(const char* name);166void register_gc_pause_end();167};168169class TimePartitionPhasesIterator {170TimePartitions* _time_partitions;171int _next;172173public:174TimePartitionPhasesIterator(TimePartitions* time_partitions) : _time_partitions(time_partitions), _next(0) { }175176virtual bool has_next();177virtual GCPhase* next();178};179180181/////////////// Unit tests ///////////////182183#ifndef PRODUCT184185class GCTimerAllTest {186public:187static void all();188};189190#endif191192#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCTIMER_HPP193194195