annotate src/share/vm/utilities/taskqueue.cpp @ 8804:91bf0bdae37b

8008217: CDS: Class data sharing limits the malloc heap on Solaris Summary: In 64bit VM move CDS archive address to 32G on all platforms using new flag SharedBaseAddress. In 32bit VM set CDS archive address to 3Gb on Linux and let other OSs pick the address. Reviewed-by: kvn, dcubed, zgu, hseigel
author coleenp
date Wed, 20 Mar 2013 08:04:54 -0400
parents 203f64878aab
children 78bbf4d43a14
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
7623
203f64878aab 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 7180
diff changeset
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
26 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
27 #include "runtime/os.hpp"
7180
f34d701e952e 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 3960
diff changeset
28 #include "runtime/thread.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
29 #include "utilities/debug.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
30 #include "utilities/stack.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1833
diff changeset
31 #include "utilities/taskqueue.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
33 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
34 uint ParallelTaskTerminator::_total_yields = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
35 uint ParallelTaskTerminator::_total_spins = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
36 uint ParallelTaskTerminator::_total_peeks = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
37 #endif
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
38
1665
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
39 #if TASKQUEUE_STATS
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
40 const char * const TaskQueueStats::_names[last_stat_id] = {
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
41 "qpush", "qpop", "qpop-s", "qattempt", "qsteal", "opush", "omax"
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
42 };
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
43
1709
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
44 TaskQueueStats & TaskQueueStats::operator +=(const TaskQueueStats & addend)
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
45 {
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
46 for (unsigned int i = 0; i < last_stat_id; ++i) {
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
47 _stats[i] += addend._stats[i];
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
48 }
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
49 return *this;
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
50 }
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
51
1665
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
52 void TaskQueueStats::print_header(unsigned int line, outputStream* const stream,
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
53 unsigned int width)
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
54 {
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
55 // Use a width w: 1 <= w <= max_width
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
56 const unsigned int max_width = 40;
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
57 const unsigned int w = MAX2(MIN2(width, max_width), 1U);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
58
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
59 if (line == 0) { // spaces equal in width to the header
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
60 const unsigned int hdr_width = w * last_stat_id + last_stat_id - 1;
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
61 stream->print("%*s", hdr_width, " ");
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
62 } else if (line == 1) { // labels
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
63 stream->print("%*s", w, _names[0]);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
64 for (unsigned int i = 1; i < last_stat_id; ++i) {
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
65 stream->print(" %*s", w, _names[i]);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
66 }
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
67 } else if (line == 2) { // dashed lines
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
68 char dashes[max_width + 1];
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
69 memset(dashes, '-', w);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
70 dashes[w] = '\0';
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
71 stream->print("%s", dashes);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
72 for (unsigned int i = 1; i < last_stat_id; ++i) {
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
73 stream->print(" %s", dashes);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
74 }
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
75 }
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
76 }
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
77
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
78 void TaskQueueStats::print(outputStream* stream, unsigned int width) const
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
79 {
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
80 #define FMT SIZE_FORMAT_W(*)
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
81 stream->print(FMT, width, _stats[0]);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
82 for (unsigned int i = 1; i < last_stat_id; ++i) {
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
83 stream->print(" " FMT, width, _stats[i]);
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
84 }
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
85 #undef FMT
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
86 }
1709
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
87
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
88 #ifdef ASSERT
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
89 // Invariants which should hold after a TaskQueue has been emptied and is
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
90 // quiescent; they do not hold at arbitrary times.
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
91 void TaskQueueStats::verify() const
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
92 {
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
93 assert(get(push) == get(pop) + get(steal),
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
94 err_msg("push=" SIZE_FORMAT " pop=" SIZE_FORMAT " steal=" SIZE_FORMAT,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
95 get(push), get(pop), get(steal)));
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
96 assert(get(pop_slow) <= get(pop),
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
97 err_msg("pop_slow=" SIZE_FORMAT " pop=" SIZE_FORMAT,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
98 get(pop_slow), get(pop)));
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
99 assert(get(steal) <= get(steal_attempt),
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
100 err_msg("steal=" SIZE_FORMAT " steal_attempt=" SIZE_FORMAT,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
101 get(steal), get(steal_attempt)));
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
102 assert(get(overflow) == 0 || get(push) != 0,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
103 err_msg("overflow=" SIZE_FORMAT " push=" SIZE_FORMAT,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
104 get(overflow), get(push)));
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
105 assert(get(overflow_max_len) == 0 || get(overflow) != 0,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
106 err_msg("overflow_max_len=" SIZE_FORMAT " overflow=" SIZE_FORMAT,
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
107 get(overflow_max_len), get(overflow)));
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
108 }
5f429ee79634 6966222: G1: simplify TaskQueue overflow handling
jcoomes
parents: 1665
diff changeset
109 #endif // ASSERT
1665
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
110 #endif // TASKQUEUE_STATS
a93a9eda13f7 6962947: shared TaskQueue statistics
jcoomes
parents: 1638
diff changeset
111
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int TaskQueueSetSuper::randomParkAndMiller(int *seed0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 const int a = 16807;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 const int m = 2147483647;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 const int q = 127773; /* m div a */
a61af66fc99e Initial load
duke
parents:
diff changeset
116 const int r = 2836; /* m mod a */
a61af66fc99e Initial load
duke
parents:
diff changeset
117 assert(sizeof(int) == 4, "I think this relies on that");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 int seed = *seed0;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 int hi = seed / q;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int lo = seed % q;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 int test = a * lo - r * hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (test > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
123 seed = test;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 else
a61af66fc99e Initial load
duke
parents:
diff changeset
125 seed = test + m;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 *seed0 = seed;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return seed;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ParallelTaskTerminator::
a61af66fc99e Initial load
duke
parents:
diff changeset
131 ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set) :
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _n_threads(n_threads),
a61af66fc99e Initial load
duke
parents:
diff changeset
133 _queue_set(queue_set),
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _offered_termination(0) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 bool ParallelTaskTerminator::peek_in_queue_set() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return _queue_set->peek();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void ParallelTaskTerminator::yield() {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
141 assert(_offered_termination <= _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
142 os::yield();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 void ParallelTaskTerminator::sleep(uint millis) {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
146 assert(_offered_termination <= _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
147 os::sleep(Thread::current(), millis, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
150 bool
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
151 ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
1833
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1709
diff changeset
152 assert(_n_threads > 0, "Initialization is incorrect");
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
153 assert(_offered_termination < _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
154 Atomic::inc(&_offered_termination);
a61af66fc99e Initial load
duke
parents:
diff changeset
155
541
23673011938d 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 470
diff changeset
156 uint yield_count = 0;
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
157 // 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
158 uint hard_spin_count = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
159 // Number of iterations in the hard spin loop.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
160 uint hard_spin_limit = WorkStealingHardSpins;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
161
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
162 // 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
163 // 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
164 // 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
165 // the count of hard spins exceeds WorkStealingSpinToYieldRatio.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
166 // 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
167 if (WorkStealingSpinToYieldRatio > 0) {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
168 hard_spin_limit = WorkStealingHardSpins >> WorkStealingSpinToYieldRatio;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
169 hard_spin_limit = MAX2(hard_spin_limit, 1U);
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 // Remember the initial spin limit.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
172 uint hard_spin_start = hard_spin_limit;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
173
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
174 // 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
175 // more work.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
176 while (true) {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
177 assert(_offered_termination <= _n_threads, "Invariant");
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
178 // Are all threads offering termination?
0
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (_offered_termination == _n_threads) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 } else {
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
182 // Look for more work.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
183 // Periodically sleep() instead of yield() to give threads
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
184 // waiting on the cores the chance to grab this code
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (yield_count <= WorkStealingYieldsBeforeSleep) {
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
186 // 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
187 // to sleep, count this as a yield.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
188 yield_count++;
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
189
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
190 // Periodically call yield() instead spinning
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
191 // After WorkStealingSpinToYieldRatio spins, do a yield() call
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
192 // and reset the counts and starting limit.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
193 if (hard_spin_count > WorkStealingSpinToYieldRatio) {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
194 yield();
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
195 hard_spin_count = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
196 hard_spin_limit = hard_spin_start;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
197 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
198 _total_yields++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
199 #endif
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
200 } else {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
201 // Hard spin this time
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
202 // 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
203 hard_spin_limit = MIN2(2*hard_spin_limit,
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
204 (uint) WorkStealingHardSpins);
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
205 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
206 SpinPause();
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
207 }
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
208 hard_spin_count++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
209 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
210 _total_spins++;
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
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 if (PrintGCDetails && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 gclog_or_tty->print_cr("ParallelTaskTerminator::offer_termination() "
a61af66fc99e Initial load
duke
parents:
diff changeset
216 "thread %d sleeps after %d yields",
a61af66fc99e Initial load
duke
parents:
diff changeset
217 Thread::current(), yield_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 yield_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // A sleep will cause this processor to seek work on another processor's
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // runqueue, if it has nothing else to run (as opposed to the yield
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // which may only move the thread to the end of the this processor's
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // runqueue).
a61af66fc99e Initial load
duke
parents:
diff changeset
224 sleep(WorkStealingSleepMillis);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
227 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
228 _total_peeks++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
229 #endif
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
230 if (peek_in_queue_set() ||
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
231 (terminator != NULL && terminator->should_exit_termination())) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
232 Atomic::dec(&_offered_termination);
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
233 assert(_offered_termination < _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
234 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
240 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
241 void ParallelTaskTerminator::print_termination_counts() {
7623
203f64878aab 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 7180
diff changeset
242 gclog_or_tty->print_cr("ParallelTaskTerminator Total yields: " UINT32_FORMAT
203f64878aab 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 7180
diff changeset
243 " Total spins: " UINT32_FORMAT " Total peeks: " UINT32_FORMAT,
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
244 total_yields(),
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
245 total_spins(),
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
246 total_peeks());
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
247 }
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
248 #endif
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
249
0
a61af66fc99e Initial load
duke
parents:
diff changeset
250 void ParallelTaskTerminator::reset_for_reuse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 if (_offered_termination != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 assert(_offered_termination == _n_threads,
a61af66fc99e Initial load
duke
parents:
diff changeset
253 "Terminator may still be in use");
a61af66fc99e Initial load
duke
parents:
diff changeset
254 _offered_termination = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
258 #ifdef ASSERT
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
259 bool ObjArrayTask::is_valid() const {
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
260 return _obj != NULL && _obj->is_objArray() && _index > 0 &&
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
261 _index < objArrayOop(_obj)->length();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
262 }
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
263 #endif // ASSERT
1833
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1709
diff changeset
264
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1709
diff changeset
265 void ParallelTaskTerminator::reset_for_reuse(int n_threads) {
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1709
diff changeset
266 reset_for_reuse();
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1709
diff changeset
267 _n_threads = n_threads;
8b10f48633dc 6984287: Regularize how GC parallel workers are specified.
jmasa
parents: 1709
diff changeset
268 }