hotspot/src/share/vm/runtime/thread.cpp

Print this page




2117   }
2118 
2119   MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
2120 
2121   clear_external_suspend();
2122 
2123   if (is_ext_suspended()) {
2124     clear_ext_suspended();
2125     SR_lock()->notify_all();
2126   }
2127 }
2128 
2129 void JavaThread::create_stack_guard_pages() {
2130   if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return;
2131   address low_addr = stack_base() - stack_size();
2132   size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
2133 
2134   int allocate = os::allocate_stack_guard_pages();
2135   // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len);
2136 
2137   if (allocate && !os::commit_memory((char *) low_addr, len)) {
2138     warning("Attempt to allocate stack guard pages failed.");
2139     return;
2140   }
2141 
2142   if (os::guard_memory((char *) low_addr, len)) {
2143     _stack_guard_state = stack_guard_enabled;
2144   } else {
2145     warning("Attempt to protect stack guard pages failed.");
2146     if (os::uncommit_memory((char *) low_addr, len)) {
2147       warning("Attempt to deallocate stack guard pages failed.");
2148     }
2149   }
2150 }
2151 
2152 void JavaThread::remove_stack_guard_pages() {
2153   if (_stack_guard_state == stack_guard_unused) return;
2154   address low_addr = stack_base() - stack_size();
2155   size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
2156 
2157   if (os::allocate_stack_guard_pages()) {
2158     if (os::uncommit_memory((char *) low_addr, len)) {
2159       _stack_guard_state = stack_guard_unused;
2160     } else {
2161       warning("Attempt to deallocate stack guard pages failed.");
2162     }
2163   } else {
2164     if (_stack_guard_state == stack_guard_unused) return;
2165     if (os::unguard_memory((char *) low_addr, len)) {
2166       _stack_guard_state = stack_guard_unused;
2167     } else {
2168         warning("Attempt to unprotect stack guard pages failed.");
2169     }
2170   }
2171 }
2172 
2173 void JavaThread::enable_stack_yellow_zone() {
2174   assert(_stack_guard_state != stack_guard_unused, "must be using guard pages.");
2175   assert(_stack_guard_state != stack_guard_enabled, "already enabled");
2176 
2177   // The base notation is from the stacks point of view, growing downward.
2178   // We need to adjust it to work correctly with guard_memory()




2117   }
2118 
2119   MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag);
2120 
2121   clear_external_suspend();
2122 
2123   if (is_ext_suspended()) {
2124     clear_ext_suspended();
2125     SR_lock()->notify_all();
2126   }
2127 }
2128 
2129 void JavaThread::create_stack_guard_pages() {
2130   if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return;
2131   address low_addr = stack_base() - stack_size();
2132   size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
2133 
2134   int allocate = os::allocate_stack_guard_pages();
2135   // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len);
2136 
2137   if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) {
2138     warning("Attempt to allocate stack guard pages failed.");
2139     return;
2140   }
2141 
2142   if (os::guard_memory((char *) low_addr, len)) {
2143     _stack_guard_state = stack_guard_enabled;
2144   } else {
2145     warning("Attempt to protect stack guard pages failed.");
2146     if (os::uncommit_memory((char *) low_addr, len)) {
2147       warning("Attempt to deallocate stack guard pages failed.");
2148     }
2149   }
2150 }
2151 
2152 void JavaThread::remove_stack_guard_pages() {
2153   if (_stack_guard_state == stack_guard_unused) return;
2154   address low_addr = stack_base() - stack_size();
2155   size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size();
2156 
2157   if (os::allocate_stack_guard_pages()) {
2158     if (os::remove_stack_guard_pages((char *) low_addr, len)) {
2159       _stack_guard_state = stack_guard_unused;
2160     } else {
2161       warning("Attempt to deallocate stack guard pages failed.");
2162     }
2163   } else {
2164     if (_stack_guard_state == stack_guard_unused) return;
2165     if (os::unguard_memory((char *) low_addr, len)) {
2166       _stack_guard_state = stack_guard_unused;
2167     } else {
2168         warning("Attempt to unprotect stack guard pages failed.");
2169     }
2170   }
2171 }
2172 
2173 void JavaThread::enable_stack_yellow_zone() {
2174   assert(_stack_guard_state != stack_guard_unused, "must be using guard pages.");
2175   assert(_stack_guard_state != stack_guard_enabled, "already enabled");
2176 
2177   // The base notation is from the stacks point of view, growing downward.
2178   // We need to adjust it to work correctly with guard_memory()