Skip to content

Commit

Permalink
Use a lookup() for field access in static constant
Browse files Browse the repository at this point in the history
This field access appears to trigger a bug in Java 8 and 11 (at
least) leading to linkage errors and classes leaking across
classloaders when a method handle is resolved at static
initialization time.

See jruby#7911

The change here provides a local MethodHandles.Lookup object
rather than using a publicLookup() to acquire the field handle.
This may work around whatever the JDK bug was.

Fixes jruby#7911
  • Loading branch information
headius committed Oct 6, 2023
1 parent 852abd4 commit ab934e6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/targets/indy/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,10 @@ public static CallSite contextValueString(Lookup lookup, String name, MethodType
.from(Ruby.class, ThreadContext.class, MutableCallSite.class)
.invokeStaticQuiet(LOOKUP, Bootstrap.class, "runtime");

// We use LOOKUP here to have a full-featured MethodHandles.Lookup, avoiding jruby/jruby#7911
private static final MethodHandle RUNTIME_FROM_CONTEXT_HANDLE =
Binder
.from(Ruby.class, ThreadContext.class)
.from(LOOKUP, Ruby.class, ThreadContext.class)
.getFieldQuiet("runtime");

private static final MethodHandle NIL_HANDLE =
Expand Down

0 comments on commit ab934e6

Please sign in to comment.