author | drchase |
Fri, 09 May 2014 16:50:54 -0400 | |
changeset 24424 | 2658d7834c6e |
parent 24331 | c0bc7e5653fb |
child 27880 | afb974a04396 |
permissions | -rw-r--r-- |
1 | 1 |
|
2 |
/* |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24331
diff
changeset
|
3 |
* Copyright (c) 2002, 2014, 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 |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24331
diff
changeset
|
37 |
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
24331
diff
changeset
|
38 |
|
1 | 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 |
if (PrintGCTaskTimeStamps) { |
|
13195 | 51 |
_time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC); |
1 | 52 |
|
53 |
guarantee(_time_stamps != NULL, "Sanity"); |
|
54 |
} |
|
55 |
set_id(which); |
|
56 |
set_name("GC task thread#%d (ParallelGC)", which); |
|
57 |
} |
|
58 |
||
59 |
GCTaskThread::~GCTaskThread() { |
|
60 |
if (_time_stamps != NULL) { |
|
13195 | 61 |
FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps, mtGC); |
1 | 62 |
} |
63 |
} |
|
64 |
||
65 |
void GCTaskThread::start() { |
|
66 |
os::start_thread(this); |
|
67 |
} |
|
68 |
||
69 |
GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { |
|
70 |
guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); |
|
71 |
||
72 |
return &(_time_stamps[index]); |
|
73 |
} |
|
74 |
||
75 |
void GCTaskThread::print_task_time_stamps() { |
|
76 |
assert(PrintGCTaskTimeStamps, "Sanity"); |
|
77 |
assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)"); |
|
78 |
||
79 |
tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index); |
|
80 |
for(uint i=0; i<_time_stamp_index; i++) { |
|
81 |
GCTaskTimeStamp* time_stamp = time_stamp_at(i); |
|
82 |
tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]", |
|
83 |
time_stamp->name(), |
|
84 |
time_stamp->entry_time(), |
|
85 |
time_stamp->exit_time()); |
|
86 |
} |
|
87 |
||
88 |
// Reset after dumping the data |
|
89 |
_time_stamp_index = 0; |
|
90 |
} |
|
91 |
||
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
92 |
// GC workers get tasks from the GCTaskManager and execute |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
93 |
// 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
|
94 |
// 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
|
95 |
// for tasks to be enqueued for execution. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
96 |
|
1 | 97 |
void GCTaskThread::run() { |
98 |
// Set up the thread for stack overflow support |
|
99 |
this->record_stack_base_and_size(); |
|
100 |
this->initialize_thread_local_storage(); |
|
101 |
// Bind yourself to your processor. |
|
102 |
if (processor_id() != GCTaskManager::sentinel_worker()) { |
|
103 |
if (TraceGCTaskThread) { |
|
104 |
tty->print_cr("GCTaskThread::run: " |
|
105 |
" binding to processor %u", processor_id()); |
|
106 |
} |
|
107 |
if (!os::bind_to_processor(processor_id())) { |
|
108 |
DEBUG_ONLY( |
|
109 |
warning("Couldn't bind GCTaskThread %u to processor %u", |
|
110 |
which(), processor_id()); |
|
111 |
) |
|
112 |
} |
|
113 |
} |
|
114 |
// Part of thread setup. |
|
115 |
// ??? Are these set up once here to make subsequent ones fast? |
|
116 |
HandleMark hm_outer; |
|
117 |
ResourceMark rm_outer; |
|
118 |
||
119 |
TimeStamp timer; |
|
120 |
||
121 |
for (;/* ever */;) { |
|
122 |
// These are so we can flush the resources allocated in the inner loop. |
|
123 |
HandleMark hm_inner; |
|
124 |
ResourceMark rm_inner; |
|
125 |
for (; /* break */; ) { |
|
126 |
// This will block until there is a task to be gotten. |
|
127 |
GCTask* task = manager()->get_task(which()); |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
128 |
// Record if this is an idle task for later use. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
129 |
bool is_idle_task = task->is_idle_task(); |
1 | 130 |
// In case the update is costly |
131 |
if (PrintGCTaskTimeStamps) { |
|
132 |
timer.update(); |
|
133 |
} |
|
134 |
||
135 |
jlong entry_time = timer.ticks(); |
|
136 |
char* name = task->name(); |
|
137 |
||
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
138 |
// If this is the barrier task, it can be destroyed |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
139 |
// by the GC task manager once the do_it() executes. |
1 | 140 |
task->do_it(manager(), which()); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
141 |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
142 |
// Use the saved value of is_idle_task because references |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
143 |
// using "task" are not reliable for the barrier task. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
144 |
if (!is_idle_task) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
145 |
manager()->note_completion(which()); |
1 | 146 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
147 |
if (PrintGCTaskTimeStamps) { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
148 |
assert(_time_stamps != NULL, |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
149 |
"Sanity (PrintGCTaskTimeStamps set late?)"); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
150 |
|
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
151 |
timer.update(); |
1 | 152 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
153 |
GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++); |
1 | 154 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
155 |
time_stamp->set_name(name); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
156 |
time_stamp->set_entry_time(entry_time); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
157 |
time_stamp->set_exit_time(timer.ticks()); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
158 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
159 |
} else { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
160 |
// idle tasks complete outside the normal accounting |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
161 |
// 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
|
162 |
// They have to be terminated separately. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
163 |
IdleGCTask::destroy((IdleGCTask*)task); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
164 |
set_is_working(true); |
1 | 165 |
} |
166 |
||
167 |
// Check if we should release our inner resources. |
|
168 |
if (manager()->should_release_resources(which())) { |
|
169 |
manager()->note_release(which()); |
|
170 |
break; |
|
171 |
} |
|
172 |
} |
|
173 |
} |
|
174 |
} |