[crac] RFR: RCU Lock - RW lock with very lightweight read- and heavyweight write-locking [v2]
Dan Heidinga
heidinga at openjdk.org
Wed Apr 12 12:27:16 UTC 2023
On Wed, 12 Apr 2023 12:22:37 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.
>
> Radim Vansa has updated the pull request incrementally with one additional commit since the last revision:
>
> Reuse MethodHandles.lookup()
>
> Co-authored-by: Dan Heidinga <heidinga at redhat.com>
src/java.base/share/native/libjava/RCULock.c line 43:
> 41: {
> 42: readerThreadsListField = (*env)->GetFieldID(env, cls, "readerThreadsList", "J");
> 43: readCriticalMethodsField = (*env)->GetFieldID(env, cls, "readCriticalMethods", "J");
Looking up fields correctly in JNI is a pain to get the error handling correct. I prefer to do the lookup reflectively and then pass the j.l.reflect.Field objects into the JNI method and convert them using `ToReflectField` [0]
It moves all the tricky error handling into Java and makes for obviously correct code.
If we keep the existing code, we need to null check the `readerThreadsListField` value before attempting a second JNI call as we can't call in with an exception pending.
[0] https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#from_reflected_field
-------------
PR Review Comment: https://git.openjdk.org/crac/pull/58#discussion_r1164056344
More information about the crac-dev
mailing list