I've defined RubyVM::InstructionHelper with singleton methods #method_serial and #constant_serial. They delegate to helper macros GET_METHOD_SERIAL() and GET_CONSTANT_SERIAL().
With these methods, users have visibility into the method and constant caches. If it makes sense, I hope this patch is included in Ruby 2.1.0.
I would like to see these exposed as well. They provide visibility into VM behavior, and are very useful for measuring how many constant or method table invalidations are happening in large applications.
The gem is a continuation of the description's example. Basically, an application wraps code in a block. Once the block executes, it reports whether or not the constant or method cache was busted. The tests have specific examples.
My main use-case for exposing these serials is to collect them automatically before and after each request in a rails app and graph how many times the caches are busted per request.
I would also like to see a Tracepoint or other hook that fires whenever the cache is busted. This would allow capturing a stack trace to see exactly where the cache busting is happening.
If we're opposed to adding multiple methods to RubyVM, maybe a RubyVM.stat will suffice. It can behave the same way that GC.stat does (optional hash argument to avoid allocations).
This issue was solved with changeset r44062.
Simeon, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
vm.c: add RubyVM.stat for accessing cache serials
vm.c (ruby_vm_stat): add RubyVM.stat() for access to internal cache
counters. this methods behaves like GC.stat, accepting an optional
hash or symbol argument. [Bug #9190] [ruby-core:58750]