changeset 42906:1a8db9cf1407

8170655: [posix] Fix minimum stack size computations Reviewed-by: dcubed, coleenp
author goetz
date Mon, 19 Dec 2016 15:48:57 -0800
parents 1af223983f82
children d1b25477073b
files hotspot/src/cpu/ppc/vm/globals_ppc.hpp hotspot/src/cpu/x86/vm/globals_x86.hpp hotspot/src/os/posix/vm/os_posix.cpp hotspot/src/os/posix/vm/os_posix.hpp hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp hotspot/src/os_cpu/linux_s390/vm/os_linux_s390.cpp hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp hotspot/src/share/vm/runtime/os.hpp
diffstat 14 files changed, 85 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/cpu/ppc/vm/globals_ppc.hpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/cpu/ppc/vm/globals_ppc.hpp	Mon Dec 19 15:48:57 2016 -0800
@@ -42,6 +42,9 @@
 
 #define DEFAULT_STACK_YELLOW_PAGES (2)
 #define DEFAULT_STACK_RED_PAGES (1)
+// Java_java_net_SocketOutputStream_socketWrite0() uses a 64k buffer on the
+// stack if compiled for unix and LP64. To pass stack overflow tests we need
+// 20 shadow pages.
 #define DEFAULT_STACK_SHADOW_PAGES (20 DEBUG_ONLY(+2))
 #define DEFAULT_STACK_RESERVED_PAGES (1)
 
--- a/hotspot/src/cpu/x86/vm/globals_x86.hpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/cpu/x86/vm/globals_x86.hpp	Mon Dec 19 15:48:57 2016 -0800
@@ -63,9 +63,10 @@
 #define MIN_STACK_RED_PAGES DEFAULT_STACK_RED_PAGES
 #define MIN_STACK_RESERVED_PAGES (0)
 
-#ifdef AMD64
-// Very large C++ stack frames using solaris-amd64 optimized builds
-// due to lack of optimization caused by C++ compiler bugs
+#ifdef _LP64
+// Java_java_net_SocketOutputStream_socketWrite0() uses a 64k buffer on the
+// stack if compiled for unix and LP64. To pass stack overflow tests we need
+// 20 shadow pages.
 #define DEFAULT_STACK_SHADOW_PAGES (NOT_WIN64(20) WIN64_ONLY(7) DEBUG_ONLY(+2))
 // For those clients that do not use write socket, we allow
 // the min range value to be below that of the default
@@ -73,7 +74,7 @@
 #else
 #define DEFAULT_STACK_SHADOW_PAGES (4 DEBUG_ONLY(+5))
 #define MIN_STACK_SHADOW_PAGES DEFAULT_STACK_SHADOW_PAGES
-#endif // AMD64
+#endif // _LP64
 
 define_pd_global(intx, StackYellowPages, DEFAULT_STACK_YELLOW_PAGES);
 define_pd_global(intx, StackRedPages, DEFAULT_STACK_RED_PAGES);
--- a/hotspot/src/os/posix/vm/os_posix.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os/posix/vm/os_posix.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -1107,14 +1107,18 @@
 
 // Check minimum allowable stack sizes for thread creation and to initialize
 // the java system classes, including StackOverflowError - depends on page
