reactorlabs / rir

GNU General Public License v2.0
62 stars 18 forks source link

Fix patching the constant pool #1210

Closed JanJecmen closed 2 years ago

JanJecmen commented 2 years ago

This should fix the bug where occasionally the close_ bytecode would find a Function in the constant pool instead of a DispatchTable.

Some cells in the constant pool are created by makeSpace with the intention that we can later patch these (used for invalidating targets after deopts). However, the patching would also write to the C++ contents cache that maps SEXPs to pool indices, and patching multiple times would leave the old mapping outdated.

For example:

  1. makeSpace 42
  2. patch X into 42
  3. patch Y into 42
  4. X gets garbage collected
  5. Z gets allocated to where X used to be
  6. insert of Z finds X in contents and returns 42 Now:
    • constant pool at 42 returns Y
    • Z may get collected since it's not reachable from the constant pool

Also, this makes sure that we cannot patch a location that doesn't come from calling makeSpace.

o- commented 2 years ago

Here are some stats for your PR:

Please find your performance results at https://rir-benchmarks.prl.fit.cvut.cz/diff?job_ids[]=2445941207&job_ids[]=2427588749&selection=all