mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8236569: -Xss not multiple of 4K does not work for the main thread on macOS
Reviewed-by: dholmes, stuefe
This commit is contained in:
parent
7159976335
commit
7846971381
4 changed files with 43 additions and 2 deletions
|
@ -651,6 +651,20 @@ static void* ThreadJavaMain(void* args) {
|
|||
return (void*)(intptr_t)JavaMain(args);
|
||||
}
|
||||
|
||||
static size_t adjustStackSize(size_t stack_size) {
|
||||
long page_size = sysconf(_SC_PAGESIZE);
|
||||
if (stack_size % page_size == 0) {
|
||||
return stack_size;
|
||||
} else {
|
||||
long pages = stack_size / page_size;
|
||||
// Ensure we don't go over limit
|
||||
if (stack_size <= SIZE_MAX - page_size) {
|
||||
pages++;
|
||||
}
|
||||
return page_size * pages;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Block current thread and continue execution in a new thread.
|
||||
*/
|
||||
|
@ -661,9 +675,17 @@ CallJavaMainInNewThread(jlong stack_size, void* args) {
|
|||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
size_t adjusted_stack_size;
|
||||
|
||||
if (stack_size > 0) {
|
||||
pthread_attr_setstacksize(&attr, stack_size);
|
||||
if (pthread_attr_setstacksize(&attr, stack_size) == EINVAL) {
|
||||
// System may require stack size to be multiple of page size
|
||||
// Retry with adjusted value
|
||||
adjusted_stack_size = adjustStackSize(stack_size);
|
||||
if (adjusted_stack_size != (size_t) stack_size) {
|
||||
pthread_attr_setstacksize(&attr, adjusted_stack_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue