3 ms·
I think instead a @ReorderingBarrier annotation might be a good solution. Like a memory barrier which doesn't allow reordering of memory operations across that
by a-priori 13y ago
I think instead a @ReorderingBarrier annotation might be a good solution. Like a memory barrier which doesn't allow reordering of memory operations across that point, a reordering barrier wouldn't allow fields declared before that point to be placed in memory after the field it's declared on or any declared afterwards.
It could also be used to control the alignment of the following field, to a cache line for example:
public class TestClass {
int a1;
long a2;
OtherClassA a3;
@ReorderingBarrier(alignment=CACHE_LINE)
OtherClassB b1;
int b2;
int b3;
long b4;
// ...
}
If I understand the reordering rules correctly, without the annotation it would be rearranged as: a2, b4, a1, b2, b3, a3, b1.
With the barrier it would be rearranged as: a2, a1, a3, (cache line alignment break), b4, b2, b3, b1.
- fmstephe 13y agoIf they provide an alignment argument then the annotation based approach becomes much more attractive. You could even go all cross platform and have 'alignment=cacheline' That would be a lot of fun to play with.
- a-priori 13y agoHah, just as you were writing that I had the same thought and did a ninja edit where I switched from saying a specific alignment to CACHE_LINE. :)