71 #include "runtime/vframe_hp.hpp" |
71 #include "runtime/vframe_hp.hpp" |
72 #include "runtime/vmThread.hpp" |
72 #include "runtime/vmThread.hpp" |
73 #include "runtime/vm_operations.hpp" |
73 #include "runtime/vm_operations.hpp" |
74 #include "services/attachListener.hpp" |
74 #include "services/attachListener.hpp" |
75 #include "services/management.hpp" |
75 #include "services/management.hpp" |
|
76 #include "services/memTracker.hpp" |
76 #include "services/threadService.hpp" |
77 #include "services/threadService.hpp" |
77 #include "trace/traceEventTypes.hpp" |
78 #include "trace/traceEventTypes.hpp" |
78 #include "utilities/defaultStream.hpp" |
79 #include "utilities/defaultStream.hpp" |
79 #include "utilities/dtrace.hpp" |
80 #include "utilities/dtrace.hpp" |
80 #include "utilities/events.hpp" |
81 #include "utilities/events.hpp" |
157 |
158 |
158 #define DTRACE_THREAD_PROBE(probe, javathread) |
159 #define DTRACE_THREAD_PROBE(probe, javathread) |
159 |
160 |
160 #endif // ndef DTRACE_ENABLED |
161 #endif // ndef DTRACE_ENABLED |
161 |
162 |
|
163 |
162 // Class hierarchy |
164 // Class hierarchy |
163 // - Thread |
165 // - Thread |
164 // - VMThread |
166 // - VMThread |
165 // - WatcherThread |
167 // - WatcherThread |
166 // - ConcurrentMarkSweepThread |
168 // - ConcurrentMarkSweepThread |
167 // - JavaThread |
169 // - JavaThread |
168 // - CompilerThread |
170 // - CompilerThread |
169 |
171 |
170 // ======= Thread ======== |
172 // ======= Thread ======== |
171 |
|
172 // Support for forcing alignment of thread objects for biased locking |
173 // Support for forcing alignment of thread objects for biased locking |
173 void* Thread::operator new(size_t size) { |
174 void* Thread::allocate(size_t size, bool throw_excpt, MEMFLAGS flags) { |
174 if (UseBiasedLocking) { |
175 if (UseBiasedLocking) { |
175 const int alignment = markOopDesc::biased_lock_alignment; |
176 const int alignment = markOopDesc::biased_lock_alignment; |
176 size_t aligned_size = size + (alignment - sizeof(intptr_t)); |
177 size_t aligned_size = size + (alignment - sizeof(intptr_t)); |
177 void* real_malloc_addr = CHeapObj::operator new(aligned_size); |
178 void* real_malloc_addr = throw_excpt? AllocateHeap(aligned_size, flags, CURRENT_PC) |
|
179 : os::malloc(aligned_size, flags, CURRENT_PC); |
178 void* aligned_addr = (void*) align_size_up((intptr_t) real_malloc_addr, alignment); |
180 void* aligned_addr = (void*) align_size_up((intptr_t) real_malloc_addr, alignment); |
179 assert(((uintptr_t) aligned_addr + (uintptr_t) size) <= |
181 assert(((uintptr_t) aligned_addr + (uintptr_t) size) <= |
180 ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size), |
182 ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size), |
181 "JavaThread alignment code overflowed allocated storage"); |
183 "JavaThread alignment code overflowed allocated storage"); |
182 if (TraceBiasedLocking) { |
184 if (TraceBiasedLocking) { |
185 real_malloc_addr, aligned_addr); |
187 real_malloc_addr, aligned_addr); |
186 } |
188 } |
187 ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr; |
189 ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr; |
188 return aligned_addr; |
190 return aligned_addr; |
189 } else { |
191 } else { |
190 return CHeapObj::operator new(size); |
192 return throw_excpt? AllocateHeap(size, flags, CURRENT_PC) |
|
193 : os::malloc(size, flags, CURRENT_PC); |
191 } |
194 } |
192 } |
195 } |
193 |
196 |
194 void Thread::operator delete(void* p) { |
197 void Thread::operator delete(void* p) { |
195 if (UseBiasedLocking) { |
198 if (UseBiasedLocking) { |
196 void* real_malloc_addr = ((Thread*) p)->_real_malloc_address; |
199 void* real_malloc_addr = ((Thread*) p)->_real_malloc_address; |
197 CHeapObj::operator delete(real_malloc_addr); |
200 FreeHeap(real_malloc_addr, mtThread); |
198 } else { |
201 } else { |
199 CHeapObj::operator delete(p); |
202 FreeHeap(p, mtThread); |
200 } |
203 } |
201 } |
204 } |
202 |
205 |
203 |
206 |
204 // Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread, |
207 // Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread, |
212 set_self_raw_id(0); |
215 set_self_raw_id(0); |
213 set_lgrp_id(-1); |
216 set_lgrp_id(-1); |
214 |
217 |
215 // allocated data structures |
218 // allocated data structures |
216 set_osthread(NULL); |
219 set_osthread(NULL); |
217 set_resource_area(new ResourceArea()); |
220 set_resource_area(new (mtThread)ResourceArea()); |
218 set_handle_area(new HandleArea(NULL)); |
221 set_handle_area(new (mtThread) HandleArea(NULL)); |
219 set_active_handles(NULL); |
222 set_active_handles(NULL); |
220 set_free_handle_block(NULL); |
223 set_free_handle_block(NULL); |
221 set_last_handle_mark(NULL); |
224 set_last_handle_mark(NULL); |
222 |
225 |
223 // This initial value ==> never claimed. |
226 // This initial value ==> never claimed. |
304 // initialize structure dependent on thread local storage |
307 // initialize structure dependent on thread local storage |
305 ThreadLocalStorage::set_thread(this); |
308 ThreadLocalStorage::set_thread(this); |
306 |
309 |
307 // set up any platform-specific state. |
310 // set up any platform-specific state. |
308 os::initialize_thread(); |
311 os::initialize_thread(); |
309 |
|
310 } |
312 } |
311 |
313 |
312 void Thread::record_stack_base_and_size() { |
314 void Thread::record_stack_base_and_size() { |
313 set_stack_base(os::current_stack_base()); |
315 set_stack_base(os::current_stack_base()); |
314 set_stack_size(os::current_stack_size()); |
316 set_stack_size(os::current_stack_size()); |
|
317 |
|
318 // record thread's native stack, stack grows downward |
|
319 address vm_base = _stack_base - _stack_size; |
|
320 MemTracker::record_virtual_memory_reserve(vm_base, _stack_size, |
|
321 CURRENT_PC, this); |
|
322 MemTracker::record_virtual_memory_type(vm_base, mtThreadStack); |
315 } |
323 } |
316 |
324 |
317 |
325 |
318 Thread::~Thread() { |
326 Thread::~Thread() { |
319 // Reclaim the objectmonitors from the omFreeList of the moribund thread. |
327 // Reclaim the objectmonitors from the omFreeList of the moribund thread. |
320 ObjectSynchronizer::omFlush (this) ; |
328 ObjectSynchronizer::omFlush (this) ; |
|
329 |
|
330 MemTracker::record_virtual_memory_release((_stack_base - _stack_size), |
|
331 _stack_size, this); |
321 |
332 |
322 // deallocate data structures |
333 // deallocate data structures |
323 delete resource_area(); |
334 delete resource_area(); |
324 // since the handle marks are using the handle area, we have to deallocated the root |
335 // since the handle marks are using the handle area, we have to deallocated the root |
325 // handle mark before deallocating the thread's handle area, |
336 // handle mark before deallocating the thread's handle area, |
1126 _processed_thread = NULL; |
1137 _processed_thread = NULL; |
1127 } |
1138 } |
1128 |
1139 |
1129 NamedThread::~NamedThread() { |
1140 NamedThread::~NamedThread() { |
1130 if (_name != NULL) { |
1141 if (_name != NULL) { |
1131 FREE_C_HEAP_ARRAY(char, _name); |
1142 FREE_C_HEAP_ARRAY(char, _name, mtThread); |
1132 _name = NULL; |
1143 _name = NULL; |
1133 } |
1144 } |
1134 } |
1145 } |
1135 |
1146 |
1136 void NamedThread::set_name(const char* format, ...) { |
1147 void NamedThread::set_name(const char* format, ...) { |
1137 guarantee(_name == NULL, "Only get to set name once."); |
1148 guarantee(_name == NULL, "Only get to set name once."); |
1138 _name = NEW_C_HEAP_ARRAY(char, max_name_len); |
1149 _name = NEW_C_HEAP_ARRAY(char, max_name_len, mtThread); |
1139 guarantee(_name != NULL, "alloc failure"); |
1150 guarantee(_name != NULL, "alloc failure"); |
1140 va_list ap; |
1151 va_list ap; |
1141 va_start(ap, format); |
1152 va_start(ap, format); |
1142 jio_vsnprintf(_name, max_name_len, format, ap); |
1153 jio_vsnprintf(_name, max_name_len, format, ap); |
1143 va_end(ap); |
1154 va_end(ap); |
1316 set_deopt_nmethod(NULL); |
1327 set_deopt_nmethod(NULL); |
1317 clear_must_deopt_id(); |
1328 clear_must_deopt_id(); |
1318 set_monitor_chunks(NULL); |
1329 set_monitor_chunks(NULL); |
1319 set_next(NULL); |
1330 set_next(NULL); |
1320 set_thread_state(_thread_new); |
1331 set_thread_state(_thread_new); |
|
1332 set_recorder(NULL); |
1321 _terminated = _not_terminated; |
1333 _terminated = _not_terminated; |
1322 _privileged_stack_top = NULL; |
1334 _privileged_stack_top = NULL; |
1323 _array_for_gc = NULL; |
1335 _array_for_gc = NULL; |
1324 _suspend_equivalent = false; |
1336 _suspend_equivalent = false; |
1325 _in_deopt_handler = 0; |
1337 _in_deopt_handler = 0; |
1391 _jni_attach_state = _attaching_via_jni; |
1403 _jni_attach_state = _attaching_via_jni; |
1392 } else { |
1404 } else { |
1393 _jni_attach_state = _not_attaching_via_jni; |
1405 _jni_attach_state = _not_attaching_via_jni; |
1394 } |
1406 } |
1395 assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor"); |
1407 assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor"); |
|
1408 _safepoint_visible = false; |
1396 } |
1409 } |
1397 |
1410 |
1398 bool JavaThread::reguard_stack(address cur_sp) { |
1411 bool JavaThread::reguard_stack(address cur_sp) { |
1399 if (_stack_guard_state != stack_guard_yellow_disabled) { |
1412 if (_stack_guard_state != stack_guard_yellow_disabled) { |
1400 return true; // Stack already guarded or guard pages not needed. |
1413 return true; // Stack already guarded or guard pages not needed. |
1453 // %note runtime_23 |
1466 // %note runtime_23 |
1454 os::ThreadType thr_type = os::java_thread; |
1467 os::ThreadType thr_type = os::java_thread; |
1455 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread : |
1468 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread : |
1456 os::java_thread; |
1469 os::java_thread; |
1457 os::create_thread(this, thr_type, stack_sz); |
1470 os::create_thread(this, thr_type, stack_sz); |
1458 |
1471 _safepoint_visible = false; |
1459 // The _osthread may be NULL here because we ran out of memory (too many threads active). |
1472 // The _osthread may be NULL here because we ran out of memory (too many threads active). |
1460 // We need to throw and OutOfMemoryError - however we cannot do this here because the caller |
1473 // We need to throw and OutOfMemoryError - however we cannot do this here because the caller |
1461 // may hold a lock and all locks must be unlocked before throwing the exception (throwing |
1474 // may hold a lock and all locks must be unlocked before throwing the exception (throwing |
1462 // the exception consists of creating the exception object & initializing it, initialization |
1475 // the exception consists of creating the exception object & initializing it, initialization |
1463 // will leave the VM via a JavaCall and then all locks must be unlocked). |
1476 // will leave the VM via a JavaCall and then all locks must be unlocked). |
1470 |
1483 |
1471 JavaThread::~JavaThread() { |
1484 JavaThread::~JavaThread() { |
1472 if (TraceThreadEvents) { |
1485 if (TraceThreadEvents) { |
1473 tty->print_cr("terminate thread %p", this); |
1486 tty->print_cr("terminate thread %p", this); |
1474 } |
1487 } |
|
1488 |
|
1489 // Info NMT that this JavaThread is exiting, its memory |
|
1490 // recorder should be collected |
|
1491 assert(!is_safepoint_visible(), "wrong state"); |
|
1492 MemTracker::thread_exiting(this); |
1475 |
1493 |
1476 // JSR166 -- return the parker to the free list |
1494 // JSR166 -- return the parker to the free list |
1477 Parker::Release(_parker); |
1495 Parker::Release(_parker); |
1478 _parker = NULL ; |
1496 _parker = NULL ; |
1479 |
1497 |
2913 |
2931 |
2914 // JVMTI PopFrame support |
2932 // JVMTI PopFrame support |
2915 void JavaThread::popframe_preserve_args(ByteSize size_in_bytes, void* start) { |
2933 void JavaThread::popframe_preserve_args(ByteSize size_in_bytes, void* start) { |
2916 assert(_popframe_preserved_args == NULL, "should not wipe out old PopFrame preserved arguments"); |
2934 assert(_popframe_preserved_args == NULL, "should not wipe out old PopFrame preserved arguments"); |
2917 if (in_bytes(size_in_bytes) != 0) { |
2935 if (in_bytes(size_in_bytes) != 0) { |
2918 _popframe_preserved_args = NEW_C_HEAP_ARRAY(char, in_bytes(size_in_bytes)); |
2936 _popframe_preserved_args = NEW_C_HEAP_ARRAY(char, in_bytes(size_in_bytes), mtThread); |
2919 _popframe_preserved_args_size = in_bytes(size_in_bytes); |
2937 _popframe_preserved_args_size = in_bytes(size_in_bytes); |
2920 Copy::conjoint_jbytes(start, _popframe_preserved_args, _popframe_preserved_args_size); |
2938 Copy::conjoint_jbytes(start, _popframe_preserved_args, _popframe_preserved_args_size); |
2921 } |
2939 } |
2922 } |
2940 } |
2923 |
2941 |
2935 return in_WordSize(sz / wordSize); |
2953 return in_WordSize(sz / wordSize); |
2936 } |
2954 } |
2937 |
2955 |
2938 void JavaThread::popframe_free_preserved_args() { |
2956 void JavaThread::popframe_free_preserved_args() { |
2939 assert(_popframe_preserved_args != NULL, "should not free PopFrame preserved arguments twice"); |
2957 assert(_popframe_preserved_args != NULL, "should not free PopFrame preserved arguments twice"); |
2940 FREE_C_HEAP_ARRAY(char, (char*) _popframe_preserved_args); |
2958 FREE_C_HEAP_ARRAY(char, (char*) _popframe_preserved_args, mtThread); |
2941 _popframe_preserved_args = NULL; |
2959 _popframe_preserved_args = NULL; |
2942 _popframe_preserved_args_size = 0; |
2960 _popframe_preserved_args_size = 0; |
2943 } |
2961 } |
2944 |
2962 |
2945 #ifndef PRODUCT |
2963 #ifndef PRODUCT |
3184 |
3202 |
3185 // Initialize the os module after parsing the args |
3203 // Initialize the os module after parsing the args |
3186 jint os_init_2_result = os::init_2(); |
3204 jint os_init_2_result = os::init_2(); |
3187 if (os_init_2_result != JNI_OK) return os_init_2_result; |
3205 if (os_init_2_result != JNI_OK) return os_init_2_result; |
3188 |
3206 |
|
3207 // intialize TLS |
|
3208 ThreadLocalStorage::init(); |
|
3209 |
|
3210 // Bootstrap native memory tracking, so it can start recording memory |
|
3211 // activities before worker thread is started. This is the first phase |
|
3212 // of bootstrapping, VM is currently running in single-thread mode. |
|
3213 MemTracker::bootstrap_single_thread(); |
|
3214 |
3189 // Initialize output stream logging |
3215 // Initialize output stream logging |
3190 ostream_init_log(); |
3216 ostream_init_log(); |
3191 |
3217 |
3192 // Convert -Xrun to -agentlib: if there is no JVM_OnLoad |
3218 // Convert -Xrun to -agentlib: if there is no JVM_OnLoad |
3193 // Must be before create_vm_init_agents() |
3219 // Must be before create_vm_init_agents() |
3202 |
3228 |
3203 // Initialize Threads state |
3229 // Initialize Threads state |
3204 _thread_list = NULL; |
3230 _thread_list = NULL; |
3205 _number_of_threads = 0; |
3231 _number_of_threads = 0; |
3206 _number_of_non_daemon_threads = 0; |
3232 _number_of_non_daemon_threads = 0; |
3207 |
|
3208 // Initialize TLS |
|
3209 ThreadLocalStorage::init(); |
|
3210 |
3233 |
3211 // Initialize global data structures and create system classes in heap |
3234 // Initialize global data structures and create system classes in heap |
3212 vm_init_globals(); |
3235 vm_init_globals(); |
3213 |
3236 |
3214 // Attach the main thread to this os thread |
3237 // Attach the main thread to this os thread |
3237 main_thread->create_stack_guard_pages(); |
3260 main_thread->create_stack_guard_pages(); |
3238 |
3261 |
3239 // Initialize Java-Level synchronization subsystem |
3262 // Initialize Java-Level synchronization subsystem |
3240 ObjectMonitor::Initialize() ; |
3263 ObjectMonitor::Initialize() ; |
3241 |
3264 |
|
3265 // Second phase of bootstrapping, VM is about entering multi-thread mode |
|
3266 MemTracker::bootstrap_multi_thread(); |
|
3267 |
3242 // Initialize global modules |
3268 // Initialize global modules |
3243 jint status = init_globals(); |
3269 jint status = init_globals(); |
3244 if (status != JNI_OK) { |
3270 if (status != JNI_OK) { |
3245 delete main_thread; |
3271 delete main_thread; |
3246 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again |
3272 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again |
3263 if (VerifyBeforeGC && |
3289 if (VerifyBeforeGC && |
3264 Universe::heap()->total_collections() >= VerifyGCStartAt) { |
3290 Universe::heap()->total_collections() >= VerifyGCStartAt) { |
3265 Universe::heap()->prepare_for_verify(); |
3291 Universe::heap()->prepare_for_verify(); |
3266 Universe::verify(); // make sure we're starting with a clean slate |
3292 Universe::verify(); // make sure we're starting with a clean slate |
3267 } |
3293 } |
|
3294 |
|
3295 // Fully start NMT |
|
3296 MemTracker::start(); |
3268 |
3297 |
3269 // Create the VMThread |
3298 // Create the VMThread |
3270 { TraceTime timer("Start VMThread", TraceStartupTime); |
3299 { TraceTime timer("Start VMThread", TraceStartupTime); |
3271 VMThread::create(); |
3300 VMThread::create(); |
3272 Thread* vmthread = VMThread::vm_thread(); |
3301 Thread* vmthread = VMThread::vm_thread(); |
3568 if (agent->is_absolute_path()) { |
3597 if (agent->is_absolute_path()) { |
3569 library = os::dll_load(name, ebuf, sizeof ebuf); |
3598 library = os::dll_load(name, ebuf, sizeof ebuf); |
3570 if (library == NULL) { |
3599 if (library == NULL) { |
3571 const char *sub_msg = " in absolute path, with error: "; |
3600 const char *sub_msg = " in absolute path, with error: "; |
3572 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
3601 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
3573 char *buf = NEW_C_HEAP_ARRAY(char, len); |
3602 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); |
3574 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
3603 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
3575 // If we can't find the agent, exit. |
3604 // If we can't find the agent, exit. |
3576 vm_exit_during_initialization(buf, NULL); |
3605 vm_exit_during_initialization(buf, NULL); |
3577 FREE_C_HEAP_ARRAY(char, buf); |
3606 FREE_C_HEAP_ARRAY(char, buf, mtThread); |
3578 } |
3607 } |
3579 } else { |
3608 } else { |
3580 // Try to load the agent from the standard dll directory |
3609 // Try to load the agent from the standard dll directory |
3581 os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), name); |
3610 os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), name); |
3582 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3611 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3586 char *props = Arguments::get_kernel_properties(); |
3615 char *props = Arguments::get_kernel_properties(); |
3587 char *home = Arguments::get_java_home(); |
3616 char *home = Arguments::get_java_home(); |
3588 const char *fmt = "%s/bin/java %s -Dkernel.background.download=false" |
3617 const char *fmt = "%s/bin/java %s -Dkernel.background.download=false" |
3589 " sun.jkernel.DownloadManager -download client_jvm"; |
3618 " sun.jkernel.DownloadManager -download client_jvm"; |
3590 size_t length = strlen(props) + strlen(home) + strlen(fmt) + 1; |
3619 size_t length = strlen(props) + strlen(home) + strlen(fmt) + 1; |
3591 char *cmd = NEW_C_HEAP_ARRAY(char, length); |
3620 char *cmd = NEW_C_HEAP_ARRAY(char, length, mtThread); |
3592 jio_snprintf(cmd, length, fmt, home, props); |
3621 jio_snprintf(cmd, length, fmt, home, props); |
3593 int status = os::fork_and_exec(cmd); |
3622 int status = os::fork_and_exec(cmd); |
3594 FreeHeap(props); |
3623 FreeHeap(props); |
3595 if (status == -1) { |
3624 if (status == -1) { |
3596 warning(cmd); |
3625 warning(cmd); |
3597 vm_exit_during_initialization("fork_and_exec failed: %s", |
3626 vm_exit_during_initialization("fork_and_exec failed: %s", |
3598 strerror(errno)); |
3627 strerror(errno)); |
3599 } |
3628 } |
3600 FREE_C_HEAP_ARRAY(char, cmd); |
3629 FREE_C_HEAP_ARRAY(char, cmd, mtThread); |
3601 // when this comes back the instrument.dll should be where it belongs. |
3630 // when this comes back the instrument.dll should be where it belongs. |
3602 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3631 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3603 } |
3632 } |
3604 #endif // KERNEL |
3633 #endif // KERNEL |
3605 if (library == NULL) { // Try the local directory |
3634 if (library == NULL) { // Try the local directory |
3607 os::dll_build_name(buffer, sizeof(buffer), ns, name); |
3636 os::dll_build_name(buffer, sizeof(buffer), ns, name); |
3608 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3637 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
3609 if (library == NULL) { |
3638 if (library == NULL) { |
3610 const char *sub_msg = " on the library path, with error: "; |
3639 const char *sub_msg = " on the library path, with error: "; |
3611 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
3640 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
3612 char *buf = NEW_C_HEAP_ARRAY(char, len); |
3641 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); |
3613 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
3642 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
3614 // If we can't find the agent, exit. |
3643 // If we can't find the agent, exit. |
3615 vm_exit_during_initialization(buf, NULL); |
3644 vm_exit_during_initialization(buf, NULL); |
3616 FREE_C_HEAP_ARRAY(char, buf); |
3645 FREE_C_HEAP_ARRAY(char, buf, mtThread); |
3617 } |
3646 } |
3618 } |
3647 } |
3619 } |
3648 } |
3620 agent->set_os_lib(library); |
3649 agent->set_os_lib(library); |
3621 } |
3650 } |
3780 // there is a serious error in VM. The two shutdown paths are not exactly |
3809 // there is a serious error in VM. The two shutdown paths are not exactly |
3781 // the same, but they share Shutdown.shutdown() at Java level and before_exit() |
3810 // the same, but they share Shutdown.shutdown() at Java level and before_exit() |
3782 // and VM_Exit op at VM level. |
3811 // and VM_Exit op at VM level. |
3783 // |
3812 // |
3784 // Shutdown sequence: |
3813 // Shutdown sequence: |
|
3814 // + Shutdown native memory tracking if it is on |
3785 // + Wait until we are the last non-daemon thread to execute |
3815 // + Wait until we are the last non-daemon thread to execute |
3786 // <-- every thing is still working at this moment --> |
3816 // <-- every thing is still working at this moment --> |
3787 // + Call java.lang.Shutdown.shutdown(), which will invoke Java level |
3817 // + Call java.lang.Shutdown.shutdown(), which will invoke Java level |
3788 // shutdown hooks, run finalizers if finalization-on-exit |
3818 // shutdown hooks, run finalizers if finalization-on-exit |
3789 // + Call before_exit(), prepare for VM exit |
3819 // + Call before_exit(), prepare for VM exit |
3825 // |
3855 // |
3826 Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0, |
3856 Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0, |
3827 Mutex::_as_suspend_equivalent_flag); |
3857 Mutex::_as_suspend_equivalent_flag); |
3828 } |
3858 } |
3829 |
3859 |
|
3860 // Shutdown NMT before exit. Otherwise, |
|
3861 // it will run into trouble when system destroys static variables. |
|
3862 MemTracker::shutdown(MemTracker::NMT_normal); |
|
3863 |
3830 // Hang forever on exit if we are reporting an error. |
3864 // Hang forever on exit if we are reporting an error. |
3831 if (ShowMessageBoxOnError && is_error_reported()) { |
3865 if (ShowMessageBoxOnError && is_error_reported()) { |
3832 os::infinite_sleep(); |
3866 os::infinite_sleep(); |
3833 } |
3867 } |
3834 os::wait_for_keypress_at_exit(); |
3868 os::wait_for_keypress_at_exit(); |
3931 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { |
3965 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { |
3932 _number_of_non_daemon_threads++; |
3966 _number_of_non_daemon_threads++; |
3933 daemon = false; |
3967 daemon = false; |
3934 } |
3968 } |
3935 |
3969 |
|
3970 p->set_safepoint_visible(true); |
|
3971 |
3936 ThreadService::add_thread(p, daemon); |
3972 ThreadService::add_thread(p, daemon); |
3937 |
3973 |
3938 // Possible GC point. |
3974 // Possible GC point. |
3939 Events::log(p, "Thread added: " INTPTR_FORMAT, p); |
3975 Events::log(p, "Thread added: " INTPTR_FORMAT, p); |
3940 } |
3976 } |
3976 // Make sure that safepoint code disregard this thread. This is needed since |
4012 // Make sure that safepoint code disregard this thread. This is needed since |
3977 // the thread might mess around with locks after this point. This can cause it |
4013 // the thread might mess around with locks after this point. This can cause it |
3978 // to do callbacks into the safepoint code. However, the safepoint code is not aware |
4014 // to do callbacks into the safepoint code. However, the safepoint code is not aware |
3979 // of this thread since it is removed from the queue. |
4015 // of this thread since it is removed from the queue. |
3980 p->set_terminated_value(); |
4016 p->set_terminated_value(); |
|
4017 |
|
4018 // Now, this thread is not visible to safepoint |
|
4019 p->set_safepoint_visible(false); |
|
4020 |
3981 } // unlock Threads_lock |
4021 } // unlock Threads_lock |
3982 |
4022 |
3983 // Since Events::log uses a lock, we grab it outside the Threads_lock |
4023 // Since Events::log uses a lock, we grab it outside the Threads_lock |
3984 Events::log(p, "Thread exited: " INTPTR_FORMAT, p); |
4024 Events::log(p, "Thread exited: " INTPTR_FORMAT, p); |
3985 } |
4025 } |