hotspot/src/share/vm/runtime/os.cpp
changeset 35201 996db89f378e
parent 35071 a0910b1d3e0d
child 35232 76aed99c0ddd
--- a/hotspot/src/share/vm/runtime/os.cpp	Fri Dec 18 13:38:49 2015 +0000
+++ b/hotspot/src/share/vm/runtime/os.cpp	Sun Dec 20 10:37:23 2015 -0500
@@ -316,8 +316,16 @@
   // decisions depending on large page support and the calculated large page size.
   large_page_init();
 
+  // We need to adapt the configured number of stack protection pages given
+  // in 4K pages to the actual os page size. We must do this before setting
+  // up minimal stack sizes etc. in os::init_2().
+  JavaThread::set_stack_red_zone_size     (align_size_up(StackRedPages      * 4 * K, vm_page_size()));
+  JavaThread::set_stack_yellow_zone_size  (align_size_up(StackYellowPages   * 4 * K, vm_page_size()));
+  JavaThread::set_stack_reserved_zone_size(align_size_up(StackReservedPages * 4 * K, vm_page_size()));
+  JavaThread::set_stack_shadow_zone_size  (align_size_up(StackShadowPages   * 4 * K, vm_page_size()));
+
   // VM version initialization identifies some characteristics of the
-  // the platform that are used during ergonomic decisions.
+  // platform that are used during ergonomic decisions.
   VM_Version::init_before_ergo();
 }
 
@@ -1015,8 +1023,7 @@
     }
     // If the addr is in the stack region for this thread then report that
     // and print thread info
-    if (thread->stack_base() >= addr &&
-        addr > (thread->stack_base() - thread->stack_size())) {
+    if (thread->on_local_stack(addr)) {
       st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: "
                    INTPTR_FORMAT, p2i(addr), p2i(thread));
       if (verbose) thread->print_on(st);
@@ -1375,9 +1382,8 @@
 
 // Returns true if the current stack pointer is above the stack shadow
 // pages, false otherwise.
-
 bool os::stack_shadow_pages_available(Thread *thread, const methodHandle& method) {
-  assert(StackRedPages > 0 && StackYellowPages > 0,"Sanity check");
+  if (!thread->is_Java_thread()) return false;
   address sp = current_stack_pointer();
   // Check if we have StackShadowPages above the yellow zone.  This parameter
   // is dependent on the depth of the maximum VM call stack possible from
@@ -1386,12 +1392,13 @@
   // respectively.
   const int framesize_in_bytes =
     Interpreter::size_top_interpreter_activation(method()) * wordSize;
-  int reserved_area = ((StackShadowPages + StackRedPages + StackYellowPages
-                      + StackReservedPages) * vm_page_size())
-                      + framesize_in_bytes;
-  // The very lower end of the stack
-  address stack_limit = thread->stack_base() - thread->stack_size();
-  return (sp > (stack_limit + reserved_area));
+
+  assert((thread->stack_base() - thread->stack_size()) +
+         (JavaThread::stack_guard_zone_size() +
+          JavaThread::stack_shadow_zone_size() + framesize_in_bytes) ==
+         ((JavaThread*)thread)->stack_overflow_limit() + framesize_in_bytes, "sanity");
+
+  return (sp > ((JavaThread*)thread)->stack_overflow_limit() + framesize_in_bytes);
 }
 
 size_t os::page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned) {