equal
deleted
inserted
replaced
38 // The current implementation will exit if the allocation |
38 // The current implementation will exit if the allocation |
39 // of any worker fails. |
39 // of any worker fails. |
40 void AbstractWorkGang::initialize_workers() { |
40 void AbstractWorkGang::initialize_workers() { |
41 log_develop_trace(gc, workgang)("Constructing work gang %s with %u threads", name(), total_workers()); |
41 log_develop_trace(gc, workgang)("Constructing work gang %s with %u threads", name(), total_workers()); |
42 _workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal); |
42 _workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal); |
43 if (_workers == NULL) { |
|
44 vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array."); |
|
45 } |
|
46 |
|
47 add_workers(true); |
43 add_workers(true); |
48 } |
44 } |
49 |
45 |
50 |
46 |
51 AbstractGangWorker* AbstractWorkGang::install_worker(uint worker_id) { |
47 AbstractGangWorker* AbstractWorkGang::install_worker(uint worker_id) { |
407 // SubTasksDone functions. |
403 // SubTasksDone functions. |
408 |
404 |
409 SubTasksDone::SubTasksDone(uint n) : |
405 SubTasksDone::SubTasksDone(uint n) : |
410 _tasks(NULL), _n_tasks(n), _threads_completed(0) { |
406 _tasks(NULL), _n_tasks(n), _threads_completed(0) { |
411 _tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal); |
407 _tasks = NEW_C_HEAP_ARRAY(uint, n, mtInternal); |
412 guarantee(_tasks != NULL, "alloc failure"); |
|
413 clear(); |
408 clear(); |
414 } |
409 } |
415 |
410 |
416 bool SubTasksDone::valid() { |
411 bool SubTasksDone::valid() { |
417 return _tasks != NULL; |
412 return _tasks != NULL; |
431 assert(t < _n_tasks, "bad task id."); |
426 assert(t < _n_tasks, "bad task id."); |
432 uint old = _tasks[t]; |
427 uint old = _tasks[t]; |
433 if (old == 0) { |
428 if (old == 0) { |
434 old = Atomic::cmpxchg(1u, &_tasks[t], 0u); |
429 old = Atomic::cmpxchg(1u, &_tasks[t], 0u); |
435 } |
430 } |
436 assert(_tasks[t] == 1, "What else?"); |
|
437 bool res = old == 0; |
431 bool res = old == 0; |
438 #ifdef ASSERT |
432 #ifdef ASSERT |
439 if (res) { |
433 if (res) { |
440 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); |
434 assert(_claimed < _n_tasks, "Too many tasks claimed; missing clear?"); |
441 Atomic::inc(&_claimed); |
435 Atomic::inc(&_claimed); |
458 } |
452 } |
459 } |
453 } |
460 |
454 |
461 |
455 |
462 SubTasksDone::~SubTasksDone() { |
456 SubTasksDone::~SubTasksDone() { |
463 if (_tasks != NULL) FREE_C_HEAP_ARRAY(uint, _tasks); |
457 FREE_C_HEAP_ARRAY(uint, _tasks); |
464 } |
458 } |
465 |
459 |
466 // *** SequentialSubTasksDone |
460 // *** SequentialSubTasksDone |
467 |
461 |
468 void SequentialSubTasksDone::clear() { |
462 void SequentialSubTasksDone::clear() { |