Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/g1/g1ErgoVerbose.hpp
38920 views
/*1* Copyright (c) 2011, 2012, 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_G1_G1ERGOVERBOSE_HPP25#define SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP2627#include "memory/allocation.hpp"28#include "utilities/debug.hpp"2930// The log of G1's heuristic decisions comprises of a series of31// records which have a similar format in order to maintain32// consistency across records and ultimately easier parsing of the33// output, if we ever choose to do that. Each record consists of:34// * A time stamp to be able to easily correlate each record with35// other events.36// * A unique string to allow us to easily identify such records.37// * The name of the heuristic the record corresponds to.38// * An action string which describes the action that G1 did or is39// about to do.40// * An optional reason string which describes the reason for the41// action.42// * An optional number of name/value pairs which contributed to the43// decision to take the action described in the record.44//45// Each record is associated with a "tag" which is the combination of46// the heuristic the record corresponds to, as well as the min level47// of verboseness at which the record should be printed. The tag is48// checked against the current settings to determine whether the record49// should be printed or not.5051// The available verboseness levels.52typedef enum {53// Determine which part of the tag is occupied by the level.54ErgoLevelShift = 8,55ErgoLevelMask = ~((1 << ErgoLevelShift) - 1),5657// ErgoLow is 0 so that we don't have to explicitly or a heuristic58// id with ErgoLow to keep its use simpler.59ErgoLow = 0,60ErgoHigh = 1 << ErgoLevelShift61} ErgoLevel;6263// The available heuristics.64typedef enum {65// Determines which part of the tag is occupied by the heuristic id.66ErgoHeuristicMask = ~ErgoLevelMask,6768ErgoHeapSizing = 0,69ErgoCSetConstruction,70ErgoConcCycles,71ErgoMixedGCs,7273ErgoHeuristicNum74} ErgoHeuristic;7576class G1ErgoVerbose : AllStatic {77private:78// Determines the minimum verboseness level at which records will be79// printed.80static ErgoLevel _level;81// Determines which heuristics are currently enabled.82static bool _enabled[ErgoHeuristicNum];8384static ErgoLevel extract_level(int tag) {85return (ErgoLevel) (tag & ErgoLevelMask);86}8788static ErgoHeuristic extract_heuristic(int tag) {89return (ErgoHeuristic) (tag & ErgoHeuristicMask);90}9192public:93// Needs to be explicitly called at GC initialization.94static void initialize();9596static void set_level(ErgoLevel level);97static void set_enabled(ErgoHeuristic h, bool enabled);98// It is applied to all heuristics.99static void set_enabled(bool enabled);100101static bool enabled(int tag) {102ErgoLevel level = extract_level(tag);103ErgoHeuristic n = extract_heuristic(tag);104return level <= _level && _enabled[n];105}106107// Extract the heuristic id from the tag and return a string with108// its name.109static const char* to_string(int tag);110};111112// The macros below generate the format string for values of different113// types and/or metrics.114115// The reason for the action is optional and is handled specially: the116// reason string is concatenated here so it's not necessary to pass it117// as a parameter.118#define ergo_format_reason(_reason_) ", reason: " _reason_119120// Single parameter format strings121#define ergo_format_str(_name_) ", " _name_ ": %s"122#define ergo_format_region(_name_) ", " _name_ ": %u regions"123#define ergo_format_byte(_name_) ", " _name_ ": " SIZE_FORMAT " bytes"124#define ergo_format_double(_name_) ", " _name_ ": %1.2f"125#define ergo_format_perc(_name_) ", " _name_ ": %1.2f %%"126#define ergo_format_ms(_name_) ", " _name_ ": %1.2f ms"127#define ergo_format_size(_name_) ", " _name_ ": " SIZE_FORMAT128129// Double parameter format strings130#define ergo_format_byte_perc(_name_) \131", " _name_ ": " SIZE_FORMAT " bytes (%1.2f %%)"132133// Generates the format string134#define ergo_format(_extra_format_) \135" %1.3f: [G1Ergonomics (%s) %s" _extra_format_ "]"136137// Conditionally, prints an ergonomic decision record. _extra_format_138// is the format string for the optional items we'd like to print139// (i.e., the decision's reason and any associated values). This140// string should be built up using the ergo_*_format macros (see141// above) to ensure consistency.142//143// Since we cannot rely on the compiler supporting variable argument144// macros, this macro accepts a fixed number of arguments and passes145// them to the print method. For convenience, we have wrapper macros146// below which take a specific number of arguments and set the rest to147// a default value.148#define ergo_verbose_common(_tag_, _action_, _extra_format_, \149_arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \150do { \151if (G1ErgoVerbose::enabled((_tag_))) { \152gclog_or_tty->print_cr(ergo_format(_extra_format_), \153os::elapsedTime(), \154G1ErgoVerbose::to_string((_tag_)), \155(_action_), \156(_arg0_), (_arg1_), (_arg2_), \157(_arg3_), (_arg4_), (_arg5_)); \158} \159} while (0)160161162#define ergo_verbose6(_tag_, _action_, _extra_format_, \163_arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_) \164ergo_verbose_common(_tag_, _action_, _extra_format_, \165_arg0_, _arg1_, _arg2_, _arg3_, _arg4_, _arg5_)166167#define ergo_verbose5(_tag_, _action_, _extra_format_, \168_arg0_, _arg1_, _arg2_, _arg3_, _arg4_) \169ergo_verbose6(_tag_, _action_, _extra_format_ "%s", \170_arg0_, _arg1_, _arg2_, _arg3_, _arg4_, "")171172#define ergo_verbose4(_tag_, _action_, _extra_format_, \173_arg0_, _arg1_, _arg2_, _arg3_) \174ergo_verbose5(_tag_, _action_, _extra_format_ "%s", \175_arg0_, _arg1_, _arg2_, _arg3_, "")176177#define ergo_verbose3(_tag_, _action_, _extra_format_, \178_arg0_, _arg1_, _arg2_) \179ergo_verbose4(_tag_, _action_, _extra_format_ "%s", \180_arg0_, _arg1_, _arg2_, "")181182#define ergo_verbose2(_tag_, _action_, _extra_format_, \183_arg0_, _arg1_) \184ergo_verbose3(_tag_, _action_, _extra_format_ "%s", \185_arg0_, _arg1_, "")186187#define ergo_verbose1(_tag_, _action_, _extra_format_, \188_arg0_) \189ergo_verbose2(_tag_, _action_, _extra_format_ "%s", \190_arg0_, "")191192193#define ergo_verbose0(_tag_, _action_, _extra_format_) \194ergo_verbose1(_tag_, _action_, _extra_format_ "%s", \195"")196197#define ergo_verbose(_tag_, _action_) \198ergo_verbose0(_tag_, _action_, "")199200201#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1ERGOVERBOSE_HPP202203204