-
Notifications
You must be signed in to change notification settings - Fork 32
Various cleanup for JRuby ext #85
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
Conversation
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.
This is merged and can be released any time. |
(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
# JRuby errors when setting pos to an out-of-range value | ||
f.pos = RbConfig::LIMITS["LONG_MAX"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any plan to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be because ByteList
cannot handle long
s.
That means JRuby cannot make 4 2GiB StringIO
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.