author | jwilhelm |
Thu, 03 Oct 2013 21:36:29 +0200 | |
changeset 20398 | b206c580c45f |
parent 17087 | f0b76c4c93a0 |
child 22234 | da823d78ad65 |
permissions | -rw-r--r-- |
1 | 1 |
|
2 |
/* |
|
13963
e5b53c306fb5
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
13195
diff
changeset
|
3 |
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* 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
|
22 |
* questions. |
1 | 23 |
* |
24 |
*/ |
|
25 |
||
7397 | 26 |
#include "precompiled.hpp" |
27 |
#include "gc_implementation/parallelScavenge/gcTaskManager.hpp" |
|
28 |
#include "gc_implementation/parallelScavenge/gcTaskThread.hpp" |
|
29 |
#include "memory/allocation.hpp" |
|
30 |
#include "memory/allocation.inline.hpp" |
|
31 |
#include "memory/resourceArea.hpp" |
|
32 |
#include "runtime/handles.hpp" |
|
33 |
#include "runtime/handles.inline.hpp" |
|
34 |
#include "runtime/os.hpp" |
|
35 |
#include "runtime/thread.hpp" |
|
1 | 36 |
|
37 |
GCTaskThread::GCTaskThread(GCTaskManager* manager, |
|
38 |
uint which, |
|
39 |
uint processor_id) : |
|
40 |
_manager(manager), |
|
41 |
_processor_id(processor_id), |
|
42 |
_time_stamps(NULL), |
|
43 |
_time_stamp_index(0) |
|
44 |
{ |
|
45 |
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
|
46 |
vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources."); |
1 | 47 |
|
48 |
if (PrintGCTaskTimeStamps) { |
|
13195 | 49 |
_time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC); |
1 | 50 |
|
51 |
guarantee(_time_stamps != NULL, "Sanity"); |
|
52 |
} |
|
53 |
set_id(which); |
|
54 |
set_name("GC task thread#%d (ParallelGC)", which); |
|
55 |
} |
|
56 |
||
57 |
GCTaskThread::~GCTaskThread() { |
|
58 |
if (_time_stamps != NULL) { |
|
13195 | 59 |
FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps, mtGC); |
1 | 60 |
} |
61 |
} |
|
62 |
||
63 |
void GCTaskThread::start() { |
|
64 |
os::start_thread(this); |
|
65 |
} |
|
66 |
||
67 |
GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { |
|
68 |
guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); |
|
69 |
||
70 |
return &(_time_stamps[index]); |
|
71 |
} |
|
72 |
||
73 |
void GCTaskThread::print_task_time_stamps() { |
|
74 |
assert(PrintGCTaskTimeStamps, "Sanity"); |
|
75 |
assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)"); |
|
76 |
||
77 |
tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index); |
|
78 |
for(uint i=0; i<_time_stamp_index; i++) { |
|
79 |
GCTaskTimeStamp* time_stamp = time_stamp_at(i); |
|
80 |
tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]", |
|
81 |
time_stamp->name(), |
|
82 |
time_stamp->entry_time(), |
|
83 |
time_stamp->exit_time()); |
|
84 |
} |
|
85 |
||
86 |
// Reset after dumping the data |
|
87 |
_time_stamp_index = 0; |
|
88 |
} |
|
89 |
||
90 |
void GCTaskThread::print_on(outputStream* st) const { |
|
91 |
st->print("\"%s\" ", name()); |
|
92 |
Thread::print_on(st); |
|
93 |
st->cr(); |
|
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(); |
|
104 |
this->initialize_thread_local_storage(); |
|
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()); |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
132 |
// Record if this is an idle task for later use. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
133 |
bool is_idle_task = task->is_idle_task(); |
1 | 134 |
// In case the update is costly |
135 |
if (PrintGCTaskTimeStamps) { |
|
136 |
timer.update(); |
|
137 |
} |
|
138 |
||
139 |
jlong entry_time = timer.ticks(); |
|
140 |
char* name = task->name(); |
|
141 |
||
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
142 |
// If this is the barrier task, it can be destroyed |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
143 |
// by the GC task manager once the do_it() executes. |
1 | 144 |
task->do_it(manager(), which()); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
145 |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
146 |
// Use the saved value of is_idle_task because references |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
147 |
// using "task" are not reliable for the barrier task. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
148 |
if (!is_idle_task) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
149 |
manager()->note_completion(which()); |
1 | 150 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
151 |
if (PrintGCTaskTimeStamps) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
152 |
assert(_time_stamps != NULL, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
153 |
"Sanity (PrintGCTaskTimeStamps set late?)"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
154 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
155 |
timer.update(); |
1 | 156 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
157 |
GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++); |
1 | 158 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
159 |
time_stamp->set_name(name); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
160 |
time_stamp->set_entry_time(entry_time); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
161 |
time_stamp->set_exit_time(timer.ticks()); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
162 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
163 |
} else { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
164 |
// idle tasks complete outside the normal accounting |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
165 |
// 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
|
166 |
// They have to be terminated separately. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
167 |
IdleGCTask::destroy((IdleGCTask*)task); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
168 |
set_is_working(true); |
1 | 169 |
} |
170 |
||
171 |
// Check if we should release our inner resources. |
|
172 |
if (manager()->should_release_resources(which())) { |
|
173 |
manager()->note_release(which()); |
|
174 |
break; |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
} |