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

changeset 1372
ead53f6b615d
parent 777
37f87013dfd8
equal deleted inserted replaced
1370:05f89f00a864 1372:ead53f6b615d
1 /*
2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 // COTracker keeps track of the concurrent overhead of a GC thread.
26
27 // A thread that needs to be tracked must, itself, start up its
28 // tracker with the start() method and then call the update() method
29 // at regular intervals. What the tracker does is to calculate the
30 // concurrent overhead of a process at a given update period. The
31 // tracker starts and when is detects that it has exceeded the given
32 // period, it calculates the duration of the period in wall-clock time
33 // and the duration of the period in vtime (i.e. how much time the
34 // concurrent processes really took up during this period). The ratio
35 // of the latter over the former is the concurrent overhead of that
36 // process for that period over a single CPU. This overhead is stored
37 // on the tracker, "timestamped" with the wall-clock time of the end
38 // of the period. When the concurrent overhead of this process needs
39 // to be queried, this last "reading" provides a good approximation
40 // (we assume that the concurrent overhead of a particular thread
41 // stays largely constant over time). The timestamp is necessary to
42 // detect when the process has stopped working and the recorded
43 // reading hasn't been updated for some time.
44
45 // Each concurrent GC thread is considered to be part of a "group"
46 // (i.e. any available concurrent marking threads are part of the
47 // "concurrent marking thread group"). A COTracker is associated with
48 // a single group at construction-time. It's up to each collector to
49 // decide how groups will be mapped to such an id (ids should start
50 // from 0 and be consecutive; there's a hardcoded max group num
51 // defined on the GCOverheadTracker class). The notion of a group has
52 // been introduced to be able to identify how much overhead was
53 // imposed by each group, instead of getting a single value that
54 // covers all concurrent overhead.
55
56 class COTracker {
57 private:
58 // It indicates whether this tracker is enabled or not. When the
59 // tracker is disabled, then it returns 0.0 as the latest concurrent
60 // overhead and several methods (reset, start, and update) are not
61 // supposed to be called on it. This enabling / disabling facility
62 // is really provided to make a bit more explicit in the code when a
63 // particulary tracker of a processes that doesn't run all the time
64 // (e.g. concurrent marking) is supposed to be used and not it's not.
65 bool _enabled;
66
67 // The ID of the group associated with this tracker.
68 int _group;
69
70 // The update period of the tracker. A new value for the concurrent
71 // overhead of the associated process will be made at intervals no
72 // smaller than this.
73 double _update_period_sec;
74
75 // The start times (both wall-block time and vtime) of the current
76 // interval.
77 double _period_start_time_sec;
78 double _period_start_vtime_sec;
79
80 // Number seq of the concurrent overhead readings within a period
81 NumberSeq _conc_overhead_seq;
82
83 // The latest reading of the concurrent overhead (over a single CPU)
84 // imposed by the associated concurrent thread, made available at
85 // the indicated wall-clock time.
86 double _conc_overhead;
87 double _time_stamp_sec;
88
89 // The number of CPUs that the host machine has (for convenience
90 // really, as we'd have to keep translating it into a double)
91 static double _cpu_number;
92
93 // Fields that keep a list of all trackers created. This is useful,
94 // since it allows us to sum up the concurrent overhead without
95 // having to write code for a specific collector to broadcast a
96 // request to all its concurrent processes.
97 COTracker* _next;
98 static COTracker* _head;
99
100 // It indicates that a new period is starting by updating the
101 // _period_start_time_sec and _period_start_vtime_sec fields.
102 void resetPeriod(double now_sec, double vnow_sec);
103 // It updates the latest concurrent overhead reading, taken at a
104 // given wall-clock time.
105 void setConcOverhead(double time_stamp_sec, double conc_overhead);
106
107 // It determines whether the time stamp of the latest concurrent
108 // overhead reading is out of date or not.
109 bool outOfDate(double now_sec) {
110 // The latest reading is considered out of date, if it was taken
111 // 1.2x the update period.
112 return (now_sec - _time_stamp_sec) > 1.2 * _update_period_sec;
113 }
114
115 public:
116 // The constructor which associates the tracker with a group ID.
117 COTracker(int group);
118
119 // Methods to enable / disable the tracker and query whether it is enabled.
120 void enable() { _enabled = true; }
121 void disable() { _enabled = false; }
122 bool enabled() { return _enabled; }
123
124 // It resets the tracker and sets concurrent overhead reading to be
125 // the given parameter and the associated time stamp to be now.
126 void reset(double starting_conc_overhead = 0.0);
127 // The tracker starts tracking. IT should only be called from the
128 // concurrent thread that is tracked by this tracker.
129 void start();
130 // It updates the tracker and, if the current period is longer than
131 // the update period, the concurrent overhead reading will be
132 // updated. force_end being true indicates that it's the last call
133 // to update() by this process before the tracker is disabled (the
134 // tracker can be re-enabled later if necessary). It should only be
135 // called from the concurrent thread that is tracked by this tracker
136 // and while the thread has joined the STS.
137 void update(bool force_end = false);
138 // It adjusts the contents of the tracker to take into account a STW
139 // pause.
140 void updateForSTW(double start_sec, double end_sec);
141
142 // It returns the last concurrent overhead reading over a single
143 // CPU. If the reading is out of date, or the tracker is disabled,
144 // it returns 0.0.
145 double concCPUOverhead(double now_sec) {
146 if (!_enabled || outOfDate(now_sec))
147 return 0.0;
148 else
149 return _conc_overhead;
150 }
151
152 // It returns the last concurrent overhead reading over all CPUs
153 // that the host machine has. If the reading is out of date, or the
154 // tracker is disabled, it returns 0.0.
155 double concOverhead(double now_sec) {
156 return concCPUOverhead(now_sec) / _cpu_number;
157 }
158
159 double predConcOverhead();
160
161 void resetPred();
162
163 // statics
164
165 // It notifies all trackers about a STW pause.
166 static void updateAllForSTW(double start_sec, double end_sec);
167
168 // It returns the sum of the concurrent overhead readings of all
169 // available (and enabled) trackers for the given time stamp. The
170 // overhead is over all the CPUs of the host machine.
171
172 static double totalConcOverhead(double now_sec);
173 // Like the previous method, but it also sums up the overheads per
174 // group number. The length of the co_per_group array must be at
175 // least as large group_num
176 static double totalConcOverhead(double now_sec,
177 size_t group_num,
178 double* co_per_group);
179
180 static double totalPredConcOverhead();
181 };

mercurial