On thread start or attach, we query the OS for the stack dimensions of the current stack. These dimensions are normally 4k page aligned, but do not have to be. Very rarely we get an unaligned stack bottom (top is never aligned but that does not matter), typically for the initial thread. In that case we fail to establish the red/yellow guard pages and the VM dies during initialization.
The picture is even more complicated because in 64k page mode, we keep up the notion of 64k-paged-everything, which is not true. Even then pthread stacks are only 4k page aligned. In order to prevent errors further down, stack dimensions - and hence guardpage placement - should be 64k page aligned in this mode.
In short, we need to always align stack bottom up to os::vm_page_size(), be it 4K or 64K.
The picture is even more complicated because in 64k page mode, we keep up the notion of 64k-paged-everything, which is not true. Even then pthread stacks are only 4k page aligned. In order to prevent errors further down, stack dimensions - and hence guardpage placement - should be 64k page aligned in this mode.
In short, we need to always align stack bottom up to os::vm_page_size(), be it 4K or 64K.