Skip to content

Store MethodGatherer's filtered methods as JDK types - #9895

Merged
headius merged 2 commits into
jruby:jruby-10.0from
matrei:fix/method-gatherer-jdk-values
Oct 27, 2026
Merged

headius merged 2 commits into
jruby:jruby-10.0from
matrei:fix/method-gatherer-jdk-values

Conversation

@matrei

@matrei matrei commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Part of #9781, against jruby-10.0 for the 10.0 LTS line.

FILTERED_DECLARED_METHODS and FILTERED_METHODS are static ClassValues, and they're computed for JDK classes too: creating a runtime already computes them for java.lang.Object, java.lang.Class, java.util.Map and others. A ClassValue stores its value in the class it's computed for. The values were PartitionedMethods, a JRuby class, so the JDK classes, which are never unloaded, kept the class loader that loaded JRuby alive after every runtime in it was torn down.

They can't be cleared at teardown, because they're shared by every runtime in the class loader, and they only matter once the whole class loader goes away. Instead, the values are now Method[][], indexed by INSTANCE_METHODS and STATIC_METHODS, so what's left on JDK classes only references JDK types.

There are two commits:

  1. Moves filterAccessible out of PartitionedMethods into MethodGatherer, unchanged. git show -w shows only the moved closing brace.
  2. Replaces PartitionedMethods with partitionMethods, which returns the Method[][]. filterAccessible and its Java 17 handling are untouched.

rake spec:ji passes (974 examples, 0 failures, 9 pending). rake spec:ruby:fast has 1 failure and 4 errors, all IPv6 socket specs that fail the same way on unmodified jruby-10.0, because my machine has no IPv6 network.

It is unchanged, only moved up from the nested class to MethodGatherer,
so that the next commit can replace PartitionedMethods without touching
it.
FILTERED_DECLARED_METHODS and FILTERED_METHODS are static ClassValues
that are also computed for JDK classes, such as java.lang.Object and
java.lang.Class. Their PartitionedMethods values are a JRuby class, so
the JDK classes kept the class loader that loaded JRuby alive after
every runtime in it was torn down.

The values are now Method[][], indexed by INSTANCE_METHODS and
STATIC_METHODS.
@headius headius added this to the JRuby 10.0.8.0 milestone Oct 27, 2026

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unfortunate side-effect of ClassValue rooting objects, but can't be helped. The JRuby-specific wrapper class is replaced by the raw Method[][] it contained, which is a system-level class and won't keep JRuby's classloader alive.

@headius
headius merged commit b6ff755 into jruby:jruby-10.0 Oct 27, 2026
125 of 127 checks passed
@matrei
matrei deleted the fix/method-gatherer-jdk-values branch October 27, 2026 18:17
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