diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java index 195b11451..3e48fcf87 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMapBuilder.java @@ -121,7 +121,7 @@ public abstract class AbstractChronicleMapBuilderIf entry size is not configured explicitly by calling this method, it is computed based on * {@linkplain #metaDataBytes(int) meta data bytes}, plus {@linkplain #keySize(int) key size}, - * plus {@linkplain #valueSize(int) value size}, plus a few bytes required by implementations, - * with respect to {@linkplain #entryAndValueAlignment(Alignment) alignment}. + * plus {@linkplain #valueSize(int) value size}, plus a few bytes required by implementations. * - *

Note that the actual entrySize will be aligned to 4 (default {@linkplain - * #entryAndValueAlignment(Alignment) entry alignment}). I. e. if you set entry size to 30, the - * actual entry size will be 32 (30 aligned to 4 bytes). If you don't want entry size to be - * aligned, set {@code entryAndValueAlignment(Alignment.NO_ALIGNMENT)}. - * - * @see #entryAndValueAlignment(Alignment) * @see #entries(long) */ @Override @@ -300,24 +293,7 @@ public abstract class AbstractChronicleMapBuilderUseful when values of the map are updated intensively, particularly fields with volatile - * access, because it doesn't work well if the value crosses cache lines. Also, on some - * (nowadays rare) architectures any misaligned memory access is more expensive than aligned. - * - *

Note that {@linkplain #entrySize(int) entry size} will be aligned according to this - * alignment. I. e. if you set {@code entrySize(20)} and {@link Alignment#OF_8_BYTES}, actual - * entry size will be 24 (20 aligned to 8 bytes). - * - *

Default is {@link Alignment#OF_4_BYTES}. - * - * @param alignment the new alignment of the maps constructed by this builder - * @return this {@code ChronicleMapBuilder} back - */ - public B entryAndValueAlignment(Alignment alignment) { + B entryAndValueAlignment(Alignment alignment) { this.alignment = alignment; return self(); } diff --git a/src/main/java/net/openhft/chronicle/map/Alignment.java b/src/main/java/net/openhft/chronicle/map/Alignment.java index ebdd6728a..d470b5305 100644 --- a/src/main/java/net/openhft/chronicle/map/Alignment.java +++ b/src/main/java/net/openhft/chronicle/map/Alignment.java @@ -23,7 +23,7 @@ import net.openhft.lang.io.Bytes; /** * Memory addresses alignment strategies. * - * @see AbstractChronicleMapBuilder#entryAndValueAlignment(Alignment) + * @see OffHeapUpdatableChronicleMapBuilder#entryAndValueAlignment(Alignment) */ public enum Alignment { /** diff --git a/src/main/java/net/openhft/chronicle/map/OffHeapUpdatableChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/OffHeapUpdatableChronicleMapBuilder.java index 19f979ee6..3d60a400c 100644 --- a/src/main/java/net/openhft/chronicle/map/OffHeapUpdatableChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/OffHeapUpdatableChronicleMapBuilder.java @@ -46,6 +46,44 @@ public final class OffHeapUpdatableChronicleMapBuilder return this; } + /** + * {@inheritDoc} With respect to {@linkplain #entryAndValueAlignment(Alignment) alignment}. + * + *

Note that the actual entrySize will be aligned to 4 (default {@linkplain + * #entryAndValueAlignment(Alignment) entry alignment}). I. e. if you set entry size to 30, + * and entry alignment is set to {@link Alignment#OF_4_BYTES}, the actual entry size will be 32 + * (30 aligned to 4 bytes). + * + * @see #entryAndValueAlignment(Alignment) + * @see #entries(long) + */ + @Override + public OffHeapUpdatableChronicleMapBuilder entrySize(int entrySize) { + return super.entrySize(entrySize); + } + + /** + * Configures alignment strategy of address in memory of entries and independently of address in + * memory of values within entries in ChronicleMaps, created by this builder. + * + *

Useful when values of the map are updated intensively, particularly fields with volatile + * access, because it doesn't work well if the value crosses cache lines. Also, on some + * (nowadays rare) architectures any misaligned memory access is more expensive than aligned. + * + *

Note that {@linkplain #entrySize(int) entry size} will be aligned according to this + * alignment. I. e. if you set {@code entrySize(20)} and {@link Alignment#OF_8_BYTES}, actual + * entry size will be 24 (20 aligned to 8 bytes). + * + *

Default is {@link Alignment#NO_ALIGNMENT}. + * + * @param alignment the new alignment of the maps constructed by this builder + * @return this {@code ChronicleMapBuilder} back + */ + @Override + public OffHeapUpdatableChronicleMapBuilder entryAndValueAlignment(Alignment alignment) { + return super.entryAndValueAlignment(alignment); + } + /** * {@inheritDoc} Also, it overrides any previous {@link #prepareValueBytesOnAcquire} * configuration to this {@code OffHeapUpdatableChronicleMapBuilder}. diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index a475bb424..bd4fa62bf 100644 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -1153,19 +1153,6 @@ public class ChronicleMapTest { .entries(10) .minSegments(1) .entrySize(10); - builder.entryAndValueAlignment(NO_ALIGNMENT); - builder.file(getPersistenceFile()); - testOversizeEntriesPutRemoveReplace( - (VanillaChronicleMap) - builder.create() - ); - builder.entryAndValueAlignment(Alignment.OF_4_BYTES); - builder.file(getPersistenceFile()); - testOversizeEntriesPutRemoveReplace( - (VanillaChronicleMap) - builder.create() - ); - builder.entryAndValueAlignment(OF_8_BYTES); builder.file(getPersistenceFile()); testOversizeEntriesPutRemoveReplace( (VanillaChronicleMap) diff --git a/src/test/java/net/openhft/chronicle/map/Issue42.java b/src/test/java/net/openhft/chronicle/map/Issue42.java index 4e856140f..38574d29d 100644 --- a/src/test/java/net/openhft/chronicle/map/Issue42.java +++ b/src/test/java/net/openhft/chronicle/map/Issue42.java @@ -42,7 +42,6 @@ public class Issue42 { final ChronicleMap map = ChronicleMapBuilder .of(CharSequence.class, CharSequence.class) - .entryAndValueAlignment(NO_ALIGNMENT) .entrySize(18) .entries(15000000) .minSegments(128).create();