Skip to content

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

Merged
merged 8 commits into from
Mar 13, 2024
Merged

Various cleanup for JRuby ext #85

merged 8 commits into from
Mar 13, 2024

Conversation

headius
Copy link
Contributor

@headius 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.

headius added 7 commits March 12, 2024 17:07
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.
@headius headius marked this pull request as ready for review March 13, 2024 04:45
@headius headius merged commit 31a9d42 into ruby:master Mar 13, 2024
@headius headius deleted the jruby_cleanup branch March 13, 2024 04:46
@headius
Copy link
Contributor Author

headius commented Mar 13, 2024

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
Comment on lines +241 to +242
# JRuby errors when setting pos to an out-of-range value
f.pos = RbConfig::LIMITS["LONG_MAX"]
Copy link
Member

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?

Copy link
Member

@nobu nobu Mar 13, 2024

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 longs.
That means JRuby cannot make 4 2GiB StringIO?

Copy link
Contributor Author

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.

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