From 9c8a9067df6e3810ef0d1fc4efd1304704d2de04 Mon Sep 17 00:00:00 2001 From: danielshaya Date: Wed, 3 Jun 2015 10:40:13 +0100 Subject: [PATCH] Last compiling version. --- .../CompiledReplicatedMapQueryContext.java | 2743 ++++++++--------- 1 file changed, 1296 insertions(+), 1447 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java index 02b722fb5..c300f0196 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java @@ -19,10 +19,8 @@ import net.openhft.chronicle.hash.replication.TimeProvider; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; import net.openhft.chronicle.map.*; -import net.openhft.chronicle.map.TcpReplicator.TcpSocketChannelEntryWriter; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; -import net.openhft.chronicle.map.impl.stage.query.MapAbsentEntryHolder; import net.openhft.chronicle.map.impl.value.instance.ValueInitableValue; import net.openhft.chronicle.map.replication.MapRemoteQueryContext; import net.openhft.chronicle.map.replication.MapReplicableEntry; @@ -45,24 +43,23 @@ import java.util.ConcurrentModificationException; import java.util.List; import java.util.concurrent.TimeUnit; -public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , ReplicatedChronicleMapHolder , MapAbsentEntryHolder , MapRemoteQueryContext , MapReplicableEntry { +public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , ReplicatedChronicleMapHolder , MapRemoteQueryContext , MapReplicableEntry { public void close() { - CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); - CompiledReplicatedMapQueryContext.this.closeReplicationInput(); - CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.closeInputKey(); + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); CompiledReplicatedMapQueryContext.this.closeUsed(); - CompiledReplicatedMapQueryContext.this.closeInputKey(); - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledReplicatedMapQueryContext.this.bytesReturnValue.closeOutput(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); CompiledReplicatedMapQueryContext.this.closeInputBytes(); + CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); CompiledReplicatedMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); + CompiledReplicatedMapQueryContext.this.innerUpdateLock.closeUpdateLockForbiddenUpgradeDependants(); + CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); @@ -117,36 +114,34 @@ public class CompiledReplicatedMapQueryContext)(entryBytesAccessor.access(entryBytes))); - this.bytesReturnValue = new BytesReturnValue(); - this.innerWriteLock = new WriteLock(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerReadLock = new ReadLock(); this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesValue(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.entryKey = new EntryKeyBytesValue(); + this.usingReturnValue = new UsingReturnValue(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesValue(); + this.dummyValue = new DummyValueZeroValue(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.usingReturnValue = new UsingReturnValue(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryKey = new EntryKeyBytesValue(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); - this.dummyValue = new DummyValueZeroValue(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerWriteLock = new WriteLock(); } public CompiledReplicatedMapQueryContext(CompiledReplicatedMapQueryContext c) { @@ -154,39 +149,42 @@ public class CompiledReplicatedMapQueryContext)(c.m)); - this.innerUpdateLock = new UpdateLock(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.bytesReturnValue = new BytesReturnValue(); - this.innerWriteLock = new WriteLock(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerReadLock = new ReadLock(); this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesValue(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); + this.entryKey = new EntryKeyBytesValue(); + this.usingReturnValue = new UsingReturnValue(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesValue(); + this.dummyValue = new DummyValueZeroValue(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.usingReturnValue = new UsingReturnValue(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryKey = new EntryKeyBytesValue(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); - this.dummyValue = new DummyValueZeroValue(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerWriteLock = new WriteLock(); } public class InputKeyBytesValue extends AbstractValue { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); @@ -201,6 +199,11 @@ public class CompiledReplicatedMapQueryContext { + @Override + public T handle() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; + } + @Override public ReadAccess access() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -281,12 +280,6 @@ public class CompiledReplicatedMapQueryContext { - @NotNull - @Override - public Value defaultValue() { - return CompiledReplicatedMapQueryContext.this.defaultValue(); - } - - @NotNull - @Override - public MapContext context() { - return CompiledReplicatedMapQueryContext.this.context(); - } - - @NotNull - @Override - public Value absentKey() { - return CompiledReplicatedMapQueryContext.this.absentKey(); - } - - @Override - public void doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.doInsert(value); - } } public class EntryValueBytesValue extends AbstractValue { @@ -648,6 +624,12 @@ public class CompiledReplicatedMapQueryContext { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + @Override public long size() { return CompiledReplicatedMapQueryContext.this.firstInputValueSize(); @@ -765,20 +751,10 @@ public class CompiledReplicatedMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); - } - @Override public long offset() { return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.firstInputValueOffset()); } - - @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); - } } public class InputSecondValueBytesValue extends AbstractValue { @@ -792,11 +768,6 @@ public class CompiledReplicatedMapQueryContext)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); } - @Override - public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.secondInputValueOffset()); - } - @Override public long size() { return CompiledReplicatedMapQueryContext.this.secondInputValueSize(); @@ -847,6 +818,11 @@ public class CompiledReplicatedMapQueryContext { @@ -865,6 +841,18 @@ public class CompiledReplicatedMapQueryContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledReplicatedMapQueryContext.this.writeLock(); - } - @NotNull @Override public InterProcessLock readLock() { @@ -976,6 +946,31 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } + return CompiledReplicatedMapQueryContext.this.entryBytes; } @Override @@ -1030,30 +1019,17 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } } @Override @@ -1088,6 +1064,18 @@ public class CompiledReplicatedMapQueryContext { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + @Override public long size() { return CompiledReplicatedMapQueryContext.this.riKeySize(); @@ -1193,11 +1179,6 @@ public class CompiledReplicatedMapQueryContext { + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + @Override public T handle() { return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public long offset() { + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).offset(CompiledReplicatedMapQueryContext.this.replicatedInputBytes(), CompiledReplicatedMapQueryContext.this.riValueOffset()); } - } - public class ReplicatedInputValueBytesValue extends AbstractValue { @Override public long size() { return CompiledReplicatedMapQueryContext.this.riValueSize(); @@ -1262,11 +1253,6 @@ public class CompiledReplicatedMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); - } - @Override public V getUsing(V usingValue) { Bytes inputBytes = CompiledReplicatedMapQueryContext.this.replicatedInputBytes(); @@ -1309,24 +1295,9 @@ public class CompiledReplicatedMapQueryContext { - @Override - public V getUsing(V usingInstance) { - throw new UnsupportedOperationException(); - } - @Override public long offset() { return 0; @@ -1337,6 +1308,16 @@ public class CompiledReplicatedMapQueryContext access() { return ReadAccess.zeros(); } - - @Override - public Void handle() { - return null; - } } public enum SearchState { @@ -1592,6 +1568,11 @@ public class CompiledReplicatedMapQueryContext { - long startOutputPos; - - TcpSocketChannelEntryWriter output = null; - - public boolean outputInit() { - return (this.output) != null; - } - - public void initOutput(TcpSocketChannelEntryWriter output) { - this.output = output; - startOutputPos = output.in().position(); - } - - public long startOutputPos() { - assert this.outputInit() : "Output should be init"; - return this.startOutputPos; - } - - public TcpSocketChannelEntryWriter output() { - assert this.outputInit() : "Output should be init"; - return this.output; - } - - public void closeOutput() { - if (!(this.outputInit())) - return ; - - this.output = null; - } - - @Override - public void close() { - if ((output().in().position()) == (startOutputPos())) { - output().ensureBufferSize(1L); - output().in().writeBoolean(true); - } - } - - @Override - public void returnValue(@NotNull - Value value) { - long valueSize = value.size(); - long totalSize = (1L + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize))) + valueSize; - output().ensureBufferSize(totalSize); - Bytes out = output().in(); - out.writeBoolean(false); - CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(out, valueSize); - Full outAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(out); - long outPosition = out.position(); - out.skip(valueSize); - value.writeTo(outAccessor, out, outPosition); - } } public class DefaultReturnValue implements InstanceReturnValue { @@ -1889,12 +1810,6 @@ public class CompiledReplicatedMapQueryContext absent() { - return CompiledReplicatedMapQueryContext.this; - } - - public void checkAccessingFromOwnerThread() { - if ((owner) != (Thread.currentThread())) { - throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry) { + return CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (CompiledReplicatedMapQueryContext.this.m().worstAlignment)) + valueSize; + } else { + return (CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; } } - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledReplicatedMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - @Override public ReplicatedChronicleMap m() { return m; @@ -2077,16 +1981,60 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (((CompiledReplicatedMapQueryContext.this.m().metaDataBytes) + (CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); + } + + long sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + } + + @NotNull + @Override + public MapContext context() { + return this; + } + + public MVI valueMetaInterop(V value) { + return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + } + + public MKI keyMetaInterop(K key) { + return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); + } + + public void closeKeyBytesInteropKeyMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); + } + private CompiledReplicatedMapQueryContext _Chaining_createChaining() { return new CompiledReplicatedMapQueryContext(this); } @@ -2108,42 +2056,33 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); + public Bytes replicatedInputBytes = null; + + public boolean replicatedInputBytesInit() { + return (this.replicatedInputBytes) != null; } - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + public void initReplicatedInputBytes(Bytes replicatedInputBytes) { + this.replicatedInputBytes = replicatedInputBytes; + this.closeReplicatedInputBytesDependants(); } - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); + public Bytes replicatedInputBytes() { + assert this.replicatedInputBytesInit() : "ReplicatedInputBytes should be init"; + return this.replicatedInputBytes; } - public void closeKeyBytesInteropKeyMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); + public void closeReplicatedInputBytes() { + if (!(this.replicatedInputBytesInit())) + return ; + + this.closeReplicatedInputBytesDependants(); + this.replicatedInputBytes = null; } - private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledReplicatedMapQueryContext.this.m().metaDataBytes) + (CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - public MVI valueMetaInterop(V value) { - return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + public void closeReplicatedInputBytesDependants() { + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueGetUsingDependants(); } public Bytes inputBytes = null; @@ -2174,9 +2113,9 @@ public class CompiledReplicatedMapQueryContext inputKey = null; public boolean inputKeyInit() { @@ -2333,6 +2311,7 @@ public class CompiledReplicatedMapQueryContext 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); - } - - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.entrySpaceOffset; - } - - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.freeList; - } - - void closeSegment() { - if (!(this.segmentInit())) - return ; - - this.closeSegmentDependants(); - entrySpaceOffset = 0; - } - - public void closeSegmentDependants() { - CompiledReplicatedMapQueryContext.this.closeEntry(); - } - - public long pos = -1; - - public long keySizeOffset; - - public long keySize; - - public long keyOffset; - - public boolean entryInit() { - return (this.pos) >= 0; - } - - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; - } - - public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keySizeOffset; - } - - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) - return ; - - this.closeEntryDependants(); - this.pos = -1; - } - - public void closeEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationState(); - } - - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValue(); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - } - - void initReplicationState(long timestamp, byte identifier) { - replicationBytesOffset = keyEnd(); - entryBytes.position(replicationBytesOffset); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.replicationBytesOffset = -1; - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - public void dropChange() { - CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); - } - - public void closeReplicationUpdateDropChangeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - } - - int hashLookupEntrySize; - - int keyBits; - - long address = -1; - - long capacityMask; - - long capacityMask2; - - long keyMask; - - long valueMask; - - long entryMask; - - public boolean segmentHashLookupInit() { - return (this.address) >= 0; - } - - public void initSegmentHashLookup() { - long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); - this.closeSegmentHashLookupDependants(); - } - - public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { - innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); - this.closeSegmentHashLookupDependants(); - } - - public int hashLookupEntrySize() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.hashLookupEntrySize; - } - - public int keyBits() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyBits; - } - - public long address() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.address; - } - - public long capacityMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask; - } - - public long capacityMask2() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask2; - } - - public long entryMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.entryMask; - } - - public long keyMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyMask; - } - - public long valueMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.valueMask; - } - - public void closeSegmentHashLookup() { - if (!(this.segmentHashLookupInit())) - return ; - - this.closeSegmentHashLookupDependants(); - this.address = -1; - } - - public void closeSegmentHashLookupDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public void closeHashLookupStepDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public void closeHashLookupReadEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - long entry(long key, long value) { - return key | (value << (keyBits())); - } - - public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public void closeHashLookupIndexToPosDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - public void closeHashLookupHlPosDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void putValueVolatile(long pos, long value) { - checkValueForPut(value); - long currentEntry = readEntry(pos); - writeEntryVolatile(pos, currentEntry, key(currentEntry), value); - } - - void forEach(EntryConsumer action) { - for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { - long entry = readEntry(pos); - if (!(empty(entry))) - action.accept(key(entry), value(entry)); - - } - } - - String hashLookupToString() { - final StringBuilder sb = new StringBuilder("{"); - forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); - } - - public void writeEntry(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long remove(long posToRemove) { - long entryToRemove = readEntry(posToRemove); - long posToShift = posToRemove; - while (true) { - posToShift = step(posToShift); - long entryToShift = readEntry(posToShift); - if (empty(entryToShift)) - break; - - long insertPos = hlPos(key(entryToShift)); - boolean cond1 = insertPos <= posToRemove; - boolean cond2 = posToRemove <= posToShift; - if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { - writeEntry(posToRemove, entryToRemove, entryToShift); - posToRemove = posToShift; - entryToRemove = entryToShift; - } - } - clearEntry(posToRemove, entryToRemove); - return posToRemove; - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); } long segmentHeaderAddress; @@ -2923,25 +2424,31 @@ public class CompiledReplicatedMapQueryContext h = CompiledReplicatedMapQueryContext.this.h(); - if (chunks > (h.maxChunksPerEntry)) - throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); - - long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - ret = freeList().setNextNContinuousClearBits(0L, chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - if (chunks == 1) { - throw new IllegalStateException("Segment is full, no free entries found"); - } else { - throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); - } - } - updateNextPosToSearchFrom(ret, chunks); - } else { - if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { - updateNextPosToSearchFrom(ret, chunks); - } - } - return ret; - } - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { @@ -2995,6 +2472,10 @@ public class CompiledReplicatedMapQueryContext= 0; } - public void clear() { - clearSegment(); + public void initSegmentHashLookup() { + long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); + this.closeSegmentHashLookupDependants(); } - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); + public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { + innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); + this.closeSegmentHashLookupDependants(); } - public long entries() { - return segmentHeader().size(segmentHeaderAddress()); + public int hashLookupEntrySize() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.hashLookupEntrySize; } - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); + public int keyBits() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyBits; } - public long size() { - return (entries()) - (deleted()); + public long address() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.address; + } + + public long capacityMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask; + } + + public long capacityMask2() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask2; + } + + public long entryMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.entryMask; + } + + public long keyMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyMask; + } + + public long valueMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.valueMask; + } + + public void closeSegmentHashLookup() { + if (!(this.segmentHashLookupInit())) + return ; + + this.closeSegmentHashLookupDependants(); + this.address = -1; + } + + public void closeSegmentHashLookupDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public void closeHashLookupKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + public void closeHashLookupEmptyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void closeHashLookupReadEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public void writeEntry(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void closeHashLookupHlPosDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; } long searchKey = UNSET_KEY; @@ -3161,8 +2837,8 @@ public class CompiledReplicatedMapQueryContext>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + public long nextPos() { long pos = CompiledReplicatedMapQueryContext.this.hashLookupPos(); while (true) { @@ -3270,6 +2957,188 @@ public class CompiledReplicatedMapQueryContext sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); + } + + public boolean checkSlotContainsExpectedKeyAndValue(long value) { + long entry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); + return ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledReplicatedMapQueryContext.this.value(entry)) == value); + } + + public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + long hashLookupOffset = h.segmentOffset(segmentIndex()); + long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); + freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); + freeList.reuse(freeListBytes); + entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); + this.closeSegmentDependants(); + } + + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.entrySpaceOffset; + } + + public SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.freeList; + } + + void closeSegment() { + if (!(this.segmentInit())) + return ; + + this.closeSegmentDependants(); + entrySpaceOffset = 0; + } + + public void closeSegmentDependants() { + CompiledReplicatedMapQueryContext.this.closeEntry(); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + if (chunks > (h.maxChunksPerEntry)) + throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); + + long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + ret = freeList().setNextNContinuousClearBits(0L, chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + if (chunks == 1) { + throw new IllegalStateException("Segment is full, no free entries found"); + } else { + throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); + } + } + updateNextPosToSearchFrom(ret, chunks); + } else { + if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { + updateNextPosToSearchFrom(ret, chunks); + } + } + return ret; + } + + public long pos = -1; + + public long keySizeOffset; + + public long keySize; + + public long keyOffset; + + public boolean entryInit() { + return (this.pos) >= 0; + } + + public void initEntry(long pos) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); + keyOffset = entryBytes.position(); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntry(long pos, Value key) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = key.size(); + CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); + keyOffset = entryBytes.position(); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntryCopying(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset; + initKeySizeOffset(newPos); + long oldKeyOffset = keyOffset; + keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); + pos = newPos; + this.closeEntryDependants(); + } + + public long keyOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keyOffset; + } + + public long keySize() { + assert this.entryInit() : "Entry should be init"; + return this.keySize; + } + + public long keySizeOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keySizeOffset; + } + + public long pos() { + assert this.entryInit() : "Entry should be init"; + return this.pos; + } + + public void closeEntry() { + if (!(this.entryInit())) + return ; + + this.closeEntryDependants(); + this.pos = -1; + } + + public void closeEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + boolean keyEquals() { return ((inputKey().size()) == (CompiledReplicatedMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledReplicatedMapQueryContext.this.entryBytesAccess)), CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle, CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()))); } @@ -3317,10 +3186,6 @@ public class CompiledReplicatedMapQueryContext entry, Value newValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); } @NotNull @Override - public InterProcessLock readLock() { + public Value defaultValue() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerReadLock; + return wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); } + @NotNull @Override - public long originTimestamp() { + public Value key() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - @Override - public Value wrapValueAsValue(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; + return CompiledReplicatedMapQueryContext.this.entryKey; } @Override @@ -3407,6 +3278,39 @@ public class CompiledReplicatedMapQueryContext queriedKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Value value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerWriteLock; + } + + @NotNull + @Override + public Value value() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryValue; + } + @NotNull @Override public InterProcessLock updateLock() { @@ -3414,26 +3318,115 @@ public class CompiledReplicatedMapQueryContext _MapQuery_absentEntry() { + @Override + public Value wrapValueAsValue(V value) { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledReplicatedMapQueryContext.this.absent(); + WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + protected boolean searchStateDeleted() { + return (((searchState()) == (SearchState.DELETED)) && (!(CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + } + + protected boolean searchStateAbsent() { + return (!(searchStatePresent())) && (!(searchStateDeleted())); + } + + private void putPrefix() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + if (underUpdatedLockIsHeld) + CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); + + boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); + if (((CompiledReplicatedMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); + + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicationState(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + } + + void initReplicationState(long timestamp, byte identifier) { + replicationBytesOffset = keyEnd(); + entryBytes.position(replicationBytesOffset); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.replicationBytesOffset = -1; + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + private boolean _MapQuery_entryPresent() { + return searchStatePresent(); + } + + protected boolean entryPresent() { + return (_MapQuery_entryPresent()) && (!(CompiledReplicatedMapQueryContext.this.entryDeleted())); } @Nullable @Override public MapAbsentEntry absentEntry() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - if (entryPresent()) { - return null; - } else { - if (!(searchStatePresent())) { - return CompiledReplicatedMapQueryContext.this.absentDelegating; - } else { - assert CompiledReplicatedMapQueryContext.this.entryDeleted(); - return CompiledReplicatedMapQueryContext.this.absent(); - } - } + return entryPresent() ? null : this; } private MapEntry _MapQuery_entry() { @@ -3446,65 +3439,16 @@ public class CompiledReplicatedMapQueryContext)(_MapQuery_entry())); } - @NotNull - @Override - public Value defaultValue() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); } - @NotNull - @Override - public Value value() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryValue; + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; } - public Value queriedKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerWriteLock; - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Value newValue) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @NotNull - @Override - public Value key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryKey; - } - - @NotNull - @Override - public MapContext context() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return this; + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); } @Override @@ -3513,40 +3457,50 @@ public class CompiledReplicatedMapQueryContext absentKey() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.inputKey(); - } - - protected void putPrefix() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); - if (underUpdatedLockIsHeld) - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - - boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); - if (((CompiledReplicatedMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) - CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); - - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; + return inputKey(); } public long riKeySize = -1; @@ -3557,12 +3511,6 @@ public class CompiledReplicatedMapQueryContext= 0; } @@ -3571,25 +3519,41 @@ public class CompiledReplicatedMapQueryContext newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); } private long _HashEntryStages_entryEnd() { @@ -3842,88 +3792,6 @@ public class CompiledReplicatedMapQueryContext newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - @Override - public long remoteTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newTimestamp(); - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newIdentifier(); - } - - private boolean testTimeStampInSensibleRange() { - if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { - long currentTime = TimeProvider.SYSTEM.currentTime(); - assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); - assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapQueryContext.this.newTimestamp()); - } - return true; - } - - public Bytes replicatedInputBytes = null; - - public boolean replicatedInputBytesInit() { - return (this.replicatedInputBytes) != null; - } - - public void initReplicatedInputBytes(Bytes replicatedInputBytes) { - this.replicatedInputBytes = replicatedInputBytes; - this.closeReplicatedInputBytesDependants(); - } - - public Bytes replicatedInputBytes() { - assert this.replicatedInputBytesInit() : "ReplicatedInputBytes should be init"; - return this.replicatedInputBytes; - } - - public void closeReplicatedInputBytes() { - if (!(this.replicatedInputBytesInit())) - return ; - - this.closeReplicatedInputBytesDependants(); - this.replicatedInputBytes = null; - } - - public void closeReplicatedInputBytesDependants() { - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueGetUsingDependants(); - } - - public int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; - } - - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; - } - - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) - return ; - - this.allocatedChunks = 0; - } - public final void freeExtraAllocatedChunks() { if (((!(CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapQueryContext.this.allocatedChunks()))) { CompiledReplicatedMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); @@ -3932,31 +3800,90 @@ public class CompiledReplicatedMapQueryContext value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - public void initEntryAndKey(long entrySize) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - void putEntry(Value value) { - assert CompiledReplicatedMapQueryContext.this.searchStateAbsent(); - long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(CompiledReplicatedMapQueryContext.this.inputKey().size(), value.size()); + assert searchStateAbsent(); + long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(inputKey().size(), value.size()); CompiledReplicatedMapQueryContext.this.initEntryAndKey(entrySize); CompiledReplicatedMapQueryContext.this.initValue(value); CompiledReplicatedMapQueryContext.this.freeExtraAllocatedChunks(); CompiledReplicatedMapQueryContext.this.putNewVolatile(CompiledReplicatedMapQueryContext.this.pos()); } - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntryCopying(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); + public void writeValueAndPutPos(Value value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + private void _MapEntryStages_putValueDeletedEntry(Value newValue) { + assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = CompiledReplicatedMapQueryContext.this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapQueryContext.this.freeList().size())) && (CompiledReplicatedMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + CompiledReplicatedMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + CompiledReplicatedMapQueryContext.this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValueAgain(newValue); + } else { + writeValueGuarded(newValue); + } + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + public void putValueDeletedEntry(Value newValue) { + throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); + } + + @Override + public void doInsert(Value value) { + putPrefix(); + if (!(searchStatePresent())) { + if (searchStateDeleted()) { + CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); + } else { + putEntry(value); + } + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + } + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); } private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { @@ -4030,47 +3957,12 @@ public class CompiledReplicatedMapQueryContext newValue) { putPrefix(); @@ -4083,85 +3975,42 @@ public class CompiledReplicatedMapQueryContext newValue) { - assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledReplicatedMapQueryContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapQueryContext.this.freeList().size())) && (CompiledReplicatedMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledReplicatedMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - CompiledReplicatedMapQueryContext.this.incrementSegmentEntriesIfNeeded(); - if (newValueSizeIsDifferent) { - initValueAgain(newValue); - } else { - writeValueGuarded(newValue); - } - } else { - if (newValueSizeIsDifferent) { - assert newSizeOfEverythingBeforeValue >= 0; - } else { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - } - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - if (newValueSizeIsDifferent) { - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + @Override + public byte remoteIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return newIdentifier(); } - public void putValueDeletedEntry(Value newValue) { - throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); - } - - private void _MapAbsent_doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.putPrefix(); - if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { - if (CompiledReplicatedMapQueryContext.this.searchStateDeleted()) { - CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); - } else { - putEntry(value); - } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - CompiledReplicatedMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + private boolean testTimeStampInSensibleRange() { + if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapQueryContext.this.newTimestamp()); } + return true; } @Override - public void doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.putPrefix(); - if (!(CompiledReplicatedMapQueryContext.this.entryPresent())) { - if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { - putEntry(value); - CompiledReplicatedMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); - } else { - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(value); - CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) - 1)); - } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - CompiledReplicatedMapQueryContext.this.writeEntryPresent(); - } else { - throw new IllegalStateException("Entry is absent in the map when doInsert() is called"); - } + public long remoteTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return newTimestamp(); + } + + private boolean updatedReplicationState = false; + + public boolean updatedReplicationStateInit() { + return (this.updatedReplicationState) != false; + } + + public void initUpdatedReplicationState() { + initReplicationState(CompiledReplicatedMapQueryContext.this.newTimestamp(), CompiledReplicatedMapQueryContext.this.newIdentifier()); + updatedReplicationState = true; + } + + public void closeUpdatedReplicationState() { + if (!(this.updatedReplicationStateInit())) + return ; + + this.updatedReplicationState = false; } }