Skip to content

Backport no-inspect NameError logic#8538

Merged
headius merged 3 commits intojruby:masterfrom
headius:no_inspect_nameerror
Jan 15, 2025
Merged

Backport no-inspect NameError logic#8538
headius merged 3 commits intojruby:masterfrom
headius:no_inspect_nameerror

Conversation

@headius
Copy link
Member

@headius headius commented Dec 20, 2024

This is a backport of the no-inspect NameError logic added to JRuby 10 in #8533, guarded by an option for users on JRuby 9.4.

On 9.4, the inspect logic is enabled by default, but can be disabled by with the option -XnameError.inspect.object=false. Because the object inspect is a specified behavior of Ruby 3.1, we can't disable it by default, but this allows users to opt out of the behavior.

JRuby 10 will ignore this logic and avoid inspecting the object attached to the NameError. The option will have no effect.

Using the example from #8384 with this new option:

$ jruby -w -J-Xmx250M -XnameError.inspect.object=false blah.rb
generating large obj
done
NameError: undefined local variable or method `nameerror' for an instance of Test
   error at blah.rb:9
  <main> at blah.rb:16

Interestingly, I discovered that the original code does not OOM on Java 21, because it never seems to call the expected inspect method. I will open an issue to investigate that.

@headius headius added this to the JRuby 9.4.10.0 milestone Dec 20, 2024
headius added a commit to headius/jruby that referenced this pull request Dec 20, 2024
Configure with -Xinspect.nameError.object=true|false. It defaults
to true in JRuby 9.4.10.0 and false in JRuby 10.

Fixes jruby#8538
@headius headius force-pushed the no_inspect_nameerror branch from 818fbc6 to 17f8214 Compare December 20, 2024 04:55
Configure with -Xinspect.nameError.object=true|false. It defaults
to true in JRuby 9.4.10.0 and false in JRuby 10.

Fixes jruby#8384
@enebo
Copy link
Member

enebo commented Dec 20, 2024

This is a backport of the no-inspect NameError logic added to JRuby 10 in #8533, guarded by an option for users on JRuby 9.4.

On 9.4, the inspect logic is enabled by default, but can be disabled by with the option -XnameError.inspect.object=false. Because the object inspect is a specified behavior of Ruby 3.1, we can't disable it by default, but this allows users to opt out of the behavior.

JRuby 10 will ignore this logic and avoid inspecting the object attached to the NameError. The option will have no effect.

Using the example from #8384 with this new option:

$ jruby -w -J-Xmx250M -XnameError.inspect.object=false blah.rb
generating large obj
done
NameError: undefined local variable or method `nameerror' for an instance of Test
   error at blah.rb:9
  <main> at blah.rb:16

Interestingly, I discovered that the original code does not OOM on Java 21, because it never seems to call the expected inspect method. I will open an issue to investigate that.

I realized that when I reproduced this it was Java 21 BUT also it was JRuby 10. I also cannot reproduce with Java 21 on 9.4. If I had to guess my TC refactoring for inspect() "fixed" it.

./bin/jruby -vw -J-Xmx250M ../snippets/name1.rb 
jruby 10.0.0.0-SNAPSHOT (3.4.0) 2024-12-19 7554ac66ab OpenJDK 64-Bit Server VM 21.0.5+11-LTS on 21.0.5+11-LTS +indy +jit [x86_64-linux]
uri:classloader:/jruby/kernel/data.rb:64: warning: ambiguity between regexp and two divisions: wrap regexp in parentheses or add a space after `/' operator
generating large obj
done
Error: Your application used more memory than the safety cap of 250M.
Specify -J-Xmx####M to increase it (#### = cap size in MB).
java.lang.OutOfMemoryError: Java heap space

@headius
Copy link
Member Author

headius commented Jan 15, 2025

Ok I think it's just that 21 is a bit more memory efficient, so it's able to handle this case in 250MB. I lowered it to 225MB and it fails like Java 8.

$ jruby -v -J-Xmx225M blah.rb
jruby 9.4.10.0-SNAPSHOT (3.1.4) 2025-01-15 2f915ca63d OpenJDK 64-Bit Server VM 21.0.5+11-LTS on 21.0.5+11-LTS +jit [arm64-darwin]
generating large obj
done
Error: Your application used more memory than the safety cap of 225M.
Specify -J-Xmx####M to increase it (#### = cap size in MB).
java.lang.OutOfMemoryError: Java heap space

Good to merge for 9.4.10.

@headius headius merged commit 71fe5f3 into jruby:master Jan 15, 2025
95 checks passed
@headius headius deleted the no_inspect_nameerror branch January 15, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OutOfMemoryError while constructing a NameError in the context of a large object

2 participants