2491 void JavaThread::create_stack_guard_pages() { |
2491 void JavaThread::create_stack_guard_pages() { |
2492 if (!os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) { return; } |
2492 if (!os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) { return; } |
2493 address low_addr = stack_end(); |
2493 address low_addr = stack_end(); |
2494 size_t len = stack_guard_zone_size(); |
2494 size_t len = stack_guard_zone_size(); |
2495 |
2495 |
2496 int allocate = os::allocate_stack_guard_pages(); |
2496 int must_commit = os::must_commit_stack_guard_pages(); |
2497 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); |
2497 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); |
2498 |
2498 |
2499 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) { |
2499 if (must_commit && !os::create_stack_guard_pages((char *) low_addr, len)) { |
2500 log_warning(os, thread)("Attempt to allocate stack guard pages failed."); |
2500 log_warning(os, thread)("Attempt to allocate stack guard pages failed."); |
2501 return; |
2501 return; |
2502 } |
2502 } |
2503 |
2503 |
2504 if (os::guard_memory((char *) low_addr, len)) { |
2504 if (os::guard_memory((char *) low_addr, len)) { |
2513 } |
2513 } |
2514 |
2514 |
2515 log_debug(os, thread)("Thread " UINTX_FORMAT " stack guard pages activated: " |
2515 log_debug(os, thread)("Thread " UINTX_FORMAT " stack guard pages activated: " |
2516 PTR_FORMAT "-" PTR_FORMAT ".", |
2516 PTR_FORMAT "-" PTR_FORMAT ".", |
2517 os::current_thread_id(), p2i(low_addr), p2i(low_addr + len)); |
2517 os::current_thread_id(), p2i(low_addr), p2i(low_addr + len)); |
2518 |
|
2519 } |
2518 } |
2520 |
2519 |
2521 void JavaThread::remove_stack_guard_pages() { |
2520 void JavaThread::remove_stack_guard_pages() { |
2522 assert(Thread::current() == this, "from different thread"); |
2521 assert(Thread::current() == this, "from different thread"); |
2523 if (_stack_guard_state == stack_guard_unused) return; |
2522 if (_stack_guard_state == stack_guard_unused) return; |
2524 address low_addr = stack_end(); |
2523 address low_addr = stack_end(); |
2525 size_t len = stack_guard_zone_size(); |
2524 size_t len = stack_guard_zone_size(); |
2526 |
2525 |
2527 if (os::allocate_stack_guard_pages()) { |
2526 if (os::must_commit_stack_guard_pages()) { |
2528 if (os::remove_stack_guard_pages((char *) low_addr, len)) { |
2527 if (os::remove_stack_guard_pages((char *) low_addr, len)) { |
2529 _stack_guard_state = stack_guard_unused; |
2528 _stack_guard_state = stack_guard_unused; |
2530 } else { |
2529 } else { |
2531 log_warning(os, thread)("Attempt to deallocate stack guard pages failed (" |
2530 log_warning(os, thread)("Attempt to deallocate stack guard pages failed (" |
2532 PTR_FORMAT "-" PTR_FORMAT ").", p2i(low_addr), p2i(low_addr + len)); |
2531 PTR_FORMAT "-" PTR_FORMAT ").", p2i(low_addr), p2i(low_addr + len)); |
2544 } |
2543 } |
2545 |
2544 |
2546 log_debug(os, thread)("Thread " UINTX_FORMAT " stack guard pages removed: " |
2545 log_debug(os, thread)("Thread " UINTX_FORMAT " stack guard pages removed: " |
2547 PTR_FORMAT "-" PTR_FORMAT ".", |
2546 PTR_FORMAT "-" PTR_FORMAT ".", |
2548 os::current_thread_id(), p2i(low_addr), p2i(low_addr + len)); |
2547 os::current_thread_id(), p2i(low_addr), p2i(low_addr + len)); |
2549 |
|
2550 } |
2548 } |
2551 |
2549 |
2552 void JavaThread::enable_stack_reserved_zone() { |
2550 void JavaThread::enable_stack_reserved_zone() { |
2553 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); |
2551 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); |
2554 assert(_stack_guard_state != stack_guard_enabled, "already enabled"); |
2552 assert(_stack_guard_state != stack_guard_enabled, "already enabled"); |