1 /*
2 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
58 guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
59 if (_time_stamps == NULL) {
60 // We allocate the _time_stamps array lazily since logging can be enabled dynamically
61 GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
62 void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL);
63 if (old != NULL) {
64 // Someone already setup the time stamps
65 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps);
66 }
67 }
68
69 return &(_time_stamps[index]);
70 }
71
72 void GCTaskThread::print_task_time_stamps() {
73 assert(log_is_enabled(Debug, gc, task, time), "Sanity");
74
75 // Since _time_stamps is now lazily allocated we need to check that it
76 // has in fact been allocated when calling this function.
77 if (_time_stamps != NULL) {
78 log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index);
79 for(uint i=0; i<_time_stamp_index; i++) {
80 GCTaskTimeStamp* time_stamp = time_stamp_at(i);
81 log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]",
82 time_stamp->name(),
83 time_stamp->entry_time(),
84 time_stamp->exit_time());
85 }
86
87 // Reset after dumping the data
88 _time_stamp_index = 0;
89 }
90 }
91
92 // GC workers get tasks from the GCTaskManager and execute
93 // them in this method. If there are no tasks to execute,
94 // the GC workers wait in the GCTaskManager's get_task()
95 // for tasks to be enqueued for execution.
96
97 void GCTaskThread::run() {
98 // Set up the thread for stack overflow support
99 this->record_stack_base_and_size();
127 bool is_idle_task = task->is_idle_task();
128 // In case the update is costly
129 if (log_is_enabled(Debug, gc, task, time)) {
130 timer.update();
131 }
132
133 jlong entry_time = timer.ticks();
134 char* name = task->name();
135
136 // If this is the barrier task, it can be destroyed
137 // by the GC task manager once the do_it() executes.
138 task->do_it(manager(), which());
139
140 // Use the saved value of is_idle_task because references
141 // using "task" are not reliable for the barrier task.
142 if (!is_idle_task) {
143 manager()->note_completion(which());
144
145 if (log_is_enabled(Debug, gc, task, time)) {
146 timer.update();
147
148 GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index);
149
150 time_stamp->set_name(name);
151 time_stamp->set_entry_time(entry_time);
152 time_stamp->set_exit_time(timer.ticks());
153
154 // Update the index after we have set up the entry correctly since
155 // GCTaskThread::print_task_time_stamps() may read this value concurrently.
156 _time_stamp_index++;
157 }
158 } else {
159 // idle tasks complete outside the normal accounting
160 // so that a task can complete without waiting for idle tasks.
161 // They have to be terminated separately.
162 IdleGCTask::destroy((IdleGCTask*)task);
163 set_is_working(true);
164 }
165
166 // Check if we should release our inner resources.
167 if (manager()->should_release_resources(which())) {
168 manager()->note_release(which());
169 break;
170 }
171 }
172 }
173 }
|
1 /*
2 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
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
119 this->record_stack_base_and_size();
147 bool is_idle_task = task->is_idle_task();
148 // In case the update is costly
149 if (log_is_enabled(Debug, gc, task, time)) {
150 timer.update();
151 }
152
153 jlong entry_time = timer.ticks();
154 char* name = task->name();
155
156 // If this is the barrier task, it can be destroyed
157 // by the GC task manager once the do_it() executes.
158 task->do_it(manager(), which());
159
160 // Use the saved value of is_idle_task because references
161 // using "task" are not reliable for the barrier task.
162 if (!is_idle_task) {
163 manager()->note_completion(which());
164
165 if (log_is_enabled(Debug, gc, task, time)) {
166 timer.update();
167 add_task_timestamp(name, entry_time, timer.ticks());
168 }
169 } else {
170 // idle tasks complete outside the normal accounting
171 // so that a task can complete without waiting for idle tasks.
172 // They have to be terminated separately.
173 IdleGCTask::destroy((IdleGCTask*)task);
174 set_is_working(true);
175 }
176
177 // Check if we should release our inner resources.
178 if (manager()->should_release_resources(which())) {
179 manager()->note_release(which());
180 break;
181 }
182 }
183 }
184 }
|