src/share/vm/utilities/taskqueue.cpp

changeset 1993
b2a00dd3117c
parent 1907
c18cbe5936b8
child 2020
a93a9eda13f7
equal deleted inserted replaced
1983:a00567c82f02 1993:b2a00dd3117c
1 /* 1 /*
2 * Copyright (c) 2001, 2009, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
180 bool ObjArrayTask::is_valid() const { 180 bool ObjArrayTask::is_valid() const {
181 return _obj != NULL && _obj->is_objArray() && _index > 0 && 181 return _obj != NULL && _obj->is_objArray() && _index > 0 &&
182 _index < objArrayOop(_obj)->length(); 182 _index < objArrayOop(_obj)->length();
183 } 183 }
184 #endif // ASSERT 184 #endif // ASSERT
185
186 bool RegionTaskQueueWithOverflow::is_empty() {
187 return (_region_queue.size() == 0) &&
188 (_overflow_stack->length() == 0);
189 }
190
191 bool RegionTaskQueueWithOverflow::stealable_is_empty() {
192 return _region_queue.size() == 0;
193 }
194
195 bool RegionTaskQueueWithOverflow::overflow_is_empty() {
196 return _overflow_stack->length() == 0;
197 }
198
199 void RegionTaskQueueWithOverflow::initialize() {
200 _region_queue.initialize();
201 assert(_overflow_stack == 0, "Creating memory leak");
202 _overflow_stack =
203 new (ResourceObj::C_HEAP) GrowableArray<RegionTask>(10, true);
204 }
205
206 void RegionTaskQueueWithOverflow::save(RegionTask t) {
207 if (TraceRegionTasksQueuing && Verbose) {
208 gclog_or_tty->print_cr("CTQ: save " PTR_FORMAT, t);
209 }
210 if(!_region_queue.push(t)) {
211 _overflow_stack->push(t);
212 }
213 }
214
215 // Note that using this method will retrieve all regions
216 // that have been saved but that it will always check
217 // the overflow stack. It may be more efficient to
218 // check the stealable queue and the overflow stack
219 // separately.
220 bool RegionTaskQueueWithOverflow::retrieve(RegionTask& region_task) {
221 bool result = retrieve_from_overflow(region_task);
222 if (!result) {
223 result = retrieve_from_stealable_queue(region_task);
224 }
225 if (TraceRegionTasksQueuing && Verbose && result) {
226 gclog_or_tty->print_cr(" CTQ: retrieve " PTR_FORMAT, result);
227 }
228 return result;
229 }
230
231 bool RegionTaskQueueWithOverflow::retrieve_from_stealable_queue(
232 RegionTask& region_task) {
233 bool result = _region_queue.pop_local(region_task);
234 if (TraceRegionTasksQueuing && Verbose) {
235 gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task);
236 }
237 return result;
238 }
239
240 bool
241 RegionTaskQueueWithOverflow::retrieve_from_overflow(RegionTask& region_task) {
242 bool result;
243 if (!_overflow_stack->is_empty()) {
244 region_task = _overflow_stack->pop();
245 result = true;
246 } else {
247 region_task = (RegionTask) NULL;
248 result = false;
249 }
250 if (TraceRegionTasksQueuing && Verbose) {
251 gclog_or_tty->print_cr("CTQ: retrieve_stealable " PTR_FORMAT, region_task);
252 }
253 return result;
254 }

mercurial