diff --git a/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHashHolder.java b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHashHolder.java new file mode 100644 index 000000000..d46d9c137 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHashHolder.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Higher Frequency Trading + * + * http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.hash.impl; + +import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; + +public interface VanillaChronicleHashHolder> { + VanillaChronicleHash h(); +} 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 b7b21c60a..904f3c655 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java @@ -14,7 +14,6 @@ import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; import net.openhft.chronicle.map.*; -import net.openhft.chronicle.map.impl.stage.map.VanillaChronicleMapHolder; import net.openhft.lang.Maths; import net.openhft.lang.MemoryUnit; import net.openhft.lang.collection.DirectBitSet; @@ -34,18 +33,18 @@ 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.closeAllocatedChunks(); + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); CompiledMapIterationContext.this.closeTheSegmentIndex(); - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapIterationContext.this.closeHashLookupPos(); + CompiledMapIterationContext.this.closeAllocatedChunks(); CompiledMapIterationContext.this.closeUsed(); CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration(); - CompiledMapIterationContext.this.closeHashLookupPos(); - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapIterationContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledMapIterationContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); CompiledMapIterationContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); } public void incrementModCountGuarded() { @@ -84,23 +83,23 @@ public class CompiledMapIterationContext)(entryBytesAccessor.access(entryBytes))); 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.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryKey = new EntryKeyBytesValue(); this.innerWriteLock = new WriteLock(); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); this.innerReadLock = new ReadLock(); this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerUpdateLock = new UpdateLock(); + 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.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryValue = new EntryValueBytesValue(); } public CompiledMapIterationContext(CompiledMapIterationContext c) { @@ -108,38 +107,38 @@ public class CompiledMapIterationContext)(c.m)); - this.entryKey = new EntryKeyBytesValue(); - this.innerUpdateLock = new UpdateLock(); - 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.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.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryKey = new EntryKeyBytesValue(); this.innerWriteLock = new WriteLock(); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); this.innerReadLock = new ReadLock(); this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerUpdateLock = new UpdateLock(); + 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.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryValue = new EntryValueBytesValue(); } public class EntryKeyBytesValue extends AbstractValue { - @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 offset() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); @@ -165,12 +164,6 @@ public class CompiledMapIterationContext { @@ -572,18 +571,6 @@ public class CompiledMapIterationContext m() { - return m; - } - - @Override - public ChronicleMap map() { - return m(); - } - - public void incrementSegmentEntriesIfNeeded() { - } - - public MKI keyMetaInterop(K key) { - return CompiledMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); - } - - @NotNull - @Override - public MapContext context() { - return CompiledMapIterationContext.this; - } - public long entryBytesAccessOffset(long offset) { return entryBytesAccessor.offset(entryBytes, offset); } @@ -1095,37 +1061,14 @@ public class CompiledMapIterationContextT 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)); - } - - private CompiledMapIterationContext _Chaining_createChaining() { - return new CompiledMapIterationContext(this); - } - - public CompiledMapIterationContext createChaining() { - return new CompiledMapIterationContext(this); - } - - public T getContext() { - for (CompiledMapIterationContext context : contextChain) { - if (!(context.usedInit())) { - return ((T)(context)); - } + 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; } - int maxNestedContexts = 1 << 16; - if ((contextChain.size()) > maxNestedContexts) { - throw new IllegalStateException((((((("More than " + maxNestedContexts) + " nested ChronicleHash contexts are not supported. Very probable that ") + "you simply forgot to close context somewhere (recommended to use ") + "try-with-resources statement). ") + "Otherwise this is a bug, please report with this ") + "stack trace on https://github.com/OpenHFT/Chronicle-Map/issues")); - } - return ((T)(createChaining())); } public void checkAccessingFromOwnerThread() { @@ -1138,6 +1081,33 @@ public class CompiledMapIterationContext absentEntry, Value value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); - } - @Override public Value defaultValue(@NotNull MapAbsentEntry absentEntry) { @@ -1180,13 +1143,6 @@ public class CompiledMapIterationContext entry) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.remove(entry); - } - @NotNull @Override public Value key() { @@ -1194,13 +1150,6 @@ public class CompiledMapIterationContext value() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryValue; - } - @Override public R replaceValue(@NotNull MapEntry entry, Value newValue) { @@ -1208,11 +1157,11 @@ public class CompiledMapIterationContext entry) { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerReadLock; + return CompiledMapIterationContext.this.m().entryOperations.remove(entry); } @Override @@ -1224,53 +1173,81 @@ public class CompiledMapIterationContext value() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryValue; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Value value) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerReadLock; + } + public boolean entryIsPresent() { return true; } - 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; + @Override + public VanillaChronicleMap m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + + @NotNull + @Override + public MapContext context() { + return CompiledMapIterationContext.this; + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + public void incrementSegmentEntriesIfNeeded() { + } + + private CompiledMapIterationContext _Chaining_createChaining() { + return new CompiledMapIterationContext(this); + } + + public CompiledMapIterationContext createChaining() { + return new CompiledMapIterationContext(this); + } + + public T getContext() { + for (CompiledMapIterationContext context : contextChain) { + if (!(context.usedInit())) { + return ((T)(context)); + } } + int maxNestedContexts = 1 << 16; + if ((contextChain.size()) > maxNestedContexts) { + throw new IllegalStateException((((((("More than " + maxNestedContexts) + " nested ChronicleHash contexts are not supported. Very probable that ") + "you simply forgot to close context somewhere (recommended to use ") + "try-with-resources statement). ") + "Otherwise this is a bug, please report with this ") + "stack trace on https://github.com/OpenHFT/Chronicle-Map/issues")); + } + return ((T)(createChaining())); } - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - 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 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 MKI keyMetaInterop(K key) { + return CompiledMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); } public boolean entryRemovedOnThisIteration = false; @@ -1307,6 +1284,50 @@ public class CompiledMapIterationContext= 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 int segmentIndex = -1; public boolean theSegmentIndexInit() { @@ -1332,171 +1353,9 @@ public class CompiledMapIterationContext= 0 ; i--) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - for (int i = indexOfThisContext + 1, size = CompiledMapIterationContext.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; - } - - public LocalLockState localLockState() { - if (!(this.locksInit())) - this.initLocks(); - - return this.localLockState; - } - - public CompiledMapIterationContext rootContextOnThisSegment() { - if (!(this.locksInit())) - this.initLocks(); - - return this.rootContextOnThisSegment; - } - - void closeLocks() { - if (!(this.locksInit())) - return ; - - if ((rootContextOnThisSegment) == this) { - closeRootLocks(); - } else { - closeNestedLocks(); - } - localLockState = null; - rootContextOnThisSegment = null; - } - - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledMapIterationContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); + CompiledMapIterationContext.this.closeSegHeader(); } long entrySpaceOffset = 0; @@ -1545,36 +1404,6 @@ public class CompiledMapIterationContext h = CompiledMapIterationContext.this.h(); - if (chunks > (h.maxChunksPerEntry)) - throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); - - long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - ret = freeList().setNextNContinuousClearBits(0L, chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - if (chunks == 1) { - throw new IllegalStateException("Segment is full, no free entries found"); - } else { - throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); - } - } - updateNextPosToSearchFrom(ret, chunks); - } else { - if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { - updateNextPosToSearchFrom(ret, chunks); - } - } - return ret; - } - public long pos = -1; public long keySizeOffset; @@ -1646,10 +1475,10 @@ public class CompiledMapIterationContext= 0 ? pos : capacityMask2(); } - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - long entry(long key, long value) { - return key | (value << (keyBits())); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - public long hlPos(long key) { return indexToPos((key & (capacityMask()))); } - public long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; } - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); } public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { @@ -1961,6 +1813,192 @@ public class CompiledMapIterationContext>> (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(); + } + + long segmentHeaderAddress; + + SegmentHeader segmentHeader = null; + + public boolean segHeaderInit() { + return (this.segmentHeader) != null; + } + + private void initSegHeader() { + segmentHeaderAddress = (CompiledMapIterationContext.this.h().ms.address()) + (CompiledMapIterationContext.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() { + CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + CompiledMapIterationContext.this.closeLocks(); + } + + public void entries(long size) { + segmentHeader().size(segmentHeaderAddress(), size); + } + + public long deleted() { + return segmentHeader().deleted(segmentHeaderAddress()); + } + + public long entries() { + return segmentHeader().size(segmentHeaderAddress()); + } + + public long size() { + return (entries()) - (deleted()); + } + + public void deleted(long deleted) { + segmentHeader().deleted(segmentHeaderAddress(), deleted); + } + + public void nextPosToSearchFrom(long nextPosToSearchFrom) { + segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); + } + + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (CompiledMapIterationContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { + CompiledMapIterationContext c = CompiledMapIterationContext.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() { + CompiledMapIterationContext.this.closeLocks(); + } + + int totalReadLockCount; + + int totalUpdateLockCount; + + int totalWriteLockCount; + + public int latestSameThreadSegmentModCount; + + public int contextModCount; + + CompiledMapIterationContext nextNode; + + public boolean concurrentSameThreadContexts; + + LocalLockState localLockState; + + public CompiledMapIterationContext rootContextOnThisSegment = null; + + public boolean locksInit() { + return (this.rootContextOnThisSegment) != null; + } + + void initLocks() { + localLockState = LocalLockState.UNLOCKED; + int indexOfThisContext = CompiledMapIterationContext.this.indexInContextChain; + for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + for (int i = indexOfThisContext + 1, size = CompiledMapIterationContext.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; + } + + public LocalLockState localLockState() { + if (!(this.locksInit())) + this.initLocks(); + + return this.localLockState; + } + + public CompiledMapIterationContext rootContextOnThisSegment() { + if (!(this.locksInit())) + this.initLocks(); + + return this.rootContextOnThisSegment; + } + + void closeLocks() { + if (!(this.locksInit())) + return ; + + if ((rootContextOnThisSegment) == this) { + closeRootLocks(); + } else { + closeNestedLocks(); + } + localLockState = null; + rootContextOnThisSegment = null; + } + + public void clearSegment() { + CompiledMapIterationContext.this.innerWriteLock.lock(); + CompiledMapIterationContext.this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); + } + + public void clear() { + clearSegment(); + } + public boolean forEachRemoving(Predicate> action) { CompiledMapIterationContext.this.innerUpdateLock.lock(); long size = CompiledMapIterationContext.this.size(); @@ -1999,52 +2037,21 @@ public class CompiledMapIterationContext sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + } - public void writeEntry(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long remove(long posToRemove) { - long entryToRemove = readEntry(posToRemove); - long posToShift = posToRemove; - while (true) { - posToShift = step(posToShift); - long entryToShift = readEntry(posToShift); - if (empty(entryToShift)) - break; - - long insertPos = hlPos(key(entryToShift)); - boolean cond1 = insertPos <= posToRemove; - boolean cond2 = posToRemove <= posToShift; - if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { - writeEntry(posToRemove, entryToRemove, entryToShift); - posToRemove = posToShift; - entryToRemove = entryToShift; - } - } - clearEntry(posToRemove, entryToRemove); - return posToRemove; + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledMapIterationContext.this.free(pos(), entrySizeInChunks()); + CompiledMapIterationContext.this.entries(((CompiledMapIterationContext.this.entries()) - 1L)); + CompiledMapIterationContext.this.incrementModCountGuarded(); } @Override @@ -2062,50 +2069,6 @@ public class CompiledMapIterationContext h = CompiledMapIterationContext.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(CompiledMapIterationContext.this.h().inChunks(entrySize)); + CompiledMapIterationContext.this.initEntryCopying(CompiledMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); + } + + public void putValueDeletedEntry(Value newValue) { + assert CompiledMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = CompiledMapIterationContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = CompiledMapIterationContext.this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (CompiledMapIterationContext.this.freeList().size())) && (CompiledMapIterationContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + CompiledMapIterationContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + CompiledMapIterationContext.this.innerWriteLock.lock(); + CompiledMapIterationContext.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) { + CompiledMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + CompiledMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); + } + protected void relocation(Value newValue, long newSizeOfEverythingBeforeValue) { CompiledMapIterationContext.this.free(pos(), entrySizeInChunks()); long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); @@ -2170,49 +2214,4 @@ public class CompiledMapIterationContext newValue) { - assert CompiledMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledMapIterationContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledMapIterationContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledMapIterationContext.this.freeList().size())) && (CompiledMapIterationContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledMapIterationContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledMapIterationContext.this.innerWriteLock.lock(); - CompiledMapIterationContext.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) { - CompiledMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); - } } 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 8152732eb..4383df885 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java @@ -34,7 +34,6 @@ import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; import net.openhft.chronicle.map.*; -import net.openhft.chronicle.map.impl.stage.map.VanillaChronicleMapHolder; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; import net.openhft.chronicle.map.impl.value.instance.ValueInitableValue; @@ -57,21 +56,21 @@ 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 { public void close() { - CompiledMapQueryContext.this.wrappedValueInstanceValue.closeNext(); - CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); CompiledMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); CompiledMapQueryContext.this.closeAllocatedChunks(); - CompiledMapQueryContext.this.closeUsed(); CompiledMapQueryContext.this.closeInputKey(); - CompiledMapQueryContext.this.closeInputBytes(); - CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); CompiledMapQueryContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledMapQueryContext.this.wrappedValueInstanceValue.closeNext(); + CompiledMapQueryContext.this.closeInputBytes(); + CompiledMapQueryContext.this.closeUsed(); + CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); CompiledMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); - CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); CompiledMapQueryContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); } public void incrementModCountGuarded() { @@ -123,31 +122,31 @@ public class CompiledMapQueryContext)(entryBytesAccessor.access(entryBytes))); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.usingReturnValue = new UsingReturnValue(); this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.inputKeyBytesValue = new InputKeyBytesValue(); this.innerUpdateLock = new UpdateLock(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); 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.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerWriteLock = new WriteLock(); + this.owner = Thread.currentThread(); + this.usingReturnValue = new UsingReturnValue(); this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); - this.entryKey = new EntryKeyBytesValue(); this.entryValue = new EntryValueBytesValue(); + this.innerReadLock = new ReadLock(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.defaultReturnValue = new DefaultReturnValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + 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.entryKey = new EntryKeyBytesValue(); + this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); } public CompiledMapQueryContext(CompiledMapQueryContext c) { @@ -155,34 +154,39 @@ public class CompiledMapQueryContext)(c.m)); - this.innerWriteLock = new WriteLock(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.defaultReturnValue = new DefaultReturnValue(); - this.owner = Thread.currentThread(); - this.innerReadLock = new ReadLock(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - 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.inputKeyBytesValue = new InputKeyBytesValue(); - this.usingReturnValue = new UsingReturnValue(); this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.inputKeyBytesValue = new InputKeyBytesValue(); this.innerUpdateLock = new UpdateLock(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); 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.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.innerWriteLock = new WriteLock(); + this.owner = Thread.currentThread(); + this.usingReturnValue = new UsingReturnValue(); this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); - this.entryKey = new EntryKeyBytesValue(); this.entryValue = new EntryValueBytesValue(); + this.innerReadLock = new ReadLock(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.defaultReturnValue = new DefaultReturnValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + 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.entryKey = new EntryKeyBytesValue(); + this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); } public class InputKeyBytesValue extends AbstractValue { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); + } + @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); @@ -244,26 +248,9 @@ public class CompiledMapQueryContext { - @Override - public T handle() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessHandle; - } - - @Override - public ReadAccess access() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccess; - } - @Override public long size() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); @@ -283,12 +270,6 @@ public class CompiledMapQueryContext access() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytesAccess; + } + + @Override + public T handle() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytesAccessHandle; + } } public class WriteLock implements InterProcessLock { @@ -336,33 +335,35 @@ public class CompiledMapQueryContext { - @Override - public long offset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.valueOffset()); - } - @Override public long size() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); @@ -660,9 +653,9 @@ public class CompiledMapQueryContext { @@ -754,13 +753,13 @@ public class CompiledMapQueryContext { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); + 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.secondInputValueOffset()); + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); } @Override @@ -772,6 +771,11 @@ public class CompiledMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); - } } public class WrappedValueInstanceValue extends CopyingInstanceValue { @@ -836,6 +835,18 @@ public class CompiledMapQueryContext { + @NotNull + @Override + public InterProcessLock writeLock() { + return CompiledMapQueryContext.this.writeLock(); + } + @NotNull @Override public InterProcessLock readLock() { @@ -941,22 +946,10 @@ 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; + return CompiledMapQueryContext.this.valueOffset(); } @Override @@ -997,26 +970,11 @@ 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 long keyOffset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keyOffset(); + } + + @Override + public long valueSize() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.valueSize(); + } } public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledMapQueryContext.this.writeLock(); - } - @NotNull @Override public InterProcessLock readLock() { @@ -1059,6 +1052,18 @@ public class CompiledMapQueryContext entry = CompiledMapQueryContext.this.entry(); - if (entry != null) { - CompiledMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } + return CompiledMapQueryContext.this.valueSize(); + } + + @NotNull + @Override + public Bytes entry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytes; } @Override @@ -1101,6 +1106,12 @@ public class CompiledMapQueryContext 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(); } - - @Override - public long valueSize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.valueSize(); - } - - @Override - public long keySize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.keySize(); - } - - @NotNull - @Override - public Bytes entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytes; - } - - @Override - public boolean valueEqualTo(V value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledMapQueryContext.this.entryValue, CompiledMapQueryContext.this.wrapValueAsValue(value)); - } } public enum SearchState { @@ -1314,6 +1313,11 @@ public class CompiledMapQueryContext implements ValueInitableValue { @@ -1747,6 +1746,50 @@ public class CompiledMapQueryContext context() { + return this; + } + public T contextAtIndexInChain(int index) { return ((T)(contextChain.get(index))); } @@ -1755,6 +1798,34 @@ public class CompiledMapQueryContext m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + private CompiledMapQueryContext _Chaining_createChaining() { return new CompiledMapQueryContext(this); } @@ -1776,76 +1847,21 @@ public class CompiledMapQueryContext context() { - return this; + public void initUsed(boolean used) { + this.used = used; } - public MKI keyMetaInterop(K key) { - return CompiledMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); - } + void closeUsed() { + if (!(this.usedInit())) + return ; - public void closeKeyBytesInteropKeyMetaInteropDependants() { - CompiledMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); - } - - public long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); - } - - public void closeMapEntryStagesEntryBytesAccessOffsetDependants() { - CompiledMapQueryContext.this.closeEntry(); - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - CompiledMapQueryContext.this.closeValue(); - } - - @Override - public VanillaChronicleMap 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() { - CompiledMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - public MVI valueMetaInterop(V value) { - return CompiledMapQueryContext.this.m().metaValueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledMapQueryContext.this.inputValueInstanceValue.closeBuffer(); - CompiledMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledMapQueryContext.this.m().metaDataBytes) + (CompiledMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + used = false; } public Bytes inputBytes = null; @@ -1875,9 +1891,9 @@ public class CompiledMapQueryContext>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - void clearEntry(long pos, long prevEntry) { long entry = prevEntry & (~(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 maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledMapQueryContext.this.closeSearchKey(); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - 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 long key(long entry) { return entry & (keyMask()); } @@ -2294,6 +2250,35 @@ public class CompiledMapQueryContext>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + void forEach(EntryConsumer action) { for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { long entry = readEntry(pos); @@ -2319,60 +2321,8 @@ public class CompiledMapQueryContext= 0; - } - - public void initHashLookupPos() { - CompiledMapQueryContext.this.innerReadLock.lock(); - this.hashLookupPos = CompiledMapQueryContext.this.searchStartPos(); - this.closeHashLookupPosDependants(); - } - - public void initHashLookupPos(long hashLookupPos) { - this.hashLookupPos = hashLookupPos; - this.closeHashLookupPosDependants(); - } - - public long hashLookupPos() { - if (!(this.hashLookupPosInit())) - this.initHashLookupPos(); - - return this.hashLookupPos; - } - - public void closeHashLookupPos() { - if (!(this.hashLookupPosInit())) - return ; - - this.closeHashLookupPosDependants(); - this.hashLookupPos = -1; - } - - public void closeHashLookupPosDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - public void putNewVolatile(long value) { - CompiledMapQueryContext.this.checkValueForPut(value); - long currentEntry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); - CompiledMapQueryContext.this.writeEntryVolatile(CompiledMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); - } - - public void found() { - CompiledMapQueryContext.this.setHashLookupPosGuarded(CompiledMapQueryContext.this.stepBack(CompiledMapQueryContext.this.hashLookupPos())); - } - - public void closeHashLookupSearchFoundDependants() { - CompiledMapQueryContext.this.closeKeySearch(); - } - - public long nextPos() { - long pos = CompiledMapQueryContext.this.hashLookupPos(); - while (true) { - long entry = CompiledMapQueryContext.this.readEntry(pos); - if (CompiledMapQueryContext.this.empty(entry)) { - CompiledMapQueryContext.this.setHashLookupPosGuarded(pos); - return -1L; - } - pos = CompiledMapQueryContext.this.step(pos); - if (pos == (searchStartPos())) - break; - - if ((CompiledMapQueryContext.this.key(entry)) == (searchKey())) { - CompiledMapQueryContext.this.setHashLookupPosGuarded(pos); - return CompiledMapQueryContext.this.value(entry); - } - } - throw new IllegalStateException(("MultiMap is full, that most likely means you " + ("misconfigured entrySize/chunkSize, and entries tend to take less chunks than " + "expected"))); - } - - public void closeHashLookupSearchNextPosDependants() { - CompiledMapQueryContext.this.closeKeySearch(); - } - - public void putVolatile(long value) { - CompiledMapQueryContext.this.checkValueForPut(value); - long currentEntry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); - assert (CompiledMapQueryContext.this.key(currentEntry)) == (searchKey()); - CompiledMapQueryContext.this.writeEntryVolatile(CompiledMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); - } - - void put(long value) { - CompiledMapQueryContext.this.checkValueForPut(value); - CompiledMapQueryContext.this.writeEntry(CompiledMapQueryContext.this.hashLookupPos(), CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()), searchKey(), value); - } - - public boolean checkSlotContainsExpectedKeyAndValue(long value) { - long entry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); - return ((CompiledMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledMapQueryContext.this.value(entry)) == value); - } - - public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - public void remove() { - CompiledMapQueryContext.this.setHashLookupPosGuarded(CompiledMapQueryContext.this.remove(CompiledMapQueryContext.this.hashLookupPos())); - } - - public boolean checkSlotIsEmpty() { - return CompiledMapQueryContext.this.empty(CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos())); - } - 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() { @@ -2747,6 +2616,25 @@ public class CompiledMapQueryContext h = CompiledMapQueryContext.this.h(); if (chunks > (h.maxChunksPerEntry)) @@ -2777,18 +2665,6 @@ public class CompiledMapQueryContext= 0; + } + + public void initHashLookupPos() { + CompiledMapQueryContext.this.innerReadLock.lock(); + this.hashLookupPos = CompiledMapQueryContext.this.searchStartPos(); + this.closeHashLookupPosDependants(); + } + + public void initHashLookupPos(long hashLookupPos) { + this.hashLookupPos = hashLookupPos; + this.closeHashLookupPosDependants(); + } + + public long hashLookupPos() { + if (!(this.hashLookupPosInit())) + this.initHashLookupPos(); + + return this.hashLookupPos; + } + + public void closeHashLookupPos() { + if (!(this.hashLookupPosInit())) + return ; + + this.closeHashLookupPosDependants(); + this.hashLookupPos = -1; + } + + public void closeHashLookupPosDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + public void remove() { + CompiledMapQueryContext.this.setHashLookupPosGuarded(CompiledMapQueryContext.this.remove(CompiledMapQueryContext.this.hashLookupPos())); + } + + public void putNewVolatile(long value) { + CompiledMapQueryContext.this.checkValueForPut(value); + long currentEntry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); + CompiledMapQueryContext.this.writeEntryVolatile(CompiledMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); + } + + public long nextPos() { + long pos = CompiledMapQueryContext.this.hashLookupPos(); + while (true) { + long entry = CompiledMapQueryContext.this.readEntry(pos); + if (CompiledMapQueryContext.this.empty(entry)) { + CompiledMapQueryContext.this.setHashLookupPosGuarded(pos); + return -1L; + } + pos = CompiledMapQueryContext.this.step(pos); + if (pos == (searchStartPos())) + break; + + if ((CompiledMapQueryContext.this.key(entry)) == (searchKey())) { + CompiledMapQueryContext.this.setHashLookupPosGuarded(pos); + return CompiledMapQueryContext.this.value(entry); + } + } + throw new IllegalStateException(("MultiMap is full, that most likely means you " + ("misconfigured entrySize/chunkSize, and entries tend to take less chunks than " + "expected"))); + } + + public void closeHashLookupSearchNextPosDependants() { + CompiledMapQueryContext.this.closeKeySearch(); + } + + public void putVolatile(long value) { + CompiledMapQueryContext.this.checkValueForPut(value); + long currentEntry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); + assert (CompiledMapQueryContext.this.key(currentEntry)) == (searchKey()); + CompiledMapQueryContext.this.writeEntryVolatile(CompiledMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); + } + + public boolean checkSlotContainsExpectedKeyAndValue(long value) { + long entry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); + return ((CompiledMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledMapQueryContext.this.value(entry)) == value); + } + + public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { + CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public boolean checkSlotIsEmpty() { + return CompiledMapQueryContext.this.empty(CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos())); + } + + public void found() { + CompiledMapQueryContext.this.setHashLookupPosGuarded(CompiledMapQueryContext.this.stepBack(CompiledMapQueryContext.this.hashLookupPos())); + } + + public void closeHashLookupSearchFoundDependants() { + CompiledMapQueryContext.this.closeKeySearch(); + } + + void put(long value) { + CompiledMapQueryContext.this.checkValueForPut(value); + CompiledMapQueryContext.this.writeEntry(CompiledMapQueryContext.this.hashLookupPos(), CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()), searchKey(), value); + } + boolean keyEquals() { return ((inputKey().size()) == (CompiledMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledMapQueryContext.this.entryBytesAccess)), CompiledMapQueryContext.this.entryBytesAccessHandle, CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()))); } @@ -3072,22 +3088,6 @@ public class CompiledMapQueryContext absentKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - @NotNull @Override public InterProcessLock writeLock() { @@ -3143,37 +3152,11 @@ public class CompiledMapQueryContext value() { + public Value defaultValue() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryValue; - } - - @Nullable - @Override - public MapAbsentEntry absentEntry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : this; - } - - @Override - public Value defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + return wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); } @Override @@ -3183,31 +3166,6 @@ public class CompiledMapQueryContext entry) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public MapEntry entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; - } - - public Value queriedKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.innerReadLock; - } - @Override public R replaceValue(@NotNull MapEntry entry, Value newValue) { @@ -3224,13 +3182,6 @@ public class CompiledMapQueryContext key() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryKey; - } - @NotNull @Override public InterProcessLock updateLock() { @@ -3240,9 +3191,67 @@ public class CompiledMapQueryContext defaultValue() { + public Value value() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); + return CompiledMapQueryContext.this.entryValue; + } + + @Override + public Value defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.innerReadLock; + } + + @NotNull + @Override + public Value key() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryKey; + } + + public Value queriedKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + + @Override + public MapEntry entry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? this : null; + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.m().entryOperations.remove(entry); + } + + private void putPrefix() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + boolean underUpdatedLockIsHeld = !(CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + if (underUpdatedLockIsHeld) + CompiledMapQueryContext.this.innerUpdateLock.lock(); + + boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledMapQueryContext.this.concurrentSameThreadContexts()); + if (((CompiledMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) + CompiledMapQueryContext.this.closeHashLookupPos(); + + } + + @Nullable + @Override + public MapAbsentEntry absentEntry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? null : this; } @Override @@ -3259,21 +3268,11 @@ public class CompiledMapQueryContext absentKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); } public int allocatedChunks = 0; @@ -3298,18 +3297,6 @@ public class CompiledMapQueryContext value) { + assert searchStateAbsent(); + long entrySize = CompiledMapQueryContext.this.entrySize(inputKey().size(), value.size()); + CompiledMapQueryContext.this.initEntryAndKey(entrySize); + CompiledMapQueryContext.this.initValue(value); + CompiledMapQueryContext.this.freeExtraAllocatedChunks(); + CompiledMapQueryContext.this.putNewVolatile(CompiledMapQueryContext.this.pos()); + } + + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { + initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); + CompiledMapQueryContext.this.initEntryCopying(CompiledMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); + } + protected void relocation(Value newValue, long newSizeOfEverythingBeforeValue) { CompiledMapQueryContext.this.free(pos(), entrySizeInChunks()); long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); @@ -3377,15 +3385,6 @@ public class CompiledMapQueryContext value) { - assert searchStateAbsent(); - long entrySize = CompiledMapQueryContext.this.entrySize(inputKey().size(), value.size()); - CompiledMapQueryContext.this.initEntryAndKey(entrySize); - CompiledMapQueryContext.this.initValue(value); - CompiledMapQueryContext.this.freeExtraAllocatedChunks(); - CompiledMapQueryContext.this.putNewVolatile(CompiledMapQueryContext.this.pos()); - } - public void putValueDeletedEntry(Value newValue) { assert CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; 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 1f1361374..b76f02fa2 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java @@ -27,7 +27,6 @@ import net.openhft.chronicle.map.MapEntry; import net.openhft.chronicle.map.MapKeyContext; import net.openhft.chronicle.map.ReplicatedChronicleMap; import net.openhft.chronicle.map.VanillaChronicleMap; -import net.openhft.chronicle.map.impl.stage.map.ReplicatedChronicleMapHolder; import net.openhft.chronicle.map.replication.MapReplicableEntry; import net.openhft.lang.Maths; import net.openhft.lang.MemoryUnit; @@ -48,19 +47,19 @@ import java.util.function.Predicate; public class CompiledReplicatedMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , MapContext , MapEntry , IterationContextInterface , ReplicatedChronicleMapHolder , MapReplicableEntry { public void close() { - CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); - CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeValue(); - CompiledReplicatedMapIterationContext.this.closeSegmentHashLookup(); - CompiledReplicatedMapIterationContext.this.closeUsed(); - CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); - CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); CompiledReplicatedMapIterationContext.this.closeReplicationUpdate(); - CompiledReplicatedMapIterationContext.this.closeTheSegmentIndex(); + CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); + CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeValue(); + CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeNext(); + CompiledReplicatedMapIterationContext.this.closeTheSegmentIndex(); + CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); + CompiledReplicatedMapIterationContext.this.closeUsed(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); + CompiledReplicatedMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); CompiledReplicatedMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); } public void incrementModCountGuarded() { @@ -70,6 +69,11 @@ public class CompiledReplicatedMapIterationContext m) { @@ -93,6 +98,23 @@ public class CompiledReplicatedMapIterationContext)(entryBytesAccessor.access(entryBytes))); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryValue = new EntryValueBytesValue(); + this.innerUpdateLock = new UpdateLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryKey = new EntryKeyBytesValue(); + this.innerWriteLock = new WriteLock(); } public CompiledReplicatedMapIterationContext(CompiledReplicatedMapIterationContext c) { @@ -100,9 +122,32 @@ public class CompiledReplicatedMapIterationContext)(c.m)); + this.owner = Thread.currentThread(); + 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.innerReadLock = new ReadLock(); + 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.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryValue = new EntryValueBytesValue(); + this.innerUpdateLock = new UpdateLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryKey = new EntryKeyBytesValue(); + this.innerWriteLock = new WriteLock(); } public class EntryKeyBytesValue extends AbstractValue { + @Override + public T handle() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; + } + @Override public ReadAccess access() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); @@ -119,6 +164,12 @@ public class CompiledReplicatedMapIterationContext { + @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 offset() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); @@ -505,12 +557,6 @@ public class CompiledReplicatedMapIterationContext access() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccess; - } - @Override public V get() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); @@ -522,12 +568,6 @@ public class CompiledReplicatedMapIterationContext { @@ -565,6 +605,7 @@ public class CompiledReplicatedMapIterationContext { - @NotNull - private UnsupportedOperationException unsupportedLocks() { - return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); + @Override + public void close() { + throw new UnsupportedOperationException("close() is not supported during iteration"); } @NotNull @Override - public InterProcessLock writeLock() { - throw unsupportedLocks(); + public K key() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.key().get(); + } + + @Override + public boolean containsKey() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return true; + } + + @Override + public boolean valueEqualTo(V value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return Value.bytesEquivalent(CompiledReplicatedMapIterationContext.this.entryValue, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(value)); + } + + @Override + public V getUsing(V usingValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.value().getUsing(usingValue); + } + + @Override + public V get() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.value().get(); + } + + @Override + public boolean put(V newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + CompiledReplicatedMapIterationContext.this.replaceValue(CompiledReplicatedMapIterationContext.this, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(newValue)); + return true; + } + + @Override + public boolean remove() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + CompiledReplicatedMapIterationContext.this.remove(CompiledReplicatedMapIterationContext.this); + return true; + } + + @NotNull + @Override + public Bytes entry() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytes; + } + + @NotNull + private UnsupportedOperationException unsupportedLocks() { + return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); } @NotNull @@ -661,16 +753,10 @@ public class CompiledReplicatedMapIterationContext value) { @@ -751,6 +792,10 @@ public class CompiledReplicatedMapIterationContext value) { entryBytes.position(valueSizeOffset); valueSize = value.size(); @@ -872,7 +928,7 @@ public class CompiledReplicatedMapIterationContext contextChain; - public final UpdateLock innerUpdateLock = new UpdateLock(); + public final UpdateLock innerUpdateLock; public UpdateLock innerUpdateLock() { return this.innerUpdateLock; @@ -941,31 +997,31 @@ public class CompiledReplicatedMapIterationContext m; - public final VI valueInterop = CompiledReplicatedMapIterationContext.this.m().valueInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalValueInterop); + public final VI valueInterop; public VI valueInterop() { return this.valueInterop; } - final Full entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + final Full entryBytesAccessor; public Full entryBytesAccessor() { return this.entryBytesAccessor; } @SuppressWarnings(value = "unchecked") - public final T entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + public final T entryBytesAccessHandle; public T entryBytesAccessHandle() { return this.entryBytesAccessHandle; } - public final BytesReader valueReader = CompiledReplicatedMapIterationContext.this.m().valueReaderProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalValueReader); + public final BytesReader valueReader; public BytesReader valueReader() { return this.valueReader; } - public final KI keyInterop = CompiledReplicatedMapIterationContext.this.h().keyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalKeyInterop); + public final KI keyInterop; public KI keyInterop() { return this.keyInterop; } @SuppressWarnings(value = "unchecked") - public final Access entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + public final Access entryBytesAccess; public Access entryBytesAccess() { return this.entryBytesAccess; } - public final BytesReader keyReader = CompiledReplicatedMapIterationContext.this.h().keyReaderProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalKeyReader); + public final BytesReader keyReader; public BytesReader keyReader() { return this.keyReader; } - public boolean entryIsPresent() { - return true; - } - - public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { - if (CompiledReplicatedMapIterationContext.this.m().constantlySizedEntry) { - return CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); - } else if (CompiledReplicatedMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { - return (sizeOfEverythingBeforeValue + (CompiledReplicatedMapIterationContext.this.m().worstAlignment)) + valueSize; - } else { - return (CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; - } - } - - @NotNull - @Override - public MapContext context() { - return CompiledReplicatedMapIterationContext.this; - } - - private CompiledReplicatedMapIterationContext _Chaining_createChaining() { - return new CompiledReplicatedMapIterationContext(this); - } - - public CompiledReplicatedMapIterationContext createChaining() { - return new CompiledReplicatedMapIterationContext(this); - } - - public T getContext() { - for (CompiledReplicatedMapIterationContext context : contextChain) { - if (!(context.used())) { - return ((T)(context)); - } - } - int maxNestedContexts = 1 << 16; - if ((contextChain.size()) > maxNestedContexts) { - throw new IllegalStateException((((((("More than " + maxNestedContexts) + " nested ChronicleHash contexts are not supported. Very probable that ") + "you simply forgot to close context somewhere (recommended to use ") + "try-with-resources statement). ") + "Otherwise this is a bug, please report with this ") + "stack trace on https://github.com/OpenHFT/Chronicle-Map/issues")); - } - return ((T)(createChaining())); - } - - public T contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public void incrementSegmentEntriesIfNeeded() { - } - - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); - } - @Override public ReplicatedChronicleMap m() { return m; @@ -1083,12 +1083,10 @@ public class CompiledReplicatedMapIterationContext context() { + return CompiledReplicatedMapIterationContext.this; } public void checkAccessingFromOwnerThread() { @@ -1101,6 +1099,164 @@ public class CompiledReplicatedMapIterationContextT getContext() { + for (CompiledReplicatedMapIterationContext context : contextChain) { + if (!(context.usedInit())) { + return ((T)(context)); + } + } + int maxNestedContexts = 1 << 16; + if ((contextChain.size()) > maxNestedContexts) { + throw new IllegalStateException((((((("More than " + maxNestedContexts) + " nested ChronicleHash contexts are not supported. Very probable that ") + "you simply forgot to close context somewhere (recommended to use ") + "try-with-resources statement). ") + "Otherwise this is a bug, please report with this ") + "stack trace on https://github.com/OpenHFT/Chronicle-Map/issues")); + } + return ((T)(createChaining())); + } + + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (CompiledReplicatedMapIterationContext.this.m().constantlySizedEntry) { + return CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (CompiledReplicatedMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (CompiledReplicatedMapIterationContext.this.m().worstAlignment)) + valueSize; + } else { + return (CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; + } + } + + public void incrementSegmentEntriesIfNeeded() { + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + public void checkEntryNotRemovedOnThisIteration() { + if (entryRemovedOnThisIterationInit()) + throw new IllegalStateException("Entry was already removed on this iteration"); + + } + + public void closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants() { + CompiledReplicatedMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { + CompiledReplicatedMapIterationContext.this.checkAccessingFromOwnerThread(); + } + + public void checkOnEachPublicOperation() { + _CheckOnEachPublicOperation_checkOnEachPublicOperation(); + CompiledReplicatedMapIterationContext.this.checkEntryNotRemovedOnThisIteration(); + } + + public void closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { + CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); + CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); + } + + @Override + public Value defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); + } + + @Override + public Value wrapValueAsValue(V value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + WrappedValueInstanceValue wrapped = CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public InterProcessLock updateLock() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.innerUpdateLock; + } + + @NotNull + @Override + public Value key() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryKey; + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Value newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.innerReadLock; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Value value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + } + + @NotNull + @Override + public Value value() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryValue; + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.innerWriteLock; + } + + public boolean entryIsPresent() { + return true; + } + + public long entryBytesAccessOffset(long offset) { + return entryBytesAccessor.offset(entryBytes, offset); + } + + public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { + CompiledReplicatedMapIterationContext.this.closeEntry(); + } + private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { return (((CompiledReplicatedMapIterationContext.this.m().metaDataBytes) + (CompiledReplicatedMapIterationContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); } @@ -1114,12 +1270,42 @@ public class CompiledReplicatedMapIterationContext= 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 stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + 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 writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; + } + + public long 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(); + } + + 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.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 = CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes); + keyOffset = entryBytes.position(); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntry(long pos, Value key) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = key.size(); + CompiledReplicatedMapIterationContext.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() { + CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicationUpdateDropChangeDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicationUpdateUpdateChangeDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); + } + + public void dropChange() { + CompiledReplicatedMapIterationContext.this.m().dropChange(CompiledReplicatedMapIterationContext.this.segmentIndex(), CompiledReplicatedMapIterationContext.this.pos()); + } + + public void closeReplicationUpdateDropChangeDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicationUpdateUpdateChangeDependants(); + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicationState(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + private long _MapEntryStages_countValueSizeOffset() { + return keyEnd(); + } + + long countValueSizeOffset() { + return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { + CompiledReplicatedMapIterationContext.this.closeValue(); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + } + + void initReplicationState(long timestamp, byte identifier) { + replicationBytesOffset = keyEnd(); + entryBytes.position(replicationBytesOffset); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.replicationBytesOffset = -1; + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); + } + + @Override + public byte originIdentifier() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return identifier(); } long segmentHeaderAddress; @@ -1185,8 +1806,8 @@ 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 free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + int totalReadLockCount; int totalUpdateLockCount; @@ -1303,272 +1973,104 @@ public class CompiledReplicatedMapIterationContext 0; + public void initAllocatedChunks(int allocatedChunks) { + this.allocatedChunks = allocatedChunks; } - void initSegment() { - VanillaChronicleHash h = CompiledReplicatedMapIterationContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - CompiledReplicatedMapIterationContext.this.initSegmentHashLookup(((h.ms.address()) + hashLookupOffset), h.segmentHashLookupCapacity, h.segmentHashLookupEntrySize, h.segmentHashLookupKeyBits, h.segmentHashLookupValueBits); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); + public int allocatedChunks() { + assert this.allocatedChunksInit() : "AllocatedChunks should be init"; + return this.allocatedChunks; } - 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())) + public void closeAllocatedChunks() { + if (!(this.allocatedChunksInit())) return ; - entrySpaceOffset = 0; - this.closeSegmentDependants(); + this.allocatedChunks = 0; } - public void closeSegmentDependants() { - CompiledReplicatedMapIterationContext.this.closeEntry(); + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { + initAllocatedChunks(CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize)); + CompiledReplicatedMapIterationContext.this.initEntryCopying(CompiledReplicatedMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); } - public long pos = -1; + public long hashLookupPos = -1; - public long keySizeOffset; - - public long keySize; - - public long keyOffset; - - public boolean entryInit() { - return (this.pos) >= 0; + public boolean hashLookupPosInit() { + return (this.hashLookupPos) >= 0; } - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); + public void initHashLookupPos(long hashLookupPos) { + this.hashLookupPos = hashLookupPos; } - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); + public long hashLookupPos() { + assert this.hashLookupPosInit() : "HashLookupPos should be init"; + return this.hashLookupPos; } - 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())) + public void closeHashLookupPos() { + if (!(this.hashLookupPosInit())) return ; - this.pos = -1; - this.closeEntryDependants(); + this.hashLookupPos = -1; } - public void closeEntryDependants() { - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicationUpdateDropChangeDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicationUpdateUpdateChangeDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - } + public boolean forEachRemoving(Predicate> action) { + CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); + long size = CompiledReplicatedMapIterationContext.this.size(); + if (size == 0) + return true; - public long keyEnd() { - return (keyOffset()) + (keySize()); - } + try { + boolean interrupted = false; + long startPos = 0L; + while (!(CompiledReplicatedMapIterationContext.this.empty(CompiledReplicatedMapIterationContext.this.readEntry(startPos)))) { + startPos = CompiledReplicatedMapIterationContext.this.step(startPos); + } + CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); + do { + CompiledReplicatedMapIterationContext.this.setHashLookupPosGuarded(CompiledReplicatedMapIterationContext.this.step(CompiledReplicatedMapIterationContext.this.hashLookupPos())); + long entry = CompiledReplicatedMapIterationContext.this.readEntry(CompiledReplicatedMapIterationContext.this.hashLookupPos()); + if (!(CompiledReplicatedMapIterationContext.this.empty(entry))) { + CompiledReplicatedMapIterationContext.this.initEntry(CompiledReplicatedMapIterationContext.this.value(entry)); + if (entryIsPresent()) { + initEntryRemovedOnThisIteration(false); + if (!(action.test(((MapEntry)(this))))) { + interrupted = true; + break; + } else { + if ((--size) == 0) + break; - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicationState(); - } - - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeValue(); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - } - - void initReplicationState(long timestamp, byte identifier) { - replicationBytesOffset = keyEnd(); - entryBytes.position(replicationBytesOffset); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.replicationBytesOffset = -1; - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - 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); - } + } while ((CompiledReplicatedMapIterationContext.this.hashLookupPos()) != startPos ); + return !interrupted; + } finally { + CompiledReplicatedMapIterationContext.this.innerReadLock.unlock(); + initEntryRemovedOnThisIteration(false); } - return ret; - } - - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - - } - - public void dropChange() { - CompiledReplicatedMapIterationContext.this.m().dropChange(CompiledReplicatedMapIterationContext.this.segmentIndex(), CompiledReplicatedMapIterationContext.this.pos()); - } - - public void closeReplicationUpdateDropChangeDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicationUpdateUpdateChangeDependants(); } public long newTimestamp; @@ -1618,40 +2120,19 @@ public class CompiledReplicatedMapIterationContext newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + private long _HashEntryStages_entryEnd() { return keyEnd(); } @@ -1797,38 +2282,6 @@ public class CompiledReplicatedMapIterationContext newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - public int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; - } - - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; - } - - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) - return ; - - this.allocatedChunks = 0; - } - public final void freeExtraAllocatedChunks() { if (((!(CompiledReplicatedMapIterationContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapIterationContext.this.allocatedChunks()))) { CompiledReplicatedMapIterationContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapIterationContext.this.allocatedChunks()) - (entrySizeInChunks()))); @@ -1837,336 +2290,6 @@ public class CompiledReplicatedMapIterationContext= 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 = false; - - public boolean usedInit() { - return (this.used) != false; - } - - public void initUsed(boolean used) { - this.used = used; - } - - public boolean used() { - assert this.usedInit() : "Used should be init"; - return this.used; - } - - public void closeUsed() { - if (!(this.usedInit())) - return ; - - this.used = false; - } - - 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 address, long capacity, int entrySize, int keyBits, int valueBits) { - this.address = address; - this.capacityMask = capacity - 1L; - this.hashLookupEntrySize = entrySize; - this.capacityMask2 = (capacityMask) * entrySize; - this.keyBits = keyBits; - this.keyMask = CompiledReplicatedMapIterationContext.mask(keyBits); - this.valueMask = CompiledReplicatedMapIterationContext.mask(valueBits); - this.entryMask = CompiledReplicatedMapIterationContext.mask((keyBits + valueBits)); - } - - public int hashLookupEntrySize() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.hashLookupEntrySize; - } - - public int keyBits() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.keyBits; - } - - public long address() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.address; - } - - public long capacityMask() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.capacityMask; - } - - public long capacityMask2() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.capacityMask2; - } - - public long entryMask() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.entryMask; - } - - public long keyMask() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.keyMask; - } - - public long valueMask() { - assert this.segmentHashLookupInit() : "SegmentHashLookup should be init"; - return this.valueMask; - } - - public void closeSegmentHashLookup() { - if (!(this.segmentHashLookupInit())) - return ; - - this.address = -1; - } - - 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 long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - 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); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void clear() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public long pos(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 boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public boolean forEachRemoving(Predicate> action) { - CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); - long size = CompiledReplicatedMapIterationContext.this.size(); - if (size == 0) - return true; - - try { - boolean interrupted = false; - long startPos = 0L; - while (!(CompiledReplicatedMapIterationContext.this.empty(CompiledReplicatedMapIterationContext.this.readEntry(startPos)))) { - startPos = CompiledReplicatedMapIterationContext.this.step(startPos); - } - CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); - do { - CompiledReplicatedMapIterationContext.this.initHashLookupPos(CompiledReplicatedMapIterationContext.this.step(CompiledReplicatedMapIterationContext.this.hashLookupPos())); - long entry = CompiledReplicatedMapIterationContext.this.readEntry(CompiledReplicatedMapIterationContext.this.hashLookupPos()); - if (!(CompiledReplicatedMapIterationContext.this.empty(entry))) { - CompiledReplicatedMapIterationContext.this.initEntry(CompiledReplicatedMapIterationContext.this.value(entry)); - if (entryIsPresent()) { - initEntryRemovedOnThisIteration(false); - if (!(action.test(((MapEntry)(this))))) { - interrupted = true; - break; - } else { - if ((--size) == 0) - break; - - } - } - } - } while ((CompiledReplicatedMapIterationContext.this.hashLookupPos()) != startPos ); - return !interrupted; - } finally { - CompiledReplicatedMapIterationContext.this.innerReadLock.unlock(); - initEntryRemovedOnThisIteration(false); - } - } - - public long key(long entry) { - return entry & (keyMask()); - } - - 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 = pos(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(); - } - - 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); - } - - public void writeValueAndPutPos(Value value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapIterationContext.this.putValueVolatile(hashLookupPos(), pos()); - } - - private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { - CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); - writeValueAndPutPos(newValue); - } - - protected void relocation(Value newValue, long newSizeOfEverythingBeforeValue) { - CompiledReplicatedMapIterationContext.this.dropChange(); - _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); - } - - public void innerDefaultReplaceValue(Value 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) { - initValueAgain(newValue); - } else { - writeValueGuarded(newValue); - } - CompiledReplicatedMapIterationContext.this.putValueVolatile(hashLookupPos(), pos()); - } - private void _MapEntryStages_putValueDeletedEntry(Value newValue) { assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; @@ -2209,105 +2332,35 @@ public class CompiledReplicatedMapIterationContext newValue) { throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); } - public boolean entryRemovedOnThisIteration = false; - - public boolean entryRemovedOnThisIterationInit() { - return (this.entryRemovedOnThisIteration) != false; + public void writeValueAndPutPos(Value value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); } - private void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { - this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; - this.closeEntryRemovedOnThisIterationDependants(); + private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { + CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); } - public boolean entryRemovedOnThisIteration() { - assert this.entryRemovedOnThisIterationInit() : "EntryRemovedOnThisIteration should be init"; - return this.entryRemovedOnThisIteration; + protected void relocation(Value newValue, long newSizeOfEverythingBeforeValue) { + CompiledReplicatedMapIterationContext.this.dropChange(); + _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); } - public void closeEntryRemovedOnThisIteration() { - if (!(this.entryRemovedOnThisIterationInit())) - return ; - - this.entryRemovedOnThisIteration = false; - this.closeEntryRemovedOnThisIterationDependants(); - } - - public void closeEntryRemovedOnThisIterationDependants() { - CompiledReplicatedMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); - } - - public void checkEntryNotRemovedOnThisIteration() { - if (entryRemovedOnThisIteration()) - throw new IllegalStateException("Entry was already removed on this iteration"); - - } - - public void closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants() { - CompiledReplicatedMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { - CompiledReplicatedMapIterationContext.this.checkAccessingFromOwnerThread(); - } - - public void checkOnEachPublicOperation() { - _CheckOnEachPublicOperation_checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.checkEntryNotRemovedOnThisIteration(); - } - - public void closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { - CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Value newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - @Override - public long originTimestamp() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - @Override - public Value wrapValueAsValue(V value) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerWriteLock; - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerUpdateLock; + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapIterationContext.this.entries(((CompiledReplicatedMapIterationContext.this.entries()) - 1L)); + CompiledReplicatedMapIterationContext.this.incrementModCountGuarded(); } @Override @@ -2317,7 +2370,7 @@ public class CompiledReplicatedMapIterationContext key() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryKey; - } - - @Override - public Value defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @NotNull - @Override - public Value value() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryValue; - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return newIdentifier(); - } - - @Override - public long remoteTimestamp() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return newTimestamp(); - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.remove(entry); + public void innerDefaultReplaceValue(Value 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) { + initValueAgain(newValue); + } else { + writeValueGuarded(newValue); + } + CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); } @Override @@ -2383,9 +2423,35 @@ public class CompiledReplicatedMapIterationContext absentEntry, Value value) { + public long remoteTimestamp() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + return newTimestamp(); + } + + private boolean updatedReplicationState = false; + + public boolean updatedReplicationStateInit() { + return (this.updatedReplicationState) != false; + } + + public void initUpdatedReplicationState() { + initReplicationState(CompiledReplicatedMapIterationContext.this.newTimestamp(), CompiledReplicatedMapIterationContext.this.newIdentifier()); + updatedReplicationState = true; + } + + public void closeUpdatedReplicationState() { + if (!(this.updatedReplicationStateInit())) + return ; + + this.updatedReplicationState = false; + } + + private boolean testTimeStampInSensibleRange() { + if ((CompiledReplicatedMapIterationContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (CompiledReplicatedMapIterationContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapIterationContext.this.newTimestamp()); + } + return true; } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java index 669cb2980..c300f0196 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java @@ -19,7 +19,6 @@ import net.openhft.chronicle.hash.replication.TimeProvider; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; import net.openhft.chronicle.map.*; -import net.openhft.chronicle.map.impl.stage.map.ReplicatedChronicleMapHolder; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; import net.openhft.chronicle.map.impl.value.instance.ValueInitableValue; @@ -45,33 +44,25 @@ import java.util.List; import java.util.concurrent.TimeUnit; public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , ReplicatedChronicleMapHolder , MapRemoteQueryContext , MapReplicableEntry { - public long nextPosGuarded() { - if (!(this.doSearchInit())) - this.initDoSearch(); - - return nextPos(); - } - public void close() { - CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledReplicatedMapQueryContext.this.closeUsed(); CompiledReplicatedMapQueryContext.this.closeInputKey(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); - CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); - CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledReplicatedMapQueryContext.this.closeUsed(); + CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); CompiledReplicatedMapQueryContext.this.closeInputBytes(); - CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); - CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.closeUpdateLockForbiddenUpgradeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); CompiledReplicatedMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); + CompiledReplicatedMapQueryContext.this.innerUpdateLock.closeUpdateLockForbiddenUpgradeDependants(); + CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); } public void incrementModCountGuarded() { @@ -81,6 +72,13 @@ public class CompiledReplicatedMapQueryContext)(entryBytesAccessor.access(entryBytes))); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); this.entryKey = new EntryKeyBytesValue(); + this.usingReturnValue = new UsingReturnValue(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesValue(); + this.dummyValue = new DummyValueZeroValue(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.owner = Thread.currentThread(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.entryValue = new EntryValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.dummyValue = new DummyValueZeroValue(); - this.innerReadLock = new ReadLock(); - this.usingReturnValue = new UsingReturnValue(); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); - this.innerWriteLock = new WriteLock(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerUpdateLock = new UpdateLock(); + this.owner = Thread.currentThread(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerWriteLock = new WriteLock(); } public CompiledReplicatedMapQueryContext(CompiledReplicatedMapQueryContext c) { @@ -151,37 +149,47 @@ public class CompiledReplicatedMapQueryContext)(c.m)); - this.innerUpdateLock = new UpdateLock(); + this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerReadLock = new ReadLock(); + this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.inputValueInstanceValue = new InputValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesValue(); this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); this.entryKey = new EntryKeyBytesValue(); + this.usingReturnValue = new UsingReturnValue(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesValue(); + this.dummyValue = new DummyValueZeroValue(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.owner = Thread.currentThread(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.entryValue = new EntryValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.dummyValue = new DummyValueZeroValue(); - this.innerReadLock = new ReadLock(); - this.usingReturnValue = new UsingReturnValue(); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); - this.innerWriteLock = new WriteLock(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.innerUpdateLock = new UpdateLock(); + this.owner = Thread.currentThread(); + this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.innerWriteLock = new WriteLock(); } public class InputKeyBytesValue extends AbstractValue { + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + @Override public long size() { return CompiledReplicatedMapQueryContext.this.inputKeySize(); @@ -238,25 +246,9 @@ public class CompiledReplicatedMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); - } } public class EntryKeyBytesValue extends AbstractValue { - @Override - public long offset() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()); - } - @Override public T handle() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -326,6 +318,12 @@ public class CompiledReplicatedMapQueryContext { @Override - public long offset() { + public ReadAccess access() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.valueOffset()); + return CompiledReplicatedMapQueryContext.this.entryBytesAccess; } @Override @@ -626,9 +625,9 @@ public class CompiledReplicatedMapQueryContext access() { + public long offset() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccess; + return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.valueOffset()); } @Override @@ -650,12 +649,6 @@ public class CompiledReplicatedMapQueryContext { @@ -710,11 +709,6 @@ public class CompiledReplicatedMapQueryContext { @@ -861,6 +860,7 @@ public class CompiledReplicatedMapQueryContext { - @Override - public void close() { - CompiledReplicatedMapQueryContext.this.close(); - } - - @Override - public V get() { - return CompiledReplicatedMapQueryContext.this.value().get(); - } - @NotNull @Override public InterProcessLock readLock() { @@ -956,11 +946,6 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } - } - - @Override - public boolean containsKey() { - return (CompiledReplicatedMapQueryContext.this.entry()) != null; - } - - @Override - public long valueSize() { + public K key() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.valueSize(); + return CompiledReplicatedMapQueryContext.this.queriedKey().get(); } @Override @@ -1007,6 +977,12 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); if (entry != null) { CompiledReplicatedMapQueryContext.this.replaceValue(entry, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(newValue)); @@ -1032,75 +1003,84 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } + } + + @Override + public long valueSize() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueSize(); + } + + @Override + public long valueOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueOffset(); } } public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledReplicatedMapQueryContext.this.writeLock(); - } - @NotNull @Override public InterProcessLock readLock() { return CompiledReplicatedMapQueryContext.this.readLock(); } - @Override - public V get() { - return CompiledReplicatedMapQueryContext.this.value().get(); - } - - @Override - public V getUsing(V usingValue) { - return CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue); - } - @NotNull @Override public InterProcessLock updateLock() { return CompiledReplicatedMapQueryContext.this.updateLock(); } + @NotNull + @Override + public InterProcessLock writeLock() { + return CompiledReplicatedMapQueryContext.this.writeLock(); + } + + @Override + public long keyOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.keyOffset(); + } + @Override public boolean valueEqualTo(V value) { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); return Value.bytesEquivalent(CompiledReplicatedMapQueryContext.this.entryValue, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(value)); } + @NotNull @Override - public long valueOffset() { + public K key() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.valueOffset(); - } - - @Override - public boolean containsKey() { - return (CompiledReplicatedMapQueryContext.this.entry()) != null; - } - - @Override - public boolean remove() { - MapEntry entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); - return true; - } else { - return false; - } - } - - @Override - public long keySize() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.keySize(); + return CompiledReplicatedMapQueryContext.this.queriedKey().get(); } @NotNull @@ -1110,9 +1090,29 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } + } + @Override public boolean put(V newValue) { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + updateLock().lock(); MapEntry entry = CompiledReplicatedMapQueryContext.this.entry(); if (entry != null) { CompiledReplicatedMapQueryContext.this.replaceValue(entry, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(newValue)); @@ -1124,44 +1124,50 @@ 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 offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).offset(CompiledReplicatedMapQueryContext.this.replicatedInputBytes(), CompiledReplicatedMapQueryContext.this.riKeyOffset()); + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } @Override @@ -1215,17 +1221,22 @@ public class CompiledReplicatedMapQueryContext { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } @Override @@ -1288,13 +1299,8 @@ public class CompiledReplicatedMapQueryContext { @Override - public Void handle() { - return null; - } - - @Override - public V get() { - throw new UnsupportedOperationException(); + public long offset() { + return 0; } @Override @@ -1303,44 +1309,29 @@ public class CompiledReplicatedMapQueryContext access() { - return ReadAccess.zeros(); - } - - @Override - public long offset() { - return 0; + public Void handle() { + return null; } @Override public V getUsing(V usingInstance) { throw new UnsupportedOperationException(); } + + @Override + public V get() { + throw new UnsupportedOperationException(); + } + + @Override + public ReadAccess access() { + return ReadAccess.zeros(); + } } public enum SearchState { PRESENT, DELETED, ABSENT; } - public long nextPos() { - long pos = CompiledReplicatedMapQueryContext.this.hashLookupPos(); - while (true) { - long entry = CompiledReplicatedMapQueryContext.this.readEntry(pos); - if (CompiledReplicatedMapQueryContext.this.empty(entry)) { - CompiledReplicatedMapQueryContext.this.initHashLookupPos(pos); - return -1L; - } - pos = CompiledReplicatedMapQueryContext.this.step(pos); - if (pos == (searchStartPos())) - break; - - if ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) { - CompiledReplicatedMapQueryContext.this.initHashLookupPos(pos); - return CompiledReplicatedMapQueryContext.this.value(entry); - } - } - throw new IllegalStateException(("MultiMap is full, that most likely means you " + ("misconfigured entrySize/chunkSize, and entries tend to take less chunks than " + "expected"))); - } - private void _MapEntryStages_writeValue(Value value) { value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); } @@ -1349,6 +1340,10 @@ public class CompiledReplicatedMapQueryContext implements ValueInitableValue { @@ -1663,10 +1658,10 @@ public class CompiledReplicatedMapQueryContext context() { - return this; + public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeEntry(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); } public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { @@ -1981,6 +1971,26 @@ 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"); + } + } + + public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { + CompiledReplicatedMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + public T contextAtIndexInChain(int index) { return ((T)(contextChain.get(index))); } @@ -1989,13 +1999,40 @@ public class CompiledReplicatedMapQueryContext context() { + return this; + } + + public MVI valueMetaInterop(V value) { + return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + } + + public MKI keyMetaInterop(K key) { + return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); + } + + public void closeKeyBytesInteropKeyMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); } private CompiledReplicatedMapQueryContext _Chaining_createChaining() { @@ -2019,48 +2056,6 @@ public class CompiledReplicatedMapQueryContext m() { - return m; - } - - @Override - public ChronicleMap map() { - return m(); - } - - public MVI valueMetaInterop(V value) { - return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); - } - - public void checkAccessingFromOwnerThread() { - if ((owner) != (Thread.currentThread())) { - throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); - } - } - - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledReplicatedMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledReplicatedMapQueryContext.this.m().metaDataBytes) + (CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - public Bytes replicatedInputBytes = null; public boolean replicatedInputBytesInit() { @@ -2118,9 +2113,9 @@ public class CompiledReplicatedMapQueryContext inputKey = null; public boolean inputKeyInit() { @@ -2365,538 +2377,11 @@ public class CompiledReplicatedMapQueryContext= 0; - } - - public void initSegmentHashLookup() { - long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); - this.closeSegmentHashLookupDependants(); - } - - public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { - innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); - this.closeSegmentHashLookupDependants(); - } - - public int hashLookupEntrySize() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.hashLookupEntrySize; - } - - public int keyBits() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyBits; - } - - public long address() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.address; - } - - public long capacityMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask; - } - - public long capacityMask2() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask2; - } - - public long entryMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.entryMask; - } - - public long keyMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyMask; - } - - public long valueMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.valueMask; - } - - public void closeSegmentHashLookup() { - if (!(this.segmentHashLookupInit())) - return ; - - this.closeSegmentHashLookupDependants(); - this.address = -1; - } - - public void closeSegmentHashLookupDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); - } - - public long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public void closeHashLookupStepDependants() { - CompiledReplicatedMapQueryContext.this.closeDoSearch(); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeDoSearch(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - 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.closeDoSearch(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); - } - - public void clear() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledReplicatedMapQueryContext.this.closeDoSearch(); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public void closeHashLookupIndexToPosDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupPosDependants(); - } - - public long pos(long key) { - return indexToPos((key & (capacityMask()))); - } - - public void closeHashLookupPosDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); - } - - long searchKey = UNSET_KEY; - - long searchStartPos; - - public boolean searchKeyInit() { - return (this.searchKey) != (UNSET_KEY); - } - - void initSearchKey() { - searchKey = CompiledReplicatedMapQueryContext.this.maskUnsetKey(CompiledReplicatedMapQueryContext.this.h().hashSplitting.segmentHash(CompiledReplicatedMapQueryContext.this.hashOfKey())); - searchStartPos = CompiledReplicatedMapQueryContext.this.pos(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() { - CompiledReplicatedMapQueryContext.this.closeDoSearch(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long remove(long posToRemove) { - long entryToRemove = readEntry(posToRemove); - long posToShift = posToRemove; - while (true) { - posToShift = step(posToShift); - long entryToShift = readEntry(posToShift); - if (empty(entryToShift)) - break; - - long insertPos = pos(key(entryToShift)); - boolean cond1 = insertPos <= posToRemove; - boolean cond2 = posToRemove <= posToShift; - if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { - writeEntry(posToRemove, entryToRemove, entryToShift); - posToRemove = posToShift; - entryToRemove = entryToShift; - } - } - clearEntry(posToRemove, entryToRemove); - return posToRemove; - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledReplicatedMapQueryContext.this.closeDoSearch(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - 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 void writeEntry(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - long entrySpaceOffset = 0; - - MultiStoreBytes freeListBytes = new MultiStoreBytes(); - - public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); - - boolean segmentInit() { - return (entrySpaceOffset) > 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); - } - - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.entrySpaceOffset; - } - - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.freeList; - } - - void closeSegment() { - if (!(this.segmentInit())) - return ; - - this.closeSegmentDependants(); - entrySpaceOffset = 0; - } - - public void closeSegmentDependants() { - CompiledReplicatedMapQueryContext.this.closeEntry(); - } - - public long pos = -1; - - public long keySizeOffset; - - public long keySize; - - public long keyOffset; - - public boolean entryInit() { - return (this.pos) >= 0; - } - - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; - } - - public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keySizeOffset; - } - - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) - return ; - - this.closeEntryDependants(); - this.pos = -1; - } - - public void closeEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - } - - boolean keyEquals() { - return ((inputKey().size()) == (CompiledReplicatedMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledReplicatedMapQueryContext.this.entryBytesAccess)), CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle, CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()))); - } - - public void closeReplicatedMapQueryKeyEqualsDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicationState(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - } - - void initReplicationState(long timestamp, byte identifier) { - replicationBytesOffset = keyEnd(); - entryBytes.position(replicationBytesOffset); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.replicationBytesOffset = -1; - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - 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 _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValue(); - } - - public void dropChange() { - CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); - } - - public void closeReplicationUpdateDropChangeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); } long segmentHeaderAddress; @@ -2950,6 +2435,18 @@ public class CompiledReplicatedMapQueryContext h = CompiledReplicatedMapQueryContext.this.h(); - if (chunks > (h.maxChunksPerEntry)) - throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); - - long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - ret = freeList().setNextNContinuousClearBits(0L, chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - if (chunks == 1) { - throw new IllegalStateException("Segment is full, no free entries found"); - } else { - throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); - } - } - updateNextPosToSearchFrom(ret, chunks); - } else { - if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { - updateNextPosToSearchFrom(ret, chunks); - } - } - return ret; - } - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { @@ -3016,16 +2472,8 @@ public class CompiledReplicatedMapQueryContext= 0; + } + + public void initSegmentHashLookup() { + long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); + this.closeSegmentHashLookupDependants(); + } + + public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { + innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); + this.closeSegmentHashLookupDependants(); + } + + public int hashLookupEntrySize() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.hashLookupEntrySize; + } + + public int keyBits() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyBits; + } + + public long address() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.address; + } + + public long capacityMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask; + } + + public long capacityMask2() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask2; + } + + public long entryMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.entryMask; + } + + public long keyMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyMask; + } + + public long valueMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.valueMask; + } + + public void closeSegmentHashLookup() { + if (!(this.segmentHashLookupInit())) + return ; + + this.closeSegmentHashLookupDependants(); + this.address = -1; + } + + public void closeSegmentHashLookupDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public void closeHashLookupKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + public void closeHashLookupEmptyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void closeHashLookupReadEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public void writeEntry(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void closeHashLookupHlPosDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; + } + + long searchKey = UNSET_KEY; + + long searchStartPos; + + public boolean searchKeyInit() { + return (this.searchKey) != (UNSET_KEY); + } + + void initSearchKey() { + searchKey = CompiledReplicatedMapQueryContext.this.maskUnsetKey(CompiledReplicatedMapQueryContext.this.h().hashSplitting.segmentHash(CompiledReplicatedMapQueryContext.this.hashOfKey())); + searchStartPos = CompiledReplicatedMapQueryContext.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() { + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public long hashLookupPos = -1; + + public boolean hashLookupPosInit() { + return (this.hashLookupPos) >= 0; + } + + public void initHashLookupPos() { + CompiledReplicatedMapQueryContext.this.innerReadLock.lock(); + this.hashLookupPos = CompiledReplicatedMapQueryContext.this.searchStartPos(); + this.closeHashLookupPosDependants(); + } + + public void initHashLookupPos(long hashLookupPos) { + this.hashLookupPos = hashLookupPos; + this.closeHashLookupPosDependants(); + } + + public long hashLookupPos() { + if (!(this.hashLookupPosInit())) + this.initHashLookupPos(); + + return this.hashLookupPos; + } + + public void closeHashLookupPos() { + if (!(this.hashLookupPosInit())) + return ; + + this.closeHashLookupPosDependants(); + this.hashLookupPos = -1; + } + + public void closeHashLookupPosDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + public void remove() { + CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.remove(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + } + + public boolean checkSlotIsEmpty() { + return CompiledReplicatedMapQueryContext.this.empty(CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + } + + public void found() { + CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.stepBack(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + } + + public void closeHashLookupSearchFoundDependants() { + CompiledReplicatedMapQueryContext.this.closeKeySearch(); + } + + void put(long value) { + CompiledReplicatedMapQueryContext.this.checkValueForPut(value); + CompiledReplicatedMapQueryContext.this.writeEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos(), CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()), searchKey(), value); + } + + 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 void putVolatile(long value) { + CompiledReplicatedMapQueryContext.this.checkValueForPut(value); + long currentEntry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); + assert (CompiledReplicatedMapQueryContext.this.key(currentEntry)) == (searchKey()); + CompiledReplicatedMapQueryContext.this.writeEntryVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); + } + + 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 long value(long entry) { + return (entry >>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public long nextPos() { + long pos = CompiledReplicatedMapQueryContext.this.hashLookupPos(); + while (true) { + long entry = CompiledReplicatedMapQueryContext.this.readEntry(pos); + if (CompiledReplicatedMapQueryContext.this.empty(entry)) { + CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(pos); + return -1L; + } + pos = CompiledReplicatedMapQueryContext.this.step(pos); + if (pos == (searchStartPos())) + break; + + if ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) { + CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(pos); + return CompiledReplicatedMapQueryContext.this.value(entry); + } + } + throw new IllegalStateException(("MultiMap is full, that most likely means you " + ("misconfigured entrySize/chunkSize, and entries tend to take less chunks than " + "expected"))); + } + + public void closeHashLookupSearchNextPosDependants() { + CompiledReplicatedMapQueryContext.this.closeKeySearch(); + } + + 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 boolean checkSlotContainsExpectedKeyAndValue(long value) { + long entry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); + return ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledReplicatedMapQueryContext.this.value(entry)) == value); + } + + public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + long hashLookupOffset = h.segmentOffset(segmentIndex()); + long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); + freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); + freeList.reuse(freeListBytes); + entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); + this.closeSegmentDependants(); + } + + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.entrySpaceOffset; + } + + public SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.freeList; + } + + void closeSegment() { + if (!(this.segmentInit())) + return ; + + this.closeSegmentDependants(); + entrySpaceOffset = 0; + } + + public void closeSegmentDependants() { + CompiledReplicatedMapQueryContext.this.closeEntry(); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + if (chunks > (h.maxChunksPerEntry)) + throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); + + long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + ret = freeList().setNextNContinuousClearBits(0L, chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + if (chunks == 1) { + throw new IllegalStateException("Segment is full, no free entries found"); + } else { + throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); + } + } + updateNextPosToSearchFrom(ret, chunks); + } else { + if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { + updateNextPosToSearchFrom(ret, chunks); + } + } + return ret; + } + + public long pos = -1; + + public long keySizeOffset; + + public long keySize; + + public long keyOffset; + + public boolean entryInit() { + return (this.pos) >= 0; + } + + public void initEntry(long pos) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); + keyOffset = entryBytes.position(); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntry(long pos, Value key) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = key.size(); + CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); + keyOffset = entryBytes.position(); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntryCopying(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset; + initKeySizeOffset(newPos); + long oldKeyOffset = keyOffset; + keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); + pos = newPos; + this.closeEntryDependants(); + } + + public long keyOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keyOffset; + } + + public long keySize() { + assert this.entryInit() : "Entry should be init"; + return this.keySize; + } + + public long keySizeOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keySizeOffset; + } + + public long pos() { + assert this.entryInit() : "Entry should be init"; + return this.pos; + } + + public void closeEntry() { + if (!(this.entryInit())) + return ; + + this.closeEntryDependants(); + this.pos = -1; + } + + public void closeEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + boolean keyEquals() { + return ((inputKey().size()) == (CompiledReplicatedMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledReplicatedMapQueryContext.this.entryBytesAccess)), CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle, CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()))); + } + + public void closeReplicatedMapQueryKeyEqualsDependants() { + CompiledReplicatedMapQueryContext.this.closeKeySearch(); + } + + protected SearchState searchState = null; + + boolean keySearchInit() { + return (this.searchState) != null; + } + + void initKeySearch() { + for (long pos ; (pos = CompiledReplicatedMapQueryContext.this.nextPos()) >= 0L ; ) { + CompiledReplicatedMapQueryContext.this.initEntry(pos); + if (!(keyEquals())) + continue; + + CompiledReplicatedMapQueryContext.this.found(); + keyFound(); + return ; + } + searchState = SearchState.ABSENT; + this.closeKeySearchDependants(); + } + + public SearchState searchState() { + if (!(this.keySearchInit())) + this.initKeySearch(); + + return this.searchState; + } + + void closeKeySearch() { + if (!(this.keySearchInit())) + return ; + + this.closeKeySearchDependants(); + this.searchState = null; + } + + public void closeKeySearchDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + private void _AllocatedChunks_incrementSegmentEntriesIfNeeded() { + } + + public void incrementSegmentEntriesIfNeeded() { + if ((CompiledReplicatedMapQueryContext.this.searchState()) != (SearchState.PRESENT)) { + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) + 1L)); + } + } + + public void initEntryAndKey(long entrySize) { + initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); + CompiledReplicatedMapQueryContext.this.initEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); + incrementSegmentEntriesIfNeeded(); + } + + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { + initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); + CompiledReplicatedMapQueryContext.this.initEntryCopying(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); + } + + protected boolean searchStatePresent() { + return (searchState()) == (SearchState.PRESENT); + } + + 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.entryKey.closeEntryKeyBytesValueSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Value newValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public Value defaultValue() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); + } + + @NotNull + @Override + public Value key() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryKey; + } + + @Override + public Value defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerReadLock; + } + + public Value queriedKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Value value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerWriteLock; + } + + @NotNull + @Override + public Value value() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryValue; + } + + @NotNull + @Override + public InterProcessLock updateLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerUpdateLock; + } + + @Override + public Value wrapValueAsValue(V value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + protected boolean searchStateDeleted() { + return (((searchState()) == (SearchState.DELETED)) && (!(CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + } + + protected boolean searchStateAbsent() { + return (!(searchStatePresent())) && (!(searchStateDeleted())); + } + + private void putPrefix() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + if (underUpdatedLockIsHeld) + CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); + + boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); + if (((CompiledReplicatedMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); + + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicationState(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + } + + void initReplicationState(long timestamp, byte identifier) { + replicationBytesOffset = keyEnd(); + entryBytes.position(replicationBytesOffset); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.replicationBytesOffset = -1; + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + private boolean _MapQuery_entryPresent() { + return searchStatePresent(); + } + + protected boolean entryPresent() { + return (_MapQuery_entryPresent()) && (!(CompiledReplicatedMapQueryContext.this.entryDeleted())); + } + + @Nullable + @Override + public MapAbsentEntry absentEntry() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? null : this; + } + + private MapEntry _MapQuery_entry() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return entryPresent() ? this : null; + } + + @Override + public MapReplicableEntry entry() { + return ((MapReplicableEntry)(_MapQuery_entry())); + } + + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); + } + + @Override + public byte originIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return identifier(); + } + + private long _MapEntryStages_countValueSizeOffset() { + return keyEnd(); + } + + long countValueSizeOffset() { + return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeValue(); + } + + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public void clearSegment() { + CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + CompiledReplicatedMapQueryContext.this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); + } + + public void clear() { + clearSegment(); + } + + public void dropChange() { + CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); + } + + public void closeReplicationUpdateDropChangeDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); + } + + @NotNull + @Override + public Value absentKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + public long riKeySize = -1; public long riValueSize; @@ -3210,28 +3584,11 @@ public class CompiledReplicatedMapQueryContext newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + private long _HashEntryStages_entryEnd() { return keyEnd(); } @@ -3466,159 +3800,19 @@ public class CompiledReplicatedMapQueryContext newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - public long hashLookupPos = -1; - - public boolean hashLookupPosInit() { - return (this.hashLookupPos) >= 0; - } - - public void initHashLookupPos(long hashLookupPos) { - this.hashLookupPos = hashLookupPos; - this.closeHashLookupPosDependants(); - } - - public long hashLookupPos() { - assert this.hashLookupPosInit() : "HashLookupPos should be init"; - return this.hashLookupPos; - } - - public void closeHashLookupPos() { - if (!(this.hashLookupPosInit())) - return ; - - this.closeHashLookupPosDependants(); - this.hashLookupPos = -1; - } - - 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) { - CompiledReplicatedMapQueryContext.this.checkValueForPut(value); - long currentEntry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); - assert (CompiledReplicatedMapQueryContext.this.key(currentEntry)) == (searchKey()); - CompiledReplicatedMapQueryContext.this.writeEntryVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); - } - - public boolean checkSlotIsEmpty() { - return CompiledReplicatedMapQueryContext.this.empty(CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos())); - } - - void put(long value) { - CompiledReplicatedMapQueryContext.this.checkValueForPut(value); - CompiledReplicatedMapQueryContext.this.writeEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos(), CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()), searchKey(), value); - } - - boolean search = false; - - public boolean doSearchInit() { - return (this.search) != false; - } - - void initDoSearch() { - CompiledReplicatedMapQueryContext.this.innerReadLock.lock(); - CompiledReplicatedMapQueryContext.this.initHashLookupPos(searchStartPos()); - search = true; - this.closeDoSearchDependants(); - } - - public void closeDoSearch() { - if (!(this.doSearchInit())) - return ; - - this.closeDoSearchDependants(); - this.search = false; - } - - public void closeDoSearchDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); + void putEntry(Value value) { + assert searchStateAbsent(); + long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(inputKey().size(), value.size()); + CompiledReplicatedMapQueryContext.this.initEntryAndKey(entrySize); + CompiledReplicatedMapQueryContext.this.initValue(value); + CompiledReplicatedMapQueryContext.this.freeExtraAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.putNewVolatile(CompiledReplicatedMapQueryContext.this.pos()); } public void writeValueAndPutPos(Value value) { initValue(value); freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putValueVolatile(hashLookupPos(), pos()); - } - - public void found() { - CompiledReplicatedMapQueryContext.this.initHashLookupPos(CompiledReplicatedMapQueryContext.this.stepBack(CompiledReplicatedMapQueryContext.this.hashLookupPos())); - } - - public void closeHashLookupSearchFoundDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); - } - - protected SearchState searchState = null; - - boolean keySearchInit() { - return (this.searchState) != null; - } - - void initKeySearch() { - for (long pos ; (pos = CompiledReplicatedMapQueryContext.this.nextPosGuarded()) >= 0L ; ) { - CompiledReplicatedMapQueryContext.this.initEntry(pos); - if (!(keyEquals())) - continue; - - CompiledReplicatedMapQueryContext.this.found(); - keyFound(); - return ; - } - searchState = SearchState.ABSENT; - this.closeKeySearchDependants(); - } - - public SearchState searchState() { - if (!(this.keySearchInit())) - this.initKeySearch(); - - return this.searchState; - } - - void closeKeySearch() { - if (!(this.keySearchInit())) - return ; - - this.closeKeySearchDependants(); - this.searchState = null; - } - - public void closeKeySearchDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - private void _AllocatedChunks_incrementSegmentEntriesIfNeeded() { - } - - public void incrementSegmentEntriesIfNeeded() { - if ((CompiledReplicatedMapQueryContext.this.searchState()) != (SearchState.PRESENT)) { - CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) + 1L)); - } - } - - public void initEntryAndKey(long entrySize) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntryCopying(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); } private void _MapEntryStages_putValueDeletedEntry(Value newValue) { @@ -3663,13 +3857,35 @@ public class CompiledReplicatedMapQueryContext newValue) { throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); } + @Override + public void doInsert(Value value) { + putPrefix(); + if (!(searchStatePresent())) { + if (searchStateDeleted()) { + CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); + } else { + putEntry(value); + } + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + } + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + } + private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); @@ -3713,253 +3929,7 @@ public class CompiledReplicatedMapQueryContext value) { - assert searchStateAbsent(); - long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(inputKey().size(), value.size()); - CompiledReplicatedMapQueryContext.this.initEntryAndKey(entrySize); - CompiledReplicatedMapQueryContext.this.initValue(value); - CompiledReplicatedMapQueryContext.this.freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putNewVolatile(CompiledReplicatedMapQueryContext.this.pos()); - } - - private boolean _MapQuery_entryPresent() { - return searchStatePresent(); - } - - protected boolean entryPresent() { - return (_MapQuery_entryPresent()) && (!(CompiledReplicatedMapQueryContext.this.entryDeleted())); - } - - public boolean checkSlotContainsExpectedKeyAndValue(long value) { - long entry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); - return ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledReplicatedMapQueryContext.this.value(entry)) == value); - } - - public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - 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.closeDoSearch(); - - } - } - } - } - } - - 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.closeEntryValueBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - } - - @Override - public long originTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerWriteLock; - } - - @NotNull - @Override - public Value absentKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public Value defaultValue() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerReadLock; - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - private MapEntry _MapQuery_entry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; - } - - @Override - public MapReplicableEntry entry() { - return ((MapReplicableEntry)(_MapQuery_entry())); - } - - @NotNull - @Override - public Value 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 long remoteTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newTimestamp(); - } - - @NotNull - @Override - public Value value() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryValue; - } - - public Value queriedKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @Override - public Value wrapValueAsValue(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @Nullable - @Override - public MapAbsentEntry absentEntry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : this; - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Value newValue) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public Value defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); - } - - private void putPrefix() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); - if (underUpdatedLockIsHeld) - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - - boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); - if (((CompiledReplicatedMapQueryContext.this.doSearchInit()) && (searchStateAbsent())) && searchResultsNotTrusted) - CompiledReplicatedMapQueryContext.this.closeDoSearch(); - - } - - @Override - public void doReplaceValue(Value newValue) { - putPrefix(); - if (searchStatePresent()) { - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(newValue); - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); - } - } - - @Override - public void doInsert(Value value) { - putPrefix(); - if (!(searchStatePresent())) { - if (searchStateDeleted()) { - CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); - } else { - putEntry(value); - } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is present in the map when doInsert() is called"); - } - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerUpdateLock; - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newIdentifier(); - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - public void remove() { - CompiledReplicatedMapQueryContext.this.initHashLookupPos(CompiledReplicatedMapQueryContext.this.remove(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); } private void _MapQuery_doRemove() { @@ -3992,4 +3962,55 @@ public class CompiledReplicatedMapQueryContext newValue) { + putPrefix(); + if (searchStatePresent()) { + CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(newValue); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); + } + } + + @Override + public byte remoteIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return newIdentifier(); + } + + private boolean testTimeStampInSensibleRange() { + if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapQueryContext.this.newTimestamp()); + } + return true; + } + + @Override + public long remoteTimestamp() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return newTimestamp(); + } + + private boolean updatedReplicationState = false; + + public boolean updatedReplicationStateInit() { + return (this.updatedReplicationState) != false; + } + + public void initUpdatedReplicationState() { + initReplicationState(CompiledReplicatedMapQueryContext.this.newTimestamp(), CompiledReplicatedMapQueryContext.this.newIdentifier()); + updatedReplicationState = true; + } + + public void closeUpdatedReplicationState() { + if (!(this.updatedReplicationStateInit())) + return ; + + this.updatedReplicationState = false; + } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/ReplicatedChronicleMapHolder.java b/src/main/java/net/openhft/chronicle/map/impl/ReplicatedChronicleMapHolder.java new file mode 100644 index 000000000..f88a75b04 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/impl/ReplicatedChronicleMapHolder.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015 Higher Frequency Trading + * + * http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.map.impl; + +import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; +import net.openhft.chronicle.map.ReplicatedChronicleMap; + +public interface ReplicatedChronicleMapHolder, + V, VI, MVI extends MetaBytesInterop, R> + extends VanillaChronicleMapHolder { + + @Override + ReplicatedChronicleMap m(); +} diff --git a/src/main/java/net/openhft/chronicle/map/impl/VanillaChronicleMapHolder.java b/src/main/java/net/openhft/chronicle/map/impl/VanillaChronicleMapHolder.java new file mode 100644 index 000000000..7c58132fe --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/impl/VanillaChronicleMapHolder.java @@ -0,0 +1,41 @@ +/* + * Copyright 2015 Higher Frequency Trading + * + * http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.map.impl; + +import net.openhft.chronicle.hash.impl.VanillaChronicleHash; +import net.openhft.chronicle.hash.impl.VanillaChronicleHashHolder; +import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; +import net.openhft.chronicle.map.ChronicleMap; +import net.openhft.chronicle.map.VanillaChronicleMap; + +public interface VanillaChronicleMapHolder, + V, VI, MVI extends MetaBytesInterop, R> + extends VanillaChronicleHashHolder { + + VanillaChronicleMap m(); + + @Override + default VanillaChronicleHash h() { + return m(); + } + + default ChronicleMap map() { + return m(); + } +}