Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses 128 bytes padding to prevent false-sharing #191

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 spatial prefetcher can drag 2 cache-lines at once into L2
int pad = cacheLine > 128 ? cacheLine : 128;
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