mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
TeamCity Automatic Merge from master into feature/java11
This commit is contained in:
@@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.openhft.chronicle.algo.bytes.Access.checkedRandomDataInputAccess;
|
||||
|
||||
@@ -137,7 +138,7 @@ public interface Data<T> {
|
||||
* @param targetOffset the offset in the target, to write the bytes from.
|
||||
*/
|
||||
default void writeTo(RandomDataOutput target, long targetOffset) {
|
||||
target.write(targetOffset, bytes(), offset(), size());
|
||||
target.write(targetOffset, Objects.requireNonNull(bytes()), offset(), size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -750,6 +750,7 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
double valueSize = averageValueSize();
|
||||
size += averageSizeStoringLength(valueBuilder, valueSize);
|
||||
int alignment = valueAlignment();
|
||||
size = alignAddr((long) Math.ceil(size), alignment); // so the value starts aligned
|
||||
int worstAlignment;
|
||||
if (worstAlignmentComputationRequiresValueSize(alignment)) {
|
||||
long constantSizeBeforeAlignment = toLong(size);
|
||||
@@ -925,6 +926,8 @@ public final class ChronicleMapBuilder<K, V> implements
|
||||
throw new IllegalArgumentException("Alignment should be a power of 2, " + alignment +
|
||||
" given");
|
||||
}
|
||||
if (Jvm.isArm() && alignment < 8)
|
||||
return this;
|
||||
this.alignment = alignment;
|
||||
return this;
|
||||
}
|
||||
|
||||
Regular → Executable
+20
-12
@@ -23,7 +23,6 @@ import net.openhft.chronicle.core.OS;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public enum ZeroBytesStore implements BytesStore<ZeroBytesStore, Void> {
|
||||
@@ -40,22 +39,22 @@ public enum ZeroBytesStore implements BytesStore<ZeroBytesStore, Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readVolatileByte(long offset) throws BufferUnderflowException {
|
||||
public byte readVolatileByte(long offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readVolatileShort(long offset) throws BufferUnderflowException {
|
||||
public short readVolatileShort(long offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readVolatileInt(long offset) throws BufferUnderflowException {
|
||||
public int readVolatileInt(long offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readVolatileLong(long offset) throws BufferUnderflowException {
|
||||
public long readVolatileLong(long offset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,22 +127,31 @@ public enum ZeroBytesStore implements BytesStore<ZeroBytesStore, Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long addressForRead(long offset) throws UnsupportedOperationException {
|
||||
public long addressForRead(long offset) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapInt(long offset, int expected, int value)
|
||||
throws BufferOverflowException, IllegalArgumentException {
|
||||
throw new UnsupportedOperationException();
|
||||
public boolean compareAndSwapInt(long offset, int expected, int value) {
|
||||
if (expected != 0 || value != 0)
|
||||
throw new UnsupportedOperationException();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapLong(long offset, long expected, long value)
|
||||
throws BufferOverflowException, IllegalArgumentException {
|
||||
throw new UnsupportedOperationException();
|
||||
public void testAndSetInt(long offset, int expected, int value) {
|
||||
if (expected != 0 || value != 0)
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compareAndSwapLong(long offset, long expected, long value) {
|
||||
if (expected != 0 || value != 0)
|
||||
throw new UnsupportedOperationException();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void reserve() throws IllegalStateException {
|
||||
}
|
||||
|
||||
@@ -224,21 +224,16 @@ public abstract class MapEntryStages<K, V> extends HashEntryStages<K>
|
||||
}
|
||||
|
||||
public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) {
|
||||
long sizeWithoutChecksum;
|
||||
if (mh.m().constantlySizedEntry) {
|
||||
sizeWithoutChecksum =
|
||||
alignAddr(sizeOfEverythingBeforeValue + valueSize, mh.m().alignment);
|
||||
} else if (mh.m().couldNotDetermineAlignmentBeforeAllocation) {
|
||||
sizeWithoutChecksum = sizeOfEverythingBeforeValue + mh.m().worstAlignment + valueSize;
|
||||
} else {
|
||||
sizeWithoutChecksum =
|
||||
alignAddr(sizeOfEverythingBeforeValue, mh.m().alignment) + valueSize;
|
||||
}
|
||||
return sizeWithoutChecksum + checksumStrategy.extraEntryBytes();
|
||||
if (!mh.m().constantlySizedEntry && mh.m().couldNotDetermineAlignmentBeforeAllocation)
|
||||
sizeOfEverythingBeforeValue += mh.m().worstAlignment;
|
||||
int alignment = mh.m().alignment;
|
||||
return alignAddr(sizeOfEverythingBeforeValue, alignment) +
|
||||
alignAddr(valueSize, alignment);
|
||||
}
|
||||
|
||||
long sizeOfEverythingBeforeValue(long keySize, long valueSize) {
|
||||
return mh.m().keySizeMarshaller.storingLength(keySize) + keySize +
|
||||
checksumStrategy.extraEntryBytes() +
|
||||
mh.m().valueSizeMarshaller.storingLength(valueSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -619,7 +619,7 @@ public class ChronicleMapTest {
|
||||
.entries((long) entries)
|
||||
.minSegments(1)
|
||||
.averageKeySize(10)
|
||||
.entryAndValueOffsetAlignment(4)
|
||||
.entryAndValueOffsetAlignment(8)
|
||||
.create()) {
|
||||
LongValue value4 = Values.newNativeReference(LongValue.class);
|
||||
LongValue value22 = Values.newNativeReference(LongValue.class);
|
||||
@@ -651,9 +651,9 @@ public class ChronicleMapTest {
|
||||
try (ChronicleMap<CharSequence, LongValue> map1 = ChronicleMapBuilder.of(CharSequence.class,
|
||||
LongValue.class)
|
||||
.entries((long) entries)
|
||||
.minSegments(1)
|
||||
// .minSegments(1)
|
||||
.averageKeySize(10)
|
||||
.entryAndValueOffsetAlignment(1)
|
||||
// .entryAndValueOffsetAlignment(8)
|
||||
.create()) {
|
||||
LongValue value1 = Values.newNativeReference(LongValue.class);
|
||||
LongValue value21 = Values.newNativeReference(LongValue.class);
|
||||
|
||||
@@ -56,6 +56,7 @@ public class DemoChronicleMapTest {
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
.entries(maxEntries)
|
||||
.entryAndValueOffsetAlignment(8)
|
||||
.createPersistedTo(file)) {
|
||||
IntValue key = Values.newHeapInstance(IntValue.class);
|
||||
|
||||
@@ -98,6 +99,7 @@ public class DemoChronicleMapTest {
|
||||
.putReturnsNull(true)
|
||||
.removeReturnsNull(true)
|
||||
.entries(maxEntries)
|
||||
.entryAndValueOffsetAlignment(8)
|
||||
.createPersistedTo(file)) {
|
||||
IntValue key = Values.newHeapInstance(IntValue.class);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.openhft.chronicle.map.ExternalMapQueryContext;
|
||||
import net.openhft.chronicle.values.Values;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
@@ -99,8 +100,7 @@ public class OpenJDKAndHashMapExamplesTest {
|
||||
|
||||
BondVOInterface bond = Values.newNativeReference(BondVOInterface.class);
|
||||
// lookup the key and give me a reference I can update in a thread safe way.
|
||||
try (net.openhft.chronicle.core.io.Closeable c =
|
||||
chm.acquireContext("369604103", bond)) {
|
||||
try (Closeable c = chm.acquireContext("369604103", bond)) {
|
||||
// found a key and bond has been set
|
||||
// get directly without touching the rest of the record.
|
||||
long _matDate = bond.getMaturityDate();
|
||||
|
||||
Reference in New Issue
Block a user