From 9746084998d53dfc41a675c6962ee73285365914 Mon Sep 17 00:00:00 2001 From: leventov Date: Tue, 16 Jun 2015 16:22:32 +0300 Subject: [PATCH] Start setting lastModifiedTime and fixed bootstrapping; clarified some test @Ignores --- .../chronicle/map/ReplicatedChronicleMap.java | 16 +- .../map/impl/CompiledMapIterationContext.java | 1507 ++++---- .../map/impl/CompiledMapQueryContext.java | 2838 +++++++------- ...CompiledReplicatedMapIterationContext.java | 2124 +++++----- .../CompiledReplicatedMapQueryContext.java | 3400 +++++++++-------- .../chronicle/map/CHMUseCasesTest.java | 1 - .../chronicle/map/ChronicleMapTest.java | 2 +- .../chronicle/map/DefaultValueTest.java | 2 +- .../chronicle/map/StatelessClientTest.java | 2 +- .../TCPSocketReplicationBootStrapTest.java | 4 +- .../map/example/ChannelReplicationTest.java | 1 - .../openhft/lang/values/DoubleArrayTest.java | 2 +- 12 files changed, 5032 insertions(+), 4867 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 3defb8fce..2eeb5dc2d 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -185,7 +185,7 @@ public class ReplicatedChronicleMap { - LOG.debug("Bootstrap entry: id {}, key {}, value {}", localIdentifier, - c.key(), c.value()); + if (debugEnabled) { + LOG.debug("Bootstrap entry: id {}, key {}, value {}", localIdentifier, + c.key(), c.value()); + } MapReplicableEntry re = (MapReplicableEntry) entry; assert re.originTimestamp() > 0L; - if (re.originIdentifier() >= fromTimeStamp && + if (debugEnabled) { + LOG.debug("Bootstrap decision: bs ts: {}, entry ts: {}, entry id: {}, " + + "local id: {}", fromTimeStamp, re.originTimestamp(), + re.originIdentifier(), localIdentifier); + } + if (re.originTimestamp() >= fromTimeStamp && (!bootstrapOnlyLocalEntries || re.originIdentifier() == localIdentifier)) { raiseChange(segmentIndex, c.pos()); diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java index 3ced7034c..fb0f7cf37 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java @@ -33,18 +33,20 @@ import java.util.function.Predicate; public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , MapContext , MapEntry , IterationContextInterface , VanillaChronicleMapHolder { public void close() { - CompiledMapIterationContext.this.closeTheSegmentIndex(); - CompiledMapIterationContext.this.closeAllocatedChunks(); - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue(); - CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration(); - CompiledMapIterationContext.this.closeUsed(); CompiledMapIterationContext.this.closeHashLookupPos(); + CompiledMapIterationContext.this.closeKeyOffset(); + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); + CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration(); + CompiledMapIterationContext.this.closePos(); + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapIterationContext.this.closeTheSegmentIndex(); + CompiledMapIterationContext.this.closeKeySize(); + CompiledMapIterationContext.this.closeUsed(); + CompiledMapIterationContext.this.closeAllocatedChunks(); + CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); + CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); CompiledMapIterationContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); CompiledMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); } public void incrementModCountGuarded() { @@ -66,40 +68,28 @@ public class CompiledMapIterationContext value) { - if (!(this.valueInit())) - this.initValue(); - - writeValue(value); - } - - void initKeySizeOffset(long pos) { - keySizeOffset = (CompiledMapIterationContext.this.entrySpaceOffset()) + (pos * (CompiledMapIterationContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - } - public CompiledMapIterationContext(VanillaChronicleMap m) { contextChain = new ArrayList(); contextChain.add(this); indexInContextChain = 0; this.m = m; - this.innerWriteLock = new WriteLock(); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryKey = new EntryKeyBytesData(); this.entryValue = new EntryValueBytesData(); this.innerReadLock = new ReadLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.entryKey = new EntryKeyBytesData(); - this.innerUpdateLock = new UpdateLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.innerWriteLock = new WriteLock(); this.owner = Thread.currentThread(); + this.innerUpdateLock = new UpdateLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledMapIterationContext.this.m().valueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueInterop); this.valueReader = CompiledMapIterationContext.this.m().valueReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueReader); this.keyInterop = CompiledMapIterationContext.this.h().keyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyInterop); this.keyReader = CompiledMapIterationContext.this.h().keyReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyReader); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); } public CompiledMapIterationContext(CompiledMapIterationContext c) { @@ -107,35 +97,59 @@ public class CompiledMapIterationContext)(c.m)); - this.innerWriteLock = new WriteLock(); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryKey = new EntryKeyBytesData(); this.entryValue = new EntryValueBytesData(); this.innerReadLock = new ReadLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.entryKey = new EntryKeyBytesData(); - this.innerUpdateLock = new UpdateLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.innerWriteLock = new WriteLock(); this.owner = Thread.currentThread(); + this.innerUpdateLock = new UpdateLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledMapIterationContext.this.m().valueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueInterop); this.valueReader = CompiledMapIterationContext.this.m().valueReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueReader); this.keyInterop = CompiledMapIterationContext.this.h().keyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyInterop); this.keyReader = CompiledMapIterationContext.this.h().keyReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyReader); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); } public class DeprecatedMapKeyContextOnIteration implements MapKeyContext { + @NotNull + private UnsupportedOperationException unsupportedLocks() { + return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); + } + + @NotNull + @Override + public InterProcessLock readLock() { + throw unsupportedLocks(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + throw unsupportedLocks(); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + throw unsupportedLocks(); + } + @Override public void close() { throw new UnsupportedOperationException("close() is not supported during iteration"); } + @NotNull @Override - public boolean valueEqualTo(V value) { + public Bytes entry() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return Data.bytesEquivalent(CompiledMapIterationContext.this.entryValue, CompiledMapIterationContext.this.context().wrapValueAsValue(value)); + return CompiledMapIterationContext.this.entryBytes; } @NotNull @@ -145,6 +159,12 @@ public class CompiledMapIterationContext { - @Override - public T handle() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccessHandle; - } - @Override public ReadAccess access() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); return CompiledMapIterationContext.this.entryBytesAccess; } + @Override + public T handle() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryBytesAccessHandle; + } + @Override public long size() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); @@ -255,6 +245,12 @@ public class CompiledMapIterationContext { - @Override - public ReadAccess access() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccess; - } - @Override public T handle() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); @@ -324,9 +308,9 @@ public class CompiledMapIterationContext access() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccessOffset(CompiledMapIterationContext.this.valueOffset()); + return CompiledMapIterationContext.this.entryBytesAccess; } @Override @@ -339,6 +323,12 @@ public class CompiledMapIterationContext { @@ -633,14 +623,14 @@ public class CompiledMapIterationContext value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); - } - final Thread owner; public Thread owner() { @@ -864,15 +850,6 @@ public class CompiledMapIterationContext value) { - entryBytes.position(valueSizeOffset); - valueSize = value.size(); - CompiledMapIterationContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - CompiledMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - writeValue(value); - } - private void unlinkFromSegmentContextsChain() { CompiledMapIterationContext prevContext = this.rootContextOnThisSegment; while (true) { @@ -982,6 +959,11 @@ public class CompiledMapIterationContext m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + + public void checkAccessingFromOwnerThread() { + if ((owner) != (Thread.currentThread())) { + throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + } + } + + public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { + CompiledMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + public void checkEntryNotRemovedOnThisIteration() { if (entryRemovedOnThisIterationInit()) throw new IllegalStateException("Entry was already removed on this iteration"); @@ -1062,13 +1087,117 @@ public class CompiledMapIterationContext value() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryValue; + } + + @NotNull + @Override + public Data key() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryKey; + } + + @NotNull + @Override + public InterProcessLock updateLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerUpdateLock; + } + + @Override + public Data wrapValueAsValue(V value) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = CompiledMapIterationContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerReadLock; + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerWriteLock; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.remove(entry); + } + + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (CompiledMapIterationContext.this.m().constantlySizedEntry) { + return CompiledMapIterationContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (CompiledMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (CompiledMapIterationContext.this.m().worstAlignment)) + valueSize; + } else { + return (CompiledMapIterationContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; + } + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + } + + public MKI keyMetaInterop(K key) { + return CompiledMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); + } + + public MVI valueMetaInterop(V value) { + return CompiledMapIterationContext.this.m().metaValueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeBuffer(); } private CompiledMapIterationContext _Chaining_createChaining() { @@ -1092,220 +1221,12 @@ public class CompiledMapIterationContext context() { return CompiledMapIterationContext.this; } - @Override - public VanillaChronicleMap m() { - return m; - } - - @Override - public ChronicleMap map() { - return m(); - } - - public MVI valueMetaInterop(V value) { - return CompiledMapIterationContext.this.m().metaValueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeBuffer(); - } - - public void checkAccessingFromOwnerThread() { - if ((owner) != (Thread.currentThread())) { - throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); - } - } - - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { - CompiledMapIterationContext.this.checkAccessingFromOwnerThread(); - } - - public void checkOnEachPublicOperation() { - _CheckOnEachPublicOperation_checkOnEachPublicOperation(); - CompiledMapIterationContext.this.checkEntryNotRemovedOnThisIteration(); - } - - public void closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { - CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @NotNull - @Override - public Data key() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryKey; - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.remove(entry); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerUpdateLock; - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public Data defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerReadLock; - } - - @Override - public Data wrapValueAsValue(V value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledMapIterationContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerWriteLock; - } - - @NotNull - @Override - public Data value() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryValue; - } - - public T contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledMapIterationContext.this.m().metaDataBytes) + (CompiledMapIterationContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - public MKI keyMetaInterop(K key) { - return CompiledMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); - } - - public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { - if (CompiledMapIterationContext.this.m().constantlySizedEntry) { - return CompiledMapIterationContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); - } else if (CompiledMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { - return (sizeOfEverythingBeforeValue + (CompiledMapIterationContext.this.m().worstAlignment)) + valueSize; - } else { - return (CompiledMapIterationContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; - } - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - public boolean entryIsPresent() { - return true; - } - - public long hashLookupPos = -1; - - public boolean hashLookupPosInit() { - return (this.hashLookupPos) >= 0; - } - - public void initHashLookupPos(long hashLookupPos) { - this.hashLookupPos = hashLookupPos; - } - - public long hashLookupPos() { - assert this.hashLookupPosInit() : "HashLookupPos should be init"; - return this.hashLookupPos; - } - - public void closeHashLookupPos() { - if (!(this.hashLookupPosInit())) - return ; - - this.hashLookupPos = -1; - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; - } - - public boolean entryRemovedOnThisIteration = false; - - boolean entryRemovedOnThisIterationInit() { - return (this.entryRemovedOnThisIteration) != false; - } - - protected void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { - this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; - } - - public void closeEntryRemovedOnThisIteration() { - if (!(this.entryRemovedOnThisIterationInit())) - return ; - - this.entryRemovedOnThisIteration = false; - } - public int allocatedChunks = 0; public boolean allocatedChunksInit() { @@ -1328,6 +1249,52 @@ public class CompiledMapIterationContext= 0; + } + + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); + } + + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; + } + + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; + } + + public void closeKeySizeDependants() { + CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + CompiledMapIterationContext.this.closeMapEntryStagesKeyEndDependants(); + } + public int segmentIndex = -1; public boolean theSegmentIndexInit() { @@ -1354,8 +1321,8 @@ public class CompiledMapIterationContext>> (keyBits())) & (valueMask()); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); } public long maskUnsetKey(long key) { return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); } - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); } void writeEntry(long pos, long prevEntry, long anotherEntry) { @@ -1492,34 +1438,55 @@ public class CompiledMapIterationContext= 0 ? pos : capacityMask2(); } - 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)); - - } + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; } - String hashLookupToString() { - final StringBuilder sb = new StringBuilder("{"); - forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); + long indexToPos(long index) { + return index * (hashLookupEntrySize()); } - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + 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 void writeEntryVolatile(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); + } + + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); } public long step(long pos) { return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; } + 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; @@ -1542,24 +1509,70 @@ public class CompiledMapIterationContext>> (keyBits())) & (valueMask()); } - 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 forEach(EntryConsumer action) { + for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { + long entry = readEntry(pos); + if (!(empty(entry))) + action.accept(key(entry), value(entry)); + + } } - 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); + 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 putValueVolatile(long pos, long value) { - checkValueForPut(value); - long currentEntry = readEntry(pos); - writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledMapIterationContext.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() { + CompiledMapIterationContext.this.closeEntryOffset(); } long segmentHeaderAddress; @@ -1603,18 +1616,6 @@ public class CompiledMapIterationContext= (CompiledMapIterationContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } - - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - int totalReadLockCount; int totalUpdateLockCount; @@ -1724,88 +1701,28 @@ public class CompiledMapIterationContext> action) { - CompiledMapIterationContext.this.innerUpdateLock.lock(); - try { - long size = CompiledMapIterationContext.this.size(); - if (size == 0) - return true; - - boolean interrupted = false; - long startPos = 0L; - while (!(CompiledMapIterationContext.this.empty(CompiledMapIterationContext.this.readEntry(startPos)))) { - startPos = CompiledMapIterationContext.this.step(startPos); - } - CompiledMapIterationContext.this.initHashLookupPos(startPos); - do { - CompiledMapIterationContext.this.setHashLookupPosGuarded(CompiledMapIterationContext.this.step(CompiledMapIterationContext.this.hashLookupPos())); - long entry = CompiledMapIterationContext.this.readEntry(CompiledMapIterationContext.this.hashLookupPos()); - if (!(CompiledMapIterationContext.this.empty(entry))) { - CompiledMapIterationContext.this.initEntry(CompiledMapIterationContext.this.value(entry)); - if (entryIsPresent()) { - initEntryRemovedOnThisIteration(false); - if (!(action.test(((MapEntry)(this))))) { - interrupted = true; - break; - } else { - if ((--size) == 0) - break; - - } - } - } - } while ((CompiledMapIterationContext.this.hashLookupPos()) != startPos ); - return !interrupted; - } finally { - CompiledMapIterationContext.this.innerReadLock.unlock(); - initEntryRemovedOnThisIteration(false); - } + public long entries() { + return segmentHeader().size(segmentHeaderAddress()); } - long entrySpaceOffset = 0; - - MultiStoreBytes freeListBytes = new MultiStoreBytes(); - - public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); - - boolean segmentInit() { - return (entrySpaceOffset) > 0; + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); } - void initSegment() { - VanillaChronicleHash h = CompiledMapIterationContext.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 void entries(long size) { + segmentHeader().size(segmentHeaderAddress(), size); } - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.entrySpaceOffset; + public void nextPosToSearchFrom(long nextPosToSearchFrom) { + segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); } - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (CompiledMapIterationContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; - return this.freeList; - } - - void closeSegment() { - if (!(this.segmentInit())) - return ; - - this.closeSegmentDependants(); - entrySpaceOffset = 0; - } - - public void closeSegmentDependants() { - CompiledMapIterationContext.this.closeEntry(); + nextPosToSearchFrom(nextPosToSearchFrom); } public long alloc(int chunks) { @@ -1838,12 +1755,6 @@ public class CompiledMapIterationContext= 0; } - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); + public void initPos(long pos) { this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Data key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledMapIterationContext.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; + this.closePosDependants(); } public long pos() { - assert this.entryInit() : "Entry should be init"; + assert this.posInit() : "Pos should be init"; return this.pos; } - public void closeEntry() { - if (!(this.entryInit())) + public void closePos() { + if (!(this.posInit())) return ; - this.closeEntryDependants(); + this.closePosDependants(); this.pos = -1; } - public void closeEntryDependants() { - CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + public void closePosDependants() { + CompiledMapIterationContext.this.closeEntryOffset(); + } + + public long keySizeOffset = -1; + + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; + } + + public void initEntryOffset() { + keySizeOffset = (CompiledMapIterationContext.this.entrySpaceOffset()) + ((pos()) * (CompiledMapIterationContext.this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); + } + + public long keySizeOffset() { + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + + return this.keySizeOffset; + } + + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) + return ; + + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; + } + + public void closeEntryOffsetDependants() { + CompiledMapIterationContext.this.closeMapEntryStagesEntrySizeDependants(); + } + + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(CompiledMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); + } + + public boolean entryRemovedOnThisIteration = false; + + boolean entryRemovedOnThisIterationInit() { + return (this.entryRemovedOnThisIteration) != false; + } + + protected void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { + this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; + } + + public void closeEntryRemovedOnThisIteration() { + if (!(this.entryRemovedOnThisIterationInit())) + return ; + + this.entryRemovedOnThisIteration = false; + } + + public long keyOffset = -1; + + public boolean keyOffsetInit() { + return (this.keyOffset) >= 0; + } + + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); + } + + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; + } + + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); CompiledMapIterationContext.this.closeMapEntryStagesKeyEndDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesEntrySizeDependants(); + } + + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + CompiledMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); } public long keyEnd() { @@ -1954,86 +1921,114 @@ public class CompiledMapIterationContext= 0; + public boolean valueSizeOffsetInit() { + return (this.valueSizeOffset) >= 0; } - void initValue() { + void initValueSizeOffset() { valueSizeOffset = countValueSizeOffset(); - entryBytes.position(valueSizeOffset); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + CompiledMapIterationContext.this.closeValSize(); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); valueSize = CompiledMapIterationContext.this.m().readValueSize(entryBytes); - CompiledMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - this.closeValueDependants(); + countValueOffset(); + this.closeValSizeDependants(); } - public void initValue(Data value) { - valueSizeOffset = countValueSizeOffset(); - innerInitValue(value); - this.closeValueDependants(); + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + CompiledMapIterationContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); } - public void initValueAgain(Data value) { - assert valueInit(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSizeOffset = countValueSizeOffset(); - assert oldValueSize == (value.size()); + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { valueSize = oldValueSize; - valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); - writeValue(value); - this.closeValueDependants(); + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); } public long valueOffset() { - if (!(this.valueInit())) - this.initValue(); + if (!(this.valSizeInit())) + this.initValSize(); return this.valueOffset; } public long valueSize() { - if (!(this.valueInit())) - this.initValue(); + if (!(this.valSizeInit())) + this.initValSize(); return this.valueSize; } - public long valueSizeOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSizeOffset; - } - - public void closeValue() { - if (!(this.valueInit())) + public void closeValSize() { + if (!(this.valSizeInit())) return ; - this.closeValueDependants(); - this.valueOffset = -1; + this.closeValSizeDependants(); + this.valueSize = -1; } - public void closeValueDependants() { + public void closeValSizeDependants() { CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); } - public long newSizeOfEverythingBeforeValue(Data newValue) { - return ((valueSizeOffset()) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + public void writeValue(Data value) { + value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); } private long _HashEntryStages_entryEnd() { @@ -2084,6 +2079,12 @@ public class CompiledMapIterationContext value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); + } + + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { + initAllocatedChunks(CompiledMapIterationContext.this.h().inChunks(entrySize)); + CompiledMapIterationContext.this.copyExistingEntry(CompiledMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); + } + + public long hashLookupPos = -1; + + public boolean hashLookupPosInit() { + return (this.hashLookupPos) >= 0; + } + + public void initHashLookupPos(long hashLookupPos) { + this.hashLookupPos = hashLookupPos; + } + + public long hashLookupPos() { + assert this.hashLookupPosInit() : "HashLookupPos should be init"; + return this.hashLookupPos; + } + + public void closeHashLookupPos() { + if (!(this.hashLookupPosInit())) + return ; + + this.hashLookupPos = -1; } public void putValueDeletedEntry(Data newValue) { @@ -2117,9 +2148,9 @@ public class CompiledMapIterationContext value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); + } + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { CompiledMapIterationContext.this.free(pos(), entrySizeInChunks()); long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); @@ -2177,9 +2214,9 @@ public class CompiledMapIterationContext> action) { + CompiledMapIterationContext.this.innerUpdateLock.lock(); + try { + long size = CompiledMapIterationContext.this.size(); + if (size == 0) + return true; + + boolean interrupted = false; + long startPos = 0L; + while (!(CompiledMapIterationContext.this.empty(CompiledMapIterationContext.this.readEntry(startPos)))) { + startPos = CompiledMapIterationContext.this.step(startPos); + } + CompiledMapIterationContext.this.initHashLookupPos(startPos); + do { + CompiledMapIterationContext.this.setHashLookupPosGuarded(CompiledMapIterationContext.this.step(CompiledMapIterationContext.this.hashLookupPos())); + long entry = CompiledMapIterationContext.this.readEntry(CompiledMapIterationContext.this.hashLookupPos()); + if (!(CompiledMapIterationContext.this.empty(entry))) { + CompiledMapIterationContext.this.readExistingEntry(CompiledMapIterationContext.this.value(entry)); + if (entryIsPresent()) { + initEntryRemovedOnThisIteration(false); + if (!(action.test(((MapEntry)(this))))) { + interrupted = true; + break; + } else { + if ((--size) == 0) + break; + + } + } + } + } while ((CompiledMapIterationContext.this.hashLookupPos()) != startPos ); + return !interrupted; + } finally { + CompiledMapIterationContext.this.innerReadLock.unlock(); + initEntryRemovedOnThisIteration(false); + } + } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java index 047a9d234..45e9abc50 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java @@ -20,6 +20,7 @@ package net.openhft.chronicle.map.impl; import net.openhft.chronicle.algo.hashing.LongHashFunction; import net.openhft.chronicle.bytes.Access; +import net.openhft.chronicle.bytes.Accessor; import net.openhft.chronicle.bytes.Accessor.Full; import net.openhft.chronicle.bytes.ReadAccess; import net.openhft.chronicle.hash.AbstractData; @@ -53,23 +54,26 @@ import java.util.ConcurrentModificationException; import java.util.List; import java.util.concurrent.TimeUnit; -public class CompiledMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , VanillaChronicleMapHolder , MapAbsentEntryHolder { +public class CompiledMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , MapAbsentEntryHolder , QueryContextInterface , VanillaChronicleMapHolder { public void close() { - CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); - CompiledMapQueryContext.this.wrappedValueInstanceValue.closeValue(); - CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); - CompiledMapQueryContext.this.closeInputBytes(); - CompiledMapQueryContext.this.closeUsed(); + CompiledMapQueryContext.this.closeKeyOffset(); CompiledMapQueryContext.this.closeInputKey(); - CompiledMapQueryContext.this.closeAllocatedChunks(); CompiledMapQueryContext.this.wrappedValueInstanceValue.closeNext(); + CompiledMapQueryContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapQueryContext.this.closeInputBytes(); + CompiledMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); + CompiledMapQueryContext.this.closePos(); + CompiledMapQueryContext.this.closeKeySize(); + CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledMapQueryContext.this.closeAllocatedChunks(); + CompiledMapQueryContext.this.closeUsed(); CompiledMapQueryContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); - CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); CompiledMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); + CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); + CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); } public void incrementModCountGuarded() { @@ -100,18 +104,6 @@ public class CompiledMapQueryContext value) { - if (!(this.valueInit())) - this.initValue(); - - writeValue(value); - } - - void initKeySizeOffset(long pos) { - keySizeOffset = (CompiledMapQueryContext.this.entrySpaceOffset()) + (pos * (CompiledMapQueryContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - } - void keyFound() { searchState = SearchState.PRESENT; } @@ -121,31 +113,31 @@ public class CompiledMapQueryContext)(entryBytesAccessor.access(entryBytes))); - this.innerReadLock = new ReadLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledMapQueryContext.this.m().valueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledMapQueryContext.this.m().valueReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledMapQueryContext.this.h().keyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledMapQueryContext.this.h().keyReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyReader); + this.usingReturnValue = new UsingReturnValue(); this.inputKeyBytesValue = new InputKeyBytesData(); this.defaultReturnValue = new DefaultReturnValue(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.entryBytes = CompiledMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerReadLock = new ReadLock(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesData(); + this.owner = Thread.currentThread(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); } public CompiledMapQueryContext(CompiledMapQueryContext c) { @@ -153,31 +145,31 @@ public class CompiledMapQueryContext)(c.m)); - this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); this.entryKey = new EntryKeyBytesData(); - this.inputSecondValueBytesValue = new InputSecondValueBytesData(); - this.entryValue = new EntryValueBytesData(); - this.innerUpdateLock = new UpdateLock(); - this.usingReturnValue = new UsingReturnValue(); + this.inputValueInstanceValue = new InputValueInstanceData(); this.inputFirstValueBytesValue = new InputFirstValueBytesData(); this.innerWriteLock = new WriteLock(); - this.inputValueInstanceValue = new InputValueInstanceData(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.owner = Thread.currentThread(); - this.entryBytes = CompiledMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.innerReadLock = new ReadLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledMapQueryContext.this.m().valueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledMapQueryContext.this.m().valueReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledMapQueryContext.this.h().keyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledMapQueryContext.this.h().keyReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyReader); + this.usingReturnValue = new UsingReturnValue(); this.inputKeyBytesValue = new InputKeyBytesData(); this.defaultReturnValue = new DefaultReturnValue(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.entryBytes = CompiledMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerReadLock = new ReadLock(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesData(); + this.owner = Thread.currentThread(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); } public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { @@ -199,10 +191,18 @@ public class CompiledMapQueryContext entry = CompiledMapQueryContext.this.entry(); + if (entry != null) { + CompiledMapQueryContext.this.replaceValue(entry, CompiledMapQueryContext.this.wrapValueAsValue(newValue)); + } else { + CompiledMapQueryContext.this.insert(CompiledMapQueryContext.this.absentEntry(), CompiledMapQueryContext.this.wrapValueAsValue(newValue)); + } + return true; } - @NotNull @Override - public Bytes entry() { + public boolean remove() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytes; + updateLock().lock(); + MapEntry entry = CompiledMapQueryContext.this.entry(); + if (entry != null) { + CompiledMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } } @Override @@ -348,69 +379,34 @@ public class CompiledMapQueryContext entry = CompiledMapQueryContext.this.entry(); - if (entry != null) { - CompiledMapQueryContext.this.replaceValue(entry, CompiledMapQueryContext.this.wrapValueAsValue(newValue)); - } else { - CompiledMapQueryContext.this.insert(CompiledMapQueryContext.this.absentEntry(), CompiledMapQueryContext.this.wrapValueAsValue(newValue)); - } - return true; - } - - @Override - public void close() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - CompiledMapQueryContext.this.close(); - } - - @Override - public long keySize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.keySize(); - } - @Override public long keyOffset() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); return CompiledMapQueryContext.this.keyOffset(); } - - @Override - public boolean remove() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry entry = CompiledMapQueryContext.this.entry(); - if (entry != null) { - CompiledMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } - } - - @NotNull - @Override - public K key() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.queriedKey().get(); - } } public class EntryKeyBytesData extends AbstractData { @Override - public long offset() { + public long size() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()); + return CompiledMapQueryContext.this.keySize(); + } + + public void closeEntryKeyBytesDataSizeDependants() { + EntryKeyBytesData.this.closeEntryKeyBytesDataInnerGetUsingDependants(); } @Override @@ -420,13 +416,15 @@ public class CompiledMapQueryContext { - @Override - public long offset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.valueOffset()); - } - @Override public ReadAccess access() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); @@ -503,6 +489,12 @@ public class CompiledMapQueryContext { - @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); - } - - @Override - public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.firstInputValueOffset()); - } - @Override public long size() { return CompiledMapQueryContext.this.firstInputValueSize(); @@ -628,14 +610,19 @@ public class CompiledMapQueryContext { + @Override + public long offset() { + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.firstInputValueOffset()); + } + @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); } + } + public class InputKeyBytesData extends AbstractData { @Override public long size() { return CompiledMapQueryContext.this.inputKeySize(); @@ -688,18 +675,11 @@ public class CompiledMapQueryContext { @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); @@ -709,10 +689,12 @@ public class CompiledMapQueryContext { @Override - public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.secondInputValueOffset()); + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); } @Override @@ -724,6 +706,16 @@ public class CompiledMapQueryContext access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); + } + @Override public V getUsing(V usingValue) { CompiledMapQueryContext.this.inputBytes().position(CompiledMapQueryContext.this.secondInputValueOffset()); @@ -768,6 +760,23 @@ public class CompiledMapQueryContext { @@ -952,18 +944,6 @@ public class CompiledMapQueryContext value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); - } - final Thread owner; public Thread owner() { @@ -1254,15 +1242,6 @@ public class CompiledMapQueryContext value) { - entryBytes.position(valueSizeOffset); - valueSize = value.size(); - CompiledMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - CompiledMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - writeValue(value); - } - private void unlinkFromSegmentContextsChain() { CompiledMapQueryContext prevContext = this.rootContextOnThisSegment; while (true) { @@ -1352,11 +1331,6 @@ public class CompiledMapQueryContext implements ValueInitableData { @@ -1425,11 +1404,6 @@ public class CompiledMapQueryContext { @@ -1627,6 +1606,11 @@ public class CompiledMapQueryContext absent() { + return CompiledMapQueryContext.this; + } + + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (CompiledMapQueryContext.this.m().constantlySizedEntry) { + return CompiledMapQueryContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (CompiledMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (CompiledMapQueryContext.this.m().worstAlignment)) + valueSize; + } else { + return (CompiledMapQueryContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; + } + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + } + @Override public VanillaChronicleMap m() { return m; @@ -1794,15 +1789,6 @@ public class CompiledMapQueryContext absent() { - return CompiledMapQueryContext.this; + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); + CompiledMapQueryContext.this.inputValueInstanceValue.closeBuffer(); } public T contextAtIndexInChain(int index) { @@ -1845,6 +1827,23 @@ public class CompiledMapQueryContext= 0; + } + + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); + } + + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; + } + + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; + } + + public void closeKeySizeDependants() { + CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); + CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + public long pos = -1; + + public boolean posInit() { + return (this.pos) >= 0; + } + + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); + } + + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) + return ; + + this.closePosDependants(); + this.pos = -1; + } + + public void closePosDependants() { + CompiledMapQueryContext.this.closeEntryOffset(); + CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public Bytes inputBytes = null; + + public boolean inputBytesInit() { + return (this.inputBytes) != null; + } + + public void initInputBytes(Bytes inputBytes) { + this.inputBytes = inputBytes; + this.closeInputBytesDependants(); + } + + public Bytes inputBytes() { + assert this.inputBytesInit() : "InputBytes should be init"; + return this.inputBytes; + } + + public void closeInputBytes() { + if (!(this.inputBytesInit())) + return ; + + this.closeInputBytesDependants(); + this.inputBytes = null; + } + + public void closeInputBytesDependants() { + CompiledMapQueryContext.this.closeInputKeyOffsets(); + CompiledMapQueryContext.this.closeFirstInputValueOffsets(); + CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.closeSecondInputValueOffsets(); + CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); + } + + public long inputKeySize = -1; + + public long inputKeyOffset; + + public boolean inputKeyOffsetsInit() { + return (this.inputKeySize) >= 0; + } + + private void initInputKeyOffsets() { + inputKeySize = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(inputBytes()); + inputKeyOffset = inputBytes().position(); + this.closeInputKeyOffsetsDependants(); + } + + public long inputKeyOffset() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeyOffset; + } + + public long inputKeySize() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeySize; + } + + public void closeInputKeyOffsets() { + if (!(this.inputKeyOffsetsInit())) + return ; + + this.closeInputKeyOffsetsDependants(); + this.inputKeySize = -1; + } + + public void closeInputKeyOffsetsDependants() { + CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); + CompiledMapQueryContext.this.closeFirstInputValueOffsets(); + CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + } + + public long firstInputValueSize = -1; + + public long firstInputValueOffset; + + public boolean firstInputValueOffsetsInit() { + return (this.firstInputValueSize) >= 0; + } + + private void initFirstInputValueOffsets() { + CompiledMapQueryContext.this.inputBytes().position(((CompiledMapQueryContext.this.inputKeyOffset()) + (CompiledMapQueryContext.this.inputKeySize()))); + firstInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); + firstInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); + this.closeFirstInputValueOffsetsDependants(); + } + + public long firstInputValueOffset() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueOffset; + } + + public long firstInputValueSize() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueSize; + } + + public void closeFirstInputValueOffsets() { + if (!(this.firstInputValueOffsetsInit())) + return ; + + this.closeFirstInputValueOffsetsDependants(); + this.firstInputValueSize = -1; + } + + public void closeFirstInputValueOffsetsDependants() { + CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); + CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.closeSecondInputValueOffsets(); + } + + public long secondInputValueSize = -1; + + public long secondInputValueOffset; + + public boolean secondInputValueOffsetsInit() { + return (this.secondInputValueSize) >= 0; + } + + private void initSecondInputValueOffsets() { + CompiledMapQueryContext.this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); + secondInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); + secondInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); + this.closeSecondInputValueOffsetsDependants(); + } + + public long secondInputValueOffset() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueOffset; + } + + public long secondInputValueSize() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueSize; + } + + public void closeSecondInputValueOffsets() { + if (!(this.secondInputValueOffsetsInit())) + return ; + + this.closeSecondInputValueOffsetsDependants(); + this.secondInputValueSize = -1; + } + + public void closeSecondInputValueOffsetsDependants() { + CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); + CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); + } + public Data inputKey = null; public boolean inputKeyInit() { @@ -1892,8 +2110,8 @@ public class CompiledMapQueryContext= 0; - } - - public void initSegmentHashLookup() { - long hashLookupOffset = CompiledMapQueryContext.this.h().segmentOffset(CompiledMapQueryContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledMapQueryContext.this.h().segmentHashLookupCapacity, CompiledMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledMapQueryContext.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() { - CompiledMapQueryContext.this.closeHashLookupValueDependants(); - CompiledMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); - CompiledMapQueryContext.this.closeHashLookupIndexToPosDependants(); - CompiledMapQueryContext.this.closeHashLookupKeyDependants(); - CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); - CompiledMapQueryContext.this.closeHashLookupStepBackDependants(); - CompiledMapQueryContext.this.closeHashLookupEmptyDependants(); - CompiledMapQueryContext.this.closeHashLookupReadEntryDependants(); - CompiledMapQueryContext.this.closeHashLookupStepDependants(); - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledMapQueryContext.this.closeSearchKey(); - } - - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public void closeHashLookupIndexToPosDependants() { - CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - 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); - } - - 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 hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - public void closeHashLookupHlPosDependants() { - CompiledMapQueryContext.this.closeSearchKey(); - } - - long searchKey = UNSET_KEY; - - long searchStartPos; - - public boolean searchKeyInit() { - return (this.searchKey) != (UNSET_KEY); - } - - void initSearchKey() { - searchKey = CompiledMapQueryContext.this.maskUnsetKey(CompiledMapQueryContext.this.h().hashSplitting.segmentHash(CompiledMapQueryContext.this.hashOfKey())); - searchStartPos = CompiledMapQueryContext.this.hlPos(searchKey); - this.closeSearchKeyDependants(); - } - - public long searchKey() { - if (!(this.searchKeyInit())) - this.initSearchKey(); - - return this.searchKey; - } - - public long searchStartPos() { - if (!(this.searchKeyInit())) - this.initSearchKey(); - - return this.searchStartPos; - } - - public void closeSearchKey() { - if (!(this.searchKeyInit())) - return ; - - this.closeSearchKeyDependants(); - this.searchKey = UNSET_KEY; - } - - public void closeSearchKeyDependants() { - CompiledMapQueryContext.this.closeHashLookupPos(); - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public void closeHashLookupReadEntryDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - 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 long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public void closeHashLookupStepDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - 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 entrySpaceOffset = 0; - - MultiStoreBytes freeListBytes = new MultiStoreBytes(); - - public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); - - boolean segmentInit() { - return (entrySpaceOffset) > 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledMapQueryContext.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() { - CompiledMapQueryContext.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 = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Data key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledMapQueryContext.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() { - CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeMapEntryStagesKeyEndDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); - } - - long countValueSizeOffset() { - return keyEnd(); - } - - public void closeMapEntryStagesCountValueSizeOffsetDependants() { - CompiledMapQueryContext.this.closeValue(); - } - - public long valueSizeOffset; - - public long valueSize; - - public long valueOffset = -1; - - boolean valueInit() { - return (this.valueOffset) >= 0; - } - - void initValue() { - valueSizeOffset = countValueSizeOffset(); - entryBytes.position(valueSizeOffset); - valueSize = CompiledMapQueryContext.this.m().readValueSize(entryBytes); - CompiledMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - this.closeValueDependants(); - } - - public void initValue(Data value) { - valueSizeOffset = countValueSizeOffset(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueAgain(Data value) { - assert valueInit(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSizeOffset = countValueSizeOffset(); - assert oldValueSize == (value.size()); - valueSize = oldValueSize; - valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); - writeValue(value); - this.closeValueDependants(); - } - - public long valueOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSize; - } - - public long valueSizeOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSizeOffset; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - this.valueOffset = -1; - } - - public void closeValueDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); - CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeMapEntryStagesEntryEndDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); - } - - public long newSizeOfEverythingBeforeValue(Data newValue) { - return ((valueSizeOffset()) + (CompiledMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - boolean keyEquals() { - return ((inputKey().size()) == (CompiledMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledMapQueryContext.this.entryBytesAccess)), CompiledMapQueryContext.this.entryBytesAccessHandle, CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()))); - } - - public void closeMapQueryKeyEqualsDependants() { - CompiledMapQueryContext.this.closeKeySearch(); - } - - long entrySize() { - return (entryEnd()) - (keySizeOffset()); - } - - public void closeMapEntryStagesEntrySizeDependants() { - CompiledMapQueryContext.this.closeTheEntrySizeInChunks(); - } - - public int entrySizeInChunks = 0; - - public boolean theEntrySizeInChunksInit() { - return (this.entrySizeInChunks) != 0; - } - - void initTheEntrySizeInChunks() { - entrySizeInChunks = CompiledMapQueryContext.this.h().inChunks(entrySize()); - } - - public void initTheEntrySizeInChunks(int actuallyUsedChunks) { - entrySizeInChunks = actuallyUsedChunks; - } - - public int entrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - this.initTheEntrySizeInChunks(); - - return this.entrySizeInChunks; - } - - public void closeTheEntrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - return ; - - this.entrySizeInChunks = 0; } long segmentHeaderAddress; @@ -2583,26 +2224,30 @@ public class CompiledMapQueryContext= (CompiledMapQueryContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); } public long entries() { return segmentHeader().size(segmentHeaderAddress()); } - public long size() { - return (entries()) - (deleted()); - } - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { CompiledMapQueryContext c = CompiledMapQueryContext.this.contextAtIndexInChain(index); if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { @@ -2716,6 +2361,456 @@ public class CompiledMapQueryContext= 0; + } + + public void initSegmentHashLookup() { + long hashLookupOffset = CompiledMapQueryContext.this.h().segmentOffset(CompiledMapQueryContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledMapQueryContext.this.h().segmentHashLookupCapacity, CompiledMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledMapQueryContext.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() { + CompiledMapQueryContext.this.closeHashLookupStepBackDependants(); + CompiledMapQueryContext.this.closeHashLookupKeyDependants(); + CompiledMapQueryContext.this.closeHashLookupReadEntryDependants(); + CompiledMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); + CompiledMapQueryContext.this.closeHashLookupValueDependants(); + CompiledMapQueryContext.this.closeHashLookupIndexToPosDependants(); + CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); + CompiledMapQueryContext.this.closeHashLookupEmptyDependants(); + CompiledMapQueryContext.this.closeHashLookupStepDependants(); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public void closeHashLookupKeyDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void closeHashLookupReadEntryDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + CompiledMapQueryContext.this.closeSearchKey(); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + public long value(long entry) { + return (entry >>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void closeHashLookupHlPosDependants() { + CompiledMapQueryContext.this.closeSearchKey(); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + public void closeHashLookupEmptyDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + 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(); + } + + 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); + } + + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + 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 void writeEntry(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledMapQueryContext.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() { + CompiledMapQueryContext.this.closeEntryOffset(); + } + + public long keySizeOffset = -1; + + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; + } + + public void initEntryOffset() { + keySizeOffset = (CompiledMapQueryContext.this.entrySpaceOffset()) + ((pos()) * (CompiledMapQueryContext.this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); + } + + public long keySizeOffset() { + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + + return this.keySizeOffset; + } + + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) + return ; + + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; + } + + public void closeEntryOffsetDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesReadExistingEntryDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); + } + + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); + } + + public void closeMapEntryStagesReadExistingEntryDependants() { + CompiledMapQueryContext.this.closeKeySearch(); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledMapQueryContext.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 void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public void clearSegment() { + CompiledMapQueryContext.this.innerWriteLock.lock(); + CompiledMapQueryContext.this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); + } + + public void clear() { + clearSegment(); + } + + long searchKey = UNSET_KEY; + + long searchStartPos; + + public boolean searchKeyInit() { + return (this.searchKey) != (UNSET_KEY); + } + + void initSearchKey() { + searchKey = CompiledMapQueryContext.this.maskUnsetKey(CompiledMapQueryContext.this.h().hashSplitting.segmentHash(CompiledMapQueryContext.this.hashOfKey())); + searchStartPos = CompiledMapQueryContext.this.hlPos(searchKey); + this.closeSearchKeyDependants(); + } + + public long searchKey() { + if (!(this.searchKeyInit())) + this.initSearchKey(); + + return this.searchKey; + } + + public long searchStartPos() { + if (!(this.searchKeyInit())) + this.initSearchKey(); + + return this.searchStartPos; + } + + public void closeSearchKey() { + if (!(this.searchKeyInit())) + return ; + + this.closeSearchKeyDependants(); + this.searchKey = UNSET_KEY; + } + + public void closeSearchKeyDependants() { + CompiledMapQueryContext.this.closeHashLookupPos(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + public long hashLookupPos = -1; public boolean hashLookupPosInit() { @@ -2749,24 +2844,17 @@ public class CompiledMapQueryContext= 0; } - public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); } - public void found() { - CompiledMapQueryContext.this.setHashLookupPosGuarded(CompiledMapQueryContext.this.stepBack(CompiledMapQueryContext.this.hashLookupPos())); + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; } - public void closeHashLookupSearchFoundDependants() { + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { + CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); + CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + } + + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + CompiledMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); + } + + boolean keyEquals() { + return ((inputKey().size()) == (CompiledMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledMapQueryContext.this.entryBytesAccess)), CompiledMapQueryContext.this.entryBytesAccessHandle, CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()))); + } + + public void closeMapQueryKeyEqualsDependants() { CompiledMapQueryContext.this.closeKeySearch(); } @@ -2829,7 +2971,7 @@ public class CompiledMapQueryContext= 0L ; ) { - CompiledMapQueryContext.this.initEntry(pos); + CompiledMapQueryContext.this.readExistingEntry(pos); if (!(keyEquals())) continue; @@ -2860,12 +3002,23 @@ public class CompiledMapQueryContext absentEntry, Data value) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.m().entryOperations.insert(absentEntry, value); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.m().entryOperations.remove(entry); + } + @Override public Data defaultValue(@NotNull MapAbsentEntry absentEntry) { @@ -2914,59 +3081,13 @@ public class CompiledMapQueryContext defaultValue() { + public Data wrapValueAsValue(V value) { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public MapEntry entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; - } - - @NotNull - @Override - public Data key() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryKey; - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.remove(entry); - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.innerReadLock; - } - - @Nullable - @Override - public MapAbsentEntry absentEntry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledMapQueryContext.this.absent(); + WrappedValueInstanceData wrapped = CompiledMapQueryContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; } @NotNull @@ -2983,13 +3104,44 @@ public class CompiledMapQueryContext wrapValueAsValue(V value) { + public Data queriedKey() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; + return inputKey(); + } + + @NotNull + @Override + public Data absentKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.inputKey(); + } + + @NotNull + @Override + public Data key() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryKey; + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.innerReadLock; + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @NotNull + @Override + public Data defaultValue() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); } @NotNull @@ -2999,8 +3151,8 @@ public class CompiledMapQueryContext absentEntry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? null : CompiledMapQueryContext.this.absent(); } - public void incrementSegmentEntriesIfNeeded() { - if ((CompiledMapQueryContext.this.searchState()) != (SearchState.PRESENT)) { - CompiledMapQueryContext.this.entries(((CompiledMapQueryContext.this.entries()) + 1L)); + @Override + public MapEntry entry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? this : null; + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeMapEntryStagesKeyEndDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); + } + + long countValueSizeOffset() { + return keyEnd(); + } + + public void closeMapEntryStagesCountValueSizeOffsetDependants() { + CompiledMapQueryContext.this.closeValueSizeOffset(); + } + + public long valueSizeOffset = -1; + + public boolean valueSizeOffsetInit() { + return (this.valueSizeOffset) >= 0; + } + + void initValueSizeOffset() { + valueSizeOffset = countValueSizeOffset(); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + CompiledMapQueryContext.this.closeValSize(); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); + valueSize = CompiledMapQueryContext.this.m().readValueSize(entryBytes); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + CompiledMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSize = oldValueSize; + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); + } + + public long valueOffset() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueSize; + } + + public void closeValSize() { + if (!(this.valSizeInit())) + return ; + + this.closeValSizeDependants(); + this.valueSize = -1; + } + + public void closeValSizeDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); + CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + public void writeValue(Data value) { + value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + private long _HashEntryStages_entryEnd() { + return keyEnd(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeMapEntryStagesEntryEndDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); + } + + long entrySize() { + return (entryEnd()) - (keySizeOffset()); + } + + public void closeMapEntryStagesEntrySizeDependants() { + CompiledMapQueryContext.this.closeTheEntrySizeInChunks(); + } + + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; + } + + void initTheEntrySizeInChunks() { + entrySizeInChunks = CompiledMapQueryContext.this.h().inChunks(entrySize()); + } + + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; + } + + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; + } + + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + return ; + + this.entrySizeInChunks = 0; + } + + public final void freeExtraAllocatedChunks() { + if (((!(CompiledMapQueryContext.this.m().constantlySizedEntry)) && (CompiledMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledMapQueryContext.this.allocatedChunks()))) { + CompiledMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); + } else { + initTheEntrySizeInChunks(CompiledMapQueryContext.this.allocatedChunks()); } } - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); + void putEntry(Data value) { + assert CompiledMapQueryContext.this.searchStateAbsent(); + long entrySize = CompiledMapQueryContext.this.entrySize(CompiledMapQueryContext.this.inputKey().size(), value.size()); + CompiledMapQueryContext.this.initEntryAndKey(entrySize); + CompiledMapQueryContext.this.initValue(value); + CompiledMapQueryContext.this.freeExtraAllocatedChunks(); + CompiledMapQueryContext.this.putNewVolatile(CompiledMapQueryContext.this.pos()); } - public void clearSegment() { - CompiledMapQueryContext.this.innerWriteLock.lock(); - CompiledMapQueryContext.this.clearHashLookup(); - freeList().clear(); - nextPosToSearchFrom(0L); - entries(0L); - } - - public void clear() { - clearSegment(); - } - - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - + public void writeValueAndPutPos(Data value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); } public void innerRemoveEntryExceptHashLookupUpdate() { @@ -3075,64 +3403,81 @@ public class CompiledMapQueryContext value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledMapQueryContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public long alloc(int chunks) { - VanillaChronicleHash h = CompiledMapQueryContext.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 void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); } public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); - CompiledMapQueryContext.this.initEntryCopying(CompiledMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); + CompiledMapQueryContext.this.copyExistingEntry(CompiledMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); incrementSegmentEntriesIfNeeded(); } + public void putValueDeletedEntry(Data newValue) { + assert CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = CompiledMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = CompiledMapQueryContext.this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (CompiledMapQueryContext.this.freeList().size())) && (CompiledMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + CompiledMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + CompiledMapQueryContext.this.innerWriteLock.lock(); + CompiledMapQueryContext.this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + CompiledMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + CompiledMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); + } + + @Override + public void doInsert(Data value) { + CompiledMapQueryContext.this.putPrefix(); + if (!(CompiledMapQueryContext.this.searchStatePresent())) { + if (CompiledMapQueryContext.this.searchStateDeleted()) { + CompiledMapQueryContext.this.putValueDeletedEntry(value); + } else { + putEntry(value); + } + CompiledMapQueryContext.this.incrementModCountGuarded(); + CompiledMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + } + } + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { CompiledMapQueryContext.this.free(pos(), entrySizeInChunks()); long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); @@ -3167,9 +3512,9 @@ public class CompiledMapQueryContext newValue) { - assert CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledMapQueryContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledMapQueryContext.this.freeList().size())) && (CompiledMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledMapQueryContext.this.innerWriteLock.lock(); - CompiledMapQueryContext.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) { - CompiledMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); - } - - public void initEntryAndKey(long entrySize) { - initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); - CompiledMapQueryContext.this.initEntry(CompiledMapQueryContext.this.alloc(allocatedChunks()), CompiledMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - - @NotNull - @Override - public Data absentKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.inputKey(); - } - - public Data queriedKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - void putEntry(Data value) { - assert CompiledMapQueryContext.this.searchStateAbsent(); - long entrySize = CompiledMapQueryContext.this.entrySize(CompiledMapQueryContext.this.inputKey().size(), value.size()); - CompiledMapQueryContext.this.initEntryAndKey(entrySize); - CompiledMapQueryContext.this.initValue(value); - CompiledMapQueryContext.this.freeExtraAllocatedChunks(); - CompiledMapQueryContext.this.putNewVolatile(CompiledMapQueryContext.this.pos()); - } - - @Override - public void doInsert(Data value) { - CompiledMapQueryContext.this.putPrefix(); - if (!(CompiledMapQueryContext.this.searchStatePresent())) { - if (CompiledMapQueryContext.this.searchStateDeleted()) { - CompiledMapQueryContext.this.putValueDeletedEntry(value); - } else { - putEntry(value); - } - CompiledMapQueryContext.this.incrementModCountGuarded(); - CompiledMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is present in the map when doInsert() is called"); - } - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; - } - - public Bytes inputBytes = null; - - public boolean inputBytesInit() { - return (this.inputBytes) != null; - } - - public void initInputBytes(Bytes inputBytes) { - this.inputBytes = inputBytes; - this.closeInputBytesDependants(); - } - - public Bytes inputBytes() { - assert this.inputBytesInit() : "InputBytes should be init"; - return this.inputBytes; - } - - public void closeInputBytes() { - if (!(this.inputBytesInit())) - return ; - - this.closeInputBytesDependants(); - this.inputBytes = null; - } - - public void closeInputBytesDependants() { - CompiledMapQueryContext.this.closeInputKeyOffsets(); - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.closeFirstInputValueOffsets(); - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.closeSecondInputValueOffsets(); - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); - } - - public long inputKeySize = -1; - - public long inputKeyOffset; - - public boolean inputKeyOffsetsInit() { - return (this.inputKeySize) >= 0; - } - - private void initInputKeyOffsets() { - inputKeySize = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(inputBytes()); - inputKeyOffset = inputBytes().position(); - this.closeInputKeyOffsetsDependants(); - } - - public long inputKeyOffset() { - if (!(this.inputKeyOffsetsInit())) - this.initInputKeyOffsets(); - - return this.inputKeyOffset; - } - - public long inputKeySize() { - if (!(this.inputKeyOffsetsInit())) - this.initInputKeyOffsets(); - - return this.inputKeySize; - } - - public void closeInputKeyOffsets() { - if (!(this.inputKeyOffsetsInit())) - return ; - - this.closeInputKeyOffsetsDependants(); - this.inputKeySize = -1; - } - - public void closeInputKeyOffsetsDependants() { - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.closeFirstInputValueOffsets(); - } - - public long firstInputValueSize = -1; - - public long firstInputValueOffset; - - public boolean firstInputValueOffsetsInit() { - return (this.firstInputValueSize) >= 0; - } - - private void initFirstInputValueOffsets() { - CompiledMapQueryContext.this.inputBytes().position(((CompiledMapQueryContext.this.inputKeyOffset()) + (CompiledMapQueryContext.this.inputKeySize()))); - firstInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); - firstInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); - this.closeFirstInputValueOffsetsDependants(); - } - - public long firstInputValueOffset() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueOffset; - } - - public long firstInputValueSize() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueSize; - } - - public void closeFirstInputValueOffsets() { - if (!(this.firstInputValueOffsetsInit())) - return ; - - this.closeFirstInputValueOffsetsDependants(); - this.firstInputValueSize = -1; - } - - public void closeFirstInputValueOffsetsDependants() { - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.closeSecondInputValueOffsets(); - } - - public long secondInputValueSize = -1; - - public long secondInputValueOffset; - - public boolean secondInputValueOffsetsInit() { - return (this.secondInputValueSize) >= 0; - } - - private void initSecondInputValueOffsets() { - CompiledMapQueryContext.this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); - secondInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); - secondInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); - this.closeSecondInputValueOffsetsDependants(); - } - - public long secondInputValueOffset() { - if (!(this.secondInputValueOffsetsInit())) - this.initSecondInputValueOffsets(); - - return this.secondInputValueOffset; - } - - public long secondInputValueSize() { - if (!(this.secondInputValueOffsetsInit())) - this.initSecondInputValueOffsets(); - - return this.secondInputValueSize; - } - - public void closeSecondInputValueOffsets() { - if (!(this.secondInputValueOffsetsInit())) - return ; - - this.closeSecondInputValueOffsetsDependants(); - this.secondInputValueSize = -1; - } - - public void closeSecondInputValueOffsetsDependants() { - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); - } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java index 13b8079db..5563c4ca3 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java @@ -49,22 +49,22 @@ import java.util.function.Predicate; public class CompiledReplicatedMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ReplicableEntry , MapContext , MapEntry , IterationContextInterface , ReplicatedChronicleMapHolder , ReplicatedIterationContextInterface , MapReplicableEntry { public void close() { - CompiledReplicatedMapIterationContext.this.closeReplicationUpdate(); - CompiledReplicatedMapIterationContext.this.closeTheSegmentIndex(); - CompiledReplicatedMapIterationContext.this.closeUsed(); - CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); - CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); - CompiledReplicatedMapIterationContext.this.closeKeyOffset(); - CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeValue(); - CompiledReplicatedMapIterationContext.this.closeKeySize(); + CompiledReplicatedMapIterationContext.this.closeReplicationUpdate(); + CompiledReplicatedMapIterationContext.this.closeUsed(); CompiledReplicatedMapIterationContext.this.closePos(); + CompiledReplicatedMapIterationContext.this.closeKeyOffset(); + CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeNext(); + CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); + CompiledReplicatedMapIterationContext.this.closeTheSegmentIndex(); + CompiledReplicatedMapIterationContext.this.closeKeySize(); + CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); CompiledReplicatedMapIterationContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockForbiddenUpgradeDependants(); CompiledReplicatedMapIterationContext.this.closeReplicatedMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); CompiledReplicatedMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockForbiddenUpgradeDependants(); } public void incrementModCountGuarded() { @@ -91,23 +91,23 @@ public class CompiledReplicatedMapIterationContext)(entryBytesAccessor.access(entryBytes))); - this.dummyValue = new DummyValueZeroData(); - this.innerUpdateLock = new UpdateLock(); - this.entryKey = new EntryKeyBytesData(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.innerReadLock = new ReadLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapIterationContext.this.m().valueInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapIterationContext.this.m().valueReaderProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapIterationContext.this.h().keyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapIterationContext.this.h().keyReaderProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalKeyReader); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.innerWriteLock = new WriteLock(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); - this.innerReadLock = new ReadLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.entryKey = new EntryKeyBytesData(); + this.innerWriteLock = new WriteLock(); + this.dummyValue = new DummyValueZeroData(); this.entryValue = new EntryValueBytesData(); } @@ -116,50 +116,37 @@ public class CompiledReplicatedMapIterationContext)(c.m)); - this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.dummyValue = new DummyValueZeroData(); - this.innerUpdateLock = new UpdateLock(); - this.entryKey = new EntryKeyBytesData(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.innerReadLock = new ReadLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapIterationContext.this.m().valueInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapIterationContext.this.m().valueReaderProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapIterationContext.this.h().keyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapIterationContext.this.h().keyReaderProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalKeyReader); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.innerWriteLock = new WriteLock(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); - this.innerReadLock = new ReadLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.entryKey = new EntryKeyBytesData(); + this.innerWriteLock = new WriteLock(); + this.dummyValue = new DummyValueZeroData(); this.entryValue = new EntryValueBytesData(); } public class DeprecatedMapKeyContextOnIteration implements MapKeyContext { @Override - public boolean put(V newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.replaceValue(CompiledReplicatedMapIterationContext.this, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(newValue)); - return true; + public void close() { + throw new UnsupportedOperationException("close() is not supported during iteration"); } + @NotNull @Override - public V getUsing(V usingValue) { + public K key() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.value().getUsing(usingValue); - } - - @Override - public V get() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.value().get(); - } - - @Override - public boolean valueEqualTo(V value) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return Data.bytesEquivalent(CompiledReplicatedMapIterationContext.this.entryValue, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(value)); + return CompiledReplicatedMapIterationContext.this.key().get(); } @NotNull @@ -170,9 +157,9 @@ public class CompiledReplicatedMapIterationContext { - @Override - public ReadAccess access() { - return ReadAccess.zeros(); - } - - @Override - public V get() { - throw new UnsupportedOperationException(); - } - @Override public long size() { return CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.minEncodableSize(); } @Override - public V getUsing(V usingInstance) { - throw new UnsupportedOperationException(); + public long offset() { + return 0; } @Override @@ -269,24 +259,34 @@ public class CompiledReplicatedMapIterationContext access() { + return ReadAccess.zeros(); + } + + @Override + public V get() { + throw new UnsupportedOperationException(); } } public class EntryKeyBytesData extends AbstractData { - @Override - public ReadAccess access() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccess; - } - @Override public T handle() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; } + @Override + public ReadAccess access() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytesAccess; + } + @Override public long size() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); @@ -365,6 +365,12 @@ public class CompiledReplicatedMapIterationContext context() { - return CompiledReplicatedMapIterationContext.this; - } - public MVI valueMetaInterop(V value) { return CompiledReplicatedMapIterationContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalMetaValueInterop, valueInterop, value); } @@ -1124,16 +1122,6 @@ public class CompiledReplicatedMapIterationContext absentEntry, Data value) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); - } - @NotNull @Override - public Data key() { + public InterProcessLock writeLock() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryKey; + return CompiledReplicatedMapIterationContext.this.innerWriteLock; } @Override @@ -1195,27 +1176,6 @@ public class CompiledReplicatedMapIterationContext value() { @@ -1230,11 +1190,39 @@ public class CompiledReplicatedMapIterationContext key() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryKey; } - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); + @NotNull + @Override + public InterProcessLock updateLock() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.innerUpdateLock; + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.innerReadLock; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + } + + public long entryBytesAccessOffset(long offset) { + return entryBytesAccessor.offset(entryBytes, offset); + } + + public void incrementSegmentEntriesIfNeeded() { } @Override @@ -1255,10 +1243,6 @@ public class CompiledReplicatedMapIterationContext= 0; + @NotNull + @Override + public MapContext context() { + return CompiledReplicatedMapIterationContext.this; } - public void initPos(long pos) { - this.pos = pos; - this.closePosDependants(); + public long hashLookupPos = -1; + + public boolean hashLookupPosInit() { + return (this.hashLookupPos) >= 0; } - public long pos() { - assert this.posInit() : "Pos should be init"; - return this.pos; + public void initHashLookupPos(long hashLookupPos) { + this.hashLookupPos = hashLookupPos; } - public void closePos() { - if (!(this.posInit())) + public long hashLookupPos() { + assert this.hashLookupPosInit() : "HashLookupPos should be init"; + return this.hashLookupPos; + } + + public void closeHashLookupPos() { + if (!(this.hashLookupPosInit())) return ; - this.closePosDependants(); - this.pos = -1; - } - - public void closePosDependants() { - CompiledReplicatedMapIterationContext.this.closeEntryOffset(); + this.hashLookupPos = -1; } public long keySize = -1; @@ -1350,6 +1344,504 @@ public class CompiledReplicatedMapIterationContext= 0; + } + + public void initTheSegmentIndex(int segmentIndex) { + this.segmentIndex = segmentIndex; + this.closeTheSegmentIndexDependants(); + } + + public int segmentIndex() { + assert this.theSegmentIndexInit() : "TheSegmentIndex should be init"; + return this.segmentIndex; + } + + public void closeTheSegmentIndex() { + if (!(this.theSegmentIndexInit())) + return ; + + this.closeTheSegmentIndexDependants(); + this.segmentIndex = -1; + } + + public void closeTheSegmentIndexDependants() { + CompiledReplicatedMapIterationContext.this.closeSegHeader(); + CompiledReplicatedMapIterationContext.this.closeSegmentHashLookup(); + CompiledReplicatedMapIterationContext.this.closeSegment(); + } + + long segmentHeaderAddress; + + SegmentHeader segmentHeader = null; + + public boolean segHeaderInit() { + return (this.segmentHeader) != null; + } + + private void initSegHeader() { + segmentHeaderAddress = (CompiledReplicatedMapIterationContext.this.h().ms.address()) + (CompiledReplicatedMapIterationContext.this.h().segmentHeaderOffset(segmentIndex())); + segmentHeader = BigSegmentHeader.INSTANCE; + this.closeSegHeaderDependants(); + } + + public long segmentHeaderAddress() { + if (!(this.segHeaderInit())) + this.initSegHeader(); + + return this.segmentHeaderAddress; + } + + public SegmentHeader segmentHeader() { + if (!(this.segHeaderInit())) + this.initSegHeader(); + + return this.segmentHeader; + } + + public void closeSegHeader() { + if (!(this.segHeaderInit())) + return ; + + this.closeSegHeaderDependants(); + this.segmentHeader = null; + } + + public void closeSegHeaderDependants() { + CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + CompiledReplicatedMapIterationContext.this.closeLocks(); + CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockLockDependants(); + } + + public void deleted(long deleted) { + segmentHeader().deleted(segmentHeaderAddress(), deleted); + } + + public long deleted() { + return segmentHeader().deleted(segmentHeaderAddress()); + } + + public long entries() { + return segmentHeader().size(segmentHeaderAddress()); + } + + public long size() { + return (entries()) - (deleted()); + } + + boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { + CompiledReplicatedMapIterationContext c = CompiledReplicatedMapIterationContext.this.contextAtIndexInChain(index); + if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { + throw new IllegalStateException("Nested context not implemented yet"); + } else { + return false; + } + } + + public void closeSegmentStagesTryFindInitLocksOfThisSegmentDependants() { + CompiledReplicatedMapIterationContext.this.closeLocks(); + } + + int totalReadLockCount; + + int totalUpdateLockCount; + + int totalWriteLockCount; + + public int latestSameThreadSegmentModCount; + + public int contextModCount; + + CompiledReplicatedMapIterationContext nextNode; + + public boolean concurrentSameThreadContexts; + + LocalLockState localLockState; + + public CompiledReplicatedMapIterationContext rootContextOnThisSegment = null; + + public boolean locksInit() { + return (this.rootContextOnThisSegment) != null; + } + + void initLocks() { + localLockState = LocalLockState.UNLOCKED; + int indexOfThisContext = CompiledReplicatedMapIterationContext.this.indexInContextChain; + for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + for (int i = indexOfThisContext + 1, size = CompiledReplicatedMapIterationContext.this.contextChain.size() ; i < size ; i++) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + rootContextOnThisSegment = this; + concurrentSameThreadContexts = false; + latestSameThreadSegmentModCount = 0; + contextModCount = 0; + nextNode = null; + totalReadLockCount = 0; + totalUpdateLockCount = 0; + totalWriteLockCount = 0; + this.closeLocksDependants(); + } + + public LocalLockState localLockState() { + if (!(this.locksInit())) + this.initLocks(); + + return this.localLockState; + } + + public CompiledReplicatedMapIterationContext rootContextOnThisSegment() { + if (!(this.locksInit())) + this.initLocks(); + + return this.rootContextOnThisSegment; + } + + void closeLocks() { + if (!(this.locksInit())) + return ; + + this.closeLocksDependants(); + if ((rootContextOnThisSegment) == this) { + closeRootLocks(); + } else { + closeNestedLocks(); + } + localLockState = null; + rootContextOnThisSegment = null; + } + + public void closeLocksDependants() { + CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockLockDependants(); + } + + public void entries(long size) { + segmentHeader().size(segmentHeaderAddress(), size); + } + + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); + } + + public void nextPosToSearchFrom(long nextPosToSearchFrom) { + segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); + } + + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (CompiledReplicatedMapIterationContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + 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 = CompiledReplicatedMapIterationContext.this.h().segmentOffset(CompiledReplicatedMapIterationContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledReplicatedMapIterationContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapIterationContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapIterationContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapIterationContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapIterationContext.this.h().segmentHashLookupValueBits); + } + + public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { + innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); + } + + 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.address = -1; + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public long value(long entry) { + return (entry >>> (keyBits())) & (valueMask()); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + 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 void writeEntryVolatile(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + } + + 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 long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_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; + } + + 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(); + } + + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledReplicatedMapIterationContext.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() { + CompiledReplicatedMapIterationContext.this.closeEntryOffset(); + } + + public void clearSegment() { + CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + CompiledReplicatedMapIterationContext.this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); + } + + public void clear() { + clearSegment(); + } + + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledReplicatedMapIterationContext.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 boolean entryRemovedOnThisIteration = false; boolean entryRemovedOnThisIterationInit() { @@ -1367,6 +1859,28 @@ public class CompiledReplicatedMapIterationContext= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - this.closeReplicationStateDependants(); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.closeReplicationStateDependants(); - this.replicationBytesOffset = -1; - } - - public void closeReplicationStateDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesIdentifierOffsetDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesUpdateReplicationStateDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesTimestampOffsetDependants(); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - private boolean _MapSegmentIteration_entryIsPresent() { - return true; - } - - public boolean entryIsPresent() { - return !(CompiledReplicatedMapIterationContext.this.entryDeleted()); - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - public void closeReplicatedMapEntryStagesIdentifierOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesIdentifierDependants(); - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - public void closeReplicatedMapEntryStagesIdentifierDependants() { - CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - void updateReplicationState(long timestamp, byte identifier) { - entryBytes.position(replicationBytesOffset()); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public void closeReplicatedMapEntryStagesUpdateReplicationStateDependants() { - CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - public void closeReplicatedMapEntryStagesTimestampOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesTimestampDependants(); - } - - public long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - public void closeReplicatedMapEntryStagesTimestampDependants() { - CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); - } - - @Override - public long originTimestamp() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return timestamp(); + CompiledReplicatedMapIterationContext.this.closeReplicationState(); } private long _MapEntryStages_countValueSizeOffset() { @@ -1610,15 +2014,21 @@ public class CompiledReplicatedMapIterationContext value) { value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); } + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { assert oldValueSize == (value.size()); initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); @@ -1637,101 +2047,142 @@ public class CompiledReplicatedMapIterationContext value) { - entryBytes.position(valueSizeOffset()); - initValSize(value.size()); - writeValue(value); + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; } - public int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; + void initReplicationState() { + replicationBytesOffset = keyEnd(); + this.closeReplicationStateDependants(); } - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; } - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) + public void closeReplicationState() { + if (!(this.replicationStateInit())) return ; - this.allocatedChunks = 0; + this.closeReplicationStateDependants(); + this.replicationBytesOffset = -1; } - public long hashLookupPos = -1; - - public boolean hashLookupPosInit() { - return (this.hashLookupPos) >= 0; + public void closeReplicationStateDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesTimestampOffsetDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesUpdateReplicationStateDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesIdentifierOffsetDependants(); } - public void initHashLookupPos(long hashLookupPos) { - this.hashLookupPos = hashLookupPos; + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; } - public long hashLookupPos() { - assert this.hashLookupPosInit() : "HashLookupPos should be init"; - return this.hashLookupPos; + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); } - public void closeHashLookupPos() { - if (!(this.hashLookupPosInit())) + private boolean _MapSegmentIteration_entryIsPresent() { + return true; + } + + public boolean entryIsPresent() { + return !(CompiledReplicatedMapIterationContext.this.entryDeleted()); + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + public void closeReplicatedMapEntryStagesTimestampOffsetDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesTimestampDependants(); + } + + public long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + public void closeReplicatedMapEntryStagesTimestampDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + void updateReplicationState(long timestamp, byte identifier) { + entryBytes.position(replicationBytesOffset()); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public void closeReplicatedMapEntryStagesUpdateReplicationStateDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + public void closeReplicatedMapEntryStagesIdentifierOffsetDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesIdentifierDependants(); + } + + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); + } + + public void closeReplicatedMapEntryStagesIdentifierDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); + } + + @Override + public byte originIdentifier() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return identifier(); + } + + public long pos = -1; + + public boolean posInit() { + return (this.pos) >= 0; + } + + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); + } + + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) return ; - this.hashLookupPos = -1; + this.closePosDependants(); + this.pos = -1; } - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; - } - - public int segmentIndex = -1; - - public boolean theSegmentIndexInit() { - return (this.segmentIndex) >= 0; - } - - public void initTheSegmentIndex(int segmentIndex) { - this.segmentIndex = segmentIndex; - this.closeTheSegmentIndexDependants(); - } - - public int segmentIndex() { - assert this.theSegmentIndexInit() : "TheSegmentIndex should be init"; - return this.segmentIndex; - } - - public void closeTheSegmentIndex() { - if (!(this.theSegmentIndexInit())) - return ; - - this.closeTheSegmentIndexDependants(); - this.segmentIndex = -1; - } - - public void closeTheSegmentIndexDependants() { - CompiledReplicatedMapIterationContext.this.closeSegment(); - CompiledReplicatedMapIterationContext.this.closeSegmentHashLookup(); - CompiledReplicatedMapIterationContext.this.closeSegHeader(); + public void closePosDependants() { + CompiledReplicatedMapIterationContext.this.closeEntryOffset(); } public void dropChange() { @@ -1750,52 +2201,6 @@ public class CompiledReplicatedMapIterationContext 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledReplicatedMapIterationContext.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() { - CompiledReplicatedMapIterationContext.this.closeEntryOffset(); - } - public long keySizeOffset = -1; public boolean entryOffsetInit() { @@ -1827,6 +2232,24 @@ public class CompiledReplicatedMapIterationContext newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); + } + + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { + initAllocatedChunks(CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize)); + CompiledReplicatedMapIterationContext.this.copyExistingEntry(CompiledReplicatedMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); + } + long entrySize() { return (entryEnd()) - (keySizeOffset()); } @@ -1863,414 +2286,6 @@ public class CompiledReplicatedMapIterationContext newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - public void readExistingEntry(long pos) { - initPos(pos); - entryBytes.position(keySizeOffset()); - initKeySize(CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes)); - initKeyOffset(entryBytes.position()); - } - - public void writeNewEntry(long pos, Data key) { - initPos(pos); - initKeySize(key.size()); - entryBytes.position(keySizeOffset()); - CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); - initKeyOffset(entryBytes.position()); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); - } - - 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 = CompiledReplicatedMapIterationContext.this.h().segmentOffset(CompiledReplicatedMapIterationContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledReplicatedMapIterationContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapIterationContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapIterationContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapIterationContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapIterationContext.this.h().segmentHashLookupValueBits); - } - - public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { - innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); - } - - 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.address = -1; - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - long entry(long key, long value) { - return key | (value << (keyBits())); - } - - 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 step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - 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 checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - 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 void writeEntryVolatile(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); - } - - public void putValueVolatile(long pos, long value) { - checkValueForPut(value); - long currentEntry = readEntry(pos); - writeEntryVolatile(pos, currentEntry, key(currentEntry), value); - } - - long segmentHeaderAddress; - - SegmentHeader segmentHeader = null; - - public boolean segHeaderInit() { - return (this.segmentHeader) != null; - } - - private void initSegHeader() { - segmentHeaderAddress = (CompiledReplicatedMapIterationContext.this.h().ms.address()) + (CompiledReplicatedMapIterationContext.this.h().segmentHeaderOffset(segmentIndex())); - segmentHeader = BigSegmentHeader.INSTANCE; - this.closeSegHeaderDependants(); - } - - public long segmentHeaderAddress() { - if (!(this.segHeaderInit())) - this.initSegHeader(); - - return this.segmentHeaderAddress; - } - - public SegmentHeader segmentHeader() { - if (!(this.segHeaderInit())) - this.initSegHeader(); - - return this.segmentHeader; - } - - public void closeSegHeader() { - if (!(this.segHeaderInit())) - return ; - - this.closeSegHeaderDependants(); - this.segmentHeader = null; - } - - public void closeSegHeaderDependants() { - CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - CompiledReplicatedMapIterationContext.this.closeLocks(); - CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockLockDependants(); - } - - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { - CompiledReplicatedMapIterationContext c = CompiledReplicatedMapIterationContext.this.contextAtIndexInChain(index); - if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { - throw new IllegalStateException("Nested context not implemented yet"); - } else { - return false; - } - } - - public void closeSegmentStagesTryFindInitLocksOfThisSegmentDependants() { - CompiledReplicatedMapIterationContext.this.closeLocks(); - } - - int totalReadLockCount; - - int totalUpdateLockCount; - - int totalWriteLockCount; - - public int latestSameThreadSegmentModCount; - - public int contextModCount; - - CompiledReplicatedMapIterationContext nextNode; - - public boolean concurrentSameThreadContexts; - - LocalLockState localLockState; - - public CompiledReplicatedMapIterationContext rootContextOnThisSegment = null; - - public boolean locksInit() { - return (this.rootContextOnThisSegment) != null; - } - - void initLocks() { - localLockState = LocalLockState.UNLOCKED; - int indexOfThisContext = CompiledReplicatedMapIterationContext.this.indexInContextChain; - for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - for (int i = indexOfThisContext + 1, size = CompiledReplicatedMapIterationContext.this.contextChain.size() ; i < size ; i++) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - rootContextOnThisSegment = this; - concurrentSameThreadContexts = false; - latestSameThreadSegmentModCount = 0; - contextModCount = 0; - nextNode = null; - totalReadLockCount = 0; - totalUpdateLockCount = 0; - totalWriteLockCount = 0; - this.closeLocksDependants(); - } - - public LocalLockState localLockState() { - if (!(this.locksInit())) - this.initLocks(); - - return this.localLockState; - } - - public CompiledReplicatedMapIterationContext rootContextOnThisSegment() { - if (!(this.locksInit())) - this.initLocks(); - - return this.rootContextOnThisSegment; - } - - void closeLocks() { - if (!(this.locksInit())) - return ; - - this.closeLocksDependants(); - if ((rootContextOnThisSegment) == this) { - closeRootLocks(); - } else { - closeNestedLocks(); - } - localLockState = null; - rootContextOnThisSegment = null; - } - - public void closeLocksDependants() { - CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockLockDependants(); - } - - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledReplicatedMapIterationContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - - public void clearSegment() { - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - CompiledReplicatedMapIterationContext.this.clearHashLookup(); - freeList().clear(); - nextPosToSearchFrom(0L); - entries(0L); - } - - public void clear() { - clearSegment(); - } - - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } - - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - - } - public final void freeExtraAllocatedChunks() { if (((!(CompiledReplicatedMapIterationContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapIterationContext.this.allocatedChunks()))) { CompiledReplicatedMapIterationContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapIterationContext.this.allocatedChunks()) - (entrySizeInChunks()))); @@ -2285,168 +2300,26 @@ public class CompiledReplicatedMapIterationContext h = CompiledReplicatedMapIterationContext.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 void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapIterationContext.this.copyExistingEntry(CompiledReplicatedMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); - } - - private void _MapEntryStages_relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + public void innerRemoveEntryExceptHashLookupUpdate() { CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); - writeValueAndPutPos(newValue); + CompiledReplicatedMapIterationContext.this.entries(((CompiledReplicatedMapIterationContext.this.entries()) - 1L)); + CompiledReplicatedMapIterationContext.this.incrementModCountGuarded(); } - protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - CompiledReplicatedMapIterationContext.this.dropChange(); - _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); } - public void innerDefaultReplaceValue(Data newValue) { - assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); - boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); - if (newValueSizeIsDifferent) { - long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long entryStartOffset = keySizeOffset(); - VanillaChronicleMap m = CompiledReplicatedMapIterationContext.this.m(); - long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - int newSizeInChunks = m.inChunks(newEntrySize); - newValueDoesNotFit : if (newSizeInChunks > (entrySizeInChunks())) { - if (newSizeInChunks > (m.maxChunksPerEntry)) { - throw new IllegalArgumentException(((((("Value too large: " + "entry takes ") + newSizeInChunks) + " chunks, ") + (m.maxChunksPerEntry)) + " is maximum.")); - } - if (CompiledReplicatedMapIterationContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { - CompiledReplicatedMapIterationContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); - break newValueDoesNotFit; - } - relocation(newValue, newSizeOfEverythingBeforeValue); - return ; - } else if (newSizeInChunks < (entrySizeInChunks())) { - CompiledReplicatedMapIterationContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); - } - } else { - } - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - if (newValueSizeIsDifferent) { - initValue(newValue); - } else { - writeValue(newValue); - } - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); - } - - private void _MapSegmentIteration_doReplaceValue(Data newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - try { - CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); - } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); - } - } - - @Override - public void doReplaceValue(Data newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - try { - CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); - CompiledReplicatedMapIterationContext.this.updateChange(); - CompiledReplicatedMapIterationContext.this.initUpdatedReplicationStateOnPresentEntry(); - } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); - } - } - - private void _MapEntryStages_putValueDeletedEntry(Data newValue) { - assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledReplicatedMapIterationContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapIterationContext.this.freeList().size())) && (CompiledReplicatedMapIterationContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledReplicatedMapIterationContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - CompiledReplicatedMapIterationContext.this.incrementSegmentEntriesIfNeeded(); - if (newValueSizeIsDifferent) { - initValue(newValue); - } else { - writeValue(newValue); - } - } else { - if (newValueSizeIsDifferent) { - assert newSizeOfEverythingBeforeValue >= 0; - } else { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - } - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - if (newValueSizeIsDifferent) { - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); - } - - public void putValueDeletedEntry(Data newValue) { - throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); - } - - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); - } - - public long entries() { - return segmentHeader().size(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); } public boolean forEachRemoving(Predicate> action) { @@ -2516,10 +2389,71 @@ public class CompiledReplicatedMapIterationContext newValue, long newSizeOfEverythingBeforeValue) { CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); - CompiledReplicatedMapIterationContext.this.entries(((CompiledReplicatedMapIterationContext.this.entries()) - 1L)); - CompiledReplicatedMapIterationContext.this.incrementModCountGuarded(); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); + } + + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + CompiledReplicatedMapIterationContext.this.dropChange(); + _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); + } + + public void innerDefaultReplaceValue(Data newValue) { + assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); + if (newValueSizeIsDifferent) { + long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long entryStartOffset = keySizeOffset(); + VanillaChronicleMap m = CompiledReplicatedMapIterationContext.this.m(); + long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + int newSizeInChunks = m.inChunks(newEntrySize); + newValueDoesNotFit : if (newSizeInChunks > (entrySizeInChunks())) { + if (newSizeInChunks > (m.maxChunksPerEntry)) { + throw new IllegalArgumentException(((((("Value too large: " + "entry takes ") + newSizeInChunks) + " chunks, ") + (m.maxChunksPerEntry)) + " is maximum.")); + } + if (CompiledReplicatedMapIterationContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { + CompiledReplicatedMapIterationContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); + break newValueDoesNotFit; + } + relocation(newValue, newSizeOfEverythingBeforeValue); + return ; + } else if (newSizeInChunks < (entrySizeInChunks())) { + CompiledReplicatedMapIterationContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); + } + } else { + } + CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); + } + + private void _MapSegmentIteration_doReplaceValue(Data newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + try { + CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); + } finally { + CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); + } + } + + @Override + public void doReplaceValue(Data newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + try { + CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); + CompiledReplicatedMapIterationContext.this.updateChange(); + CompiledReplicatedMapIterationContext.this.initUpdatedReplicationStateOnPresentEntry(); + } finally { + CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); + } } private void _MapSegmentIteration_doRemove() { @@ -2553,6 +2487,72 @@ public class CompiledReplicatedMapIterationContext newValue) { + assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = CompiledReplicatedMapIterationContext.this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapIterationContext.this.freeList().size())) && (CompiledReplicatedMapIterationContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + CompiledReplicatedMapIterationContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + CompiledReplicatedMapIterationContext.this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); + } + + public void putValueDeletedEntry(Data newValue) { + throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); + } + + boolean used; + + public boolean usedInit() { + return used; + } + + public void initUsed(boolean used) { + this.used = used; + } + + void closeUsed() { + if (!(this.usedInit())) + return ; + + used = false; + } + public long innerRemoteTimestamp; public byte innerRemoteIdentifier = ((byte)(0)); @@ -2592,18 +2592,6 @@ public class CompiledReplicatedMapIterationContext, 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 , MapAbsentEntryHolder , QueryContextInterface , ReplicatedChronicleMapHolder , MapRemoteQueryContext , MapReplicableEntry { public void close() { - CompiledReplicatedMapQueryContext.this.closeInputKey(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); - CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); - CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); - CompiledReplicatedMapQueryContext.this.closeKeyOffset(); + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); + CompiledReplicatedMapQueryContext.this.closeReplicationInput(); CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); CompiledReplicatedMapQueryContext.this.closePos(); - CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); - CompiledReplicatedMapQueryContext.this.closeKeySize(); - CompiledReplicatedMapQueryContext.this.closeReplicationInput(); CompiledReplicatedMapQueryContext.this.bytesReturnValue.closeOutput(); - CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); - CompiledReplicatedMapQueryContext.this.closeUsed(); + CompiledReplicatedMapQueryContext.this.closeKeySize(); + CompiledReplicatedMapQueryContext.this.closeInputKey(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); CompiledReplicatedMapQueryContext.this.closeInputBytes(); - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeKeyOffset(); + CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); + CompiledReplicatedMapQueryContext.this.closeUsed(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); CompiledReplicatedMapQueryContext.this.innerWriteLock.closeWriteLockForbiddenUpgradeDependants(); CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); - CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); } public void incrementModCountGuarded() { @@ -106,36 +107,36 @@ public class CompiledReplicatedMapQueryContext)(entryBytesAccessor.access(entryBytes))); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.inputKeyBytesValue = new InputKeyBytesData(); + this.entryKey = new EntryKeyBytesData(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + 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.dummyValue = new DummyValueZeroData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.entryValue = new EntryValueBytesData(); + this.innerReadLock = new ReadLock(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); } public CompiledReplicatedMapQueryContext(CompiledReplicatedMapQueryContext c) { @@ -143,39 +144,45 @@ public class CompiledReplicatedMapQueryContext)(c.m)); - this.entryKey = new EntryKeyBytesData(); - this.entryValue = new EntryValueBytesData(); - this.defaultReturnValue = new DefaultReturnValue(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.inputKeyInstanceValue = new InputKeyInstanceData(); - this.inputValueInstanceValue = new InputValueInstanceData(); - this.innerReadLock = new ReadLock(); - this.innerUpdateLock = new UpdateLock(); - 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.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); - this.inputFirstValueBytesValue = new InputFirstValueBytesData(); this.usingReturnValue = new UsingReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesData(); - this.dummyValue = new DummyValueZeroData(); + this.inputValueInstanceValue = new InputValueInstanceData(); + this.defaultReturnValue = new DefaultReturnValue(); this.innerWriteLock = new WriteLock(); - this.inputSecondValueBytesValue = new InputSecondValueBytesData(); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); this.bytesReturnValue = new BytesReturnValue(); 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.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.inputKeyBytesValue = new InputKeyBytesData(); + this.entryKey = new EntryKeyBytesData(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + 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.dummyValue = new DummyValueZeroData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.entryValue = new EntryValueBytesData(); + this.innerReadLock = new ReadLock(); + this.innerUpdateLock = new UpdateLock(); this.owner = Thread.currentThread(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); } public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { + @NotNull + @Override + public InterProcessLock updateLock() { + return CompiledReplicatedMapQueryContext.this.updateLock(); + } + @NotNull @Override public InterProcessLock writeLock() { @@ -188,16 +195,10 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } - } - - @Override - public boolean containsKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return (CompiledReplicatedMapQueryContext.this.entry()) != null; - } - - @Override - public V getUsing(V usingValue) { - return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; - } - - @Override - public V get() { - assert containsKey(); - return CompiledReplicatedMapQueryContext.this.usingReturnValue.returnValue(); + return CompiledReplicatedMapQueryContext.this.queriedKey().get(); } @Override @@ -281,21 +253,44 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } + } + + @Override + public long valueOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueOffset(); + } + + @Override + public boolean containsKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return (CompiledReplicatedMapQueryContext.this.entry()) != null; + } + + @Override + public V getUsing(V usingValue) { + return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; + } + + @Override + public V get() { + assert containsKey(); + return CompiledReplicatedMapQueryContext.this.usingReturnValue.returnValue(); } } public class DeprecatedMapKeyContextOnQuery implements MapKeyContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledReplicatedMapQueryContext.this.writeLock(); - } - @NotNull @Override public InterProcessLock updateLock() { @@ -308,34 +303,10 @@ public class CompiledReplicatedMapQueryContext { + @Override + public long size() { + return CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.minEncodableSize(); + } + @Override public long offset() { return 0; @@ -412,19 +418,14 @@ public class CompiledReplicatedMapQueryContext { - @Override - public T handle() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; - } - @Override public long offset() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()); } + @Override + public T handle() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; + } + @Override public ReadAccess access() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -531,12 +532,6 @@ public class CompiledReplicatedMapQueryContext access() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); return CompiledReplicatedMapQueryContext.this.entryBytesAccess; } + @Override + public V getUsing(V usingValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return innerGetUsing(usingValue); + } + + @Override + public V get() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return cachedEntryValue(); + } + @Override public long offset() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -595,16 +596,6 @@ public class CompiledReplicatedMapQueryContext)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); } - @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); - } - - @Override - public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.firstInputValueOffset()); - } - @Override public long size() { return CompiledReplicatedMapQueryContext.this.firstInputValueSize(); @@ -655,16 +646,22 @@ public class CompiledReplicatedMapQueryContext { @Override - public long size() { - return CompiledReplicatedMapQueryContext.this.inputKeySize(); - } - - public void closeInputKeyBytesDataSizeDependants() { - InputKeyBytesData.this.closeInputKeyBytesDataGetUsingDependants(); + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); } @Override @@ -673,8 +670,12 @@ 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 long size() { return CompiledReplicatedMapQueryContext.this.riKeySize(); @@ -879,16 +890,6 @@ public class CompiledReplicatedMapQueryContext 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.riKeyOffset()); } } public class ReplicatedInputValueBytesData extends AbstractData { @Override - public long size() { - return CompiledReplicatedMapQueryContext.this.riValueSize(); - } - - public void closeReplicatedInputValueBytesDataSizeDependants() { - ReplicatedInputValueBytesData.this.closeReplicatedInputValueBytesDataGetUsingDependants(); + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } @Override @@ -958,6 +955,15 @@ public class CompiledReplicatedMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); - } } public class ReplicatedMapAbsentDelegating implements MapAbsentEntry { @NotNull @Override - public MapContext context() { - return CompiledReplicatedMapQueryContext.this.context(); + public Data absentKey() { + return CompiledReplicatedMapQueryContext.this.absentKey(); } @NotNull @@ -1022,8 +1023,8 @@ public class CompiledReplicatedMapQueryContext absentKey() { - return CompiledReplicatedMapQueryContext.this.absentKey(); + public MapContext context() { + return CompiledReplicatedMapQueryContext.this.context(); } @Override @@ -1038,11 +1039,6 @@ public class CompiledReplicatedMapQueryContext { @@ -1142,18 +1143,6 @@ public class CompiledReplicatedMapQueryContext implements ValueInitableData { @@ -1665,11 +1666,6 @@ public class CompiledReplicatedMapQueryContext { @@ -2026,19 +2027,20 @@ public class CompiledReplicatedMapQueryContext m() { - return m; + public long entryBytesAccessOffset(long offset) { + return entryBytesAccessor.offset(entryBytes, offset); } - @Override - public ChronicleMap map() { - return m(); + public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); } - @Override - public MapAbsentEntry absent() { - return CompiledReplicatedMapQueryContext.this; + 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(); } public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { @@ -2064,6 +2066,25 @@ public class CompiledReplicatedMapQueryContext m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + public void checkAccessingFromOwnerThread() { if ((owner) != (Thread.currentThread())) { throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); @@ -2074,21 +2095,9 @@ public class CompiledReplicatedMapQueryContext absent() { + return CompiledReplicatedMapQueryContext.this; } public T contextAtIndexInChain(int index) { @@ -2120,12 +2129,102 @@ public class CompiledReplicatedMapQueryContext= 0; + } + + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); + } + + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; + } + + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); } public Bytes inputBytes = null; @@ -2288,444 +2387,6 @@ public class CompiledReplicatedMapQueryContext= 0; - } - - public void initReplicationInput(Bytes replicatedInputBytes) { - initReplicatedInputBytes(replicatedInputBytes); - riKeySize = CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.readSize(replicatedInputBytes); - riValueSize = CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.readSize(replicatedInputBytes); - riTimestamp = replicatedInputBytes.readStopBit(); - riId = replicatedInputBytes.readByte(); - CompiledReplicatedMapQueryContext.this.initReplicationUpdate(riTimestamp, riId); - isDeleted = replicatedInputBytes.readBoolean(); - riKeyOffset = replicatedInputBytes.position(); - riValueOffset = (riKeyOffset) + (riKeySize); - this.closeReplicationInputDependants(); - } - - public boolean isDeleted() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.isDeleted; - } - - public byte riId() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riId; - } - - public long riKeyOffset() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riKeyOffset; - } - - public long riKeySize() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riKeySize; - } - - public long riValueOffset() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riValueOffset; - } - - public long riValueSize() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riValueSize; - } - - public void closeReplicationInput() { - if (!(this.replicationInputInit())) - return ; - - this.closeReplicationInputDependants(); - this.riKeySize = -1; - } - - public void closeReplicationInputDependants() { - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataGetUsingDependants(); - } - - public long keySize = -1; - - public boolean keySizeInit() { - return (this.keySize) >= 0; - } - - public void initKeySize(long keySize) { - this.keySize = keySize; - this.closeKeySizeDependants(); - } - - public long keySize() { - assert this.keySizeInit() : "KeySize should be init"; - return this.keySize; - } - - public void closeKeySize() { - if (!(this.keySizeInit())) - return ; - - this.closeKeySizeDependants(); - this.keySize = -1; - } - - public void closeKeySizeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - } - - 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.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataGetUsingDependants(); - } - - public long pos = -1; - - public boolean posInit() { - return (this.pos) >= 0; - } - - public void initPos(long pos) { - this.pos = pos; - this.closePosDependants(); - } - - public long pos() { - assert this.posInit() : "Pos should be init"; - return this.pos; - } - - public void closePos() { - if (!(this.posInit())) - return ; - - this.closePosDependants(); - this.pos = -1; - } - - public void closePosDependants() { - CompiledReplicatedMapQueryContext.this.closeEntryOffset(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - public long keyOffset = -1; - - public boolean keyOffsetInit() { - return (this.keyOffset) >= 0; - } - - public void initKeyOffset(long keyOffset) { - this.keyOffset = keyOffset; - this.closeKeyOffsetDependants(); - } - - public long keyOffset() { - assert this.keyOffsetInit() : "KeyOffset should be init"; - return this.keyOffset; - } - - public void closeKeyOffset() { - if (!(this.keyOffsetInit())) - return ; - - this.closeKeyOffsetDependants(); - this.keyOffset = -1; - } - - public void closeKeyOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); - } - - 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.closeValueSizeOffset(); - } - - public long valueSizeOffset = -1; - - public boolean valueSizeOffsetInit() { - return (this.valueSizeOffset) >= 0; - } - - void initValueSizeOffset() { - valueSizeOffset = countValueSizeOffset(); - this.closeValueSizeOffsetDependants(); - } - - public long valueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - this.initValueSizeOffset(); - - return this.valueSizeOffset; - } - - public void closeValueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - return ; - - this.closeValueSizeOffsetDependants(); - this.valueSizeOffset = -1; - } - - public void closeValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValSize(); - } - - public long valueSize = -1; - - public long valueOffset; - - public boolean valSizeInit() { - return (this.valueSize) >= 0; - } - - void initValSize() { - entryBytes.position(valueSizeOffset()); - valueSize = CompiledReplicatedMapQueryContext.this.m().readValueSize(entryBytes); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSize(long valueSize) { - this.valueSize = valueSize; - entryBytes.position(valueSizeOffset()); - CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSize = oldValueSize; - valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); - this.closeValSizeDependants(); - } - - public long valueOffset() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueSize; - } - - public void closeValSize() { - if (!(this.valSizeInit())) - return ; - - this.closeValSizeDependants(); - this.valueSize = -1; - } - - public void closeValSizeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeReplicatedMapEntryStagesEntryEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - } - - public void writeValue(Data value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); - } - - public void initValue(Data value) { - entryBytes.position(valueSizeOffset()); - initValSize(value.size()); - writeValue(value); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - assert oldValueSize == (value.size()); - initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); - writeValue(value); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - this.closeReplicationStateDependants(); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.closeReplicationStateDependants(); - this.replicationBytesOffset = -1; - } - - public void closeReplicationStateDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesTimestampOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesIdentifierOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesUpdateReplicationStateDependants(); - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - public void closeReplicatedMapEntryStagesTimestampOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesTimestampDependants(); - } - - public long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - public void closeReplicatedMapEntryStagesTimestampDependants() { - CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - public void closeReplicatedMapEntryStagesIdentifierOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesIdentifierDependants(); - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - public void closeReplicatedMapEntryStagesIdentifierDependants() { - CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); - } - - void updateReplicationState(long timestamp, byte identifier) { - entryBytes.position(replicationBytesOffset()); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public void closeReplicatedMapEntryStagesUpdateReplicationStateDependants() { - CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - public long innerRemoteTimestamp; public byte innerRemoteIdentifier = ((byte)(0)); @@ -2765,37 +2426,6 @@ public class CompiledReplicatedMapQueryContext inputKey = null; public boolean inputKeyInit() { @@ -2888,454 +2518,9 @@ 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.closeEntryOffset(); - } - - public long keySizeOffset = -1; - - public boolean entryOffsetInit() { - return (this.keySizeOffset) >= 0; - } - - public void initEntryOffset() { - keySizeOffset = (CompiledReplicatedMapQueryContext.this.entrySpaceOffset()) + ((pos()) * (CompiledReplicatedMapQueryContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - this.closeEntryOffsetDependants(); - } - - public long keySizeOffset() { - if (!(this.entryOffsetInit())) - this.initEntryOffset(); - - return this.keySizeOffset; - } - - public void closeEntryOffset() { - if (!(this.entryOffsetInit())) - return ; - - this.closeEntryOffsetDependants(); - this.keySizeOffset = -1; - } - - public void closeEntryOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesReadExistingEntryDependants(); - } - - public void writeNewEntry(long pos, Data key) { - initPos(pos); - initKeySize(key.size()); - entryBytes.position(keySizeOffset()); - CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); - initKeyOffset(entryBytes.position()); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); - } - - public void copyExistingEntry(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset(); - long oldKeyOffset = keyOffset(); - initPos(newPos); - initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); - } - - long entrySize() { - return (entryEnd()) - (keySizeOffset()); - } - - public void closeReplicatedMapEntryStagesEntrySizeDependants() { - CompiledReplicatedMapQueryContext.this.closeTheEntrySizeInChunks(); - } - - public int entrySizeInChunks = 0; - - public boolean theEntrySizeInChunksInit() { - return (this.entrySizeInChunks) != 0; - } - - void initTheEntrySizeInChunks() { - entrySizeInChunks = CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize()); - } - - public void initTheEntrySizeInChunks(int actuallyUsedChunks) { - entrySizeInChunks = actuallyUsedChunks; - } - - public int entrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - this.initTheEntrySizeInChunks(); - - return this.entrySizeInChunks; - } - - public void closeTheEntrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - return ; - - this.entrySizeInChunks = 0; - } - - public void readExistingEntry(long pos) { - initPos(pos); - entryBytes.position(keySizeOffset()); - initKeySize(CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes)); - initKeyOffset(entryBytes.position()); - } - - public void closeReplicatedMapEntryStagesReadExistingEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); - } - - public long newSizeOfEverythingBeforeValue(Data newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - long segmentHeaderAddress; - - SegmentHeader segmentHeader = null; - - public boolean segHeaderInit() { - return (this.segmentHeader) != null; - } - - private void initSegHeader() { - segmentHeaderAddress = (CompiledReplicatedMapQueryContext.this.h().ms.address()) + (CompiledReplicatedMapQueryContext.this.h().segmentHeaderOffset(segmentIndex())); - segmentHeader = BigSegmentHeader.INSTANCE; - this.closeSegHeaderDependants(); - } - - public long segmentHeaderAddress() { - if (!(this.segHeaderInit())) - this.initSegHeader(); - - return this.segmentHeaderAddress; - } - - public SegmentHeader segmentHeader() { - if (!(this.segHeaderInit())) - this.initSegHeader(); - - return this.segmentHeader; - } - - public void closeSegHeader() { - if (!(this.segHeaderInit())) - return ; - - this.closeSegHeaderDependants(); - this.segmentHeader = null; - } - - public void closeSegHeaderDependants() { - CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); - CompiledReplicatedMapQueryContext.this.closeLocks(); - CompiledReplicatedMapQueryContext.this.innerWriteLock.closeWriteLockLockDependants(); - CompiledReplicatedMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); - } - - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { - CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); - if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { - throw new IllegalStateException("Nested context not implemented yet"); - } else { - return false; - } - } - - public void closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants() { - CompiledReplicatedMapQueryContext.this.closeLocks(); - } - - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } - - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - - int totalReadLockCount; - - int totalUpdateLockCount; - - int totalWriteLockCount; - - public int latestSameThreadSegmentModCount; - - public int contextModCount; - - CompiledReplicatedMapQueryContext nextNode; - - public boolean concurrentSameThreadContexts; - - LocalLockState localLockState; - - public CompiledReplicatedMapQueryContext rootContextOnThisSegment = null; - - public boolean locksInit() { - return (this.rootContextOnThisSegment) != null; - } - - void initLocks() { - localLockState = LocalLockState.UNLOCKED; - int indexOfThisContext = CompiledReplicatedMapQueryContext.this.indexInContextChain; - for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - for (int i = indexOfThisContext + 1, size = CompiledReplicatedMapQueryContext.this.contextChain.size() ; i < size ; i++) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - rootContextOnThisSegment = this; - concurrentSameThreadContexts = false; - latestSameThreadSegmentModCount = 0; - contextModCount = 0; - nextNode = null; - totalReadLockCount = 0; - totalUpdateLockCount = 0; - totalWriteLockCount = 0; - this.closeLocksDependants(); - } - - public boolean concurrentSameThreadContexts() { - if (!(this.locksInit())) - this.initLocks(); - - return this.concurrentSameThreadContexts; - } - - public int contextModCount() { - if (!(this.locksInit())) - this.initLocks(); - - return this.contextModCount; - } - - public int latestSameThreadSegmentModCount() { - if (!(this.locksInit())) - this.initLocks(); - - return this.latestSameThreadSegmentModCount; - } - - public LocalLockState localLockState() { - if (!(this.locksInit())) - this.initLocks(); - - return this.localLockState; - } - - public CompiledReplicatedMapQueryContext rootContextOnThisSegment() { - if (!(this.locksInit())) - this.initLocks(); - - return this.rootContextOnThisSegment; - } - - void closeLocks() { - if (!(this.locksInit())) - return ; - - this.closeLocksDependants(); - if ((rootContextOnThisSegment) == this) { - closeRootLocks(); - } else { - closeNestedLocks(); - } - localLockState = null; - rootContextOnThisSegment = null; - } - - public void closeLocksDependants() { - CompiledReplicatedMapQueryContext.this.innerWriteLock.closeWriteLockLockDependants(); - CompiledReplicatedMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - private boolean updatedReplicationState = false; - - public boolean updatedReplicationStateInit() { - return (this.updatedReplicationState) != false; - } - - public void initUpdatedReplicationStateOnAbsentEntry() { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - if (CompiledReplicatedMapQueryContext.this.replicationUpdateInit()) { - updateReplicationState(CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp(), CompiledReplicatedMapQueryContext.this.innerRemoteIdentifier()); - } else { - updateReplicationState(CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(), CompiledReplicatedMapQueryContext.this.m().identifier()); - } - updatedReplicationState = true; - } - - public void initUpdatedReplicationStateOnPresentEntry() { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - if (CompiledReplicatedMapQueryContext.this.replicationUpdateInit()) { - updateReplicationState(CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp(), CompiledReplicatedMapQueryContext.this.innerRemoteIdentifier()); - } else { - long timestamp; - if ((identifier()) != (CompiledReplicatedMapQueryContext.this.m().identifier())) { - timestamp = Math.max(((timestamp()) + 1), CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime()); - } else { - timestamp = CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(); - } - updateReplicationState(timestamp, CompiledReplicatedMapQueryContext.this.m().identifier()); - } - updatedReplicationState = true; - } - - public void closeUpdatedReplicationState() { - if (!(this.updatedReplicationStateInit())) - return ; - - this.updatedReplicationState = false; - } - - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); - } - - public long entries() { - return segmentHeader().size(segmentHeaderAddress()); - } - - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledReplicatedMapQueryContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - 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 void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - - } - - public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); - CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - } - - 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()))); - } else { - initTheEntrySizeInChunks(CompiledReplicatedMapQueryContext.this.allocatedChunks()); - } - } - - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); - } - - public void raiseChange() { - CompiledReplicatedMapQueryContext.this.m().raiseChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); - } - - public void dropChange() { - CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); - } - - public void updateChange() { - if (replicationUpdateInit()) { - dropChange(); - } else { - raiseChange(); - } } int hashLookupEntrySize; @@ -3434,15 +2619,54 @@ public class CompiledReplicatedMapQueryContext= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + public long maskUnsetKey(long key) { return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); } @@ -3461,26 +2693,368 @@ public class CompiledReplicatedMapQueryContext>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + 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(); } long entry(long key, long value) { return key | (value << (keyBits())); } - 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 void writeEntryVolatile(long pos, long prevEntry, long key, long value) { long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); } - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + 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 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.closeEntryOffset(); + } + + long segmentHeaderAddress; + + SegmentHeader segmentHeader = null; + + public boolean segHeaderInit() { + return (this.segmentHeader) != null; + } + + private void initSegHeader() { + segmentHeaderAddress = (CompiledReplicatedMapQueryContext.this.h().ms.address()) + (CompiledReplicatedMapQueryContext.this.h().segmentHeaderOffset(segmentIndex())); + segmentHeader = BigSegmentHeader.INSTANCE; + this.closeSegHeaderDependants(); + } + + public long segmentHeaderAddress() { + if (!(this.segHeaderInit())) + this.initSegHeader(); + + return this.segmentHeaderAddress; + } + + public SegmentHeader segmentHeader() { + if (!(this.segHeaderInit())) + this.initSegHeader(); + + return this.segmentHeader; + } + + public void closeSegHeader() { + if (!(this.segHeaderInit())) + return ; + + this.closeSegHeaderDependants(); + this.segmentHeader = null; + } + + public void closeSegHeaderDependants() { + CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + CompiledReplicatedMapQueryContext.this.closeLocks(); + CompiledReplicatedMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); + CompiledReplicatedMapQueryContext.this.innerWriteLock.closeWriteLockLockDependants(); + } + + public void entries(long size) { + segmentHeader().size(segmentHeaderAddress(), size); + } + + public void nextPosToSearchFrom(long nextPosToSearchFrom) { + segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); + } + + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (CompiledReplicatedMapQueryContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { + CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); + if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { + throw new IllegalStateException("Nested context not implemented yet"); + } else { + return false; + } + } + + public void closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants() { + CompiledReplicatedMapQueryContext.this.closeLocks(); + } + + int totalReadLockCount; + + int totalUpdateLockCount; + + int totalWriteLockCount; + + public int latestSameThreadSegmentModCount; + + public int contextModCount; + + CompiledReplicatedMapQueryContext nextNode; + + public boolean concurrentSameThreadContexts; + + LocalLockState localLockState; + + public CompiledReplicatedMapQueryContext rootContextOnThisSegment = null; + + public boolean locksInit() { + return (this.rootContextOnThisSegment) != null; + } + + void initLocks() { + localLockState = LocalLockState.UNLOCKED; + int indexOfThisContext = CompiledReplicatedMapQueryContext.this.indexInContextChain; + for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + for (int i = indexOfThisContext + 1, size = CompiledReplicatedMapQueryContext.this.contextChain.size() ; i < size ; i++) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + rootContextOnThisSegment = this; + concurrentSameThreadContexts = false; + latestSameThreadSegmentModCount = 0; + contextModCount = 0; + nextNode = null; + totalReadLockCount = 0; + totalUpdateLockCount = 0; + totalWriteLockCount = 0; + this.closeLocksDependants(); + } + + public boolean concurrentSameThreadContexts() { + if (!(this.locksInit())) + this.initLocks(); + + return this.concurrentSameThreadContexts; + } + + public int contextModCount() { + if (!(this.locksInit())) + this.initLocks(); + + return this.contextModCount; + } + + public int latestSameThreadSegmentModCount() { + if (!(this.locksInit())) + this.initLocks(); + + return this.latestSameThreadSegmentModCount; + } + + public LocalLockState localLockState() { + if (!(this.locksInit())) + this.initLocks(); + + return this.localLockState; + } + + public CompiledReplicatedMapQueryContext rootContextOnThisSegment() { + if (!(this.locksInit())) + this.initLocks(); + + return this.rootContextOnThisSegment; + } + + void closeLocks() { + if (!(this.locksInit())) + return ; + + this.closeLocksDependants(); + if ((rootContextOnThisSegment) == this) { + closeRootLocks(); + } else { + closeNestedLocks(); + } + localLockState = null; + rootContextOnThisSegment = null; + } + + public void closeLocksDependants() { + CompiledReplicatedMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + CompiledReplicatedMapQueryContext.this.innerWriteLock.closeWriteLockLockDependants(); + } + + public long deleted() { + return segmentHeader().deleted(segmentHeaderAddress()); + } + + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); + } + + 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 void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public void deleted(long deleted) { + segmentHeader().deleted(segmentHeaderAddress(), deleted); + } + + public long entries() { + return segmentHeader().size(segmentHeaderAddress()); + } + + public long size() { + return (entries()) - (deleted()); } public void clearSegment() { @@ -3495,14 +3069,6 @@ public class CompiledReplicatedMapQueryContext>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public void closeHashLookupReadEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void putNewVolatile(long value) { - CompiledReplicatedMapQueryContext.this.checkValueForPut(value); - long currentEntry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); - CompiledReplicatedMapQueryContext.this.writeEntryVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); } void put(long value) { @@ -3617,35 +3154,6 @@ public class CompiledReplicatedMapQueryContext value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - 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 putNewVolatile(long value) { + CompiledReplicatedMapQueryContext.this.checkValueForPut(value); + long currentEntry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); + CompiledReplicatedMapQueryContext.this.writeEntryVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); } public void putVolatile(long value) { @@ -3690,6 +3176,22 @@ public class CompiledReplicatedMapQueryContext= 0 ? pos : capacityMask2(); + public long keySize = -1; + + public boolean keySizeInit() { + return (this.keySize) >= 0; } - public void closeHashLookupStepBackDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); } - public void found() { - CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.stepBack(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; } - public void closeHashLookupSearchFoundDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; } - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + public void closeKeySizeDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); } - 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; + public long keyEnd() { + return (keyOffset()) + (keySize()); + } - 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; - } + 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(); + this.closeReplicationStateDependants(); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.closeReplicationStateDependants(); + this.replicationBytesOffset = -1; + } + + public void closeReplicationStateDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesIdentifierOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesUpdateReplicationStateDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesTimestampOffsetDependants(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + public void closeReplicatedMapEntryStagesIdentifierOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesIdentifierDependants(); + } + + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); + } + + public void closeReplicatedMapEntryStagesIdentifierDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + void updateReplicationState(long timestamp, byte identifier) { + entryBytes.position(replicationBytesOffset()); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public void closeReplicatedMapEntryStagesUpdateReplicationStateDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + public void closeReplicatedMapEntryStagesTimestampOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesTimestampDependants(); + } + + public long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + public void closeReplicatedMapEntryStagesTimestampDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + 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.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp()); } - clearEntry(posToRemove, entryToRemove); - return posToRemove; + return true; } - public void remove() { - CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.remove(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + private boolean updatedReplicationState = false; + + public boolean updatedReplicationStateInit() { + return (this.updatedReplicationState) != false; + } + + public void initUpdatedReplicationStateOnAbsentEntry() { + CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + if (CompiledReplicatedMapQueryContext.this.replicationUpdateInit()) { + updateReplicationState(CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp(), CompiledReplicatedMapQueryContext.this.innerRemoteIdentifier()); + } else { + updateReplicationState(CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(), CompiledReplicatedMapQueryContext.this.m().identifier()); + } + updatedReplicationState = true; + } + + public void initUpdatedReplicationStateOnPresentEntry() { + CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + if (CompiledReplicatedMapQueryContext.this.replicationUpdateInit()) { + updateReplicationState(CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp(), CompiledReplicatedMapQueryContext.this.innerRemoteIdentifier()); + } else { + long timestamp; + if ((identifier()) != (CompiledReplicatedMapQueryContext.this.m().identifier())) { + timestamp = Math.max(((timestamp()) + 1), CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime()); + } else { + timestamp = CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(); + } + updateReplicationState(timestamp, CompiledReplicatedMapQueryContext.this.m().identifier()); + } + updatedReplicationState = true; + } + + public void closeUpdatedReplicationState() { + if (!(this.updatedReplicationStateInit())) + return ; + + this.updatedReplicationState = false; + } + + private long _MapEntryStages_countValueSizeOffset() { + return keyEnd(); + } + + long countValueSizeOffset() { + return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeValueSizeOffset(); + } + + public long valueSizeOffset = -1; + + public boolean valueSizeOffsetInit() { + return (this.valueSizeOffset) >= 0; + } + + void initValueSizeOffset() { + valueSizeOffset = countValueSizeOffset(); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeValSize(); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); + valueSize = CompiledReplicatedMapQueryContext.this.m().readValueSize(entryBytes); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSize = oldValueSize; + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); + } + + public long valueOffset() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueSize; + } + + public void closeValSize() { + if (!(this.valSizeInit())) + return ; + + this.closeValSizeDependants(); + this.valueSize = -1; + } + + public void closeValSizeDependants() { + CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + private long _HashEntryStages_entryEnd() { + return keyEnd(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeReplicatedMapEntryStagesEntryEndDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + public void writeValue(Data value) { + value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); } boolean keyEquals() { @@ -3769,6 +3529,82 @@ public class CompiledReplicatedMapQueryContext= 0; + } + + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); + } + + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) + return ; + + this.closePosDependants(); + this.pos = -1; + } + + public void closePosDependants() { + CompiledReplicatedMapQueryContext.this.closeEntryOffset(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public void raiseChange() { + CompiledReplicatedMapQueryContext.this.m().raiseChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); + } + + public long keySizeOffset = -1; + + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; + } + + public void initEntryOffset() { + keySizeOffset = (CompiledReplicatedMapQueryContext.this.entrySpaceOffset()) + ((pos()) * (CompiledReplicatedMapQueryContext.this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); + } + + public long keySizeOffset() { + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + + return this.keySizeOffset; + } + + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) + return ; + + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; + } + + public void closeEntryOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesReadExistingEntryDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); + } + + public void closeReplicatedMapEntryStagesReadExistingEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeKeySearch(); + } + protected SearchState searchState = null; boolean keySearchInit() { @@ -3808,155 +3644,6 @@ public class CompiledReplicatedMapQueryContext wrapValueAsValue(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - @NotNull - @Override - public MapContext context() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return this; - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerReadLock; - } - - @NotNull - @Override - public Data value() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryValue; - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerUpdateLock; - } - - @Override - public long originTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - @Override - public Data defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data 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 Data defaultValue() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); - } - - @NotNull - @Override - public Data absentKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.inputKey(); - } - - @NotNull - @Override - public Data key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryKey; - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return innerRemoteIdentifier(); - } - public boolean searchStatePresent() { return (searchState()) == (SearchState.PRESENT); } @@ -3969,38 +3656,6 @@ public class CompiledReplicatedMapQueryContext _MapQuery_entry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; - } - - @Override - public MapReplicableEntry entry() { - return ((MapReplicableEntry)(_MapQuery_entry())); - } - - @Nullable - private MapAbsentEntry _MapQuery_absentEntry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledReplicatedMapQueryContext.this.absent(); - } - - @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(); - } - } - } - public boolean searchStateDeleted() { return (((searchState()) == (SearchState.DELETED)) && (!(CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); } @@ -4009,18 +3664,6 @@ public class CompiledReplicatedMapQueryContext key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); + } + + public void initEntryAndKey(long entrySize) { + initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); + CompiledReplicatedMapQueryContext.this.writeNewEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); + incrementSegmentEntriesIfNeeded(); + } + + long entrySize() { + return (entryEnd()) - (keySizeOffset()); + } + + public void closeReplicatedMapEntryStagesEntrySizeDependants() { + CompiledReplicatedMapQueryContext.this.closeTheEntrySizeInChunks(); + } + + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; + } + + void initTheEntrySizeInChunks() { + entrySizeInChunks = CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize()); + } + + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; + } + + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; + } + + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + return ; + + this.entrySizeInChunks = 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()))); + } else { + initTheEntrySizeInChunks(CompiledReplicatedMapQueryContext.this.allocatedChunks()); + } + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); + } + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); CompiledReplicatedMapQueryContext.this.copyExistingEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); incrementSegmentEntriesIfNeeded(); } - private void _MapEntryStages_relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); - writeValueAndPutPos(newValue); - } - - protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - CompiledReplicatedMapQueryContext.this.dropChange(); - _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); - } - - public void innerDefaultReplaceValue(Data newValue) { - assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); - boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); - if (newValueSizeIsDifferent) { - long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long entryStartOffset = keySizeOffset(); - VanillaChronicleMap m = CompiledReplicatedMapQueryContext.this.m(); - long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - int newSizeInChunks = m.inChunks(newEntrySize); - newValueDoesNotFit : if (newSizeInChunks > (entrySizeInChunks())) { - if (newSizeInChunks > (m.maxChunksPerEntry)) { - throw new IllegalArgumentException(((((("Value too large: " + "entry takes ") + newSizeInChunks) + " chunks, ") + (m.maxChunksPerEntry)) + " is maximum.")); - } - if (CompiledReplicatedMapQueryContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { - CompiledReplicatedMapQueryContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); - break newValueDoesNotFit; - } - relocation(newValue, newSizeOfEverythingBeforeValue); - return ; - } else if (newSizeInChunks < (entrySizeInChunks())) { - CompiledReplicatedMapQueryContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); - } - } else { - } - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - if (newValueSizeIsDifferent) { - initValue(newValue); - } else { - writeValue(newValue); - } - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - private void _MapQuery_doRemove() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - if (searchStatePresent()) { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - CompiledReplicatedMapQueryContext.this.remove(); - CompiledReplicatedMapQueryContext.this.innerRemoveEntryExceptHashLookupUpdate(); - setSearchStateGuarded(SearchState.DELETED); - } else { - throw new IllegalStateException("Entry is absent when doRemove() is called"); - } - } - - @Override - public void doRemove() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - if (entryPresent()) { - if ((CompiledReplicatedMapQueryContext.this.valueSize()) > (CompiledReplicatedMapQueryContext.this.dummyValue.size())) - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(CompiledReplicatedMapQueryContext.this.dummyValue); - - CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); - CompiledReplicatedMapQueryContext.this.writeEntryDeleted(); - CompiledReplicatedMapQueryContext.this.updateChange(); - CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) + 1)); - } else { - throw new IllegalStateException("Entry is absent in the map when doRemove() is called"); - } - } - - public void processReplicatedEvent() { - if ((riId()) == (CompiledReplicatedMapQueryContext.this.m().identifier())) { - return ; - } - CompiledReplicatedMapQueryContext.this.initInputKey(CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue); - boolean debugEnabled = CompiledReplicatedMapQueryContext.this.LOG.isDebugEnabled(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - if (isDeleted()) { - if (debugEnabled) { - CompiledReplicatedMapQueryContext.this.LOG.debug("READING FROM SOURCE - into local-id={}, remote={}, remove(key={})", CompiledReplicatedMapQueryContext.this.m().identifier(), riId(), CompiledReplicatedMapQueryContext.this.inputKey()); - } - if ((CompiledReplicatedMapQueryContext.this.m().remoteOperations.remove(this)) == (AcceptanceDecision.ACCEPT)) { - CompiledReplicatedMapQueryContext.this.absent().doInsert(CompiledReplicatedMapQueryContext.this.dummyValue); - CompiledReplicatedMapQueryContext.this.doRemove(); - if (!(CompiledReplicatedMapQueryContext.this.updatedReplicationStateInit())) - CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); - - } - return ; - } - String message = null; - if (debugEnabled) { - message = String.format("READING FROM SOURCE - into local-id=%d, remote-id=%d, put(key=%s,", CompiledReplicatedMapQueryContext.this.m().identifier(), riId(), CompiledReplicatedMapQueryContext.this.inputKey()); - } - if ((CompiledReplicatedMapQueryContext.this.m().remoteOperations.put(this, CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue)) == (AcceptanceDecision.ACCEPT)) { - if (!(CompiledReplicatedMapQueryContext.this.updatedReplicationStateInit())) - CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); - - } - if (debugEnabled) { - CompiledReplicatedMapQueryContext.this.LOG.debug((((message + "value=") + (CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue)) + ")")); - } - } - private void _MapEntryStages_putValueDeletedEntry(Data newValue) { assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; @@ -4195,12 +3799,6 @@ public class CompiledReplicatedMapQueryContext value) { assert CompiledReplicatedMapQueryContext.this.searchStateAbsent(); long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(CompiledReplicatedMapQueryContext.this.inputKey().size(), value.size()); @@ -4210,6 +3808,274 @@ public class CompiledReplicatedMapQueryContext value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + } + + public void dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed() { + if (CompiledReplicatedMapQueryContext.this.locksInit()) { + if ((CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()) && ((CompiledReplicatedMapQueryContext.this.rootContextOnThisSegment().latestSameThreadSegmentModCount()) != (CompiledReplicatedMapQueryContext.this.contextModCount()))) { + if (keySearchInit()) { + if ((searchState()) == (SearchState.PRESENT)) { + if (!(CompiledReplicatedMapQueryContext.this.checkSlotContainsExpectedKeyAndValue(CompiledReplicatedMapQueryContext.this.pos()))) + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); + + } + } + } + } + } + + public void closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants() { + CompiledReplicatedMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { + CompiledReplicatedMapQueryContext.this.checkAccessingFromOwnerThread(); + } + + public void checkOnEachPublicOperation() { + _CheckOnEachPublicOperation_checkOnEachPublicOperation(); + CompiledReplicatedMapQueryContext.this.dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed(); + } + + public void closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { + CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + public Data queriedKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + + @Override + public byte remoteIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return innerRemoteIdentifier(); + } + + @NotNull + @Override + public Data absentKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.inputKey(); + } + + @NotNull + @Override + public Data key() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryKey; + } + + 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(); + + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + @Override + public Data wrapValueAsValue(V value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public Data defaultValue() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerWriteLock; + } + + @Override + public long remoteTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return innerRemoteTimestamp(); + } + + private MapEntry _MapQuery_entry() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? this : null; + } + + @Override + public MapReplicableEntry entry() { + return ((MapReplicableEntry)(_MapQuery_entry())); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerUpdateLock; + } + + @Nullable + private MapAbsentEntry _MapQuery_absentEntry() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? null : CompiledReplicatedMapQueryContext.this.absent(); + } + + @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(); + } + } + } + + @Override + public byte originIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return identifier(); + } + + @NotNull + @Override + public MapContext context() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return this; + } + + @NotNull + @Override + public Data value() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryValue; + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerReadLock; + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + } + + public void dropChange() { + CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); + } + + private void _MapEntryStages_relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); + } + + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + CompiledReplicatedMapQueryContext.this.dropChange(); + _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); + } + + public void innerDefaultReplaceValue(Data newValue) { + assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); + boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); + if (newValueSizeIsDifferent) { + long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long entryStartOffset = keySizeOffset(); + VanillaChronicleMap m = CompiledReplicatedMapQueryContext.this.m(); + long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + int newSizeInChunks = m.inChunks(newEntrySize); + newValueDoesNotFit : if (newSizeInChunks > (entrySizeInChunks())) { + if (newSizeInChunks > (m.maxChunksPerEntry)) { + throw new IllegalArgumentException(((((("Value too large: " + "entry takes ") + newSizeInChunks) + " chunks, ") + (m.maxChunksPerEntry)) + " is maximum.")); + } + if (CompiledReplicatedMapQueryContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { + CompiledReplicatedMapQueryContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); + break newValueDoesNotFit; + } + relocation(newValue, newSizeOfEverythingBeforeValue); + return ; + } else if (newSizeInChunks < (entrySizeInChunks())) { + CompiledReplicatedMapQueryContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); + } + } else { + } + CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + public void updateChange() { + if (replicationUpdateInit()) { + dropChange(); + } else { + raiseChange(); + } + } + private void _MapAbsent_doInsert(Data value) { CompiledReplicatedMapQueryContext.this.putPrefix(); if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { @@ -4245,6 +4111,36 @@ public class CompiledReplicatedMapQueryContext (CompiledReplicatedMapQueryContext.this.dummyValue.size())) + CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(CompiledReplicatedMapQueryContext.this.dummyValue); + + CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); + CompiledReplicatedMapQueryContext.this.writeEntryDeleted(); + CompiledReplicatedMapQueryContext.this.updateChange(); + CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) + 1)); + } else { + throw new IllegalStateException("Entry is absent in the map when doRemove() is called"); + } + } + private void _MapQuery_doReplaceValue(Data newValue) { putPrefix(); if (searchStatePresent()) { @@ -4263,8 +4159,120 @@ public class CompiledReplicatedMapQueryContext queriedKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); + public long riKeySize = -1; + + public long riValueSize; + + public long riKeyOffset; + + public long riValueOffset; + + public long riTimestamp; + + public byte riId; + + public boolean isDeleted; + + public boolean replicationInputInit() { + return (this.riKeySize) >= 0; + } + + public void initReplicationInput(Bytes replicatedInputBytes) { + initReplicatedInputBytes(replicatedInputBytes); + riKeySize = CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.readSize(replicatedInputBytes); + riValueSize = CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.readSize(replicatedInputBytes); + riTimestamp = replicatedInputBytes.readStopBit(); + riId = replicatedInputBytes.readByte(); + CompiledReplicatedMapQueryContext.this.initReplicationUpdate(riTimestamp, riId); + isDeleted = replicatedInputBytes.readBoolean(); + riKeyOffset = replicatedInputBytes.position(); + riValueOffset = (riKeyOffset) + (riKeySize); + this.closeReplicationInputDependants(); + } + + public boolean isDeleted() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.isDeleted; + } + + public byte riId() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riId; + } + + public long riKeyOffset() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riKeyOffset; + } + + public long riKeySize() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riKeySize; + } + + public long riTimestamp() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riTimestamp; + } + + public long riValueOffset() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riValueOffset; + } + + public long riValueSize() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riValueSize; + } + + public void closeReplicationInput() { + if (!(this.replicationInputInit())) + return ; + + this.closeReplicationInputDependants(); + this.riKeySize = -1; + } + + public void closeReplicationInputDependants() { + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataGetUsingDependants(); + } + + public void processReplicatedEvent() { + if ((riId()) == (CompiledReplicatedMapQueryContext.this.m().identifier())) { + return ; + } + CompiledReplicatedMapQueryContext.this.initInputKey(CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue); + boolean debugEnabled = CompiledReplicatedMapQueryContext.this.LOG.isDebugEnabled(); + CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); + if (isDeleted()) { + if (debugEnabled) { + CompiledReplicatedMapQueryContext.this.LOG.debug("READING FROM SOURCE - into local-id={}, remote={}, remove(key={})", CompiledReplicatedMapQueryContext.this.m().identifier(), riId(), CompiledReplicatedMapQueryContext.this.inputKey()); + } + if ((CompiledReplicatedMapQueryContext.this.m().remoteOperations.remove(this)) == (AcceptanceDecision.ACCEPT)) { + CompiledReplicatedMapQueryContext.this.absent().doInsert(CompiledReplicatedMapQueryContext.this.dummyValue); + CompiledReplicatedMapQueryContext.this.doRemove(); + if (!(CompiledReplicatedMapQueryContext.this.updatedReplicationStateInit())) + CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); + + } + CompiledReplicatedMapQueryContext.this.m().setLastModificationTime(riId(), riTimestamp()); + return ; + } + String message = null; + if (debugEnabled) { + message = String.format("READING FROM SOURCE - into local-id=%d, remote-id=%d, put(key=%s,", CompiledReplicatedMapQueryContext.this.m().identifier(), riId(), CompiledReplicatedMapQueryContext.this.inputKey()); + } + if ((CompiledReplicatedMapQueryContext.this.m().remoteOperations.put(this, CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue)) == (AcceptanceDecision.ACCEPT)) { + if (!(CompiledReplicatedMapQueryContext.this.updatedReplicationStateInit())) + CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); + + } + CompiledReplicatedMapQueryContext.this.m().setLastModificationTime(riId(), riTimestamp()); + if (debugEnabled) { + CompiledReplicatedMapQueryContext.this.LOG.debug((((message + "value=") + (CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue)) + ")")); + } } } diff --git a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java index 5cd6e1a35..5445c9717 100644 --- a/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java +++ b/src/test/java/net/openhft/chronicle/map/CHMUseCasesTest.java @@ -1162,7 +1162,6 @@ public class CHMUseCasesTest { } - // @Ignore("HCOLL-268 JSON serialisation issue") @Test public void testByteBufferByteBufferDefaultKeyValueMarshaller() throws ExecutionException, InterruptedException, IOException { diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index 2669f3901..f8320c822 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -1687,7 +1687,7 @@ public class ChronicleMapTest { @Test - @Ignore + @Ignore("TODO investigate, debug") public void testByteArrayKeySizeBySample() throws IOException { TcpTransportAndNetworkConfig serverConfig = TcpTransportAndNetworkConfig.of(8877); diff --git a/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java b/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java index 9bc21852f..3c9bdfb1a 100644 --- a/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java @@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals; public class DefaultValueTest { @Test - @Ignore + @Ignore("Cannot reuse List instance in acquireUsing()") public void test() throws IllegalAccessException, InstantiationException, IOException { File file = Builder.getPersistenceFile(); try { diff --git a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java index c423e96b1..f2af3a766 100644 --- a/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java +++ b/src/test/java/net/openhft/chronicle/map/StatelessClientTest.java @@ -45,7 +45,7 @@ import static org.junit.Assert.assertTrue; /** * @author Rob Austin. */ -@Ignore +@Ignore("Stateless clients in this form are deprecated and left not working") public class StatelessClientTest { private static final Logger LOG = LoggerFactory.getLogger(StatelessClientTest.class); diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationBootStrapTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationBootStrapTest.java index 3f9afae6a..7587d2105 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationBootStrapTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationBootStrapTest.java @@ -43,7 +43,6 @@ import static org.junit.Assert.assertEquals; * * @author Rob Austin. */ -@Ignore public class TCPSocketReplicationBootStrapTest { private ReplicatedChronicleMap map1; @@ -186,11 +185,14 @@ public class TCPSocketReplicationBootStrapTest { * @throws InterruptedException */ private void waitTillEqual(final int timeOutMs) throws InterruptedException { + long startTime = System.currentTimeMillis(); int t = 0; for (; t < timeOutMs; t++) { if (map1.equals(map2)) break; Thread.sleep(1); + if (System.currentTimeMillis() - startTime > timeOutMs) + break; } } diff --git a/src/test/java/net/openhft/chronicle/map/example/ChannelReplicationTest.java b/src/test/java/net/openhft/chronicle/map/example/ChannelReplicationTest.java index 40a9ec911..bacb2c600 100644 --- a/src/test/java/net/openhft/chronicle/map/example/ChannelReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/example/ChannelReplicationTest.java @@ -36,7 +36,6 @@ import static org.junit.Assert.assertEquals; /** * @author Rob Austin. */ -@Ignore public class ChannelReplicationTest { private ChronicleMap favoriteComputerServer1; diff --git a/src/test/java/net/openhft/lang/values/DoubleArrayTest.java b/src/test/java/net/openhft/lang/values/DoubleArrayTest.java index 7ceb3c38e..4163f1a68 100755 --- a/src/test/java/net/openhft/lang/values/DoubleArrayTest.java +++ b/src/test/java/net/openhft/lang/values/DoubleArrayTest.java @@ -68,7 +68,7 @@ public class DoubleArrayTest { } @Test - @Ignore + @Ignore("TODO What is HACK???") public void addToAMap2() { DoubleArray.HACK = false; DoubleArray a = new DoubleArray(10);