author | coleenp |
Wed, 23 Dec 2015 20:07:39 +0000 | |
changeset 35222 | fc89375d788d |
parent 35177 | 22c9af3d46fd |
child 35460 | 1fca55136d66 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29326 | 2 |
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
30764 | 26 |
#include "gc/parallel/gcTaskManager.hpp" |
27 |
#include "gc/parallel/gcTaskThread.hpp" |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
30764
diff
changeset
|
28 |
#include "gc/shared/gcId.hpp" |
35061 | 29 |
#include "logging/log.hpp" |
7397 | 30 |
#include "memory/allocation.hpp" |
31 |
#include "memory/allocation.inline.hpp" |
|
32 |
#include "memory/resourceArea.hpp" |
|
35061 | 33 |
#include "runtime/atomic.inline.hpp" |
7397 | 34 |
#include "runtime/handles.hpp" |
35 |
#include "runtime/handles.inline.hpp" |
|
36 |
#include "runtime/os.hpp" |
|
37 |
#include "runtime/thread.hpp" |
|
1 | 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 |
if (!os::create_thread(this, os::pgc_thread)) |
|
17087
f0b76c4c93a0
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
13963
diff
changeset
|
48 |
vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources."); |
1 | 49 |
|
50 |
set_id(which); |
|
29464
02c245ad3ec9
8073545: Use shorter and more descriptive names for GC worker threads
david
parents:
29326
diff
changeset
|
51 |
set_name("ParGC Thread#%d", which); |
1 | 52 |
} |
53 |
||
54 |
GCTaskThread::~GCTaskThread() { |
|
55 |
if (_time_stamps != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
56 |
FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps); |
1 | 57 |
} |
58 |
} |
|
59 |
||
60 |
void GCTaskThread::start() { |
|
61 |
os::start_thread(this); |
|
62 |
} |
|
63 |
||
64 |
GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { |
|
65 |
guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); |
|
35061 | 66 |
if (_time_stamps == NULL) { |
67 |
// We allocate the _time_stamps array lazily since logging can be enabled dynamically |
|
68 |
GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC); |
|
69 |
void* old = Atomic::cmpxchg_ptr(time_stamps, &_time_stamps, NULL); |
|
70 |
if (old != NULL) { |
|
71 |
// Someone already setup the time stamps |
|
72 |
FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps); |
|
73 |
} |
|
74 |
} |
|
1 | 75 |
|
76 |
return &(_time_stamps[index]); |
|
77 |
} |
|
78 |
||
79 |
void GCTaskThread::print_task_time_stamps() { |
|
35061 | 80 |
assert(log_is_enabled(Debug, gc, task, time), "Sanity"); |
81 |
assert(_time_stamps != NULL, "Sanity"); |
|
1 | 82 |
|
35061 | 83 |
log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index); |
1 | 84 |
for(uint i=0; i<_time_stamp_index; i++) { |
85 |
GCTaskTimeStamp* time_stamp = time_stamp_at(i); |
|
35061 | 86 |
log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]", |
87 |
time_stamp->name(), |
|
88 |
time_stamp->entry_time(), |
|
89 |
time_stamp->exit_time()); |
|
1 | 90 |
} |
91 |
||
92 |
// Reset after dumping the data |
|
93 |
_time_stamp_index = 0; |
|
94 |
} |
|
95 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
96 |
// GC workers get tasks from the GCTaskManager and execute |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
97 |
// them in this method. If there are no tasks to execute, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
98 |
// the GC workers wait in the GCTaskManager's get_task() |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
99 |
// for tasks to be enqueued for execution. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
100 |
|
1 | 101 |
void GCTaskThread::run() { |
102 |
// Set up the thread for stack overflow support |
|
103 |
this->record_stack_base_and_size(); |
|
29326 | 104 |
this->initialize_named_thread(); |
1 | 105 |
// Bind yourself to your processor. |
106 |
if (processor_id() != GCTaskManager::sentinel_worker()) { |
|
107 |
if (TraceGCTaskThread) { |
|
108 |
tty->print_cr("GCTaskThread::run: " |
|
109 |
" binding to processor %u", processor_id()); |
|
110 |
} |
|
111 |
if (!os::bind_to_processor(processor_id())) { |
|
112 |
DEBUG_ONLY( |
|
113 |
warning("Couldn't bind GCTaskThread %u to processor %u", |
|
114 |
which(), processor_id()); |
|
115 |
) |
|
116 |
} |
|
117 |
} |
|
118 |
// Part of thread setup. |
|
119 |
// ??? Are these set up once here to make subsequent ones fast? |
|
120 |
HandleMark hm_outer; |
|
121 |
ResourceMark rm_outer; |
|
122 |
||
123 |
TimeStamp timer; |
|
124 |
||
125 |
for (;/* ever */;) { |
|
126 |
// These are so we can flush the resources allocated in the inner loop. |
|
127 |
HandleMark hm_inner; |
|
128 |
ResourceMark rm_inner; |
|
129 |
for (; /* break */; ) { |
|
130 |
// This will block until there is a task to be gotten. |
|
131 |
GCTask* task = manager()->get_task(which()); |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
30764
diff
changeset
|
132 |
GCIdMark gc_id_mark(task->gc_id()); |
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
133 |
// Record if this is an idle task for later use. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
134 |
bool is_idle_task = task->is_idle_task(); |
1 | 135 |
// In case the update is costly |
35061 | 136 |
if (log_is_enabled(Debug, gc, task, time)) { |
1 | 137 |
timer.update(); |
138 |
} |
|
139 |
||
140 |
jlong entry_time = timer.ticks(); |
|
141 |
char* name = task->name(); |
|
142 |
||
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
143 |
// If this is the barrier task, it can be destroyed |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
144 |
// by the GC task manager once the do_it() executes. |
1 | 145 |
task->do_it(manager(), which()); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
146 |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
147 |
// Use the saved value of is_idle_task because references |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
148 |
// using "task" are not reliable for the barrier task. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
149 |
if (!is_idle_task) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
150 |
manager()->note_completion(which()); |
1 | 151 |
|
35061 | 152 |
if (log_is_enabled(Debug, gc, task, time)) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
153 |
timer.update(); |
1 | 154 |
|
35177 | 155 |
GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index); |
1 | 156 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
157 |
time_stamp->set_name(name); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
158 |
time_stamp->set_entry_time(entry_time); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
159 |
time_stamp->set_exit_time(timer.ticks()); |
35177 | 160 |
|
161 |
// Update the index after we have set up the entry correctly since |
|
162 |
// GCTaskThread::print_task_time_stamps() may read this value concurrently. |
|
163 |
_time_stamp_index++; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
164 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
165 |
} else { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
166 |
// idle tasks complete outside the normal accounting |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
167 |
// so that a task can complete without waiting for idle tasks. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
168 |
// They have to be terminated separately. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
169 |
IdleGCTask::destroy((IdleGCTask*)task); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
170 |
set_is_working(true); |
1 | 171 |
} |
172 |
||
173 |
// Check if we should release our inner resources. |
|
174 |
if (manager()->should_release_resources(which())) { |
|
175 |
manager()->note_release(which()); |
|
176 |
break; |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
} |