322 } |
322 } |
323 #if INCLUDE_NMT |
323 #if INCLUDE_NMT |
324 // record thread's native stack, stack grows downward |
324 // record thread's native stack, stack grows downward |
325 MemTracker::record_thread_stack(stack_end(), stack_size()); |
325 MemTracker::record_thread_stack(stack_end(), stack_size()); |
326 #endif // INCLUDE_NMT |
326 #endif // INCLUDE_NMT |
|
327 log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: " |
|
328 PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).", |
|
329 os::current_thread_id(), p2i(stack_base() - stack_size()), |
|
330 p2i(stack_base()), stack_size()/1024); |
327 } |
331 } |
328 |
332 |
329 |
333 |
330 Thread::~Thread() { |
334 Thread::~Thread() { |
331 // Reclaim the objectmonitors from the omFreeList of the moribund thread. |
335 // Reclaim the objectmonitors from the omFreeList of the moribund thread. |
1800 } |
1804 } |
1801 |
1805 |
1802 // Call after last event on thread |
1806 // Call after last event on thread |
1803 EVENT_THREAD_EXIT(this); |
1807 EVENT_THREAD_EXIT(this); |
1804 |
1808 |
|
1809 log_info(os, thread)("Thread " UINTX_FORMAT " %s.", |
|
1810 os::current_thread_id(), |
|
1811 exit_type == JavaThread::normal_exit ? "exiting" : "detaching"); |
|
1812 |
1805 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during |
1813 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during |
1806 // the execution of the method. If that is not enough, then we don't really care. Thread.stop |
1814 // the execution of the method. If that is not enough, then we don't really care. Thread.stop |
1807 // is deprecated anyhow. |
1815 // is deprecated anyhow. |
1808 if (!is_Compiler_thread()) { |
1816 if (!is_Compiler_thread()) { |
1809 int count = 3; |
1817 int count = 3; |
2489 |
2497 |
2490 int allocate = os::allocate_stack_guard_pages(); |
2498 int allocate = os::allocate_stack_guard_pages(); |
2491 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); |
2499 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); |
2492 |
2500 |
2493 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) { |
2501 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) { |
2494 warning("Attempt to allocate stack guard pages failed."); |
2502 log_warning(os, thread)("Attempt to allocate stack guard pages failed."); |
2495 return; |
2503 return; |
2496 } |
2504 } |
2497 |
2505 |
2498 if (os::guard_memory((char *) low_addr, len)) { |
2506 if (os::guard_memory((char *) low_addr, len)) { |
2499 _stack_guard_state = stack_guard_enabled; |
2507 _stack_guard_state = stack_guard_enabled; |
2500 } else { |
2508 } else { |
2501 warning("Attempt to protect stack guard pages failed."); |
2509 log_warning(os, thread)("Attempt to protect stack guard pages failed (" |
|
2510 PTR_FORMAT "-" PTR_FORMAT ").", p2i(low_addr), p2i(low_addr + len)); |
2502 if (os::uncommit_memory((char *) low_addr, len)) { |
2511 if (os::uncommit_memory((char *) low_addr, len)) { |
2503 warning("Attempt to deallocate stack guard pages failed."); |
2512 log_warning(os, thread)("Attempt to deallocate stack guard pages failed."); |
2504 } |
2513 } |
2505 } |
2514 return; |
|
2515 } |
|
2516 |
|
2517 log_debug(os, thread)("Thread " UINTX_FORMAT " stack guard pages activated: " |
|
2518 PTR_FORMAT "-" PTR_FORMAT ".", |
|
2519 os::current_thread_id(), p2i(low_addr), p2i(low_addr + len)); |
|
2520 |
2506 } |
2521 } |
2507 |
2522 |
2508 void JavaThread::remove_stack_guard_pages() { |
2523 void JavaThread::remove_stack_guard_pages() { |
2509 assert(Thread::current() == this, "from different thread"); |
2524 assert(Thread::current() == this, "from different thread"); |
2510 if (_stack_guard_state == stack_guard_unused) return; |
2525 if (_stack_guard_state == stack_guard_unused) return; |
2513 |
2528 |
2514 if (os::allocate_stack_guard_pages()) { |
2529 if (os::allocate_stack_guard_pages()) { |
2515 if (os::remove_stack_guard_pages((char *) low_addr, len)) { |
2530 if (os::remove_stack_guard_pages((char *) low_addr, len)) { |
2516 _stack_guard_state = stack_guard_unused; |
2531 _stack_guard_state = stack_guard_unused; |
2517 } else { |
2532 } else { |
2518 warning("Attempt to deallocate stack guard pages failed."); |
2533 log_warning(os, thread)("Attempt to deallocate stack guard pages failed (" |
|
2534 PTR_FORMAT "-" PTR_FORMAT ").", p2i(low_addr), p2i(low_addr + len)); |
|
2535 return; |
2519 } |
2536 } |
2520 } else { |
2537 } else { |
2521 if (_stack_guard_state == stack_guard_unused) return; |
2538 if (_stack_guard_state == stack_guard_unused) return; |
2522 if (os::unguard_memory((char *) low_addr, len)) { |
2539 if (os::unguard_memory((char *) low_addr, len)) { |
2523 _stack_guard_state = stack_guard_unused; |
2540 _stack_guard_state = stack_guard_unused; |
2524 } else { |
2541 } else { |
2525 warning("Attempt to unprotect stack guard pages failed."); |
2542 log_warning(os, thread)("Attempt to unprotect stack guard pages failed (" |
2526 } |
2543 PTR_FORMAT "-" PTR_FORMAT ").", p2i(low_addr), p2i(low_addr + len)); |
2527 } |
2544 return; |
|
2545 } |
|
2546 } |
|
2547 |
|
2548 log_debug(os, thread)("Thread " UINTX_FORMAT " stack guard pages removed: " |
|
2549 PTR_FORMAT "-" PTR_FORMAT ".", |
|
2550 os::current_thread_id(), p2i(low_addr), p2i(low_addr + len)); |
|
2551 |
2528 } |
2552 } |
2529 |
2553 |
2530 void JavaThread::enable_stack_reserved_zone() { |
2554 void JavaThread::enable_stack_reserved_zone() { |
2531 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); |
2555 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); |
2532 assert(_stack_guard_state != stack_guard_enabled, "already enabled"); |
2556 assert(_stack_guard_state != stack_guard_enabled, "already enabled"); |