Skip to content

Improve tagged pointer emulation#6545

Merged
headius merged 2 commits intojruby:masterfrom
headius:fake_flonums
Feb 1, 2021
Merged

Improve tagged pointer emulation#6545
headius merged 2 commits intojruby:masterfrom
headius:fake_flonums

Conversation

@headius
Copy link
Member

@headius headius commented Feb 1, 2021

This commit improves the emulation of CRuby's fixnum and flonum tagged pointers.

Float emulation of flonum:

  • Floats within flonum range will produce a flonum object_id that is reversible by ObjectSpace._id2ref.
  • Float objects with equivalent values within flonum range are considered identical via equal?.
  • RubyFloat.eql overrides the default RubyBasicObject.eql dynamic dispatch, as in RubyFixnum.

Fixnum emulation of fixnum:

  • Fixnum objects with equivalent values within fixnum range only are considered identical via equal?. Previously all equivalent Fixnum objects were considered equal?.

Impact to existing behavior:

  • Floats within range will now behave like flonums on CRuby rather than as independent objects.
  • Fixnums outside of fixnum range will behave like independent objects for identity purposes.
  • In order to accommodate the flonum IDs in _id2ref, non-fixnum non-flonum values are now modulo 4. This means we have halved the number of incremental object ID values available (Long.MAX_VALUE / 4 versus Long.MAX_VALUE / 2 for fixnum emulation alone).

See ruby/spec#829 for some discussion of this.

* Floats are considered equal? if they have the same value within
  flonum range.
* Float#object_id and ObjectSpace.id2ref produce and recognize the
  flonum bits for round-tripping IDs.
* RubyFloat.eql added to short-circuit RubyBasicObject.eql dynamic
  call.

Ref ruby/spec#829
@headius headius added this to the JRuby 9.3.0.0 milestone Feb 1, 2021
In CRuby, only integer values within the valid range for fixnum
tagged pointers are considered identical. JRuby considered all
Fixnum objects identical. This commit narows the JRuby identity
logic to only values within the fixnum tagged pointer range.
@headius headius merged commit 222eec9 into jruby:master Feb 1, 2021
@headius headius deleted the fake_flonums branch February 1, 2021 23:21
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.

1 participant