Skip to content

Commit 6ce0799

Browse files
albertnetymkThomas Schatzl
authored andcommitted
8259851: Use boolean type for tasks in SubTasksDone
Reviewed-by: kbarrett, tschatzl
1 parent 4bcffeb commit 6ce0799

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/hotspot/share/gc/shared/workgroup.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void WorkGangBarrierSync::abort() {
353353

354354
SubTasksDone::SubTasksDone(uint n) :
355355
_tasks(NULL), _n_tasks(n), _threads_completed(0) {
356-
_tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal);
356+
_tasks = NEW_C_HEAP_ARRAY(bool, n, mtInternal);
357357
clear();
358358
}
359359

@@ -363,7 +363,7 @@ bool SubTasksDone::valid() {
363363

364364
void SubTasksDone::clear() {
365365
for (uint i = 0; i < _n_tasks; i++) {
366-
_tasks[i] = 0;
366+
_tasks[i] = false;
367367
}
368368
_threads_completed = 0;
369369
}
@@ -374,7 +374,7 @@ void SubTasksDone::all_tasks_completed_impl(uint n_threads,
374374
#ifdef ASSERT
375375
// all non-skipped tasks are claimed
376376
for (uint i = 0; i < _n_tasks; ++i) {
377-
if (_tasks[i] == 0) {
377+
if (!_tasks[i]) {
378378
auto is_skipped = false;
379379
for (size_t j = 0; j < skipped_size; ++j) {
380380
if (i == skipped[j]) {
@@ -389,7 +389,7 @@ void SubTasksDone::all_tasks_completed_impl(uint n_threads,
389389
for (size_t i = 0; i < skipped_size; ++i) {
390390
auto task_index = skipped[i];
391391
assert(task_index < _n_tasks, "Array in range.");
392-
assert(_tasks[task_index] == 0, "%d is both claimed and skipped.", task_index);
392+
assert(!_tasks[task_index], "%d is both claimed and skipped.", task_index);
393393
}
394394
#endif
395395
uint observed = _threads_completed;
@@ -407,17 +407,11 @@ void SubTasksDone::all_tasks_completed_impl(uint n_threads,
407407

408408
bool SubTasksDone::try_claim_task(uint t) {
409409
assert(t < _n_tasks, "bad task id.");
410-
uint old = _tasks[t];
411-
if (old == 0) {
412-
old = Atomic::cmpxchg(&_tasks[t], 0u, 1u);
413-
}
414-
bool res = old == 0;
415-
return res;
410+
return !_tasks[t] && !Atomic::cmpxchg(&_tasks[t], false, true);
416411
}
417412

418-
419413
SubTasksDone::~SubTasksDone() {
420-
FREE_C_HEAP_ARRAY(uint, _tasks);
414+
FREE_C_HEAP_ARRAY(bool, _tasks);
421415
}
422416

423417
// *** SequentialSubTasksDone

src/hotspot/share/gc/shared/workgroup.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class WorkGangBarrierSync : public StackObj {
302302
// enumeration type.
303303

304304
class SubTasksDone: public CHeapObj<mtInternal> {
305-
volatile uint* _tasks;
305+
volatile bool* _tasks;
306306
uint _n_tasks;
307307
volatile uint _threads_completed;
308308

0 commit comments

Comments
 (0)