RFR: 8328679: Improve comment for UNSAFE_ENTRY_SCOPED in unsafe.cpp

Jorn Vernee jvernee at openjdk.org
Thu Mar 21 19:02:21 UTC 2024


On Thu, 21 Mar 2024 11:04:41 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This small PR is an attempt at improving the comment in the UNSAFE_ENTRY_SCOPED macro.
> I found that the comment contained some duplicated claims, did not properly introduced the concepts it referred to, and some of its claims were not explained in full.
> 
> As this is a delicate part of how FFM ensures the "no use after free" guarantee, I think it would be a good idea for this comment to better reflect what the expectations are.

src/hotspot/share/prims/unsafe.cpp line 85:

> 83: //
> 84: // Closing a scope object (cf. scopedMemoryAccess.cpp) can install
> 85: // an async handshake on the entry to scoped method. When that happens,

Suggestion:

// an async exception during a safepoint. When that happens,

src/hotspot/share/prims/unsafe.cpp line 94:

> 92: // If an async exception handshake were installed in such a safepoint,
> 93: // memory access might still occur before the handshake is honored by
> 94: // the accessing thread.

It's not so much that we can't have safepoints, it's more that we avoid them, since they allow async exception to be installed, which in turn allows memory to be freed.

Maybe you could put something like: `As a rule, we disallow further safepoints within a scoped method` at the end of the previous (2nd) paragraph, and then drop the 3rd paragraph.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18429#discussion_r1534482542
PR Review Comment: https://git.openjdk.org/jdk/pull/18429#discussion_r1534487539


More information about the hotspot-dev mailing list