Skip to content

Commit

Permalink
Add a property to configure eager constants
Browse files Browse the repository at this point in the history
In order to avoid polluting the Java:: namespace with classes from
other classloader hierarchies, we are modifying the proxy class
setup process to not eagerly set a constant for newly-encountered
classes. This property controls the behavior, defaulting to true
for JRuby 9.4.x but likely to switch to false in a future release
(probably JRuby 10).

The constants will still be defined if accessed directly, as
before. We just won't define them when we happen to see an object
with an unfamiliar type.

See jruby#8208 and the bug it fixed jruby#8156.
  • Loading branch information
headius committed Apr 25, 2024
1 parent 31f1ed6 commit 1165d44
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/Java.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public static RubyModule getProxyClass(Ruby runtime, JavaClass javaClass) {

@SuppressWarnings("deprecation")
public static RubyModule getProxyClass(final Ruby runtime, final Class<?> clazz) {
return getProxyClass(runtime, clazz, false);
return getProxyClass(runtime, clazz, Options.JI_EAGER_CONSTANTS.load());
}

@SuppressWarnings("deprecation")
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public class Options {
public static final Option<Boolean> JI_LOAD_LAZY = bool(JAVA_INTEGRATION, "ji.load.lazy", true, "Load Java support (class extensions) lazily on demand or ahead of time.");
public static final Option<Boolean> JI_CLOSE_CLASSLOADER = bool(JAVA_INTEGRATION, "ji.close.classloader", false, "Close the JRubyClassLoader used by each runtime");
public static final Option<String> JI_NESTED_JAR_TMPDIR = string(JAVA_INTEGRATION, "ji.nested.jar.tmpdir", "Use specified dir as a base for unpacking nested jar files.");
public static final Option<Boolean> JI_EAGER_CONSTANTS = bool(JAVA_INTEGRATION, "ji.eager.constants", true, "Eagerly bind Java:: constants for newly-encountered classes");

public static final Option<Integer> PROFILE_MAX_METHODS = integer(PROFILING, "profile.max.methods", 100000, "Maximum number of methods to consider for profiling.");

Expand Down

0 comments on commit 1165d44

Please sign in to comment.