Skip to content

Dereference proc from interface impl singleton#5820

Merged
headius merged 3 commits intojruby:masterfrom
headius:detach_interface_proc
Aug 8, 2019
Merged

Dereference proc from interface impl singleton#5820
headius merged 3 commits intojruby:masterfrom
headius:detach_interface_proc

Conversation

@headius
Copy link
Member

@headius headius commented Aug 8, 2019

By holding a reference to the proc, we anchor the proc's binding to the singleton class. When methods from the singleton class are cached elsewhere, such as for Java interface proxies (see GH-4968) we end up keeping the proc's binding alive longer than we'd like.

This patch detaches the proc object from the singleton, instead pointing it at the Proc class. The side effects from this include(at least) that any new singleton methods defined on that proc's singleton class will dispatch to hook methods (like singleton_method_defined) on Proc, rather than on the proc object. It's unknown whether this would affect any existing code.

By holding a reference to the proc, we anchor the proc's binding
to the singleton class. When methods from the singleton class are
cached elsewhere, such as for Java interface proxies (see jrubyGH-4968)
we end up keeping the proc's binding alive longer than we'd like.

This patch detaches the proc object from the singleton, instead
pointing it at the Proc class. The side effects from this include
(at least) that any new singleton methods defined on that proc's
singleton class will dispatch to hook methods (like
singleton_method_defined) on Proc, rather than on the proc object.
It's unknown whether this would affect any existing code.
@headius headius changed the title Detach the proc from the singleton class. Dereference proc from interface impl singleton Aug 8, 2019
headius added 2 commits August 8, 2019 14:49
This avoids detaching the object for user-provided singleton procs
where they may actually want the hard reference and hook callbacks
to work as before.

See jrubyGH-4968.
This is a test that the fix for jrubyGH-4968 does not break existing
singleton procs' "attached" relationship. The self in the
singleton_method_added hook should still be the proc, rather than
a reattached value as in the fix.
@headius
Copy link
Member Author

headius commented Aug 8, 2019

Approved by @enebo and @kares.

@headius headius added this to the JRuby 9.2.8.0 milestone Aug 8, 2019
@headius headius merged commit 642a1e2 into jruby:master Aug 8, 2019
@headius headius deleted the detach_interface_proc branch August 8, 2019 20:47
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