author | jmasa |
Thu, 19 May 2016 13:59:50 -0700 | |
changeset 39704 | 157f39705057 |
parent 38216 | 250794c6f95f |
child 40655 | 9f644073d3a0 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
37073
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
35460
diff
changeset
|
2 |
* Copyright (c) 2002, 2016, 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 |
set_id(which); |
|
39704 | 48 |
set_name("%s#%d", manager->group_name(), which); |
1 | 49 |
} |
50 |
||
51 |
GCTaskThread::~GCTaskThread() { |
|
52 |
if (_time_stamps != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
24424
diff
changeset
|
53 |
FREE_C_HEAP_ARRAY(GCTaskTimeStamp, _time_stamps); |
1 | 54 |
} |
55 |
} |
|
56 |
||
57 |
GCTaskTimeStamp* GCTaskThread::time_stamp_at(uint index) { |
|
58 |
guarantee(index < GCTaskTimeStampEntries, "increase GCTaskTimeStampEntries"); |
|
35061 | 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 |
} |
|
1 | 68 |
|
69 |
return &(_time_stamps[index]); |
|
70 |
} |
|
71 |
||
72 |
void GCTaskThread::print_task_time_stamps() { |
|
35061 | 73 |
assert(log_is_enabled(Debug, gc, task, time), "Sanity"); |
1 | 74 |
|
35460
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
75 |
// Since _time_stamps is now lazily allocated we need to check that it |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
76 |
// has in fact been allocated when calling this function. |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
77 |
if (_time_stamps != NULL) { |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
78 |
log_debug(gc, task, time)("GC-Thread %u entries: %d", id(), _time_stamp_index); |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
79 |
for(uint i=0; i<_time_stamp_index; i++) { |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
80 |
GCTaskTimeStamp* time_stamp = time_stamp_at(i); |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
81 |
log_debug(gc, task, time)("\t[ %s " JLONG_FORMAT " " JLONG_FORMAT " ]", |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
82 |
time_stamp->name(), |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
83 |
time_stamp->entry_time(), |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
84 |
time_stamp->exit_time()); |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
85 |
} |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
86 |
|
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
87 |
// Reset after dumping the data |
1fca55136d66
8146409: TestPromotionFailedEventWithParallelScavenge.java failed with assert(_time_stamps != __null) failed: Sanity
david
parents:
35177
diff
changeset
|
88 |
_time_stamp_index = 0; |
1 | 89 |
} |
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(); |
|
29326 | 100 |
this->initialize_named_thread(); |
1 | 101 |
// Bind yourself to your processor. |
102 |
if (processor_id() != GCTaskManager::sentinel_worker()) { |
|
37224
fd3320bf6413
8153186: Convert TraceGCTaskThread to use unified logging
brutisso
parents:
37073
diff
changeset
|
103 |
log_trace(gc, task, thread)("GCTaskThread::run: binding to processor %u", processor_id()); |
1 | 104 |
if (!os::bind_to_processor(processor_id())) { |
105 |
DEBUG_ONLY( |
|
37073
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
35460
diff
changeset
|
106 |
log_warning(gc)("Couldn't bind GCTaskThread %u to processor %u", |
c39d0903390b
8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents:
35460
diff
changeset
|
107 |
which(), processor_id()); |
1 | 108 |
) |
109 |
} |
|
110 |
} |
|
111 |
// Part of thread setup. |
|
112 |
// ??? Are these set up once here to make subsequent ones fast? |
|
113 |
HandleMark hm_outer; |
|
114 |
ResourceMark rm_outer; |
|
115 |
||
116 |
TimeStamp timer; |
|
117 |
||
118 |
for (;/* ever */;) { |
|
119 |
// These are so we can flush the resources allocated in the inner loop. |
|
120 |
HandleMark hm_inner; |
|
121 |
ResourceMark rm_inner; |
|
122 |
for (; /* break */; ) { |
|
123 |
// This will block until there is a task to be gotten. |
|
124 |
GCTask* task = manager()->get_task(which()); |
|
33126
260ff671354b
8138707: TestPromotionEventWithParallelScavenge.java crashes using undefined GC id.
brutisso
parents:
30764
diff
changeset
|
125 |
GCIdMark gc_id_mark(task->gc_id()); |
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
126 |
// Record if this is an idle task for later use. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
127 |
bool is_idle_task = task->is_idle_task(); |
1 | 128 |
// In case the update is costly |
35061 | 129 |
if (log_is_enabled(Debug, gc, task, time)) { |
1 | 130 |
timer.update(); |
131 |
} |
|
132 |
||
133 |
jlong entry_time = timer.ticks(); |
|
134 |
char* name = task->name(); |
|
135 |
||
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
136 |
// If this is the barrier task, it can be destroyed |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
137 |
// by the GC task manager once the do_it() executes. |
1 | 138 |
task->do_it(manager(), which()); |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
139 |
|
11208
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
140 |
// Use the saved value of is_idle_task because references |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
141 |
// using "task" are not reliable for the barrier task. |
101816314520
7119584: UseParallelGC barrier task can be overwritten.
jmasa
parents:
11174
diff
changeset
|
142 |
if (!is_idle_task) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
143 |
manager()->note_completion(which()); |
1 | 144 |
|
35061 | 145 |
if (log_is_enabled(Debug, gc, task, time)) { |
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
146 |
timer.update(); |
1 | 147 |
|
35177 | 148 |
GCTaskTimeStamp* time_stamp = time_stamp_at(_time_stamp_index); |
1 | 149 |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
150 |
time_stamp->set_name(name); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
151 |
time_stamp->set_entry_time(entry_time); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
152 |
time_stamp->set_exit_time(timer.ticks()); |
35177 | 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++; |
|
11174
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
157 |
} |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
158 |
} else { |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
159 |
// idle tasks complete outside the normal accounting |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
160 |
// 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
|
161 |
// They have to be terminated separately. |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
162 |
IdleGCTask::destroy((IdleGCTask*)task); |
fccee5238e70
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
7397
diff
changeset
|
163 |
set_is_working(true); |
1 | 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 |
} |