< prev index next >

src/share/vm/gc/parallel/gcTaskThread.cpp

Print this page

        

*** 25,37 **** --- 25,39 ---- #include "precompiled.hpp" #include "gc/parallel/gcTaskManager.hpp" #include "gc/parallel/gcTaskThread.hpp" #include "gc/shared/gcId.hpp" + #include "logging/log.hpp" #include "memory/allocation.hpp" #include "memory/allocation.inline.hpp" #include "memory/resourceArea.hpp" + #include "runtime/atomic.inline.hpp" #include "runtime/handles.hpp" #include "runtime/handles.inline.hpp" #include "runtime/os.hpp" #include "runtime/thread.hpp"
*** 44,58 **** _time_stamp_index(0) { if (!os::create_thread(this, os::pgc_thread)) vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources."); - if (PrintGCTaskTimeStamps) { - _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC); - - guarantee(_time_stamps != NULL, "Sanity"); - } set_id(which); set_name("ParGC Thread#%d", which); } GCTaskThread::~GCTaskThread() { --- 46,55 ----
*** 65,86 **** os::start_thread(this); } GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); return &(_time_stamps[index]); } void GCTaskThread::print_task_time_stamps() { ! assert(PrintGCTaskTimeStamps, "Sanity"); ! assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)"); ! tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index); for(uint i=0; i<_time_stamp_index; i++) { GCTaskTimeStamp* time_stamp = time_stamp_at(i); ! tty->print_cr("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]", time_stamp->name(), time_stamp->entry_time(), time_stamp->exit_time()); } --- 62,92 ---- os::start_thread(this); } GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); + if (_time_stamps == NULL) { + // We allocate the _time_stamps array lazily since logging can be enabled dynamically + GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC); + void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL); + if (old != NULL) { + // Someone already setup the time stamps + FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps); + } + } return &(_time_stamps[index]); } void GCTaskThread::print_task_time_stamps() { ! assert((Log<LOG_TAGS(gc, task, time)>::is_debug()), "Sanity"); ! assert(_time_stamps != NULL, "Sanity"); ! log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index); for(uint i=0; i<_time_stamp_index; i++) { GCTaskTimeStamp* time_stamp = time_stamp_at(i); ! log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]", time_stamp->name(), time_stamp->entry_time(), time_stamp->exit_time()); }
*** 127,137 **** GCTask* task = manager()->get_task(which()); GCIdMark gc_id_mark(task->gc_id()); // Record if this is an idle task for later use. bool is_idle_task = task->is_idle_task(); // In case the update is costly ! if (PrintGCTaskTimeStamps) { timer.update(); } jlong entry_time = timer.ticks(); char* name = task->name(); --- 133,143 ---- GCTask* task = manager()->get_task(which()); GCIdMark gc_id_mark(task->gc_id()); // Record if this is an idle task for later use. bool is_idle_task = task->is_idle_task(); // In case the update is costly ! if (Log<LOG_TAGS(gc, task, time)>::is_debug()) { timer.update(); } jlong entry_time = timer.ticks(); char* name = task->name();
*** 143,156 **** // Use the saved value of is_idle_task because references // using "task" are not reliable for the barrier task. if (!is_idle_task) { manager()->note_completion(which()); ! if (PrintGCTaskTimeStamps) { ! assert(_time_stamps != NULL, ! "Sanity (PrintGCTaskTimeStamps set late?)"); ! timer.update(); GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++); time_stamp->set_name(name); --- 149,159 ---- // Use the saved value of is_idle_task because references // using "task" are not reliable for the barrier task. if (!is_idle_task) { manager()->note_completion(which()); ! if (Log<LOG_TAGS(gc, task, time)>::is_debug()) { timer.update(); GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++); time_stamp->set_name(name);
< prev index next >