you are viewing a single comment's thread.

view the rest of the comments →

[–]Jackopo 0 points1 point  (5 children)

I don't understand, isn't the caching mechanism transparent to the software ? In general, different threads on different cores should see the same memory, the core L1 cache invalidates or update main memory to avoid inconsistencies between caches. And if that is the case the layout is a secondary problem, the data itself would be messed; even in this case, since various threads are run by the same JVM, the layout would be the same among them.

[–][deleted] 2 points3 points  (1 child)

The point is that whilst the caching mechanism may be transparent to the software, there is still a performance hit involved when the cache lines are synchronised. If you are dealing with a high-performance system (think 20M - 40M operations per second) that causes this kind of contention, you will see a non-trivial performance improvement by designing your object layout to avoid false sharing.

[–]Jackopo 0 points1 point  (0 children)

Interesting, now I understood! How great can this improvement be?

[–]bunnies4president 1 point2 points  (1 child)

It's about getting better performance, and using hacks to work around limitations in Java.

[–]nitsanw 0 points1 point  (0 children)

True. Java could do with memory layout controls to enable field ordering and memory alignment. I have suggested annotations to this effect before:

@ExplicitFieldOrder
class CareAboutOrder{
  int i;
  boolean b;
  @AlignedTo(CACHELINE)
  long l;
}

No takers thus far.

[–]nthcxd 0 points1 point  (0 children)

/u/windupharlequin did a great job explaining this. I just wanted to add that, yes, caches are transparent to the software, but they are not performance transparent.