Mercurial > hg > graal-compiler
annotate src/share/vm/utilities/taskqueue.cpp @ 521:4db4e58c16bd
6791815: Fix for 6471657 can cause deadlock on non-Solaris platforms when initializing direct buffer support
Summary: Place the state transition inside the loop so that the VMThread could proceed for safepoint
Reviewed-by: dholmes, never, acorn
author | xlu |
---|---|
date | Tue, 13 Jan 2009 12:08:43 -0800 |
parents | 81cd571500b0 |
children | ad8c8ca4ab0f |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 2001-2006 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 # include "incls/_precompiled.incl" | |
26 # include "incls/_taskqueue.cpp.incl" | |
27 | |
28 bool TaskQueueSuper::peek() { | |
29 return _bottom != _age.top(); | |
30 } | |
31 | |
32 int TaskQueueSetSuper::randomParkAndMiller(int *seed0) { | |
33 const int a = 16807; | |
34 const int m = 2147483647; | |
35 const int q = 127773; /* m div a */ | |
36 const int r = 2836; /* m mod a */ | |
37 assert(sizeof(int) == 4, "I think this relies on that"); | |
38 int seed = *seed0; | |
39 int hi = seed / q; | |
40 int lo = seed % q; | |
41 int test = a * lo - r * hi; | |
42 if (test > 0) | |
43 seed = test; | |
44 else | |
45 seed = test + m; | |
46 *seed0 = seed; | |
47 return seed; | |
48 } | |
49 | |
50 ParallelTaskTerminator:: | |
51 ParallelTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set) : | |
52 _n_threads(n_threads), | |
53 _queue_set(queue_set), | |
54 _offered_termination(0) {} | |
55 | |
56 bool ParallelTaskTerminator::peek_in_queue_set() { | |
57 return _queue_set->peek(); | |
58 } | |
59 | |
60 void ParallelTaskTerminator::yield() { | |
61 os::yield(); | |
62 } | |
63 | |
64 void ParallelTaskTerminator::sleep(uint millis) { | |
65 os::sleep(Thread::current(), millis, false); | |
66 } | |
67 | |
342 | 68 bool |
69 ParallelTaskTerminator::offer_termination(TerminatorTerminator* terminator) { | |
0 | 70 Atomic::inc(&_offered_termination); |
71 | |
72 juint yield_count = 0; | |
73 while (true) { | |
74 if (_offered_termination == _n_threads) { | |
75 //inner_termination_loop(); | |
76 return true; | |
77 } else { | |
78 if (yield_count <= WorkStealingYieldsBeforeSleep) { | |
79 yield_count++; | |
80 yield(); | |
81 } else { | |
82 if (PrintGCDetails && Verbose) { | |
83 gclog_or_tty->print_cr("ParallelTaskTerminator::offer_termination() " | |
84 "thread %d sleeps after %d yields", | |
85 Thread::current(), yield_count); | |
86 } | |
87 yield_count = 0; | |
88 // A sleep will cause this processor to seek work on another processor's | |
89 // runqueue, if it has nothing else to run (as opposed to the yield | |
90 // which may only move the thread to the end of the this processor's | |
91 // runqueue). | |
92 sleep(WorkStealingSleepMillis); | |
93 } | |
94 | |
342 | 95 if (peek_in_queue_set() || |
96 (terminator != NULL && terminator->should_exit_termination())) { | |
0 | 97 Atomic::dec(&_offered_termination); |
98 return false; | |
99 } | |
100 } | |
101 } | |
102 } | |
103 | |
104 void ParallelTaskTerminator::reset_for_reuse() { | |
105 if (_offered_termination != 0) { | |
106 assert(_offered_termination == _n_threads, | |
107 "Terminator may still be in use"); | |
108 _offered_termination = 0; | |
109 } | |
110 } | |
111 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
112 bool RegionTaskQueueWithOverflow::is_empty() { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
113 return (_region_queue.size() == 0) && |
0 | 114 (_overflow_stack->length() == 0); |
115 } | |
116 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
117 bool RegionTaskQueueWithOverflow::stealable_is_empty() { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
118 return _region_queue.size() == 0; |
0 | 119 } |
120 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
121 bool RegionTaskQueueWithOverflow::overflow_is_empty() { |
0 | 122 return _overflow_stack->length() == 0; |
123 } | |
124 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
125 void RegionTaskQueueWithOverflow::initialize() { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
126 _region_queue.initialize(); |
0 | 127 assert(_overflow_stack == 0, "Creating memory leak"); |
128 _overflow_stack = | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
129 new (ResourceObj::C_HEAP) GrowableArray<RegionTask>(10, true); |
0 | 130 } |
131 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
132 void RegionTaskQueueWithOverflow::save(RegionTask t) { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
133 if (TraceRegionTasksQueuing && Verbose) { |
0 | 134 gclog_or_tty->print_cr("CTQ: save " PTR_FORMAT, t); |
135 } | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
136 if(!_region_queue.push(t)) { |
0 | 137 _overflow_stack->push(t); |
138 } | |
139 } | |
140 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
141 // Note that using this method will retrieve all regions |
0 | 142 // that have been saved but that it will always check |
143 // the overflow stack. It may be more efficient to | |
144 // check the stealable queue and the overflow stack | |
145 // separately. | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
146 bool RegionTaskQueueWithOverflow::retrieve(RegionTask& region_task) { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
147 bool result = retrieve_from_overflow(region_task); |
0 | 148 if (!result) { |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
149 result = retrieve_from_stealable_queue(region_task); |
0 | 150 } |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
151 if (TraceRegionTasksQueuing && Verbose && result) { |
0 | 152 gclog_or_tty->print_cr(" CTQ: retrieve " PTR_FORMAT, result); |
153 } | |
154 return result; | |
155 } | |
156 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
157 bool RegionTaskQueueWithOverflow::retrieve_from_stealable_queue( |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
158 RegionTask& region_task) { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
159 bool result = _region_queue.pop_local(region_task); |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
160 if (TraceRegionTasksQueuing && Verbose) { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
161 gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task); |
0 | 162 } |
163 return result; | |
164 } | |
165 | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
166 bool |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
167 RegionTaskQueueWithOverflow::retrieve_from_overflow(RegionTask& region_task) { |
0 | 168 bool result; |
169 if (!_overflow_stack->is_empty()) { | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
170 region_task = _overflow_stack->pop(); |
0 | 171 result = true; |
172 } else { | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
173 region_task = (RegionTask) NULL; |
0 | 174 result = false; |
175 } | |
375
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
176 if (TraceRegionTasksQueuing && Verbose) { |
81cd571500b0
6725697: par compact - rename class ChunkData to RegionData
jcoomes
parents:
342
diff
changeset
|
177 gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task); |
0 | 178 } |
179 return result; | |
180 } |