Skip to content
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

Use NoSafepointVerifier + avoid extra safepoint in Unsafe_CopySwapMemory0 #2

Conversation

JornVernee
Copy link

  • Use NoSafepointVerifier to verify that we don't actually get a safepoint after checking for async exception handshake. Not every unsafe function is compatible with this, so I've introduced a new UNSAFE_ENTRY_SCOPED macro that can be used for unsafe functions called in the context of @Scoped methods (from ScopedMemoryAccess).

  • Unsafe_CopySwapMemory0 was actually polling for safepoint halfway into the function. This function tries to stay in the native thread state for off-heap -> off-heap copies, to avoid blocking the GC, and then lazily transitions to VM state when heap memory is involved. I've flipped this around so that we instead lazily transition to native state when we do a pure off-heap copy. I believe this is also required for safely checking for async exception handshakes, as we potentially take a lock for that, so should be in VM mode (I think?). Unfortunately, this means that we will now have 2 thread state transitions for the purely off-heap case: one from native to VM when the function is entered, and one from VM to native just before the copy. While unfortunate, I don't see a good way around this, as we need to check for async exception handshakes upon entering the method in case of any previous safepoint poll having installed a handshake. The additional state transitions could be avoided by intrinsifying the method, similar to how Unsafe_CopyMemory0 is already intrinsified.

@fisk fisk merged commit 0b91ac9 into fisk:8310644_panama_async_handshake_close Nov 24, 2023
@JornVernee JornVernee deleted the PR_async_close+ASYNC_EXCEPTION_CHECK branch November 24, 2023 15:49
fisk pushed a commit that referenced this pull request Oct 25, 2024
fisk pushed a commit that referenced this pull request Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants