annotate src/share/vm/gc_implementation/parallelScavenge/gcTaskThread.cpp @ 17937:78bbf4d43a14

8037816: Fix for 8036122 breaks build with Xcode5/clang 8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas 8043164: Format warning in traceStream.hpp Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings Reviewed-by: kvn, coleenp, iveresov, twisti
author drchase
date Thu, 22 May 2014 15:52:41 -0400
parents 55fb97c4c58d
children 52b4284cb496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1
a61af66fc99e Initial load
duke
parents:
diff changeset
2 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17467
diff changeset
3 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
5 *
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
8 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
9 *
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
14 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
15 *
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
19 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
22 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
23 *
a61af66fc99e Initial load
duke
parents:
diff changeset
24 */
a61af66fc99e Initial load
duke
parents:
diff changeset
25
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "gc_implementation/parallelScavenge/gcTaskManager.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_implementation/parallelScavenge/gcTaskThread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "runtime/handles.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/handles.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "runtime/thread.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17467
diff changeset
37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17467
diff changeset
38
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39 GCTaskThread::GCTaskThread(GCTaskManager* manager,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 uint which,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 uint processor_id) :
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _manager(manager),
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _processor_id(processor_id),
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _time_stamps(NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _time_stamp_index(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
46 {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 if (!os::create_thread(this, os::pgc_thread))
10161
746b070f5022 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 6842
diff changeset
48 vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GC thread. Out of system resources.");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if (PrintGCTaskTimeStamps) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4132
diff changeset
51 _time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 guarantee(_time_stamps != NULL, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 set_id(which);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 set_name("GC task thread#%d (ParallelGC)", which);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 GCTaskThread::~GCTaskThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 if (_time_stamps != NULL) {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 4132
diff changeset
61 FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps, mtGC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 void GCTaskThread::start() {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 os::start_thread(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries");
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return &(_time_stamps[index]);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 void GCTaskThread::print_task_time_stamps() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert(PrintGCTaskTimeStamps, "Sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 assert(_time_stamps != NULL, "Sanity (Probably set PrintGCTaskTimeStamps late)");
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 tty->print_cr("GC-Thread %u entries: %d", id(), _time_stamp_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 for(uint i=0; i<_time_stamp_index; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 GCTaskTimeStamp* time_stamp = time_stamp_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 tty->print_cr("\t[ %s " INT64_FORMAT " " INT64_FORMAT " ]",
a61af66fc99e Initial load
duke
parents:
diff changeset
83 time_stamp->name(),
a61af66fc99e Initial load
duke
parents:
diff changeset
84 time_stamp->entry_time(),
a61af66fc99e Initial load
duke
parents:
diff changeset
85 time_stamp->exit_time());
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Reset after dumping the data
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _time_stamp_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void GCTaskThread::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 st->print("\"%s\" ", name());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 Thread::print_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 st->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
98 // GC workers get tasks from the GCTaskManager and execute
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
99 // them in this method. If there are no tasks to execute,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
100 // the GC workers wait in the GCTaskManager's get_task()
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
101 // for tasks to be enqueued for execution.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
102
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void GCTaskThread::run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Set up the thread for stack overflow support
a61af66fc99e Initial load
duke
parents:
diff changeset
105 this->record_stack_base_and_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 this->initialize_thread_local_storage();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Bind yourself to your processor.
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (processor_id() != GCTaskManager::sentinel_worker()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (TraceGCTaskThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 tty->print_cr("GCTaskThread::run: "
a61af66fc99e Initial load
duke
parents:
diff changeset
111 " binding to processor %u", processor_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (!os::bind_to_processor(processor_id())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 DEBUG_ONLY(
a61af66fc99e Initial load
duke
parents:
diff changeset
115 warning("Couldn't bind GCTaskThread %u to processor %u",
a61af66fc99e Initial load
duke
parents:
diff changeset
116 which(), processor_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
117 )
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // Part of thread setup.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // ??? Are these set up once here to make subsequent ones fast?
a61af66fc99e Initial load
duke
parents:
diff changeset
122 HandleMark hm_outer;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 ResourceMark rm_outer;
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 TimeStamp timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 for (;/* ever */;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // These are so we can flush the resources allocated in the inner loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
129 HandleMark hm_inner;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 ResourceMark rm_inner;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 for (; /* break */; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // This will block until there is a task to be gotten.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 GCTask* task = manager()->get_task(which());
4132
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
134 // Record if this is an idle task for later use.
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
135 bool is_idle_task = task->is_idle_task();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // In case the update is costly
a61af66fc99e Initial load
duke
parents:
diff changeset
137 if (PrintGCTaskTimeStamps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 timer.update();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 jlong entry_time = timer.ticks();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 char* name = task->name();
a61af66fc99e Initial load
duke
parents:
diff changeset
143
4132
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
144 // If this is the barrier task, it can be destroyed
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
145 // by the GC task manager once the do_it() executes.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 task->do_it(manager(), which());
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
147
4132
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
148 // Use the saved value of is_idle_task because references
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
149 // using "task" are not reliable for the barrier task.
6d7d0790074d 7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents: 4095
diff changeset
150 if (!is_idle_task) {
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
151 manager()->note_completion(which());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
152
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
153 if (PrintGCTaskTimeStamps) {
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
154 assert(_time_stamps != NULL,
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
155 "Sanity (PrintGCTaskTimeStamps set late?)");
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
156
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
157 timer.update();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
159 GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index++);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
160
4095
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
161 time_stamp->set_name(name);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
162 time_stamp->set_entry_time(entry_time);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
163 time_stamp->set_exit_time(timer.ticks());
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
164 }
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
165 } else {
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
166 // idle tasks complete outside the normal accounting
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
167 // so that a task can complete without waiting for idle tasks.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
168 // They have to be terminated separately.
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
169 IdleGCTask::destroy((IdleGCTask*)task);
bca17e38de00 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 1972
diff changeset
170 set_is_working(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Check if we should release our inner resources.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (manager()->should_release_resources(which())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 manager()->note_release(which());
a61af66fc99e Initial load
duke
parents:
diff changeset
176 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }