RFR: 8236569: -Xss not multiple of 4K does not work for the main thread on macOS [v5]

Henry Jen henryjen at openjdk.java.net
Mon Jun 7 03:25:03 UTC 2021


On Mon, 7 Jun 2021 03:18:32 GMT, Henry Jen <henryjen at openjdk.org> wrote:

>> …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 get `7183` and `649` respectively. After fix, both would output `649`, while `-Xss161k` would be same as `-Xss164k` and see 691 as the output.
>> 
>> ```code:java
>> public class StackLeak {
>>     public int depth = 0;
>>     public void stackLeak() {
>>         depth++;
>>         stackLeak();
>>     }
>> 
>>     public static void main(String[] args) {
>>         var test = new StackLeak();
>>         try {
>>             test.stackLeak();
>>         } catch (Throwable e) {
>>             System.out.println(test.depth);
>>         }
>>     }
>> }
>
> Henry Jen has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains seven additional commits since the last revision:
> 
>  - Cast type
>  - Merge
>  - Change java -X output for -Xss
>  - Merge
>  - Only try to round-up when current value failed
>  - Avoid overflow on page size
>  - JDK-8236569: -Xss not multiple of 4K does not work for the main thread on macOS

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.
We round-up for MacOS as the document explicitly said that the size need to be multiple of system page size. I also changed to use getpagesize() as you suggested, although that's not needed.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4256


More information about the core-libs-dev mailing list