socketry / rspec-memory

MIT License
16 stars 7 forks source link

JRuby: NoMethodError: undefined method `memsize_of' for ObjectSpace:Module #8

Open olleolleolle opened 2 years ago

olleolleolle commented 2 years ago

JRuby:

Script coverage disabled: unknown event: script_compiled

An error occurred while loading ./spec/rspec/memory_spec.rb.
Failure/Error: SLOT_SIZE = ObjectSpace.memsize_of(Object.new)

NoMethodError:
  undefined method `memsize_of' for ObjectSpace:Module
# ./lib/rspec/memory/trace.rb:26:in `block in Memory'
# ./lib/rspec/memory/trace.rb:25:in `<module:Memory>'
# ./lib/rspec/memory/trace.rb:24:in `<module:RSpec>'
# ./lib/rspec/memory/trace.rb:23:in `<main>'
# ./lib/rspec/memory/matchers/limit_allocations.rb:22:in `<main>'
# ./lib/rspec/memory.rb:21:in `<main>'
# ./spec/rspec/memory_spec.rb:21:in `<main>'
No examples found.

Finished in 0.00316 seconds (files took 1.62 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
olleolleolle commented 2 years ago

@enebo 👋 Hi, do you know whether this method is ever in the cards for JRuby? The only reference I could find of it was a 2019 comment on a "Update specs" PR, which mentioned it in output (with the same NoMethodError as above):

https://github.com/jruby/jruby/pull/5747

enebo commented 2 years ago

@olleolleolle it could be in a future release but it probably will not be a simple feature to add. Instrumentation seems to be the common way this is done (which means installing an agent) but even that by itself is only showing shallow object size (e.g. does not deep count all elements of an array as an example). I add a link to this since this might also be a solution: https://github.com/twitter-archive/commons/blob/master/src/java/com/twitter/common/objectsize/ObjectSizeCalculator.java

[NOTE: @olleolleolle I wrote this 10 days ago and never clicked on comment :( ]