annotate src/share/vm/utilities/taskqueue.cpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents 2a1472c30599
children b2a00dd3117c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1311
diff changeset
2 * Copyright (c) 2001, 2009, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_taskqueue.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
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
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34 int TaskQueueSetSuper::randomParkAndMiller(int *seed0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 const int a = 16807;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 const int m = 2147483647;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 const int q = 127773; /* m div a */
a61af66fc99e Initial load
duke
parents:
diff changeset
38 const int r = 2836; /* m mod a */
a61af66fc99e Initial load
duke
parents:
diff changeset
39 assert(sizeof(int) == 4, "I think this relies on that");
a61af66fc99e Initial load
duke
parents:
diff changeset
40 int seed = *seed0;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 int hi = seed / q;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 int lo = seed % q;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 int test = a * lo - r * hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 if (test > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
45 seed = test;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 else
a61af66fc99e Initial load
duke
parents:
diff changeset
47 seed = test + m;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 *seed0 = seed;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return seed;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 ParallelTaskTerminator::
a61af66fc99e Initial load
duke
parents:
diff changeset
53 ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set) :
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _n_threads(n_threads),
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _queue_set(queue_set),
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _offered_termination(0) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 bool ParallelTaskTerminator::peek_in_queue_set() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return _queue_set->peek();
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 void ParallelTaskTerminator::yield() {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
63 assert(_offered_termination <= _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
64 os::yield();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 void ParallelTaskTerminator::sleep(uint millis) {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
68 assert(_offered_termination <= _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
69 os::sleep(Thread::current(), millis, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
72 bool
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
73 ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
74 assert(_offered_termination < _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Atomic::inc(&_offered_termination);
a61af66fc99e Initial load
duke
parents:
diff changeset
76
541
23673011938d 6787254: Work queue capacity can be increased substantially on some platforms
ysr
parents: 470
diff changeset
77 uint yield_count = 0;
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
78 // 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
79 uint hard_spin_count = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
80 // Number of iterations in the hard spin loop.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
81 uint hard_spin_limit = WorkStealingHardSpins;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
82
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
83 // 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
84 // 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
85 // 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
86 // the count of hard spins exceeds WorkStealingSpinToYieldRatio.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
87 // 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
88 if (WorkStealingSpinToYieldRatio > 0) {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
89 hard_spin_limit = WorkStealingHardSpins >> WorkStealingSpinToYieldRatio;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
90 hard_spin_limit = MAX2(hard_spin_limit, 1U);
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
91 }
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
92 // Remember the initial spin limit.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
93 uint hard_spin_start = hard_spin_limit;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
94
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
95 // 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
96 // more work.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
97 while (true) {
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
98 assert(_offered_termination <= _n_threads, "Invariant");
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
99 // Are all threads offering termination?
0
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (_offered_termination == _n_threads) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 } else {
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
103 // Look for more work.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
104 // Periodically sleep() instead of yield() to give threads
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
105 // waiting on the cores the chance to grab this code
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (yield_count <= WorkStealingYieldsBeforeSleep) {
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
107 // 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
108 // to sleep, count this as a yield.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
109 yield_count++;
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
110
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
111 // Periodically call yield() instead spinning
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
112 // After WorkStealingSpinToYieldRatio spins, do a yield() call
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
113 // and reset the counts and starting limit.
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
114 if (hard_spin_count > WorkStealingSpinToYieldRatio) {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
115 yield();
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
116 hard_spin_count = 0;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
117 hard_spin_limit = hard_spin_start;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
118 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
119 _total_yields++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
120 #endif
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
121 } else {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
122 // Hard spin this time
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
123 // 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
124 hard_spin_limit = MIN2(2*hard_spin_limit,
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
125 (uint) WorkStealingHardSpins);
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
126 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
127 SpinPause();
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
128 }
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
129 hard_spin_count++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
130 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
131 _total_spins++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
132 #endif
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
133 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if (PrintGCDetails && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 gclog_or_tty->print_cr("ParallelTaskTerminator::offer_termination() "
a61af66fc99e Initial load
duke
parents:
diff changeset
137 "thread %d sleeps after %d yields",
a61af66fc99e Initial load
duke
parents:
diff changeset
138 Thread::current(), yield_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 yield_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // A sleep will cause this processor to seek work on another processor's
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // runqueue, if it has nothing else to run (as opposed to the yield
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // which may only move the thread to the end of the this processor's
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // runqueue).
a61af66fc99e Initial load
duke
parents:
diff changeset
145 sleep(WorkStealingSleepMillis);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
148 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
149 _total_peeks++;
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
150 #endif
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
151 if (peek_in_queue_set() ||
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 0
diff changeset
152 (terminator != NULL && terminator->should_exit_termination())) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
153 Atomic::dec(&_offered_termination);
845
df6caf649ff7 6700789: G1: Enable use of compressed oops with G1 heaps
ysr
parents: 579
diff changeset
154 assert(_offered_termination < _n_threads, "Invariant");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
546
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
161 #ifdef TRACESPINNING
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
162 void ParallelTaskTerminator::print_termination_counts() {
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
163 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
164 "Total spins: %lld Total peeks: %lld",
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
165 total_yields(),
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
166 total_spins(),
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
167 total_peeks());
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
168 }
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
169 #endif
05c6d52fa7a9 6690928: Use spinning in combination with yields for workstealing termination.
jmasa
parents: 541
diff changeset
170
0
a61af66fc99e Initial load
duke
parents:
diff changeset
171 void ParallelTaskTerminator::reset_for_reuse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (_offered_termination != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 assert(_offered_termination == _n_threads,
a61af66fc99e Initial load
duke
parents:
diff changeset
174 "Terminator may still be in use");
a61af66fc99e Initial load
duke
parents:
diff changeset
175 _offered_termination = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
1311
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
179 #ifdef ASSERT
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
180 bool ObjArrayTask::is_valid() const {
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
181 return _obj != NULL && _obj->is_objArray() && _index > 0 &&
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
182 _index < objArrayOop(_obj)->length();
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
183 }
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
184 #endif // ASSERT
2a1472c30599 4396719: Mark Sweep stack overflow on deeply nested Object arrays
jcoomes
parents: 845
diff changeset
185
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
186 bool RegionTaskQueueWithOverflow::is_empty() {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
187 return (_region_queue.size() == 0) &&
0
a61af66fc99e Initial load
duke
parents:
diff changeset
188 (_overflow_stack->length() == 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
191 bool RegionTaskQueueWithOverflow::stealable_is_empty() {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
192 return _region_queue.size() == 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
195 bool RegionTaskQueueWithOverflow::overflow_is_empty() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return _overflow_stack->length() == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
199 void RegionTaskQueueWithOverflow::initialize() {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
200 _region_queue.initialize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 assert(_overflow_stack == 0, "Creating memory leak");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 _overflow_stack =
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
203 new (ResourceObj::C_HEAP) GrowableArray<RegionTask>(10, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
206 void RegionTaskQueueWithOverflow::save(RegionTask t) {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
207 if (TraceRegionTasksQueuing && Verbose) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
208 gclog_or_tty->print_cr("CTQ: save " PTR_FORMAT, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
210 if(!_region_queue.push(t)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
211 _overflow_stack->push(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
215 // Note that using this method will retrieve all regions
0
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // that have been saved but that it will always check
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // the overflow stack. It may be more efficient to
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // check the stealable queue and the overflow stack
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // separately.
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
220 bool RegionTaskQueueWithOverflow::retrieve(RegionTask& region_task) {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
221 bool result = retrieve_from_overflow(region_task);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (!result) {
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
223 result = retrieve_from_stealable_queue(region_task);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
225 if (TraceRegionTasksQueuing && Verbose && result) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
226 gclog_or_tty->print_cr(" CTQ: retrieve " PTR_FORMAT, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
231 bool RegionTaskQueueWithOverflow::retrieve_from_stealable_queue(
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
232 RegionTask& region_task) {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
233 bool result = _region_queue.pop_local(region_task);
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
234 if (TraceRegionTasksQueuing && Verbose) {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
235 gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
240 bool
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
241 RegionTaskQueueWithOverflow::retrieve_from_overflow(RegionTask& region_task) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
242 bool result;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (!_overflow_stack->is_empty()) {
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
244 region_task = _overflow_stack->pop();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 result = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 } else {
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
247 region_task = (RegionTask) NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
248 result = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
375
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
250 if (TraceRegionTasksQueuing && Verbose) {
81cd571500b0 6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents: 342
diff changeset
251 gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }