yjit icon indicating copy to clipboard operation
yjit copied to clipboard

Memory leak with const_set

Open XrXr opened this issue 4 years ago • 1 comments

The current opt_setinlinecache implementation invalidates the block for the corresponding opt_getinlinecache, and one could make opt_setinlinecache run by setting any constant. Apps that use Module#const_set at runtime will leak memory because of this. The following script eventually triggers [BUG] out of executable memory.

$VERBOSE = nil

Const = 0
def get
  Const
end
loop do
  get
  Object.send(:const_set, :Const, 0)
end

XrXr avatar Jun 03 '21 15:06 XrXr

Three thoughts:

  1. This would also be fixed by a mechanism to throw away executable code when we hit the limit.
  2. We could technically monitor how many times a given opt_getinlinecache gets recompiled and eventually stop recompiling? May not be practical since we currently don't invalidate per inline cache?
  3. I would like you to engage in an exercise. Every time you report a problem, try to also suggest one or more potential solutions, ideally as simple and efficient as possible.

maximecb avatar Jun 03 '21 15:06 maximecb

Is this still relevant? The insn sequence is different today, just opt_getconstant_path, and it seems like I can't reproduce the issue with that script.

k0kubun avatar Nov 07 '22 23:11 k0kubun