Skip to content

Conversation

@headius
Copy link
Member

@headius headius commented Mar 6, 2025

The previous functionality was provided by the backported pure-Ruby version of Data, which had several issues:

  • Missing several pieces of functionality, like with and deconstruction.
  • Uses instance variables and as a result incompatible with Marshal expectations.
  • Slow and complex.

The new implementation is based upon our existing object-shaping logic. Members declared to define are set up as Java fields and the resulting Data subtype will allocate a right-sized RubyObject to hold them. All accesses of the Data members should optimize to direct Java field accesses.

@headius headius added this to the JRuby 10.0.0.0 milestone Mar 6, 2025
headius added 3 commits March 6, 2025 14:26
This version replaces the backport pure-Ruby version and passes
all CRuby tests and ruby/spec specs for Data other than those
relating to Marshal.
Data is a confusing type in CRuby, because although it does not
extend from Struct, it looks like Struct internally for all other
purposes.

In JRuby, where we are implementing Data as a specialized
RubyObject subclass, we have no way to identify the instances as
either Data or Struct. This makes marshal's narrowing of Data to
Struct a bit tricky to support.

This issue also means we cannot currently support extending a
Data class with another concrete Ruby class, because the field
specialization must live on the nearest concrete type. The effect
of this is that extended Data classes will fail to see their own
members and raise an error on construction.

Barring the issues with extended Data classes, all specs for Data
marshaling are now green.
@headius headius merged commit cd3f2f1 into jruby:10-dev Mar 7, 2025
55 of 73 checks passed
@headius headius deleted the native_data branch March 7, 2025 02:57
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