When it comes to algorithms for lock free / wait free data structures, Some algorithms will steal the 2 least significant bits from a pointer since they aren't used, and use them as status bits (like if a node is logically deleted or something). I figured that in java, I'd just use the AtomicStampedReference instead of bit stealing. However, I realized that the only way to solve the ABA problem in java is to use the AtomicStampedReference to keep track of whether a node was changed or not.
NOTE: If your'e not sure what the ABA problem is, wikipedia's gives a wonderful example explaining how badly things gets screwed up by it: https://en.wikipedia.org/wiki/ABA_problem
NOTE: The reason I say the ONLY way to solve the ABA problem is to use the AtomicStampedReference is based on this post: http://tutorials.jenkov.com/java-util-concurrent/atomicstampedreference.html#atomicstampedreference-and-the-a-b-a-problem
So, since I can't use the integer in the atomic stamped reference to keep track of things like logical deletion anymore, is there a way I can steal the unused bits in the reference itself? I tried to access the "unsafe" package to do this task by calling:
import sun.misc.Unsafe;
But when I do that, I get the following error from Eclipse:
Access restriction: The type Unsafe is not accessible due to restriction on required library C:\Program Files\Java\jre1.8.0_40\lib\rt.jar
Anyone have any ideas? If you're curious what I'm trying to do, I'm trying to implement a thread safe lock free hashmap in java as a school project. And I need to use the 2 LSB bits to differentiate between 3 different node types: a data node (00), a marked data node (01), or an array node (10)
EDIT: I should mention, I need the 2 status bits to be inside the atomic reference. The reason I need this is because I'm going to be doing compare and swap operations, and I need to Compare And Swap to fail if a data node (00) gets marked (01), or turned into an arrayNode(10). I originally used the integer in the AtomicStampedReference for this, but I can't do that anymore as the AtomicStampedReference should be reserved to prevent problems caused by ABA.