[crac] RFR: RCU Lock - RW lock with very lightweight read- and heavyweight write-locking

Dan Heidinga heidinga at openjdk.org
Wed Apr 12 12:19:06 UTC 2023


On Wed, 12 Apr 2023 08:57:48 GMT, Radim Vansa <duke at openjdk.org> wrote:

> This implementation is suitable for uses where the write-locking happens very rarely (if at all), as in the case of CRaC checkpoint, and we don't want to slow down regular access to the protected resource.

src/java.base/share/classes/jdk/crac/RCULock.java line 136:

> 134:             MethodHandle noop = MethodHandles.lookup().findSpecial(RCULock.class, "noop", voidType, RCULock.class);
> 135:             MethodHandle readLockImpl = MethodHandles.lookup().findSpecial(RCULock.class, "readLockImpl", voidType, RCULock.class);
> 136:             MethodHandle readUnlockImpl = MethodHandles.lookup().findSpecial(RCULock.class, "readUnlockImpl", voidType, RCULock.class);

Creating a Lookup object is expensive.  Better to cache in a local
Suggestion:

            MethodHandles.Lookup lookup = MethodHandles.lookup();
            MethodHandle noop = lookup.findSpecial(RCULock.class, "noop", voidType, RCULock.class);
            MethodHandle readLockImpl = lookup.findSpecial(RCULock.class, "readLockImpl", voidType, RCULock.class);
            MethodHandle readUnlockImpl = lookup.findSpecial(RCULock.class, "readUnlockImpl", voidType, RCULock.class);

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

PR Review Comment: https://git.openjdk.org/crac/pull/58#discussion_r1164049509


More information about the crac-dev mailing list