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

changeset 777
37f87013dfd8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/shared/coTracker.hpp	Thu Jun 05 15:57:56 2008 -0700
     1.3 @@ -0,0 +1,181 @@
     1.4 +/*
     1.5 + * Copyright 2001-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// COTracker keeps track of the concurrent overhead of a GC thread.
    1.29 +
    1.30 +// A thread that needs to be tracked must, itself, start up its
    1.31 +// tracker with the start() method and then call the update() method
    1.32 +// at regular intervals. What the tracker does is to calculate the
    1.33 +// concurrent overhead of a process at a given update period. The
    1.34 +// tracker starts and when is detects that it has exceeded the given
    1.35 +// period, it calculates the duration of the period in wall-clock time
    1.36 +// and the duration of the period in vtime (i.e. how much time the
    1.37 +// concurrent processes really took up during this period). The ratio
    1.38 +// of the latter over the former is the concurrent overhead of that
    1.39 +// process for that period over a single CPU. This overhead is stored
    1.40 +// on the tracker, "timestamped" with the wall-clock time of the end
    1.41 +// of the period. When the concurrent overhead of this process needs
    1.42 +// to be queried, this last "reading" provides a good approximation
    1.43 +// (we assume that the concurrent overhead of a particular thread
    1.44 +// stays largely constant over time). The timestamp is necessary to
    1.45 +// detect when the process has stopped working and the recorded
    1.46 +// reading hasn't been updated for some time.
    1.47 +
    1.48 +// Each concurrent GC thread is considered to be part of a "group"
    1.49 +// (i.e. any available concurrent marking threads are part of the
    1.50 +// "concurrent marking thread group"). A COTracker is associated with
    1.51 +// a single group at construction-time. It's up to each collector to
    1.52 +// decide how groups will be mapped to such an id (ids should start
    1.53 +// from 0 and be consecutive; there's a hardcoded max group num
    1.54 +// defined on the GCOverheadTracker class). The notion of a group has
    1.55 +// been introduced to be able to identify how much overhead was
    1.56 +// imposed by each group, instead of getting a single value that
    1.57 +// covers all concurrent overhead.
    1.58 +
    1.59 +class COTracker {
    1.60 +private:
    1.61 +  // It indicates whether this tracker is enabled or not. When the
    1.62 +  // tracker is disabled, then it returns 0.0 as the latest concurrent
    1.63 +  // overhead and several methods (reset, start, and update) are not
    1.64 +  // supposed to be called on it. This enabling / disabling facility
    1.65 +  // is really provided to make a bit more explicit in the code when a
    1.66 +  // particulary tracker of a processes that doesn't run all the time
    1.67 +  // (e.g. concurrent marking) is supposed to be used and not it's not.
    1.68 +  bool               _enabled;
    1.69 +
    1.70 +  // The ID of the group associated with this tracker.
    1.71 +  int                _group;
    1.72 +
    1.73 +  // The update period of the tracker. A new value for the concurrent
    1.74 +  // overhead of the associated process will be made at intervals no
    1.75 +  // smaller than this.
    1.76 +  double             _update_period_sec;
    1.77 +
    1.78 +  // The start times (both wall-block time and vtime) of the current
    1.79 +  // interval.
    1.80 +  double             _period_start_time_sec;
    1.81 +  double             _period_start_vtime_sec;
    1.82 +
    1.83 +  // Number seq of the concurrent overhead readings within a period
    1.84 +  NumberSeq          _conc_overhead_seq;
    1.85 +
    1.86 +  // The latest reading of the concurrent overhead (over a single CPU)
    1.87 +  // imposed by the associated concurrent thread, made available at
    1.88 +  // the indicated wall-clock time.
    1.89 +  double             _conc_overhead;
    1.90 +  double             _time_stamp_sec;
    1.91 +
    1.92 +  // The number of CPUs that the host machine has (for convenience
    1.93 +  // really, as we'd have to keep translating it into a double)
    1.94 +  static double      _cpu_number;
    1.95 +
    1.96 +  // Fields that keep a list of all trackers created. This is useful,
    1.97 +  // since it allows us to sum up the concurrent overhead without
    1.98 +  // having to write code for a specific collector to broadcast a
    1.99 +  // request to all its concurrent processes.
   1.100 +  COTracker*         _next;
   1.101 +  static COTracker*  _head;
   1.102 +
   1.103 +  // It indicates that a new period is starting by updating the
   1.104 +  // _period_start_time_sec and _period_start_vtime_sec fields.
   1.105 +  void resetPeriod(double now_sec, double vnow_sec);
   1.106 +  // It updates the latest concurrent overhead reading, taken at a
   1.107 +  // given wall-clock time.
   1.108 +  void setConcOverhead(double time_stamp_sec, double conc_overhead);
   1.109 +
   1.110 +  // It determines whether the time stamp of the latest concurrent
   1.111 +  // overhead reading is out of date or not.
   1.112 +  bool outOfDate(double now_sec) {
   1.113 +    // The latest reading is considered out of date, if it was taken
   1.114 +    // 1.2x the update period.
   1.115 +    return (now_sec - _time_stamp_sec) > 1.2 * _update_period_sec;
   1.116 +  }
   1.117 +
   1.118 +public:
   1.119 +  // The constructor which associates the tracker with a group ID.
   1.120 +  COTracker(int group);
   1.121 +
   1.122 +  // Methods to enable / disable the tracker and query whether it is enabled.
   1.123 +  void enable()  { _enabled = true;  }
   1.124 +  void disable() { _enabled = false; }
   1.125 +  bool enabled() { return _enabled;  }
   1.126 +
   1.127 +  // It resets the tracker and sets concurrent overhead reading to be
   1.128 +  // the given parameter and the associated time stamp to be now.
   1.129 +  void reset(double starting_conc_overhead = 0.0);
   1.130 +  // The tracker starts tracking. IT should only be called from the
   1.131 +  // concurrent thread that is tracked by this tracker.
   1.132 +  void start();
   1.133 +  // It updates the tracker and, if the current period is longer than
   1.134 +  // the update period, the concurrent overhead reading will be
   1.135 +  // updated. force_end being true indicates that it's the last call
   1.136 +  // to update() by this process before the tracker is disabled (the
   1.137 +  // tracker can be re-enabled later if necessary).  It should only be
   1.138 +  // called from the concurrent thread that is tracked by this tracker
   1.139 +  // and while the thread has joined the STS.
   1.140 +  void update(bool force_end = false);
   1.141 +  // It adjusts the contents of the tracker to take into account a STW
   1.142 +  // pause.
   1.143 +  void updateForSTW(double start_sec, double end_sec);
   1.144 +
   1.145 +  // It returns the last concurrent overhead reading over a single
   1.146 +  // CPU. If the reading is out of date, or the tracker is disabled,
   1.147 +  // it returns 0.0.
   1.148 +  double concCPUOverhead(double now_sec) {
   1.149 +    if (!_enabled || outOfDate(now_sec))
   1.150 +      return 0.0;
   1.151 +    else
   1.152 +      return _conc_overhead;
   1.153 +  }
   1.154 +
   1.155 +  // It returns the last concurrent overhead reading over all CPUs
   1.156 +  // that the host machine has. If the reading is out of date, or the
   1.157 +  // tracker is disabled, it returns 0.0.
   1.158 +  double concOverhead(double now_sec) {
   1.159 +    return concCPUOverhead(now_sec) / _cpu_number;
   1.160 +  }
   1.161 +
   1.162 +  double predConcOverhead();
   1.163 +
   1.164 +  void resetPred();
   1.165 +
   1.166 +  // statics
   1.167 +
   1.168 +  // It notifies all trackers about a STW pause.
   1.169 +  static void updateAllForSTW(double start_sec, double end_sec);
   1.170 +
   1.171 +  // It returns the sum of the concurrent overhead readings of all
   1.172 +  // available (and enabled) trackers for the given time stamp. The
   1.173 +  // overhead is over all the CPUs of the host machine.
   1.174 +
   1.175 +  static double totalConcOverhead(double now_sec);
   1.176 +  // Like the previous method, but it also sums up the overheads per
   1.177 +  // group number. The length of the co_per_group array must be at
   1.178 +  // least as large group_num
   1.179 +  static double totalConcOverhead(double now_sec,
   1.180 +                                  size_t group_num,
   1.181 +                                  double* co_per_group);
   1.182 +
   1.183 +  static double totalPredConcOverhead();
   1.184 +};

mercurial