37 #include "runtime/thread.hpp"
38
39 GCTaskThread::GCTaskThread(GCTaskManager* manager,
40 uint which,
41 uint processor_id) :
42 _manager(manager),
43 _processor_id(processor_id),
44 _time_stamps(NULL),
45 _time_stamp_index(0)
46 {
47 set_id(which);
48 set_name("%s#%d", manager->group_name(), which);
49 }
50
51 GCTaskThread::~GCTaskThread() {
52 if (_time_stamps != NULL) {
53 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
54 }
55 }
56
57 void GCTaskThread::add_task_timestamp(char* name, jlong t_entry, jlong t_exit) {
58 if (_time_stamp_index == GCTaskTimeStampEntries) {
59 log_warning(gc, task, time)("GC-thread %u: Too many timestamps, overwriting last. Increase GCTaskTimeStampEntries to get more info.", id());
60 }
61
62 uint time = MIN2(_time_stamp_index, (uint)GCTaskTimeStampEntries - 1);
63 GCTaskTimeStamp* time_stamp = time_stamp_at(time);
64 time_stamp->set_name(name);
65 time_stamp->set_entry_time(t_entry);
66 time_stamp->set_exit_time(t_exit);
67
68 _time_stamp_index++;
69 }
70
71 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
72 assert(index < GCTaskTimeStampEntries, "Precondition");
73 if (_time_stamps == NULL) {
74 // We allocate the _time_stamps array lazily since logging can be enabled dynamically
75 GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
76 void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL);
77 if (old != NULL) {
78 // Someone already setup the time stamps
79 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps);
80 }
81 }
82 return &(_time_stamps[index]);
83 }
84
85 void GCTaskThread::print_task_time_stamps() {
86 assert(log_is_enabled(Debug, gc, task, time), "Sanity");
87
88 // Since _time_stamps is now lazily allocated we need to check that it
89 // has in fact been allocated when calling this function.
90 if (_time_stamps != NULL) {
91 log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index);
92 const uint max_index = MIN2(_time_stamp_index, (uint)GCTaskTimeStampEntries);
93 for (uint i = 0; i < max_index; i++) {
94 GCTaskTimeStamp* time_stamp = time_stamp_at(i);
95 log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]",
96 time_stamp->name(),
97 time_stamp->entry_time(),
98 time_stamp->exit_time());
99 }
100
101 // Reset after dumping the data
102 _time_stamp_index = 0;
103 }
104 }
105
106 // GC workers get tasks from the GCTaskManager and execute
107 // them in this method. If there are no tasks to execute,
108 // the GC workers wait in the GCTaskManager's get_task()
109 // for tasks to be enqueued for execution.
110
111 void GCTaskThread::run() {
112 // Set up the thread for stack overflow support
|
37 #include "runtime/thread.hpp"
38
39 GCTaskThread::GCTaskThread(GCTaskManager* manager,
40 uint which,
41 uint processor_id) :
42 _manager(manager),
43 _processor_id(processor_id),
44 _time_stamps(NULL),
45 _time_stamp_index(0)
46 {
47 set_id(which);
48 set_name("%s#%d", manager->group_name(), which);
49 }
50
51 GCTaskThread::~GCTaskThread() {
52 if (_time_stamps != NULL) {
53 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps);
54 }
55 }
56
57 void GCTaskThread::add_task_timestamp(const char* name, jlong t_entry, jlong t_exit) {
58 if (_time_stamp_index < GCTaskTimeStampEntries) {
59 GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index);
60 time_stamp->set_name(name);
61 time_stamp->set_entry_time(t_entry);
62 time_stamp->set_exit_time(t_exit);
63 } else {
64 if (_time_stamp_index == GCTaskTimeStampEntries) {
65 log_warning(gc, task, time)("GC-thread %u: Too many timestamps, ignoring future ones. "
66 "Increase GCTaskTimeStampEntries to get more info.",
67 id());
68 }
69 // Let _time_stamp_index keep counting to give the user an idea about how many
70 // are needed.
71 }
72 _time_stamp_index++;
73 }
74
75 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
76 assert(index < GCTaskTimeStampEntries, "Precondition");
77 if (_time_stamps == NULL) {
78 // We allocate the _time_stamps array lazily since logging can be enabled dynamically
79 GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
80 void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL);
81 if (old != NULL) {
82 // Someone already setup the time stamps
83 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps);
84 }
85 }
86 return &(_time_stamps[index]);
87 }
88
89 void GCTaskThread::print_task_time_stamps() {
90 assert(log_is_enabled(Debug, gc, task, time), "Sanity");
91
92 // Since _time_stamps is now lazily allocated we need to check that it
93 // has in fact been allocated when calling this function.
94 if (_time_stamps != NULL) {
95 log_debug(gc, task, time)("GC-Thread %u entries: %d%s", id(),
96 _time_stamp_index,
97 _time_stamp_index >= GCTaskTimeStampEntries ? " (overflow)" : "");
98 const uint max_index = MIN2(_time_stamp_index, GCTaskTimeStampEntries);
99 for (uint i = 0; i < max_index; i++) {
100 GCTaskTimeStamp* time_stamp = time_stamp_at(i);
101 log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]",
102 time_stamp->name(),
103 time_stamp->entry_time(),
104 time_stamp->exit_time());
105 }
106
107 // Reset after dumping the data
108 _time_stamp_index = 0;
109 }
110 }
111
112 // GC workers get tasks from the GCTaskManager and execute
113 // them in this method. If there are no tasks to execute,
114 // the GC workers wait in the GCTaskManager's get_task()
115 // for tasks to be enqueued for execution.
116
117 void GCTaskThread::run() {
118 // Set up the thread for stack overflow support
|