--- a/hotspot/src/os/linux/vm/os_linux.cpp Thu Mar 23 17:45:13 2017 +0100
+++ b/hotspot/src/os/linux/vm/os_linux.cpp Thu Mar 23 11:10:55 2017 -0700
@@ -723,9 +723,16 @@
// the size of the guard pages to the stack size, instead Linux
// takes the space out of 'stacksize'. Thus we adapt the requested
// stack_size by the size of the guard pages to mimick proper
- // behaviour.
- stack_size = align_size_up(stack_size + os::Linux::default_guard_size(thr_type), vm_page_size());
- pthread_attr_setstacksize(&attr, stack_size);
+ // behaviour. However, be careful not to end up with a size
+ // of zero due to overflow. Don't add the guard page in that case.
+ size_t guard_size = os::Linux::default_guard_size(thr_type);
+ if (stack_size <= SIZE_MAX - guard_size) {
+ stack_size += guard_size;
+ }
+ assert(is_size_aligned(stack_size, os::vm_page_size()), "stack_size not aligned");
+
+ int status = pthread_attr_setstacksize(&attr, stack_size);
+ assert_status(status == 0, status, "pthread_attr_setstacksize");
// Configure glibc guard page.
pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type));