Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
/ jdk20 Public archive

8298400: Virtual thread instability when stack overflows #101

Closed
wants to merge 4 commits into from

Conversation

pron
Copy link
Member

@pron pron commented Jan 12, 2023

The stack overflow is detected in the native code and a pending exception is set, but it is not thrown.

Additionally, the stack overflow detection is changed use StackOverflow::shadow_zone_safe_limit rather than StackOverflow::stack_overflow_limit.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8298400: Virtual thread instability when stack overflows

Reviewers

Contributors

  • Fei Yang <fyang@openjdk.org>
  • Richard Reingruber <rrich@openjdk.org>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk20 pull/101/head:pull/101
$ git checkout pull/101

Update a local copy of the PR:
$ git checkout pull/101
$ git pull https://git.openjdk.org/jdk20 pull/101/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 101

View PR using the GUI difftool:
$ git pr show -t 101

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk20/pull/101.diff

@pron pron closed this Jan 12, 2023
@pron pron reopened this Jan 12, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Jan 12, 2023

👋 Welcome back rpressler! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 12, 2023

@pron The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Jan 12, 2023
@dean-long
Copy link
Member

I'm wondering if both gen_continuation_enter and gen_continuation_yield can handle exceptions the same way. Have _yield set an exception_offset, so there is no overhead when there is no exception. Then if _yield can use StubRoutines::forward_exception_entry, then _enter probably can too.

@dean-long
Copy link
Member

dean-long commented Jan 13, 2023

It seems like this exception handling problem would have existed before JDK-8292584, when _yield was a stub. At least I'm not aware of stubs have automatic exception handling.

@pron
Copy link
Member Author

pron commented Jan 13, 2023

There is a difference between enter and yield. enter may call a Java method, and that is the only way it may have an exception (as thaw never throws an exception from native code, only in the special case of a SOE, thrown in generate_cont_thaw, so I don't think it uses pending exceptions). yield, on the other hand, never calls a Java method, and only throws exceptions from native code.

There is no added overhead in yield, because the exception handling code is only reached when the continuation is pinned, which we check anyway (and should be rare).

…stack_overflow_limit in stack overflow tests in continuationFreezeThaw.cpp
@pron pron marked this pull request as ready for review January 18, 2023 00:43
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 18, 2023
@mlbridge
Copy link

mlbridge bot commented Jan 18, 2023

Webrevs

@RealFYang
Copy link
Member

Looks like the hang is still there with this fix on aarch64 using fastdebug build?

@pron
Copy link
Member Author

pron commented Jan 18, 2023

There are still failures, but I'm trying to understand from @theRealAph whether it's a separate, scoped-value-specific problem.

@pron
Copy link
Member Author

pron commented Jan 18, 2023

@theRealAph says the remaining failures are a separate ScopedValue bug.

@RealFYang
Copy link
Member

RealFYang commented Jan 19, 2023

Also prepared a small change for RISC-V which has passed sanity test.
Could you please incorporate it while you are on it? Thanks.

diff --git a/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp b/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp
index d2992b9012b..56899a3a234 100644
--- a/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp
+++ b/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp
@@ -1095,6 +1095,15 @@ static void gen_continuation_yield(MacroAssembler* masm,

   __ bind(pinned); // pinned -- return to caller

+  // handle pending exception thrown by freeze
+  __ ld(t0, Address(xthread, in_bytes(Thread::pending_exception_offset())));
+  Label ok;
+  __ beqz(t0, ok);
+  __ leave();
+  __ la(t0, RuntimeAddress(StubRoutines::forward_exception_entry()));
+  __ jr(t0);
+  __ bind(ok);
+
   __ leave();
   __ ret();

Copy link
Member

@dean-long dean-long left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@openjdk
Copy link

openjdk bot commented Jan 19, 2023

@pron 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:

8298400: Virtual thread instability when stack overflows

Co-authored-by: Fei Yang <fyang@openjdk.org>
Co-authored-by: Richard Reingruber <rrich@openjdk.org>
Reviewed-by: dlong, pchilanomate

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 25 new commits pushed to the master branch:

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 19, 2023
Copy link
Contributor

@pchilano pchilano left a comment

Choose a reason for hiding this comment

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

Looks good.

Thanks,
Patricio

@pron
Copy link
Member Author

pron commented Jan 19, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Jan 19, 2023

@pron An unexpected error occurred during integration. No push attempt will be made. The error has been logged and will be investigated. It is possible that this error is caused by a transient issue; feel free to retry the operation.

@reinrich
Copy link
Member

@pron pity you did not wait 5min after the second review. I wanted to add the ppc version.

@reinrich
Copy link
Member

I was still testing.

FTR

diff --git a/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp b/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp
index 2cd3323f181..27e2bae6ab7 100644
--- a/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp
+++ b/src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp
@@ -1990,6 +1990,19 @@ static void gen_continuation_yield(MacroAssembler* masm,
 
   __ bind(L_pinned); // pinned -- return to caller
 
+  // handle pending exception thrown by freeze
+  Label ok;
+  __ ld(tmp, in_bytes(JavaThread::pending_exception_offset()), R16_thread);
+  __ cmpdi(CCR0, tmp, 0);
+  __ beq(CCR0, ok);
+  __ pop_frame();
+  __ ld(R0, _abi0(lr), R1_SP); // Return pc
+  __ mtlr(R0);
+  __ load_const_optimized(tmp, StubRoutines::forward_exception_entry(), R0);
+  __ mtctr(tmp);
+  __ bctr();
+  __ bind(ok);
+
   // Pop frame and return
   __ pop_frame();
   __ ld(R0, _abi0(lr), R1_SP); // Return pc

@pron
Copy link
Member Author

pron commented Jan 19, 2023

@reinrich The integration failed for some reason, so I'll try adding that as well.

@reinrich
Copy link
Member

@reinrich The integration failed for some reason, so I'll try adding that as well.

Ok. Thank you.

@pron
Copy link
Member Author

pron commented Jan 19, 2023

/contributor add @RealFYang

@pron
Copy link
Member Author

pron commented Jan 19, 2023

/contributor add @reinrich

@openjdk
Copy link

openjdk bot commented Jan 19, 2023

@pron
Contributor Fei Yang <fyang@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented Jan 19, 2023

@pron
Contributor Richard Reingruber <rrich@openjdk.org> successfully added.

@pron
Copy link
Member Author

pron commented Jan 19, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Jan 19, 2023

Going to push as commit 1c84050.
Since your change was applied there have been 25 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 19, 2023
@openjdk openjdk bot closed this Jan 19, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 19, 2023
@openjdk
Copy link

openjdk bot commented Jan 19, 2023

@pron Pushed as commit 1c84050.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
5 participants