Mercurial > hg > truffle
annotate src/share/vm/utilities/taskqueue.cpp @ 1665:a93a9eda13f7
6962947: shared TaskQueue statistics
Reviewed-by: tonyp, ysr
author | jcoomes |
---|---|
date | Fri, 16 Jul 2010 21:33:21 -0700 |
parents | b2a00dd3117c |
children | 5f429ee79634 |
rev | line source |
---|---|
0 | 1 /* |
1638 | 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1311
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1311
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1311
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_taskqueue.cpp.incl" | |
27 | |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
28 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
29 uint ParallelTaskTerminator::_total_yields = 0; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
30 uint ParallelTaskTerminator::_total_spins = 0; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
31 uint ParallelTaskTerminator::_total_peeks = 0; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
32 #endif |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
33 |
1665 | 34 #if TASKQUEUE_STATS |
35 const char * const TaskQueueStats::_names[last_stat_id] = { | |
36 "qpush", "qpop", "qpop-s", "qattempt", "qsteal", "opush", "omax" | |
37 }; | |
38 | |
39 void TaskQueueStats::print_header(unsigned int line, outputStream* const stream, | |
40 unsigned int width) | |
41 { | |
42 // Use a width w: 1 <= w <= max_width | |
43 const unsigned int max_width = 40; | |
44 const unsigned int w = MAX2(MIN2(width, max_width), 1U); | |
45 | |
46 if (line == 0) { // spaces equal in width to the header | |
47 const unsigned int hdr_width = w * last_stat_id + last_stat_id - 1; | |
48 stream->print("%*s", hdr_width, " "); | |
49 } else if (line == 1) { // labels | |
50 stream->print("%*s", w, _names[0]); | |
51 for (unsigned int i = 1; i < last_stat_id; ++i) { | |
52 stream->print(" %*s", w, _names[i]); | |
53 } | |
54 } else if (line == 2) { // dashed lines | |
55 char dashes[max_width + 1]; | |
56 memset(dashes, '-', w); | |
57 dashes[w] = '\0'; | |
58 stream->print("%s", dashes); | |
59 for (unsigned int i = 1; i < last_stat_id; ++i) { | |
60 stream->print(" %s", dashes); | |
61 } | |
62 } | |
63 } | |
64 | |
65 void TaskQueueStats::print(outputStream* stream, unsigned int width) const | |
66 { | |
67 #define FMT SIZE_FORMAT_W(*) | |
68 stream->print(FMT, width, _stats[0]); | |
69 for (unsigned int i = 1; i < last_stat_id; ++i) { | |
70 stream->print(" " FMT, width, _stats[i]); | |
71 } | |
72 #undef FMT | |
73 } | |
74 #endif // TASKQUEUE_STATS | |
75 | |
0 | 76 int TaskQueueSetSuper::randomParkAndMiller(int *seed0) { |
77 const int a = 16807; | |
78 const int m = 2147483647; | |
79 const int q = 127773; /* m div a */ | |
80 const int r = 2836; /* m mod a */ | |
81 assert(sizeof(int) == 4, "I think this relies on that"); | |
82 int seed = *seed0; | |
83 int hi = seed / q; | |
84 int lo = seed % q; | |
85 int test = a * lo - r * hi; | |
86 if (test > 0) | |
87 seed = test; | |
88 else | |
89 seed = test + m; | |
90 *seed0 = seed; | |
91 return seed; | |
92 } | |
93 | |
94 ParallelTaskTerminator:: | |
95 ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set) : | |
96 _n_threads(n_threads), | |
97 _queue_set(queue_set), | |
98 _offered_termination(0) {} | |
99 | |
100 bool ParallelTaskTerminator::peek_in_queue_set() { | |
101 return _queue_set->peek(); | |
102 } | |
103 | |
104 void ParallelTaskTerminator::yield() { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
579
diff
changeset
|
105 assert(_offered_termination <= _n_threads, "Invariant"); |
0 | 106 os::yield(); |
107 } | |
108 | |
109 void ParallelTaskTerminator::sleep(uint millis) { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
579
diff
changeset
|
110 assert(_offered_termination <= _n_threads, "Invariant"); |
0 | 111 os::sleep(Thread::current(), millis, false); |
112 } | |
113 | |
342 | 114 bool |
115 ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) { | |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
579
diff
changeset
|
116 assert(_offered_termination < _n_threads, "Invariant"); |
0 | 117 Atomic::inc(&_offered_termination); |
118 | |
541
23673011938d
6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents:
470
diff
changeset
|
119 uint yield_count = 0; |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
120 // Number of hard spin loops done since last yield |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
121 uint hard_spin_count = 0; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
122 // Number of iterations in the hard spin loop. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
123 uint hard_spin_limit = WorkStealingHardSpins; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
124 |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
125 // If WorkStealingSpinToYieldRatio is 0, no hard spinning is done. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
126 // If it is greater than 0, then start with a small number |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
127 // of spins and increase number with each turn at spinning until |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
128 // the count of hard spins exceeds WorkStealingSpinToYieldRatio. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
129 // Then do a yield() call and start spinning afresh. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
130 if (WorkStealingSpinToYieldRatio > 0) { |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
131 hard_spin_limit = WorkStealingHardSpins >> WorkStealingSpinToYieldRatio; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
132 hard_spin_limit = MAX2(hard_spin_limit, 1U); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
133 } |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
134 // Remember the initial spin limit. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
135 uint hard_spin_start = hard_spin_limit; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
136 |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
137 // Loop waiting for all threads to offer termination or |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
138 // more work. |
0 | 139 while (true) { |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
579
diff
changeset
|
140 assert(_offered_termination <= _n_threads, "Invariant"); |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
141 // Are all threads offering termination? |
0 | 142 if (_offered_termination == _n_threads) { |
143 return true; | |
144 } else { | |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
145 // Look for more work. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
146 // Periodically sleep() instead of yield() to give threads |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
147 // waiting on the cores the chance to grab this code |
0 | 148 if (yield_count <= WorkStealingYieldsBeforeSleep) { |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
149 // Do a yield or hardspin. For purposes of deciding whether |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
150 // to sleep, count this as a yield. |
0 | 151 yield_count++; |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
152 |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
153 // Periodically call yield() instead spinning |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
154 // After WorkStealingSpinToYieldRatio spins, do a yield() call |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
155 // and reset the counts and starting limit. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
156 if (hard_spin_count > WorkStealingSpinToYieldRatio) { |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
157 yield(); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
158 hard_spin_count = 0; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
159 hard_spin_limit = hard_spin_start; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
160 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
161 _total_yields++; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
162 #endif |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
163 } else { |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
164 // Hard spin this time |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
165 // Increase the hard spinning period but only up to a limit. |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
166 hard_spin_limit = MIN2(2*hard_spin_limit, |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
167 (uint) WorkStealingHardSpins); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
168 for (uint j = 0; j < hard_spin_limit; j++) { |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
169 SpinPause(); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
170 } |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
171 hard_spin_count++; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
172 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
173 _total_spins++; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
174 #endif |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
175 } |
0 | 176 } else { |
177 if (PrintGCDetails && Verbose) { | |
178 gclog_or_tty->print_cr("ParallelTaskTerminator::offer_termination() " | |
179 "thread %d sleeps after %d yields", | |
180 Thread::current(), yield_count); | |
181 } | |
182 yield_count = 0; | |
183 // A sleep will cause this processor to seek work on another processor's | |
184 // runqueue, if it has nothing else to run (as opposed to the yield | |
185 // which may only move the thread to the end of the this processor's | |
186 // runqueue). | |
187 sleep(WorkStealingSleepMillis); | |
188 } | |
189 | |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
190 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
191 _total_peeks++; |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
192 #endif |
342 | 193 if (peek_in_queue_set() || |
194 (terminator != NULL && terminator->should_exit_termination())) { | |
0 | 195 Atomic::dec(&_offered_termination); |
845
df6caf649ff7
6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents:
579
diff
changeset
|
196 assert(_offered_termination < _n_threads, "Invariant"); |
0 | 197 return false; |
198 } | |
199 } | |
200 } | |
201 } | |
202 | |
546
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
203 #ifdef TRACESPINNING |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
204 void ParallelTaskTerminator::print_termination_counts() { |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
205 gclog_or_tty->print_cr("ParallelTaskTerminator Total yields: %lld " |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
206 "Total spins: %lld Total peeks: %lld", |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
207 total_yields(), |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
208 total_spins(), |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
209 total_peeks()); |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
210 } |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
211 #endif |
05c6d52fa7a9
6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents:
541
diff
changeset
|
212 |
0 | 213 void ParallelTaskTerminator::reset_for_reuse() { |
214 if (_offered_termination != 0) { | |
215 assert(_offered_termination == _n_threads, | |
216 "Terminator may still be in use"); | |
217 _offered_termination = 0; | |
218 } | |
219 } | |
220 | |
1311
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
845
diff
changeset
|
221 #ifdef ASSERT |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
845
diff
changeset
|
222 bool ObjArrayTask::is_valid() const { |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
845
diff
changeset
|
223 return _obj != NULL && _obj->is_objArray() && _index > 0 && |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
845
diff
changeset
|
224 _index < objArrayOop(_obj)->length(); |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
845
diff
changeset
|
225 } |
2a1472c30599
4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents:
845
diff
changeset
|
226 #endif // ASSERT |