I am developing some concurrent algorithms which deal with Reference objects. I am using java 17.
The thing is I don't know what's the memory semantics of operations like get, clear or refersTo. It isn't documented in the Javadoc.
Looking into the source code of OpenJdk, the referent has no modifier, such as volatile (while the next pointer for reference queues is volatile). Also, get implementation is trivial, but it is an intrinsic candidate. clear and refersTo are native. So I don't know what they really do.
When the GC clears a reference, I have to assume that all threads will see it cleared, or otherwise they would see a reference to an object (in process of being) garbage collected, but it's just an informal guess.
Is there any warranty about the memory semantics of all these operations?
If there isn't, is there a way to obtain the same warranries of a volatile access by invoking, for instance, a fence operation before and/or after calling one of these operations?