Merged
Conversation
Contributor
headius
commented
Mar 13, 2024
- Fix compile warnings on latest Java.
- Adjust one test for JRuby erroring on bad pos= value.
- Replace hard JVM synchronization with a spin lock.
- Avoid duplicate reads of state fields where possible.
- Remove long-deprecated codepoints, chars, bytes, lines methods.
- Mark fcntl as not implemented
- Split most of the remaining variable-arity methods.
Warnings about release=8 can't be avoided at the moment. JRuby 10 will bump minimum up to 17 or 21 and we will deal with bumping the Java version for StringIO then.
Being based on JVM, JRuby cannot support a byte[] size larger than a signed in, and it checks that the position is within that range at the time it is set rather than when it is used by other operations. This patch moves the position set into the assertion so it will pass on both JRuby and other implementations.
All of these operations are leaves, so no reentrancy is necessary. None of them make any blocking calls, either, so they should return very quickly. And use of StringIO under concurrent load is very unusual and unlikely to lead to contention. This patch switches from using hard JVM synchronization to instead just spin- lock on an atomic int value associated with the data ptr object. Performance on a benchmark of the Prism parser from ruby/prism#2358 shows a reduction per loop from 0.050s to 0.044s.
Removed in 2020 from CRuby (ruby/stringio@48fdd28e727ff2) after being deprecated since 2012.
The few I did not convert make calls back into JRuby that require argument arrays anyway, so no value in splitting them until JRuby has split paths downstream.
Contributor
Author
|
This is merged and can be released any time. |
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Mar 13, 2024
(ruby/stringio#85) * Fix compile warnings on latest Java. * Adjust one test for JRuby erroring on bad pos= value. * Replace hard JVM synchronization with a spin lock. * Avoid duplicate reads of state fields where possible. * Remove long-deprecated codepoints, chars, bytes, lines methods. * Mark fcntl as not implemented * Split most of the remaining variable-arity methods. ruby/stringio@31a9d42e6c
nobu
reviewed
Mar 13, 2024
Comment on lines
+241
to
+242
| # JRuby errors when setting pos to an out-of-range value | ||
| f.pos = RbConfig::LIMITS["LONG_MAX"] |
Member
There was a problem hiding this comment.
This seems to be because ByteList cannot handle longs.
That means JRuby cannot make 4 2GiB StringIO?
Contributor
Author
There was a problem hiding this comment.
That is correct; there's no plan to fix this because the JVM itself cannot manage arrays larger than a signed integer.
The test change here is due to JRuby detecting pos= set to a value above this size and immediately raising. I think CRuby should also add this behavior for pos= above the maximum range of an array offset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.