Use NoSafepointVerifier + avoid extra safepoint in Unsafe_CopySwapMemory0
#2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 newUNSAFE_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.