-// size.  Add two 4K pages for compiler2 recursion in main thread.
-// Add in 4*BytesPerWord 4K pages to account for VM stack during
-// class initialization depending on 32 or 64 bit VM.
+// size.
+// The space needed for frames during startup is platform dependent. It
+// depends on word size, platform calling conventions, C frame layout and
+// interpreter/C1/C2 design decisions. Therefore this is given in a
+// platform (os/cpu) dependent constant.
+// To this, space for guard mechanisms is added, which depends on the
+// page size which again depends on the concrete system the VM is running
+// on. Space for libc guard pages is not included in this size.
 jint os::Posix::set_minimum_stack_sizes() {
-  _java_thread_min_stack_allowed = MAX2(_java_thread_min_stack_allowed,
-                                        JavaThread::stack_guard_zone_size() +
-                                        JavaThread::stack_shadow_zone_size() +
-                                        (4 * BytesPerWord COMPILER2_PRESENT(+ 2)) * 4 * K);
+  _java_thread_min_stack_allowed = _java_thread_min_stack_allowed +
+                                   JavaThread::stack_guard_zone_size() +
+                                   JavaThread::stack_shadow_zone_size();
 
   _java_thread_min_stack_allowed = align_size_up(_java_thread_min_stack_allowed, vm_page_size());
 
@@ -1130,28 +1134,14 @@
     return JNI_ERR;
   }
 
-#ifdef SOLARIS
-  // For 64kbps there will be a 64kb page size, which makes
-  // the usable default stack size quite a bit less.  Increase the
-  // stack for 64kb (or any > than 8kb) pages, this increases
-  // virtual memory fragmentation (since we're not creating the
-  // stack on a power of 2 boundary.  The real fix for this
-  // should be to fix the guard page mechanism.
-
-  if (vm_page_size() > 8*K) {
-    stack_size_in_bytes = (stack_size_in_bytes != 0)
-       ? stack_size_in_bytes +
-         JavaThread::stack_red_zone_size() +
-         JavaThread::stack_yellow_zone_size()
-       : 0;
-    ThreadStackSize = stack_size_in_bytes/K;
-  }
-#endif // SOLARIS
-
   // Make the stack size a multiple of the page size so that
   // the yellow/red zones can be guarded.
-  JavaThread::set_stack_size_at_create(round_to(stack_size_in_bytes,
-                                                vm_page_size()));
+  JavaThread::set_stack_size_at_create(round_to(stack_size_in_bytes, vm_page_size()));
+
+  // Reminder: a compiler thread is a Java thread.
+  _compiler_thread_min_stack_allowed = _compiler_thread_min_stack_allowed +
+                                       JavaThread::stack_guard_zone_size() +
+                                       JavaThread::stack_shadow_zone_size();
 
   _compiler_thread_min_stack_allowed = align_size_up(_compiler_thread_min_stack_allowed, vm_page_size());
 
--- a/hotspot/src/os/posix/vm/os_posix.hpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os/posix/vm/os_posix.hpp	Mon Dec 19 15:48:57 2016 -0800
@@ -43,7 +43,11 @@
   static void print_load_average(outputStream* st);
 
   // Minimum stack size a thread can be created with (allowing
-  // the VM to completely create the thread and enter user code)
+  // the VM to completely create the thread and enter user code).
+  // The initial values exclude any guard pages (by HotSpot or libc).
+  // set_minimum_stack_sizes() will add the size required for
+  // HotSpot guard pages depending on page size and flag settings.
+  // Libc guard pages are never considered by these values.
   static size_t _compiler_thread_min_stack_allowed;
   static size_t _java_thread_min_stack_allowed;
   static size_t _vm_internal_thread_min_stack_allowed;
--- a/hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/aix_ppc/vm/os_aix_ppc.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -535,11 +535,11 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-// These sizes exclude libc stack guard pages, but include
-// the HotSpot guard pages.
-size_t os::Posix::_compiler_thread_min_stack_allowed = 512 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 512 * K;
-size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 192 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 
 // Return default stack size for thr_type.
 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
--- a/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -839,19 +839,20 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-#ifdef AMD64
-size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 48 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 48 * K;
+#ifdef _LP64
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 #else
-size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
-size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
+#endif // _LP64
 
+#ifndef AMD64
 #ifdef __GNUC__
 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
 #endif
-
 #endif // AMD64
 
 // return default stack size for thr_type
--- a/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/linux_aarch64/vm/os_linux_aarch64.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -473,8 +473,10 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 32 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 32 * K;
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 
 // return default stack size for thr_type
--- a/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -535,15 +535,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-// These sizes exclude libc stack guard pages, but include
-// the HotSpot guard pages.
-size_t os::Posix::_compiler_thread_min_stack_allowed = 384 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 384 * K;
-size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 
-// return default stack size for thr_type
+// Return default stack size for thr_type.
 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
-  // default stack size (compiler thread needs larger stack)
+  // Default stack size (compiler thread needs larger stack).
   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
   return s;
 }
--- a/hotspot/src/os_cpu/linux_s390/vm/os_linux_s390.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/linux_s390/vm/os_linux_s390.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -473,11 +473,11 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-// These sizes exclude libc stack guard pages, but include
-// the HotSpot guard pages.
-size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 236 * K;
-size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = (52 DEBUG_ONLY(+ 32)) * K;
+size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 8)) * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 32 * K;
 
 // Return default stack size for thr_type.
 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
--- a/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -681,8 +681,10 @@
 ///////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 
 // return default stack size for thr_type
--- a/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -677,15 +677,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 // thread stack
 
-#ifdef AMD64
-size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 48 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 40 * K;
+#ifdef _LP64
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 #else
-size_t os::Posix::_compiler_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
-size_t os::Posix::_java_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = (48 DEBUG_ONLY(+ 4)) * K;
-#endif // AMD64
+#endif // _LP64
 
 // return default stack size for thr_type
 size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
--- a/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -81,15 +81,13 @@
 
 #define MAX_PATH (2 * K)
 
-// Minimum stack size for the VM.  It's easier to document a constant
-// but it's different for x86 and sparc because the page sizes are different.
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+size_t os::Posix::_compiler_thread_min_stack_allowed = 104 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 86 * K;
 #ifdef _LP64
-size_t os::Posix::_compiler_thread_min_stack_allowed = 128 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 128 * K;
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 128 * K;
 #else
-size_t os::Posix::_compiler_thread_min_stack_allowed = 96 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 96 * K;
 size_t os::Posix::_vm_internal_thread_min_stack_allowed = 96 * K;
 #endif
 
--- a/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp	Mon Dec 19 15:48:57 2016 -0800
@@ -86,19 +86,23 @@
 
 #define MAX_PATH (2 * K)
 
-// Minimum stack sizes for the VM.  It's easier to document a constant value
-// but it's different for x86 and sparc because the page sizes are different.
+// Minimum usable stack sizes required to get to user code. Space for
+// HotSpot guard pages is added later.
+#ifdef _LP64
+size_t os::Posix::_compiler_thread_min_stack_allowed = 202 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 48 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 224 * K;
+#else
+size_t os::Posix::_compiler_thread_min_stack_allowed = 32 * K;
+size_t os::Posix::_java_thread_min_stack_allowed = 32 * K;
+size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
+#endif // _LP64
+
 #ifdef AMD64
-size_t os::Posix::_compiler_thread_min_stack_allowed = 394 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 224 * K;
-size_t os::Posix::_vm_internal_thread_min_stack_allowed = 224 * K;
 #define REG_SP REG_RSP
 #define REG_PC REG_RIP
 #define REG_FP REG_RBP
 #else
-size_t os::Posix::_compiler_thread_min_stack_allowed = 64 * K;
-size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
-size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
 #define REG_SP UESP
 #define REG_PC EIP
 #define REG_FP EBP
--- a/hotspot/src/share/vm/runtime/os.hpp	Tue Nov 08 16:30:36 2016 +0100
+++ b/hotspot/src/share/vm/runtime/os.hpp	Mon Dec 19 15:48:57 2016 -0800
@@ -436,7 +436,7 @@
     vm_thread,
     cgc_thread,        // Concurrent GC thread
     pgc_thread,        // Parallel GC thread
-    java_thread,
+    java_thread,       // Java, CodeCacheSweeper, JVMTIAgent and Service threads.
     compiler_thread,
     watcher_thread,
     os_thread