diff --git a/src/share/vm/gc/parallel/gcTaskThread.cpp b/src/share/vm/gc/parallel/gcTaskThread.cpp index 48eb3c4..8570f71 100644 --- a/src/share/vm/gc/parallel/gcTaskThread.cpp +++ b/src/share/vm/gc/parallel/gcTaskThread.cpp @@ -54,8 +54,24 @@ GCTaskThread::~GCTaskThread() { } } +void GCTaskThread::add_task_timestamp(char* name, jlong t_entry, jlong t_exit) { + + if (_time_stamp_index < GCTaskTimeStampEntries) { + GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index); + time_stamp->set_name(name); + time_stamp->set_entry_time(t_entry); + time_stamp->set_exit_time(t_exit); + + // Update the index after we have set up the entry correctly since + // GCTaskThread::print_task_time_stamps() may read this value concurrently. + _time_stamp_index++; + } + // Else silently discard the log entry + assert(_time_stamp_index <= GCTaskTimeStampEntries, "Invariant"); +} + GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { - guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); + assert(index < GCTaskTimeStampEntries, "Precondition"); 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); @@ -65,7 +81,6 @@ GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps); } } - return &(_time_stamps[index]); } @@ -75,8 +90,10 @@ void GCTaskThread::print_task_time_stamps() { // Since _time_stamps is now lazily allocated we need to check that it // has in fact been allocated when calling this function. if (_time_stamps != NULL) { - log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index); - for(uint i=0; i<_time_stamp_index; i++) { + assert(_time_stamp_index <= GCTaskTimeStampEntries, "Sanity"); + const uint max_index = _time_stamp_index; + log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), max_index); + for (uint i = 0; i < max_index; i++) { GCTaskTimeStamp* time_stamp = time_stamp_at(i); log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]", time_stamp->name(), @@ -144,16 +161,7 @@ void GCTaskThread::run() { if (log_is_enabled(Debug, gc, task, time)) { timer.update(); - - GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index); - - time_stamp->set_name(name); - time_stamp->set_entry_time(entry_time); - time_stamp->set_exit_time(timer.ticks()); - - // Update the index after we have set up the entry correctly since - // GCTaskThread::print_task_time_stamps() may read this value concurrently. - _time_stamp_index++; + add_task_timestamp(name, entry_time, timer.ticks()); } } else { // idle tasks complete outside the normal accounting diff --git a/src/share/vm/gc/parallel/gcTaskThread.hpp b/src/share/vm/gc/parallel/gcTaskThread.hpp index 59e6286..db58cd0 100644 --- a/src/share/vm/gc/parallel/gcTaskThread.hpp +++ b/src/share/vm/gc/parallel/gcTaskThread.hpp @@ -45,6 +45,7 @@ private: uint _time_stamp_index; GCTaskTimeStamp* time_stamp_at(uint index); + void add_task_timestamp(char* name, jlong t_entry, jlong t_exit); bool _is_working; // True if participating in GC tasks