Skip to content

Commit

Permalink
Uses 128 bytes padding to prevent false-sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Sep 24, 2024
1 parent 9be3116 commit c2d466e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/org/jboss/threads/EnhancedQueueExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,18 @@ private static final class RuntimeFields {
// guess
cacheLine = 64;
}
// cpu archs uses spatial prefetcher can keep 2 cache-lines into L2
int pad = cacheLine * 2;
int longScale = unsafe.arrayIndexScale(long[].class);
int objScale = unsafe.arrayIndexScale(Object[].class);
// these fields are in units of array scale
unsharedObjectsSize = cacheLine / objScale * (numUnsharedObjects + 1);
unsharedLongsSize = cacheLine / longScale * (numUnsharedLongs + 1);
unsharedObjectsSize = pad / objScale * (numUnsharedObjects + 1);
unsharedLongsSize = pad / longScale * (numUnsharedLongs + 1);
// these fields are in bytes
headOffset = unsafe.arrayBaseOffset(Object[].class) + cacheLine;
tailOffset = unsafe.arrayBaseOffset(Object[].class) + cacheLine * 2;
threadStatusOffset = unsafe.arrayBaseOffset(long[].class) + cacheLine;
queueSizeOffset = unsafe.arrayBaseOffset(long[].class) + cacheLine * 2;
headOffset = unsafe.arrayBaseOffset(Object[].class) + pad;
tailOffset = unsafe.arrayBaseOffset(Object[].class) + pad * 2;
threadStatusOffset = unsafe.arrayBaseOffset(long[].class) + pad;
queueSizeOffset = unsafe.arrayBaseOffset(long[].class) + pad * 2;
}
}

Expand Down

0 comments on commit c2d466e

Please sign in to comment.