Skip to content

Correctly initialize Data field accessors#9253

Open
headius wants to merge 2 commits intojruby:masterfrom
headius:data_field_accessors
Open

Correctly initialize Data field accessors#9253
headius wants to merge 2 commits intojruby:masterfrom
headius:data_field_accessors

Conversation

@headius
Copy link
Copy Markdown
Member

@headius headius commented Feb 18, 2026

Part of the root cause of #9241 was the improper initialization of variable accessors during Data type setup. The changes here attempt to address that and make sure that:

  • Data type fields are properly set up with native Java field accessors. Previously, a specialized object shape was allocated, but the accessors had already been initialized to use the growable varTable. This could lead to child classes having a different view of the varTable and mismatching fields to values.
  • Always copy the parent class's variable table manager to the child. This was previously added just for cases where the direct superclass is Data, which could again lead to child classes forming their own picture of the object's shape.

The changes here extend #9252 and may be too experimental for a 10.0 maintenance release, but without them all Data objects are being allocated much larger than they should be and not using native fields.

Data types are initialized with a set of accessors for the
requested fields, which allows caching those accessors and
avoiding costly hash lookups for future accesses. Due to a bug in
how these accessors are initialized, parent and subclasses may
have a different view of how those fields are stored in the object.

Here, the cached accessors are iterated, but then not used to read
the field. This results in a second field being created for the
subclass, in a different order from definition time. Using the
original accessor here accesses the correct field.

Fixes jruby#9241.

Note that there's other problems with the data layout inside a Data
type and other fixes will be needed to clean up how these accessors
are allocated and shared with subclasses.
There's a few changes here to support Data types and their
subclasses:

* Always copy the variable table manager from parent to child,
  unless the parent is Object. This ensures that Data type
  subclasses still see the same accessors and likely makes sense
  for most other classes that inherit instance variables.
* Fix the definition sequence for Data fields to specialize and
  properly use the field-based accessors rather than the growable
  varTable accessors. This maintains a compact store for Data
  fields where previously the object was specialized but variables
  still were stored in varTable.

This relates to and partially fixes some root causes of the Data
type subclass issues reported in jruby#9241.

There are other concerns with this structure of Data, however,
since it may use accessors from the parent in the child (rather
than the cloned versions for the child). We need a larger overhaul
of both Data and how the variable table manager is propagated from
parents to children (previously no propagation happened and all
child classes re-discovered their own instance variables).
@headius headius force-pushed the data_field_accessors branch from 824a359 to 73b2a99 Compare February 18, 2026 20:56
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