Skip to content

Root specialized object classloader at JRuby classloader#8433

Merged
headius merged 3 commits intojruby:masterfrom
headius:specialized_object_classloader
Nov 20, 2024
Merged

Root specialized object classloader at JRuby classloader#8433
headius merged 3 commits intojruby:masterfrom
headius:specialized_object_classloader

Conversation

@headius
Copy link
Member

@headius headius commented Nov 18, 2024

The classes generated here need to be visible to other classes loaded and generated by JRuby, such as Ruby classes that implement Java interfaces. If the specialized class and a Java interface to implement come from different classloader hierarchies, the JVM classloading subsystem will be unable to resolve the impl class.

The fix here makes the RubyObjectSpecializer per-runtime, so the specialized classes live within the standard JRubyClassLoader hierarchy, visible to other classes loaded and generated by Ruby code at runtime.

An additional fix will pre-generate the first 50 specialized object classes, which will also fix the same issue (they will load into the same classloader as JRuby itself) and avoid re-generating these classes for each runtime instance.

Fixes #8412.

The classes generated here need to be visible to other classes
loaded and generated by JRuby, such as Ruby classes that implement
Java interfaces. If the specialized class and a Java interface to
implement come from different classloader hierarchies, the JVM
classloading subsystem will be unable to resolve the impl class.

The fix here makes the RubyObjectSpecializer per-runtime, so the
specialized classes live within the standard JRubyClassLoader
hierarchy, visible to other classes loaded and generated by Ruby
code at runtime.

An additional fix will pre-generate the first 50 specialized
object classes, which will also fix the same issue (they will load
into the same classloader as JRuby itself) and avoid re-generating
these classes for each runtime instance.

Fixes jruby#8412.
@headius headius added this to the JRuby 9.4.10.0 milestone Nov 18, 2024
This patch generates all the specialized widths of RubyObject that
we support, up to the configured maximum. This avoids racing to
to generate these classes and potentially speeds up early boot
stages.
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.

Intermittent exceptions with 'Java::JavaLang::NoClassDefFoundError : org/jruby/gen/RubyObject13'

1 participant