Skip to content
Permalink
Browse files
8273373: Zero: Cannot invoke JVM in primordial threads on Zero
Backport-of: 0f31d0fb2c0d5db305e75e1d61bcc44de3e77839
  • Loading branch information
shipilev committed Oct 4, 2021
1 parent c5446c1 commit b5d4060
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
@@ -3354,6 +3354,9 @@ bool os::pd_create_stack_guard_pages(char* addr, size_t size) {

if (mincore((address)stack_extent, os::vm_page_size(), vec) == -1) {
// Fallback to slow path on all errors, including EAGAIN
assert((uintptr_t)addr >= stack_extent,
"Sanity: addr should be larger than extent, " PTR_FORMAT " >= " PTR_FORMAT,
p2i(addr), stack_extent);
stack_extent = (uintptr_t) get_stack_commited_bottom(
os::Linux::initial_thread_stack_bottom(),
(size_t)addr - stack_extent);
@@ -199,6 +199,20 @@ size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
}

static void current_stack_region(address *bottom, size_t *size) {
if (os::is_primordial_thread()) {
// primordial thread needs special handling because pthread_getattr_np()
// may return bogus value.
address stack_bottom = os::Linux::initial_thread_stack_bottom();
size_t stack_bytes = os::Linux::initial_thread_stack_size();

assert(os::current_stack_pointer() >= stack_bottom, "should do");
assert(os::current_stack_pointer() < stack_bottom + stack_bytes, "should do");

*bottom = stack_bottom;
*size = stack_bytes;
return;
}

pthread_attr_t attr;
int res = pthread_getattr_np(pthread_self(), &attr);
if (res != 0) {
@@ -247,18 +261,6 @@ static void current_stack_region(address *bottom, size_t *size) {

pthread_attr_destroy(&attr);

// The initial thread has a growable stack, and the size reported
// by pthread_attr_getstack is the maximum size it could possibly
// be given what currently mapped. This can be huge, so we cap it.
if (os::is_primordial_thread()) {
stack_bytes = stack_top - stack_bottom;

if (stack_bytes > JavaThread::stack_size_at_create())
stack_bytes = JavaThread::stack_size_at_create();

stack_bottom = stack_top - stack_bytes;
}

assert(os::current_stack_pointer() >= stack_bottom, "should do");
assert(os::current_stack_pointer() < stack_top, "should do");

1 comment on commit b5d4060

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.