author | iklam |
Tue, 11 Feb 2014 08:43:17 -0800 | |
changeset 22758 | c6b6abb73544 |
parent 22551 | 9bf46d16dcc6 |
child 24094 | 5dbf1f44de18 |
permissions | -rw-r--r-- |
1374 | 1 |
/* |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10769
diff
changeset
|
2 |
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. |
1374 | 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:
3261
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
3261
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:
3261
diff
changeset
|
21 |
* questions. |
1374 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "gc_implementation/shared/concurrentGCThread.hpp" |
|
28 |
#include "oops/instanceRefKlass.hpp" |
|
29 |
#include "oops/oop.inline.hpp" |
|
30 |
#include "runtime/init.hpp" |
|
31 |
#include "runtime/interfaceSupport.hpp" |
|
32 |
#include "runtime/java.hpp" |
|
33 |
#include "runtime/javaCalls.hpp" |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22551
diff
changeset
|
34 |
#include "runtime/os.hpp" |
1374 | 35 |
|
7397 | 36 |
// CopyrightVersion 1.2 |
1374 | 37 |
|
38 |
int ConcurrentGCThread::_CGC_flag = CGC_nil; |
|
39 |
||
40 |
SuspendibleThreadSet ConcurrentGCThread::_sts; |
|
41 |
||
2881 | 42 |
ConcurrentGCThread::ConcurrentGCThread() : |
43 |
_should_terminate(false), _has_terminated(false) { |
|
1374 | 44 |
_sts.initialize(); |
45 |
}; |
|
46 |
||
47 |
void ConcurrentGCThread::safepoint_synchronize() { |
|
48 |
_sts.suspend_all(); |
|
49 |
} |
|
50 |
||
51 |
void ConcurrentGCThread::safepoint_desynchronize() { |
|
52 |
_sts.resume_all(); |
|
53 |
} |
|
54 |
||
55 |
void ConcurrentGCThread::create_and_start() { |
|
56 |
if (os::create_thread(this, os::cgc_thread)) { |
|
57 |
// XXX: need to set this to low priority |
|
22551 | 58 |
// unless "aggressive mode" set; priority |
1374 | 59 |
// should be just less than that of VMThread. |
60 |
os::set_priority(this, NearMaxPriority); |
|
61 |
if (!_should_terminate && !DisableStartThread) { |
|
62 |
os::start_thread(this); |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
void ConcurrentGCThread::initialize_in_thread() { |
|
68 |
this->record_stack_base_and_size(); |
|
69 |
this->initialize_thread_local_storage(); |
|
70 |
this->set_active_handles(JNIHandleBlock::allocate_block()); |
|
71 |
// From this time Thread::current() should be working. |
|
72 |
assert(this == Thread::current(), "just checking"); |
|
73 |
} |
|
74 |
||
75 |
void ConcurrentGCThread::wait_for_universe_init() { |
|
76 |
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag); |
|
77 |
while (!is_init_completed() && !_should_terminate) { |
|
78 |
CGC_lock->wait(Mutex::_no_safepoint_check_flag, 200); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
void ConcurrentGCThread::terminate() { |
|
83 |
// Signal that it is terminated |
|
84 |
{ |
|
85 |
MutexLockerEx mu(Terminator_lock, |
|
86 |
Mutex::_no_safepoint_check_flag); |
|
87 |
_has_terminated = true; |
|
88 |
Terminator_lock->notify(); |
|
89 |
} |
|
90 |
||
91 |
// Thread destructor usually does this.. |
|
92 |
ThreadLocalStorage::set_thread(NULL); |
|
93 |
} |
|
94 |
||
95 |
||
96 |
void SuspendibleThreadSet::initialize_work() { |
|
97 |
MutexLocker x(STS_init_lock); |
|
98 |
if (!_initialized) { |
|
99 |
_m = new Monitor(Mutex::leaf, |
|
100 |
"SuspendibleThreadSetLock", true); |
|
101 |
_async = 0; |
|
102 |
_async_stop = false; |
|
103 |
_async_stopped = 0; |
|
104 |
_initialized = true; |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
void SuspendibleThreadSet::join() { |
|
109 |
initialize(); |
|
110 |
MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag); |
|
111 |
while (_async_stop) _m->wait(Mutex::_no_safepoint_check_flag); |
|
112 |
_async++; |
|
113 |
assert(_async > 0, "Huh."); |
|
114 |
} |
|
115 |
||
116 |
void SuspendibleThreadSet::leave() { |
|
117 |
assert(_initialized, "Must be initialized."); |
|
118 |
MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag); |
|
119 |
_async--; |
|
120 |
assert(_async >= 0, "Huh."); |
|
121 |
if (_async_stop) _m->notify_all(); |
|
122 |
} |
|
123 |
||
124 |
void SuspendibleThreadSet::yield(const char* id) { |
|
125 |
assert(_initialized, "Must be initialized."); |
|
126 |
if (_async_stop) { |
|
127 |
MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag); |
|
128 |
if (_async_stop) { |
|
129 |
_async_stopped++; |
|
130 |
assert(_async_stopped > 0, "Huh."); |
|
131 |
if (_async_stopped == _async) { |
|
132 |
if (ConcGCYieldTimeout > 0) { |
|
133 |
double now = os::elapsedTime(); |
|
134 |
guarantee((now - _suspend_all_start) * 1000.0 < |
|
135 |
(double)ConcGCYieldTimeout, |
|
136 |
"Long delay; whodunit?"); |
|
137 |
} |
|
138 |
} |
|
139 |
_m->notify_all(); |
|
140 |
while (_async_stop) _m->wait(Mutex::_no_safepoint_check_flag); |
|
141 |
_async_stopped--; |
|
142 |
assert(_async >= 0, "Huh"); |
|
143 |
_m->notify_all(); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
void SuspendibleThreadSet::suspend_all() { |
|
149 |
initialize(); // If necessary. |
|
150 |
if (ConcGCYieldTimeout > 0) { |
|
151 |
_suspend_all_start = os::elapsedTime(); |
|
152 |
} |
|
153 |
MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag); |
|
154 |
assert(!_async_stop, "Only one at a time."); |
|
155 |
_async_stop = true; |
|
156 |
while (_async_stopped < _async) _m->wait(Mutex::_no_safepoint_check_flag); |
|
157 |
} |
|
158 |
||
159 |
void SuspendibleThreadSet::resume_all() { |
|
160 |
assert(_initialized, "Must be initialized."); |
|
161 |
MutexLockerEx x(_m, Mutex::_no_safepoint_check_flag); |
|
162 |
assert(_async_stopped == _async, "Huh."); |
|
163 |
_async_stop = false; |
|
164 |
_m->notify_all(); |
|
165 |
} |
|
166 |
||
167 |
static void _sltLoop(JavaThread* thread, TRAPS) { |
|
168 |
SurrogateLockerThread* slt = (SurrogateLockerThread*)thread; |
|
169 |
slt->loop(); |
|
170 |
} |
|
171 |
||
172 |
SurrogateLockerThread::SurrogateLockerThread() : |
|
173 |
JavaThread(&_sltLoop), |
|
174 |
_monitor(Mutex::nonleaf, "SLTMonitor"), |
|
175 |
_buffer(empty) |
|
176 |
{} |
|
177 |
||
178 |
SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10769
diff
changeset
|
179 |
Klass* k = |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
180 |
SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), |
1374 | 181 |
true, CHECK_NULL); |
182 |
instanceKlassHandle klass (THREAD, k); |
|
183 |
instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); |
|
184 |
||
6768
71338ecb7813
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
5547
diff
changeset
|
185 |
const char thread_name[] = "Surrogate Locker Thread (Concurrent GC)"; |
1374 | 186 |
Handle string = java_lang_String::create_from_str(thread_name, CHECK_NULL); |
187 |
||
188 |
// Initialize thread_oop to put it into the system threadGroup |
|
189 |
Handle thread_group (THREAD, Universe::system_thread_group()); |
|
190 |
JavaValue result(T_VOID); |
|
191 |
JavaCalls::call_special(&result, thread_oop, |
|
192 |
klass, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
193 |
vmSymbols::object_initializer_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
194 |
vmSymbols::threadgroup_string_void_signature(), |
1374 | 195 |
thread_group, |
196 |
string, |
|
197 |
CHECK_NULL); |
|
198 |
||
199 |
SurrogateLockerThread* res; |
|
200 |
{ |
|
201 |
MutexLocker mu(Threads_lock); |
|
202 |
res = new SurrogateLockerThread(); |
|
203 |
||
204 |
// At this point it may be possible that no osthread was created for the |
|
205 |
// JavaThread due to lack of memory. We would have to throw an exception |
|
206 |
// in that case. However, since this must work and we do not allow |
|
207 |
// exceptions anyway, check and abort if this fails. |
|
208 |
if (res == NULL || res->osthread() == NULL) { |
|
209 |
vm_exit_during_initialization("java.lang.OutOfMemoryError", |
|
22758
c6b6abb73544
7182040: volano29 limited by os resource on Linux - need better diagnostic message
iklam
parents:
22551
diff
changeset
|
210 |
os::native_thread_creation_failed_msg()); |
1374 | 211 |
} |
212 |
java_lang_Thread::set_thread(thread_oop(), res); |
|
213 |
java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); |
|
214 |
java_lang_Thread::set_daemon(thread_oop()); |
|
215 |
||
216 |
res->set_threadObj(thread_oop()); |
|
217 |
Threads::add(res); |
|
218 |
Thread::start(res); |
|
219 |
} |
|
220 |
os::yield(); // This seems to help with initial start-up of SLT |
|
221 |
return res; |
|
222 |
} |
|
223 |
||
224 |
void SurrogateLockerThread::manipulatePLL(SLT_msg_type msg) { |
|
225 |
MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag); |
|
226 |
assert(_buffer == empty, "Should be empty"); |
|
227 |
assert(msg != empty, "empty message"); |
|
10769
983d377770fd
7099824: G1: we should take the pending list lock before doing the remark pause
johnc
parents:
9990
diff
changeset
|
228 |
assert(!Heap_lock->owned_by_self(), "Heap_lock owned by requesting thread"); |
983d377770fd
7099824: G1: we should take the pending list lock before doing the remark pause
johnc
parents:
9990
diff
changeset
|
229 |
|
1374 | 230 |
_buffer = msg; |
231 |
while (_buffer != empty) { |
|
232 |
_monitor.notify(); |
|
233 |
_monitor.wait(Mutex::_no_safepoint_check_flag); |
|
234 |
} |
|
235 |
} |
|
236 |
||
237 |
// ======= Surrogate Locker Thread ============= |
|
238 |
||
239 |
void SurrogateLockerThread::loop() { |
|
240 |
BasicLock pll_basic_lock; |
|
241 |
SLT_msg_type msg; |
|
242 |
debug_only(unsigned int owned = 0;) |
|
243 |
||
244 |
while (/* !isTerminated() */ 1) { |
|
245 |
{ |
|
246 |
MutexLocker x(&_monitor); |
|
247 |
// Since we are a JavaThread, we can't be here at a safepoint. |
|
248 |
assert(!SafepointSynchronize::is_at_safepoint(), |
|
249 |
"SLT is a JavaThread"); |
|
250 |
// wait for msg buffer to become non-empty |
|
251 |
while (_buffer == empty) { |
|
252 |
_monitor.notify(); |
|
253 |
_monitor.wait(); |
|
254 |
} |
|
255 |
msg = _buffer; |
|
256 |
} |
|
257 |
switch(msg) { |
|
258 |
case acquirePLL: { |
|
13738
d67be49a5beb
7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents:
13728
diff
changeset
|
259 |
InstanceRefKlass::acquire_pending_list_lock(&pll_basic_lock); |
1374 | 260 |
debug_only(owned++;) |
261 |
break; |
|
262 |
} |
|
263 |
case releaseAndNotifyPLL: { |
|
264 |
assert(owned > 0, "Don't have PLL"); |
|
13738
d67be49a5beb
7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents:
13728
diff
changeset
|
265 |
InstanceRefKlass::release_and_notify_pending_list_lock(&pll_basic_lock); |
1374 | 266 |
debug_only(owned--;) |
267 |
break; |
|
268 |
} |
|
269 |
case empty: |
|
270 |
default: { |
|
271 |
guarantee(false,"Unexpected message in _buffer"); |
|
272 |
break; |
|
273 |
} |
|
274 |
} |
|
275 |
{ |
|
276 |
MutexLocker x(&_monitor); |
|
277 |
// Since we are a JavaThread, we can't be here at a safepoint. |
|
278 |
assert(!SafepointSynchronize::is_at_safepoint(), |
|
279 |
"SLT is a JavaThread"); |
|
280 |
_buffer = empty; |
|
281 |
_monitor.notify(); |
|
282 |
} |
|
283 |
} |
|
284 |
assert(!_monitor.owned_by_self(), "Should unlock before exit."); |
|
285 |
} |
|
286 |
||
287 |
||
288 |
// ===== STS Access From Outside CGCT ===== |
|
289 |
||
290 |
void ConcurrentGCThread::stsYield(const char* id) { |
|
291 |
assert( Thread::current()->is_ConcurrentGC_thread(), |
|
292 |
"only a conc GC thread can call this" ); |
|
293 |
_sts.yield(id); |
|
294 |
} |
|
295 |
||
296 |
bool ConcurrentGCThread::stsShouldYield() { |
|
297 |
assert( Thread::current()->is_ConcurrentGC_thread(), |
|
298 |
"only a conc GC thread can call this" ); |
|
299 |
return _sts.should_yield(); |
|
300 |
} |
|
301 |
||
302 |
void ConcurrentGCThread::stsJoin() { |
|
303 |
assert( Thread::current()->is_ConcurrentGC_thread(), |
|
304 |
"only a conc GC thread can call this" ); |
|
305 |
_sts.join(); |
|
306 |
} |
|
307 |
||
308 |
void ConcurrentGCThread::stsLeave() { |
|
309 |
assert( Thread::current()->is_ConcurrentGC_thread(), |
|
310 |
"only a conc GC thread can call this" ); |
|
311 |
_sts.leave(); |
|
312 |
} |