Mercurial > hg > graal-compiler
annotate src/share/vm/runtime/thread.cpp @ 6580:d56d600819fe
moved AMD64 into its own (new) project: com.oracle.graal.amd64
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 25 Oct 2012 12:52:54 +0200 |
parents | 957c266d8bc5 |
children | e522a00b91aa |
rev | line source |
---|---|
0 | 1 /* |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4800
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1320
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1320
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1320
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | |
27 #include "classfile/javaClasses.hpp" | |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "classfile/vmSymbols.hpp" | |
30 #include "code/scopeDesc.hpp" | |
31 #include "compiler/compileBroker.hpp" | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
32 #ifdef GRAAL |
3064
8b0236cbed14
Make sure that the compiler is initialized at startup (and not on the first compiled method).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2925
diff
changeset
|
33 #include "graal/graalCompiler.hpp" |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
34 #endif |
1972 | 35 #include "interpreter/interpreter.hpp" |
36 #include "interpreter/linkResolver.hpp" | |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
37 #include "interpreter/oopMapCache.hpp" |
2126
db2b0f8c1cef
6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents:
2100
diff
changeset
|
38 #include "jvmtifiles/jvmtiEnv.hpp" |
4873
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
39 #include "memory/gcLocker.inline.hpp" |
1972 | 40 #include "memory/oopFactory.hpp" |
41 #include "memory/universe.inline.hpp" | |
42 #include "oops/instanceKlass.hpp" | |
43 #include "oops/objArrayOop.hpp" | |
44 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
45 #include "oops/symbol.hpp" |
1972 | 46 #include "prims/jvm_misc.hpp" |
47 #include "prims/jvmtiExport.hpp" | |
48 #include "prims/jvmtiThreadState.hpp" | |
49 #include "prims/privilegedStack.hpp" | |
50 #include "runtime/aprofiler.hpp" | |
51 #include "runtime/arguments.hpp" | |
52 #include "runtime/biasedLocking.hpp" | |
53 #include "runtime/deoptimization.hpp" | |
54 #include "runtime/fprofiler.hpp" | |
55 #include "runtime/frame.inline.hpp" | |
56 #include "runtime/init.hpp" | |
57 #include "runtime/interfaceSupport.hpp" | |
58 #include "runtime/java.hpp" | |
59 #include "runtime/javaCalls.hpp" | |
60 #include "runtime/jniPeriodicChecker.hpp" | |
61 #include "runtime/memprofiler.hpp" | |
62 #include "runtime/mutexLocker.hpp" | |
63 #include "runtime/objectMonitor.hpp" | |
64 #include "runtime/osThread.hpp" | |
65 #include "runtime/safepoint.hpp" | |
66 #include "runtime/sharedRuntime.hpp" | |
67 #include "runtime/statSampler.hpp" | |
68 #include "runtime/stubRoutines.hpp" | |
69 #include "runtime/task.hpp" | |
70 #include "runtime/threadCritical.hpp" | |
71 #include "runtime/threadLocalStorage.hpp" | |
72 #include "runtime/vframe.hpp" | |
73 #include "runtime/vframeArray.hpp" | |
74 #include "runtime/vframe_hp.hpp" | |
75 #include "runtime/vmThread.hpp" | |
76 #include "runtime/vm_operations.hpp" | |
77 #include "services/attachListener.hpp" | |
78 #include "services/management.hpp" | |
6197 | 79 #include "services/memTracker.hpp" |
1972 | 80 #include "services/threadService.hpp" |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
81 #include "trace/traceEventTypes.hpp" |
1972 | 82 #include "utilities/defaultStream.hpp" |
83 #include "utilities/dtrace.hpp" | |
84 #include "utilities/events.hpp" | |
85 #include "utilities/preserveException.hpp" | |
86 #ifdef TARGET_OS_FAMILY_linux | |
87 # include "os_linux.inline.hpp" | |
88 # include "thread_linux.inline.hpp" | |
89 #endif | |
90 #ifdef TARGET_OS_FAMILY_solaris | |
91 # include "os_solaris.inline.hpp" | |
92 # include "thread_solaris.inline.hpp" | |
93 #endif | |
94 #ifdef TARGET_OS_FAMILY_windows | |
95 # include "os_windows.inline.hpp" | |
96 # include "thread_windows.inline.hpp" | |
97 #endif | |
3960 | 98 #ifdef TARGET_OS_FAMILY_bsd |
99 # include "os_bsd.inline.hpp" | |
100 # include "thread_bsd.inline.hpp" | |
101 #endif | |
1972 | 102 #ifndef SERIALGC |
103 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" | |
104 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" | |
105 #include "gc_implementation/parallelScavenge/pcTasks.hpp" | |
106 #endif | |
107 #ifdef COMPILER1 | |
108 #include "c1/c1_Compiler.hpp" | |
109 #endif | |
110 #ifdef COMPILER2 | |
111 #include "opto/c2compiler.hpp" | |
112 #include "opto/idealGraphPrinter.hpp" | |
113 #endif | |
0 | 114 |
115 #ifdef DTRACE_ENABLED | |
116 | |
117 // Only bother with this argument setup if dtrace is available | |
118 | |
4006 | 119 #ifndef USDT2 |
0 | 120 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin); |
121 HS_DTRACE_PROBE_DECL(hotspot, vm__init__end); | |
122 HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t, | |
123 intptr_t, intptr_t, bool); | |
124 HS_DTRACE_PROBE_DECL5(hotspot, thread__stop, char*, intptr_t, | |
125 intptr_t, intptr_t, bool); | |
126 | |
127 #define DTRACE_THREAD_PROBE(probe, javathread) \ | |
128 { \ | |
129 ResourceMark rm(this); \ | |
130 int len = 0; \ | |
131 const char* name = (javathread)->get_thread_name(); \ | |
132 len = strlen(name); \ | |
133 HS_DTRACE_PROBE5(hotspot, thread__##probe, \ | |
134 name, len, \ | |
135 java_lang_Thread::thread_id((javathread)->threadObj()), \ | |
136 (javathread)->osthread()->thread_id(), \ | |
137 java_lang_Thread::is_daemon((javathread)->threadObj())); \ | |
138 } | |
139 | |
4006 | 140 #else /* USDT2 */ |
141 | |
142 #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_PROBE_START | |
143 #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_PROBE_STOP | |
144 | |
145 #define DTRACE_THREAD_PROBE(probe, javathread) \ | |
146 { \ | |
147 ResourceMark rm(this); \ | |
148 int len = 0; \ | |
149 const char* name = (javathread)->get_thread_name(); \ | |
150 len = strlen(name); \ | |
151 HOTSPOT_THREAD_PROBE_##probe( /* probe = start, stop */ \ | |
152 (char *) name, len, \ | |
153 java_lang_Thread::thread_id((javathread)->threadObj()), \ | |
154 (uintptr_t) (javathread)->osthread()->thread_id(), \ | |
155 java_lang_Thread::is_daemon((javathread)->threadObj())); \ | |
156 } | |
157 | |
158 #endif /* USDT2 */ | |
159 | |
0 | 160 #else // ndef DTRACE_ENABLED |
161 | |
162 #define DTRACE_THREAD_PROBE(probe, javathread) | |
163 | |
164 #endif // ndef DTRACE_ENABLED | |
165 | |
6197 | 166 |
0 | 167 // Class hierarchy |
168 // - Thread | |
169 // - VMThread | |
170 // - WatcherThread | |
171 // - ConcurrentMarkSweepThread | |
172 // - JavaThread | |
173 // - CompilerThread | |
174 | |
175 // ======= Thread ======== | |
176 // Support for forcing alignment of thread objects for biased locking | |
6197 | 177 void* Thread::allocate(size_t size, bool throw_excpt, MEMFLAGS flags) { |
0 | 178 if (UseBiasedLocking) { |
179 const int alignment = markOopDesc::biased_lock_alignment; | |
180 size_t aligned_size = size + (alignment - sizeof(intptr_t)); | |
6197 | 181 void* real_malloc_addr = throw_excpt? AllocateHeap(aligned_size, flags, CURRENT_PC) |
182 : os::malloc(aligned_size, flags, CURRENT_PC); | |
0 | 183 void* aligned_addr = (void*) align_size_up((intptr_t) real_malloc_addr, alignment); |
184 assert(((uintptr_t) aligned_addr + (uintptr_t) size) <= | |
185 ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size), | |
186 "JavaThread alignment code overflowed allocated storage"); | |
187 if (TraceBiasedLocking) { | |
188 if (aligned_addr != real_malloc_addr) | |
189 tty->print_cr("Aligned thread " INTPTR_FORMAT " to " INTPTR_FORMAT, | |
190 real_malloc_addr, aligned_addr); | |
191 } | |
192 ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr; | |
193 return aligned_addr; | |
194 } else { | |
6197 | 195 return throw_excpt? AllocateHeap(size, flags, CURRENT_PC) |
196 : os::malloc(size, flags, CURRENT_PC); | |
0 | 197 } |
198 } | |
199 | |
200 void Thread::operator delete(void* p) { | |
201 if (UseBiasedLocking) { | |
202 void* real_malloc_addr = ((Thread*) p)->_real_malloc_address; | |
6197 | 203 FreeHeap(real_malloc_addr, mtThread); |
0 | 204 } else { |
6197 | 205 FreeHeap(p, mtThread); |
0 | 206 } |
207 } | |
208 | |
209 | |
210 // Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread, | |
211 // JavaThread | |
212 | |
213 | |
214 Thread::Thread() { | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
215 // stack and get_thread |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
216 set_stack_base(NULL); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
217 set_stack_size(0); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
218 set_self_raw_id(0); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
219 set_lgrp_id(-1); |
0 | 220 |
221 // allocated data structures | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
222 set_osthread(NULL); |
6197 | 223 set_resource_area(new (mtThread)ResourceArea()); |
224 set_handle_area(new (mtThread) HandleArea(NULL)); | |
0 | 225 set_active_handles(NULL); |
226 set_free_handle_block(NULL); | |
227 set_last_handle_mark(NULL); | |
228 | |
229 // This initial value ==> never claimed. | |
230 _oops_do_parity = 0; | |
231 | |
232 // the handle mark links itself to last_handle_mark | |
233 new HandleMark(this); | |
234 | |
235 // plain initialization | |
236 debug_only(_owned_locks = NULL;) | |
237 debug_only(_allow_allocation_count = 0;) | |
238 NOT_PRODUCT(_allow_safepoint_count = 0;) | |
806
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
702
diff
changeset
|
239 NOT_PRODUCT(_skip_gcalot = false;) |
0 | 240 CHECK_UNHANDLED_OOPS_ONLY(_gc_locked_out_count = 0;) |
241 _jvmti_env_iteration_count = 0; | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
242 set_allocated_bytes(0); |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
243 set_trace_buffer(NULL); |
0 | 244 _vm_operation_started_count = 0; |
245 _vm_operation_completed_count = 0; | |
246 _current_pending_monitor = NULL; | |
247 _current_pending_monitor_is_from_java = true; | |
248 _current_waiting_monitor = NULL; | |
249 _num_nested_signal = 0; | |
250 omFreeList = NULL ; | |
251 omFreeCount = 0 ; | |
252 omFreeProvision = 32 ; | |
1587 | 253 omInUseList = NULL ; |
254 omInUseCount = 0 ; | |
0 | 255 |
5928
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
256 #ifdef ASSERT |
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
257 _visited_for_critical_count = false; |
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
258 #endif |
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
259 |
0 | 260 _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true); |
261 _suspend_flags = 0; | |
262 | |
263 // thread-specific hashCode stream generator state - Marsaglia shift-xor form | |
264 _hashStateX = os::random() ; | |
265 _hashStateY = 842502087 ; | |
266 _hashStateZ = 0x8767 ; // (int)(3579807591LL & 0xffff) ; | |
267 _hashStateW = 273326509 ; | |
268 | |
269 _OnTrap = 0 ; | |
270 _schedctl = NULL ; | |
271 _Stalled = 0 ; | |
272 _TypeTag = 0x2BAD ; | |
273 | |
274 // Many of the following fields are effectively final - immutable | |
275 // Note that nascent threads can't use the Native Monitor-Mutex | |
276 // construct until the _MutexEvent is initialized ... | |
277 // CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents | |
278 // we might instead use a stack of ParkEvents that we could provision on-demand. | |
279 // The stack would act as a cache to avoid calls to ParkEvent::Allocate() | |
280 // and ::Release() | |
281 _ParkEvent = ParkEvent::Allocate (this) ; | |
282 _SleepEvent = ParkEvent::Allocate (this) ; | |
283 _MutexEvent = ParkEvent::Allocate (this) ; | |
284 _MuxEvent = ParkEvent::Allocate (this) ; | |
285 | |
286 #ifdef CHECK_UNHANDLED_OOPS | |
287 if (CheckUnhandledOops) { | |
288 _unhandled_oops = new UnhandledOops(this); | |
289 } | |
290 #endif // CHECK_UNHANDLED_OOPS | |
291 #ifdef ASSERT | |
292 if (UseBiasedLocking) { | |
293 assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed"); | |
294 assert(this == _real_malloc_address || | |
295 this == (void*) align_size_up((intptr_t) _real_malloc_address, markOopDesc::biased_lock_alignment), | |
296 "bug in forced alignment of thread objects"); | |
297 } | |
298 #endif /* ASSERT */ | |
299 } | |
300 | |
301 void Thread::initialize_thread_local_storage() { | |
302 // Note: Make sure this method only calls | |
303 // non-blocking operations. Otherwise, it might not work | |
304 // with the thread-startup/safepoint interaction. | |
305 | |
306 // During Java thread startup, safepoint code should allow this | |
307 // method to complete because it may need to allocate memory to | |
308 // store information for the new thread. | |
309 | |
310 // initialize structure dependent on thread local storage | |
311 ThreadLocalStorage::set_thread(this); | |
312 | |
313 // set up any platform-specific state. | |
314 os::initialize_thread(); | |
315 } | |
316 | |
317 void Thread::record_stack_base_and_size() { | |
318 set_stack_base(os::current_stack_base()); | |
319 set_stack_size(os::current_stack_size()); | |
6197 | 320 |
321 // record thread's native stack, stack grows downward | |
322 address vm_base = _stack_base - _stack_size; | |
323 MemTracker::record_virtual_memory_reserve(vm_base, _stack_size, | |
324 CURRENT_PC, this); | |
325 MemTracker::record_virtual_memory_type(vm_base, mtThreadStack); | |
0 | 326 } |
327 | |
328 | |
329 Thread::~Thread() { | |
330 // Reclaim the objectmonitors from the omFreeList of the moribund thread. | |
331 ObjectSynchronizer::omFlush (this) ; | |
332 | |
6197 | 333 MemTracker::record_virtual_memory_release((_stack_base - _stack_size), |
334 _stack_size, this); | |
335 | |
0 | 336 // deallocate data structures |
337 delete resource_area(); | |
338 // since the handle marks are using the handle area, we have to deallocated the root | |
339 // handle mark before deallocating the thread's handle area, | |
340 assert(last_handle_mark() != NULL, "check we have an element"); | |
341 delete last_handle_mark(); | |
342 assert(last_handle_mark() == NULL, "check we have reached the end"); | |
343 | |
344 // It's possible we can encounter a null _ParkEvent, etc., in stillborn threads. | |
345 // We NULL out the fields for good hygiene. | |
346 ParkEvent::Release (_ParkEvent) ; _ParkEvent = NULL ; | |
347 ParkEvent::Release (_SleepEvent) ; _SleepEvent = NULL ; | |
348 ParkEvent::Release (_MutexEvent) ; _MutexEvent = NULL ; | |
349 ParkEvent::Release (_MuxEvent) ; _MuxEvent = NULL ; | |
350 | |
351 delete handle_area(); | |
352 | |
353 // osthread() can be NULL, if creation of thread failed. | |
354 if (osthread() != NULL) os::free_thread(osthread()); | |
355 | |
356 delete _SR_lock; | |
357 | |
358 // clear thread local storage if the Thread is deleting itself | |
359 if (this == Thread::current()) { | |
360 ThreadLocalStorage::set_thread(NULL); | |
361 } else { | |
362 // In the case where we're not the current thread, invalidate all the | |
363 // caches in case some code tries to get the current thread or the | |
364 // thread that was destroyed, and gets stale information. | |
365 ThreadLocalStorage::invalidate_all(); | |
366 } | |
367 CHECK_UNHANDLED_OOPS_ONLY(if (CheckUnhandledOops) delete unhandled_oops();) | |
368 } | |
369 | |
370 // NOTE: dummy function for assertion purpose. | |
371 void Thread::run() { | |
372 ShouldNotReachHere(); | |
373 } | |
374 | |
375 #ifdef ASSERT | |
376 // Private method to check for dangling thread pointer | |
377 void check_for_dangling_thread_pointer(Thread *thread) { | |
378 assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(), | |
379 "possibility of dangling Thread pointer"); | |
380 } | |
381 #endif | |
382 | |
383 | |
384 #ifndef PRODUCT | |
385 // Tracing method for basic thread operations | |
386 void Thread::trace(const char* msg, const Thread* const thread) { | |
387 if (!TraceThreadEvents) return; | |
388 ResourceMark rm; | |
389 ThreadCritical tc; | |
390 const char *name = "non-Java thread"; | |
391 int prio = -1; | |
392 if (thread->is_Java_thread() | |
393 && !thread->is_Compiler_thread()) { | |
394 // The Threads_lock must be held to get information about | |
395 // this thread but may not be in some situations when | |
396 // tracing thread events. | |
397 bool release_Threads_lock = false; | |
398 if (!Threads_lock->owned_by_self()) { | |
399 Threads_lock->lock(); | |
400 release_Threads_lock = true; | |
401 } | |
402 JavaThread* jt = (JavaThread *)thread; | |
403 name = (char *)jt->get_thread_name(); | |
404 oop thread_oop = jt->threadObj(); | |
405 if (thread_oop != NULL) { | |
406 prio = java_lang_Thread::priority(thread_oop); | |
407 } | |
408 if (release_Threads_lock) { | |
409 Threads_lock->unlock(); | |
410 } | |
411 } | |
412 tty->print_cr("Thread::%s " INTPTR_FORMAT " [%lx] %s (prio: %d)", msg, thread, thread->osthread()->thread_id(), name, prio); | |
413 } | |
414 #endif | |
415 | |
416 | |
417 ThreadPriority Thread::get_priority(const Thread* const thread) { | |
418 trace("get priority", thread); | |
419 ThreadPriority priority; | |
420 // Can return an error! | |
421 (void)os::get_priority(thread, priority); | |
422 assert(MinPriority <= priority && priority <= MaxPriority, "non-Java priority found"); | |
423 return priority; | |
424 } | |
425 | |
426 void Thread::set_priority(Thread* thread, ThreadPriority priority) { | |
427 trace("set priority", thread); | |
428 debug_only(check_for_dangling_thread_pointer(thread);) | |
429 // Can return an error! | |
430 (void)os::set_priority(thread, priority); | |
431 } | |
432 | |
433 | |
434 void Thread::start(Thread* thread) { | |
435 trace("start", thread); | |
436 // Start is different from resume in that its safety is guaranteed by context or | |
437 // being called from a Java method synchronized on the Thread object. | |
438 if (!DisableStartThread) { | |
439 if (thread->is_Java_thread()) { | |
440 // Initialize the thread state to RUNNABLE before starting this thread. | |
441 // Can not set it after the thread started because we do not know the | |
442 // exact thread state at that time. It could be in MONITOR_WAIT or | |
443 // in SLEEPING or some other state. | |
444 java_lang_Thread::set_thread_status(((JavaThread*)thread)->threadObj(), | |
445 java_lang_Thread::RUNNABLE); | |
446 } | |
447 os::start_thread(thread); | |
448 } | |
449 } | |
450 | |
451 // Enqueue a VM_Operation to do the job for us - sometime later | |
452 void Thread::send_async_exception(oop java_thread, oop java_throwable) { | |
453 VM_ThreadStop* vm_stop = new VM_ThreadStop(java_thread, java_throwable); | |
454 VMThread::execute(vm_stop); | |
455 } | |
456 | |
457 | |
458 // | |
459 // Check if an external suspend request has completed (or has been | |
460 // cancelled). Returns true if the thread is externally suspended and | |
461 // false otherwise. | |
462 // | |
463 // The bits parameter returns information about the code path through | |
464 // the routine. Useful for debugging: | |
465 // | |
466 // set in is_ext_suspend_completed(): | |
467 // 0x00000001 - routine was entered | |
468 // 0x00000010 - routine return false at end | |
469 // 0x00000100 - thread exited (return false) | |
470 // 0x00000200 - suspend request cancelled (return false) | |
471 // 0x00000400 - thread suspended (return true) | |
472 // 0x00001000 - thread is in a suspend equivalent state (return true) | |
473 // 0x00002000 - thread is native and walkable (return true) | |
474 // 0x00004000 - thread is native_trans and walkable (needed retry) | |
475 // | |
476 // set in wait_for_ext_suspend_completion(): | |
477 // 0x00010000 - routine was entered | |
478 // 0x00020000 - suspend request cancelled before loop (return false) | |
479 // 0x00040000 - thread suspended before loop (return true) | |
480 // 0x00080000 - suspend request cancelled in loop (return false) | |
481 // 0x00100000 - thread suspended in loop (return true) | |
482 // 0x00200000 - suspend not completed during retry loop (return false) | |
483 // | |
484 | |
485 // Helper class for tracing suspend wait debug bits. | |
486 // | |
487 // 0x00000100 indicates that the target thread exited before it could | |
488 // self-suspend which is not a wait failure. 0x00000200, 0x00020000 and | |
489 // 0x00080000 each indicate a cancelled suspend request so they don't | |
490 // count as wait failures either. | |
491 #define DEBUG_FALSE_BITS (0x00000010 | 0x00200000) | |
492 | |
493 class TraceSuspendDebugBits : public StackObj { | |
494 private: | |
495 JavaThread * jt; | |
496 bool is_wait; | |
497 bool called_by_wait; // meaningful when !is_wait | |
498 uint32_t * bits; | |
499 | |
500 public: | |
501 TraceSuspendDebugBits(JavaThread *_jt, bool _is_wait, bool _called_by_wait, | |
502 uint32_t *_bits) { | |
503 jt = _jt; | |
504 is_wait = _is_wait; | |
505 called_by_wait = _called_by_wait; | |
506 bits = _bits; | |
507 } | |
508 | |
509 ~TraceSuspendDebugBits() { | |
510 if (!is_wait) { | |
511 #if 1 | |
512 // By default, don't trace bits for is_ext_suspend_completed() calls. | |
513 // That trace is very chatty. | |
514 return; | |
515 #else | |
516 if (!called_by_wait) { | |
517 // If tracing for is_ext_suspend_completed() is enabled, then only | |
518 // trace calls to it from wait_for_ext_suspend_completion() | |
519 return; | |
520 } | |
521 #endif | |
522 } | |
523 | |
524 if (AssertOnSuspendWaitFailure || TraceSuspendWaitFailures) { | |
525 if (bits != NULL && (*bits & DEBUG_FALSE_BITS) != 0) { | |
526 MutexLocker ml(Threads_lock); // needed for get_thread_name() | |
527 ResourceMark rm; | |
528 | |
529 tty->print_cr( | |
530 "Failed wait_for_ext_suspend_completion(thread=%s, debug_bits=%x)", | |
531 jt->get_thread_name(), *bits); | |
532 | |
533 guarantee(!AssertOnSuspendWaitFailure, "external suspend wait failed"); | |
534 } | |
535 } | |
536 } | |
537 }; | |
538 #undef DEBUG_FALSE_BITS | |
539 | |
540 | |
541 bool JavaThread::is_ext_suspend_completed(bool called_by_wait, int delay, uint32_t *bits) { | |
542 TraceSuspendDebugBits tsdb(this, false /* !is_wait */, called_by_wait, bits); | |
543 | |
544 bool did_trans_retry = false; // only do thread_in_native_trans retry once | |
545 bool do_trans_retry; // flag to force the retry | |
546 | |
547 *bits |= 0x00000001; | |
548 | |
549 do { | |
550 do_trans_retry = false; | |
551 | |
552 if (is_exiting()) { | |
553 // Thread is in the process of exiting. This is always checked | |
554 // first to reduce the risk of dereferencing a freed JavaThread. | |
555 *bits |= 0x00000100; | |
556 return false; | |
557 } | |
558 | |
559 if (!is_external_suspend()) { | |
560 // Suspend request is cancelled. This is always checked before | |
561 // is_ext_suspended() to reduce the risk of a rogue resume | |
562 // confusing the thread that made the suspend request. | |
563 *bits |= 0x00000200; | |
564 return false; | |
565 } | |
566 | |
567 if (is_ext_suspended()) { | |
568 // thread is suspended | |
569 *bits |= 0x00000400; | |
570 return true; | |
571 } | |
572 | |
573 // Now that we no longer do hard suspends of threads running | |
574 // native code, the target thread can be changing thread state | |
575 // while we are in this routine: | |
576 // | |
577 // _thread_in_native -> _thread_in_native_trans -> _thread_blocked | |
578 // | |
579 // We save a copy of the thread state as observed at this moment | |
580 // and make our decision about suspend completeness based on the | |
581 // copy. This closes the race where the thread state is seen as | |
582 // _thread_in_native_trans in the if-thread_blocked check, but is | |
583 // seen as _thread_blocked in if-thread_in_native_trans check. | |
584 JavaThreadState save_state = thread_state(); | |
585 | |
586 if (save_state == _thread_blocked && is_suspend_equivalent()) { | |
587 // If the thread's state is _thread_blocked and this blocking | |
588 // condition is known to be equivalent to a suspend, then we can | |
589 // consider the thread to be externally suspended. This means that | |
590 // the code that sets _thread_blocked has been modified to do | |
591 // self-suspension if the blocking condition releases. We also | |
592 // used to check for CONDVAR_WAIT here, but that is now covered by | |
593 // the _thread_blocked with self-suspension check. | |
594 // | |
595 // Return true since we wouldn't be here unless there was still an | |
596 // external suspend request. | |
597 *bits |= 0x00001000; | |
598 return true; | |
599 } else if (save_state == _thread_in_native && frame_anchor()->walkable()) { | |
600 // Threads running native code will self-suspend on native==>VM/Java | |
601 // transitions. If its stack is walkable (should always be the case | |
602 // unless this function is called before the actual java_suspend() | |
603 // call), then the wait is done. | |
604 *bits |= 0x00002000; | |
605 return true; | |
606 } else if (!called_by_wait && !did_trans_retry && | |
607 save_state == _thread_in_native_trans && | |
608 frame_anchor()->walkable()) { | |
609 // The thread is transitioning from thread_in_native to another | |
610 // thread state. check_safepoint_and_suspend_for_native_trans() | |
611 // will force the thread to self-suspend. If it hasn't gotten | |
612 // there yet we may have caught the thread in-between the native | |
613 // code check above and the self-suspend. Lucky us. If we were | |
614 // called by wait_for_ext_suspend_completion(), then it | |
615 // will be doing the retries so we don't have to. | |
616 // | |
617 // Since we use the saved thread state in the if-statement above, | |
618 // there is a chance that the thread has already transitioned to | |
619 // _thread_blocked by the time we get here. In that case, we will | |
620 // make a single unnecessary pass through the logic below. This | |
621 // doesn't hurt anything since we still do the trans retry. | |
622 | |
623 *bits |= 0x00004000; | |
624 | |
625 // Once the thread leaves thread_in_native_trans for another | |
626 // thread state, we break out of this retry loop. We shouldn't | |
627 // need this flag to prevent us from getting back here, but | |
628 // sometimes paranoia is good. | |
629 did_trans_retry = true; | |
630 | |
631 // We wait for the thread to transition to a more usable state. | |
632 for (int i = 1; i <= SuspendRetryCount; i++) { | |
633 // We used to do an "os::yield_all(i)" call here with the intention | |
634 // that yielding would increase on each retry. However, the parameter | |
635 // is ignored on Linux which means the yield didn't scale up. Waiting | |
636 // on the SR_lock below provides a much more predictable scale up for | |
637 // the delay. It also provides a simple/direct point to check for any | |
638 // safepoint requests from the VMThread | |
639 | |
640 // temporarily drops SR_lock while doing wait with safepoint check | |
641 // (if we're a JavaThread - the WatcherThread can also call this) | |
642 // and increase delay with each retry | |
643 SR_lock()->wait(!Thread::current()->is_Java_thread(), i * delay); | |
644 | |
645 // check the actual thread state instead of what we saved above | |
646 if (thread_state() != _thread_in_native_trans) { | |
647 // the thread has transitioned to another thread state so | |
648 // try all the checks (except this one) one more time. | |
649 do_trans_retry = true; | |
650 break; | |
651 } | |
652 } // end retry loop | |
653 | |
654 | |
655 } | |
656 } while (do_trans_retry); | |
657 | |
658 *bits |= 0x00000010; | |
659 return false; | |
660 } | |
661 | |
662 // | |
663 // Wait for an external suspend request to complete (or be cancelled). | |
664 // Returns true if the thread is externally suspended and false otherwise. | |
665 // | |
666 bool JavaThread::wait_for_ext_suspend_completion(int retries, int delay, | |
667 uint32_t *bits) { | |
668 TraceSuspendDebugBits tsdb(this, true /* is_wait */, | |
669 false /* !called_by_wait */, bits); | |
670 | |
671 // local flag copies to minimize SR_lock hold time | |
672 bool is_suspended; | |
673 bool pending; | |
674 uint32_t reset_bits; | |
675 | |
676 // set a marker so is_ext_suspend_completed() knows we are the caller | |
677 *bits |= 0x00010000; | |
678 | |
679 // We use reset_bits to reinitialize the bits value at the top of | |
680 // each retry loop. This allows the caller to make use of any | |
681 // unused bits for their own marking purposes. | |
682 reset_bits = *bits; | |
683 | |
684 { | |
685 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
686 is_suspended = is_ext_suspend_completed(true /* called_by_wait */, | |
687 delay, bits); | |
688 pending = is_external_suspend(); | |
689 } | |
690 // must release SR_lock to allow suspension to complete | |
691 | |
692 if (!pending) { | |
693 // A cancelled suspend request is the only false return from | |
694 // is_ext_suspend_completed() that keeps us from entering the | |
695 // retry loop. | |
696 *bits |= 0x00020000; | |
697 return false; | |
698 } | |
699 | |
700 if (is_suspended) { | |
701 *bits |= 0x00040000; | |
702 return true; | |
703 } | |
704 | |
705 for (int i = 1; i <= retries; i++) { | |
706 *bits = reset_bits; // reinit to only track last retry | |
707 | |
708 // We used to do an "os::yield_all(i)" call here with the intention | |
709 // that yielding would increase on each retry. However, the parameter | |
710 // is ignored on Linux which means the yield didn't scale up. Waiting | |
711 // on the SR_lock below provides a much more predictable scale up for | |
712 // the delay. It also provides a simple/direct point to check for any | |
713 // safepoint requests from the VMThread | |
714 | |
715 { | |
716 MutexLocker ml(SR_lock()); | |
717 // wait with safepoint check (if we're a JavaThread - the WatcherThread | |
718 // can also call this) and increase delay with each retry | |
719 SR_lock()->wait(!Thread::current()->is_Java_thread(), i * delay); | |
720 | |
721 is_suspended = is_ext_suspend_completed(true /* called_by_wait */, | |
722 delay, bits); | |
723 | |
724 // It is possible for the external suspend request to be cancelled | |
725 // (by a resume) before the actual suspend operation is completed. | |
726 // Refresh our local copy to see if we still need to wait. | |
727 pending = is_external_suspend(); | |
728 } | |
729 | |
730 if (!pending) { | |
731 // A cancelled suspend request is the only false return from | |
732 // is_ext_suspend_completed() that keeps us from staying in the | |
733 // retry loop. | |
734 *bits |= 0x00080000; | |
735 return false; | |
736 } | |
737 | |
738 if (is_suspended) { | |
739 *bits |= 0x00100000; | |
740 return true; | |
741 } | |
742 } // end retry loop | |
743 | |
744 // thread did not suspend after all our retries | |
745 *bits |= 0x00200000; | |
746 return false; | |
747 } | |
748 | |
749 #ifndef PRODUCT | |
750 void JavaThread::record_jump(address target, address instr, const char* file, int line) { | |
751 | |
752 // This should not need to be atomic as the only way for simultaneous | |
753 // updates is via interrupts. Even then this should be rare or non-existant | |
754 // and we don't care that much anyway. | |
755 | |
756 int index = _jmp_ring_index; | |
757 _jmp_ring_index = (index + 1 ) & (jump_ring_buffer_size - 1); | |
758 _jmp_ring[index]._target = (intptr_t) target; | |
759 _jmp_ring[index]._instruction = (intptr_t) instr; | |
760 _jmp_ring[index]._file = file; | |
761 _jmp_ring[index]._line = line; | |
762 } | |
763 #endif /* PRODUCT */ | |
764 | |
765 // Called by flat profiler | |
766 // Callers have already called wait_for_ext_suspend_completion | |
767 // The assertion for that is currently too complex to put here: | |
768 bool JavaThread::profile_last_Java_frame(frame* _fr) { | |
769 bool gotframe = false; | |
770 // self suspension saves needed state. | |
771 if (has_last_Java_frame() && _anchor.walkable()) { | |
772 *_fr = pd_last_frame(); | |
773 gotframe = true; | |
774 } | |
775 return gotframe; | |
776 } | |
777 | |
778 void Thread::interrupt(Thread* thread) { | |
779 trace("interrupt", thread); | |
780 debug_only(check_for_dangling_thread_pointer(thread);) | |
781 os::interrupt(thread); | |
782 } | |
783 | |
784 bool Thread::is_interrupted(Thread* thread, bool clear_interrupted) { | |
785 trace("is_interrupted", thread); | |
786 debug_only(check_for_dangling_thread_pointer(thread);) | |
787 // Note: If clear_interrupted==false, this simply fetches and | |
788 // returns the value of the field osthread()->interrupted(). | |
789 return os::is_interrupted(thread, clear_interrupted); | |
790 } | |
791 | |
792 | |
793 // GC Support | |
794 bool Thread::claim_oops_do_par_case(int strong_roots_parity) { | |
795 jint thread_parity = _oops_do_parity; | |
796 if (thread_parity != strong_roots_parity) { | |
797 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
798 if (res == thread_parity) { |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
799 return true; |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
800 } else { |
0 | 801 guarantee(res == strong_roots_parity, "Or else what?"); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
802 assert(SharedHeap::heap()->workers()->active_workers() > 0, |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
803 "Should only fail when parallel."); |
0 | 804 return false; |
805 } | |
806 } | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
807 assert(SharedHeap::heap()->workers()->active_workers() > 0, |
0 | 808 "Should only fail when parallel."); |
809 return false; | |
810 } | |
811 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
812 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) { |
0 | 813 active_handles()->oops_do(f); |
814 // Do oop for ThreadShadow | |
815 f->do_oop((oop*)&_pending_exception); | |
816 handle_area()->oops_do(f); | |
817 } | |
818 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
819 void Thread::nmethods_do(CodeBlobClosure* cf) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
820 // no nmethods in a generic thread... |
0 | 821 } |
822 | |
823 void Thread::print_on(outputStream* st) const { | |
824 // get_priority assumes osthread initialized | |
825 if (osthread() != NULL) { | |
826 st->print("prio=%d tid=" INTPTR_FORMAT " ", get_priority(this), this); | |
827 osthread()->print_on(st); | |
828 } | |
829 debug_only(if (WizardMode) print_owned_locks_on(st);) | |
830 } | |
831 | |
832 // Thread::print_on_error() is called by fatal error handler. Don't use | |
833 // any lock or allocate memory. | |
834 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const { | |
835 if (is_VM_thread()) st->print("VMThread"); | |
836 else if (is_Compiler_thread()) st->print("CompilerThread"); | |
837 else if (is_Java_thread()) st->print("JavaThread"); | |
838 else if (is_GC_task_thread()) st->print("GCTaskThread"); | |
839 else if (is_Watcher_thread()) st->print("WatcherThread"); | |
840 else if (is_ConcurrentGC_thread()) st->print("ConcurrentGCThread"); | |
841 else st->print("Thread"); | |
842 | |
843 st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]", | |
844 _stack_base - _stack_size, _stack_base); | |
845 | |
846 if (osthread()) { | |
847 st->print(" [id=%d]", osthread()->thread_id()); | |
848 } | |
849 } | |
850 | |
851 #ifdef ASSERT | |
852 void Thread::print_owned_locks_on(outputStream* st) const { | |
853 Monitor *cur = _owned_locks; | |
854 if (cur == NULL) { | |
855 st->print(" (no locks) "); | |
856 } else { | |
857 st->print_cr(" Locks owned:"); | |
858 while(cur) { | |
859 cur->print_on(st); | |
860 cur = cur->next(); | |
861 } | |
862 } | |
863 } | |
864 | |
865 static int ref_use_count = 0; | |
866 | |
867 bool Thread::owns_locks_but_compiled_lock() const { | |
868 for(Monitor *cur = _owned_locks; cur; cur = cur->next()) { | |
869 if (cur != Compile_lock) return true; | |
870 } | |
871 return false; | |
872 } | |
873 | |
874 | |
875 #endif | |
876 | |
877 #ifndef PRODUCT | |
878 | |
879 // The flag: potential_vm_operation notifies if this particular safepoint state could potential | |
880 // invoke the vm-thread (i.e., and oop allocation). In that case, we also have to make sure that | |
881 // no threads which allow_vm_block's are held | |
882 void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) { | |
883 // Check if current thread is allowed to block at a safepoint | |
884 if (!(_allow_safepoint_count == 0)) | |
885 fatal("Possible safepoint reached by thread that does not allow it"); | |
886 if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) { | |
887 fatal("LEAF method calling lock?"); | |
888 } | |
889 | |
890 #ifdef ASSERT | |
891 if (potential_vm_operation && is_Java_thread() | |
892 && !Universe::is_bootstrapping()) { | |
893 // Make sure we do not hold any locks that the VM thread also uses. | |
894 // This could potentially lead to deadlocks | |
895 for(Monitor *cur = _owned_locks; cur; cur = cur->next()) { | |
896 // Threads_lock is special, since the safepoint synchronization will not start before this is | |
897 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, | |
898 // since it is used to transfer control between JavaThreads and the VMThread | |
899 // Do not *exclude* any locks unless you are absolutly sure it is correct. Ask someone else first! | |
900 if ( (cur->allow_vm_block() && | |
901 cur != Threads_lock && | |
902 cur != Compile_lock && // Temporary: should not be necessary when we get spearate compilation | |
903 cur != VMOperationRequest_lock && | |
904 cur != VMOperationQueue_lock) || | |
905 cur->rank() == Mutex::special) { | |
906 warning("Thread holding lock at safepoint that vm can block on: %s", cur->name()); | |
907 } | |
908 } | |
909 } | |
910 | |
911 if (GCALotAtAllSafepoints) { | |
912 // We could enter a safepoint here and thus have a gc | |
913 InterfaceSupport::check_gc_alot(); | |
914 } | |
915 #endif | |
916 } | |
917 #endif | |
918 | |
919 bool Thread::is_in_stack(address adr) const { | |
920 assert(Thread::current() == this, "is_in_stack can only be called from current thread"); | |
921 address end = os::current_stack_pointer(); | |
922 if (stack_base() >= adr && adr >= end) return true; | |
923 | |
924 return false; | |
925 } | |
926 | |
927 | |
928 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter | |
929 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being | |
930 // used for compilation in the future. If that change is made, the need for these methods | |
931 // should be revisited, and they should be removed if possible. | |
932 | |
933 bool Thread::is_lock_owned(address adr) const { | |
1688
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1608
diff
changeset
|
934 return on_local_stack(adr); |
0 | 935 } |
936 | |
937 bool Thread::set_as_starting_thread() { | |
938 // NOTE: this must be called inside the main thread. | |
939 return os::create_main_thread((JavaThread*)this); | |
940 } | |
941 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
942 static void initialize_class(Symbol* class_name, TRAPS) { |
0 | 943 klassOop klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK); |
944 instanceKlass::cast(klass)->initialize(CHECK); | |
945 } | |
946 | |
947 | |
948 // Creates the initial ThreadGroup | |
949 static Handle create_initial_thread_group(TRAPS) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
950 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ThreadGroup(), true, CHECK_NH); |
0 | 951 instanceKlassHandle klass (THREAD, k); |
952 | |
953 Handle system_instance = klass->allocate_instance_handle(CHECK_NH); | |
954 { | |
955 JavaValue result(T_VOID); | |
956 JavaCalls::call_special(&result, | |
957 system_instance, | |
958 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
959 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
960 vmSymbols::void_method_signature(), |
0 | 961 CHECK_NH); |
962 } | |
963 Universe::set_system_thread_group(system_instance()); | |
964 | |
965 Handle main_instance = klass->allocate_instance_handle(CHECK_NH); | |
966 { | |
967 JavaValue result(T_VOID); | |
968 Handle string = java_lang_String::create_from_str("main", CHECK_NH); | |
969 JavaCalls::call_special(&result, | |
970 main_instance, | |
971 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
972 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
973 vmSymbols::threadgroup_string_void_signature(), |
0 | 974 system_instance, |
975 string, | |
976 CHECK_NH); | |
977 } | |
978 return main_instance; | |
979 } | |
980 | |
981 // Creates the initial Thread | |
982 static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
983 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL); |
0 | 984 instanceKlassHandle klass (THREAD, k); |
985 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); | |
986 | |
987 java_lang_Thread::set_thread(thread_oop(), thread); | |
988 java_lang_Thread::set_priority(thread_oop(), NormPriority); | |
989 thread->set_threadObj(thread_oop()); | |
990 | |
991 Handle string = java_lang_String::create_from_str("main", CHECK_NULL); | |
992 | |
993 JavaValue result(T_VOID); | |
994 JavaCalls::call_special(&result, thread_oop, | |
995 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
996 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
997 vmSymbols::threadgroup_string_void_signature(), |
0 | 998 thread_group, |
999 string, | |
1000 CHECK_NULL); | |
1001 return thread_oop(); | |
1002 } | |
1003 | |
1004 static void call_initializeSystemClass(TRAPS) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1005 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK); |
0 | 1006 instanceKlassHandle klass (THREAD, k); |
1007 | |
1008 JavaValue result(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1009 JavaCalls::call_static(&result, klass, vmSymbols::initializeSystemClass_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1010 vmSymbols::void_method_signature(), CHECK); |
0 | 1011 } |
1012 | |
6181 | 1013 char java_runtime_name[128] = ""; |
1014 | |
1015 // extract the JRE name from sun.misc.Version.java_runtime_name | |
1016 static const char* get_java_runtime_name(TRAPS) { | |
1017 klassOop k = SystemDictionary::find(vmSymbols::sun_misc_Version(), | |
1018 Handle(), Handle(), CHECK_AND_CLEAR_NULL); | |
1019 fieldDescriptor fd; | |
1020 bool found = k != NULL && | |
1021 instanceKlass::cast(k)->find_local_field(vmSymbols::java_runtime_name_name(), | |
1022 vmSymbols::string_signature(), &fd); | |
1023 if (found) { | |
1024 oop name_oop = k->java_mirror()->obj_field(fd.offset()); | |
1025 if (name_oop == NULL) | |
1026 return NULL; | |
1027 const char* name = java_lang_String::as_utf8_string(name_oop, | |
1028 java_runtime_name, | |
1029 sizeof(java_runtime_name)); | |
1030 return name; | |
1031 } else { | |
1032 return NULL; | |
1033 } | |
1034 } | |
1035 | |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1036 // General purpose hook into Java code, run once when the VM is initialized. |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1037 // The Java library method itself may be changed independently from the VM. |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1038 static void call_postVMInitHook(TRAPS) { |
3938 | 1039 klassOop k = SystemDictionary::PostVMInitHook_klass(); |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1040 instanceKlassHandle klass (THREAD, k); |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1041 if (klass.not_null()) { |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1042 JavaValue result(T_VOID); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1043 JavaCalls::call_static(&result, klass, vmSymbols::run_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1044 vmSymbols::void_method_signature(), |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1045 CHECK); |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1046 } |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1047 } |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1048 |
0 | 1049 static void reset_vm_info_property(TRAPS) { |
1050 // the vm info string | |
1051 ResourceMark rm(THREAD); | |
1052 const char *vm_info = VM_Version::vm_info_string(); | |
1053 | |
1054 // java.lang.System class | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1055 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK); |
0 | 1056 instanceKlassHandle klass (THREAD, k); |
1057 | |
1058 // setProperty arguments | |
1059 Handle key_str = java_lang_String::create_from_str("java.vm.info", CHECK); | |
1060 Handle value_str = java_lang_String::create_from_str(vm_info, CHECK); | |
1061 | |
1062 // return value | |
1063 JavaValue r(T_OBJECT); | |
1064 | |
1065 // public static String setProperty(String key, String value); | |
1066 JavaCalls::call_static(&r, | |
1067 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1068 vmSymbols::setProperty_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1069 vmSymbols::string_string_string_signature(), |
0 | 1070 key_str, |
1071 value_str, | |
1072 CHECK); | |
1073 } | |
1074 | |
1075 | |
1076 void JavaThread::allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS) { | |
1077 assert(thread_group.not_null(), "thread group should be specified"); | |
1078 assert(threadObj() == NULL, "should only create Java thread object once"); | |
1079 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1080 klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); |
0 | 1081 instanceKlassHandle klass (THREAD, k); |
1082 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); | |
1083 | |
1084 java_lang_Thread::set_thread(thread_oop(), this); | |
1085 java_lang_Thread::set_priority(thread_oop(), NormPriority); | |
1086 set_threadObj(thread_oop()); | |
1087 | |
1088 JavaValue result(T_VOID); | |
1089 if (thread_name != NULL) { | |
1090 Handle name = java_lang_String::create_from_str(thread_name, CHECK); | |
1091 // Thread gets assigned specified name and null target | |
1092 JavaCalls::call_special(&result, | |
1093 thread_oop, | |
1094 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1095 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1096 vmSymbols::threadgroup_string_void_signature(), |
0 | 1097 thread_group, // Argument 1 |
1098 name, // Argument 2 | |
1099 THREAD); | |
1100 } else { | |
1101 // Thread gets assigned name "Thread-nnn" and null target | |
1102 // (java.lang.Thread doesn't have a constructor taking only a ThreadGroup argument) | |
1103 JavaCalls::call_special(&result, | |
1104 thread_oop, | |
1105 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1106 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1107 vmSymbols::threadgroup_runnable_void_signature(), |
0 | 1108 thread_group, // Argument 1 |
1109 Handle(), // Argument 2 | |
1110 THREAD); | |
1111 } | |
1112 | |
1113 | |
1114 if (daemon) { | |
1115 java_lang_Thread::set_daemon(thread_oop()); | |
1116 } | |
1117 | |
1118 if (HAS_PENDING_EXCEPTION) { | |
1119 return; | |
1120 } | |
1121 | |
1142 | 1122 KlassHandle group(this, SystemDictionary::ThreadGroup_klass()); |
0 | 1123 Handle threadObj(this, this->threadObj()); |
1124 | |
1125 JavaCalls::call_special(&result, | |
1126 thread_group, | |
1127 group, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1128 vmSymbols::add_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1129 vmSymbols::thread_void_signature(), |
0 | 1130 threadObj, // Arg 1 |
1131 THREAD); | |
1132 | |
1133 | |
1134 } | |
1135 | |
1136 // NamedThread -- non-JavaThread subclasses with multiple | |
1137 // uniquely named instances should derive from this. | |
1138 NamedThread::NamedThread() : Thread() { | |
1139 _name = NULL; | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
1140 _processed_thread = NULL; |
0 | 1141 } |
1142 | |
1143 NamedThread::~NamedThread() { | |
1144 if (_name != NULL) { | |
6197 | 1145 FREE_C_HEAP_ARRAY(char, _name, mtThread); |
0 | 1146 _name = NULL; |
1147 } | |
1148 } | |
1149 | |
1150 void NamedThread::set_name(const char* format, ...) { | |
1151 guarantee(_name == NULL, "Only get to set name once."); | |
6197 | 1152 _name = NEW_C_HEAP_ARRAY(char, max_name_len, mtThread); |
0 | 1153 guarantee(_name != NULL, "alloc failure"); |
1154 va_list ap; | |
1155 va_start(ap, format); | |
1156 jio_vsnprintf(_name, max_name_len, format, ap); | |
1157 va_end(ap); | |
1158 } | |
1159 | |
1160 // ======= WatcherThread ======== | |
1161 | |
1162 // The watcher thread exists to simulate timer interrupts. It should | |
1163 // be replaced by an abstraction over whatever native support for | |
1164 // timer interrupts exists on the platform. | |
1165 | |
1166 WatcherThread* WatcherThread::_watcher_thread = NULL; | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1167 volatile bool WatcherThread::_should_terminate = false; |
0 | 1168 |
1169 WatcherThread::WatcherThread() : Thread() { | |
1170 assert(watcher_thread() == NULL, "we can only allocate one WatcherThread"); | |
1171 if (os::create_thread(this, os::watcher_thread)) { | |
1172 _watcher_thread = this; | |
1173 | |
1174 // Set the watcher thread to the highest OS priority which should not be | |
1175 // used, unless a Java thread with priority java.lang.Thread.MAX_PRIORITY | |
1176 // is created. The only normal thread using this priority is the reference | |
1177 // handler thread, which runs for very short intervals only. | |
1178 // If the VMThread's priority is not lower than the WatcherThread profiling | |
1179 // will be inaccurate. | |
1180 os::set_priority(this, MaxPriority); | |
1181 if (!DisableStartThread) { | |
1182 os::start_thread(this); | |
1183 } | |
1184 } | |
1185 } | |
1186 | |
1187 void WatcherThread::run() { | |
1188 assert(this == watcher_thread(), "just checking"); | |
1189 | |
1190 this->record_stack_base_and_size(); | |
1191 this->initialize_thread_local_storage(); | |
1192 this->set_active_handles(JNIHandleBlock::allocate_block()); | |
1193 while(!_should_terminate) { | |
1194 assert(watcher_thread() == Thread::current(), "thread consistency check"); | |
1195 assert(watcher_thread() == this, "thread consistency check"); | |
1196 | |
1197 // Calculate how long it'll be until the next PeriodicTask work | |
1198 // should be done, and sleep that amount of time. | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1199 size_t time_to_wait = PeriodicTask::time_to_wait(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1200 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1201 // we expect this to timeout - we only ever get unparked when |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1202 // we should terminate |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1203 { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1204 OSThreadWaitState osts(this->osthread(), false /* not Object.wait() */); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1205 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1206 jlong prev_time = os::javaTimeNanos(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1207 for (;;) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1208 int res= _SleepEvent->park(time_to_wait); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1209 if (res == OS_TIMEOUT || _should_terminate) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1210 break; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1211 // spurious wakeup of some kind |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1212 jlong now = os::javaTimeNanos(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1213 time_to_wait -= (now - prev_time) / 1000000; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1214 if (time_to_wait <= 0) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1215 break; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1216 prev_time = now; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1217 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1218 } |
0 | 1219 |
1220 if (is_error_reported()) { | |
1221 // A fatal error has happened, the error handler(VMError::report_and_die) | |
1222 // should abort JVM after creating an error log file. However in some | |
1223 // rare cases, the error handler itself might deadlock. Here we try to | |
1224 // kill JVM if the fatal error handler fails to abort in 2 minutes. | |
1225 // | |
1226 // This code is in WatcherThread because WatcherThread wakes up | |
1227 // periodically so the fatal error handler doesn't need to do anything; | |
1228 // also because the WatcherThread is less likely to crash than other | |
1229 // threads. | |
1230 | |
1231 for (;;) { | |
1232 if (!ShowMessageBoxOnError | |
1233 && (OnError == NULL || OnError[0] == '\0') | |
1234 && Arguments::abort_hook() == NULL) { | |
1235 os::sleep(this, 2 * 60 * 1000, false); | |
1236 fdStream err(defaultStream::output_fd()); | |
1237 err.print_raw_cr("# [ timer expired, abort... ]"); | |
1238 // skip atexit/vm_exit/vm_abort hooks | |
1239 os::die(); | |
1240 } | |
1241 | |
1242 // Wake up 5 seconds later, the fatal handler may reset OnError or | |
1243 // ShowMessageBoxOnError when it is ready to abort. | |
1244 os::sleep(this, 5 * 1000, false); | |
1245 } | |
1246 } | |
1247 | |
1248 PeriodicTask::real_time_tick(time_to_wait); | |
1249 | |
1250 // If we have no more tasks left due to dynamic disenrollment, | |
1251 // shut down the thread since we don't currently support dynamic enrollment | |
1252 if (PeriodicTask::num_tasks() == 0) { | |
1253 _should_terminate = true; | |
1254 } | |
1255 } | |
1256 | |
1257 // Signal that it is terminated | |
1258 { | |
1259 MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag); | |
1260 _watcher_thread = NULL; | |
1261 Terminator_lock->notify(); | |
1262 } | |
1263 | |
1264 // Thread destructor usually does this.. | |
1265 ThreadLocalStorage::set_thread(NULL); | |
1266 } | |
1267 | |
1268 void WatcherThread::start() { | |
1269 if (watcher_thread() == NULL) { | |
1270 _should_terminate = false; | |
1271 // Create the single instance of WatcherThread | |
1272 new WatcherThread(); | |
1273 } | |
1274 } | |
1275 | |
1276 void WatcherThread::stop() { | |
1277 // it is ok to take late safepoints here, if needed | |
1278 MutexLocker mu(Terminator_lock); | |
1279 _should_terminate = true; | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1280 OrderAccess::fence(); // ensure WatcherThread sees update in main loop |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1281 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1282 Thread* watcher = watcher_thread(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1283 if (watcher != NULL) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1284 watcher->_SleepEvent->unpark(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1285 |
0 | 1286 while(watcher_thread() != NULL) { |
1287 // This wait should make safepoint checks, wait without a timeout, | |
1288 // and wait as a suspend-equivalent condition. | |
1289 // | |
1290 // Note: If the FlatProfiler is running, then this thread is waiting | |
1291 // for the WatcherThread to terminate and the WatcherThread, via the | |
1292 // FlatProfiler task, is waiting for the external suspend request on | |
1293 // this thread to complete. wait_for_ext_suspend_completion() will | |
1294 // eventually timeout, but that takes time. Making this wait a | |
1295 // suspend-equivalent condition solves that timeout problem. | |
1296 // | |
1297 Terminator_lock->wait(!Mutex::_no_safepoint_check_flag, 0, | |
1298 Mutex::_as_suspend_equivalent_flag); | |
1299 } | |
1300 } | |
1301 | |
1302 void WatcherThread::print_on(outputStream* st) const { | |
1303 st->print("\"%s\" ", name()); | |
1304 Thread::print_on(st); | |
1305 st->cr(); | |
1306 } | |
1307 | |
1308 // ======= JavaThread ======== | |
1309 | |
1310 // A JavaThread is a normal Java thread | |
1311 | |
1312 void JavaThread::initialize() { | |
1313 // Initialize fields | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1314 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1315 // Set the claimed par_id to -1 (ie not claiming any par_ids) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1316 set_claimed_par_id(-1); |
3555
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3464
diff
changeset
|
1317 |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3464
diff
changeset
|
1318 _env = NULL; |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3464
diff
changeset
|
1319 _buffer_blob = NULL; |
0 | 1320 set_saved_exception_pc(NULL); |
1321 set_threadObj(NULL); | |
1322 _anchor.clear(); | |
1323 set_entry_point(NULL); | |
1324 set_jni_functions(jni_functions()); | |
1325 set_callee_target(NULL); | |
1326 set_vm_result(NULL); | |
1327 set_vm_result_2(NULL); | |
1328 set_vframe_array_head(NULL); | |
1329 set_vframe_array_last(NULL); | |
1330 set_deferred_locals(NULL); | |
1331 set_deopt_mark(NULL); | |
1814
fd5d4527cdf5
6986270: guarantee(*bcp != Bytecodes::_monitorenter || exec_mode != Deoptimization::Unpack_exception) fails
iveresov
parents:
1731
diff
changeset
|
1332 set_deopt_nmethod(NULL); |
0 | 1333 clear_must_deopt_id(); |
1334 set_monitor_chunks(NULL); | |
1335 set_next(NULL); | |
1336 set_thread_state(_thread_new); | |
6197 | 1337 set_recorder(NULL); |
0 | 1338 _terminated = _not_terminated; |
1339 _privileged_stack_top = NULL; | |
1340 _array_for_gc = NULL; | |
1341 _suspend_equivalent = false; | |
1342 _in_deopt_handler = 0; | |
1343 _doing_unsafe_access = false; | |
1344 _stack_guard_state = stack_guard_unused; | |
5747
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
1345 #ifdef GRAAL |
3558
bc95d122df79
added runtime call to supply info upon deoptimization
Lukas Stadler <lukas.stadler@jku.at>
parents:
3555
diff
changeset
|
1346 _graal_deopt_info = NULL; |
4993
897b7d18bebc
added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
4981
diff
changeset
|
1347 _graal_alternate_call_target = NULL; |
5747
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
1348 #endif |
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
1349 #ifdef HIGH_LEVEL_INTERPRETER |
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
1350 _high_level_interpreter_in_vm = false; |
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
1351 #endif |
0 | 1352 _exception_oop = NULL; |
1353 _exception_pc = 0; | |
1354 _exception_handler_pc = 0; | |
1903 | 1355 _is_method_handle_return = 0; |
0 | 1356 _jvmti_thread_state= NULL; |
1213
6deeaebad47a
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
1166
diff
changeset
|
1357 _should_post_on_exceptions_flag = JNI_FALSE; |
0 | 1358 _jvmti_get_loaded_classes_closure = NULL; |
1359 _interp_only_mode = 0; | |
1360 _special_runtime_exit_condition = _no_async_condition; | |
1361 _pending_async_exception = NULL; | |
1362 _is_compiling = false; | |
1363 _thread_stat = NULL; | |
1364 _thread_stat = new ThreadStatistics(); | |
1365 _blocked_on_compilation = false; | |
1366 _jni_active_critical = 0; | |
1367 _do_not_unlock_if_synchronized = false; | |
1368 _cached_monitor_info = NULL; | |
1369 _parker = Parker::Allocate(this) ; | |
3696
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
1370 _scanned_nmethod = NULL; |
0 | 1371 |
1372 #ifndef PRODUCT | |
1373 _jmp_ring_index = 0; | |
1374 for (int ji = 0 ; ji < jump_ring_buffer_size ; ji++ ) { | |
1375 record_jump(NULL, NULL, NULL, 0); | |
1376 } | |
1377 #endif /* PRODUCT */ | |
1378 | |
1379 set_thread_profiler(NULL); | |
1380 if (FlatProfiler::is_active()) { | |
1381 // This is where we would decide to either give each thread it's own profiler | |
1382 // or use one global one from FlatProfiler, | |
1383 // or up to some count of the number of profiled threads, etc. | |
1384 ThreadProfiler* pp = new ThreadProfiler(); | |
1385 pp->engage(); | |
1386 set_thread_profiler(pp); | |
1387 } | |
1388 | |
1389 // Setup safepoint state info for this thread | |
1390 ThreadSafepointState::create(this); | |
1391 | |
1392 debug_only(_java_call_counter = 0); | |
1393 | |
1394 // JVMTI PopFrame support | |
1395 _popframe_condition = popframe_inactive; | |
1396 _popframe_preserved_args = NULL; | |
1397 _popframe_preserved_args_size = 0; | |
1398 | |
1399 pd_initialize(); | |
1400 } | |
1401 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1402 #ifndef SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1403 SATBMarkQueueSet JavaThread::_satb_mark_queue_set; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1404 DirtyCardQueueSet JavaThread::_dirty_card_queue_set; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1405 #endif // !SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1406 |
4006 | 1407 JavaThread::JavaThread(bool is_attaching_via_jni) : |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1408 Thread() |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1409 #ifndef SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1410 , _satb_mark_queue(&_satb_mark_queue_set), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1411 _dirty_card_queue(&_dirty_card_queue_set) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1412 #endif // !SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1413 { |
0 | 1414 initialize(); |
4006 | 1415 if (is_attaching_via_jni) { |
1416 _jni_attach_state = _attaching_via_jni; | |
1417 } else { | |
1418 _jni_attach_state = _not_attaching_via_jni; | |
1419 } | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
997
diff
changeset
|
1420 assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor"); |
6197 | 1421 _safepoint_visible = false; |
0 | 1422 } |
1423 | |
1424 bool JavaThread::reguard_stack(address cur_sp) { | |
1425 if (_stack_guard_state != stack_guard_yellow_disabled) { | |
1426 return true; // Stack already guarded or guard pages not needed. | |
1427 } | |
1428 | |
1429 if (register_stack_overflow()) { | |
1430 // For those architectures which have separate register and | |
1431 // memory stacks, we must check the register stack to see if | |
1432 // it has overflowed. | |
1433 return false; | |
1434 } | |
1435 | |
1436 // Java code never executes within the yellow zone: the latter is only | |
1437 // there to provoke an exception during stack banging. If java code | |
1438 // is executing there, either StackShadowPages should be larger, or | |
1439 // some exception code in c1, c2 or the interpreter isn't unwinding | |
1440 // when it should. | |
1441 guarantee(cur_sp > stack_yellow_zone_base(), "not enough space to reguard - increase StackShadowPages"); | |
1442 | |
1443 enable_stack_yellow_zone(); | |
1444 return true; | |
1445 } | |
1446 | |
1447 bool JavaThread::reguard_stack(void) { | |
1448 return reguard_stack(os::current_stack_pointer()); | |
1449 } | |
1450 | |
1451 | |
1452 void JavaThread::block_if_vm_exited() { | |
1453 if (_terminated == _vm_exited) { | |
1454 // _vm_exited is set at safepoint, and Threads_lock is never released | |
1455 // we will block here forever | |
1456 Threads_lock->lock_without_safepoint_check(); | |
1457 ShouldNotReachHere(); | |
1458 } | |
1459 } | |
1460 | |
1461 | |
1462 // Remove this ifdef when C1 is ported to the compiler interface. | |
1463 static void compiler_thread_entry(JavaThread* thread, TRAPS); | |
1464 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1465 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1466 Thread() |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1467 #ifndef SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1468 , _satb_mark_queue(&_satb_mark_queue_set), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1469 _dirty_card_queue(&_dirty_card_queue_set) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1470 #endif // !SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1471 { |
0 | 1472 if (TraceThreadEvents) { |
1473 tty->print_cr("creating thread %p", this); | |
1474 } | |
1475 initialize(); | |
4006 | 1476 _jni_attach_state = _not_attaching_via_jni; |
0 | 1477 set_entry_point(entry_point); |
1478 // Create the native thread itself. | |
1479 // %note runtime_23 | |
1480 os::ThreadType thr_type = os::java_thread; | |
1481 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread : | |
1482 os::java_thread; | |
1483 os::create_thread(this, thr_type, stack_sz); | |
6197 | 1484 _safepoint_visible = false; |
0 | 1485 // The _osthread may be NULL here because we ran out of memory (too many threads active). |
1486 // We need to throw and OutOfMemoryError - however we cannot do this here because the caller | |
1487 // may hold a lock and all locks must be unlocked before throwing the exception (throwing | |
1488 // the exception consists of creating the exception object & initializing it, initialization | |
1489 // will leave the VM via a JavaCall and then all locks must be unlocked). | |
1490 // | |
1491 // The thread is still suspended when we reach here. Thread must be explicit started | |
1492 // by creator! Furthermore, the thread must also explicitly be added to the Threads list | |
1493 // by calling Threads:add. The reason why this is not done here, is because the thread | |
1494 // object must be fully initialized (take a look at JVM_Start) | |
1495 } | |
1496 | |
1497 JavaThread::~JavaThread() { | |
1498 if (TraceThreadEvents) { | |
1499 tty->print_cr("terminate thread %p", this); | |
1500 } | |
1501 | |
6197 | 1502 // Info NMT that this JavaThread is exiting, its memory |
1503 // recorder should be collected | |
1504 assert(!is_safepoint_visible(), "wrong state"); | |
1505 MemTracker::thread_exiting(this); | |
1506 | |
0 | 1507 // JSR166 -- return the parker to the free list |
1508 Parker::Release(_parker); | |
1509 _parker = NULL ; | |
1510 | |
1511 // Free any remaining previous UnrollBlock | |
1512 vframeArray* old_array = vframe_array_last(); | |
1513 | |
1514 if (old_array != NULL) { | |
1515 Deoptimization::UnrollBlock* old_info = old_array->unroll_block(); | |
1516 old_array->set_unroll_block(NULL); | |
1517 delete old_info; | |
1518 delete old_array; | |
1519 } | |
1520 | |
1521 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred = deferred_locals(); | |
1522 if (deferred != NULL) { | |
1523 // This can only happen if thread is destroyed before deoptimization occurs. | |
1524 assert(deferred->length() != 0, "empty array!"); | |
1525 do { | |
1526 jvmtiDeferredLocalVariableSet* dlv = deferred->at(0); | |
1527 deferred->remove_at(0); | |
1528 // individual jvmtiDeferredLocalVariableSet are CHeapObj's | |
1529 delete dlv; | |
1530 } while (deferred->length() != 0); | |
1531 delete deferred; | |
1532 } | |
1533 | |
1534 // All Java related clean up happens in exit | |
1535 ThreadSafepointState::destroy(this); | |
1536 if (_thread_profiler != NULL) delete _thread_profiler; | |
1537 if (_thread_stat != NULL) delete _thread_stat; | |
1538 } | |
1539 | |
1540 | |
1541 // The first routine called by a new Java thread | |
1542 void JavaThread::run() { | |
1543 // initialize thread-local alloc buffer related fields | |
1544 this->initialize_tlab(); | |
1545 | |
1546 // used to test validitity of stack trace backs | |
1547 this->record_base_of_stack_pointer(); | |
1548 | |
1549 // Record real stack base and size. | |
1550 this->record_stack_base_and_size(); | |
1551 | |
1552 // Initialize thread local storage; set before calling MutexLocker | |
1553 this->initialize_thread_local_storage(); | |
1554 | |
1555 this->create_stack_guard_pages(); | |
1556 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1557 this->cache_global_variables(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1558 |
0 | 1559 // Thread is now sufficient initialized to be handled by the safepoint code as being |
1560 // in the VM. Change thread state from _thread_new to _thread_in_vm | |
1561 ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm); | |
1562 | |
1563 assert(JavaThread::current() == this, "sanity check"); | |
1564 assert(!Thread::current()->owns_locks(), "sanity check"); | |
1565 | |
1566 DTRACE_THREAD_PROBE(start, this); | |
1567 | |
1568 // This operation might block. We call that after all safepoint checks for a new thread has | |
1569 // been completed. | |
1570 this->set_active_handles(JNIHandleBlock::allocate_block()); | |
1571 | |
1572 if (JvmtiExport::should_post_thread_life()) { | |
1573 JvmtiExport::post_thread_start(this); | |
1574 } | |
1575 | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1576 EVENT_BEGIN(TraceEventThreadStart, event); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1577 EVENT_COMMIT(event, |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1578 EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(this->threadObj()))); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1579 |
0 | 1580 // We call another function to do the rest so we are sure that the stack addresses used |
1581 // from there will be lower than the stack base just computed | |
1582 thread_main_inner(); | |
1583 | |
1584 // Note, thread is no longer valid at this point! | |
1585 } | |
1586 | |
1587 | |
1588 void JavaThread::thread_main_inner() { | |
1589 assert(JavaThread::current() == this, "sanity check"); | |
1590 assert(this->threadObj() != NULL, "just checking"); | |
1591 | |
2162
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1592 // Execute thread entry point unless this thread has a pending exception |
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1593 // or has been stopped before starting. |
0 | 1594 // Note: Due to JVM_StopThread we can have pending exceptions already! |
2162
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1595 if (!this->has_pending_exception() && |
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1596 !java_lang_Thread::is_stillborn(this->threadObj())) { |
4006 | 1597 { |
1598 ResourceMark rm(this); | |
1599 this->set_native_thread_name(this->get_thread_name()); | |
1600 } | |
0 | 1601 HandleMark hm(this); |
1602 this->entry_point()(this, this); | |
1603 } | |
1604 | |
1605 DTRACE_THREAD_PROBE(stop, this); | |
1606 | |
1607 this->exit(false); | |
1608 delete this; | |
1609 } | |
1610 | |
1611 | |
1612 static void ensure_join(JavaThread* thread) { | |
1613 // We do not need to grap the Threads_lock, since we are operating on ourself. | |
1614 Handle threadObj(thread, thread->threadObj()); | |
1615 assert(threadObj.not_null(), "java thread object must exist"); | |
1616 ObjectLocker lock(threadObj, thread); | |
1617 // Ignore pending exception (ThreadDeath), since we are exiting anyway | |
1618 thread->clear_pending_exception(); | |
1619 // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED. | |
1620 java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED); | |
2162
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1621 // Clear the native thread instance - this makes isAlive return false and allows the join() |
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1622 // to complete once we've done the notify_all below |
0 | 1623 java_lang_Thread::set_thread(threadObj(), NULL); |
1624 lock.notify_all(thread); | |
1625 // Ignore pending exception (ThreadDeath), since we are exiting anyway | |
1626 thread->clear_pending_exception(); | |
1627 } | |
1628 | |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1629 |
0 | 1630 // For any new cleanup additions, please check to see if they need to be applied to |
1631 // cleanup_failed_attach_current_thread as well. | |
1632 void JavaThread::exit(bool destroy_vm, ExitType exit_type) { | |
1633 assert(this == JavaThread::current(), "thread consistency check"); | |
1634 if (!InitializeJavaLangSystem) return; | |
1635 | |
1636 HandleMark hm(this); | |
1637 Handle uncaught_exception(this, this->pending_exception()); | |
1638 this->clear_pending_exception(); | |
1639 Handle threadObj(this, this->threadObj()); | |
1640 assert(threadObj.not_null(), "Java thread object should be created"); | |
1641 | |
1642 if (get_thread_profiler() != NULL) { | |
1643 get_thread_profiler()->disengage(); | |
1644 ResourceMark rm; | |
1645 get_thread_profiler()->print(get_thread_name()); | |
1646 } | |
1647 | |
1648 | |
1649 // FIXIT: This code should be moved into else part, when reliable 1.2/1.3 check is in place | |
1650 { | |
1651 EXCEPTION_MARK; | |
1652 | |
1653 CLEAR_PENDING_EXCEPTION; | |
1654 } | |
1655 // FIXIT: The is_null check is only so it works better on JDK1.2 VM's. This | |
1656 // has to be fixed by a runtime query method | |
1657 if (!destroy_vm || JDK_Version::is_jdk12x_version()) { | |
1658 // JSR-166: change call from from ThreadGroup.uncaughtException to | |
1659 // java.lang.Thread.dispatchUncaughtException | |
1660 if (uncaught_exception.not_null()) { | |
1661 Handle group(this, java_lang_Thread::threadGroup(threadObj())); | |
1662 { | |
1663 EXCEPTION_MARK; | |
1664 // Check if the method Thread.dispatchUncaughtException() exists. If so | |
1665 // call it. Otherwise we have an older library without the JSR-166 changes, | |
1666 // so call ThreadGroup.uncaughtException() | |
1667 KlassHandle recvrKlass(THREAD, threadObj->klass()); | |
1668 CallInfo callinfo; | |
1142 | 1669 KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass()); |
0 | 1670 LinkResolver::resolve_virtual_call(callinfo, threadObj, recvrKlass, thread_klass, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1671 vmSymbols::dispatchUncaughtException_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1672 vmSymbols::throwable_void_signature(), |
0 | 1673 KlassHandle(), false, false, THREAD); |
1674 CLEAR_PENDING_EXCEPTION; | |
1675 methodHandle method = callinfo.selected_method(); | |
1676 if (method.not_null()) { | |
1677 JavaValue result(T_VOID); | |
1678 JavaCalls::call_virtual(&result, | |
1679 threadObj, thread_klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1680 vmSymbols::dispatchUncaughtException_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1681 vmSymbols::throwable_void_signature(), |
0 | 1682 uncaught_exception, |
1683 THREAD); | |
1684 } else { | |
1142 | 1685 KlassHandle thread_group(THREAD, SystemDictionary::ThreadGroup_klass()); |
0 | 1686 JavaValue result(T_VOID); |
1687 JavaCalls::call_virtual(&result, | |
1688 group, thread_group, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1689 vmSymbols::uncaughtException_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1690 vmSymbols::thread_throwable_void_signature(), |
0 | 1691 threadObj, // Arg 1 |
1692 uncaught_exception, // Arg 2 | |
1693 THREAD); | |
1694 } | |
2200
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1695 if (HAS_PENDING_EXCEPTION) { |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1696 ResourceMark rm(this); |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1697 jio_fprintf(defaultStream::error_stream(), |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1698 "\nException: %s thrown from the UncaughtExceptionHandler" |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1699 " in thread \"%s\"\n", |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1700 Klass::cast(pending_exception()->klass())->external_name(), |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1701 get_thread_name()); |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1702 CLEAR_PENDING_EXCEPTION; |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1703 } |
0 | 1704 } |
1705 } | |
1706 | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1707 // Called before the java thread exit since we want to read info |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1708 // from java_lang_Thread object |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1709 EVENT_BEGIN(TraceEventThreadEnd, event); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1710 EVENT_COMMIT(event, |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1711 EVENT_SET(event, javalangthread, java_lang_Thread::thread_id(this->threadObj()))); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1712 |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1713 // Call after last event on thread |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1714 EVENT_THREAD_EXIT(this); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1715 |
0 | 1716 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during |
1717 // the execution of the method. If that is not enough, then we don't really care. Thread.stop | |
1718 // is deprecated anyhow. | |
1719 { int count = 3; | |
1720 while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) { | |
1721 EXCEPTION_MARK; | |
1722 JavaValue result(T_VOID); | |
1142 | 1723 KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass()); |
0 | 1724 JavaCalls::call_virtual(&result, |
1725 threadObj, thread_klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1726 vmSymbols::exit_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1727 vmSymbols::void_method_signature(), |
0 | 1728 THREAD); |
1729 CLEAR_PENDING_EXCEPTION; | |
1730 } | |
1731 } | |
1732 | |
1733 // notify JVMTI | |
1734 if (JvmtiExport::should_post_thread_life()) { | |
1735 JvmtiExport::post_thread_end(this); | |
1736 } | |
1737 | |
1738 // We have notified the agents that we are exiting, before we go on, | |
1739 // we must check for a pending external suspend request and honor it | |
1740 // in order to not surprise the thread that made the suspend request. | |
1741 while (true) { | |
1742 { | |
1743 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
1744 if (!is_external_suspend()) { | |
1745 set_terminated(_thread_exiting); | |
1746 ThreadService::current_thread_exiting(this); | |
1747 break; | |
1748 } | |
1749 // Implied else: | |
1750 // Things get a little tricky here. We have a pending external | |
1751 // suspend request, but we are holding the SR_lock so we | |
1752 // can't just self-suspend. So we temporarily drop the lock | |
1753 // and then self-suspend. | |
1754 } | |
1755 | |
1756 ThreadBlockInVM tbivm(this); | |
1757 java_suspend_self(); | |
1758 | |
1759 // We're done with this suspend request, but we have to loop around | |
1760 // and check again. Eventually we will get SR_lock without a pending | |
1761 // external suspend request and will be able to mark ourselves as | |
1762 // exiting. | |
1763 } | |
1764 // no more external suspends are allowed at this point | |
1765 } else { | |
1766 // before_exit() has already posted JVMTI THREAD_END events | |
1767 } | |
1768 | |
1769 // Notify waiters on thread object. This has to be done after exit() is called | |
1770 // on the thread (if the thread is the last thread in a daemon ThreadGroup the | |
1771 // group should have the destroyed bit set before waiters are notified). | |
1772 ensure_join(this); | |
1773 assert(!this->has_pending_exception(), "ensure_join should have cleared"); | |
1774 | |
1775 // 6282335 JNI DetachCurrentThread spec states that all Java monitors | |
1776 // held by this thread must be released. A detach operation must only | |
1777 // get here if there are no Java frames on the stack. Therefore, any | |
1778 // owned monitors at this point MUST be JNI-acquired monitors which are | |
1779 // pre-inflated and in the monitor cache. | |
1780 // | |
1781 // ensure_join() ignores IllegalThreadStateExceptions, and so does this. | |
1782 if (exit_type == jni_detach && JNIDetachReleasesMonitors) { | |
1783 assert(!this->has_last_Java_frame(), "detaching with Java frames?"); | |
1784 ObjectSynchronizer::release_monitors_owned_by_thread(this); | |
1785 assert(!this->has_pending_exception(), "release_monitors should have cleared"); | |
1786 } | |
1787 | |
1788 // These things needs to be done while we are still a Java Thread. Make sure that thread | |
1789 // is in a consistent state, in case GC happens | |
1790 assert(_privileged_stack_top == NULL, "must be NULL when we get here"); | |
1791 | |
1792 if (active_handles() != NULL) { | |
1793 JNIHandleBlock* block = active_handles(); | |
1794 set_active_handles(NULL); | |
1795 JNIHandleBlock::release_block(block); | |
1796 } | |
1797 | |
1798 if (free_handle_block() != NULL) { | |
1799 JNIHandleBlock* block = free_handle_block(); | |
1800 set_free_handle_block(NULL); | |
1801 JNIHandleBlock::release_block(block); | |
1802 } | |
1803 | |
1804 // These have to be removed while this is still a valid thread. | |
1805 remove_stack_guard_pages(); | |
1806 | |
1807 if (UseTLAB) { | |
1808 tlab().make_parsable(true); // retire TLAB | |
1809 } | |
1810 | |
2126
db2b0f8c1cef
6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents:
2100
diff
changeset
|
1811 if (JvmtiEnv::environments_might_exist()) { |
49
31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
dcubed
parents:
0
diff
changeset
|
1812 JvmtiExport::cleanup_thread(this); |
31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
dcubed
parents:
0
diff
changeset
|
1813 } |
31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
dcubed
parents:
0
diff
changeset
|
1814 |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1815 #ifndef SERIALGC |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1816 // We must flush G1-related buffers before removing a thread from |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1817 // the list of active threads. |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1818 if (UseG1GC) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1819 flush_barrier_queues(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1820 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1821 #endif |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1822 |
0 | 1823 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread |
1824 Threads::remove(this); | |
1825 } | |
1826 | |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1827 #ifndef SERIALGC |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1828 // Flush G1-related queues. |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1829 void JavaThread::flush_barrier_queues() { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1830 satb_mark_queue().flush(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1831 dirty_card_queue().flush(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1832 } |
1842
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1833 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1834 void JavaThread::initialize_queues() { |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1835 assert(!SafepointSynchronize::is_at_safepoint(), |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1836 "we should not be at a safepoint"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1837 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1838 ObjPtrQueue& satb_queue = satb_mark_queue(); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1839 SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set(); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1840 // The SATB queue should have been constructed with its active |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1841 // field set to false. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1842 assert(!satb_queue.is_active(), "SATB queue should not be active"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1843 assert(satb_queue.is_empty(), "SATB queue should be empty"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1844 // If we are creating the thread during a marking cycle, we should |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1845 // set the active field of the SATB queue to true. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1846 if (satb_queue_set.is_active()) { |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1847 satb_queue.set_active(true); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1848 } |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1849 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1850 DirtyCardQueue& dirty_queue = dirty_card_queue(); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1851 // The dirty card queue should have been constructed with its |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1852 // active field set to true. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1853 assert(dirty_queue.is_active(), "dirty card queue should be active"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1854 } |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1855 #endif // !SERIALGC |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1856 |
0 | 1857 void JavaThread::cleanup_failed_attach_current_thread() { |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1858 if (get_thread_profiler() != NULL) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1859 get_thread_profiler()->disengage(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1860 ResourceMark rm; |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1861 get_thread_profiler()->print(get_thread_name()); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1862 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1863 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1864 if (active_handles() != NULL) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1865 JNIHandleBlock* block = active_handles(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1866 set_active_handles(NULL); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1867 JNIHandleBlock::release_block(block); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1868 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1869 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1870 if (free_handle_block() != NULL) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1871 JNIHandleBlock* block = free_handle_block(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1872 set_free_handle_block(NULL); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1873 JNIHandleBlock::release_block(block); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1874 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1875 |
1290
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1213
diff
changeset
|
1876 // These have to be removed while this is still a valid thread. |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1213
diff
changeset
|
1877 remove_stack_guard_pages(); |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1213
diff
changeset
|
1878 |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1879 if (UseTLAB) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1880 tlab().make_parsable(true); // retire TLAB, if any |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1881 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1882 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1883 #ifndef SERIALGC |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1884 if (UseG1GC) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1885 flush_barrier_queues(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1886 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1887 #endif |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1888 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1889 Threads::remove(this); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1890 delete this; |
0 | 1891 } |
1892 | |
1893 | |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1894 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1895 |
0 | 1896 JavaThread* JavaThread::active() { |
1897 Thread* thread = ThreadLocalStorage::thread(); | |
1898 assert(thread != NULL, "just checking"); | |
1899 if (thread->is_Java_thread()) { | |
1900 return (JavaThread*) thread; | |
1901 } else { | |
1902 assert(thread->is_VM_thread(), "this must be a vm thread"); | |
1903 VM_Operation* op = ((VMThread*) thread)->vm_operation(); | |
1904 JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread(); | |
1905 assert(ret->is_Java_thread(), "must be a Java thread"); | |
1906 return ret; | |
1907 } | |
1908 } | |
1909 | |
1910 bool JavaThread::is_lock_owned(address adr) const { | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
1911 if (Thread::is_lock_owned(adr)) return true; |
0 | 1912 |
1913 for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) { | |
1914 if (chunk->contains(adr)) return true; | |
1915 } | |
1916 | |
1917 return false; | |
1918 } | |
1919 | |
1920 | |
1921 void JavaThread::add_monitor_chunk(MonitorChunk* chunk) { | |
1922 chunk->set_next(monitor_chunks()); | |
1923 set_monitor_chunks(chunk); | |
1924 } | |
1925 | |
1926 void JavaThread::remove_monitor_chunk(MonitorChunk* chunk) { | |
1927 guarantee(monitor_chunks() != NULL, "must be non empty"); | |
1928 if (monitor_chunks() == chunk) { | |
1929 set_monitor_chunks(chunk->next()); | |
1930 } else { | |
1931 MonitorChunk* prev = monitor_chunks(); | |
1932 while (prev->next() != chunk) prev = prev->next(); | |
1933 prev->set_next(chunk->next()); | |
1934 } | |
1935 } | |
1936 | |
1937 // JVM support. | |
1938 | |
1939 // Note: this function shouldn't block if it's called in | |
1940 // _thread_in_native_trans state (such as from | |
1941 // check_special_condition_for_native_trans()). | |
1942 void JavaThread::check_and_handle_async_exceptions(bool check_unsafe_error) { | |
1943 | |
1944 if (has_last_Java_frame() && has_async_condition()) { | |
1945 // If we are at a polling page safepoint (not a poll return) | |
1946 // then we must defer async exception because live registers | |
1947 // will be clobbered by the exception path. Poll return is | |
1948 // ok because the call we a returning from already collides | |
1949 // with exception handling registers and so there is no issue. | |
1950 // (The exception handling path kills call result registers but | |
1951 // this is ok since the exception kills the result anyway). | |
1952 | |
1953 if (is_at_poll_safepoint()) { | |
1954 // if the code we are returning to has deoptimized we must defer | |
1955 // the exception otherwise live registers get clobbered on the | |
1956 // exception path before deoptimization is able to retrieve them. | |
1957 // | |
1958 RegisterMap map(this, false); | |
1959 frame caller_fr = last_frame().sender(&map); | |
1960 assert(caller_fr.is_compiled_frame(), "what?"); | |
1961 if (caller_fr.is_deoptimized_frame()) { | |
1962 if (TraceExceptions) { | |
1963 ResourceMark rm; | |
1964 tty->print_cr("deferred async exception at compiled safepoint"); | |
1965 } | |
1966 return; | |
1967 } | |
1968 } | |
1969 } | |
1970 | |
1971 JavaThread::AsyncRequests condition = clear_special_runtime_exit_condition(); | |
1972 if (condition == _no_async_condition) { | |
1973 // Conditions have changed since has_special_runtime_exit_condition() | |
1974 // was called: | |
1975 // - if we were here only because of an external suspend request, | |
1976 // then that was taken care of above (or cancelled) so we are done | |
1977 // - if we were here because of another async request, then it has | |
1978 // been cleared between the has_special_runtime_exit_condition() | |
1979 // and now so again we are done | |
1980 return; | |
1981 } | |
1982 | |
1983 // Check for pending async. exception | |
1984 if (_pending_async_exception != NULL) { | |
1985 // Only overwrite an already pending exception, if it is not a threadDeath. | |
1142 | 1986 if (!has_pending_exception() || !pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())) { |
0 | 1987 |
1988 // We cannot call Exceptions::_throw(...) here because we cannot block | |
1989 set_pending_exception(_pending_async_exception, __FILE__, __LINE__); | |
1990 | |
1991 if (TraceExceptions) { | |
1992 ResourceMark rm; | |
1993 tty->print("Async. exception installed at runtime exit (" INTPTR_FORMAT ")", this); | |
1994 if (has_last_Java_frame() ) { | |
1995 frame f = last_frame(); | |
1996 tty->print(" (pc: " INTPTR_FORMAT " sp: " INTPTR_FORMAT " )", f.pc(), f.sp()); | |
1997 } | |
1998 tty->print_cr(" of type: %s", instanceKlass::cast(_pending_async_exception->klass())->external_name()); | |
1999 } | |
2000 _pending_async_exception = NULL; | |
2001 clear_has_async_exception(); | |
2002 } | |
2003 } | |
2004 | |
2005 if (check_unsafe_error && | |
2006 condition == _async_unsafe_access_error && !has_pending_exception()) { | |
2007 condition = _no_async_condition; // done | |
2008 switch (thread_state()) { | |
2009 case _thread_in_vm: | |
2010 { | |
2011 JavaThread* THREAD = this; | |
2012 THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in an unsafe memory access operation"); | |
2013 } | |
2014 case _thread_in_native: | |
2015 { | |
2016 ThreadInVMfromNative tiv(this); | |
2017 JavaThread* THREAD = this; | |
2018 THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in an unsafe memory access operation"); | |
2019 } | |
2020 case _thread_in_Java: | |
2021 { | |
2022 ThreadInVMfromJava tiv(this); | |
2023 JavaThread* THREAD = this; | |
2024 THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in a recent unsafe memory access operation in compiled Java code"); | |
2025 } | |
2026 default: | |
2027 ShouldNotReachHere(); | |
2028 } | |
2029 } | |
2030 | |
2031 assert(condition == _no_async_condition || has_pending_exception() || | |
2032 (!check_unsafe_error && condition == _async_unsafe_access_error), | |
2033 "must have handled the async condition, if no exception"); | |
2034 } | |
2035 | |
2036 void JavaThread::handle_special_runtime_exit_condition(bool check_asyncs) { | |
2037 // | |
2038 // Check for pending external suspend. Internal suspend requests do | |
2039 // not use handle_special_runtime_exit_condition(). | |
2040 // If JNIEnv proxies are allowed, don't self-suspend if the target | |
2041 // thread is not the current thread. In older versions of jdbx, jdbx | |
2042 // threads could call into the VM with another thread's JNIEnv so we | |
2043 // can be here operating on behalf of a suspended thread (4432884). | |
2044 bool do_self_suspend = is_external_suspend_with_lock(); | |
2045 if (do_self_suspend && (!AllowJNIEnvProxy || this == JavaThread::current())) { | |
2046 // | |
2047 // Because thread is external suspended the safepoint code will count | |
2048 // thread as at a safepoint. This can be odd because we can be here | |
2049 // as _thread_in_Java which would normally transition to _thread_blocked | |
2050 // at a safepoint. We would like to mark the thread as _thread_blocked | |
2051 // before calling java_suspend_self like all other callers of it but | |
2052 // we must then observe proper safepoint protocol. (We can't leave | |
2053 // _thread_blocked with a safepoint in progress). However we can be | |
2054 // here as _thread_in_native_trans so we can't use a normal transition | |
2055 // constructor/destructor pair because they assert on that type of | |
2056 // transition. We could do something like: | |
2057 // | |
2058 // JavaThreadState state = thread_state(); | |
2059 // set_thread_state(_thread_in_vm); | |
2060 // { | |
2061 // ThreadBlockInVM tbivm(this); | |
2062 // java_suspend_self() | |
2063 // } | |
2064 // set_thread_state(_thread_in_vm_trans); | |
2065 // if (safepoint) block; | |
2066 // set_thread_state(state); | |
2067 // | |
2068 // but that is pretty messy. Instead we just go with the way the | |
2069 // code has worked before and note that this is the only path to | |
2070 // java_suspend_self that doesn't put the thread in _thread_blocked | |
2071 // mode. | |
2072 | |
2073 frame_anchor()->make_walkable(this); | |
2074 java_suspend_self(); | |
2075 | |
2076 // We might be here for reasons in addition to the self-suspend request | |
2077 // so check for other async requests. | |
2078 } | |
2079 | |
2080 if (check_asyncs) { | |
2081 check_and_handle_async_exceptions(); | |
2082 } | |
2083 } | |
2084 | |
2085 void JavaThread::send_thread_stop(oop java_throwable) { | |
2086 assert(Thread::current()->is_VM_thread(), "should be in the vm thread"); | |
2087 assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code"); | |
2088 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); | |
2089 | |
2090 // Do not throw asynchronous exceptions against the compiler thread | |
2091 // (the compiler thread should not be a Java thread -- fix in 1.4.2) | |
1410
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1320
diff
changeset
|
2092 |
5056
2f2c6347fce4
comments cleanup/retagging
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4993
diff
changeset
|
2093 // (thomaswue) May we do this? |
1410
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1320
diff
changeset
|
2094 //if (is_Compiler_thread()) return; |
0 | 2095 |
2096 { | |
2097 // Actually throw the Throwable against the target Thread - however | |
2098 // only if there is no thread death exception installed already. | |
1142 | 2099 if (_pending_async_exception == NULL || !_pending_async_exception->is_a(SystemDictionary::ThreadDeath_klass())) { |
0 | 2100 // If the topmost frame is a runtime stub, then we are calling into |
2101 // OptoRuntime from compiled code. Some runtime stubs (new, monitor_exit..) | |
2102 // must deoptimize the caller before continuing, as the compiled exception handler table | |
2103 // may not be valid | |
2104 if (has_last_Java_frame()) { | |
2105 frame f = last_frame(); | |
2106 if (f.is_runtime_frame() || f.is_safepoint_blob_frame()) { | |
2107 // BiasedLocking needs an updated RegisterMap for the revoke monitors pass | |
2108 RegisterMap reg_map(this, UseBiasedLocking); | |
2109 frame compiled_frame = f.sender(®_map); | |
2110 if (compiled_frame.can_be_deoptimized()) { | |
5110
0ebca2e35ca5
more preparations for disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5056
diff
changeset
|
2111 Deoptimization::deoptimize(this, compiled_frame, ®_map, Deoptimization::Reason_constraint); |
0 | 2112 } |
2113 } | |
2114 } | |
2115 | |
2116 // Set async. pending exception in thread. | |
2117 set_pending_async_exception(java_throwable); | |
2118 | |
2119 if (TraceExceptions) { | |
2120 ResourceMark rm; | |
2121 tty->print_cr("Pending Async. exception installed of type: %s", instanceKlass::cast(_pending_async_exception->klass())->external_name()); | |
2122 } | |
2123 // for AbortVMOnException flag | |
2124 NOT_PRODUCT(Exceptions::debug_check_abort(instanceKlass::cast(_pending_async_exception->klass())->external_name())); | |
2125 } | |
2126 } | |
2127 | |
2128 | |
2129 // Interrupt thread so it will wake up from a potential wait() | |
2130 Thread::interrupt(this); | |
2131 } | |
2132 | |
2133 // External suspension mechanism. | |
2134 // | |
2135 // Tell the VM to suspend a thread when ever it knows that it does not hold on | |
2136 // to any VM_locks and it is at a transition | |
2137 // Self-suspension will happen on the transition out of the vm. | |
2138 // Catch "this" coming in from JNIEnv pointers when the thread has been freed | |
2139 // | |
2140 // Guarantees on return: | |
2141 // + Target thread will not execute any new bytecode (that's why we need to | |
2142 // force a safepoint) | |
2143 // + Target thread will not enter any new monitors | |
2144 // | |
2145 void JavaThread::java_suspend() { | |
2146 { MutexLocker mu(Threads_lock); | |
2147 if (!Threads::includes(this) || is_exiting() || this->threadObj() == NULL) { | |
2148 return; | |
2149 } | |
2150 } | |
2151 | |
2152 { MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
2153 if (!is_external_suspend()) { | |
2154 // a racing resume has cancelled us; bail out now | |
2155 return; | |
2156 } | |
2157 | |
2158 // suspend is done | |
2159 uint32_t debug_bits = 0; | |
2160 // Warning: is_ext_suspend_completed() may temporarily drop the | |
2161 // SR_lock to allow the thread to reach a stable thread state if | |
2162 // it is currently in a transient thread state. | |
2163 if (is_ext_suspend_completed(false /* !called_by_wait */, | |
2164 SuspendRetryDelay, &debug_bits) ) { | |
2165 return; | |
2166 } | |
2167 } | |
2168 | |
2169 VM_ForceSafepoint vm_suspend; | |
2170 VMThread::execute(&vm_suspend); | |
2171 } | |
2172 | |
2173 // Part II of external suspension. | |
2174 // A JavaThread self suspends when it detects a pending external suspend | |
2175 // request. This is usually on transitions. It is also done in places | |
2176 // where continuing to the next transition would surprise the caller, | |
2177 // e.g., monitor entry. | |
2178 // | |
2179 // Returns the number of times that the thread self-suspended. | |
2180 // | |
2181 // Note: DO NOT call java_suspend_self() when you just want to block current | |
2182 // thread. java_suspend_self() is the second stage of cooperative | |
2183 // suspension for external suspend requests and should only be used | |
2184 // to complete an external suspend request. | |
2185 // | |
2186 int JavaThread::java_suspend_self() { | |
2187 int ret = 0; | |
2188 | |
2189 // we are in the process of exiting so don't suspend | |
2190 if (is_exiting()) { | |
2191 clear_external_suspend(); | |
2192 return ret; | |
2193 } | |
2194 | |
2195 assert(_anchor.walkable() || | |
2196 (is_Java_thread() && !((JavaThread*)this)->has_last_Java_frame()), | |
2197 "must have walkable stack"); | |
2198 | |
2199 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
2200 | |
979 | 2201 assert(!this->is_ext_suspended(), |
0 | 2202 "a thread trying to self-suspend should not already be suspended"); |
2203 | |
2204 if (this->is_suspend_equivalent()) { | |
2205 // If we are self-suspending as a result of the lifting of a | |
2206 // suspend equivalent condition, then the suspend_equivalent | |
2207 // flag is not cleared until we set the ext_suspended flag so | |
2208 // that wait_for_ext_suspend_completion() returns consistent | |
2209 // results. | |
2210 this->clear_suspend_equivalent(); | |
2211 } | |
2212 | |
2213 // A racing resume may have cancelled us before we grabbed SR_lock | |
2214 // above. Or another external suspend request could be waiting for us | |
2215 // by the time we return from SR_lock()->wait(). The thread | |
2216 // that requested the suspension may already be trying to walk our | |
2217 // stack and if we return now, we can change the stack out from under | |
2218 // it. This would be a "bad thing (TM)" and cause the stack walker | |
2219 // to crash. We stay self-suspended until there are no more pending | |
2220 // external suspend requests. | |
2221 while (is_external_suspend()) { | |
2222 ret++; | |
2223 this->set_ext_suspended(); | |
2224 | |
2225 // _ext_suspended flag is cleared by java_resume() | |
2226 while (is_ext_suspended()) { | |
2227 this->SR_lock()->wait(Mutex::_no_safepoint_check_flag); | |
2228 } | |
2229 } | |
2230 | |
2231 return ret; | |
2232 } | |
2233 | |
2234 #ifdef ASSERT | |
2235 // verify the JavaThread has not yet been published in the Threads::list, and | |
2236 // hence doesn't need protection from concurrent access at this stage | |
2237 void JavaThread::verify_not_published() { | |
2238 if (!Threads_lock->owned_by_self()) { | |
2239 MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag); | |
2240 assert( !Threads::includes(this), | |
2241 "java thread shouldn't have been published yet!"); | |
2242 } | |
2243 else { | |
2244 assert( !Threads::includes(this), | |
2245 "java thread shouldn't have been published yet!"); | |
2246 } | |
2247 } | |
2248 #endif | |
2249 | |
2250 // Slow path when the native==>VM/Java barriers detect a safepoint is in | |
2251 // progress or when _suspend_flags is non-zero. | |
2252 // Current thread needs to self-suspend if there is a suspend request and/or | |
2253 // block if a safepoint is in progress. | |
2254 // Async exception ISN'T checked. | |
2255 // Note only the ThreadInVMfromNative transition can call this function | |
2256 // directly and when thread state is _thread_in_native_trans | |
2257 void JavaThread::check_safepoint_and_suspend_for_native_trans(JavaThread *thread) { | |
2258 assert(thread->thread_state() == _thread_in_native_trans, "wrong state"); | |
2259 | |
2260 JavaThread *curJT = JavaThread::current(); | |
2261 bool do_self_suspend = thread->is_external_suspend(); | |
2262 | |
2263 assert(!curJT->has_last_Java_frame() || curJT->frame_anchor()->walkable(), "Unwalkable stack in native->vm transition"); | |
2264 | |
2265 // If JNIEnv proxies are allowed, don't self-suspend if the target | |
2266 // thread is not the current thread. In older versions of jdbx, jdbx | |
2267 // threads could call into the VM with another thread's JNIEnv so we | |
2268 // can be here operating on behalf of a suspended thread (4432884). | |
2269 if (do_self_suspend && (!AllowJNIEnvProxy || curJT == thread)) { | |
2270 JavaThreadState state = thread->thread_state(); | |
2271 | |
2272 // We mark this thread_blocked state as a suspend-equivalent so | |
2273 // that a caller to is_ext_suspend_completed() won't be confused. | |
2274 // The suspend-equivalent state is cleared by java_suspend_self(). | |
2275 thread->set_suspend_equivalent(); | |
2276 | |
2277 // If the safepoint code sees the _thread_in_native_trans state, it will | |
2278 // wait until the thread changes to other thread state. There is no | |
2279 // guarantee on how soon we can obtain the SR_lock and complete the | |
2280 // self-suspend request. It would be a bad idea to let safepoint wait for | |
2281 // too long. Temporarily change the state to _thread_blocked to | |
2282 // let the VM thread know that this thread is ready for GC. The problem | |
2283 // of changing thread state is that safepoint could happen just after | |
2284 // java_suspend_self() returns after being resumed, and VM thread will | |
2285 // see the _thread_blocked state. We must check for safepoint | |
2286 // after restoring the state and make sure we won't leave while a safepoint | |
2287 // is in progress. | |
2288 thread->set_thread_state(_thread_blocked); | |
2289 thread->java_suspend_self(); | |
2290 thread->set_thread_state(state); | |
2291 // Make sure new state is seen by VM thread | |
2292 if (os::is_MP()) { | |
2293 if (UseMembar) { | |
2294 // Force a fence between the write above and read below | |
2295 OrderAccess::fence(); | |
2296 } else { | |
2297 // Must use this rather than serialization page in particular on Windows | |
2298 InterfaceSupport::serialize_memory(thread); | |
2299 } | |
2300 } | |
2301 } | |
2302 | |
2303 if (SafepointSynchronize::do_call_back()) { | |
2304 // If we are safepointing, then block the caller which may not be | |
2305 // the same as the target thread (see above). | |
2306 SafepointSynchronize::block(curJT); | |
2307 } | |
2308 | |
2309 if (thread->is_deopt_suspend()) { | |
2310 thread->clear_deopt_suspend(); | |
2311 RegisterMap map(thread, false); | |
2312 frame f = thread->last_frame(); | |
2313 while ( f.id() != thread->must_deopt_id() && ! f.is_first_frame()) { | |
2314 f = f.sender(&map); | |
2315 } | |
2316 if (f.id() == thread->must_deopt_id()) { | |
2317 thread->clear_must_deopt_id(); | |
1727
da877bdc9000
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
1689
diff
changeset
|
2318 f.deoptimize(thread); |
0 | 2319 } else { |
2320 fatal("missed deoptimization!"); | |
2321 } | |
2322 } | |
2323 } | |
2324 | |
2325 // Slow path when the native==>VM/Java barriers detect a safepoint is in | |
2326 // progress or when _suspend_flags is non-zero. | |
2327 // Current thread needs to self-suspend if there is a suspend request and/or | |
2328 // block if a safepoint is in progress. | |
2329 // Also check for pending async exception (not including unsafe access error). | |
2330 // Note only the native==>VM/Java barriers can call this function and when | |
2331 // thread state is _thread_in_native_trans. | |
2332 void JavaThread::check_special_condition_for_native_trans(JavaThread *thread) { | |
2333 check_safepoint_and_suspend_for_native_trans(thread); | |
2334 | |
2335 if (thread->has_async_exception()) { | |
2336 // We are in _thread_in_native_trans state, don't handle unsafe | |
2337 // access error since that may block. | |
2338 thread->check_and_handle_async_exceptions(false); | |
2339 } | |
2340 } | |
2341 | |
4873
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2342 // This is a variant of the normal |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2343 // check_special_condition_for_native_trans with slightly different |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2344 // semantics for use by critical native wrappers. It does all the |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2345 // normal checks but also performs the transition back into |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2346 // thread_in_Java state. This is required so that critical natives |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2347 // can potentially block and perform a GC if they are the last thread |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2348 // exiting the GC_locker. |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2349 void JavaThread::check_special_condition_for_native_trans_and_transition(JavaThread *thread) { |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2350 check_special_condition_for_native_trans(thread); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2351 |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2352 // Finish the transition |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2353 thread->set_thread_state(_thread_in_Java); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2354 |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2355 if (thread->do_critical_native_unlock()) { |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2356 ThreadInVMfromJavaNoAsyncException tiv(thread); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2357 GC_locker::unlock_critical(thread); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2358 thread->clear_critical_native_unlock(); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2359 } |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2360 } |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2361 |
0 | 2362 // We need to guarantee the Threads_lock here, since resumes are not |
2363 // allowed during safepoint synchronization | |
2364 // Can only resume from an external suspension | |
2365 void JavaThread::java_resume() { | |
2366 assert_locked_or_safepoint(Threads_lock); | |
2367 | |
2368 // Sanity check: thread is gone, has started exiting or the thread | |
2369 // was not externally suspended. | |
2370 if (!Threads::includes(this) || is_exiting() || !is_external_suspend()) { | |
2371 return; | |
2372 } | |
2373 | |
2374 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
2375 | |
2376 clear_external_suspend(); | |
2377 | |
2378 if (is_ext_suspended()) { | |
2379 clear_ext_suspended(); | |
2380 SR_lock()->notify_all(); | |
2381 } | |
2382 } | |
2383 | |
2384 void JavaThread::create_stack_guard_pages() { | |
2385 if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return; | |
2386 address low_addr = stack_base() - stack_size(); | |
2387 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size(); | |
2388 | |
2389 int allocate = os::allocate_stack_guard_pages(); | |
2390 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); | |
2391 | |
1320
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1290
diff
changeset
|
2392 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) { |
0 | 2393 warning("Attempt to allocate stack guard pages failed."); |
2394 return; | |
2395 } | |
2396 | |
2397 if (os::guard_memory((char *) low_addr, len)) { | |
2398 _stack_guard_state = stack_guard_enabled; | |
2399 } else { | |
2400 warning("Attempt to protect stack guard pages failed."); | |
2401 if (os::uncommit_memory((char *) low_addr, len)) { | |
2402 warning("Attempt to deallocate stack guard pages failed."); | |
2403 } | |
2404 } | |
2405 } | |
2406 | |
2407 void JavaThread::remove_stack_guard_pages() { | |
2408 if (_stack_guard_state == stack_guard_unused) return; | |
2409 address low_addr = stack_base() - stack_size(); | |
2410 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size(); | |
2411 | |
2412 if (os::allocate_stack_guard_pages()) { | |
1320
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1290
diff
changeset
|
2413 if (os::remove_stack_guard_pages((char *) low_addr, len)) { |
0 | 2414 _stack_guard_state = stack_guard_unused; |
2415 } else { | |
2416 warning("Attempt to deallocate stack guard pages failed."); | |
2417 } | |
2418 } else { | |
2419 if (_stack_guard_state == stack_guard_unused) return; | |
2420 if (os::unguard_memory((char *) low_addr, len)) { | |
2421 _stack_guard_state = stack_guard_unused; | |
2422 } else { | |
2423 warning("Attempt to unprotect stack guard pages failed."); | |
2424 } | |
2425 } | |
2426 } | |
2427 | |
2428 void JavaThread::enable_stack_yellow_zone() { | |
2429 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2430 assert(_stack_guard_state != stack_guard_enabled, "already enabled"); | |
2431 | |
2432 // The base notation is from the stacks point of view, growing downward. | |
2433 // We need to adjust it to work correctly with guard_memory() | |
2434 address base = stack_yellow_zone_base() - stack_yellow_zone_size(); | |
2435 | |
2436 guarantee(base < stack_base(),"Error calculating stack yellow zone"); | |
2437 guarantee(base < os::current_stack_pointer(),"Error calculating stack yellow zone"); | |
2438 | |
2439 if (os::guard_memory((char *) base, stack_yellow_zone_size())) { | |
2440 _stack_guard_state = stack_guard_enabled; | |
2441 } else { | |
2442 warning("Attempt to guard stack yellow zone failed."); | |
2443 } | |
2444 enable_register_stack_guard(); | |
2445 } | |
2446 | |
2447 void JavaThread::disable_stack_yellow_zone() { | |
2448 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2449 assert(_stack_guard_state != stack_guard_yellow_disabled, "already disabled"); | |
2450 | |
2451 // Simply return if called for a thread that does not use guard pages. | |
2452 if (_stack_guard_state == stack_guard_unused) return; | |
2453 | |
2454 // The base notation is from the stacks point of view, growing downward. | |
2455 // We need to adjust it to work correctly with guard_memory() | |
2456 address base = stack_yellow_zone_base() - stack_yellow_zone_size(); | |
2457 | |
2458 if (os::unguard_memory((char *)base, stack_yellow_zone_size())) { | |
2459 _stack_guard_state = stack_guard_yellow_disabled; | |
2460 } else { | |
2461 warning("Attempt to unguard stack yellow zone failed."); | |
2462 } | |
2463 disable_register_stack_guard(); | |
2464 } | |
2465 | |
2466 void JavaThread::enable_stack_red_zone() { | |
2467 // The base notation is from the stacks point of view, growing downward. | |
2468 // We need to adjust it to work correctly with guard_memory() | |
2469 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2470 address base = stack_red_zone_base() - stack_red_zone_size(); | |
2471 | |
2472 guarantee(base < stack_base(),"Error calculating stack red zone"); | |
2473 guarantee(base < os::current_stack_pointer(),"Error calculating stack red zone"); | |
2474 | |
2475 if(!os::guard_memory((char *) base, stack_red_zone_size())) { | |
2476 warning("Attempt to guard stack red zone failed."); | |
2477 } | |
2478 } | |
2479 | |
2480 void JavaThread::disable_stack_red_zone() { | |
2481 // The base notation is from the stacks point of view, growing downward. | |
2482 // We need to adjust it to work correctly with guard_memory() | |
2483 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2484 address base = stack_red_zone_base() - stack_red_zone_size(); | |
2485 if (!os::unguard_memory((char *)base, stack_red_zone_size())) { | |
2486 warning("Attempt to unguard stack red zone failed."); | |
2487 } | |
2488 } | |
2489 | |
2490 void JavaThread::frames_do(void f(frame*, const RegisterMap* map)) { | |
2491 // ignore is there is no stack | |
2492 if (!has_last_Java_frame()) return; | |
2493 // traverse the stack frames. Starts from top frame. | |
2494 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
2495 frame* fr = fst.current(); | |
2496 f(fr, fst.register_map()); | |
2497 } | |
2498 } | |
2499 | |
2500 | |
2501 #ifndef PRODUCT | |
2502 // Deoptimization | |
2503 // Function for testing deoptimization | |
2504 void JavaThread::deoptimize() { | |
2505 // BiasedLocking needs an updated RegisterMap for the revoke monitors pass | |
2506 StackFrameStream fst(this, UseBiasedLocking); | |
2507 bool deopt = false; // Dump stack only if a deopt actually happens. | |
2508 bool only_at = strlen(DeoptimizeOnlyAt) > 0; | |
2509 // Iterate over all frames in the thread and deoptimize | |
2510 for(; !fst.is_done(); fst.next()) { | |
2511 if(fst.current()->can_be_deoptimized()) { | |
2512 | |
2513 if (only_at) { | |
2514 // Deoptimize only at particular bcis. DeoptimizeOnlyAt | |
2515 // consists of comma or carriage return separated numbers so | |
2516 // search for the current bci in that string. | |
2517 address pc = fst.current()->pc(); | |
2518 nmethod* nm = (nmethod*) fst.current()->cb(); | |
2519 ScopeDesc* sd = nm->scope_desc_at( pc); | |
2520 char buffer[8]; | |
2521 jio_snprintf(buffer, sizeof(buffer), "%d", sd->bci()); | |
2522 size_t len = strlen(buffer); | |
2523 const char * found = strstr(DeoptimizeOnlyAt, buffer); | |
2524 while (found != NULL) { | |
2525 if ((found[len] == ',' || found[len] == '\n' || found[len] == '\0') && | |
2526 (found == DeoptimizeOnlyAt || found[-1] == ',' || found[-1] == '\n')) { | |
2527 // Check that the bci found is bracketed by terminators. | |
2528 break; | |
2529 } | |
2530 found = strstr(found + 1, buffer); | |
2531 } | |
2532 if (!found) { | |
2533 continue; | |
2534 } | |
2535 } | |
2536 | |
2537 if (DebugDeoptimization && !deopt) { | |
2538 deopt = true; // One-time only print before deopt | |
2539 tty->print_cr("[BEFORE Deoptimization]"); | |
2540 trace_frames(); | |
2541 trace_stack(); | |
2542 } | |
5111
422c979ff392
fixed two cases where DeoptAction was invalid
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5110
diff
changeset
|
2543 Deoptimization::deoptimize(this, *fst.current(), fst.register_map(), Deoptimization::Reason_constraint); |
0 | 2544 } |
2545 } | |
2546 | |
2547 if (DebugDeoptimization && deopt) { | |
2548 tty->print_cr("[AFTER Deoptimization]"); | |
2549 trace_frames(); | |
2550 } | |
2551 } | |
2552 | |
2553 | |
2554 // Make zombies | |
2555 void JavaThread::make_zombies() { | |
2556 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
2557 if (fst.current()->can_be_deoptimized()) { | |
2558 // it is a Java nmethod | |
2559 nmethod* nm = CodeCache::find_nmethod(fst.current()->pc()); | |
2560 nm->make_not_entrant(); | |
2561 } | |
2562 } | |
2563 } | |
2564 #endif // PRODUCT | |
2565 | |
2566 | |
2567 void JavaThread::deoptimized_wrt_marked_nmethods() { | |
2568 if (!has_last_Java_frame()) return; | |
2569 // BiasedLocking needs an updated RegisterMap for the revoke monitors pass | |
2570 StackFrameStream fst(this, UseBiasedLocking); | |
2571 for(; !fst.is_done(); fst.next()) { | |
2572 if (fst.current()->should_be_deoptimized()) { | |
5110
0ebca2e35ca5
more preparations for disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5056
diff
changeset
|
2573 Deoptimization::deoptimize(this, *fst.current(), fst.register_map(), Deoptimization::Reason_constraint); |
0 | 2574 } |
2575 } | |
2576 } | |
2577 | |
2578 | |
2579 // GC support | |
2580 static void frame_gc_epilogue(frame* f, const RegisterMap* map) { f->gc_epilogue(); } | |
2581 | |
2582 void JavaThread::gc_epilogue() { | |
2583 frames_do(frame_gc_epilogue); | |
2584 } | |
2585 | |
2586 | |
2587 static void frame_gc_prologue(frame* f, const RegisterMap* map) { f->gc_prologue(); } | |
2588 | |
2589 void JavaThread::gc_prologue() { | |
2590 frames_do(frame_gc_prologue); | |
2591 } | |
2592 | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2593 // If the caller is a NamedThread, then remember, in the current scope, |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2594 // the given JavaThread in its _processed_thread field. |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2595 class RememberProcessedThread: public StackObj { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2596 NamedThread* _cur_thr; |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2597 public: |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2598 RememberProcessedThread(JavaThread* jthr) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2599 Thread* thread = Thread::current(); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2600 if (thread->is_Named_thread()) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2601 _cur_thr = (NamedThread *)thread; |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2602 _cur_thr->set_processed_thread(jthr); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2603 } else { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2604 _cur_thr = NULL; |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2605 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2606 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2607 |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2608 ~RememberProcessedThread() { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2609 if (_cur_thr) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2610 _cur_thr->set_processed_thread(NULL); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2611 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2612 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2613 }; |
0 | 2614 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2615 void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) { |
1166 | 2616 // Verify that the deferred card marks have been flushed. |
2617 assert(deferred_card_mark().is_empty(), "Should be empty during GC"); | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
997
diff
changeset
|
2618 |
0 | 2619 // The ThreadProfiler oops_do is done from FlatProfiler::oops_do |
2620 // since there may be more than one thread using each ThreadProfiler. | |
2621 | |
2622 // Traverse the GCHandles | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2623 Thread::oops_do(f, cf); |
0 | 2624 |
2625 assert( (!has_last_Java_frame() && java_call_counter() == 0) || | |
2626 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!"); | |
2627 | |
2628 if (has_last_Java_frame()) { | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2629 // Record JavaThread to GC thread |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2630 RememberProcessedThread rpt(this); |
0 | 2631 |
2632 // Traverse the privileged stack | |
2633 if (_privileged_stack_top != NULL) { | |
2634 _privileged_stack_top->oops_do(f); | |
2635 } | |
2636 | |
2637 // traverse the registered growable array | |
2638 if (_array_for_gc != NULL) { | |
2639 for (int index = 0; index < _array_for_gc->length(); index++) { | |
2640 f->do_oop(_array_for_gc->adr_at(index)); | |
2641 } | |
2642 } | |
2643 | |
2644 // Traverse the monitor chunks | |
2645 for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) { | |
2646 chunk->oops_do(f); | |
2647 } | |
2648 | |
2649 // Traverse the execution stack | |
2650 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2651 fst.current()->oops_do(f, cf, fst.register_map()); |
0 | 2652 } |
2653 } | |
2654 | |
2655 // callee_target is never live across a gc point so NULL it here should | |
2656 // it still contain a methdOop. | |
2657 | |
2658 set_callee_target(NULL); | |
2659 | |
2660 assert(vframe_array_head() == NULL, "deopt in progress at a safepoint!"); | |
2661 // If we have deferred set_locals there might be oops waiting to be | |
2662 // written | |
2663 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = deferred_locals(); | |
2664 if (list != NULL) { | |
2665 for (int i = 0; i < list->length(); i++) { | |
2666 list->at(i)->oops_do(f); | |
2667 } | |
2668 } | |
2669 | |
2670 // Traverse instance variables at the end since the GC may be moving things | |
2671 // around using this function | |
2672 f->do_oop((oop*) &_threadObj); | |
2673 f->do_oop((oop*) &_vm_result); | |
2674 f->do_oop((oop*) &_vm_result_2); | |
5747
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
2675 #ifdef GRAAL |
3558
bc95d122df79
added runtime call to supply info upon deoptimization
Lukas Stadler <lukas.stadler@jku.at>
parents:
3555
diff
changeset
|
2676 f->do_oop((oop*) &_graal_deopt_info); |
5747
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
2677 #endif |
0 | 2678 f->do_oop((oop*) &_exception_oop); |
2679 f->do_oop((oop*) &_pending_async_exception); | |
2680 | |
2681 if (jvmti_thread_state() != NULL) { | |
2682 jvmti_thread_state()->oops_do(f); | |
2683 } | |
3696
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2684 |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2685 if (_scanned_nmethod != NULL && cf != NULL) { |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2686 // Safepoints can occur when the sweeper is scanning an nmethod so |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2687 // process it here to make sure it isn't unloaded in the middle of |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2688 // a scan. |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2689 cf->do_code_blob(_scanned_nmethod); |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2690 } |
0 | 2691 } |
2692 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2693 void JavaThread::nmethods_do(CodeBlobClosure* cf) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2694 Thread::nmethods_do(cf); // (super method is a no-op) |
0 | 2695 |
2696 assert( (!has_last_Java_frame() && java_call_counter() == 0) || | |
2697 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!"); | |
2698 | |
2699 if (has_last_Java_frame()) { | |
2700 // Traverse the execution stack | |
2701 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2702 fst.current()->nmethods_do(cf); |
0 | 2703 } |
2704 } | |
2705 } | |
2706 | |
2707 // Printing | |
2708 const char* _get_thread_state_name(JavaThreadState _thread_state) { | |
2709 switch (_thread_state) { | |
2710 case _thread_uninitialized: return "_thread_uninitialized"; | |
2711 case _thread_new: return "_thread_new"; | |
2712 case _thread_new_trans: return "_thread_new_trans"; | |
2713 case _thread_in_native: return "_thread_in_native"; | |
2714 case _thread_in_native_trans: return "_thread_in_native_trans"; | |
2715 case _thread_in_vm: return "_thread_in_vm"; | |
2716 case _thread_in_vm_trans: return "_thread_in_vm_trans"; | |
2717 case _thread_in_Java: return "_thread_in_Java"; | |
2718 case _thread_in_Java_trans: return "_thread_in_Java_trans"; | |
2719 case _thread_blocked: return "_thread_blocked"; | |
2720 case _thread_blocked_trans: return "_thread_blocked_trans"; | |
2721 default: return "unknown thread state"; | |
2722 } | |
2723 } | |
2724 | |
2725 #ifndef PRODUCT | |
2726 void JavaThread::print_thread_state_on(outputStream *st) const { | |
2727 st->print_cr(" JavaThread state: %s", _get_thread_state_name(_thread_state)); | |
2728 }; | |
2729 void JavaThread::print_thread_state() const { | |
2730 print_thread_state_on(tty); | |
2731 }; | |
2732 #endif // PRODUCT | |
2733 | |
2734 // Called by Threads::print() for VM_PrintThreads operation | |
2735 void JavaThread::print_on(outputStream *st) const { | |
2736 st->print("\"%s\" ", get_thread_name()); | |
2737 oop thread_oop = threadObj(); | |
2738 if (thread_oop != NULL && java_lang_Thread::is_daemon(thread_oop)) st->print("daemon "); | |
2739 Thread::print_on(st); | |
2740 // print guess for valid stack memory region (assume 4K pages); helps lock debugging | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
2741 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12)); |
0 | 2742 if (thread_oop != NULL && JDK_Version::is_gte_jdk15x_version()) { |
2743 st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop)); | |
2744 } | |
2745 #ifndef PRODUCT | |
2746 print_thread_state_on(st); | |
2747 _safepoint_state->print_on(st); | |
2748 #endif // PRODUCT | |
2749 } | |
2750 | |
2751 // Called by fatal error handler. The difference between this and | |
2752 // JavaThread::print() is that we can't grab lock or allocate memory. | |
2753 void JavaThread::print_on_error(outputStream* st, char *buf, int buflen) const { | |
2754 st->print("JavaThread \"%s\"", get_thread_name_string(buf, buflen)); | |
2755 oop thread_obj = threadObj(); | |
2756 if (thread_obj != NULL) { | |
2757 if (java_lang_Thread::is_daemon(thread_obj)) st->print(" daemon"); | |
2758 } | |
2759 st->print(" ["); | |
2760 st->print("%s", _get_thread_state_name(_thread_state)); | |
2761 if (osthread()) { | |
2762 st->print(", id=%d", osthread()->thread_id()); | |
2763 } | |
2764 st->print(", stack(" PTR_FORMAT "," PTR_FORMAT ")", | |
2765 _stack_base - _stack_size, _stack_base); | |
2766 st->print("]"); | |
2767 return; | |
2768 } | |
2769 | |
2770 // Verification | |
2771 | |
2772 static void frame_verify(frame* f, const RegisterMap *map) { f->verify(map); } | |
2773 | |
2774 void JavaThread::verify() { | |
2775 // Verify oops in the thread. | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2776 oops_do(&VerifyOopClosure::verify_oop, NULL); |
0 | 2777 |
2778 // Verify the stack frames. | |
2779 frames_do(frame_verify); | |
2780 } | |
2781 | |
2782 // CR 6300358 (sub-CR 2137150) | |
2783 // Most callers of this method assume that it can't return NULL but a | |
2784 // thread may not have a name whilst it is in the process of attaching to | |
2785 // the VM - see CR 6412693, and there are places where a JavaThread can be | |
2786 // seen prior to having it's threadObj set (eg JNI attaching threads and | |
2787 // if vm exit occurs during initialization). These cases can all be accounted | |
2788 // for such that this method never returns NULL. | |
2789 const char* JavaThread::get_thread_name() const { | |
2790 #ifdef ASSERT | |
2791 // early safepoints can hit while current thread does not yet have TLS | |
2792 if (!SafepointSynchronize::is_at_safepoint()) { | |
2793 Thread *cur = Thread::current(); | |
2794 if (!(cur->is_Java_thread() && cur == this)) { | |
2795 // Current JavaThreads are allowed to get their own name without | |
2796 // the Threads_lock. | |
2797 assert_locked_or_safepoint(Threads_lock); | |
2798 } | |
2799 } | |
2800 #endif // ASSERT | |
2801 return get_thread_name_string(); | |
2802 } | |
2803 | |
2804 // Returns a non-NULL representation of this thread's name, or a suitable | |
2805 // descriptive string if there is no set name | |
2806 const char* JavaThread::get_thread_name_string(char* buf, int buflen) const { | |
2807 const char* name_str; | |
2808 oop thread_obj = threadObj(); | |
2809 if (thread_obj != NULL) { | |
2810 typeArrayOop name = java_lang_Thread::name(thread_obj); | |
2811 if (name != NULL) { | |
2812 if (buf == NULL) { | |
2813 name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
2814 } | |
2815 else { | |
2816 name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen); | |
2817 } | |
2818 } | |
4006 | 2819 else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306 |
0 | 2820 name_str = "<no-name - thread is attaching>"; |
2821 } | |
2822 else { | |
2823 name_str = Thread::name(); | |
2824 } | |
2825 } | |
2826 else { | |
2827 name_str = Thread::name(); | |
2828 } | |
2829 assert(name_str != NULL, "unexpected NULL thread name"); | |
2830 return name_str; | |
2831 } | |
2832 | |
2833 | |
2834 const char* JavaThread::get_threadgroup_name() const { | |
2835 debug_only(if (JavaThread::current() != this) assert_locked_or_safepoint(Threads_lock);) | |
2836 oop thread_obj = threadObj(); | |
2837 if (thread_obj != NULL) { | |
2838 oop thread_group = java_lang_Thread::threadGroup(thread_obj); | |
2839 if (thread_group != NULL) { | |
2840 typeArrayOop name = java_lang_ThreadGroup::name(thread_group); | |
2841 // ThreadGroup.name can be null | |
2842 if (name != NULL) { | |
2843 const char* str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
2844 return str; | |
2845 } | |
2846 } | |
2847 } | |
2848 return NULL; | |
2849 } | |
2850 | |
2851 const char* JavaThread::get_parent_name() const { | |
2852 debug_only(if (JavaThread::current() != this) assert_locked_or_safepoint(Threads_lock);) | |
2853 oop thread_obj = threadObj(); | |
2854 if (thread_obj != NULL) { | |
2855 oop thread_group = java_lang_Thread::threadGroup(thread_obj); | |
2856 if (thread_group != NULL) { | |
2857 oop parent = java_lang_ThreadGroup::parent(thread_group); | |
2858 if (parent != NULL) { | |
2859 typeArrayOop name = java_lang_ThreadGroup::name(parent); | |
2860 // ThreadGroup.name can be null | |
2861 if (name != NULL) { | |
2862 const char* str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
2863 return str; | |
2864 } | |
2865 } | |
2866 } | |
2867 } | |
2868 return NULL; | |
2869 } | |
2870 | |
2871 ThreadPriority JavaThread::java_priority() const { | |
2872 oop thr_oop = threadObj(); | |
2873 if (thr_oop == NULL) return NormPriority; // Bootstrapping | |
2874 ThreadPriority priority = java_lang_Thread::priority(thr_oop); | |
2875 assert(MinPriority <= priority && priority <= MaxPriority, "sanity check"); | |
2876 return priority; | |
2877 } | |
2878 | |
2879 void JavaThread::prepare(jobject jni_thread, ThreadPriority prio) { | |
2880 | |
2881 assert(Threads_lock->owner() == Thread::current(), "must have threads lock"); | |
2882 // Link Java Thread object <-> C++ Thread | |
2883 | |
2884 // Get the C++ thread object (an oop) from the JNI handle (a jthread) | |
2885 // and put it into a new Handle. The Handle "thread_oop" can then | |
2886 // be used to pass the C++ thread object to other methods. | |
2887 | |
2888 // Set the Java level thread object (jthread) field of the | |
2889 // new thread (a JavaThread *) to C++ thread object using the | |
2890 // "thread_oop" handle. | |
2891 | |
2892 // Set the thread field (a JavaThread *) of the | |
2893 // oop representing the java_lang_Thread to the new thread (a JavaThread *). | |
2894 | |
2895 Handle thread_oop(Thread::current(), | |
2896 JNIHandles::resolve_non_null(jni_thread)); | |
2897 assert(instanceKlass::cast(thread_oop->klass())->is_linked(), | |
2898 "must be initialized"); | |
2899 set_threadObj(thread_oop()); | |
2900 java_lang_Thread::set_thread(thread_oop(), this); | |
2901 | |
2902 if (prio == NoPriority) { | |
2903 prio = java_lang_Thread::priority(thread_oop()); | |
2904 assert(prio != NoPriority, "A valid priority should be present"); | |
2905 } | |
2906 | |
2907 // Push the Java priority down to the native thread; needs Threads_lock | |
2908 Thread::set_priority(this, prio); | |
2909 | |
2910 // Add the new thread to the Threads list and set it in motion. | |
2911 // We must have threads lock in order to call Threads::add. | |
2912 // It is crucial that we do not block before the thread is | |
2913 // added to the Threads list for if a GC happens, then the java_thread oop | |
2914 // will not be visited by GC. | |
2915 Threads::add(this); | |
2916 } | |
2917 | |
2918 oop JavaThread::current_park_blocker() { | |
2919 // Support for JSR-166 locks | |
2920 oop thread_oop = threadObj(); | |
242 | 2921 if (thread_oop != NULL && |
2922 JDK_Version::current().supports_thread_park_blocker()) { | |
0 | 2923 return java_lang_Thread::park_blocker(thread_oop); |
2924 } | |
2925 return NULL; | |
2926 } | |
2927 | |
2928 | |
2929 void JavaThread::print_stack_on(outputStream* st) { | |
2930 if (!has_last_Java_frame()) return; | |
2931 ResourceMark rm; | |
2932 HandleMark hm; | |
2933 | |
2934 RegisterMap reg_map(this); | |
2935 vframe* start_vf = last_java_vframe(®_map); | |
2936 int count = 0; | |
2937 for (vframe* f = start_vf; f; f = f->sender() ) { | |
2938 if (f->is_java_frame()) { | |
2939 javaVFrame* jvf = javaVFrame::cast(f); | |
2940 java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci()); | |
2941 | |
2942 // Print out lock information | |
2943 if (JavaMonitorsInStackTrace) { | |
2944 jvf->print_lock_info_on(st, count); | |
2945 } | |
2946 } else { | |
2947 // Ignore non-Java frames | |
2948 } | |
2949 | |
2950 // Bail-out case for too deep stacks | |
2951 count++; | |
2952 if (MaxJavaStackTraceDepth == count) return; | |
2953 } | |
2954 } | |
2955 | |
2956 | |
2957 // JVMTI PopFrame support | |
2958 void JavaThread::popframe_preserve_args(ByteSize size_in_bytes, void* start) { | |
2959 assert(_popframe_preserved_args == NULL, "should not wipe out old PopFrame preserved arguments"); | |
2960 if (in_bytes(size_in_bytes) != 0) { | |
6197 | 2961 _popframe_preserved_args = NEW_C_HEAP_ARRAY(char, in_bytes(size_in_bytes), mtThread); |
0 | 2962 _popframe_preserved_args_size = in_bytes(size_in_bytes); |
1603
d93949c5bdcc
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
1584
diff
changeset
|
2963 Copy::conjoint_jbytes(start, _popframe_preserved_args, _popframe_preserved_args_size); |
0 | 2964 } |
2965 } | |
2966 | |
2967 void* JavaThread::popframe_preserved_args() { | |
2968 return _popframe_preserved_args; | |
2969 } | |
2970 | |
2971 ByteSize JavaThread::popframe_preserved_args_size() { | |
2972 return in_ByteSize(_popframe_preserved_args_size); | |
2973 } | |
2974 | |
2975 WordSize JavaThread::popframe_preserved_args_size_in_words() { | |
2976 int sz = in_bytes(popframe_preserved_args_size()); | |
2977 assert(sz % wordSize == 0, "argument size must be multiple of wordSize"); | |
2978 return in_WordSize(sz / wordSize); | |
2979 } | |
2980 | |
2981 void JavaThread::popframe_free_preserved_args() { | |
2982 assert(_popframe_preserved_args != NULL, "should not free PopFrame preserved arguments twice"); | |
6197 | 2983 FREE_C_HEAP_ARRAY(char, (char*) _popframe_preserved_args, mtThread); |
0 | 2984 _popframe_preserved_args = NULL; |
2985 _popframe_preserved_args_size = 0; | |
2986 } | |
2987 | |
2988 #ifndef PRODUCT | |
2989 | |
2990 void JavaThread::trace_frames() { | |
2991 tty->print_cr("[Describe stack]"); | |
2992 int frame_no = 1; | |
2993 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
2994 tty->print(" %d. ", frame_no++); | |
2995 fst.current()->print_value_on(tty,this); | |
2996 tty->cr(); | |
2997 } | |
2998 } | |
2999 | |
3908
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3000 class PrintAndVerifyOopClosure: public OopClosure { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3001 protected: |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3002 template <class T> inline void do_oop_work(T* p) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3003 oop obj = oopDesc::load_decode_heap_oop(p); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3004 if (obj == NULL) return; |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3005 tty->print(INTPTR_FORMAT ": ", p); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3006 if (obj->is_oop_or_null()) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3007 if (obj->is_objArray()) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3008 tty->print_cr("valid objArray: " INTPTR_FORMAT, (oopDesc*) obj); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3009 } else { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3010 obj->print(); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3011 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3012 } else { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3013 tty->print_cr("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3014 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3015 tty->cr(); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3016 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3017 public: |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3018 virtual void do_oop(oop* p) { do_oop_work(p); } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3019 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3020 }; |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3021 |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3022 |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3023 static void oops_print(frame* f, const RegisterMap *map) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3024 PrintAndVerifyOopClosure print; |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3025 f->print_value(); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3026 f->oops_do(&print, NULL, (RegisterMap*)map); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3027 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3028 |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3029 // Print our all the locations that contain oops and whether they are |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3030 // valid or not. This useful when trying to find the oldest frame |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3031 // where an oop has gone bad since the frame walk is from youngest to |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3032 // oldest. |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3033 void JavaThread::trace_oops() { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3034 tty->print_cr("[Trace oops]"); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3035 frames_do(oops_print); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3036 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3037 |
0 | 3038 |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3384
diff
changeset
|
3039 #ifdef ASSERT |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3040 // Print or validate the layout of stack frames |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3041 void JavaThread::print_frame_layout(int depth, bool validate_only) { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3042 ResourceMark rm; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3043 PRESERVE_EXCEPTION_MARK; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3044 FrameValues values; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3045 int frame_no = 0; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3046 for(StackFrameStream fst(this, false); !fst.is_done(); fst.next()) { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3047 fst.current()->describe(values, ++frame_no); |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3048 if (depth == frame_no) break; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3049 } |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3050 if (validate_only) { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3051 values.validate(); |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3052 } else { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3053 tty->print_cr("[Describe stack layout]"); |
4042
b20d64f83668
7090904: JSR 292: JRuby junit test crashes in PSScavengeRootsClosure::do_oop
twisti
parents:
4007
diff
changeset
|
3054 values.print(this); |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3055 } |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3056 } |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3384
diff
changeset
|
3057 #endif |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3058 |
0 | 3059 void JavaThread::trace_stack_from(vframe* start_vf) { |
3060 ResourceMark rm; | |
3061 int vframe_no = 1; | |
3062 for (vframe* f = start_vf; f; f = f->sender() ) { | |
3063 if (f->is_java_frame()) { | |
3064 javaVFrame::cast(f)->print_activation(vframe_no++); | |
3065 } else { | |
3066 f->print(); | |
3067 } | |
3068 if (vframe_no > StackPrintLimit) { | |
3069 tty->print_cr("...<more frames>..."); | |
3070 return; | |
3071 } | |
3072 } | |
3073 } | |
3074 | |
3075 | |
3076 void JavaThread::trace_stack() { | |
3077 if (!has_last_Java_frame()) return; | |
3078 ResourceMark rm; | |
3079 HandleMark hm; | |
3080 RegisterMap reg_map(this); | |
3081 trace_stack_from(last_java_vframe(®_map)); | |
3082 } | |
3083 | |
3084 | |
3085 #endif // PRODUCT | |
3086 | |
3087 | |
3088 javaVFrame* JavaThread::last_java_vframe(RegisterMap *reg_map) { | |
3089 assert(reg_map != NULL, "a map must be given"); | |
3090 frame f = last_frame(); | |
3091 for (vframe* vf = vframe::new_vframe(&f, reg_map, this); vf; vf = vf->sender() ) { | |
3092 if (vf->is_java_frame()) return javaVFrame::cast(vf); | |
3093 } | |
3094 return NULL; | |
3095 } | |
3096 | |
3097 | |
3098 klassOop JavaThread::security_get_caller_class(int depth) { | |
3099 vframeStream vfst(this); | |
3100 vfst.security_get_caller_frame(depth); | |
3101 if (!vfst.at_end()) { | |
3102 return vfst.method()->method_holder(); | |
3103 } | |
3104 return NULL; | |
3105 } | |
3106 | |
3107 static void compiler_thread_entry(JavaThread* thread, TRAPS) { | |
3108 assert(thread->is_Compiler_thread(), "must be compiler thread"); | |
3109 CompileBroker::compiler_thread_loop(); | |
3110 } | |
3111 | |
3112 // Create a CompilerThread | |
3113 CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters) | |
3114 : JavaThread(&compiler_thread_entry) { | |
3115 _log = NULL; | |
3116 _task = NULL; | |
3117 _queue = queue; | |
3118 _counters = counters; | |
3119 | |
3120 #ifndef PRODUCT | |
3121 _ideal_graph_printer = NULL; | |
3122 #endif | |
3123 } | |
3124 | |
3125 // ======= Threads ======== | |
3126 | |
3127 // The Threads class links together all active threads, and provides | |
3128 // operations over all threads. It is protected by its own Mutex | |
3129 // lock, which is also used in other contexts to protect thread | |
3130 // operations from having the thread being operated on from exiting | |
3131 // and going away unexpectedly (e.g., safepoint synchronization) | |
3132 | |
3133 JavaThread* Threads::_thread_list = NULL; | |
3134 int Threads::_number_of_threads = 0; | |
3135 int Threads::_number_of_non_daemon_threads = 0; | |
3136 int Threads::_return_code = 0; | |
3137 size_t JavaThread::_stack_size_at_create = 0; | |
3138 | |
3139 // All JavaThreads | |
3140 #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next()) | |
3141 | |
3142 void os_stream(); | |
3143 | |
3144 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system) | |
3145 void Threads::threads_do(ThreadClosure* tc) { | |
3146 assert_locked_or_safepoint(Threads_lock); | |
3147 // ALL_JAVA_THREADS iterates through all JavaThreads | |
3148 ALL_JAVA_THREADS(p) { | |
3149 tc->do_thread(p); | |
3150 } | |
3151 // Someday we could have a table or list of all non-JavaThreads. | |
3152 // For now, just manually iterate through them. | |
3153 tc->do_thread(VMThread::vm_thread()); | |
3154 Universe::heap()->gc_threads_do(tc); | |
323
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3155 WatcherThread *wt = WatcherThread::watcher_thread(); |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3156 // Strictly speaking, the following NULL check isn't sufficient to make sure |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3157 // the data for WatcherThread is still valid upon being examined. However, |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3158 // considering that WatchThread terminates when the VM is on the way to |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3159 // exit at safepoint, the chance of the above is extremely small. The right |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3160 // way to prevent termination of WatcherThread would be to acquire |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3161 // Terminator_lock, but we can't do that without violating the lock rank |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3162 // checking in some cases. |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3163 if (wt != NULL) |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3164 tc->do_thread(wt); |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3165 |
0 | 3166 // If CompilerThreads ever become non-JavaThreads, add them here |
3167 } | |
3168 | |
3169 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { | |
3170 | |
242 | 3171 extern void JDK_Version_init(); |
3172 | |
0 | 3173 // Check version |
3174 if (!is_supported_jni_version(args->version)) return JNI_EVERSION; | |
3175 | |
3176 // Initialize the output stream module | |
3177 ostream_init(); | |
3178 | |
3179 // Process java launcher properties. | |
3180 Arguments::process_sun_java_launcher_properties(args); | |
3181 | |
3182 // Initialize the os module before using TLS | |
3183 os::init(); | |
3184 | |
3185 // Initialize system properties. | |
3186 Arguments::init_system_properties(); | |
3187 | |
242 | 3188 // So that JDK version can be used as a discrimintor when parsing arguments |
3189 JDK_Version_init(); | |
3190 | |
1864
dfb38ea7da17
6988363: Rebrand vm vendor property settings (jdk7 only)
zgu
parents:
1731
diff
changeset
|
3191 // Update/Initialize System properties after JDK version number is known |
dfb38ea7da17
6988363: Rebrand vm vendor property settings (jdk7 only)
zgu
parents:
1731
diff
changeset
|
3192 Arguments::init_version_specific_system_properties(); |
dfb38ea7da17
6988363: Rebrand vm vendor property settings (jdk7 only)
zgu
parents:
1731
diff
changeset
|
3193 |
0 | 3194 // Parse arguments |
3195 jint parse_result = Arguments::parse(args); | |
3196 if (parse_result != JNI_OK) return parse_result; | |
3197 | |
3198 if (PauseAtStartup) { | |
3199 os::pause(); | |
3200 } | |
3201 | |
4006 | 3202 #ifndef USDT2 |
0 | 3203 HS_DTRACE_PROBE(hotspot, vm__init__begin); |
4006 | 3204 #else /* USDT2 */ |
3205 HOTSPOT_VM_INIT_BEGIN(); | |
3206 #endif /* USDT2 */ | |
0 | 3207 |
3208 // Record VM creation timing statistics | |
3209 TraceVmCreationTime create_vm_timer; | |
3210 create_vm_timer.start(); | |
3211 | |
3212 // Timing (must come after argument parsing) | |
3213 TraceTime timer("Create VM", TraceStartupTime); | |
3214 | |
3215 // Initialize the os module after parsing the args | |
3216 jint os_init_2_result = os::init_2(); | |
3217 if (os_init_2_result != JNI_OK) return os_init_2_result; | |
3218 | |
6197 | 3219 // intialize TLS |
3220 ThreadLocalStorage::init(); | |
3221 | |
3222 // Bootstrap native memory tracking, so it can start recording memory | |
3223 // activities before worker thread is started. This is the first phase | |
3224 // of bootstrapping, VM is currently running in single-thread mode. | |
3225 MemTracker::bootstrap_single_thread(); | |
3226 | |
0 | 3227 // Initialize output stream logging |
3228 ostream_init_log(); | |
3229 | |
3230 // Convert -Xrun to -agentlib: if there is no JVM_OnLoad | |
3231 // Must be before create_vm_init_agents() | |
3232 if (Arguments::init_libraries_at_startup()) { | |
3233 convert_vm_init_libraries_to_agents(); | |
3234 } | |
3235 | |
3236 // Launch -agentlib/-agentpath and converted -Xrun agents | |
3237 if (Arguments::init_agents_at_startup()) { | |
3238 create_vm_init_agents(); | |
3239 } | |
3240 | |
3241 // Initialize Threads state | |
3242 _thread_list = NULL; | |
3243 _number_of_threads = 0; | |
3244 _number_of_non_daemon_threads = 0; | |
3245 | |
3246 // Initialize global data structures and create system classes in heap | |
3247 vm_init_globals(); | |
3248 | |
3249 // Attach the main thread to this os thread | |
3250 JavaThread* main_thread = new JavaThread(); | |
3251 main_thread->set_thread_state(_thread_in_vm); | |
3252 // must do this before set_active_handles and initialize_thread_local_storage | |
3253 // Note: on solaris initialize_thread_local_storage() will (indirectly) | |
3254 // change the stack size recorded here to one based on the java thread | |
3255 // stacksize. This adjusted size is what is used to figure the placement | |
3256 // of the guard pages. | |
3257 main_thread->record_stack_base_and_size(); | |
3258 main_thread->initialize_thread_local_storage(); | |
3259 | |
3260 main_thread->set_active_handles(JNIHandleBlock::allocate_block()); | |
3261 | |
3262 if (!main_thread->set_as_starting_thread()) { | |
3263 vm_shutdown_during_initialization( | |
3264 "Failed necessary internal allocation. Out of swap space"); | |
3265 delete main_thread; | |
3266 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again | |
3267 return JNI_ENOMEM; | |
3268 } | |
3269 | |
3270 // Enable guard page *after* os::create_main_thread(), otherwise it would | |
3271 // crash Linux VM, see notes in os_linux.cpp. | |
3272 main_thread->create_stack_guard_pages(); | |
3273 | |
1878 | 3274 // Initialize Java-Level synchronization subsystem |
3275 ObjectMonitor::Initialize() ; | |
0 | 3276 |
6197 | 3277 // Second phase of bootstrapping, VM is about entering multi-thread mode |
3278 MemTracker::bootstrap_multi_thread(); | |
3279 | |
0 | 3280 // Initialize global modules |
3281 jint status = init_globals(); | |
3282 if (status != JNI_OK) { | |
3283 delete main_thread; | |
3284 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again | |
3285 return status; | |
3286 } | |
3287 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3288 // Should be done after the heap is fully created |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3289 main_thread->cache_global_variables(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3290 |
0 | 3291 HandleMark hm; |
3292 | |
3293 { MutexLocker mu(Threads_lock); | |
3294 Threads::add(main_thread); | |
3295 } | |
3296 | |
3297 // Any JVMTI raw monitors entered in onload will transition into | |
3298 // real raw monitor. VM is setup enough here for raw monitor enter. | |
3299 JvmtiExport::transition_pending_onload_raw_monitors(); | |
3300 | |
3301 if (VerifyBeforeGC && | |
3302 Universe::heap()->total_collections() >= VerifyGCStartAt) { | |
3303 Universe::heap()->prepare_for_verify(); | |
3304 Universe::verify(); // make sure we're starting with a clean slate | |
3305 } | |
3306 | |
6197 | 3307 // Fully start NMT |
3308 MemTracker::start(); | |
3309 | |
0 | 3310 // Create the VMThread |
3311 { TraceTime timer("Start VMThread", TraceStartupTime); | |
3312 VMThread::create(); | |
3313 Thread* vmthread = VMThread::vm_thread(); | |
3314 | |
3315 if (!os::create_thread(vmthread, os::vm_thread)) | |
3316 vm_exit_during_initialization("Cannot create VM thread. Out of system resources."); | |
3317 | |
3318 // Wait for the VM thread to become ready, and VMThread::run to initialize | |
3319 // Monitors can have spurious returns, must always check another state flag | |
3320 { | |
3321 MutexLocker ml(Notify_lock); | |
3322 os::start_thread(vmthread); | |
3323 while (vmthread->active_handles() == NULL) { | |
3324 Notify_lock->wait(); | |
3325 } | |
3326 } | |
3327 } | |
3328 | |
3329 assert (Universe::is_fully_initialized(), "not initialized"); | |
3330 EXCEPTION_MARK; | |
3331 | |
3332 // At this point, the Universe is initialized, but we have not executed | |
3333 // any byte code. Now is a good time (the only time) to dump out the | |
3334 // internal state of the JVM for sharing. | |
3335 | |
3336 if (DumpSharedSpaces) { | |
3337 Universe::heap()->preload_and_dump(CHECK_0); | |
3338 ShouldNotReachHere(); | |
3339 } | |
3340 | |
3341 // Always call even when there are not JVMTI environments yet, since environments | |
3342 // may be attached late and JVMTI must track phases of VM execution | |
3343 JvmtiExport::enter_start_phase(); | |
3344 | |
3345 // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents. | |
3346 JvmtiExport::post_vm_start(); | |
3347 | |
3348 { | |
3349 TraceTime timer("Initialize java.lang classes", TraceStartupTime); | |
3350 | |
3351 if (EagerXrunInit && Arguments::init_libraries_at_startup()) { | |
3352 create_vm_init_libraries(); | |
3353 } | |
3354 | |
3355 if (InitializeJavaLangString) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3356 initialize_class(vmSymbols::java_lang_String(), CHECK_0); |
0 | 3357 } else { |
3358 warning("java.lang.String not initialized"); | |
3359 } | |
3360 | |
18
c7d713375c94
6621621: HashMap front cache should be enabled only with AggressiveOpts
phh
parents:
0
diff
changeset
|
3361 if (AggressiveOpts) { |
192
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3362 { |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3363 // Forcibly initialize java/util/HashMap and mutate the private |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3364 // static final "frontCacheEnabled" field before we start creating instances |
18
c7d713375c94
6621621: HashMap front cache should be enabled only with AggressiveOpts
phh
parents:
0
diff
changeset
|
3365 #ifdef ASSERT |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3366 klassOop tmp_k = SystemDictionary::find(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0); |
192
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3367 assert(tmp_k == NULL, "java/util/HashMap should not be loaded yet"); |
18
c7d713375c94
6621621: HashMap front cache should be enabled only with AggressiveOpts
phh
parents:
0
diff
changeset
|
3368 #endif |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3369 klassOop k_o = SystemDictionary::resolve_or_null(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0); |
192
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3370 KlassHandle k = KlassHandle(THREAD, k_o); |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3371 guarantee(k.not_null(), "Must find java/util/HashMap"); |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3372 instanceKlassHandle ik = instanceKlassHandle(THREAD, k()); |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3373 ik->initialize(CHECK_0); |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3374 fieldDescriptor fd; |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3375 // Possible we might not find this field; if so, don't break |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3376 if (ik->find_local_field(vmSymbols::frontCacheEnabled_name(), vmSymbols::bool_signature(), &fd)) { |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2302
diff
changeset
|
3377 k()->java_mirror()->bool_field_put(fd.offset(), true); |
192
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3378 } |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3379 } |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3380 |
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3381 if (UseStringCache) { |
669
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3382 // Forcibly initialize java/lang/StringValue and mutate the private |
192
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3383 // static final "stringCacheEnabled" field before we start creating instances |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3384 klassOop k_o = SystemDictionary::resolve_or_null(vmSymbols::java_lang_StringValue(), Handle(), Handle(), CHECK_0); |
669
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3385 // Possible that StringValue isn't present: if so, silently don't break |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3386 if (k_o != NULL) { |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3387 KlassHandle k = KlassHandle(THREAD, k_o); |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3388 instanceKlassHandle ik = instanceKlassHandle(THREAD, k()); |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3389 ik->initialize(CHECK_0); |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3390 fieldDescriptor fd; |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3391 // Possible we might not find this field: if so, silently don't break |
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3392 if (ik->find_local_field(vmSymbols::stringCacheEnabled_name(), vmSymbols::bool_signature(), &fd)) { |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2302
diff
changeset
|
3393 k()->java_mirror()->bool_field_put(fd.offset(), true); |
669
eca19a8425b5
6810653: Change String cache class used by Hotspot from String to StringValue
phh
parents:
441
diff
changeset
|
3394 } |
192
6d13fcb3663f
6714404: Add UseStringCache switch to enable String caching under AggressiveOpts
kvn
parents:
62
diff
changeset
|
3395 } |
18
c7d713375c94
6621621: HashMap front cache should be enabled only with AggressiveOpts
phh
parents:
0
diff
changeset
|
3396 } |
c7d713375c94
6621621: HashMap front cache should be enabled only with AggressiveOpts
phh
parents:
0
diff
changeset
|
3397 } |
c7d713375c94
6621621: HashMap front cache should be enabled only with AggressiveOpts
phh
parents:
0
diff
changeset
|
3398 |
0 | 3399 // Initialize java_lang.System (needed before creating the thread) |
3400 if (InitializeJavaLangSystem) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3401 initialize_class(vmSymbols::java_lang_System(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3402 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0); |
0 | 3403 Handle thread_group = create_initial_thread_group(CHECK_0); |
3404 Universe::set_main_thread_group(thread_group()); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3405 initialize_class(vmSymbols::java_lang_Thread(), CHECK_0); |
0 | 3406 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0); |
3407 main_thread->set_threadObj(thread_object); | |
3408 // Set thread status to running since main thread has | |
3409 // been started and running. | |
3410 java_lang_Thread::set_thread_status(thread_object, | |
3411 java_lang_Thread::RUNNABLE); | |
3412 | |
3413 // The VM preresolve methods to these classes. Make sure that get initialized | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3414 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3415 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0); |
0 | 3416 // The VM creates & returns objects of this class. Make sure it's initialized. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3417 initialize_class(vmSymbols::java_lang_Class(), CHECK_0); |
0 | 3418 call_initializeSystemClass(CHECK_0); |
6181 | 3419 |
3420 // get the Java runtime name after java.lang.System is initialized | |
3421 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD)); | |
0 | 3422 } else { |
3423 warning("java.lang.System not initialized"); | |
3424 } | |
3425 | |
3426 // an instance of OutOfMemory exception has been allocated earlier | |
3427 if (InitializeJavaLangExceptionsErrors) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3428 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3429 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3430 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3431 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3432 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3433 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3434 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0); |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3435 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0); |
0 | 3436 } else { |
3437 warning("java.lang.OutOfMemoryError has not been initialized"); | |
3438 warning("java.lang.NullPointerException has not been initialized"); | |
3439 warning("java.lang.ClassCastException has not been initialized"); | |
3440 warning("java.lang.ArrayStoreException has not been initialized"); | |
3441 warning("java.lang.ArithmeticException has not been initialized"); | |
3442 warning("java.lang.StackOverflowError has not been initialized"); | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3443 warning("java.lang.IllegalArgumentException has not been initialized"); |
0 | 3444 } |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
3445 } |
0 | 3446 |
3447 // See : bugid 4211085. | |
3448 // Background : the static initializer of java.lang.Compiler tries to read | |
3449 // property"java.compiler" and read & write property "java.vm.info". | |
3450 // When a security manager is installed through the command line | |
3451 // option "-Djava.security.manager", the above properties are not | |
3452 // readable and the static initializer for java.lang.Compiler fails | |
3453 // resulting in a NoClassDefFoundError. This can happen in any | |
3454 // user code which calls methods in java.lang.Compiler. | |
3455 // Hack : the hack is to pre-load and initialize this class, so that only | |
3456 // system domains are on the stack when the properties are read. | |
3457 // Currently even the AWT code has calls to methods in java.lang.Compiler. | |
3458 // On the classic VM, java.lang.Compiler is loaded very early to load the JIT. | |
3459 // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and | |
3460 // read and write"java.vm.info" in the default policy file. See bugid 4211383 | |
3461 // Once that is done, we should remove this hack. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3462 initialize_class(vmSymbols::java_lang_Compiler(), CHECK_0); |
0 | 3463 |
3464 // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to | |
3465 // the java.vm.info property if no jit gets loaded through java.lang.Compiler (the hotspot | |
3466 // compiler does not get loaded through java.lang.Compiler). "java -version" with the | |
3467 // hotspot vm says "nojit" all the time which is confusing. So, we reset it here. | |
3468 // This should also be taken out as soon as 4211383 gets fixed. | |
3469 reset_vm_info_property(CHECK_0); | |
3470 | |
3471 quicken_jni_functions(); | |
3472 | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3473 // Must be run after init_ft which initializes ft_enabled |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3474 if (TRACE_INITIALIZE() != JNI_OK) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3475 vm_exit_during_initialization("Failed to initialize tracing backend"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3476 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3477 |
0 | 3478 // Set flag that basic initialization has completed. Used by exceptions and various |
3479 // debug stuff, that does not work until all basic classes have been initialized. | |
3480 set_init_completed(); | |
3481 | |
4006 | 3482 #ifndef USDT2 |
0 | 3483 HS_DTRACE_PROBE(hotspot, vm__init__end); |
4006 | 3484 #else /* USDT2 */ |
3485 HOTSPOT_VM_INIT_END(); | |
3486 #endif /* USDT2 */ | |
0 | 3487 |
3488 // record VM initialization completion time | |
3489 Management::record_vm_init_completed(); | |
3490 | |
3491 // Compute system loader. Note that this has to occur after set_init_completed, since | |
3492 // valid exceptions may be thrown in the process. | |
3493 // Note that we do not use CHECK_0 here since we are inside an EXCEPTION_MARK and | |
3494 // set_init_completed has just been called, causing exceptions not to be shortcut | |
3495 // anymore. We call vm_exit_during_initialization directly instead. | |
3496 SystemDictionary::compute_java_system_loader(THREAD); | |
3497 if (HAS_PENDING_EXCEPTION) { | |
3498 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
3499 } | |
3500 | |
3501 #ifndef SERIALGC | |
3502 // Support for ConcurrentMarkSweep. This should be cleaned up | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3503 // and better encapsulated. The ugly nested if test would go away |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3504 // once things are properly refactored. XXX YSR |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3505 if (UseConcMarkSweepGC || UseG1GC) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3506 if (UseConcMarkSweepGC) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3507 ConcurrentMarkSweepThread::makeSurrogateLockerThread(THREAD); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3508 } else { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3509 ConcurrentMarkThread::makeSurrogateLockerThread(THREAD); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3510 } |
0 | 3511 if (HAS_PENDING_EXCEPTION) { |
3512 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
3513 } | |
3514 } | |
3515 #endif // SERIALGC | |
3516 | |
3517 // Always call even when there are not JVMTI environments yet, since environments | |
3518 // may be attached late and JVMTI must track phases of VM execution | |
3519 JvmtiExport::enter_live_phase(); | |
3520 | |
3521 // Signal Dispatcher needs to be started before VMInit event is posted | |
3522 os::signal_init(); | |
3523 | |
3524 // Start Attach Listener if +StartAttachListener or it can't be started lazily | |
3525 if (!DisableAttachMechanism) { | |
3526 if (StartAttachListener || AttachListener::init_at_startup()) { | |
3527 AttachListener::init(); | |
3528 } | |
3529 } | |
3530 | |
3531 // Launch -Xrun agents | |
3532 // Must be done in the JVMTI live phase so that for backward compatibility the JDWP | |
3533 // back-end can launch with -Xdebug -Xrunjdwp. | |
3534 if (!EagerXrunInit && Arguments::init_libraries_at_startup()) { | |
3535 create_vm_init_libraries(); | |
3536 } | |
3537 | |
6002
df4cd4aac5c1
7160924: jvmti: GetPhase returns incorrect phase before VMInit event is issued
rbackman
parents:
5928
diff
changeset
|
3538 // Notify JVMTI agents that VM initialization is complete - nop if no agents. |
df4cd4aac5c1
7160924: jvmti: GetPhase returns incorrect phase before VMInit event is issued
rbackman
parents:
5928
diff
changeset
|
3539 JvmtiExport::post_vm_initialized(); |
df4cd4aac5c1
7160924: jvmti: GetPhase returns incorrect phase before VMInit event is issued
rbackman
parents:
5928
diff
changeset
|
3540 |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
3541 if (!TRACE_START()) { |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
3542 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
3543 } |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
3544 |
3799
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3769
diff
changeset
|
3545 if (CleanChunkPoolAsync) { |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3769
diff
changeset
|
3546 Chunk::start_chunk_pool_cleaner_task(); |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3769
diff
changeset
|
3547 } |
0 | 3548 |
3549 // initialize compiler(s) | |
3550 CompileBroker::compilation_init(); | |
3551 | |
3552 Management::initialize(THREAD); | |
3553 if (HAS_PENDING_EXCEPTION) { | |
3554 // management agent fails to start possibly due to | |
3555 // configuration problem and is responsible for printing | |
3556 // stack trace if appropriate. Simply exit VM. | |
3557 vm_exit(1); | |
3558 } | |
3559 | |
3560 if (Arguments::has_profile()) FlatProfiler::engage(main_thread, true); | |
3561 if (Arguments::has_alloc_profile()) AllocationProfiler::engage(); | |
3562 if (MemProfiling) MemProfiler::engage(); | |
3563 StatSampler::engage(); | |
3564 if (CheckJNICalls) JniPeriodicChecker::engage(); | |
3565 | |
3566 BiasedLocking::init(); | |
3567 | |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3568 if (JDK_Version::current().post_vm_init_hook_enabled()) { |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3569 call_postVMInitHook(THREAD); |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3570 // The Java side of PostVMInitHook.run must deal with all |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3571 // exceptions and provide means of diagnosis. |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3572 if (HAS_PENDING_EXCEPTION) { |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3573 CLEAR_PENDING_EXCEPTION; |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3574 } |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3575 } |
0 | 3576 |
3577 // Start up the WatcherThread if there are any periodic tasks | |
3578 // NOTE: All PeriodicTasks should be registered by now. If they | |
3579 // aren't, late joiners might appear to start slowly (we might | |
3580 // take a while to process their first tick). | |
3581 if (PeriodicTask::num_tasks() > 0) { | |
3582 WatcherThread::start(); | |
3583 } | |
3584 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3585 // Give os specific code one last chance to start |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3586 os::init_3(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3587 |
0 | 3588 create_vm_timer.end(); |
3589 return JNI_OK; | |
3590 } | |
3591 | |
3592 // type for the Agent_OnLoad and JVM_OnLoad entry points | |
3593 extern "C" { | |
3594 typedef jint (JNICALL *OnLoadEntry_t)(JavaVM *, char *, void *); | |
3595 } | |
3596 // Find a command line agent library and return its entry point for | |
3597 // -agentlib: -agentpath: -Xrun | |
3598 // num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array. | |
3599 static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) { | |
3600 OnLoadEntry_t on_load_entry = NULL; | |
3601 void *library = agent->os_lib(); // check if we have looked it up before | |
3602 | |
3603 if (library == NULL) { | |
3604 char buffer[JVM_MAXPATHLEN]; | |
3605 char ebuf[1024]; | |
3606 const char *name = agent->name(); | |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3607 const char *msg = "Could not find agent library "; |
0 | 3608 |
3609 if (agent->is_absolute_path()) { | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3610 library = os::dll_load(name, ebuf, sizeof ebuf); |
0 | 3611 if (library == NULL) { |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3612 const char *sub_msg = " in absolute path, with error: "; |
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3613 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
6197 | 3614 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3615 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
0 | 3616 // If we can't find the agent, exit. |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3617 vm_exit_during_initialization(buf, NULL); |
6197 | 3618 FREE_C_HEAP_ARRAY(char, buf, mtThread); |
0 | 3619 } |
3620 } else { | |
3621 // Try to load the agent from the standard dll directory | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3622 os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), name); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3623 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
0 | 3624 #ifdef KERNEL |
3625 // Download instrument dll | |
3626 if (library == NULL && strcmp(name, "instrument") == 0) { | |
3627 char *props = Arguments::get_kernel_properties(); | |
3628 char *home = Arguments::get_java_home(); | |
3629 const char *fmt = "%s/bin/java %s -Dkernel.background.download=false" | |
3630 " sun.jkernel.DownloadManager -download client_jvm"; | |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3631 size_t length = strlen(props) + strlen(home) + strlen(fmt) + 1; |
6197 | 3632 char *cmd = NEW_C_HEAP_ARRAY(char, length, mtThread); |
0 | 3633 jio_snprintf(cmd, length, fmt, home, props); |
3634 int status = os::fork_and_exec(cmd); | |
3635 FreeHeap(props); | |
3636 if (status == -1) { | |
3637 warning(cmd); | |
3638 vm_exit_during_initialization("fork_and_exec failed: %s", | |
3639 strerror(errno)); | |
3640 } | |
6197 | 3641 FREE_C_HEAP_ARRAY(char, cmd, mtThread); |
0 | 3642 // when this comes back the instrument.dll should be where it belongs. |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3643 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
0 | 3644 } |
3645 #endif // KERNEL | |
3646 if (library == NULL) { // Try the local directory | |
3647 char ns[1] = {0}; | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3648 os::dll_build_name(buffer, sizeof(buffer), ns, name); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3649 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
0 | 3650 if (library == NULL) { |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3651 const char *sub_msg = " on the library path, with error: "; |
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3652 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
6197 | 3653 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3654 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
0 | 3655 // If we can't find the agent, exit. |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3656 vm_exit_during_initialization(buf, NULL); |
6197 | 3657 FREE_C_HEAP_ARRAY(char, buf, mtThread); |
0 | 3658 } |
3659 } | |
3660 } | |
3661 agent->set_os_lib(library); | |
3662 } | |
3663 | |
3664 // Find the OnLoad function. | |
3665 for (size_t symbol_index = 0; symbol_index < num_symbol_entries; symbol_index++) { | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3666 on_load_entry = CAST_TO_FN_PTR(OnLoadEntry_t, os::dll_lookup(library, on_load_symbols[symbol_index])); |
0 | 3667 if (on_load_entry != NULL) break; |
3668 } | |
3669 return on_load_entry; | |
3670 } | |
3671 | |
3672 // Find the JVM_OnLoad entry point | |
3673 static OnLoadEntry_t lookup_jvm_on_load(AgentLibrary* agent) { | |
3674 const char *on_load_symbols[] = JVM_ONLOAD_SYMBOLS; | |
3675 return lookup_on_load(agent, on_load_symbols, sizeof(on_load_symbols) / sizeof(char*)); | |
3676 } | |
3677 | |
3678 // Find the Agent_OnLoad entry point | |
3679 static OnLoadEntry_t lookup_agent_on_load(AgentLibrary* agent) { | |
3680 const char *on_load_symbols[] = AGENT_ONLOAD_SYMBOLS; | |
3681 return lookup_on_load(agent, on_load_symbols, sizeof(on_load_symbols) / sizeof(char*)); | |
3682 } | |
3683 | |
3684 // For backwards compatibility with -Xrun | |
3685 // Convert libraries with no JVM_OnLoad, but which have Agent_OnLoad to be | |
3686 // treated like -agentpath: | |
3687 // Must be called before agent libraries are created | |
3688 void Threads::convert_vm_init_libraries_to_agents() { | |
3689 AgentLibrary* agent; | |
3690 AgentLibrary* next; | |
3691 | |
3692 for (agent = Arguments::libraries(); agent != NULL; agent = next) { | |
3693 next = agent->next(); // cache the next agent now as this agent may get moved off this list | |
3694 OnLoadEntry_t on_load_entry = lookup_jvm_on_load(agent); | |
3695 | |
3696 // If there is an JVM_OnLoad function it will get called later, | |
3697 // otherwise see if there is an Agent_OnLoad | |
3698 if (on_load_entry == NULL) { | |
3699 on_load_entry = lookup_agent_on_load(agent); | |
3700 if (on_load_entry != NULL) { | |
3701 // switch it to the agent list -- so that Agent_OnLoad will be called, | |
3702 // JVM_OnLoad won't be attempted and Agent_OnUnload will | |
3703 Arguments::convert_library_to_agent(agent); | |
3704 } else { | |
3705 vm_exit_during_initialization("Could not find JVM_OnLoad or Agent_OnLoad function in the library", agent->name()); | |
3706 } | |
3707 } | |
3708 } | |
3709 } | |
3710 | |
3711 // Create agents for -agentlib: -agentpath: and converted -Xrun | |
3712 // Invokes Agent_OnLoad | |
3713 // Called very early -- before JavaThreads exist | |
3714 void Threads::create_vm_init_agents() { | |
3715 extern struct JavaVM_ main_vm; | |
3716 AgentLibrary* agent; | |
3717 | |
3718 JvmtiExport::enter_onload_phase(); | |
3719 for (agent = Arguments::agents(); agent != NULL; agent = agent->next()) { | |
3720 OnLoadEntry_t on_load_entry = lookup_agent_on_load(agent); | |
3721 | |
3722 if (on_load_entry != NULL) { | |
3723 // Invoke the Agent_OnLoad function | |
3724 jint err = (*on_load_entry)(&main_vm, agent->options(), NULL); | |
3725 if (err != JNI_OK) { | |
3726 vm_exit_during_initialization("agent library failed to init", agent->name()); | |
3727 } | |
3728 } else { | |
3729 vm_exit_during_initialization("Could not find Agent_OnLoad function in the agent library", agent->name()); | |
3730 } | |
3731 } | |
3732 JvmtiExport::enter_primordial_phase(); | |
3733 } | |
3734 | |
3735 extern "C" { | |
3736 typedef void (JNICALL *Agent_OnUnload_t)(JavaVM *); | |
3737 } | |
3738 | |
3739 void Threads::shutdown_vm_agents() { | |
3740 // Send any Agent_OnUnload notifications | |
3741 const char *on_unload_symbols[] = AGENT_ONUNLOAD_SYMBOLS; | |
3742 extern struct JavaVM_ main_vm; | |
3743 for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) { | |
3744 | |
3745 // Find the Agent_OnUnload function. | |
3746 for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_unload_symbols); symbol_index++) { | |
3747 Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t, | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3748 os::dll_lookup(agent->os_lib(), on_unload_symbols[symbol_index])); |
0 | 3749 |
3750 // Invoke the Agent_OnUnload function | |
3751 if (unload_entry != NULL) { | |
3752 JavaThread* thread = JavaThread::current(); | |
3753 ThreadToNativeFromVM ttn(thread); | |
3754 HandleMark hm(thread); | |
3755 (*unload_entry)(&main_vm); | |
3756 break; | |
3757 } | |
3758 } | |
3759 } | |
3760 } | |
3761 | |
3762 // Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries | |
3763 // Invokes JVM_OnLoad | |
3764 void Threads::create_vm_init_libraries() { | |
3765 extern struct JavaVM_ main_vm; | |
3766 AgentLibrary* agent; | |
3767 | |
3768 for (agent = Arguments::libraries(); agent != NULL; agent = agent->next()) { | |
3769 OnLoadEntry_t on_load_entry = lookup_jvm_on_load(agent); | |
3770 | |
3771 if (on_load_entry != NULL) { | |
3772 // Invoke the JVM_OnLoad function | |
3773 JavaThread* thread = JavaThread::current(); | |
3774 ThreadToNativeFromVM ttn(thread); | |
3775 HandleMark hm(thread); | |
3776 jint err = (*on_load_entry)(&main_vm, agent->options(), NULL); | |
3777 if (err != JNI_OK) { | |
3778 vm_exit_during_initialization("-Xrun library failed to init", agent->name()); | |
3779 } | |
3780 } else { | |
3781 vm_exit_during_initialization("Could not find JVM_OnLoad function in -Xrun library", agent->name()); | |
3782 } | |
3783 } | |
3784 } | |
3785 | |
3786 // Last thread running calls java.lang.Shutdown.shutdown() | |
3787 void JavaThread::invoke_shutdown_hooks() { | |
3788 HandleMark hm(this); | |
3789 | |
3790 // We could get here with a pending exception, if so clear it now. | |
3791 if (this->has_pending_exception()) { | |
3792 this->clear_pending_exception(); | |
3793 } | |
3794 | |
3795 EXCEPTION_MARK; | |
3796 klassOop k = | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3797 SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), |
0 | 3798 THREAD); |
3799 if (k != NULL) { | |
3800 // SystemDictionary::resolve_or_null will return null if there was | |
3801 // an exception. If we cannot load the Shutdown class, just don't | |
3802 // call Shutdown.shutdown() at all. This will mean the shutdown hooks | |
3803 // and finalizers (if runFinalizersOnExit is set) won't be run. | |
3804 // Note that if a shutdown hook was registered or runFinalizersOnExit | |
3805 // was called, the Shutdown class would have already been loaded | |
3806 // (Runtime.addShutdownHook and runFinalizersOnExit will load it). | |
3807 instanceKlassHandle shutdown_klass (THREAD, k); | |
3808 JavaValue result(T_VOID); | |
3809 JavaCalls::call_static(&result, | |
3810 shutdown_klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3811 vmSymbols::shutdown_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3812 vmSymbols::void_method_signature(), |
0 | 3813 THREAD); |
3814 } | |
3815 CLEAR_PENDING_EXCEPTION; | |
3816 } | |
3817 | |
3818 // Threads::destroy_vm() is normally called from jni_DestroyJavaVM() when | |
3819 // the program falls off the end of main(). Another VM exit path is through | |
3820 // vm_exit() when the program calls System.exit() to return a value or when | |
3821 // there is a serious error in VM. The two shutdown paths are not exactly | |
3822 // the same, but they share Shutdown.shutdown() at Java level and before_exit() | |
3823 // and VM_Exit op at VM level. | |
3824 // | |
3825 // Shutdown sequence: | |
6197 | 3826 // + Shutdown native memory tracking if it is on |
0 | 3827 // + Wait until we are the last non-daemon thread to execute |
3828 // <-- every thing is still working at this moment --> | |
3829 // + Call java.lang.Shutdown.shutdown(), which will invoke Java level | |
3830 // shutdown hooks, run finalizers if finalization-on-exit | |
3831 // + Call before_exit(), prepare for VM exit | |
3832 // > run VM level shutdown hooks (they are registered through JVM_OnExit(), | |
3833 // currently the only user of this mechanism is File.deleteOnExit()) | |
3834 // > stop flat profiler, StatSampler, watcher thread, CMS threads, | |
3835 // post thread end and vm death events to JVMTI, | |
3836 // stop signal thread | |
3837 // + Call JavaThread::exit(), it will: | |
3838 // > release JNI handle blocks, remove stack guard pages | |
3839 // > remove this thread from Threads list | |
3840 // <-- no more Java code from this thread after this point --> | |
3841 // + Stop VM thread, it will bring the remaining VM to a safepoint and stop | |
3842 // the compiler threads at safepoint | |
3843 // <-- do not use anything that could get blocked by Safepoint --> | |
3844 // + Disable tracing at JNI/JVM barriers | |
3845 // + Set _vm_exited flag for threads that are still running native code | |
3846 // + Delete this thread | |
3847 // + Call exit_globals() | |
3848 // > deletes tty | |
3849 // > deletes PerfMemory resources | |
3850 // + Return to caller | |
3851 | |
3852 bool Threads::destroy_vm() { | |
3853 JavaThread* thread = JavaThread::current(); | |
3854 | |
3855 // Wait until we are the last non-daemon thread to execute | |
3856 { MutexLocker nu(Threads_lock); | |
3857 while (Threads::number_of_non_daemon_threads() > 1 ) | |
3858 // This wait should make safepoint checks, wait without a timeout, | |
3859 // and wait as a suspend-equivalent condition. | |
3860 // | |
3861 // Note: If the FlatProfiler is running and this thread is waiting | |
3862 // for another non-daemon thread to finish, then the FlatProfiler | |
3863 // is waiting for the external suspend request on this thread to | |
3864 // complete. wait_for_ext_suspend_completion() will eventually | |
3865 // timeout, but that takes time. Making this wait a suspend- | |
3866 // equivalent condition solves that timeout problem. | |
3867 // | |
3868 Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0, | |
3869 Mutex::_as_suspend_equivalent_flag); | |
3870 } | |
3871 | |
6197 | 3872 // Shutdown NMT before exit. Otherwise, |
3873 // it will run into trouble when system destroys static variables. | |
3874 MemTracker::shutdown(MemTracker::NMT_normal); | |
3875 | |
0 | 3876 // Hang forever on exit if we are reporting an error. |
3877 if (ShowMessageBoxOnError && is_error_reported()) { | |
3878 os::infinite_sleep(); | |
3879 } | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2203
diff
changeset
|
3880 os::wait_for_keypress_at_exit(); |
0 | 3881 |
3882 if (JDK_Version::is_jdk12x_version()) { | |
3883 // We are the last thread running, so check if finalizers should be run. | |
3884 // For 1.3 or later this is done in thread->invoke_shutdown_hooks() | |
3885 HandleMark rm(thread); | |
3886 Universe::run_finalizers_on_exit(); | |
3887 } else { | |
3888 // run Java level shutdown hooks | |
3889 thread->invoke_shutdown_hooks(); | |
3890 } | |
3891 | |
3892 before_exit(thread); | |
3893 | |
3894 thread->exit(true); | |
3895 | |
3896 // Stop VM thread. | |
3897 { | |
3898 // 4945125 The vm thread comes to a safepoint during exit. | |
3899 // GC vm_operations can get caught at the safepoint, and the | |
3900 // heap is unparseable if they are caught. Grab the Heap_lock | |
3901 // to prevent this. The GC vm_operations will not be able to | |
3902 // queue until after the vm thread is dead. | |
3769
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3903 // After this point, we'll never emerge out of the safepoint before |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3904 // the VM exits, so concurrent GC threads do not need to be explicitly |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3905 // stopped; they remain inactive until the process exits. |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3906 // Note: some concurrent G1 threads may be running during a safepoint, |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3907 // but these will not be accessing the heap, just some G1-specific side |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3908 // data structures that are not accessed by any other threads but them |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3909 // after this point in a terminal safepoint. |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
3910 |
0 | 3911 MutexLocker ml(Heap_lock); |
3912 | |
3913 VMThread::wait_for_vm_thread_exit(); | |
3914 assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint"); | |
3915 VMThread::destroy(); | |
3916 } | |
3917 | |
3918 // clean up ideal graph printers | |
3919 #if defined(COMPILER2) && !defined(PRODUCT) | |
3920 IdealGraphPrinter::clean_up(); | |
3921 #endif | |
3922 | |
3923 // Now, all Java threads are gone except daemon threads. Daemon threads | |
3924 // running Java code or in VM are stopped by the Safepoint. However, | |
3925 // daemon threads executing native code are still running. But they | |
3926 // will be stopped at native=>Java/VM barriers. Note that we can't | |
3927 // simply kill or suspend them, as it is inherently deadlock-prone. | |
3928 | |
3929 #ifndef PRODUCT | |
3930 // disable function tracing at JNI/JVM barriers | |
3931 TraceJNICalls = false; | |
3932 TraceJVMCalls = false; | |
3933 TraceRuntimeCalls = false; | |
3934 #endif | |
3935 | |
3936 VM_Exit::set_vm_exited(); | |
3937 | |
3938 notify_vm_shutdown(); | |
3939 | |
3940 delete thread; | |
3941 | |
3942 // exit_globals() will delete tty | |
3943 exit_globals(); | |
3944 | |
3945 return true; | |
3946 } | |
3947 | |
3948 | |
3949 jboolean Threads::is_supported_jni_version_including_1_1(jint version) { | |
3950 if (version == JNI_VERSION_1_1) return JNI_TRUE; | |
3951 return is_supported_jni_version(version); | |
3952 } | |
3953 | |
3954 | |
3955 jboolean Threads::is_supported_jni_version(jint version) { | |
3956 if (version == JNI_VERSION_1_2) return JNI_TRUE; | |
3957 if (version == JNI_VERSION_1_4) return JNI_TRUE; | |
3958 if (version == JNI_VERSION_1_6) return JNI_TRUE; | |
3959 return JNI_FALSE; | |
3960 } | |
3961 | |
3962 | |
3963 void Threads::add(JavaThread* p, bool force_daemon) { | |
3964 // The threads lock must be owned at this point | |
3965 assert_locked_or_safepoint(Threads_lock); | |
1842
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
3966 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
3967 // See the comment for this method in thread.hpp for its purpose and |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
3968 // why it is called here. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
3969 p->initialize_queues(); |
0 | 3970 p->set_next(_thread_list); |
3971 _thread_list = p; | |
3972 _number_of_threads++; | |
3973 oop threadObj = p->threadObj(); | |
3974 bool daemon = true; | |
3975 // Bootstrapping problem: threadObj can be null for initial | |
3976 // JavaThread (or for threads attached via JNI) | |
3977 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { | |
3978 _number_of_non_daemon_threads++; | |
3979 daemon = false; | |
3980 } | |
3981 | |
6197 | 3982 p->set_safepoint_visible(true); |
3983 | |
0 | 3984 ThreadService::add_thread(p, daemon); |
3985 | |
3986 // Possible GC point. | |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4800
diff
changeset
|
3987 Events::log(p, "Thread added: " INTPTR_FORMAT, p); |
0 | 3988 } |
3989 | |
3990 void Threads::remove(JavaThread* p) { | |
3991 // Extra scope needed for Thread_lock, so we can check | |
3992 // that we do not remove thread without safepoint code notice | |
3993 { MutexLocker ml(Threads_lock); | |
3994 | |
3995 assert(includes(p), "p must be present"); | |
3996 | |
3997 JavaThread* current = _thread_list; | |
3998 JavaThread* prev = NULL; | |
3999 | |
4000 while (current != p) { | |
4001 prev = current; | |
4002 current = current->next(); | |
4003 } | |
4004 | |
4005 if (prev) { | |
4006 prev->set_next(current->next()); | |
4007 } else { | |
4008 _thread_list = p->next(); | |
4009 } | |
4010 _number_of_threads--; | |
4011 oop threadObj = p->threadObj(); | |
4012 bool daemon = true; | |
4013 if (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj)) { | |
4014 _number_of_non_daemon_threads--; | |
4015 daemon = false; | |
4016 | |
4017 // Only one thread left, do a notify on the Threads_lock so a thread waiting | |
4018 // on destroy_vm will wake up. | |
4019 if (number_of_non_daemon_threads() == 1) | |
4020 Threads_lock->notify_all(); | |
4021 } | |
4022 ThreadService::remove_thread(p, daemon); | |
4023 | |
4024 // Make sure that safepoint code disregard this thread. This is needed since | |
4025 // the thread might mess around with locks after this point. This can cause it | |
4026 // to do callbacks into the safepoint code. However, the safepoint code is not aware | |
4027 // of this thread since it is removed from the queue. | |
4028 p->set_terminated_value(); | |
6197 | 4029 |
4030 // Now, this thread is not visible to safepoint | |
4031 p->set_safepoint_visible(false); | |
4032 | |
0 | 4033 } // unlock Threads_lock |
4034 | |
4035 // Since Events::log uses a lock, we grab it outside the Threads_lock | |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4800
diff
changeset
|
4036 Events::log(p, "Thread exited: " INTPTR_FORMAT, p); |
0 | 4037 } |
4038 | |
4039 // Threads_lock must be held when this is called (or must be called during a safepoint) | |
4040 bool Threads::includes(JavaThread* p) { | |
4041 assert(Threads_lock->is_locked(), "sanity check"); | |
4042 ALL_JAVA_THREADS(q) { | |
4043 if (q == p ) { | |
4044 return true; | |
4045 } | |
4046 } | |
4047 return false; | |
4048 } | |
4049 | |
4050 // Operations on the Threads list for GC. These are not explicitly locked, | |
4051 // but the garbage collector must provide a safe context for them to run. | |
4052 // In particular, these things should never be called when the Threads_lock | |
4053 // is held by some other thread. (Note: the Safepoint abstraction also | |
4054 // uses the Threads_lock to gurantee this property. It also makes sure that | |
4055 // all threads gets blocked when exiting or starting). | |
4056 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4057 void Threads::oops_do(OopClosure* f, CodeBlobClosure* cf) { |
0 | 4058 ALL_JAVA_THREADS(p) { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4059 p->oops_do(f, cf); |
0 | 4060 } |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4061 VMThread::vm_thread()->oops_do(f, cf); |
0 | 4062 } |
4063 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4064 void Threads::possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf) { |
0 | 4065 // Introduce a mechanism allowing parallel threads to claim threads as |
4066 // root groups. Overhead should be small enough to use all the time, | |
4067 // even in sequential code. | |
4068 SharedHeap* sh = SharedHeap::heap(); | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4069 // Cannot yet substitute active_workers for n_par_threads |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4070 // because of G1CollectedHeap::verify() use of |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4071 // SharedHeap::process_strong_roots(). n_par_threads == 0 will |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4072 // turn off parallelism in process_strong_roots while active_workers |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4073 // is being used for parallelism elsewhere. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4074 bool is_par = sh->n_par_threads() > 0; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4075 assert(!is_par || |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4076 (SharedHeap::heap()->n_par_threads() == |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4077 SharedHeap::heap()->workers()->active_workers()), "Mismatch"); |
0 | 4078 int cp = SharedHeap::heap()->strong_roots_parity(); |
4079 ALL_JAVA_THREADS(p) { | |
4080 if (p->claim_oops_do(is_par, cp)) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4081 p->oops_do(f, cf); |
0 | 4082 } |
4083 } | |
4084 VMThread* vmt = VMThread::vm_thread(); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
4085 if (vmt->claim_oops_do(is_par, cp)) { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4086 vmt->oops_do(f, cf); |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
4087 } |
0 | 4088 } |
4089 | |
4090 #ifndef SERIALGC | |
4091 // Used by ParallelScavenge | |
4092 void Threads::create_thread_roots_tasks(GCTaskQueue* q) { | |
4093 ALL_JAVA_THREADS(p) { | |
4094 q->enqueue(new ThreadRootsTask(p)); | |
4095 } | |
4096 q->enqueue(new ThreadRootsTask(VMThread::vm_thread())); | |
4097 } | |
4098 | |
4099 // Used by Parallel Old | |
4100 void Threads::create_thread_roots_marking_tasks(GCTaskQueue* q) { | |
4101 ALL_JAVA_THREADS(p) { | |
4102 q->enqueue(new ThreadRootsMarkingTask(p)); | |
4103 } | |
4104 q->enqueue(new ThreadRootsMarkingTask(VMThread::vm_thread())); | |
4105 } | |
4106 #endif // SERIALGC | |
4107 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4108 void Threads::nmethods_do(CodeBlobClosure* cf) { |
0 | 4109 ALL_JAVA_THREADS(p) { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4110 p->nmethods_do(cf); |
0 | 4111 } |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4112 VMThread::vm_thread()->nmethods_do(cf); |
0 | 4113 } |
4114 | |
4115 void Threads::gc_epilogue() { | |
4116 ALL_JAVA_THREADS(p) { | |
4117 p->gc_epilogue(); | |
4118 } | |
4119 } | |
4120 | |
4121 void Threads::gc_prologue() { | |
4122 ALL_JAVA_THREADS(p) { | |
4123 p->gc_prologue(); | |
4124 } | |
4125 } | |
4126 | |
4127 void Threads::deoptimized_wrt_marked_nmethods() { | |
4128 ALL_JAVA_THREADS(p) { | |
4129 p->deoptimized_wrt_marked_nmethods(); | |
4130 } | |
4131 } | |
4132 | |
4133 | |
4134 // Get count Java threads that are waiting to enter the specified monitor. | |
4135 GrowableArray<JavaThread*>* Threads::get_pending_threads(int count, | |
4136 address monitor, bool doLock) { | |
4137 assert(doLock || SafepointSynchronize::is_at_safepoint(), | |
4138 "must grab Threads_lock or be at safepoint"); | |
4139 GrowableArray<JavaThread*>* result = new GrowableArray<JavaThread*>(count); | |
4140 | |
4141 int i = 0; | |
4142 { | |
4143 MutexLockerEx ml(doLock ? Threads_lock : NULL); | |
4144 ALL_JAVA_THREADS(p) { | |
4145 if (p->is_Compiler_thread()) continue; | |
4146 | |
4147 address pending = (address)p->current_pending_monitor(); | |
4148 if (pending == monitor) { // found a match | |
4149 if (i < count) result->append(p); // save the first count matches | |
4150 i++; | |
4151 } | |
4152 } | |
4153 } | |
4154 return result; | |
4155 } | |
4156 | |
4157 | |
4158 JavaThread *Threads::owning_thread_from_monitor_owner(address owner, bool doLock) { | |
4159 assert(doLock || | |
4160 Threads_lock->owned_by_self() || | |
4161 SafepointSynchronize::is_at_safepoint(), | |
4162 "must grab Threads_lock or be at safepoint"); | |
4163 | |
4164 // NULL owner means not locked so we can skip the search | |
4165 if (owner == NULL) return NULL; | |
4166 | |
4167 { | |
4168 MutexLockerEx ml(doLock ? Threads_lock : NULL); | |
4169 ALL_JAVA_THREADS(p) { | |
4170 // first, see if owner is the address of a Java thread | |
4171 if (owner == (address)p) return p; | |
4172 } | |
4173 } | |
4174 assert(UseHeavyMonitors == false, "Did not find owning Java thread with UseHeavyMonitors enabled"); | |
4175 if (UseHeavyMonitors) return NULL; | |
4176 | |
4177 // | |
4178 // If we didn't find a matching Java thread and we didn't force use of | |
4179 // heavyweight monitors, then the owner is the stack address of the | |
4180 // Lock Word in the owning Java thread's stack. | |
4181 // | |
4182 JavaThread* the_owner = NULL; | |
4183 { | |
4184 MutexLockerEx ml(doLock ? Threads_lock : NULL); | |
4185 ALL_JAVA_THREADS(q) { | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
4186 if (q->is_lock_owned(owner)) { |
0 | 4187 the_owner = q; |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
4188 break; |
0 | 4189 } |
4190 } | |
4191 } | |
4192 assert(the_owner != NULL, "Did not find owning Java thread for lock word address"); | |
4193 return the_owner; | |
4194 } | |
4195 | |
4196 // Threads::print_on() is called at safepoint by VM_PrintThreads operation. | |
4197 void Threads::print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks) { | |
4198 char buf[32]; | |
4199 st->print_cr(os::local_time_string(buf, sizeof(buf))); | |
4200 | |
4201 st->print_cr("Full thread dump %s (%s %s):", | |
4202 Abstract_VM_Version::vm_name(), | |
4203 Abstract_VM_Version::vm_release(), | |
4204 Abstract_VM_Version::vm_info_string() | |
4205 ); | |
4206 st->cr(); | |
4207 | |
4208 #ifndef SERIALGC | |
4209 // Dump concurrent locks | |
4210 ConcurrentLocksDump concurrent_locks; | |
4211 if (print_concurrent_locks) { | |
4212 concurrent_locks.dump_at_safepoint(); | |
4213 } | |
4214 #endif // SERIALGC | |
4215 | |
4216 ALL_JAVA_THREADS(p) { | |
4217 ResourceMark rm; | |
4218 p->print_on(st); | |
4219 if (print_stacks) { | |
4220 if (internal_format) { | |
4221 p->trace_stack(); | |
4222 } else { | |
4223 p->print_stack_on(st); | |
4224 } | |
4225 } | |
4226 st->cr(); | |
4227 #ifndef SERIALGC | |
4228 if (print_concurrent_locks) { | |
4229 concurrent_locks.print_locks_on(p, st); | |
4230 } | |
4231 #endif // SERIALGC | |
4232 } | |
4233 | |
4234 VMThread::vm_thread()->print_on(st); | |
4235 st->cr(); | |
4236 Universe::heap()->print_gc_threads_on(st); | |
4237 WatcherThread* wt = WatcherThread::watcher_thread(); | |
4238 if (wt != NULL) wt->print_on(st); | |
4239 st->cr(); | |
4240 CompileBroker::print_compiler_threads_on(st); | |
4241 st->flush(); | |
4242 } | |
4243 | |
4244 // Threads::print_on_error() is called by fatal error handler. It's possible | |
4245 // that VM is not at safepoint and/or current thread is inside signal handler. | |
4246 // Don't print stack trace, as the stack may not be walkable. Don't allocate | |
4247 // memory (even in resource area), it might deadlock the error handler. | |
4248 void Threads::print_on_error(outputStream* st, Thread* current, char* buf, int buflen) { | |
4249 bool found_current = false; | |
4250 st->print_cr("Java Threads: ( => current thread )"); | |
4251 ALL_JAVA_THREADS(thread) { | |
4252 bool is_current = (current == thread); | |
4253 found_current = found_current || is_current; | |
4254 | |
4255 st->print("%s", is_current ? "=>" : " "); | |
4256 | |
4257 st->print(PTR_FORMAT, thread); | |
4258 st->print(" "); | |
4259 thread->print_on_error(st, buf, buflen); | |
4260 st->cr(); | |
4261 } | |
4262 st->cr(); | |
4263 | |
4264 st->print_cr("Other Threads:"); | |
4265 if (VMThread::vm_thread()) { | |
4266 bool is_current = (current == VMThread::vm_thread()); | |
4267 found_current = found_current || is_current; | |
4268 st->print("%s", current == VMThread::vm_thread() ? "=>" : " "); | |
4269 | |
4270 st->print(PTR_FORMAT, VMThread::vm_thread()); | |
4271 st->print(" "); | |
4272 VMThread::vm_thread()->print_on_error(st, buf, buflen); | |
4273 st->cr(); | |
4274 } | |
4275 WatcherThread* wt = WatcherThread::watcher_thread(); | |
4276 if (wt != NULL) { | |
4277 bool is_current = (current == wt); | |
4278 found_current = found_current || is_current; | |
4279 st->print("%s", is_current ? "=>" : " "); | |
4280 | |
4281 st->print(PTR_FORMAT, wt); | |
4282 st->print(" "); | |
4283 wt->print_on_error(st, buf, buflen); | |
4284 st->cr(); | |
4285 } | |
4286 if (!found_current) { | |
4287 st->cr(); | |
4288 st->print("=>" PTR_FORMAT " (exited) ", current); | |
4289 current->print_on_error(st, buf, buflen); | |
4290 st->cr(); | |
4291 } | |
4292 } | |
4293 | |
1878 | 4294 // Internal SpinLock and Mutex |
4295 // Based on ParkEvent | |
4296 | |
4297 // Ad-hoc mutual exclusion primitives: SpinLock and Mux | |
0 | 4298 // |
1878 | 4299 // We employ SpinLocks _only for low-contention, fixed-length |
4300 // short-duration critical sections where we're concerned | |
4301 // about native mutex_t or HotSpot Mutex:: latency. | |
4302 // The mux construct provides a spin-then-block mutual exclusion | |
4303 // mechanism. | |
4304 // | |
4305 // Testing has shown that contention on the ListLock guarding gFreeList | |
4306 // is common. If we implement ListLock as a simple SpinLock it's common | |
4307 // for the JVM to devolve to yielding with little progress. This is true | |
4308 // despite the fact that the critical sections protected by ListLock are | |
4309 // extremely short. | |
0 | 4310 // |
1878 | 4311 // TODO-FIXME: ListLock should be of type SpinLock. |
4312 // We should make this a 1st-class type, integrated into the lock | |
4313 // hierarchy as leaf-locks. Critically, the SpinLock structure | |
4314 // should have sufficient padding to avoid false-sharing and excessive | |
4315 // cache-coherency traffic. | |
4316 | |
4317 | |
4318 typedef volatile int SpinLockT ; | |
4319 | |
4320 void Thread::SpinAcquire (volatile int * adr, const char * LockName) { | |
4321 if (Atomic::cmpxchg (1, adr, 0) == 0) { | |
4322 return ; // normal fast-path return | |
4323 } | |
4324 | |
4325 // Slow-path : We've encountered contention -- Spin/Yield/Block strategy. | |
4326 TEVENT (SpinAcquire - ctx) ; | |
4327 int ctr = 0 ; | |
4328 int Yields = 0 ; | |
0 | 4329 for (;;) { |
1878 | 4330 while (*adr != 0) { |
4331 ++ctr ; | |
4332 if ((ctr & 0xFFF) == 0 || !os::is_MP()) { | |
4333 if (Yields > 5) { | |
4334 // Consider using a simple NakedSleep() instead. | |
4335 // Then SpinAcquire could be called by non-JVM threads | |
4336 Thread::current()->_ParkEvent->park(1) ; | |
4337 } else { | |
4338 os::NakedYield() ; | |
4339 ++Yields ; | |
4340 } | |
4341 } else { | |
4342 SpinPause() ; | |
0 | 4343 } |
1878 | 4344 } |
4345 if (Atomic::cmpxchg (1, adr, 0) == 0) return ; | |
0 | 4346 } |
4347 } | |
4348 | |
1878 | 4349 void Thread::SpinRelease (volatile int * adr) { |
4350 assert (*adr != 0, "invariant") ; | |
4351 OrderAccess::fence() ; // guarantee at least release consistency. | |
4352 // Roach-motel semantics. | |
4353 // It's safe if subsequent LDs and STs float "up" into the critical section, | |
4354 // but prior LDs and STs within the critical section can't be allowed | |
4355 // to reorder or float past the ST that releases the lock. | |
4356 *adr = 0 ; | |
0 | 4357 } |
4358 | |
1878 | 4359 // muxAcquire and muxRelease: |
4360 // | |
4361 // * muxAcquire and muxRelease support a single-word lock-word construct. | |
4362 // The LSB of the word is set IFF the lock is held. | |
4363 // The remainder of the word points to the head of a singly-linked list | |
4364 // of threads blocked on the lock. | |
4365 // | |
4366 // * The current implementation of muxAcquire-muxRelease uses its own | |
4367 // dedicated Thread._MuxEvent instance. If we're interested in | |
4368 // minimizing the peak number of extant ParkEvent instances then | |
4369 // we could eliminate _MuxEvent and "borrow" _ParkEvent as long | |
4370 // as certain invariants were satisfied. Specifically, care would need | |
4371 // to be taken with regards to consuming unpark() "permits". | |
4372 // A safe rule of thumb is that a thread would never call muxAcquire() | |
4373 // if it's enqueued (cxq, EntryList, WaitList, etc) and will subsequently | |
4374 // park(). Otherwise the _ParkEvent park() operation in muxAcquire() could | |
4375 // consume an unpark() permit intended for monitorenter, for instance. | |
4376 // One way around this would be to widen the restricted-range semaphore | |
4377 // implemented in park(). Another alternative would be to provide | |
4378 // multiple instances of the PlatformEvent() for each thread. One | |
4379 // instance would be dedicated to muxAcquire-muxRelease, for instance. | |
4380 // | |
4381 // * Usage: | |
4382 // -- Only as leaf locks | |
4383 // -- for short-term locking only as muxAcquire does not perform | |
4384 // thread state transitions. | |
4385 // | |
4386 // Alternatives: | |
4387 // * We could implement muxAcquire and muxRelease with MCS or CLH locks | |
4388 // but with parking or spin-then-park instead of pure spinning. | |
4389 // * Use Taura-Oyama-Yonenzawa locks. | |
4390 // * It's possible to construct a 1-0 lock if we encode the lockword as | |
4391 // (List,LockByte). Acquire will CAS the full lockword while Release | |
4392 // will STB 0 into the LockByte. The 1-0 scheme admits stranding, so | |
4393 // acquiring threads use timers (ParkTimed) to detect and recover from | |
4394 // the stranding window. Thread/Node structures must be aligned on 256-byte | |
4395 // boundaries by using placement-new. | |
4396 // * Augment MCS with advisory back-link fields maintained with CAS(). | |
4397 // Pictorially: LockWord -> T1 <-> T2 <-> T3 <-> ... <-> Tn <-> Owner. | |
4398 // The validity of the backlinks must be ratified before we trust the value. | |
4399 // If the backlinks are invalid the exiting thread must back-track through the | |
4400 // the forward links, which are always trustworthy. | |
4401 // * Add a successor indication. The LockWord is currently encoded as | |
4402 // (List, LOCKBIT:1). We could also add a SUCCBIT or an explicit _succ variable | |
4403 // to provide the usual futile-wakeup optimization. | |
4404 // See RTStt for details. | |
4405 // * Consider schedctl.sc_nopreempt to cover the critical section. | |
4406 // | |
4407 | |
4408 | |
4409 typedef volatile intptr_t MutexT ; // Mux Lock-word | |
4410 enum MuxBits { LOCKBIT = 1 } ; | |
4411 | |
4412 void Thread::muxAcquire (volatile intptr_t * Lock, const char * LockName) { | |
4413 intptr_t w = Atomic::cmpxchg_ptr (LOCKBIT, Lock, 0) ; | |
4414 if (w == 0) return ; | |
4415 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4416 return ; | |
4417 } | |
4418 | |
4419 TEVENT (muxAcquire - Contention) ; | |
4420 ParkEvent * const Self = Thread::current()->_MuxEvent ; | |
4421 assert ((intptr_t(Self) & LOCKBIT) == 0, "invariant") ; | |
0 | 4422 for (;;) { |
1878 | 4423 int its = (os::is_MP() ? 100 : 0) + 1 ; |
4424 | |
4425 // Optional spin phase: spin-then-park strategy | |
4426 while (--its >= 0) { | |
4427 w = *Lock ; | |
4428 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4429 return ; | |
4430 } | |
4431 } | |
4432 | |
4433 Self->reset() ; | |
4434 Self->OnList = intptr_t(Lock) ; | |
4435 // The following fence() isn't _strictly necessary as the subsequent | |
4436 // CAS() both serializes execution and ratifies the fetched *Lock value. | |
4437 OrderAccess::fence(); | |
4438 for (;;) { | |
4439 w = *Lock ; | |
4440 if ((w & LOCKBIT) == 0) { | |
4441 if (Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4442 Self->OnList = 0 ; // hygiene - allows stronger asserts | |
4443 return ; | |
4444 } | |
4445 continue ; // Interference -- *Lock changed -- Just retry | |
0 | 4446 } |
1878 | 4447 assert (w & LOCKBIT, "invariant") ; |
4448 Self->ListNext = (ParkEvent *) (w & ~LOCKBIT ); | |
4449 if (Atomic::cmpxchg_ptr (intptr_t(Self)|LOCKBIT, Lock, w) == w) break ; | |
4450 } | |
4451 | |
4452 while (Self->OnList != 0) { | |
4453 Self->park() ; | |
4454 } | |
0 | 4455 } |
4456 } | |
4457 | |
1878 | 4458 void Thread::muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) { |
4459 intptr_t w = Atomic::cmpxchg_ptr (LOCKBIT, Lock, 0) ; | |
4460 if (w == 0) return ; | |
4461 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4462 return ; | |
4463 } | |
4464 | |
4465 TEVENT (muxAcquire - Contention) ; | |
4466 ParkEvent * ReleaseAfter = NULL ; | |
4467 if (ev == NULL) { | |
4468 ev = ReleaseAfter = ParkEvent::Allocate (NULL) ; | |
4469 } | |
4470 assert ((intptr_t(ev) & LOCKBIT) == 0, "invariant") ; | |
4471 for (;;) { | |
4472 guarantee (ev->OnList == 0, "invariant") ; | |
4473 int its = (os::is_MP() ? 100 : 0) + 1 ; | |
4474 | |
4475 // Optional spin phase: spin-then-park strategy | |
4476 while (--its >= 0) { | |
4477 w = *Lock ; | |
4478 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4479 if (ReleaseAfter != NULL) { | |
4480 ParkEvent::Release (ReleaseAfter) ; | |
4481 } | |
4482 return ; | |
4483 } | |
4484 } | |
4485 | |
4486 ev->reset() ; | |
4487 ev->OnList = intptr_t(Lock) ; | |
4488 // The following fence() isn't _strictly necessary as the subsequent | |
4489 // CAS() both serializes execution and ratifies the fetched *Lock value. | |
4490 OrderAccess::fence(); | |
4491 for (;;) { | |
4492 w = *Lock ; | |
4493 if ((w & LOCKBIT) == 0) { | |
4494 if (Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4495 ev->OnList = 0 ; | |
4496 // We call ::Release while holding the outer lock, thus | |
4497 // artificially lengthening the critical section. | |
4498 // Consider deferring the ::Release() until the subsequent unlock(), | |
4499 // after we've dropped the outer lock. | |
4500 if (ReleaseAfter != NULL) { | |
4501 ParkEvent::Release (ReleaseAfter) ; | |
4502 } | |
4503 return ; | |
4504 } | |
4505 continue ; // Interference -- *Lock changed -- Just retry | |
4506 } | |
4507 assert (w & LOCKBIT, "invariant") ; | |
4508 ev->ListNext = (ParkEvent *) (w & ~LOCKBIT ); | |
4509 if (Atomic::cmpxchg_ptr (intptr_t(ev)|LOCKBIT, Lock, w) == w) break ; | |
4510 } | |
4511 | |
4512 while (ev->OnList != 0) { | |
4513 ev->park() ; | |
4514 } | |
4515 } | |
4516 } | |
4517 | |
4518 // Release() must extract a successor from the list and then wake that thread. | |
4519 // It can "pop" the front of the list or use a detach-modify-reattach (DMR) scheme | |
4520 // similar to that used by ParkEvent::Allocate() and ::Release(). DMR-based | |
4521 // Release() would : | |
4522 // (A) CAS() or swap() null to *Lock, releasing the lock and detaching the list. | |
4523 // (B) Extract a successor from the private list "in-hand" | |
4524 // (C) attempt to CAS() the residual back into *Lock over null. | |
4525 // If there were any newly arrived threads and the CAS() would fail. | |
4526 // In that case Release() would detach the RATs, re-merge the list in-hand | |
4527 // with the RATs and repeat as needed. Alternately, Release() might | |
4528 // detach and extract a successor, but then pass the residual list to the wakee. | |
4529 // The wakee would be responsible for reattaching and remerging before it | |
4530 // competed for the lock. | |
4531 // | |
4532 // Both "pop" and DMR are immune from ABA corruption -- there can be | |
4533 // multiple concurrent pushers, but only one popper or detacher. | |
4534 // This implementation pops from the head of the list. This is unfair, | |
4535 // but tends to provide excellent throughput as hot threads remain hot. | |
4536 // (We wake recently run threads first). | |
4537 | |
4538 void Thread::muxRelease (volatile intptr_t * Lock) { | |
4539 for (;;) { | |
4540 const intptr_t w = Atomic::cmpxchg_ptr (0, Lock, LOCKBIT) ; | |
4541 assert (w & LOCKBIT, "invariant") ; | |
4542 if (w == LOCKBIT) return ; | |
4543 ParkEvent * List = (ParkEvent *) (w & ~LOCKBIT) ; | |
4544 assert (List != NULL, "invariant") ; | |
4545 assert (List->OnList == intptr_t(Lock), "invariant") ; | |
4546 ParkEvent * nxt = List->ListNext ; | |
4547 | |
4548 // The following CAS() releases the lock and pops the head element. | |
4549 if (Atomic::cmpxchg_ptr (intptr_t(nxt), Lock, w) != w) { | |
4550 continue ; | |
4551 } | |
4552 List->OnList = 0 ; | |
4553 OrderAccess::fence() ; | |
4554 List->unpark () ; | |
4555 return ; | |
4556 } | |
4557 } | |
4558 | |
4559 | |
0 | 4560 void Threads::verify() { |
4561 ALL_JAVA_THREADS(p) { | |
4562 p->verify(); | |
4563 } | |
4564 VMThread* thread = VMThread::vm_thread(); | |
4565 if (thread != NULL) thread->verify(); | |
4566 } |