-
Notifications
You must be signed in to change notification settings - Fork 5.9k
8236569: -Xss not multiple of 4K does not work for the main thread on macOS #4256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back henryjen! A progress list of the required criteria for merging this PR into |
Webrevs
|
@@ -722,6 +723,16 @@ static void MacOSXStartup(int argc, char *argv[]) { | |||
return (void*)(intptr_t)JavaMain(args); | |||
} | |||
|
|||
static size_t alignUp(size_t stack_size) { | |||
long page_size = sysconf(_SC_PAGESIZE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In hotspot we use getpagesize()
. There is also a guard for a very large stack (within a page of SIZE_MAX) so that rounding up does not produce zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like that (getpagesize) should work with m1 mac as well, as they have 16k pages. will it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sysconf is the portable way based on POSIX, we can use getpagesize give this is macOS specific code, which is BSD based.
Withdraw for keep current behavior for compatibility. It would be preferred for user to specify proper value than we change the value on user's behalf. |
I'm a bit confused about the state of this PR. It was closed/withdrawn but then reopened but with changes applied to platforms other than macOS - why? |
Also the code does not compile on Linux in current form. |
Planned to close JDK-8236569 as 'Won't Fix', as the issue was re-opened, we give it another shot. As explained in the CSR review, we will only round-up the stack size as required by the operating system. Test on Ubuntu shows that there is no need to round-up, while some other Posix system might as explained in the man page. |
What manpage? The POSIX specification for this does not allow for EINVAL being returned due to alignment issues. That is an extra constraint imposed by macOS and which makes it non-conforming to the POSIX spec IMO. While the changes in src/java.base/unix/native/libjli/java_md.c seem perfectly fine, are we actually ever going to execute it? |
Linux man page for pthread_attr_setstacksize() states that,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Henry,
I'm okay with these changes in the current form.
The help text needs tweaking - see CSR request.
Thanks,
David
@@ -172,6 +172,8 @@ java.launcher.X.usage=\n\ | |||
\ (Linux Only) show host system or container\n\ | |||
\ configuration and continue\n\ | |||
\ -Xss<size> set java thread stack size\n\ | |||
\ The actual size may be round up to multiple of system\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See updated help text in the CSR request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks
@slowhog This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 684 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
proposed shorter form. Otherwise this looks fine.
Cheers, Thomas
} | ||
return page_size * pages; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably be shortened to something like this:
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
return (stack_size + (pagesize - 1)) & ~(pagesize - 1);
or, if you insist on checking for SIZE_MAX:
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
size_t max = SIZE_MAX - pagesize;
return stack_size <= max ? (stack_size + (pagesize - 1)) & ~(pagesize - 1) : max;
(I see David requested this, so this is fine, though passing SIZE_MAX to this function will quite likely fail anyway :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While sysconf(_SC_PAGESIZE) is most likely(if not always) be power of 2, it's not a constant we know for sure here and this is not critical path for performance, thus I didn't take that approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern was not performance but brevity, especially since you add the same function twice. And about using the same logic for aligning up as we do within hotspot (see align.hpp). You also mix up size_t and long (signed vs unsigned, and potentially different sizes) - there is nothing obvious wrong with that but I would at least consistently use size_t here.
Please make sure the failing tests have nothing to do with your patch. |
Mailing list message from David Holmes on core-libs-dev: On 8/06/2021 11:40 pm, Thomas Stuefe wrote:
warning: using incubating module(s): jdk.incubator.foreign Looks like shenandoah test was not updated for latest Foreign changes. David |
Mailing list message from David Holmes on core-libs-dev: On 8/06/2021 11:40 pm, Thomas Stuefe wrote:
warning: using incubating module(s): jdk.incubator.foreign Looks like shenandoah test was not updated for latest Foreign changes. David |
@slowhog This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Still pending CSR, also considering adapt hotspot align up as suggested by @tstuefe. |
|
||
if (stack_size > 0) { | ||
pthread_attr_setstacksize(&attr, stack_size); | ||
if (EINVAL == pthread_attr_setstacksize(&attr, stack_size)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style-wise it might be more consistent put EINVAL on the RHS of the ==.
@slowhog This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@slowhog This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
/open |
@asotona Only the pull request author can set the pull request state to "open" |
Continuation in #8953 |
…d on macOS
This patch simply round up the specified stack size to multiple of the system page size.
Test is trivial, simply run java with -Xss option against following code. On MacOS, before the fix, running with
-Xss159k
and-Xss160k
would get7183
and649
respectively. After fix, both would output649
, while-Xss161k
would be same as-Xss164k
and see 691 as the output.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4256/head:pull/4256
$ git checkout pull/4256
Update a local copy of the PR:
$ git checkout pull/4256
$ git pull https://git.openjdk.java.net/jdk pull/4256/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4256
View PR using the GUI difftool:
$ git pr show -t 4256
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4256.diff