mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Ensure the chunk size is a multiple of the alignment, closed https://github.com/OpenHFT/Chronicle-Map/issues/169
This commit is contained in:
@@ -730,6 +730,8 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
}
|
||||
if (actualChunkSize <= 0)
|
||||
throw new IllegalArgumentException("Chunk size must be positive");
|
||||
if (alignment > 0 && actualChunkSize % alignment != 0)
|
||||
throw new IllegalArgumentException("The chunk size (" + actualChunkSize + ") must be a multiple of the alignment (" + alignment + ")");
|
||||
this.actualChunkSize = actualChunkSize;
|
||||
return this;
|
||||
}
|
||||
@@ -928,16 +930,25 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
}
|
||||
if (Jvm.isArm() && alignment < 8)
|
||||
return this;
|
||||
validateAlignment(actualChunkSize, actualChunkSize, alignment);
|
||||
|
||||
this.alignment = alignment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void validateAlignment(int ifSet, int actualChunkSize, int alignment) {
|
||||
if (ifSet > 0 && actualChunkSize % alignment != 0)
|
||||
throw new IllegalArgumentException("The chunk size (" + actualChunkSize + ") must be a multiple of the alignment (" + alignment + ")");
|
||||
}
|
||||
|
||||
int valueAlignment() {
|
||||
if (alignment != UNDEFINED_ALIGNMENT_CONFIG)
|
||||
return alignment;
|
||||
try {
|
||||
if (Values.isValueInterfaceOrImplClass(valueBuilder.tClass)) {
|
||||
return ValueModel.acquire(valueBuilder.tClass).recommendedOffsetAlignment();
|
||||
int alignment = ValueModel.acquire(valueBuilder.tClass).recommendedOffsetAlignment();
|
||||
validateAlignment(alignment, actualChunkSize, alignment);
|
||||
return alignment;
|
||||
} else {
|
||||
return NO_ALIGNMENT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user