1 /* |
1 /* |
2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2016, 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. |
38 // of any worker fails. Still, return a boolean so that |
38 // of any worker fails. Still, return a boolean so that |
39 // a future implementation can possibly do a partial |
39 // a future implementation can possibly do a partial |
40 // initialization of the workers and report such to the |
40 // initialization of the workers and report such to the |
41 // caller. |
41 // caller. |
42 bool AbstractWorkGang::initialize_workers() { |
42 bool AbstractWorkGang::initialize_workers() { |
43 |
43 log_develop_trace(gc, workgang)("Constructing work gang %s with %u threads", name(), total_workers()); |
44 if (TraceWorkGang) { |
|
45 tty->print_cr("Constructing work gang %s with %d threads", |
|
46 name(), |
|
47 total_workers()); |
|
48 } |
|
49 _workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal); |
44 _workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal); |
50 if (_workers == NULL) { |
45 if (_workers == NULL) { |
51 vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array."); |
46 vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array."); |
52 return false; |
47 return false; |
53 } |
48 } |
277 void AbstractGangWorker::initialize() { |
272 void AbstractGangWorker::initialize() { |
278 this->record_stack_base_and_size(); |
273 this->record_stack_base_and_size(); |
279 this->initialize_named_thread(); |
274 this->initialize_named_thread(); |
280 assert(_gang != NULL, "No gang to run in"); |
275 assert(_gang != NULL, "No gang to run in"); |
281 os::set_priority(this, NearMaxPriority); |
276 os::set_priority(this, NearMaxPriority); |
282 if (TraceWorkGang) { |
277 log_develop_trace(gc, workgang)("Running gang worker for gang %s id %u", gang()->name(), id()); |
283 tty->print_cr("Running gang worker for gang %s id %u", |
|
284 gang()->name(), id()); |
|
285 } |
|
286 // The VM thread should not execute here because MutexLocker's are used |
278 // The VM thread should not execute here because MutexLocker's are used |
287 // as (opposed to MutexLockerEx's). |
279 // as (opposed to MutexLockerEx's). |
288 assert(!Thread::current()->is_VM_thread(), "VM thread should not be part" |
280 assert(!Thread::current()->is_VM_thread(), "VM thread should not be part" |
289 " of a work gang"); |
281 " of a work gang"); |
290 } |
282 } |
309 |
301 |
310 void GangWorker::signal_task_done() { |
302 void GangWorker::signal_task_done() { |
311 gang()->dispatcher()->worker_done_with_task(); |
303 gang()->dispatcher()->worker_done_with_task(); |
312 } |
304 } |
313 |
305 |
314 void GangWorker::print_task_started(WorkData data) { |
|
315 if (TraceWorkGang) { |
|
316 tty->print_cr("Running work gang %s task %s worker %u", name(), data._task->name(), data._worker_id); |
|
317 } |
|
318 } |
|
319 |
|
320 void GangWorker::print_task_done(WorkData data) { |
|
321 if (TraceWorkGang) { |
|
322 tty->print_cr("\nFinished work gang %s task %s worker %u", name(), data._task->name(), data._worker_id); |
|
323 Thread* me = Thread::current(); |
|
324 tty->print_cr(" T: " PTR_FORMAT " VM_thread: %d", p2i(me), me->is_VM_thread()); |
|
325 } |
|
326 } |
|
327 |
|
328 void GangWorker::run_task(WorkData data) { |
306 void GangWorker::run_task(WorkData data) { |
329 print_task_started(data); |
|
330 |
|
331 GCIdMark gc_id_mark(data._task->gc_id()); |
307 GCIdMark gc_id_mark(data._task->gc_id()); |
|
308 log_develop_trace(gc, workgang)("Running work gang: %s task: %s worker: %u", name(), data._task->name(), data._worker_id); |
|
309 |
332 data._task->work(data._worker_id); |
310 data._task->work(data._worker_id); |
333 |
311 |
334 print_task_done(data); |
312 log_develop_trace(gc, workgang)("Finished work gang: %s task: %s worker: %u thread: " PTR_FORMAT, |
|
313 name(), data._task->name(), data._worker_id, p2i(Thread::current())); |
335 } |
314 } |
336 |
315 |
337 void GangWorker::loop() { |
316 void GangWorker::loop() { |
338 while (true) { |
317 while (true) { |
339 WorkData data = wait_for_task(); |
318 WorkData data = wait_for_task(); |