From your clarifications, it seems like what you really need is papers on ways to write "atomic" operations in Java.
For what you want to do I can't think of a way to avoid using locks. After all, even just writing to a long
or double
is not atomic without synchronization.
Here are some links related to what you want to do:
You should determine what locking mechanism to use based on your expected use cases of this data structure.
https://blog.takipi.com/java-8-stampedlocks-vs-readwritelocks-and-synchronized/
Also, some people might complain about premature optimization but I also like to consider the efficiency of code before it's an issue. However using synchronization/locks in this case probably isn't as bad as you might think.
If you want lower level then I would resort to JNI
.
However, no matter how low-level you go, I think using locks/synchronization would still be unavoidable since there's no guarantee the hardware would have instructions that could do what you want atomically. How would a CPU perform an or
operation across multiple words atomically?
As a side note, if you are going to be using these bitmasks a lot and want the most performance, then it might possibly maybe be worth writing this code for a GPU. Though I'm not fully sure of the pros and cons, those would be left for further research...
I think you're looking for a level of efficiency that hardware simply cannot provide right now.