diff --git a/pom.xml b/pom.xml index 3782d7610..ce32cdac8 100755 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ net.openhft chronicle-bom pom - 1.3.3-SNAPSHOT + 1.4.0 import @@ -90,7 +90,6 @@ net.openhft chronicle-bytes - 1.0.5-alpha @@ -118,11 +117,6 @@ pax-url-aether - - net.openhft - chronicle-network - - diff --git a/src/main/java/net/openhft/chronicle/hash/AbstractData.java b/src/main/java/net/openhft/chronicle/hash/AbstractData.java index 652b4dabd..de3c148fa 100644 --- a/src/main/java/net/openhft/chronicle/hash/AbstractData.java +++ b/src/main/java/net/openhft/chronicle/hash/AbstractData.java @@ -26,7 +26,7 @@ import net.openhft.chronicle.algo.hashing.LongHashFunction; * but Java 8 doesn't allow to override {@code Object}'s methods by default implementations * in interfaces. */ -public abstract class AbstractData implements Data { +public abstract class AbstractData implements Data { /** * Constructor for use by subclasses. @@ -49,7 +49,7 @@ public abstract class AbstractData implements Data { public boolean equals(Object obj) { return obj != null && obj instanceof Data && - Data.bytesEquivalent(this, (Data) obj); + Data.bytesEquivalent(this, (Data) obj); } /** diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java index 8b95ade53..6e633fc8e 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java @@ -86,7 +86,7 @@ public interface ChronicleHash, EQC extends ExternalH * @param key the queried key as {@code Data} * @return the context to perform operations with the key */ - @NotNull EQC queryContext(Data key); + @NotNull EQC queryContext(Data key); /** * Checks the given predicate on each entry in this {@code ChronicleHash} until all entries diff --git a/src/main/java/net/openhft/chronicle/hash/Data.java b/src/main/java/net/openhft/chronicle/hash/Data.java index 5a14cac67..96cd5f631 100644 --- a/src/main/java/net/openhft/chronicle/hash/Data.java +++ b/src/main/java/net/openhft/chronicle/hash/Data.java @@ -18,14 +18,18 @@ package net.openhft.chronicle.hash; -import net.openhft.chronicle.bytes.*; import net.openhft.chronicle.algo.hashing.LongHashFunction; +import net.openhft.chronicle.bytes.BytesUtil; +import net.openhft.chronicle.bytes.RandomDataInput; +import net.openhft.chronicle.bytes.RandomDataOutput; import org.jetbrains.annotations.Nullable; +import static net.openhft.chronicle.algo.bytes.Access.checkedRandomDataInputAccess; + /** * Dual bytes/object access to keys/values/elements. * - *

Bytes access: {@link #access()} + {@link #handle()} + {@link #offset()} + {@link #size()}. + *

Bytes access: {@link #bytes()} + {@link #offset()} + {@link #size()}. * *

Object access: {@link #get()}. * @@ -34,19 +38,10 @@ import org.jetbrains.annotations.Nullable; * accordingly. * * @param type of the accessed objects - * @param type of the handle for bytes access */ -public interface Data { +public interface Data { - /** - * Returns access to the value's bytes. - */ - ReadAccess access(); - - /** - * Returns a handle to access the value's bytes. - */ - T handle(); + RandomDataInput bytes(); /** * Returns the offset to the value's bytes. @@ -59,33 +54,15 @@ public interface Data { long size(); default long hash(LongHashFunction f) { - return f.hash(handle(), access(), offset(), size()); + return f.hash(bytes(), checkedRandomDataInputAccess(), offset(), size()); } - default boolean equivalent(ReadAccess access, T2 handle, long offset) { - return Access.equivalent(access(), handle(), offset(), access, handle, offset, size()); + default boolean equivalent(RandomDataInput source, long sourceOffset) { + return BytesUtil.bytesEqual(source, sourceOffset, bytes(), offset(), size()); } - default > boolean equivalent( - Accessor accessor, S source, long index) { - return equivalent(accessor.access(source), accessor.handle(source), - accessor.offset(source, index)); - } - - default void writeTo(WriteAccess targetAccess, T2 target, long targetOffset) { - Access.copy(access(), handle(), offset(), targetAccess, target, targetOffset, size()); - } - - default void writeTo(StreamingDataOutput output) { - long offset = output.accessPositionOffset(); - output.skip(size()); - writeTo(output.access(), output.accessHandle(), offset); - } - - default > void writeTo( - Accessor targetAccessor, S target, long index) { - writeTo(targetAccessor.access(target), targetAccessor.handle(target), - targetAccessor.offset(target, index)); + default void writeTo(RandomDataOutput target, long targetOffset) { + target.write(targetOffset, bytes(), offset(), size()); } /** @@ -102,10 +79,9 @@ public interface Data { */ V getUsing(@Nullable V usingInstance); - static boolean bytesEquivalent(Data v1, Data v2) { - if (v1.size() != v2.size()) + static boolean bytesEquivalent(Data d1, Data d2) { + if (d1.size() != d2.size()) return false; - return Access.equivalent(v1.access(), v1.handle(), v1.offset(), - v2.access(), v2.handle(), v2.offset(), v1.size()); + return BytesUtil.bytesEqual(d1.bytes(), d1.offset(), d2.bytes(), d2.offset(), d1.size()); } } diff --git a/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java b/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java index f97cfb732..47ac61431 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java +++ b/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java @@ -25,5 +25,5 @@ public interface HashAbsentEntry { * Returns the key is going to be inserted into the {@code ChronicleHash}. */ @NotNull - Data absentKey(); + Data absentKey(); } diff --git a/src/main/java/net/openhft/chronicle/hash/HashEntry.java b/src/main/java/net/openhft/chronicle/hash/HashEntry.java index cee107e9a..57e439663 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashEntry.java +++ b/src/main/java/net/openhft/chronicle/hash/HashEntry.java @@ -41,7 +41,7 @@ public interface HashEntry { * Returns the entry key. */ @NotNull - Data key(); + Data key(); /** * Removes the entry from the {@code ChronicleHash}. diff --git a/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java b/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java index c3bada023..622c9fe2f 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java +++ b/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java @@ -142,7 +142,7 @@ public interface HashQueryContext extends HashContext, InterProcessReadWri /** * Returns the queried key as a {@code Data}. */ - Data queriedKey(); + Data queriedKey(); /** * Returns the entry context, if the entry with the queried key is present diff --git a/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java b/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java index 0d82da723..e019f9046 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java @@ -18,50 +18,48 @@ package net.openhft.chronicle.hash.impl; -import net.openhft.chronicle.bytes.ReadAccess; +import net.openhft.chronicle.bytes.RandomDataInput; import net.openhft.chronicle.hash.AbstractData; import net.openhft.lang.io.DirectBytes; import net.openhft.lang.io.DirectStore; import net.openhft.lang.io.serialization.JDKObjectSerializer; -import static net.openhft.chronicle.hash.impl.JavaLangBytesAccessors.uncheckedBytesAccessor; +public abstract class CopyingInstanceData extends AbstractData { -public abstract class CopyingInstanceData extends AbstractData { + private final JavaLangBytesReusableBytesStore bytesStore = + new JavaLangBytesReusableBytesStore(); - public static DirectBytes getBuffer(DirectBytes b, long capacity) { + public DirectBytes getBuffer(DirectBytes b, long capacity) { if (b != null) { if (b.capacity() >= capacity) { return (DirectBytes) b.clear(); } else { DirectStore store = (DirectStore) b.store(); store.resize(capacity, false); - return store.bytes(); + DirectBytes bytes = store.bytes(); + bytesStore.setBytes(bytes); + return bytes; } } else { - return new DirectStore(JDKObjectSerializer.INSTANCE, Math.max(1, capacity), true) - .bytes(); + DirectBytes bytes = new DirectStore(JDKObjectSerializer.INSTANCE, + Math.max(1, capacity), true).bytes(); + bytesStore.setBytes(bytes); + return bytes; } } + @Override + public RandomDataInput bytes() { + return bytesStore; + } + public abstract I instance(); public abstract DirectBytes buffer(); - @Override - public ReadAccess access() { - //noinspection unchecked - return (ReadAccess) uncheckedBytesAccessor(buffer()).access(buffer()); - } - - @Override - public T handle() { - //noinspection unchecked - return (T) uncheckedBytesAccessor(buffer()).handle(buffer()); - } - @Override public long offset() { - return uncheckedBytesAccessor(buffer()).offset(buffer(), 0); + return 0; } @Override diff --git a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccess.java b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccess.java deleted file mode 100644 index 65006bbcc..000000000 --- a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccess.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.bytes.Access; -import net.openhft.lang.io.Bytes; - -import java.nio.ByteOrder; - -enum JavaLangBytesAccess implements Access { - INSTANCE; - - @Override - public byte readByte(Bytes handle, long offset) { - return handle.readByte(offset); - } - - @Override - public short readShort(Bytes handle, long offset) { - return handle.readShort(offset); - } - - @Override - public char readChar(Bytes handle, long offset) { - return handle.readChar(offset); - } - - @Override - public int readInt(Bytes handle, long offset) { - return handle.readInt(offset); - } - - @Override - public long readLong(Bytes handle, long offset) { - return handle.readLong(offset); - } - - @Override - public void writeByte(Bytes handle, long offset, byte i8) { - handle.writeByte(offset, i8); - } - - @Override - public void writeShort(Bytes handle, long offset, short i) { - handle.writeShort(offset, i); - } - - @Override - public void writeChar(Bytes handle, long offset, char c) { - handle.writeChar(offset, c); - } - - @Override - public void writeInt(Bytes handle, long offset, int i) { - handle.writeInt(offset, i); - } - - @Override - public void writeLong(Bytes handle, long offset, long i) { - handle.writeLong(offset, i); - } - - @Override - public void writeFloat(Bytes handle, long offset, float d) { - handle.writeFloat(offset, d); - } - - @Override - public void writeDouble(Bytes handle, long offset, double d) { - handle.writeDouble(offset, d); - } - - @Override - public ByteOrder byteOrder(Bytes handle) { - return handle.byteOrder(); - } -} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccessors.java b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccessors.java deleted file mode 100644 index 02a0a6aba..000000000 --- a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesAccessors.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.bytes.Access; -import net.openhft.chronicle.bytes.Accessor; -import net.openhft.lang.io.Bytes; -import net.openhft.lang.io.NativeBytes; - -import static net.openhft.chronicle.bytes.Access.nativeAccess; - -public final class JavaLangBytesAccessors { - - public static Accessor.Full uncheckedBytesAccessor(Bytes bytes) { - return bytes instanceof NativeBytes ? GenericBytesAccessor.INSTANCE : - GenericBytesAccessor.INSTANCE; - } - - enum NativeBytesAccessor implements Accessor.Full { - INSTANCE; - - @Override - public Access access(Bytes source) { - return nativeAccess(); - } - - @Override - public Void handle(Bytes source) { - return null; - } - - @Override - public long offset(Bytes source, long index) { - return source.address() + index; - } - } - - enum GenericBytesAccessor implements Accessor.Full { - INSTANCE; - - @Override - public Access access(Bytes source) { - return JavaLangBytesAccess.INSTANCE; - } - - @Override - public Bytes handle(Bytes source) { - return source; - } - - @Override - public long offset(Bytes source, long index) { - return index; - } - } - - private JavaLangBytesAccessors() {} -} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesReusableBytesStore.java b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesReusableBytesStore.java new file mode 100644 index 000000000..abdba3cfb --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/impl/JavaLangBytesReusableBytesStore.java @@ -0,0 +1,168 @@ +package net.openhft.chronicle.hash.impl; + +import net.openhft.chronicle.bytes.BytesStore; +import net.openhft.chronicle.bytes.RandomDataInput; +import net.openhft.lang.io.Bytes; + +import java.nio.ByteBuffer; + +public class JavaLangBytesReusableBytesStore + implements BytesStore { + + private Bytes bytes; + + public void setBytes(Bytes bytes) { + this.bytes = bytes; + } + + @Override + public BytesStore copy() { + throw new UnsupportedOperationException(); + } + + @Override + public long capacity() { + return bytes.capacity(); + } + + @Override + public long address() throws UnsupportedOperationException { + return bytes.address(); + } + + @Override + public Void underlyingObject() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean compareAndSwapInt(long offset, int expected, int value) { + return bytes.compareAndSwapInt(offset, expected, value); + } + + @Override + public boolean compareAndSwapLong(long offset, long expected, long value) { + return bytes.compareAndSwapLong(offset, expected, value); + } + + @Override + public byte readByte(long offset) { + return bytes.readByte(offset); + } + + @Override + public short readShort(long offset) { + return bytes.readShort(offset); + } + + @Override + public int readInt(long offset) { + return bytes.readInt(offset); + } + + @Override + public long readLong(long offset) { + return bytes.readLong(offset); + } + + @Override + public float readFloat(long offset) { + return bytes.readFloat(offset); + } + + @Override + public double readDouble(long offset) { + return bytes.readDouble(offset); + } + + @Override + public void nativeRead(long position, long address, long size) { + throw new UnsupportedOperationException(); + } + + @Override + public JavaLangBytesReusableBytesStore writeByte(long offset, byte i8) { + bytes.writeByte(offset, i8); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeShort(long offset, short i) { + bytes.writeShort(offset, i); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeInt(long offset, int i) { + bytes.writeInt(offset, i); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeOrderedInt(long offset, int i) { + bytes.writeOrderedInt(offset, i); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeLong(long offset, long i) { + bytes.writeLong(offset, i); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeOrderedLong(long offset, long i) { + bytes.writeOrderedLong(offset, i); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeFloat(long offset, float d) { + bytes.writeFloat(offset, d); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore writeDouble(long offset, double d) { + bytes.writeDouble(offset, d); + return this; + } + + @Override + public JavaLangBytesReusableBytesStore write(long offsetInRDO, + byte[] bs, int offset, int length) { + bytes.write(offsetInRDO, bs, offset, length); + return this; + } + + @Override + public void write(long offsetInRDO, ByteBuffer bb, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public JavaLangBytesReusableBytesStore write(long offsetInRDO, + RandomDataInput input, long offset, long length) { + throw new UnsupportedOperationException(); + } + + @Override + public void nativeWrite(long address, long position, long size) { + throw new UnsupportedOperationException(); + } + + @Override + public void reserve() throws IllegalStateException { + throw new UnsupportedOperationException(); + } + + @Override + public void release() throws IllegalStateException { + throw new UnsupportedOperationException(); + } + + @Override + public long refCount() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java b/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java index 75bb2dee7..db765a63b 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java @@ -2,7 +2,7 @@ package net.openhft.chronicle.hash.impl.value.instance; import net.openhft.chronicle.hash.Data; -public interface KeyInitableData extends Data { +public interface KeyInitableData extends Data { void initKey(K key); } diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java index d778a5c2b..8211d1b83 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/internal/CopyingMetaBytesInterop.java @@ -35,7 +35,11 @@ public abstract class CopyingMetaBytesInterop extends BasicCopyingMetaByte throw new IllegalStateException("We try to figure out size of objects " + "in serialized form, but it exceeds " + MAX_REASONABLE_SERIALIZED_SIZE + " bytes. We assume this is " + - "a error and throw exception at this point. If you really " + + "a error and throw exception at this point. There could be two reasons:\n" + + "1) The given object is not Serializable. Configure ChronicleMapBuilder" + + ".keyMarshallers/valueMarshallers to handle the given objects.\n" + + "2) Your object are very large in serialized form (larger than " + + MAX_REASONABLE_SERIALIZED_SIZE + " bytes). If you really " + "want larger keys/values, use ChronicleMapBuilder." + "keySize(int)/valueSize(int)/entrySize(int) configurations", ex); } diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java index 9ce4540f4..e30cf5345 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java @@ -256,12 +256,17 @@ abstract class AbstractChannelReplicator implements Closeable { public void closeResources() { isClosed = true; - // context.close(); executorService.shutdown(); - try { - executorService.awaitTermination(5, TimeUnit.MILLISECONDS); + if (!executorService.awaitTermination(5, TimeUnit.MILLISECONDS)) { + executorService.shutdownNow(); + try { + executorService.awaitTermination(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + LOG.error("", e); + } + } } catch (Exception e) { executorService.shutdownNow(); try { diff --git a/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java b/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java index 741f4a49a..4274878db 100644 --- a/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java +++ b/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java @@ -49,7 +49,7 @@ public interface MapAbsentEntry extends HashAbsentEntry { * operation are not met * @see MapEntryOperations#insert(MapAbsentEntry, Data) */ - void doInsert(Data value); + void doInsert(Data value); /** * Returns the default (or nil) value, that should be inserted into the map in @@ -63,5 +63,5 @@ public interface MapAbsentEntry extends HashAbsentEntry { * @see MapEntryOperations#defaultValue(MapAbsentEntry) */ @NotNull - Data defaultValue(); + Data defaultValue(); } diff --git a/src/main/java/net/openhft/chronicle/map/MapContext.java b/src/main/java/net/openhft/chronicle/map/MapContext.java index da1710fca..a9274f9ba 100644 --- a/src/main/java/net/openhft/chronicle/map/MapContext.java +++ b/src/main/java/net/openhft/chronicle/map/MapContext.java @@ -55,5 +55,5 @@ public interface MapContext extends HashContext, MapEntryOperations< * @param value the value object to wrap * @return the value as {@code Data} */ - Data wrapValueAsValue(V value); + Data wrapValueAsValue(V value); } diff --git a/src/main/java/net/openhft/chronicle/map/MapEntry.java b/src/main/java/net/openhft/chronicle/map/MapEntry.java index 184d6b3ca..cdce98313 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEntry.java +++ b/src/main/java/net/openhft/chronicle/map/MapEntry.java @@ -38,7 +38,7 @@ public interface MapEntry extends HashEntry { * Returns the entry value. */ @NotNull - Data value(); + Data value(); /** * Replaces the entry's value with the given {@code newValue}. @@ -51,7 +51,7 @@ public interface MapEntry extends HashEntry { * @throws IllegalStateException if some locking/state conditions required to perform replace * operation are not met */ - void doReplaceValue(Data newValue); + void doReplaceValue(Data newValue); /** * Removes the entry from the map. diff --git a/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java b/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java index cd94e4706..ef7b3e3ee 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java +++ b/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java @@ -130,7 +130,7 @@ public interface MapEntryOperations { * @throws RuntimeException if value replacement was unconditionally unsuccessful due * to any reason */ - default R replaceValue(@NotNull MapEntry entry, Data newValue) { + default R replaceValue(@NotNull MapEntry entry, Data newValue) { entry.doReplaceValue(newValue); return null; } @@ -146,7 +146,7 @@ public interface MapEntryOperations { * operation are not met * @throws RuntimeException if insertion was unconditionally unsuccessful due to any reason */ - default R insert(@NotNull MapAbsentEntry absentEntry, Data value) { + default R insert(@NotNull MapAbsentEntry absentEntry, Data value) { absentEntry.doInsert(value); return null; } @@ -158,7 +158,7 @@ public interface MapEntryOperations { * * @implNote simply delegates to {@link MapAbsentEntry#defaultValue()}. */ - default Data defaultValue(@NotNull MapAbsentEntry absentEntry) { + default Data defaultValue(@NotNull MapAbsentEntry absentEntry) { return absentEntry.defaultValue(); } } diff --git a/src/main/java/net/openhft/chronicle/map/MapMethods.java b/src/main/java/net/openhft/chronicle/map/MapMethods.java index 85f6bf114..3228bd28a 100644 --- a/src/main/java/net/openhft/chronicle/map/MapMethods.java +++ b/src/main/java/net/openhft/chronicle/map/MapMethods.java @@ -69,7 +69,7 @@ public interface MapMethods { * q.insert(q.absentEntry(), value); * }} */ - default void put(MapQueryContext q, Data value, ReturnValue returnValue) { + default void put(MapQueryContext q, Data value, ReturnValue returnValue) { // We cannot read the previous value under read lock, because then we will need // to release the read lock -> acquire write lock, the value might be updated in // between, that will break ConcurrentMap.put() atomicity guarantee. So, we acquire @@ -108,7 +108,7 @@ public interface MapMethods { * } */ default void putIfAbsent(MapQueryContext q, - Data value, ReturnValue returnValue) { + Data value, ReturnValue returnValue) { if (tryReturnCurrentValueIfPresent(q, returnValue)) return; // Key is absent @@ -234,7 +234,7 @@ public interface MapMethods { * * @return if the entry was removed */ - default boolean remove(MapQueryContext q, Data value) { + default boolean remove(MapQueryContext q, Data value) { // remove(key, value) should find the entry & remove most of the time, // so don't try to check key presence and value equivalence under read lock first, // as in putIfAbsent()/acquireUsing(), start with update lock: @@ -263,7 +263,7 @@ public interface MapMethods { * }} */ default void replace(MapQueryContext q, - Data value, ReturnValue returnValue) { + Data value, ReturnValue returnValue) { // replace(key, value) should find the key & put the value most of the time, // so don't try to check key presence under read lock first, // as in putIfAbsent()/acquireUsing(), start with update lock: @@ -294,7 +294,7 @@ public interface MapMethods { * @return if the entry was replaced */ default boolean replace(MapQueryContext q, - Data oldValue, Data newValue) { + Data oldValue, Data newValue) { // replace(key, old, new) should find the entry & put new value most of the time, // so don't try to check key presence and value equivalence under read lock first, // as in putIfAbsent()/acquireUsing(), start with update lock: @@ -337,7 +337,7 @@ public interface MapMethods { V oldValue = entry != null ? entry.value().get() : null; V newValue = remappingFunction.apply(q.queriedKey().get(), oldValue); if (newValue != null) { - Data newValueData = q.wrapValueAsValue(newValue); + Data newValueData = q.wrapValueAsValue(newValue); if (entry != null) { q.replaceValue(entry, newValueData); } else { @@ -409,11 +409,11 @@ public interface MapMethods { * returnValue.returnValue(entry.value()); * } */ - default void merge(MapQueryContext q, Data value, + default void merge(MapQueryContext q, Data value, BiFunction remappingFunction, ReturnValue returnValue) { q.updateLock().lock(); - Data newValueData; + Data newValueData; MapEntry entry = q.entry(); if (entry != null) { V oldValue = entry.value().get(); diff --git a/src/main/java/net/openhft/chronicle/map/ReturnValue.java b/src/main/java/net/openhft/chronicle/map/ReturnValue.java index 417149c00..c264bfcec 100644 --- a/src/main/java/net/openhft/chronicle/map/ReturnValue.java +++ b/src/main/java/net/openhft/chronicle/map/ReturnValue.java @@ -22,5 +22,5 @@ import net.openhft.chronicle.hash.Data; import org.jetbrains.annotations.NotNull; public interface ReturnValue { - void returnValue(@NotNull Data value); + void returnValue(@NotNull Data value); } diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 9ec66b29c..5975cfceb 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -555,7 +555,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon @NotNull @Override - public ExternalMapQueryContext queryContext(Data key) { + public ExternalMapQueryContext queryContext(Data key) { throw new UnsupportedOperationException("Contexts are not supported by stateless clients"); } diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index 75c1ce6db..92c3f35dd 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -171,18 +171,18 @@ public class VanillaChronicleMap>() { + queryCxt = new ThreadLocal>() { @Override - protected CompiledMapQueryContext initialValue() { + protected CompiledMapQueryContext initialValue() { return new CompiledMapQueryContext<>(VanillaChronicleMap.this); } }; } void initIterationContext() { - iterCxt = new ThreadLocal>() { + iterCxt = new ThreadLocal>() { @Override - protected CompiledMapIterationContext initialValue() { + protected CompiledMapIterationContext initialValue() { return new CompiledMapIterationContext<>(VanillaChronicleMap.this); } }; @@ -335,23 +335,23 @@ public class VanillaChronicleMap q() { - return (CompiledMapQueryContext) queryCxt.get(); + private CompiledMapQueryContext q() { + return (CompiledMapQueryContext) queryCxt.get(); } public QueryContextInterface mapContext() { - CompiledMapQueryContext q = q().getContext(); + CompiledMapQueryContext q = q().getContext(); q.initUsed(true); return q; } - private CompiledMapIterationContext i() { - return (CompiledMapIterationContext) iterCxt.get(); + private CompiledMapIterationContext i() { + return (CompiledMapIterationContext) iterCxt.get(); } @Override public IterationContextInterface iterationContext() { - CompiledMapIterationContext c = i().getContext(); + CompiledMapIterationContext c = i().getContext(); c.initUsed(true); return c; } @@ -368,7 +368,7 @@ public class VanillaChronicleMap queryContext(Data key) { + public QueryContextInterface queryContext(Data key) { QueryContextInterface q = mapContext(); q.initInputKey(key); return q; 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 fb0f7cf37..49e5cfaf9 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java @@ -1,9 +1,8 @@ package net.openhft.chronicle.map.impl; -import net.openhft.chronicle.bytes.Access; -import net.openhft.chronicle.bytes.Accessor; -import net.openhft.chronicle.bytes.Accessor.Full; -import net.openhft.chronicle.bytes.ReadAccess; +import net.openhft.chronicle.bytes.BytesStore; +import net.openhft.chronicle.bytes.NativeBytesStore; +import net.openhft.chronicle.bytes.RandomDataInput; import net.openhft.chronicle.hash.AbstractData; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashEntry; @@ -31,22 +30,22 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; -public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , MapContext , MapEntry , IterationContextInterface , VanillaChronicleMapHolder { +public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , MapContext , MapEntry , IterationContextInterface , VanillaChronicleMapHolder { public void close() { - CompiledMapIterationContext.this.closeHashLookupPos(); - CompiledMapIterationContext.this.closeKeyOffset(); - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); - CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration(); - CompiledMapIterationContext.this.closePos(); - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue(); - CompiledMapIterationContext.this.closeTheSegmentIndex(); - CompiledMapIterationContext.this.closeKeySize(); - CompiledMapIterationContext.this.closeUsed(); - CompiledMapIterationContext.this.closeAllocatedChunks(); - CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); - CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); - CompiledMapIterationContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); - CompiledMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + this.closeTheSegmentIndex(); + this.wrappedValueInstanceValue.closeValue(); + this.closeEntryRemovedOnThisIteration(); + this.wrappedValueInstanceValue.closeNext(); + this.closeUsed(); + this.closeKeySize(); + this.closePos(); + this.closeAllocatedChunks(); + this.closeHashLookupPos(); + this.closeKeyOffset(); + this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); + this.closeValueBytesInteropValueMetaInteropDependants(); + this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); } public void incrementModCountGuarded() { @@ -69,26 +68,24 @@ public class CompiledMapIterationContext m) { - contextChain = new ArrayList(); + contextChain = new ArrayList(); contextChain.add(this); indexInContextChain = 0; this.m = m; - this.entryKey = new EntryKeyBytesData(); - this.entryValue = new EntryValueBytesData(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.innerWriteLock = new WriteLock(); - this.owner = Thread.currentThread(); - this.innerUpdateLock = new UpdateLock(); this.copies = ThreadLocalCopies.get(); - this.valueInterop = CompiledMapIterationContext.this.m().valueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueInterop); - this.valueReader = CompiledMapIterationContext.this.m().valueReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueReader); - this.keyInterop = CompiledMapIterationContext.this.h().keyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyInterop); - this.keyReader = CompiledMapIterationContext.this.h().keyReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyReader); + this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.innerReadLock = new ReadLock(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); } @@ -97,26 +94,29 @@ public class CompiledMapIterationContext)(c.m)); - this.entryKey = new EntryKeyBytesData(); - this.entryValue = new EntryValueBytesData(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.innerWriteLock = new WriteLock(); - this.owner = Thread.currentThread(); - this.innerUpdateLock = new UpdateLock(); this.copies = ThreadLocalCopies.get(); - this.valueInterop = CompiledMapIterationContext.this.m().valueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueInterop); - this.valueReader = CompiledMapIterationContext.this.m().valueReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalValueReader); - this.keyInterop = CompiledMapIterationContext.this.h().keyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyInterop); - this.keyReader = CompiledMapIterationContext.this.h().keyReaderProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalKeyReader); + this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.innerReadLock = new ReadLock(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); } public class DeprecatedMapKeyContextOnIteration implements MapKeyContext { + @Override + public void close() { + throw new UnsupportedOperationException("close() is not supported during iteration"); + } + @NotNull private UnsupportedOperationException unsupportedLocks() { return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); @@ -128,28 +128,22 @@ public class CompiledMapIterationContext { + public class EntryKeyBytesData extends AbstractData { @Override - public ReadAccess access() { + public RandomDataInput bytes() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccess; + return CompiledMapIterationContext.this.entryBS; } @Override - public T handle() { + public long offset() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccessHandle; + return CompiledMapIterationContext.this.keyOffset(); } @Override @@ -242,13 +237,7 @@ public class CompiledMapIterationContext { + public class EntryValueBytesData extends AbstractData { @Override - public T handle() { + public RandomDataInput bytes() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccessHandle; + return CompiledMapIterationContext.this.entryBS; } @Override - public ReadAccess access() { + public long offset() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccess; + return CompiledMapIterationContext.this.valueOffset(); } @Override @@ -320,13 +309,7 @@ public class CompiledMapIterationContext { + public class WrappedValueInstanceData extends CopyingInstanceData { public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); @@ -559,6 +542,18 @@ public class CompiledMapIterationContext contextChain; + public final List contextChain; public final UpdateLock innerUpdateLock; @@ -949,27 +944,27 @@ public class CompiledMapIterationContext contextChain() { + public List contextChain() { return this.contextChain; } public final ThreadLocalCopies copies; + final EntryKeyBytesData entryKey; + + public EntryKeyBytesData entryKey() { + return this.entryKey; + } + public ThreadLocalCopies copies() { return this.copies; } private void countValueOffset() { - CompiledMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); + this.m().alignment.alignPositionAddr(entryBytes); valueOffset = entryBytes.position(); } - final EntryKeyBytesData entryKey; - - public EntryKeyBytesData entryKey() { - return this.entryKey; - } - public final EntryValueBytesData entryValue; public EntryValueBytesData entryValue() { @@ -996,17 +991,10 @@ public class CompiledMapIterationContext entryBytesAccessor; + public final BytesStore entryBS; - public Full entryBytesAccessor() { - return this.entryBytesAccessor; - } - - @SuppressWarnings(value = "unchecked") - public final T entryBytesAccessHandle; - - public T entryBytesAccessHandle() { - return this.entryBytesAccessHandle; + public BytesStore entryBS() { + return this.entryBS; } public final BytesReader valueReader; @@ -1021,30 +1009,12 @@ public class CompiledMapIterationContext entryBytesAccess; - - public Access entryBytesAccess() { - return this.entryBytesAccess; - } - public final BytesReader keyReader; public BytesReader keyReader() { return this.keyReader; } - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledMapIterationContext.this.m().metaDataBytes) + (CompiledMapIterationContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - public void incrementSegmentEntriesIfNeeded() { - } - - public long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); - } - public boolean entryIsPresent() { return true; } @@ -1059,151 +1029,6 @@ public class CompiledMapIterationContextT contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public void checkEntryNotRemovedOnThisIteration() { - if (entryRemovedOnThisIterationInit()) - throw new IllegalStateException("Entry was already removed on this iteration"); - - } - - public void closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants() { - CompiledMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { - CompiledMapIterationContext.this.checkAccessingFromOwnerThread(); - } - - public void checkOnEachPublicOperation() { - _CheckOnEachPublicOperation_checkOnEachPublicOperation(); - CompiledMapIterationContext.this.checkEntryNotRemovedOnThisIteration(); - } - - public void closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { - CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - } - - @NotNull - @Override - public Data value() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryValue; - } - - @NotNull - @Override - public Data key() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryKey; - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerUpdateLock; - } - - @Override - public Data wrapValueAsValue(V value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledMapIterationContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerReadLock; - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerWriteLock; - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public Data defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.remove(entry); - } - - public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { - if (CompiledMapIterationContext.this.m().constantlySizedEntry) { - return CompiledMapIterationContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); - } else if (CompiledMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { - return (sizeOfEverythingBeforeValue + (CompiledMapIterationContext.this.m().worstAlignment)) + valueSize; - } else { - return (CompiledMapIterationContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; - } - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - public MKI keyMetaInterop(K key) { - return CompiledMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); - } - - public MVI valueMetaInterop(V value) { - return CompiledMapIterationContext.this.m().metaValueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeBuffer(); - } - - private CompiledMapIterationContext _Chaining_createChaining() { - return new CompiledMapIterationContext(this); - } - public CompiledMapIterationContext createChaining() { return new CompiledMapIterationContext(this); } @@ -1221,10 +1046,205 @@ public class CompiledMapIterationContext context() { - return CompiledMapIterationContext.this; + return this; + } + + public MVI valueMetaInterop(V value) { + return this.m().metaValueInteropProvider.get(this.copies, this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + this.wrappedValueInstanceValue.closeBuffer(); + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { + this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + public MKI keyMetaInterop(K key) { + return this.h().metaKeyInteropProvider.get(this.copies, this.h().originalMetaKeyInterop, keyInterop, key); + } + + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (this.m().constantlySizedEntry) { + return this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (this.m().worstAlignment)) + valueSize; + } else { + return (this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; + } + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + } + + public void checkAccessingFromOwnerThread() { + if ((owner) != (Thread.currentThread())) { + throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + } + } + + public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { + this.closeIterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + public void checkOnEachPublicOperation() { + _CheckOnEachPublicOperation_checkOnEachPublicOperation(); + this.checkEntryNotRemovedOnThisIteration(); + } + + public void closeIterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + this.checkOnEachPublicOperation(); + return this.innerUpdateLock; + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public Data wrapValueAsValue(V value) { + this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public InterProcessLock writeLock() { + this.checkOnEachPublicOperation(); + return this.innerWriteLock; + } + + @NotNull + @Override + public Data value() { + this.checkOnEachPublicOperation(); + return this.entryValue; + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.defaultValue(absentEntry); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public Data key() { + this.checkOnEachPublicOperation(); + return this.entryKey; + } + + @NotNull + @Override + public InterProcessLock readLock() { + this.checkOnEachPublicOperation(); + return this.innerReadLock; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.insert(absentEntry, value); + } + + public long keyOffset = -1; + + public boolean keyOffsetInit() { + return (this.keyOffset) >= 0; + } + + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); + } + + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; + } + + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { + this.closeMapEntryStagesKeyEndDependants(); + this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + } + + 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 int allocatedChunks = 0; @@ -1249,21 +1269,32 @@ public class CompiledMapIterationContext= 0; } - public void initUsed(boolean used) { - this.used = used; + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); } - void closeUsed() { - if (!(this.usedInit())) + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) return ; - used = false; + this.closePosDependants(); + this.pos = -1; + } + + public void closePosDependants() { + this.closeEntryOffset(); } public long keySize = -1; @@ -1291,8 +1322,170 @@ public class CompiledMapIterationContext= 0; + } + + void initValueSizeOffset() { + valueSizeOffset = countValueSizeOffset(); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + this.closeValSize(); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); + valueSize = this.m().readValueSize(entryBytes); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSize = oldValueSize; + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); + } + + public long valueOffset() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueSize; + } + + public void closeValSize() { + if (!(this.valSizeInit())) + return ; + + this.closeValSizeDependants(); + this.valueSize = -1; + } + + public void closeValSizeDependants() { + this.closeMapEntryStagesEntryEndDependants(); + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeMapEntryStagesEntryEndDependants() { + this.closeMapEntryStagesEntrySizeDependants(); + } + + public void writeValue(Data value) { + value.writeTo(entryBS, valueOffset()); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + boolean used; + + public boolean usedInit() { + return used; + } + + public void initUsed(boolean used) { + this.used = used; + } + + void closeUsed() { + if (!(this.usedInit())) + return ; + + used = false; + } + + public boolean entryRemovedOnThisIteration = false; + + boolean entryRemovedOnThisIterationInit() { + return (this.entryRemovedOnThisIteration) != false; + } + + protected void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { + this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; + } + + public void closeEntryRemovedOnThisIteration() { + if (!(this.entryRemovedOnThisIterationInit())) + return ; + + this.entryRemovedOnThisIteration = false; } public int segmentIndex = -1; @@ -1320,9 +1513,150 @@ public class CompiledMapIterationContext 0; + } + + void initSegment() { + VanillaChronicleHash h = 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() { + this.closeEntryOffset(); + } + + public long keySizeOffset = -1; + + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; + } + + public void initEntryOffset() { + keySizeOffset = (this.entrySpaceOffset()) + ((pos()) * (this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); + } + + public long keySizeOffset() { + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + + return this.keySizeOffset; + } + + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) + return ; + + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; + } + + public void closeEntryOffsetDependants() { + this.closeMapEntryStagesEntrySizeDependants(); + } + + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBS, keyOffset()); + } + + long entrySize() { + return (entryEnd()) - (keySizeOffset()); + } + + public void closeMapEntryStagesEntrySizeDependants() { + this.closeTheEntrySizeInChunks(); + } + + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; + } + + void initTheEntrySizeInChunks() { + entrySizeInChunks = this.h().inChunks(entrySize()); + } + + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; + } + + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; + } + + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + return ; + + this.entrySizeInChunks = 0; + } + + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + entryBS.write(keySizeOffset(), entryBS, oldKeySizeOffset, bytesToCopy); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); } int hashLookupEntrySize; @@ -1346,8 +1680,8 @@ public class CompiledMapIterationContext= 0 ? pos : capacityMask2(); } - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - long indexToPos(long index) { return index * (hashLookupEntrySize()); } - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); + 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 clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long key(long entry) { + return entry & (keyMask()); + } + public void writeEntry(long pos, long prevEntry, long key, long value) { long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); NativeBytes.UNSAFE.putLong(((address()) + pos), entry); } - public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long value(long entry) { + return (entry >>> (keyBits())) & (valueMask()); + } + + 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 void putValueVolatile(long pos, long value) { @@ -1474,19 +1816,15 @@ public class CompiledMapIterationContext>> (keyBits())) & (valueMask()); - } - void forEach(EntryConsumer action) { for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { long entry = readEntry(pos); @@ -1529,52 +1863,6 @@ public class CompiledMapIterationContext 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledMapIterationContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); - } - - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.entrySpaceOffset; - } - - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.freeList; - } - - void closeSegment() { - if (!(this.segmentInit())) - return ; - - this.closeSegmentDependants(); - entrySpaceOffset = 0; - } - - public void closeSegmentDependants() { - CompiledMapIterationContext.this.closeEntryOffset(); - } - long segmentHeaderAddress; SegmentHeader segmentHeader = null; @@ -1584,7 +1872,7 @@ public class CompiledMapIterationContext= (this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = 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(this.h().inChunks(entrySize)); + this.copyExistingEntry(this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); + } + + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public final void freeExtraAllocatedChunks() { + if (((!(this.m().constantlySizedEntry)) && (this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (this.allocatedChunks()))) { + this.free(((pos()) + (entrySizeInChunks())), ((this.allocatedChunks()) - (entrySizeInChunks()))); + } else { + initTheEntrySizeInChunks(this.allocatedChunks()); + } + } + + public void writeValueAndPutPos(Data value) { + initValue(value); + freeExtraAllocatedChunks(); + this.putValueVolatile(this.hashLookupPos(), pos()); + } + + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + this.free(pos(), entrySizeInChunks()); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); } boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { - CompiledMapIterationContext c = CompiledMapIterationContext.this.contextAtIndexInChain(index); + CompiledMapIterationContext c = this.contextAtIndexInChain(index); if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { throw new IllegalStateException("Nested context not implemented yet"); } else { @@ -1626,7 +1994,27 @@ public class CompiledMapIterationContext= 0 ; i--) { if (tryFindInitLocksOfThisSegment(this, i)) return ; } - for (int i = indexOfThisContext + 1, size = CompiledMapIterationContext.this.contextChain.size() ; i < size ; i++) { + for (int i = indexOfThisContext + 1, size = this.contextChain.size() ; i < size ; i++) { if (tryFindInitLocksOfThisSegment(this, i)) return ; @@ -1692,7 +2080,7 @@ public class CompiledMapIterationContext> action) { + this.innerUpdateLock.lock(); + try { + long size = this.size(); + if (size == 0) + return true; - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } + boolean interrupted = false; + long startPos = 0L; + while (!(this.empty(this.readEntry(startPos)))) { + startPos = this.step(startPos); + } + this.initHashLookupPos(startPos); + do { + this.setHashLookupPosGuarded(this.step(this.hashLookupPos())); + long entry = this.readEntry(this.hashLookupPos()); + if (!(this.empty(entry))) { + this.readExistingEntry(this.value(entry)); + if (entryIsPresent()) { + initEntryRemovedOnThisIteration(false); + if (!(action.test(((MapEntry)(this))))) { + interrupted = true; + break; + } else { + if ((--size) == 0) + break; - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledMapIterationContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public long alloc(int chunks) { - VanillaChronicleHash 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); - } + } while ((this.hashLookupPos()) != startPos ); + return !interrupted; + } finally { + 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 deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); - } - - public void clearSegment() { - CompiledMapIterationContext.this.innerWriteLock.lock(); - CompiledMapIterationContext.this.clearHashLookup(); - freeList().clear(); - nextPosToSearchFrom(0L); - entries(0L); - } - - public void clear() { - clearSegment(); - } - - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); - } - - public long pos = -1; - - public boolean posInit() { - return (this.pos) >= 0; - } - - public void initPos(long pos) { - this.pos = pos; - this.closePosDependants(); - } - - public long pos() { - assert this.posInit() : "Pos should be init"; - return this.pos; - } - - public void closePos() { - if (!(this.posInit())) - return ; - - this.closePosDependants(); - this.pos = -1; - } - - public void closePosDependants() { - CompiledMapIterationContext.this.closeEntryOffset(); - } - - public long keySizeOffset = -1; - - public boolean entryOffsetInit() { - return (this.keySizeOffset) >= 0; - } - - public void initEntryOffset() { - keySizeOffset = (CompiledMapIterationContext.this.entrySpaceOffset()) + ((pos()) * (CompiledMapIterationContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - this.closeEntryOffsetDependants(); - } - - public long keySizeOffset() { - if (!(this.entryOffsetInit())) - this.initEntryOffset(); - - return this.keySizeOffset; - } - - public void closeEntryOffset() { - if (!(this.entryOffsetInit())) - return ; - - this.closeEntryOffsetDependants(); - this.keySizeOffset = -1; - } - - public void closeEntryOffsetDependants() { - CompiledMapIterationContext.this.closeMapEntryStagesEntrySizeDependants(); - } - - public void readExistingEntry(long pos) { - initPos(pos); - entryBytes.position(keySizeOffset()); - initKeySize(CompiledMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes)); - initKeyOffset(entryBytes.position()); - } - - public boolean entryRemovedOnThisIteration = false; - - boolean entryRemovedOnThisIterationInit() { - return (this.entryRemovedOnThisIteration) != false; - } - - protected void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { - this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; - } - - public void closeEntryRemovedOnThisIteration() { - if (!(this.entryRemovedOnThisIterationInit())) - return ; - - this.entryRemovedOnThisIteration = false; - } - - public long keyOffset = -1; - - public boolean keyOffsetInit() { - return (this.keyOffset) >= 0; - } - - public void initKeyOffset(long keyOffset) { - this.keyOffset = keyOffset; - this.closeKeyOffsetDependants(); - } - - public long keyOffset() { - assert this.keyOffsetInit() : "KeyOffset should be init"; - return this.keyOffset; - } - - public void closeKeyOffset() { - if (!(this.keyOffsetInit())) - return ; - - this.closeKeyOffsetDependants(); - this.keyOffset = -1; - } - - public void closeKeyOffsetDependants() { - CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesKeyEndDependants(); - } - - public void writeNewEntry(long pos, Data key) { - initPos(pos); - initKeySize(key.size()); - entryBytes.position(keySizeOffset()); - CompiledMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); - initKeyOffset(entryBytes.position()); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeMapEntryStagesKeyEndDependants() { - CompiledMapIterationContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); - } - - long countValueSizeOffset() { - return keyEnd(); - } - - public void closeMapEntryStagesCountValueSizeOffsetDependants() { - CompiledMapIterationContext.this.closeValueSizeOffset(); - } - - public long valueSizeOffset = -1; - - public boolean valueSizeOffsetInit() { - return (this.valueSizeOffset) >= 0; - } - - void initValueSizeOffset() { - valueSizeOffset = countValueSizeOffset(); - this.closeValueSizeOffsetDependants(); - } - - public long valueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - this.initValueSizeOffset(); - - return this.valueSizeOffset; - } - - public void closeValueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - return ; - - this.closeValueSizeOffsetDependants(); - this.valueSizeOffset = -1; - } - - public void closeValueSizeOffsetDependants() { - CompiledMapIterationContext.this.closeValSize(); - } - - public long newSizeOfEverythingBeforeValue(Data newValue) { - return ((valueSizeOffset()) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - public long valueSize = -1; - - public long valueOffset; - - public boolean valSizeInit() { - return (this.valueSize) >= 0; - } - - void initValSize() { - entryBytes.position(valueSizeOffset()); - valueSize = CompiledMapIterationContext.this.m().readValueSize(entryBytes); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSize(long valueSize) { - this.valueSize = valueSize; - entryBytes.position(valueSizeOffset()); - CompiledMapIterationContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSize = oldValueSize; - valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); - this.closeValSizeDependants(); - } - - public long valueOffset() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueSize; - } - - public void closeValSize() { - if (!(this.valSizeInit())) - return ; - - this.closeValSizeDependants(); - this.valueSize = -1; - } - - public void closeValSizeDependants() { - CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); - } - - public void writeValue(Data value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - assert oldValueSize == (value.size()); - initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); - writeValue(value); - } - - public void initValue(Data value) { - entryBytes.position(valueSizeOffset()); - initValSize(value.size()); - writeValue(value); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeMapEntryStagesEntryEndDependants() { - CompiledMapIterationContext.this.closeMapEntryStagesEntrySizeDependants(); - } - - long entrySize() { - return (entryEnd()) - (keySizeOffset()); - } - - public void closeMapEntryStagesEntrySizeDependants() { - CompiledMapIterationContext.this.closeTheEntrySizeInChunks(); - } - - public int entrySizeInChunks = 0; - - public boolean theEntrySizeInChunksInit() { - return (this.entrySizeInChunks) != 0; - } - - void initTheEntrySizeInChunks() { - entrySizeInChunks = CompiledMapIterationContext.this.h().inChunks(entrySize()); - } - - public void initTheEntrySizeInChunks(int actuallyUsedChunks) { - entrySizeInChunks = actuallyUsedChunks; - } - - public int entrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - this.initTheEntrySizeInChunks(); - - return this.entrySizeInChunks; - } - - public void closeTheEntrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - return ; - - this.entrySizeInChunks = 0; } public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledMapIterationContext.this.free(pos(), entrySizeInChunks()); - CompiledMapIterationContext.this.entries(((CompiledMapIterationContext.this.entries()) - 1L)); - CompiledMapIterationContext.this.incrementModCountGuarded(); + this.free(pos(), entrySizeInChunks()); + this.entries(((this.entries()) - 1L)); + this.incrementModCountGuarded(); } - public final void freeExtraAllocatedChunks() { - if (((!(CompiledMapIterationContext.this.m().constantlySizedEntry)) && (CompiledMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledMapIterationContext.this.allocatedChunks()))) { - CompiledMapIterationContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledMapIterationContext.this.allocatedChunks()) - (entrySizeInChunks()))); - } else { - initTheEntrySizeInChunks(CompiledMapIterationContext.this.allocatedChunks()); + @Override + public void doRemove() { + this.checkOnEachPublicOperation(); + initEntryRemovedOnThisIteration(true); + this.innerWriteLock.lock(); + try { + if ((this.remove(this.hashLookupPos())) != (this.hashLookupPos())) { + this.setHashLookupPosGuarded(this.stepBack(this.hashLookupPos())); + } + this.innerRemoveEntryExceptHashLookupUpdate(); + } finally { + this.innerWriteLock.unlock(); } } - public void copyExistingEntry(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset(); - long oldKeyOffset = keyOffset(); - initPos(newPos); - initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); - } - - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledMapIterationContext.this.h().inChunks(entrySize)); - CompiledMapIterationContext.this.copyExistingEntry(CompiledMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); - } - - public long hashLookupPos = -1; - - public boolean hashLookupPosInit() { - return (this.hashLookupPos) >= 0; - } - - public void initHashLookupPos(long hashLookupPos) { - this.hashLookupPos = hashLookupPos; - } - - public long hashLookupPos() { - assert this.hashLookupPosInit() : "HashLookupPos should be init"; - return this.hashLookupPos; - } - - public void closeHashLookupPos() { - if (!(this.hashLookupPosInit())) - return ; - - this.hashLookupPos = -1; - } - - public void putValueDeletedEntry(Data newValue) { - assert CompiledMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + public void putValueDeletedEntry(Data newValue) { + assert 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 newValueOffset = this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledMapIterationContext.this.m().inChunks(newEntrySize); + newSizeInChunks = 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 ((((pos()) + newSizeInChunks) < (this.freeList().size())) && (this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + this.innerWriteLock.lock(); + this.incrementSegmentEntriesIfNeeded(); if (newValueSizeIsDifferent) { initValue(newValue); } else { @@ -2160,40 +2179,27 @@ public class CompiledMapIterationContext value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); - } - - protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - CompiledMapIterationContext.this.free(pos(), entrySizeInChunks()); - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - CompiledMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); - writeValueAndPutPos(newValue); - } - - public void innerDefaultReplaceValue(Data newValue) { - assert CompiledMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + public void innerDefaultReplaceValue(Data newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); if (newValueSizeIsDifferent) { long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); long entryStartOffset = keySizeOffset(); - VanillaChronicleMap m = CompiledMapIterationContext.this.m(); + VanillaChronicleMap m = this.m(); long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; int newSizeInChunks = m.inChunks(newEntrySize); @@ -2201,86 +2207,45 @@ public class CompiledMapIterationContext (m.maxChunksPerEntry)) { throw new IllegalArgumentException(((((("Value too large: " + "entry takes ") + newSizeInChunks) + " chunks, ") + (m.maxChunksPerEntry)) + " is maximum.")); } - if (CompiledMapIterationContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { - CompiledMapIterationContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); + if (this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { + this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); break newValueDoesNotFit; } relocation(newValue, newSizeOfEverythingBeforeValue); return ; } else if (newSizeInChunks < (entrySizeInChunks())) { - CompiledMapIterationContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); + this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); } } else { } - CompiledMapIterationContext.this.innerWriteLock.lock(); + this.innerWriteLock.lock(); if (newValueSizeIsDifferent) { initValue(newValue); } else { writeValue(newValue); } - CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); + this.putValueVolatile(this.hashLookupPos(), pos()); } @Override - public void doReplaceValue(Data newValue) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); + public void doReplaceValue(Data newValue) { + this.checkOnEachPublicOperation(); try { - CompiledMapIterationContext.this.innerDefaultReplaceValue(newValue); + this.innerDefaultReplaceValue(newValue); } finally { - CompiledMapIterationContext.this.innerWriteLock.unlock(); + this.innerWriteLock.unlock(); } } - @Override - public void doRemove() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - initEntryRemovedOnThisIteration(true); - CompiledMapIterationContext.this.innerWriteLock.lock(); - try { - if ((CompiledMapIterationContext.this.remove(CompiledMapIterationContext.this.hashLookupPos())) != (CompiledMapIterationContext.this.hashLookupPos())) { - CompiledMapIterationContext.this.setHashLookupPosGuarded(CompiledMapIterationContext.this.stepBack(CompiledMapIterationContext.this.hashLookupPos())); - } - CompiledMapIterationContext.this.innerRemoveEntryExceptHashLookupUpdate(); - } finally { - CompiledMapIterationContext.this.innerWriteLock.unlock(); - } + public void clearSegment() { + this.innerWriteLock.lock(); + this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); } - public boolean forEachRemoving(Predicate> action) { - CompiledMapIterationContext.this.innerUpdateLock.lock(); - try { - long size = CompiledMapIterationContext.this.size(); - if (size == 0) - return true; - - boolean interrupted = false; - long startPos = 0L; - while (!(CompiledMapIterationContext.this.empty(CompiledMapIterationContext.this.readEntry(startPos)))) { - startPos = CompiledMapIterationContext.this.step(startPos); - } - CompiledMapIterationContext.this.initHashLookupPos(startPos); - do { - CompiledMapIterationContext.this.setHashLookupPosGuarded(CompiledMapIterationContext.this.step(CompiledMapIterationContext.this.hashLookupPos())); - long entry = CompiledMapIterationContext.this.readEntry(CompiledMapIterationContext.this.hashLookupPos()); - if (!(CompiledMapIterationContext.this.empty(entry))) { - CompiledMapIterationContext.this.readExistingEntry(CompiledMapIterationContext.this.value(entry)); - if (entryIsPresent()) { - initEntryRemovedOnThisIteration(false); - if (!(action.test(((MapEntry)(this))))) { - interrupted = true; - break; - } else { - if ((--size) == 0) - break; - - } - } - } - } while ((CompiledMapIterationContext.this.hashLookupPos()) != startPos ); - return !interrupted; - } finally { - CompiledMapIterationContext.this.innerReadLock.unlock(); - initEntryRemovedOnThisIteration(false); - } + public void clear() { + clearSegment(); } } 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 45e9abc50..56be52e15 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapQueryContext.java @@ -18,11 +18,10 @@ package net.openhft.chronicle.map.impl; -import net.openhft.chronicle.algo.hashing.LongHashFunction; -import net.openhft.chronicle.bytes.Access; -import net.openhft.chronicle.bytes.Accessor; -import net.openhft.chronicle.bytes.Accessor.Full; -import net.openhft.chronicle.bytes.ReadAccess; +import net.openhft.chronicle.bytes.BytesStore; +import net.openhft.chronicle.bytes.BytesUtil; +import net.openhft.chronicle.bytes.NativeBytesStore; +import net.openhft.chronicle.bytes.RandomDataInput; import net.openhft.chronicle.hash.AbstractData; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashEntry; @@ -34,9 +33,9 @@ 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.data.instance.ValueInitableData; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; -import net.openhft.chronicle.map.impl.value.instance.ValueInitableData; import net.openhft.lang.Maths; import net.openhft.lang.MemoryUnit; import net.openhft.lang.collection.DirectBitSet; @@ -54,26 +53,25 @@ import java.util.ConcurrentModificationException; import java.util.List; import java.util.concurrent.TimeUnit; -public class CompiledMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , MapAbsentEntryHolder , QueryContextInterface , VanillaChronicleMapHolder { +public class CompiledMapQueryContext, V, VI, MVI extends MetaBytesInterop, R> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , MapAbsentEntryHolder , QueryContextInterface , VanillaChronicleMapHolder { public void close() { - CompiledMapQueryContext.this.closeKeyOffset(); - CompiledMapQueryContext.this.closeInputKey(); - CompiledMapQueryContext.this.wrappedValueInstanceValue.closeNext(); - CompiledMapQueryContext.this.wrappedValueInstanceValue.closeValue(); - CompiledMapQueryContext.this.closeInputBytes(); - CompiledMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); - CompiledMapQueryContext.this.closePos(); - CompiledMapQueryContext.this.closeKeySize(); - CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); - CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledMapQueryContext.this.closeAllocatedChunks(); - CompiledMapQueryContext.this.closeUsed(); - CompiledMapQueryContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); - CompiledMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); - CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + this.wrappedValueInstanceValue.closeValue(); + this.inputValueInstanceValue.closeValue(); + this.closeInputBytes(); + this.wrappedValueInstanceValue.closeNext(); + this.usingReturnValue.closeUsingReturnValue(); + this.defaultReturnValue.closeDefaultReturnedValue(); + this.closeUsed(); + this.closeKeySize(); + this.inputKeyInstanceValue.closeKey(); + this.closePos(); + this.closeInputKey(); + this.closeAllocatedChunks(); + this.closeKeyOffset(); + this.closeKeyBytesInteropKeyMetaInteropDependants(); + this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); + this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + this.closeValueBytesInteropValueMetaInteropDependants(); } public void incrementModCountGuarded() { @@ -97,7 +95,7 @@ public class CompiledMapQueryContext m) { - contextChain = new ArrayList(); + contextChain = new ArrayList(); contextChain.add(this); indexInContextChain = 0; this.m = m; - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.entryKey = new EntryKeyBytesData(); - this.inputValueInstanceValue = new InputValueInstanceData(); - this.inputFirstValueBytesValue = new InputFirstValueBytesData(); - this.innerWriteLock = new WriteLock(); - this.copies = ThreadLocalCopies.get(); - this.valueInterop = CompiledMapQueryContext.this.m().valueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueInterop); - this.valueReader = CompiledMapQueryContext.this.m().valueReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueReader); - this.keyInterop = CompiledMapQueryContext.this.h().keyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyInterop); - this.keyReader = CompiledMapQueryContext.this.h().keyReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyReader); - this.usingReturnValue = new UsingReturnValue(); this.inputKeyBytesValue = new InputKeyBytesData(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesData(); - this.innerUpdateLock = new UpdateLock(); - this.entryBytes = CompiledMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.innerReadLock = new ReadLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.entryValue = new EntryValueBytesData(); - this.owner = Thread.currentThread(); - this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.inputValueInstanceValue = new InputValueInstanceData(); + this.copies = ThreadLocalCopies.get(); + this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.usingReturnValue = new UsingReturnValue(); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.innerReadLock = new ReadLock(); + this.inputStore = new JavaLangBytesReusableBytesStore(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); } public CompiledMapQueryContext(CompiledMapQueryContext c) { @@ -145,31 +142,30 @@ public class CompiledMapQueryContext)(c.m)); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.entryKey = new EntryKeyBytesData(); - this.inputValueInstanceValue = new InputValueInstanceData(); - this.inputFirstValueBytesValue = new InputFirstValueBytesData(); - this.innerWriteLock = new WriteLock(); - this.copies = ThreadLocalCopies.get(); - this.valueInterop = CompiledMapQueryContext.this.m().valueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueInterop); - this.valueReader = CompiledMapQueryContext.this.m().valueReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueReader); - this.keyInterop = CompiledMapQueryContext.this.h().keyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyInterop); - this.keyReader = CompiledMapQueryContext.this.h().keyReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyReader); - this.usingReturnValue = new UsingReturnValue(); this.inputKeyBytesValue = new InputKeyBytesData(); this.defaultReturnValue = new DefaultReturnValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesData(); - this.innerUpdateLock = new UpdateLock(); - this.entryBytes = CompiledMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.innerReadLock = new ReadLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.entryValue = new EntryValueBytesData(); - this.owner = Thread.currentThread(); - this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.inputValueInstanceValue = new InputValueInstanceData(); + this.copies = ThreadLocalCopies.get(); + this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.usingReturnValue = new UsingReturnValue(); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.innerReadLock = new ReadLock(); + this.inputStore = new JavaLangBytesReusableBytesStore(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); } public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { @@ -181,14 +177,26 @@ public class CompiledMapQueryContext entry = CompiledMapQueryContext.this.entry(); - if (entry != null) { - CompiledMapQueryContext.this.replaceValue(entry, CompiledMapQueryContext.this.wrapValueAsValue(newValue)); - } else { - CompiledMapQueryContext.this.insert(CompiledMapQueryContext.this.absentEntry(), CompiledMapQueryContext.this.wrapValueAsValue(newValue)); - } - return true; - } - - @Override - public void close() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - put(CompiledMapQueryContext.this.usingReturnValue.returnValue()); - CompiledMapQueryContext.this.close(); - } - @Override public boolean remove() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); @@ -268,21 +245,40 @@ 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 V get() { + assert containsKey(); + return CompiledMapQueryContext.this.usingReturnValue.returnValue(); + } + + @Override + public void close() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + put(CompiledMapQueryContext.this.usingReturnValue.returnValue()); + CompiledMapQueryContext.this.close(); } } @@ -293,12 +289,6 @@ 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(); + } + + @NotNull + @Override + public Bytes entry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytes; + } + + @Override + public long keyOffset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keyOffset(); + } + + @NotNull + @Override + public K key() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.queriedKey().get(); } @Override @@ -369,36 +370,37 @@ 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; } } - public class EntryKeyBytesData extends AbstractData { + public class EntryKeyBytesData extends AbstractData { + @Override + public long offset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keyOffset(); + } + @Override public long size() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); @@ -406,25 +408,7 @@ public class CompiledMapQueryContext access() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccess; - } - - @Override - public T handle() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessHandle; - } - - @Override - public long offset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()); + this.closeEntryKeyBytesDataInnerGetUsingDependants(); } private K innerGetUsing(K usingKey) { @@ -433,13 +417,7 @@ public class CompiledMapQueryContext { - @Override - public ReadAccess access() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccess; - } - - @Override - public T handle() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessHandle; - } - + public class EntryValueBytesData extends AbstractData { @Override public long offset() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.valueOffset()); + return CompiledMapQueryContext.this.valueOffset(); } @Override @@ -502,7 +480,7 @@ public class CompiledMapQueryContext { + public class InputFirstValueBytesData extends AbstractData { + @Override + public RandomDataInput bytes() { + return CompiledMapQueryContext.this.inputStore; + } + + @Override + public long offset() { + return CompiledMapQueryContext.this.firstInputValueOffset(); + } + @Override public long size() { return CompiledMapQueryContext.this.firstInputValueSize(); } public void closeInputFirstValueBytesDataSizeDependants() { - InputFirstValueBytesData.this.closeInputFirstValueBytesDataGetUsingDependants(); + this.closeInputFirstValueBytesDataGetUsingDependants(); } @Override @@ -571,7 +565,7 @@ public class CompiledMapQueryContext { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); + public RandomDataInput bytes() { + return CompiledMapQueryContext.this.inputStore; } @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.firstInputValueOffset()); + return CompiledMapQueryContext.this.inputKeyOffset(); } - @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); - } - } - - public class InputKeyBytesData extends AbstractData { @Override public long size() { return CompiledMapQueryContext.this.inputKeySize(); } public void closeInputKeyBytesDataSizeDependants() { - InputKeyBytesData.this.closeInputKeyBytesDataGetUsingDependants(); + this.closeInputKeyBytesDataGetUsingDependants(); } @Override @@ -640,7 +629,7 @@ public class CompiledMapQueryContext { + @Override + public RandomDataInput bytes() { + return CompiledMapQueryContext.this.inputStore; + } @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.inputKeyOffset()); - } - - @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); - } - - @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); - } - } - - public class InputSecondValueBytesData extends AbstractData { - @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); + return CompiledMapQueryContext.this.secondInputValueOffset(); } @Override @@ -703,17 +682,7 @@ public class CompiledMapQueryContext access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); + this.closeInputSecondValueBytesDataGetUsingDependants(); } @Override @@ -723,7 +692,7 @@ public class CompiledMapQueryContext { + public class WrappedValueInstanceData extends CopyingInstanceData { public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); @@ -944,6 +913,18 @@ public class CompiledMapQueryContext { @Override public void returnValue(@NotNull - Data value) { + Data value) { initDefaultReturnedValue(value); } @@ -1275,7 +1259,7 @@ public class CompiledMapQueryContext value) { + Data value) { defaultReturnedValue = value.getUsing(null); } @@ -1301,7 +1285,7 @@ public class CompiledMapQueryContext implements KeyInitableData { + public class InputKeyInstanceData extends CopyingInstanceData implements KeyInitableData { private K key = null; public boolean keyInit() { @@ -1328,7 +1312,12 @@ public class CompiledMapQueryContext implements ValueInitableData { + public class InputValueInstanceData extends CopyingInstanceData implements ValueInitableData { private V value = null; public boolean valueInit() { @@ -1401,7 +1385,12 @@ public class CompiledMapQueryContext { @Override public void returnValue(@NotNull - Data value) { + Data value) { initReturnedValue(value); } @@ -1480,7 +1464,7 @@ public class CompiledMapQueryContext value) { + Data value) { returnedValue = value.getUsing(usingReturnValue()); } @@ -1588,7 +1572,7 @@ public class CompiledMapQueryContext contextChain; + public final List contextChain; public final UpdateLock innerUpdateLock; @@ -1596,45 +1580,45 @@ public class CompiledMapQueryContext contextChain() { + public List contextChain() { return this.contextChain; } public final ThreadLocalCopies copies; + final EntryKeyBytesData entryKey; + + public EntryKeyBytesData entryKey() { + return this.entryKey; + } + public ThreadLocalCopies copies() { return this.copies; } private void countValueOffset() { - CompiledMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); + this.m().alignment.alignPositionAddr(entryBytes); valueOffset = entryBytes.position(); } - final EntryKeyBytesData entryKey; - - public EntryKeyBytesData entryKey() { - return this.entryKey; - } - public final UsingReturnValue usingReturnValue; public UsingReturnValue usingReturnValue() { return this.usingReturnValue; } - public final DefaultReturnValue defaultReturnValue; - - public DefaultReturnValue defaultReturnValue() { - return this.defaultReturnValue; - } - public final InputKeyBytesData inputKeyBytesValue; public InputKeyBytesData inputKeyBytesValue() { return this.inputKeyBytesValue; } + public final DefaultReturnValue defaultReturnValue; + + public DefaultReturnValue defaultReturnValue() { + return this.defaultReturnValue; + } + public final EntryValueBytesData entryValue; public EntryValueBytesData entryValue() { @@ -1649,6 +1633,12 @@ public class CompiledMapQueryContext entryBytesAccessor; + public final BytesStore entryBS; - public Full entryBytesAccessor() { - return this.entryBytesAccessor; - } - - @SuppressWarnings(value = "unchecked") - public final T entryBytesAccessHandle; - - public T entryBytesAccessHandle() { - return this.entryBytesAccessHandle; + public BytesStore entryBS() { + return this.entryBS; } public final BytesReader valueReader; @@ -1716,67 +1699,15 @@ public class CompiledMapQueryContext entryBytesAccess; - - public Access entryBytesAccess() { - return this.entryBytesAccess; - } - public final BytesReader keyReader; public BytesReader keyReader() { return this.keyReader; } - 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 void checkAccessingFromOwnerThread() { - if ((owner) != (Thread.currentThread())) { - throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); - } - } - - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - public MKI keyMetaInterop(K key) { - return CompiledMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); - } - - public void closeKeyBytesInteropKeyMetaInteropDependants() { - CompiledMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); - } - - public long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); - } - - public void closeMapEntryStagesEntryBytesAccessOffsetDependants() { - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - } - @Override public MapAbsentEntry absent() { - return CompiledMapQueryContext.this; - } - - public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { - if (CompiledMapQueryContext.this.m().constantlySizedEntry) { - return CompiledMapQueryContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); - } else if (CompiledMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { - return (sizeOfEverythingBeforeValue + (CompiledMapQueryContext.this.m().worstAlignment)) + valueSize; - } else { - return (CompiledMapQueryContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; - } - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + return this; } @Override @@ -1789,8 +1720,42 @@ public class CompiledMapQueryContextT contextAtIndexInChain(int index) { return ((T)(contextChain.get(index))); } public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); } - boolean used; - - public boolean usedInit() { - return used; + public MKI keyMetaInterop(K key) { + return this.h().metaKeyInteropProvider.get(this.copies, this.h().originalMetaKeyInterop, keyInterop, key); } - public void initUsed(boolean used) { - this.used = used; + public void closeKeyBytesInteropKeyMetaInteropDependants() { + this.inputKeyInstanceValue.closeBuffer(); } - void closeUsed() { - if (!(this.usedInit())) + public long keyOffset = -1; + + public boolean keyOffsetInit() { + return (this.keyOffset) >= 0; + } + + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); + } + + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; + } + + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) return ; - used = false; + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { + this.closeMapEntryStagesKeyEndDependants(); + this.closeMapQueryKeyEqualsDependants(); + this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); } public int allocatedChunks = 0; @@ -1866,237 +1843,18 @@ public class CompiledMapQueryContext= 0; - } - - public void initKeySize(long keySize) { - this.keySize = keySize; - this.closeKeySizeDependants(); - } - - public long keySize() { - assert this.keySizeInit() : "KeySize should be init"; - return this.keySize; - } - - public void closeKeySize() { - if (!(this.keySizeInit())) - return ; - - this.closeKeySizeDependants(); - this.keySize = -1; - } - - public void closeKeySizeDependants() { - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - } - - public long pos = -1; - - public boolean posInit() { - return (this.pos) >= 0; - } - - public void initPos(long pos) { - this.pos = pos; - this.closePosDependants(); - } - - public long pos() { - assert this.posInit() : "Pos should be init"; - return this.pos; - } - - public void closePos() { - if (!(this.posInit())) - return ; - - this.closePosDependants(); - this.pos = -1; - } - - public void closePosDependants() { - CompiledMapQueryContext.this.closeEntryOffset(); - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - public Bytes inputBytes = null; - - public boolean inputBytesInit() { - return (this.inputBytes) != null; - } - - public void initInputBytes(Bytes inputBytes) { - this.inputBytes = inputBytes; - this.closeInputBytesDependants(); - } - - public Bytes inputBytes() { - assert this.inputBytesInit() : "InputBytes should be init"; - return this.inputBytes; - } - - public void closeInputBytes() { - if (!(this.inputBytesInit())) - return ; - - this.closeInputBytesDependants(); - this.inputBytes = null; - } - - public void closeInputBytesDependants() { - CompiledMapQueryContext.this.closeInputKeyOffsets(); - CompiledMapQueryContext.this.closeFirstInputValueOffsets(); - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.closeSecondInputValueOffsets(); - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); - } - - public long inputKeySize = -1; - - public long inputKeyOffset; - - public boolean inputKeyOffsetsInit() { - return (this.inputKeySize) >= 0; - } - - private void initInputKeyOffsets() { - inputKeySize = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(inputBytes()); - inputKeyOffset = inputBytes().position(); - this.closeInputKeyOffsetsDependants(); - } - - public long inputKeyOffset() { - if (!(this.inputKeyOffsetsInit())) - this.initInputKeyOffsets(); - - return this.inputKeyOffset; - } - - public long inputKeySize() { - if (!(this.inputKeyOffsetsInit())) - this.initInputKeyOffsets(); - - return this.inputKeySize; - } - - public void closeInputKeyOffsets() { - if (!(this.inputKeyOffsetsInit())) - return ; - - this.closeInputKeyOffsetsDependants(); - this.inputKeySize = -1; - } - - public void closeInputKeyOffsetsDependants() { - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); - CompiledMapQueryContext.this.closeFirstInputValueOffsets(); - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); - } - - public long firstInputValueSize = -1; - - public long firstInputValueOffset; - - public boolean firstInputValueOffsetsInit() { - return (this.firstInputValueSize) >= 0; - } - - private void initFirstInputValueOffsets() { - CompiledMapQueryContext.this.inputBytes().position(((CompiledMapQueryContext.this.inputKeyOffset()) + (CompiledMapQueryContext.this.inputKeySize()))); - firstInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); - firstInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); - this.closeFirstInputValueOffsetsDependants(); - } - - public long firstInputValueOffset() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueOffset; - } - - public long firstInputValueSize() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueSize; - } - - public void closeFirstInputValueOffsets() { - if (!(this.firstInputValueOffsetsInit())) - return ; - - this.closeFirstInputValueOffsetsDependants(); - this.firstInputValueSize = -1; - } - - public void closeFirstInputValueOffsetsDependants() { - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); - CompiledMapQueryContext.this.closeSecondInputValueOffsets(); - } - - public long secondInputValueSize = -1; - - public long secondInputValueOffset; - - public boolean secondInputValueOffsetsInit() { - return (this.secondInputValueSize) >= 0; - } - - private void initSecondInputValueOffsets() { - CompiledMapQueryContext.this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); - secondInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); - secondInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); - this.closeSecondInputValueOffsetsDependants(); - } - - public long secondInputValueOffset() { - if (!(this.secondInputValueOffsetsInit())) - this.initSecondInputValueOffsets(); - - return this.secondInputValueOffset; - } - - public long secondInputValueSize() { - if (!(this.secondInputValueOffsetsInit())) - this.initSecondInputValueOffsets(); - - return this.secondInputValueSize; - } - - public void closeSecondInputValueOffsets() { - if (!(this.secondInputValueOffsetsInit())) - return ; - - this.closeSecondInputValueOffsetsDependants(); - this.secondInputValueSize = -1; - } - - public void closeSecondInputValueOffsetsDependants() { - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); - } - - public Data inputKey = null; + public Data inputKey = null; public boolean inputKeyInit() { return (this.inputKey) != null; } - public void initInputKey(Data inputKey) { + public void initInputKey(Data inputKey) { this.inputKey = inputKey; this.closeInputKeyDependants(); } - public Data inputKey() { + public Data inputKey() { assert this.inputKeyInit() : "InputKey should be init"; return this.inputKey; } @@ -2110,8 +1868,8 @@ public class CompiledMapQueryContext 0; } - private void initSegHeader() { - segmentHeaderAddress = (CompiledMapQueryContext.this.h().ms.address()) + (CompiledMapQueryContext.this.h().segmentHeaderOffset(segmentIndex())); - segmentHeader = BigSegmentHeader.INSTANCE; - this.closeSegHeaderDependants(); + void initSegment() { + VanillaChronicleHash h = 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 segmentHeaderAddress() { - if (!(this.segHeaderInit())) - this.initSegHeader(); + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); - return this.segmentHeaderAddress; + return this.entrySpaceOffset; } - public SegmentHeader segmentHeader() { - if (!(this.segHeaderInit())) - this.initSegHeader(); + public SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); - return this.segmentHeader; + return this.freeList; } - public void closeSegHeader() { - if (!(this.segHeaderInit())) + void closeSegment() { + if (!(this.segmentInit())) return ; - this.closeSegHeaderDependants(); - this.segmentHeader = null; + this.closeSegmentDependants(); + entrySpaceOffset = 0; } - public void closeSegHeaderDependants() { - CompiledMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); - CompiledMapQueryContext.this.closeLocks(); - CompiledMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); - } - - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } - - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledMapQueryContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public long entries() { - return segmentHeader().size(segmentHeaderAddress()); - } - - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { - CompiledMapQueryContext c = CompiledMapQueryContext.this.contextAtIndexInChain(index); - if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { - throw new IllegalStateException("Nested context not implemented yet"); - } else { - return false; - } - } - - public void closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants() { - CompiledMapQueryContext.this.closeLocks(); - } - - int totalReadLockCount; - - int totalUpdateLockCount; - - int totalWriteLockCount; - - public int latestSameThreadSegmentModCount; - - public int contextModCount; - - CompiledMapQueryContext nextNode; - - public boolean concurrentSameThreadContexts; - - LocalLockState localLockState; - - public CompiledMapQueryContext rootContextOnThisSegment = null; - - public boolean locksInit() { - return (this.rootContextOnThisSegment) != null; - } - - void initLocks() { - localLockState = LocalLockState.UNLOCKED; - int indexOfThisContext = CompiledMapQueryContext.this.indexInContextChain; - for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - for (int i = indexOfThisContext + 1, size = CompiledMapQueryContext.this.contextChain.size() ; i < size ; i++) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - rootContextOnThisSegment = this; - concurrentSameThreadContexts = false; - latestSameThreadSegmentModCount = 0; - contextModCount = 0; - nextNode = null; - totalReadLockCount = 0; - totalUpdateLockCount = 0; - totalWriteLockCount = 0; - this.closeLocksDependants(); - } - - public boolean concurrentSameThreadContexts() { - if (!(this.locksInit())) - this.initLocks(); - - return this.concurrentSameThreadContexts; - } - - public int contextModCount() { - if (!(this.locksInit())) - this.initLocks(); - - return this.contextModCount; - } - - public int latestSameThreadSegmentModCount() { - if (!(this.locksInit())) - this.initLocks(); - - return this.latestSameThreadSegmentModCount; - } - - public LocalLockState localLockState() { - if (!(this.locksInit())) - this.initLocks(); - - return this.localLockState; - } - - public CompiledMapQueryContext rootContextOnThisSegment() { - if (!(this.locksInit())) - this.initLocks(); - - return this.rootContextOnThisSegment; - } - - void closeLocks() { - if (!(this.locksInit())) - return ; - - this.closeLocksDependants(); - if ((rootContextOnThisSegment) == this) { - closeRootLocks(); - } else { - closeNestedLocks(); - } - localLockState = null; - rootContextOnThisSegment = null; - } - - public void closeLocksDependants() { - CompiledMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); - } - - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); + public void closeSegmentDependants() { + this.closeEntryOffset(); } int hashLookupEntrySize; @@ -2394,8 +2007,8 @@ public class CompiledMapQueryContext= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + this.closeHashLookupReadEntryDependants(); + this.closeHashLookupStepDependants(); + this.closeHashLookupStepBackDependants(); + this.closeHashLookupIndexToPosDependants(); + this.closeHashLookupMaskUnsetKeyDependants(); + this.closeHashLookupKeyDependants(); + this.closeHashLookupValueDependants(); + this.closeHashLookupHlPosDependants(); + this.closeHashLookupEmptyDependants(); } public long readEntry(long pos) { @@ -2507,34 +2098,24 @@ public class CompiledMapQueryContext= 0 ? pos : capacityMask2(); } - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + public void closeHashLookupStepBackDependants() { + this.closeHashLookupSearchFoundDependants(); } long indexToPos(long index) { @@ -2542,39 +2123,15 @@ public class CompiledMapQueryContext sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); + public void closeHashLookupMaskUnsetKeyDependants() { + this.closeSearchKey(); } long entry(long key, long value) { @@ -2586,18 +2143,67 @@ public class CompiledMapQueryContext>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + this.closeHashLookupSearchNextPosDependants(); + this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void closeHashLookupHlPosDependants() { + this.closeSearchKey(); + } + + 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 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 void closeHashLookupStepDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + public void closeHashLookupEmptyDependants() { + this.closeHashLookupSearchNextPosDependants(); } public long remove(long posToRemove) { @@ -2622,106 +2228,82 @@ public class CompiledMapQueryContext sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); } - long entrySpaceOffset = 0; + long segmentHeaderAddress; - MultiStoreBytes freeListBytes = new MultiStoreBytes(); + SegmentHeader segmentHeader = null; - public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); - - boolean segmentInit() { - return (entrySpaceOffset) > 0; + public boolean segHeaderInit() { + return (this.segmentHeader) != null; } - void initSegment() { - VanillaChronicleHash h = CompiledMapQueryContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); + private void initSegHeader() { + segmentHeaderAddress = (this.h().ms.address()) + (this.h().segmentHeaderOffset(segmentIndex())); + segmentHeader = BigSegmentHeader.INSTANCE; + this.closeSegHeaderDependants(); } - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); + public long segmentHeaderAddress() { + if (!(this.segHeaderInit())) + this.initSegHeader(); - return this.entrySpaceOffset; + return this.segmentHeaderAddress; } - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); + public SegmentHeader segmentHeader() { + if (!(this.segHeaderInit())) + this.initSegHeader(); - return this.freeList; + return this.segmentHeader; } - void closeSegment() { - if (!(this.segmentInit())) + public void closeSegHeader() { + if (!(this.segHeaderInit())) return ; - this.closeSegmentDependants(); - entrySpaceOffset = 0; + this.closeSegHeaderDependants(); + this.segmentHeader = null; } - public void closeSegmentDependants() { - CompiledMapQueryContext.this.closeEntryOffset(); + public void closeSegHeaderDependants() { + this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + this.closeLocks(); + this.innerReadLock.closeReadLockLockDependants(); } - public long keySizeOffset = -1; - - public boolean entryOffsetInit() { - return (this.keySizeOffset) >= 0; + public void nextPosToSearchFrom(long nextPosToSearchFrom) { + segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); } - public void initEntryOffset() { - keySizeOffset = (CompiledMapQueryContext.this.entrySpaceOffset()) + ((pos()) * (CompiledMapQueryContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - this.closeEntryOffsetDependants(); + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); } - public long keySizeOffset() { - if (!(this.entryOffsetInit())) - this.initEntryOffset(); - - return this.keySizeOffset; - } - - public void closeEntryOffset() { - if (!(this.entryOffsetInit())) - return ; - - this.closeEntryOffsetDependants(); - this.keySizeOffset = -1; - } - - public void closeEntryOffsetDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesReadExistingEntryDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); - } - - public void readExistingEntry(long pos) { - initPos(pos); - entryBytes.position(keySizeOffset()); - initKeySize(CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes)); - initKeyOffset(entryBytes.position()); - } - - public void closeMapEntryStagesReadExistingEntryDependants() { - CompiledMapQueryContext.this.closeKeySearch(); + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); } public long alloc(int chunks) { - VanillaChronicleHash h = CompiledMapQueryContext.this.h(); + VanillaChronicleHash h = this.h(); if (chunks > (h.maxChunksPerEntry)) throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); @@ -2757,9 +2339,142 @@ public class CompiledMapQueryContext= 0 ; i--) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + for (int i = indexOfThisContext + 1, size = this.contextChain.size() ; i < size ; i++) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + rootContextOnThisSegment = this; + concurrentSameThreadContexts = false; + latestSameThreadSegmentModCount = 0; + contextModCount = 0; + nextNode = null; + totalReadLockCount = 0; + totalUpdateLockCount = 0; + totalWriteLockCount = 0; + this.closeLocksDependants(); + } + + public boolean concurrentSameThreadContexts() { + if (!(this.locksInit())) + this.initLocks(); + + return this.concurrentSameThreadContexts; + } + + public int contextModCount() { + if (!(this.locksInit())) + this.initLocks(); + + return this.contextModCount; + } + + public int latestSameThreadSegmentModCount() { + if (!(this.locksInit())) + this.initLocks(); + + return this.latestSameThreadSegmentModCount; + } + + public LocalLockState localLockState() { + if (!(this.locksInit())) + this.initLocks(); + + return this.localLockState; + } + + public CompiledMapQueryContext rootContextOnThisSegment() { + if (!(this.locksInit())) + this.initLocks(); + + return this.rootContextOnThisSegment; + } + + void closeLocks() { + if (!(this.locksInit())) + return ; + + this.closeLocksDependants(); + if ((rootContextOnThisSegment) == (this)) { + closeRootLocks(); + } else { + closeNestedLocks(); + } + localLockState = null; + rootContextOnThisSegment = null; + } + + public void closeLocksDependants() { + this.innerReadLock.closeReadLockLockDependants(); + this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + public void clearSegment() { - CompiledMapQueryContext.this.innerWriteLock.lock(); - CompiledMapQueryContext.this.clearHashLookup(); + this.innerWriteLock.lock(); + this.clearHashLookup(); freeList().clear(); nextPosToSearchFrom(0L); entries(0L); @@ -2778,8 +2493,8 @@ public class CompiledMapQueryContext= 0; + public void putNewVolatile(long value) { + this.checkValueForPut(value); + long currentEntry = this.readEntry(this.hashLookupPos()); + this.writeEntryVolatile(this.hashLookupPos(), currentEntry, searchKey(), value); } - public void initKeyOffset(long keyOffset) { - this.keyOffset = keyOffset; - this.closeKeyOffsetDependants(); + void put(long value) { + this.checkValueForPut(value); + this.writeEntry(this.hashLookupPos(), this.readEntry(this.hashLookupPos()), searchKey(), value); } - public long keyOffset() { - assert this.keyOffsetInit() : "KeyOffset should be init"; - return this.keyOffset; + public void found() { + this.setHashLookupPosGuarded(this.stepBack(this.hashLookupPos())); } - public void closeKeyOffset() { - if (!(this.keyOffsetInit())) + public void closeHashLookupSearchFoundDependants() { + this.closeKeySearch(); + } + + public boolean checkSlotContainsExpectedKeyAndValue(long value) { + long entry = this.readEntry(this.hashLookupPos()); + return ((this.key(entry)) == (searchKey())) && ((this.value(entry)) == value); + } + + public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { + this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public void remove() { + this.setHashLookupPosGuarded(this.remove(this.hashLookupPos())); + } + + public boolean checkSlotIsEmpty() { + return this.empty(this.readEntry(this.hashLookupPos())); + } + + public long pos = -1; + + public boolean posInit() { + return (this.pos) >= 0; + } + + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); + } + + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) return ; - this.closeKeyOffsetDependants(); - this.keyOffset = -1; + this.closePosDependants(); + this.pos = -1; } - public void closeKeyOffsetDependants() { - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + public void closePosDependants() { + this.closeEntryOffset(); + this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); } - public void writeNewEntry(long pos, Data key) { + public long keySizeOffset = -1; + + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; + } + + public void initEntryOffset() { + keySizeOffset = (this.entrySpaceOffset()) + ((pos()) * (this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); + } + + public long keySizeOffset() { + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + + return this.keySizeOffset; + } + + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) + return ; + + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; + } + + public void closeEntryOffsetDependants() { + this.closeMapEntryStagesEntrySizeDependants(); + this.closeMapEntryStagesReadExistingEntryDependants(); + } + + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + entryBS.write(keySizeOffset(), entryBS, oldKeySizeOffset, bytesToCopy); + } + + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); + } + + public void closeMapEntryStagesReadExistingEntryDependants() { + this.closeKeySearch(); + } + + public long keySize = -1; + + public boolean keySizeInit() { + return (this.keySize) >= 0; + } + + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); + } + + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; + } + + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; + } + + public void closeKeySizeDependants() { + this.closeMapEntryStagesKeyEndDependants(); + this.closeMapQueryKeyEqualsDependants(); + this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + public void writeNewEntry(long pos, Data key) { initPos(pos); initKeySize(key.size()); entryBytes.position(keySizeOffset()); - CompiledMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); initKeyOffset(entryBytes.position()); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); - } - - boolean keyEquals() { - return ((inputKey().size()) == (CompiledMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledMapQueryContext.this.entryBytesAccess)), CompiledMapQueryContext.this.entryBytesAccessHandle, CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()))); - } - - public void closeMapQueryKeyEqualsDependants() { - CompiledMapQueryContext.this.closeKeySearch(); - } - - protected SearchState searchState = null; - - boolean keySearchInit() { - return (this.searchState) != null; - } - - void initKeySearch() { - for (long pos ; (pos = CompiledMapQueryContext.this.nextPos()) >= 0L ; ) { - CompiledMapQueryContext.this.readExistingEntry(pos); - if (!(keyEquals())) - continue; - - CompiledMapQueryContext.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() { - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - } - - private void _AllocatedChunks_incrementSegmentEntriesIfNeeded() { - } - - public void incrementSegmentEntriesIfNeeded() { - if ((CompiledMapQueryContext.this.searchState()) != (SearchState.PRESENT)) { - CompiledMapQueryContext.this.entries(((CompiledMapQueryContext.this.entries()) + 1L)); - } - } - - public void initEntryAndKey(long entrySize) { - initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); - CompiledMapQueryContext.this.writeNewEntry(CompiledMapQueryContext.this.alloc(allocatedChunks()), CompiledMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - - public boolean searchStateDeleted() { - return (((searchState()) == (SearchState.DELETED)) && (!(CompiledMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); - } - - public void dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed() { - if (CompiledMapQueryContext.this.locksInit()) { - if ((CompiledMapQueryContext.this.concurrentSameThreadContexts()) && ((CompiledMapQueryContext.this.rootContextOnThisSegment().latestSameThreadSegmentModCount()) != (CompiledMapQueryContext.this.contextModCount()))) { - if (keySearchInit()) { - if ((searchState()) == (SearchState.PRESENT)) { - if (!(CompiledMapQueryContext.this.checkSlotContainsExpectedKeyAndValue(CompiledMapQueryContext.this.pos()))) - CompiledMapQueryContext.this.closeHashLookupPos(); - - } - } - } - } - } - - public void closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants() { - CompiledMapQueryContext.this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - - private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { - CompiledMapQueryContext.this.checkAccessingFromOwnerThread(); - } - - public void checkOnEachPublicOperation() { - _CheckOnEachPublicOperation_checkOnEachPublicOperation(); - CompiledMapQueryContext.this.dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed(); - } - - public void closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public Data defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.innerWriteLock; - } - - @Override - public Data wrapValueAsValue(V value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.innerUpdateLock; - } - - @NotNull - @Override - public Data value() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryValue; - } - - public Data queriedKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public Data absentKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.inputKey(); - } - - @NotNull - @Override - public Data key() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryKey; - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.innerReadLock; - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @NotNull - @Override - public Data defaultValue() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); - } - - @NotNull - @Override - public MapContext context() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return this; - } - - public boolean searchStatePresent() { - return (searchState()) == (SearchState.PRESENT); - } - - public boolean searchStateAbsent() { - return (!(searchStatePresent())) && (!(searchStateDeleted())); - } - - protected 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(); - - } - - public boolean entryPresent() { - return searchStatePresent(); - } - - @Nullable - @Override - public MapAbsentEntry absentEntry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledMapQueryContext.this.absent(); - } - - @Override - public MapEntry entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; + key.writeTo(entryBS, keyOffset()); } public long keyEnd() { @@ -3193,8 +2755,8 @@ public class CompiledMapQueryContext newValue) { - return ((valueSizeOffset()) + (CompiledMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + this.closeValSize(); } public long valueSize = -1; @@ -3249,7 +2807,7 @@ public class CompiledMapQueryContext value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - assert oldValueSize == (value.size()); - initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); - writeValue(value); - } - - public void initValue(Data value) { - entryBytes.position(valueSizeOffset()); - initValSize(value.size()); - writeValue(value); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); + this.closeMapEntryStagesEntryEndDependants(); + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); } protected long entryEnd() { @@ -3321,7 +2859,7 @@ public class CompiledMapQueryContext value) { - assert CompiledMapQueryContext.this.searchStateAbsent(); - long entrySize = CompiledMapQueryContext.this.entrySize(CompiledMapQueryContext.this.inputKey().size(), value.size()); - CompiledMapQueryContext.this.initEntryAndKey(entrySize); - CompiledMapQueryContext.this.initValue(value); - CompiledMapQueryContext.this.freeExtraAllocatedChunks(); - CompiledMapQueryContext.this.putNewVolatile(CompiledMapQueryContext.this.pos()); - } - - public void writeValueAndPutPos(Data value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); - } - public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledMapQueryContext.this.free(pos(), entrySizeInChunks()); - CompiledMapQueryContext.this.entries(((CompiledMapQueryContext.this.entries()) - 1L)); - CompiledMapQueryContext.this.incrementModCountGuarded(); + this.free(pos(), entrySizeInChunks()); + this.entries(((this.entries()) - 1L)); + this.incrementModCountGuarded(); } - @Override - public void doRemove() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - CompiledMapQueryContext.this.innerUpdateLock.lock(); - if (searchStatePresent()) { - CompiledMapQueryContext.this.innerWriteLock.lock(); - CompiledMapQueryContext.this.remove(); - CompiledMapQueryContext.this.innerRemoveEntryExceptHashLookupUpdate(); - setSearchStateGuarded(SearchState.DELETED); - } else { - throw new IllegalStateException("Entry is absent when doRemove() is called"); + public void writeValue(Data value) { + value.writeTo(entryBS, valueOffset()); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + public void writeValueAndPutPos(Data value) { + initValue(value); + freeExtraAllocatedChunks(); + this.putValueVolatile(this.hashLookupPos(), pos()); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + boolean keyEquals() { + return ((inputKey().size()) == (this.keySize())) && (BytesUtil.bytesEqual(this.entryBS, this.keyOffset(), inputKey().bytes(), inputKey().offset(), this.keySize())); + } + + public void closeMapQueryKeyEqualsDependants() { + this.closeKeySearch(); + } + + protected CompiledMapQueryContext.SearchState searchState = null; + + boolean keySearchInit() { + return (this.searchState) != null; + } + + void initKeySearch() { + for (long pos ; (pos = this.nextPos()) >= 0L ; ) { + this.readExistingEntry(pos); + if (!(keyEquals())) + continue; + + this.found(); + keyFound(); + return ; + } + searchState = CompiledMapQueryContext.SearchState.ABSENT; + this.closeKeySearchDependants(); + } + + public CompiledMapQueryContext.SearchState searchState() { + if (!(this.keySearchInit())) + this.initKeySearch(); + + return this.searchState; + } + + void closeKeySearch() { + if (!(this.keySearchInit())) + return ; + + this.closeKeySearchDependants(); + this.searchState = null; + } + + public void closeKeySearchDependants() { + this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public void incrementSegmentEntriesIfNeeded() { + if ((this.searchState()) != (CompiledMapQueryContext.SearchState.PRESENT)) { + this.entries(((this.entries()) + 1L)); } } - public void copyExistingEntry(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset(); - long oldKeyOffset = keyOffset(); - initPos(newPos); - initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); - } - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); - CompiledMapQueryContext.this.copyExistingEntry(CompiledMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); + initAllocatedChunks(this.h().inChunks(entrySize)); + this.copyExistingEntry(this.alloc(allocatedChunks()), bytesToCopy); incrementSegmentEntriesIfNeeded(); } - public void putValueDeletedEntry(Data newValue) { - assert CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + this.free(pos(), entrySizeInChunks()); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); + } + + public void innerDefaultReplaceValue(Data newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); + boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); + if (newValueSizeIsDifferent) { + long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long entryStartOffset = keySizeOffset(); + VanillaChronicleMap m = 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 (this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { + this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); + break newValueDoesNotFit; + } + relocation(newValue, newSizeOfEverythingBeforeValue); + return ; + } else if (newSizeInChunks < (entrySizeInChunks())) { + this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); + } + } else { + } + this.innerWriteLock.lock(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + this.putValueVolatile(this.hashLookupPos(), pos()); + } + + public void putValueDeletedEntry(Data newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; long entryStartOffset = keySizeOffset(); long newSizeOfEverythingBeforeValue = -1; boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); if (newValueSizeIsDifferent) { newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newValueOffset = this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledMapQueryContext.this.m().inChunks(newEntrySize); + newSizeInChunks = this.m().inChunks(newEntrySize); } else { newSizeInChunks = entrySizeInChunks(); } - if ((((pos()) + newSizeInChunks) < (CompiledMapQueryContext.this.freeList().size())) && (CompiledMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledMapQueryContext.this.innerWriteLock.lock(); - CompiledMapQueryContext.this.incrementSegmentEntriesIfNeeded(); + if ((((pos()) + newSizeInChunks) < (this.freeList().size())) && (this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + this.innerWriteLock.lock(); + this.incrementSegmentEntriesIfNeeded(); if (newValueSizeIsDifferent) { initValue(newValue); } else { @@ -3448,86 +3069,419 @@ public class CompiledMapQueryContext value) { - CompiledMapQueryContext.this.putPrefix(); - if (!(CompiledMapQueryContext.this.searchStatePresent())) { - if (CompiledMapQueryContext.this.searchStateDeleted()) { - CompiledMapQueryContext.this.putValueDeletedEntry(value); + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.replaceValue(entry, newValue); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + this.checkOnEachPublicOperation(); + return this.innerUpdateLock; + } + + @NotNull + @Override + public InterProcessLock readLock() { + this.checkOnEachPublicOperation(); + return this.innerReadLock; + } + + @NotNull + @Override + public Data value() { + this.checkOnEachPublicOperation(); + return this.entryValue; + } + + @Override + public R remove(@NotNull + MapEntry entry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public Data defaultValue() { + this.checkOnEachPublicOperation(); + return this.wrapValueAsValue(this.m().defaultValue(this.deprecatedMapKeyContext)); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + this.checkOnEachPublicOperation(); + return this.innerWriteLock; + } + + @NotNull + @Override + public MapContext context() { + this.checkOnEachPublicOperation(); + return this; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.insert(absentEntry, value); + } + + @Override + public Data wrapValueAsValue(V value) { + this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + public Data queriedKey() { + this.checkOnEachPublicOperation(); + return inputKey(); + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.defaultValue(absentEntry); + } + + @NotNull + @Override + public Data absentKey() { + this.checkOnEachPublicOperation(); + return this.inputKey(); + } + + @NotNull + @Override + public Data key() { + this.checkOnEachPublicOperation(); + return this.entryKey; + } + + public boolean searchStatePresent() { + return (searchState()) == (CompiledMapQueryContext.SearchState.PRESENT); + } + + public boolean entryPresent() { + return searchStatePresent(); + } + + @Override + public MapEntry entry() { + this.checkOnEachPublicOperation(); + return entryPresent() ? this : null; + } + + @Nullable + @Override + public MapAbsentEntry absentEntry() { + this.checkOnEachPublicOperation(); + return entryPresent() ? null : this.absent(); + } + + public boolean searchStateAbsent() { + return (!(searchStatePresent())) && (!(searchStateDeleted())); + } + + void putEntry(Data value) { + assert this.searchStateAbsent(); + long entrySize = this.entrySize(this.inputKey().size(), value.size()); + this.initEntryAndKey(entrySize); + this.initValue(value); + this.freeExtraAllocatedChunks(); + this.putNewVolatile(this.pos()); + } + + protected void putPrefix() { + this.checkOnEachPublicOperation(); + boolean underUpdatedLockIsHeld = !(this.innerUpdateLock.isHeldByCurrentThread()); + if (underUpdatedLockIsHeld) + this.innerUpdateLock.lock(); + + boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (this.concurrentSameThreadContexts()); + if (((this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) + this.closeHashLookupPos(); + + } + + @Override + public void doInsert(Data value) { + this.putPrefix(); + if (!(this.searchStatePresent())) { + if (this.searchStateDeleted()) { + this.putValueDeletedEntry(value); } else { putEntry(value); } - CompiledMapQueryContext.this.incrementModCountGuarded(); - CompiledMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); + this.incrementModCountGuarded(); + this.setSearchStateGuarded(CompiledMapQueryContext.SearchState.PRESENT); } else { throw new IllegalStateException("Entry is present in the map when doInsert() is called"); } } - protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - CompiledMapQueryContext.this.free(pos(), entrySizeInChunks()); - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - CompiledMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); - writeValueAndPutPos(newValue); - } - - public void innerDefaultReplaceValue(Data newValue) { - assert CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); - boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); - if (newValueSizeIsDifferent) { - long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long entryStartOffset = keySizeOffset(); - VanillaChronicleMap m = CompiledMapQueryContext.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 (CompiledMapQueryContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { - CompiledMapQueryContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); - break newValueDoesNotFit; - } - relocation(newValue, newSizeOfEverythingBeforeValue); - return ; - } else if (newSizeInChunks < (entrySizeInChunks())) { - CompiledMapQueryContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); - } - } else { - } - CompiledMapQueryContext.this.innerWriteLock.lock(); - if (newValueSizeIsDifferent) { - initValue(newValue); - } else { - writeValue(newValue); - } - CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); - } - @Override - public void doReplaceValue(Data newValue) { + public void doReplaceValue(Data newValue) { putPrefix(); if (searchStatePresent()) { - CompiledMapQueryContext.this.innerDefaultReplaceValue(newValue); - CompiledMapQueryContext.this.incrementModCountGuarded(); - setSearchStateGuarded(SearchState.PRESENT); + this.innerDefaultReplaceValue(newValue); + this.incrementModCountGuarded(); + setSearchStateGuarded(CompiledMapQueryContext.SearchState.PRESENT); } else { throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); } } + + @Override + public void doRemove() { + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); + if (searchStatePresent()) { + this.innerWriteLock.lock(); + this.remove(); + this.innerRemoveEntryExceptHashLookupUpdate(); + setSearchStateGuarded(CompiledMapQueryContext.SearchState.DELETED); + } else { + throw new IllegalStateException("Entry is absent when doRemove() is called"); + } + } + + boolean used; + + public boolean usedInit() { + return used; + } + + public void initUsed(boolean used) { + this.used = used; + } + + void closeUsed() { + if (!(this.usedInit())) + return ; + + used = false; + } + + public Bytes inputBytes = null; + + public boolean inputBytesInit() { + return (this.inputBytes) != null; + } + + public void initInputBytes(Bytes inputBytes) { + this.inputBytes = inputBytes; + inputStore.setBytes(inputBytes); + this.closeInputBytesDependants(); + } + + public Bytes inputBytes() { + assert this.inputBytesInit() : "InputBytes should be init"; + return this.inputBytes; + } + + public void closeInputBytes() { + if (!(this.inputBytesInit())) + return ; + + this.closeInputBytesDependants(); + this.inputBytes = null; + } + + public void closeInputBytesDependants() { + this.closeInputKeyOffsets(); + this.closeFirstInputValueOffsets(); + this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + this.closeSecondInputValueOffsets(); + this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); + } + + public long inputKeySize = -1; + + public long inputKeyOffset; + + public boolean inputKeyOffsetsInit() { + return (this.inputKeySize) >= 0; + } + + private void initInputKeyOffsets() { + inputKeySize = this.h().keySizeMarshaller.readSize(inputBytes()); + inputKeyOffset = inputBytes().position(); + this.closeInputKeyOffsetsDependants(); + } + + public long inputKeyOffset() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeyOffset; + } + + public long inputKeySize() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeySize; + } + + public void closeInputKeyOffsets() { + if (!(this.inputKeyOffsetsInit())) + return ; + + this.closeInputKeyOffsetsDependants(); + this.inputKeySize = -1; + } + + public void closeInputKeyOffsetsDependants() { + this.closeFirstInputValueOffsets(); + this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); + this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + } + + public long firstInputValueSize = -1; + + public long firstInputValueOffset; + + public boolean firstInputValueOffsetsInit() { + return (this.firstInputValueSize) >= 0; + } + + private void initFirstInputValueOffsets() { + this.inputBytes().position(((this.inputKeyOffset()) + (this.inputKeySize()))); + firstInputValueSize = this.m().valueSizeMarshaller.readSize(this.inputBytes()); + firstInputValueOffset = this.inputBytes().position(); + this.closeFirstInputValueOffsetsDependants(); + } + + public long firstInputValueOffset() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueOffset; + } + + public long firstInputValueSize() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueSize; + } + + public void closeFirstInputValueOffsets() { + if (!(this.firstInputValueOffsetsInit())) + return ; + + this.closeFirstInputValueOffsetsDependants(); + this.firstInputValueSize = -1; + } + + public void closeFirstInputValueOffsetsDependants() { + this.closeSecondInputValueOffsets(); + this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); + this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + } + + public long secondInputValueSize = -1; + + public long secondInputValueOffset; + + public boolean secondInputValueOffsetsInit() { + return (this.secondInputValueSize) >= 0; + } + + private void initSecondInputValueOffsets() { + this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); + secondInputValueSize = this.m().valueSizeMarshaller.readSize(this.inputBytes()); + secondInputValueOffset = this.inputBytes().position(); + this.closeSecondInputValueOffsetsDependants(); + } + + public long secondInputValueOffset() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueOffset; + } + + public long secondInputValueSize() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueSize; + } + + public void closeSecondInputValueOffsets() { + if (!(this.secondInputValueOffsetsInit())) + return ; + + this.closeSecondInputValueOffsetsDependants(); + this.secondInputValueSize = -1; + } + + public void closeSecondInputValueOffsetsDependants() { + this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); + this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); + } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java index 9f1415f55..7d117fad4 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java @@ -1,18 +1,13 @@ package net.openhft.chronicle.map.impl; -import net.openhft.chronicle.bytes.Access; -import net.openhft.chronicle.bytes.Accessor; -import net.openhft.chronicle.bytes.Accessor.Full; -import net.openhft.chronicle.bytes.ReadAccess; +import net.openhft.chronicle.bytes.BytesStore; +import net.openhft.chronicle.bytes.NativeBytesStore; +import net.openhft.chronicle.bytes.RandomDataInput; +import net.openhft.chronicle.bytes.ZeroRandomDataInput; import net.openhft.chronicle.hash.AbstractData; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashEntry; -import net.openhft.chronicle.hash.impl.BigSegmentHeader; -import net.openhft.chronicle.hash.impl.CopyingInstanceData; -import net.openhft.chronicle.hash.impl.JavaLangBytesAccessors; -import net.openhft.chronicle.hash.impl.LocalLockState; -import net.openhft.chronicle.hash.impl.SegmentHeader; -import net.openhft.chronicle.hash.impl.VanillaChronicleHash; +import net.openhft.chronicle.hash.impl.*; import net.openhft.chronicle.hash.impl.hashlookup.EntryConsumer; import net.openhft.chronicle.hash.locks.InterProcessLock; import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; @@ -21,13 +16,7 @@ import net.openhft.chronicle.hash.replication.ReplicableEntry; 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.ChronicleMap; -import net.openhft.chronicle.map.MapAbsentEntry; -import net.openhft.chronicle.map.MapContext; -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.*; import net.openhft.chronicle.map.replication.MapReplicableEntry; import net.openhft.lang.Maths; import net.openhft.lang.MemoryUnit; @@ -47,23 +36,23 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Predicate; -public class CompiledReplicatedMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ReplicableEntry , MapContext , MapEntry , IterationContextInterface , ReplicatedChronicleMapHolder , ReplicatedIterationContextInterface , MapReplicableEntry { +public class CompiledReplicatedMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ReplicableEntry , MapContext , MapEntry , IterationContextInterface , ReplicatedChronicleMapHolder , ReplicatedIterationContextInterface , MapReplicableEntry { public void close() { - CompiledReplicatedMapIterationContext.this.closePos(); - CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeValue(); - CompiledReplicatedMapIterationContext.this.closeReplicationUpdate(); - CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeNext(); - CompiledReplicatedMapIterationContext.this.closeKeyOffset(); - CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); - CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); - CompiledReplicatedMapIterationContext.this.closeUsed(); - CompiledReplicatedMapIterationContext.this.closeKeySize(); - CompiledReplicatedMapIterationContext.this.closeTheSegmentIndex(); - CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); - CompiledReplicatedMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + this.closeTheSegmentIndex(); + this.wrappedValueInstanceValue.closeValue(); + this.closeEntryRemovedOnThisIteration(); + this.wrappedValueInstanceValue.closeNext(); + this.closeUsed(); + this.closeKeySize(); + this.closePos(); + this.closeReplicationUpdate(); + this.closeAllocatedChunks(); + this.closeHashLookupPos(); + this.closeKeyOffset(); + this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + this.closeValueBytesInteropValueMetaInteropDependants(); + this.closeReplicatedMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); } public void incrementModCountGuarded() { @@ -85,29 +74,35 @@ public class CompiledReplicatedMapIterationContext m) { - contextChain = new ArrayList(); + contextChain = new ArrayList(); contextChain.add(this); indexInContextChain = 0; this.m = m; - this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.entryKey = new EntryKeyBytesData(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.innerWriteLock = new WriteLock(); - 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.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); + this.entryKey = new EntryKeyBytesData(); this.innerUpdateLock = new UpdateLock(); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.entryValue = new EntryValueBytesData(); - this.dummyValue = new DummyValueZeroData(); this.innerReadLock = new ReadLock(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.dummyValue = new DummyValueZeroData(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); } public CompiledReplicatedMapIterationContext(CompiledReplicatedMapIterationContext c) { @@ -115,32 +110,93 @@ public class CompiledReplicatedMapIterationContext)(c.m)); - this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.entryKey = new EntryKeyBytesData(); - this.wrappedValueInstanceValue = new WrappedValueInstanceData(); - this.innerWriteLock = new WriteLock(); - 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.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); + this.entryKey = new EntryKeyBytesData(); this.innerUpdateLock = new UpdateLock(); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.entryValue = new EntryValueBytesData(); - this.dummyValue = new DummyValueZeroData(); this.innerReadLock = new ReadLock(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.dummyValue = new DummyValueZeroData(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); } public class DeprecatedMapKeyContextOnIteration implements MapKeyContext { + @Override + public void close() { + throw new UnsupportedOperationException("close() is not supported during iteration"); + } + + @Override + public V get() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.value().get(); + } + + @NotNull + @Override + public K key() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.key().get(); + } + + @Override + public boolean containsKey() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return true; + } + + @Override + public boolean put(V newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + CompiledReplicatedMapIterationContext.this.replaceValue(CompiledReplicatedMapIterationContext.this, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(newValue)); + return true; + } + + @NotNull + @Override + public Bytes entry() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytes; + } + + @Override + public boolean valueEqualTo(V value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledReplicatedMapIterationContext.this.entryValue, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(value)); + } + + @Override + public boolean remove() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + CompiledReplicatedMapIterationContext.this.remove(CompiledReplicatedMapIterationContext.this); + return true; + } + + @Override + public V getUsing(V usingValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.value().getUsing(usingValue); + } + @NotNull private UnsupportedOperationException unsupportedLocks() { return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); } + @NotNull + @Override + public InterProcessLock readLock() { + throw unsupportedLocks(); + } + @NotNull @Override public InterProcessLock writeLock() { @@ -153,79 +209,10 @@ public class CompiledReplicatedMapIterationContext { + public class DummyValueZeroData extends AbstractData { + @Override + public long size() { + return CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.minEncodableSize(); + } + + @Override + public RandomDataInput bytes() { + return ZeroRandomDataInput.INSTANCE; + } + @Override public V get() { throw new UnsupportedOperationException(); } - @Override - public Void handle() { - return null; - } - - @Override - public long offset() { - return 0; - } - - @Override - public ReadAccess access() { - return ReadAccess.zeros(); - } - @Override public V getUsing(V usingInstance) { throw new UnsupportedOperationException(); } @Override - public long size() { - return CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.minEncodableSize(); + public long offset() { + return 0; } } - public class EntryKeyBytesData extends AbstractData { + public class EntryKeyBytesData extends AbstractData { @Override - public ReadAccess access() { + public RandomDataInput bytes() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccess; + return CompiledReplicatedMapIterationContext.this.entryBS; } @Override - public T handle() { + public long offset() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; + return CompiledReplicatedMapIterationContext.this.keyOffset(); } @Override @@ -293,7 +281,7 @@ public class CompiledReplicatedMapIterationContext { + public class EntryValueBytesData extends AbstractData { @Override - public T handle() { + public RandomDataInput bytes() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; + return CompiledReplicatedMapIterationContext.this.entryBS; } @Override - public ReadAccess access() { + public long offset() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccess; + return CompiledReplicatedMapIterationContext.this.valueOffset(); } @Override @@ -371,7 +353,7 @@ public class CompiledReplicatedMapIterationContext { + public class WrappedValueInstanceData extends CopyingInstanceData { public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); @@ -651,7 +627,7 @@ public class CompiledReplicatedMapIterationContext newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); } - - @Override - public boolean tryLock(long time, @NotNull - TimeUnit unit) throws InterruptedException { - switch (CompiledReplicatedMapIterationContext.this.localLockState()) { - case UNLOCKED : - if (CompiledReplicatedMapIterationContext.this.segmentHeader().tryWriteLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress(), time, unit)) { - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - if (CompiledReplicatedMapIterationContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress(), time, unit)) { - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case WRITE_LOCKED : - return true; + if ((((pos()) + newSizeInChunks) < (this.freeList().size())) && (this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + this.innerWriteLock.lock(); + this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); } - throw new AssertionError(); + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + this.putValueVolatile(this.hashLookupPos(), pos()); + } + + private void _MapSegmentIteration_doRemove() { + this.checkOnEachPublicOperation(); + initEntryRemovedOnThisIteration(true); + this.innerWriteLock.lock(); + try { + if ((this.remove(this.hashLookupPos())) != (this.hashLookupPos())) { + this.setHashLookupPosGuarded(this.stepBack(this.hashLookupPos())); + } + this.innerRemoveEntryExceptHashLookupUpdate(); + } finally { + this.innerWriteLock.unlock(); + } + } + + private void _MapSegmentIteration_doReplaceValue(Data newValue) { + this.checkOnEachPublicOperation(); + try { + this.innerDefaultReplaceValue(newValue); + } finally { + this.innerWriteLock.unlock(); } } @@ -905,7 +953,7 @@ public class CompiledReplicatedMapIterationContext newValue, long newSizeOfEverythingBeforeValue) { + this.free(pos(), entrySizeInChunks()); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); + } + + private CompiledReplicatedMapIterationContext _Chaining_createChaining() { + return new CompiledReplicatedMapIterationContext(this); + } + public final int indexInContextChain; public int indexInContextChain() { @@ -992,7 +1059,7 @@ public class CompiledReplicatedMapIterationContext contextChain; + public final List contextChain; public final UpdateLock innerUpdateLock; @@ -1000,18 +1067,24 @@ public class CompiledReplicatedMapIterationContext contextChain() { + public List contextChain() { return this.contextChain; } public final ThreadLocalCopies copies; + final EntryKeyBytesData entryKey; + + public EntryKeyBytesData entryKey() { + return this.entryKey; + } + public ThreadLocalCopies copies() { return this.copies; } private void countValueOffset() { - CompiledReplicatedMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); + this.m().alignment.alignPositionAddr(entryBytes); valueOffset = entryBytes.position(); } @@ -1021,12 +1094,6 @@ public class CompiledReplicatedMapIterationContext entryBytesAccessor; + public final BytesStore entryBS; - public Full entryBytesAccessor() { - return this.entryBytesAccessor; - } - - @SuppressWarnings(value = "unchecked") - public final T entryBytesAccessHandle; - - public T entryBytesAccessHandle() { - return this.entryBytesAccessHandle; + public BytesStore entryBS() { + return this.entryBS; } public final BytesReader valueReader; @@ -1078,45 +1138,12 @@ public class CompiledReplicatedMapIterationContext entryBytesAccess; - - public Access entryBytesAccess() { - return this.entryBytesAccess; - } - public final BytesReader keyReader; public BytesReader keyReader() { return this.keyReader; } - public T contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public MVI valueMetaInterop(V value) { - return CompiledReplicatedMapIterationContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeBuffer(); - } - - @NotNull - @Override - public MapContext context() { - return CompiledReplicatedMapIterationContext.this; - } - - public long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); - } - @Override public ReplicatedChronicleMap m() { return m; @@ -1127,22 +1154,139 @@ public class CompiledReplicatedMapIterationContext context() { + return this; + } + + public MVI valueMetaInterop(V value) { + return this.m().metaValueInteropProvider.get(this.copies, this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + this.wrappedValueInstanceValue.closeBuffer(); + } + 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; + if (this.m().constantlySizedEntry) { + return this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (this.m().worstAlignment)) + valueSize; } else { - return (CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; + return (this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; } } - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); } - private CompiledReplicatedMapIterationContext _Chaining_createChaining() { - return new CompiledReplicatedMapIterationContext(this); + public void checkAccessingFromOwnerThread() { + if ((owner) != (Thread.currentThread())) { + throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + } + } + + public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { + this.closeIterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + public void checkOnEachPublicOperation() { + _CheckOnEachPublicOperation_checkOnEachPublicOperation(); + this.checkEntryNotRemovedOnThisIteration(); + } + + public void closeIterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + this.checkOnEachPublicOperation(); + return this.innerUpdateLock; + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public Data wrapValueAsValue(V value) { + this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public InterProcessLock writeLock() { + this.checkOnEachPublicOperation(); + return this.innerWriteLock; + } + + @NotNull + @Override + public Data value() { + this.checkOnEachPublicOperation(); + return this.entryValue; + } + + @NotNull + @Override + public Data key() { + this.checkOnEachPublicOperation(); + return this.entryKey; + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.defaultValue(absentEntry); + } + + @Override + public R remove(@NotNull + MapEntry entry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public InterProcessLock readLock() { + this.checkOnEachPublicOperation(); + return this.innerReadLock; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.insert(absentEntry, value); } public CompiledReplicatedMapIterationContext createChaining() { @@ -1162,126 +1306,70 @@ public class CompiledReplicatedMapIterationContextT contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); } - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledReplicatedMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); } - public void checkEntryNotRemovedOnThisIteration() { - if (entryRemovedOnThisIterationInit()) - throw new IllegalStateException("Entry was already removed on this iteration"); - + public MKI keyMetaInterop(K key) { + return this.h().metaKeyInteropProvider.get(this.copies, this.h().originalMetaKeyInterop, keyInterop, key); } - public void closeReplicatedMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants() { - CompiledReplicatedMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + public long keyOffset = -1; + + public boolean keyOffsetInit() { + return (this.keyOffset) >= 0; } - private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { - CompiledReplicatedMapIterationContext.this.checkAccessingFromOwnerThread(); + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); } - public void checkOnEachPublicOperation() { - _CheckOnEachPublicOperation_checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.checkEntryNotRemovedOnThisIteration(); + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; } - public void closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { - CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; } - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data value) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + public void closeKeyOffsetDependants() { + this.closeReplicatedMapEntryStagesKeyEndDependants(); + this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); } - @NotNull - @Override - public InterProcessLock readLock() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerReadLock; + public long hashLookupPos = -1; + + public boolean hashLookupPosInit() { + return (this.hashLookupPos) >= 0; } - @Override - public Data defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); + public void initHashLookupPos(long hashLookupPos) { + this.hashLookupPos = hashLookupPos; } - @NotNull - @Override - public Data key() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryKey; + public long hashLookupPos() { + assert this.hashLookupPosInit() : "HashLookupPos should be init"; + return this.hashLookupPos; } - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerWriteLock; - } + public void closeHashLookupPos() { + if (!(this.hashLookupPosInit())) + return ; - @Override - public Data wrapValueAsValue(V value) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.remove(entry); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerUpdateLock; - } - - @NotNull - @Override - public Data value() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryValue; + this.hashLookupPos = -1; } public int allocatedChunks = 0; @@ -1306,6 +1394,358 @@ public class CompiledReplicatedMapIterationContext= 0; + } + + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); + } + + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) + return ; + + this.closePosDependants(); + this.pos = -1; + } + + public void closePosDependants() { + this.closeEntryOffset(); + } + + public long keySize = -1; + + public boolean keySizeInit() { + return (this.keySize) >= 0; + } + + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); + } + + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; + } + + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; + } + + public void closeKeySizeDependants() { + this.closeReplicatedMapEntryStagesKeyEndDependants(); + this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + this.closeReplicationState(); + this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + long countValueSizeOffset() { + return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { + this.closeValueSizeOffset(); + } + + public long valueSizeOffset = -1; + + public boolean valueSizeOffsetInit() { + return (this.valueSizeOffset) >= 0; + } + + void initValueSizeOffset() { + valueSizeOffset = countValueSizeOffset(); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + this.closeValSize(); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); + valueSize = this.m().readValueSize(entryBytes); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSize = oldValueSize; + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); + } + + public long valueOffset() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueSize; + } + + public void closeValSize() { + if (!(this.valSizeInit())) + return ; + + this.closeValSizeDependants(); + this.valueSize = -1; + } + + public void closeValSizeDependants() { + this.closeReplicatedMapEntryStagesEntryEndDependants(); + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + public void writeValue(Data value) { + value.writeTo(entryBS, valueOffset()); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.replicationBytesOffset = -1; + } + + void updateReplicationState(long timestamp, byte identifier) { + entryBytes.position(replicationBytesOffset()); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryDeleted() { + entryBS.writeBoolean(entryDeletedOffset(), true); + } + + public void writeEntryPresent() { + entryBS.writeBoolean(entryDeletedOffset(), false); + } + + public boolean entryDeleted() { + return entryBS.readBoolean(entryDeletedOffset()); + } + + public boolean entryIsPresent() { + return !(this.entryDeleted()); + } + + public long timestamp() { + return entryBS.readLong(replicationBytesOffset()); + } + + @Override + public long originTimestamp() { + this.checkOnEachPublicOperation(); + return timestamp(); + } + + private boolean testTimeStampInSensibleRange() { + if ((this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (this.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (this.innerRemoteTimestamp()); + } + return true; + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + byte identifier() { + return entryBS.readByte(identifierOffset()); + } + + @Override + public byte originIdentifier() { + this.checkOnEachPublicOperation(); + return identifier(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeReplicatedMapEntryStagesEntryEndDependants() { + this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + boolean used; + + public boolean usedInit() { + return used; + } + + public void initUsed(boolean used) { + this.used = used; + } + + void closeUsed() { + if (!(this.usedInit())) + return ; + + used = false; + } + + public boolean entryRemovedOnThisIteration = false; + + boolean entryRemovedOnThisIterationInit() { + return (this.entryRemovedOnThisIteration) != false; + } + + protected void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { + this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; + } + + public void closeEntryRemovedOnThisIteration() { + if (!(this.entryRemovedOnThisIterationInit())) + return ; + + this.entryRemovedOnThisIteration = false; + } + public int segmentIndex = -1; public boolean theSegmentIndexInit() { @@ -1331,9 +1771,13 @@ public class CompiledReplicatedMapIterationContext h = CompiledReplicatedMapIterationContext.this.h(); + VanillaChronicleHash h = this.h(); long hashLookupOffset = h.segmentOffset(segmentIndex()); long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); @@ -1379,11 +1823,112 @@ public class CompiledReplicatedMapIterationContext= 0; + } + + public void initEntryOffset() { + keySizeOffset = (this.entrySpaceOffset()) + ((pos()) * (this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); + } + + public long keySizeOffset() { + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + + return this.keySizeOffset; + } + + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) + return ; + + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; + } + + public void closeEntryOffsetDependants() { + this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + long entrySize() { + return (entryEnd()) - (keySizeOffset()); + } + + public void closeReplicatedMapEntryStagesEntrySizeDependants() { + this.closeTheEntrySizeInChunks(); + } + + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; + } + + void initTheEntrySizeInChunks() { + entrySizeInChunks = this.h().inChunks(entrySize()); + } + + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; + } + + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; + } + + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + return ; + + this.entrySizeInChunks = 0; + } + + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBS, keyOffset()); + } + + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + entryBS.write(keySizeOffset(), entryBS, oldKeySizeOffset, bytesToCopy); + } + + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public void raiseChange() { + this.m().raiseChange(this.segmentIndex(), this.pos()); + } + + public void updateChange() { + if (!(replicationUpdateInit())) { + raiseChange(); + } } int hashLookupEntrySize; @@ -1407,8 +1952,8 @@ public class CompiledReplicatedMapIterationContext= 0 ? pos : capacityMask2(); + } + + 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) { @@ -1495,72 +2052,49 @@ public class CompiledReplicatedMapIterationContext>> (keyBits())) & (valueMask()); + } + + 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 stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - 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); } - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - void clearEntry(long pos, long prevEntry) { long entry = prevEntry & (~(entryMask())); NativeBytes.UNSAFE.putLong(((address()) + pos), entry); } - 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 indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); } public long remove(long posToRemove) { @@ -1585,9 +2119,24 @@ public class CompiledReplicatedMapIterationContext sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); + } + + public void moveChange(long oldPos, long newPos) { + this.m().moveChange(this.segmentIndex(), oldPos, newPos); } long segmentHeaderAddress; @@ -1599,7 +2148,7 @@ public class CompiledReplicatedMapIterationContext= (CompiledReplicatedMapIterationContext.this.h().actualChunksPerSegment)) + if (nextPosToSearchFrom >= (this.h().actualChunksPerSegment)) nextPosToSearchFrom = 0L; nextPosToSearchFrom(nextPosToSearchFrom); } - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); - } - - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { - CompiledReplicatedMapIterationContext c = CompiledReplicatedMapIterationContext.this.contextAtIndexInChain(index); - if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { - throw new IllegalStateException("Nested context not implemented yet"); - } else { - return false; - } - } - - public void closeSegmentStagesTryFindInitLocksOfThisSegmentDependants() { - CompiledReplicatedMapIterationContext.this.closeLocks(); - } - - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - long nextPosToSearchFrom() { return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); } - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - - } - public long alloc(int chunks) { - VanillaChronicleHash h = CompiledReplicatedMapIterationContext.this.h(); + VanillaChronicleHash h = this.h(); if (chunks > (h.maxChunksPerEntry)) throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); @@ -1713,6 +2226,72 @@ public class CompiledReplicatedMapIterationContext value) { + initValue(value); + freeExtraAllocatedChunks(); + this.putValueVolatile(this.hashLookupPos(), pos()); + } + + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + long oldPos = pos(); + _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); + this.moveChange(oldPos, pos()); + } + + boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { + CompiledReplicatedMapIterationContext c = 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() { + this.closeLocks(); + } + + public void deleted(long deleted) { + segmentHeader().deleted(segmentHeaderAddress(), deleted); + } + + public long deleted() { + return segmentHeader().deleted(segmentHeaderAddress()); + } + + public void entries(long size) { + segmentHeader().size(segmentHeaderAddress(), size); + } + + public long entries() { + return segmentHeader().size(segmentHeaderAddress()); + } + + public long size() { + return (entries()) - (deleted()); + } + int totalReadLockCount; int totalUpdateLockCount; @@ -1737,13 +2316,13 @@ public class CompiledReplicatedMapIterationContext= 0 ; i--) { if (tryFindInitLocksOfThisSegment(this, i)) return ; } - for (int i = indexOfThisContext + 1, size = CompiledReplicatedMapIterationContext.this.contextChain.size() ; i < size ; i++) { + for (int i = indexOfThisContext + 1, size = this.contextChain.size() ; i < size ; i++) { if (tryFindInitLocksOfThisSegment(this, i)) return ; @@ -1776,7 +2355,7 @@ public class CompiledReplicatedMapIterationContext= 0; - } - - public void initKeySize(long keySize) { - this.keySize = keySize; - this.closeKeySizeDependants(); - } - - public long keySize() { - assert this.keySizeInit() : "KeySize should be init"; - return this.keySize; - } - - public void closeKeySize() { - if (!(this.keySizeInit())) - return ; - - this.closeKeySizeDependants(); - this.keySize = -1; - } - - public void closeKeySizeDependants() { - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; - } - - public long 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 boolean entryRemovedOnThisIteration = false; - - boolean entryRemovedOnThisIterationInit() { - return (this.entryRemovedOnThisIteration) != false; - } - - protected void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { - this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; - } - - public void closeEntryRemovedOnThisIteration() { - if (!(this.entryRemovedOnThisIterationInit())) - return ; - - this.entryRemovedOnThisIteration = false; - } - - public long keyOffset = -1; - - public boolean keyOffsetInit() { - return (this.keyOffset) >= 0; - } - - public void initKeyOffset(long keyOffset) { - this.keyOffset = keyOffset; - this.closeKeyOffsetDependants(); - } - - public long keyOffset() { - assert this.keyOffsetInit() : "KeyOffset should be init"; - return this.keyOffset; - } - - public void closeKeyOffset() { - if (!(this.keyOffsetInit())) - return ; - - this.closeKeyOffsetDependants(); - this.keyOffset = -1; - } - - public void closeKeyOffsetDependants() { - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicationState(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.replicationBytesOffset = -1; - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - private long timestampOffset() { - return replicationBytesOffset(); - } - - public long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); - } - - @Override - public long originTimestamp() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - void updateReplicationState(long timestamp, byte identifier) { - entryBytes.position(replicationBytesOffset()); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); - } - - public void updatedReplicationStateOnAbsentEntry() { - if (!(CompiledReplicatedMapIterationContext.this.replicationUpdateInit())) { - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - updateReplicationState(CompiledReplicatedMapIterationContext.this.m().timeProvider.currentTime(), CompiledReplicatedMapIterationContext.this.m().identifier()); - } - } - - public void updatedReplicationStateOnPresentEntry() { - if (!(CompiledReplicatedMapIterationContext.this.replicationUpdateInit())) { - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - long timestamp; - if ((identifier()) != (CompiledReplicatedMapIterationContext.this.m().identifier())) { - timestamp = Math.max(((timestamp()) + 1), CompiledReplicatedMapIterationContext.this.m().timeProvider.currentTime()); - } else { - timestamp = CompiledReplicatedMapIterationContext.this.m().timeProvider.currentTime(); - } - updateReplicationState(timestamp, CompiledReplicatedMapIterationContext.this.m().identifier()); - } - } - - @Override - public void updateOrigin(byte newIdentifier, long newTimestamp) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - updateReplicationState(newTimestamp, newIdentifier); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - private boolean _MapSegmentIteration_entryIsPresent() { - return true; - } - - public boolean entryIsPresent() { - return !(CompiledReplicatedMapIterationContext.this.entryDeleted()); - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeValueSizeOffset(); - } - - public long valueSizeOffset = -1; - - public boolean valueSizeOffsetInit() { - return (this.valueSizeOffset) >= 0; - } - - void initValueSizeOffset() { - valueSizeOffset = countValueSizeOffset(); - this.closeValueSizeOffsetDependants(); - } - - public long valueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - this.initValueSizeOffset(); - - return this.valueSizeOffset; - } - - public void closeValueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - return ; - - this.closeValueSizeOffsetDependants(); - this.valueSizeOffset = -1; - } - - public void closeValueSizeOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeValSize(); - } - - public long valueSize = -1; - - public long valueOffset; - - public boolean valSizeInit() { - return (this.valueSize) >= 0; - } - - void initValSize() { - entryBytes.position(valueSizeOffset()); - valueSize = CompiledReplicatedMapIterationContext.this.m().readValueSize(entryBytes); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSize(long valueSize) { - this.valueSize = valueSize; - entryBytes.position(valueSizeOffset()); - CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSize = oldValueSize; - valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); - this.closeValSizeDependants(); - } - - public long valueOffset() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueSize; - } - - public void closeValSize() { - if (!(this.valSizeInit())) - return ; - - this.closeValSizeDependants(); - this.valueSize = -1; - } - - public void closeValSizeDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeReplicatedMapEntryStagesEntryEndDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - } - - public void writeValue(Data value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - assert oldValueSize == (value.size()); - initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); - writeValue(value); - } - - public void initValue(Data value) { - entryBytes.position(valueSizeOffset()); - initValSize(value.size()); - writeValue(value); - } - - public long innerRemoteTimestamp; - - public byte innerRemoteIdentifier = ((byte)(0)); - - public boolean replicationUpdateInit() { - return (this.innerRemoteIdentifier) != ((byte)(0)); - } - - public void initReplicationUpdate(long timestamp, byte identifier) { - innerRemoteTimestamp = timestamp; - if (identifier == 0) - throw new IllegalStateException("identifier can\'t be 0"); - - innerRemoteIdentifier = identifier; - } - - public byte innerRemoteIdentifier() { - assert this.replicationUpdateInit() : "ReplicationUpdate should be init"; - return this.innerRemoteIdentifier; - } - - public long innerRemoteTimestamp() { - assert this.replicationUpdateInit() : "ReplicationUpdate should be init"; - return this.innerRemoteTimestamp; - } - - public void closeReplicationUpdate() { - if (!(this.replicationUpdateInit())) - return ; - - this.innerRemoteIdentifier = ((byte)(0)); - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return innerRemoteIdentifier(); - } - - 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.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (CompiledReplicatedMapIterationContext.this.innerRemoteTimestamp()); - } - return true; - } - - @Override - public long remoteTimestamp() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return innerRemoteTimestamp(); - } - - public long pos = -1; - - public boolean posInit() { - return (this.pos) >= 0; - } - - public void initPos(long pos) { - this.pos = pos; - this.closePosDependants(); - } - - public long pos() { - assert this.posInit() : "Pos should be init"; - return this.pos; - } - - public void closePos() { - if (!(this.posInit())) - return ; - - this.closePosDependants(); - this.pos = -1; - } - - public void closePosDependants() { - CompiledReplicatedMapIterationContext.this.closeEntryOffset(); - } - - public void dropChange() { - CompiledReplicatedMapIterationContext.this.m().dropChange(CompiledReplicatedMapIterationContext.this.segmentIndex(), CompiledReplicatedMapIterationContext.this.pos()); - } - @Override public void dropChanged() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); - CompiledReplicatedMapIterationContext.this.dropChange(); + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); + this.dropChange(); } - public long keySizeOffset = -1; - - public boolean entryOffsetInit() { - return (this.keySizeOffset) >= 0; - } - - public void initEntryOffset() { - keySizeOffset = (CompiledReplicatedMapIterationContext.this.entrySpaceOffset()) + ((pos()) * (CompiledReplicatedMapIterationContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - this.closeEntryOffsetDependants(); - } - - public long keySizeOffset() { - if (!(this.entryOffsetInit())) - this.initEntryOffset(); - - return this.keySizeOffset; - } - - public void closeEntryOffset() { - if (!(this.entryOffsetInit())) - return ; - - this.closeEntryOffsetDependants(); - this.keySizeOffset = -1; - } - - public void closeEntryOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - } - - long entrySize() { - return (entryEnd()) - (keySizeOffset()); - } - - public void closeReplicatedMapEntryStagesEntrySizeDependants() { - CompiledReplicatedMapIterationContext.this.closeTheEntrySizeInChunks(); - } - - public int entrySizeInChunks = 0; - - public boolean theEntrySizeInChunksInit() { - return (this.entrySizeInChunks) != 0; - } - - void initTheEntrySizeInChunks() { - entrySizeInChunks = CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize()); - } - - public void initTheEntrySizeInChunks(int actuallyUsedChunks) { - entrySizeInChunks = actuallyUsedChunks; - } - - public int entrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - this.initTheEntrySizeInChunks(); - - return this.entrySizeInChunks; - } - - public void closeTheEntrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - return ; - - this.entrySizeInChunks = 0; - } - - public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); - CompiledReplicatedMapIterationContext.this.entries(((CompiledReplicatedMapIterationContext.this.entries()) - 1L)); - CompiledReplicatedMapIterationContext.this.incrementModCountGuarded(); - } - - public void copyExistingEntry(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset(); - long oldKeyOffset = keyOffset(); - initPos(newPos); - initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); - } - - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapIterationContext.this.copyExistingEntry(CompiledReplicatedMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); - } - - public long newSizeOfEverythingBeforeValue(Data newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - public void readExistingEntry(long pos) { - initPos(pos); - entryBytes.position(keySizeOffset()); - initKeySize(CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes)); - initKeyOffset(entryBytes.position()); - } - - public boolean forEachRemoving(Predicate> action) { - CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); + public boolean forEachRemoving(Predicate> action) { + this.innerUpdateLock.lock(); try { - long size = CompiledReplicatedMapIterationContext.this.size(); + long size = this.size(); if (size == 0) return true; boolean interrupted = false; long startPos = 0L; - while (!(CompiledReplicatedMapIterationContext.this.empty(CompiledReplicatedMapIterationContext.this.readEntry(startPos)))) { - startPos = CompiledReplicatedMapIterationContext.this.step(startPos); + while (!(this.empty(this.readEntry(startPos)))) { + startPos = this.step(startPos); } - CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); + 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.readExistingEntry(CompiledReplicatedMapIterationContext.this.value(entry)); + this.setHashLookupPosGuarded(this.step(this.hashLookupPos())); + long entry = this.readEntry(this.hashLookupPos()); + if (!(this.empty(entry))) { + this.readExistingEntry(this.value(entry)); if (entryIsPresent()) { initEntryRemovedOnThisIteration(false); if (!(action.test(((MapEntry)(this))))) { @@ -2382,135 +2401,86 @@ public class CompiledReplicatedMapIterationContext action) { - CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); + public void forEachReplicableEntry(Consumer action) { + this.innerUpdateLock.lock(); try { - long entries = CompiledReplicatedMapIterationContext.this.entries(); + long entries = this.entries(); if (entries == 0) return ; long startPos = 0L; - while (!(CompiledReplicatedMapIterationContext.this.empty(CompiledReplicatedMapIterationContext.this.readEntry(startPos)))) { - startPos = CompiledReplicatedMapIterationContext.this.step(startPos); + while (!(this.empty(this.readEntry(startPos)))) { + startPos = this.step(startPos); } - CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); + 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.readExistingEntry(CompiledReplicatedMapIterationContext.this.value(entry)); + this.setHashLookupPosGuarded(this.step(this.hashLookupPos())); + long entry = this.readEntry(this.hashLookupPos()); + if (!(this.empty(entry))) { + this.readExistingEntry(this.value(entry)); action.accept(this); if ((--entries) == 0) break; } - } while ((CompiledReplicatedMapIterationContext.this.hashLookupPos()) != startPos ); + } while ((this.hashLookupPos()) != startPos ); } finally { - CompiledReplicatedMapIterationContext.this.innerReadLock.unlock(); + this.innerReadLock.unlock(); } } - public void writeNewEntry(long pos, Data key) { - initPos(pos); - initKeySize(key.size()); - entryBytes.position(keySizeOffset()); - CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); - initKeyOffset(entryBytes.position()); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); + @Override + public void raiseChanged() { + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); + this.raiseChange(); } - 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()))); - } else { - initTheEntrySizeInChunks(CompiledReplicatedMapIterationContext.this.allocatedChunks()); - } + public void innerRemoveEntryExceptHashLookupUpdate() { + this.free(pos(), entrySizeInChunks()); + this.entries(((this.entries()) - 1L)); + this.incrementModCountGuarded(); } - private void _MapEntryStages_putValueDeletedEntry(Data newValue) { - assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledReplicatedMapIterationContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapIterationContext.this.freeList().size())) && (CompiledReplicatedMapIterationContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledReplicatedMapIterationContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - CompiledReplicatedMapIterationContext.this.incrementSegmentEntriesIfNeeded(); - if (newValueSizeIsDifferent) { - initValue(newValue); - } else { - writeValue(newValue); - } - } else { - if (newValueSizeIsDifferent) { - assert newSizeOfEverythingBeforeValue >= 0; - } else { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - } - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - if (newValueSizeIsDifferent) { - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); + public void clearSegment() { + this.innerWriteLock.lock(); + this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); } - public void putValueDeletedEntry(Data newValue) { + public void clear() { + clearSegment(); + } + + public void putValueDeletedEntry(Data newValue) { throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); } - public void writeValueAndPutPos(Data value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); + public void updatedReplicationStateOnAbsentEntry() { + if (!(this.replicationUpdateInit())) { + this.innerWriteLock.lock(); + updateReplicationState(this.m().timeProvider.currentTime(), this.m().identifier()); + } } - private void _MapEntryStages_relocation(Data 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(Data newValue, long newSizeOfEverythingBeforeValue) { - long oldPos = pos(); - _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); - CompiledReplicatedMapIterationContext.this.moveChange(oldPos, pos()); - } - - public void innerDefaultReplaceValue(Data newValue) { - assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + public void innerDefaultReplaceValue(Data newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); if (newValueSizeIsDifferent) { long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); long entryStartOffset = keySizeOffset(); - VanillaChronicleMap m = CompiledReplicatedMapIterationContext.this.m(); + VanillaChronicleMap m = this.m(); long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; int newSizeInChunks = m.inChunks(newEntrySize); @@ -2518,92 +2488,72 @@ public class CompiledReplicatedMapIterationContext (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)); + if (this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { + 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()))); + this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); } } else { } - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + this.innerWriteLock.lock(); if (newValueSizeIsDifferent) { initValue(newValue); } else { writeValue(newValue); } - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); + this.putValueVolatile(this.hashLookupPos(), pos()); } - public void raiseChange() { - CompiledReplicatedMapIterationContext.this.m().raiseChange(CompiledReplicatedMapIterationContext.this.segmentIndex(), CompiledReplicatedMapIterationContext.this.pos()); - } - - public void updateChange() { - if (!(replicationUpdateInit())) { - raiseChange(); - } - } - - private void _MapSegmentIteration_doRemove() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - initEntryRemovedOnThisIteration(true); - CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); - try { - if ((CompiledReplicatedMapIterationContext.this.remove(CompiledReplicatedMapIterationContext.this.hashLookupPos())) != (CompiledReplicatedMapIterationContext.this.hashLookupPos())) { - CompiledReplicatedMapIterationContext.this.setHashLookupPosGuarded(CompiledReplicatedMapIterationContext.this.stepBack(CompiledReplicatedMapIterationContext.this.hashLookupPos())); + public void updatedReplicationStateOnPresentEntry() { + if (!(this.replicationUpdateInit())) { + this.innerWriteLock.lock(); + long timestamp; + if ((identifier()) != (this.m().identifier())) { + timestamp = Math.max(((timestamp()) + 1), this.m().timeProvider.currentTime()); + } else { + timestamp = this.m().timeProvider.currentTime(); } - CompiledReplicatedMapIterationContext.this.innerRemoveEntryExceptHashLookupUpdate(); - } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); + updateReplicationState(timestamp, this.m().identifier()); } } + @Override + public void doReplaceValue(Data newValue) { + this.checkOnEachPublicOperation(); + try { + this.innerDefaultReplaceValue(newValue); + this.updateChange(); + this.updatedReplicationStateOnPresentEntry(); + } finally { + this.innerWriteLock.unlock(); + } + } + + @Override + public void updateOrigin(byte newIdentifier, long newTimestamp) { + this.checkOnEachPublicOperation(); + this.innerWriteLock.lock(); + updateReplicationState(newTimestamp, newIdentifier); + } + @Override public void doRemove() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + this.checkOnEachPublicOperation(); initEntryRemovedOnThisIteration(true); try { - if ((CompiledReplicatedMapIterationContext.this.valueSize()) > (CompiledReplicatedMapIterationContext.this.dummyValue.size())) - CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(CompiledReplicatedMapIterationContext.this.dummyValue); + if ((this.valueSize()) > (this.dummyValue.size())) + this.innerDefaultReplaceValue(this.dummyValue); - CompiledReplicatedMapIterationContext.this.updatedReplicationStateOnPresentEntry(); - CompiledReplicatedMapIterationContext.this.writeEntryDeleted(); - CompiledReplicatedMapIterationContext.this.updateChange(); - CompiledReplicatedMapIterationContext.this.deleted(((CompiledReplicatedMapIterationContext.this.deleted()) + 1)); + this.updatedReplicationStateOnPresentEntry(); + this.writeEntryDeleted(); + this.updateChange(); + this.deleted(((this.deleted()) + 1)); } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); + this.innerWriteLock.unlock(); } } - - private void _MapSegmentIteration_doReplaceValue(Data newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - try { - CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); - } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); - } - } - - @Override - public void doReplaceValue(Data newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - try { - CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); - CompiledReplicatedMapIterationContext.this.updateChange(); - CompiledReplicatedMapIterationContext.this.updatedReplicationStateOnPresentEntry(); - } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); - } - } - - @Override - public void raiseChanged() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); - CompiledReplicatedMapIterationContext.this.raiseChange(); - } } 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 122953d30..dd8b16bb0 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java @@ -1,13 +1,9 @@ package net.openhft.chronicle.map.impl; -import net.openhft.chronicle.algo.hashing.LongHashFunction; -import net.openhft.chronicle.bytes.Access; -import net.openhft.chronicle.bytes.Accessor; -import net.openhft.chronicle.bytes.Accessor.Full; -import net.openhft.chronicle.bytes.ReadAccess; -import net.openhft.chronicle.hash.*; +import net.openhft.chronicle.bytes.*; import net.openhft.chronicle.hash.AbstractData; import net.openhft.chronicle.hash.Data; +import net.openhft.chronicle.hash.HashEntry; import net.openhft.chronicle.hash.impl.*; import net.openhft.chronicle.hash.impl.hashlookup.EntryConsumer; import net.openhft.chronicle.hash.impl.value.instance.KeyInitableData; @@ -18,10 +14,9 @@ import net.openhft.chronicle.hash.replication.TimeProvider; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop; import net.openhft.chronicle.map.*; -import net.openhft.chronicle.map.TcpReplicator.TcpSocketChannelEntryWriter; +import net.openhft.chronicle.map.impl.data.instance.ValueInitableData; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; -import net.openhft.chronicle.map.impl.value.instance.ValueInitableData; import net.openhft.chronicle.map.replication.MapRemoteQueryContext; import net.openhft.chronicle.map.replication.MapReplicableEntry; import net.openhft.lang.Maths; @@ -43,30 +38,29 @@ import java.util.ConcurrentModificationException; import java.util.List; import java.util.concurrent.TimeUnit; -public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , MapAbsentEntryHolder , QueryContextInterface , ReplicatedChronicleMapHolder , MapRemoteQueryContext , MapReplicableEntry { +public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , MapAbsentEntryHolder , QueryContextInterface , ReplicatedChronicleMapHolder , MapRemoteQueryContext , MapReplicableEntry { public void close() { - CompiledReplicatedMapQueryContext.this.closeUsed(); - CompiledReplicatedMapQueryContext.this.closeReplicationInput(); - CompiledReplicatedMapQueryContext.this.closeKeySize(); - CompiledReplicatedMapQueryContext.this.closeInputBytes(); - CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); - CompiledReplicatedMapQueryContext.this.closeKeyOffset(); - CompiledReplicatedMapQueryContext.this.closePos(); - CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledReplicatedMapQueryContext.this.closeInputKey(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); - CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); - CompiledReplicatedMapQueryContext.this.bytesReturnValue.closeOutput(); - CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); - CompiledReplicatedMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); - CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); + this.bytesReturnValue.closeOutput(); + this.wrappedValueInstanceValue.closeValue(); + this.inputValueInstanceValue.closeValue(); + this.closeInputBytes(); + this.closeReplicationInput(); + this.closeUsed(); + this.closeAllocatedChunks(); + this.closeReplicationUpdate(); + this.wrappedValueInstanceValue.closeNext(); + this.usingReturnValue.closeUsingReturnValue(); + this.defaultReturnValue.closeDefaultReturnedValue(); + this.closeKeySize(); + this.inputKeyInstanceValue.closeKey(); + this.closeReplicatedInputBytes(); + this.closePos(); + this.closeInputKey(); + this.closeKeyOffset(); + this.closeKeyBytesInteropKeyMetaInteropDependants(); + this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + this.closeValueBytesInteropValueMetaInteropDependants(); } public void incrementModCountGuarded() { @@ -90,52 +84,60 @@ public class CompiledReplicatedMapQueryContext m) { - contextChain = new ArrayList(); + contextChain = new ArrayList(); contextChain.add(this); indexInContextChain = 0; this.m = m; - 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.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.defaultReturnValue = new DefaultReturnValue(); - this.bytesReturnValue = new BytesReturnValue(); - this.innerReadLock = new ReadLock(); - this.innerWriteLock = new WriteLock(); this.inputKeyBytesValue = new InputKeyBytesData(); - this.inputSecondValueBytesValue = new InputSecondValueBytesData(); - this.owner = Thread.currentThread(); - this.entryKey = new EntryKeyBytesData(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); - this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.defaultReturnValue = new DefaultReturnValue(); this.inputValueInstanceValue = new InputValueInstanceData(); - this.usingReturnValue = new UsingReturnValue(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.innerUpdateLock = new UpdateLock(); - this.dummyValue = new DummyValueZeroData(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryValue = new EntryValueBytesData(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); - this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.copies = ThreadLocalCopies.get(); + this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.usingReturnValue = new UsingReturnValue(); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.innerReadLock = new ReadLock(); + this.inputStore = new JavaLangBytesReusableBytesStore(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.bytesReturnValue = new BytesReturnValue(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.replicatedInputStore = new JavaLangBytesReusableBytesStore(); + this.dummyValue = new DummyValueZeroData(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); } public CompiledReplicatedMapQueryContext(CompiledReplicatedMapQueryContext c) { @@ -143,36 +145,101 @@ public class CompiledReplicatedMapQueryContext)(c.m)); - 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.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.defaultReturnValue = new DefaultReturnValue(); - this.bytesReturnValue = new BytesReturnValue(); - this.innerReadLock = new ReadLock(); - this.innerWriteLock = new WriteLock(); this.inputKeyBytesValue = new InputKeyBytesData(); - this.inputSecondValueBytesValue = new InputSecondValueBytesData(); - this.owner = Thread.currentThread(); - this.entryKey = new EntryKeyBytesData(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); - this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.defaultReturnValue = new DefaultReturnValue(); this.inputValueInstanceValue = new InputValueInstanceData(); - this.usingReturnValue = new UsingReturnValue(); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.innerUpdateLock = new UpdateLock(); - this.dummyValue = new DummyValueZeroData(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryValue = new EntryValueBytesData(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); - this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.copies = ThreadLocalCopies.get(); + this.valueInterop = this.m().valueInteropProvider.get(this.copies, this.m().originalValueInterop); + this.valueReader = this.m().valueReaderProvider.get(this.copies, this.m().originalValueReader); + this.keyInterop = this.h().keyInteropProvider.get(this.copies, this.h().originalKeyInterop); + this.keyReader = this.h().keyReaderProvider.get(this.copies, this.h().originalKeyReader); this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.usingReturnValue = new UsingReturnValue(); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.innerReadLock = new ReadLock(); + this.inputStore = new JavaLangBytesReusableBytesStore(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); + this.entryValue = new EntryValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.bytesReturnValue = new BytesReturnValue(); + this.entryBytes = this.h().ms.bytes(); + this.entryBS = new NativeBytesStore(entryBytes.address() , entryBytes.capacity() , null , false); + this.owner = Thread.currentThread(); + this.replicatedInputStore = new JavaLangBytesReusableBytesStore(); + this.dummyValue = new DummyValueZeroData(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + } + + public class BytesReturnValue implements AutoCloseable , ReturnValue { + public BytesReturnValue() { + this.outputStore = new JavaLangBytesReusableBytesStore(); + } + + private final JavaLangBytesReusableBytesStore outputStore; + + public JavaLangBytesReusableBytesStore outputStore() { + return this.outputStore; + } + + long startOutputPos; + + TcpReplicator.TcpSocketChannelEntryWriter output = null; + + public boolean outputInit() { + return (this.output) != null; + } + + public void initOutput(TcpReplicator.TcpSocketChannelEntryWriter output) { + this.output = output; + startOutputPos = output.in().position(); + } + + public long startOutputPos() { + assert this.outputInit() : "Output should be init"; + return this.startOutputPos; + } + + public TcpReplicator.TcpSocketChannelEntryWriter output() { + assert this.outputInit() : "Output should be init"; + return this.output; + } + + public void closeOutput() { + if (!(this.outputInit())) + return ; + + this.output = null; + } + + @Override + public void returnValue(@NotNull + Data value) { + long valueSize = value.size(); + long totalSize = (1L + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize))) + valueSize; + output().ensureBufferSize(totalSize); + Bytes out = output().in(); + out.writeBoolean(false); + CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(out, valueSize); + long outPosition = out.position(); + out.skip(valueSize); + outputStore.setBytes(out); + value.writeTo(outputStore, outPosition); + } + + @Override + public void close() { + if ((output().in().position()) == (startOutputPos())) { + output().ensureBufferSize(1L); + output().in().writeBoolean(true); + } + } } public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { @@ -194,31 +261,6 @@ public class CompiledReplicatedMapQueryContext entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.replaceValue(entry, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(newValue)); + } else { + CompiledReplicatedMapQueryContext.this.insert(CompiledReplicatedMapQueryContext.this.absentEntry(), CompiledReplicatedMapQueryContext.this.wrapValueAsValue(newValue)); + } + return true; + } + + @Override + public boolean remove() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + updateLock().lock(); + MapEntry entry = CompiledReplicatedMapQueryContext.this.entry(); + if (entry != null) { + CompiledReplicatedMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } + } + @Override public boolean containsKey() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -255,32 +348,6 @@ 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)); - } else { - CompiledReplicatedMapQueryContext.this.insert(CompiledReplicatedMapQueryContext.this.absentEntry(), CompiledReplicatedMapQueryContext.this.wrapValueAsValue(newValue)); - } - return true; - } - @Override public void close() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -292,8 +359,8 @@ public class CompiledReplicatedMapQueryContext { @NotNull @Override - public InterProcessLock updateLock() { - return CompiledReplicatedMapQueryContext.this.updateLock(); + public InterProcessLock writeLock() { + return CompiledReplicatedMapQueryContext.this.writeLock(); } @NotNull @@ -304,14 +371,20 @@ public class CompiledReplicatedMapQueryContext { @Override - public ReadAccess access() { - return ReadAccess.zeros(); + public boolean containsKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return (CompiledReplicatedMapQueryContext.this.entry()) != null; + } + + @Override + public V getUsing(V usingValue) { + return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; } @Override public V get() { - throw new UnsupportedOperationException(); + return containsKey() ? CompiledReplicatedMapQueryContext.this.value().get() : null; } + @Override + public long keySize() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.keySize(); + } + } + + public class DummyValueZeroData extends AbstractData { @Override public long size() { return CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.minEncodableSize(); } @Override - public Void handle() { - return null; + public RandomDataInput bytes() { + return ZeroRandomDataInput.INSTANCE; + } + + @Override + public V get() { + throw new UnsupportedOperationException(); } @Override @@ -433,17 +495,17 @@ public class CompiledReplicatedMapQueryContext { + public class EntryKeyBytesData extends AbstractData { @Override public long offset() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()); + return CompiledReplicatedMapQueryContext.this.keyOffset(); } @Override - public T handle() { + public RandomDataInput bytes() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; + return CompiledReplicatedMapQueryContext.this.entryBS; } @Override @@ -453,7 +515,7 @@ public class CompiledReplicatedMapQueryContext access() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccess; - } } - public class EntryValueBytesData extends AbstractData { - @Override - public ReadAccess access() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccess; - } - - @Override - public T handle() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; - } - + public class EntryValueBytesData extends AbstractData { @Override public long offset() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.valueOffset()); + return CompiledReplicatedMapQueryContext.this.valueOffset(); } @Override @@ -537,7 +581,7 @@ public class CompiledReplicatedMapQueryContext { @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + public V getUsing(V usingValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return innerGetUsing(usingValue); } @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + public RandomDataInput bytes() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBS; + } + } + + public class InputFirstValueBytesData extends AbstractData { + @Override + public RandomDataInput bytes() { + return CompiledReplicatedMapQueryContext.this.inputStore; + } + + @Override + public long offset() { + return CompiledReplicatedMapQueryContext.this.firstInputValueOffset(); } @Override @@ -606,7 +656,7 @@ public class CompiledReplicatedMapQueryContext { + @Override + public RandomDataInput bytes() { + return CompiledReplicatedMapQueryContext.this.inputStore; + } @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.firstInputValueOffset()); - } - } - - public class InputKeyBytesData extends AbstractData { - @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + return CompiledReplicatedMapQueryContext.this.inputKeyOffset(); } @Override @@ -669,7 +719,7 @@ public class CompiledReplicatedMapQueryContext { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + public RandomDataInput bytes() { + return CompiledReplicatedMapQueryContext.this.inputStore; } @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.inputKeyOffset()); - } - } - - public class InputSecondValueBytesData extends AbstractData { - @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()))); + return CompiledReplicatedMapQueryContext.this.secondInputValueOffset(); } @Override @@ -743,12 +783,7 @@ public class CompiledReplicatedMapQueryContext { + public class ReplicatedInputKeyBytesData extends AbstractData { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public RandomDataInput bytes() { + return CompiledReplicatedMapQueryContext.this.replicatedInputStore; } @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public long offset() { + return CompiledReplicatedMapQueryContext.this.riKeyOffset(); } @Override @@ -886,7 +921,7 @@ public class CompiledReplicatedMapQueryContext { + public class ReplicatedInputValueBytesData extends AbstractData { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); - } - - @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public RandomDataInput bytes() { + return CompiledReplicatedMapQueryContext.this.replicatedInputStore; } @Override @@ -955,12 +980,7 @@ public class CompiledReplicatedMapQueryContext { + @NotNull + @Override + public Data absentKey() { + return CompiledReplicatedMapQueryContext.this.absentKey(); + } + + @NotNull + @Override + public Data defaultValue() { + return CompiledReplicatedMapQueryContext.this.defaultValue(); + } + @NotNull @Override public MapContext context() { return CompiledReplicatedMapQueryContext.this.context(); } - @NotNull @Override - public Data absentKey() { - return CompiledReplicatedMapQueryContext.this.absentKey(); - } - - @NotNull - @Override - public Data defaultValue() { - return CompiledReplicatedMapQueryContext.this.defaultValue(); - } - - @Override - public void doInsert(Data value) { + public void doInsert(Data value) { CompiledReplicatedMapQueryContext.this.doInsert(value); } } @@ -1038,6 +1063,25 @@ public class CompiledReplicatedMapQueryContext { + public class WrappedValueInstanceData extends CopyingInstanceData { public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); @@ -1183,7 +1208,12 @@ public class CompiledReplicatedMapQueryContext value) { + this.putPrefix(); + if (!(this.searchStatePresent())) { + if (this.searchStateDeleted()) { + this.putValueDeletedEntry(value); + } else { + putEntry(value); + } + this.incrementModCountGuarded(); + this.setSearchStateGuarded(CompiledReplicatedMapQueryContext.SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is present in the map when doInsert() is called"); + } + } + + private void _MapEntryStages_putValueDeletedEntry(Data newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (this.freeList().size())) && (this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + this.innerWriteLock.lock(); + this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + this.putValueVolatile(this.hashLookupPos(), pos()); + } + + private void _MapQuery_doRemove() { + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); + if (searchStatePresent()) { + this.innerWriteLock.lock(); + this.remove(); + this.innerRemoveEntryExceptHashLookupUpdate(); + setSearchStateGuarded(CompiledReplicatedMapQueryContext.SearchState.DELETED); + } else { + throw new IllegalStateException("Entry is absent when doRemove() is called"); + } + } + + private void _MapQuery_doReplaceValue(Data newValue) { + putPrefix(); + if (searchStatePresent()) { + this.innerDefaultReplaceValue(newValue); + this.incrementModCountGuarded(); + setSearchStateGuarded(CompiledReplicatedMapQueryContext.SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); + } + } + public void incrementModCount() { contextModCount = rootContextOnThisSegment.latestSameThreadSegmentModCount = (rootContextOnThisSegment.latestSameThreadSegmentModCount) + 1; } @@ -1357,7 +1473,7 @@ public class CompiledReplicatedMapQueryContext newValue, long newSizeOfEverythingBeforeValue) { + this.free(pos(), entrySizeInChunks()); + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); + writeValueAndPutPos(newValue); + } + + private CompiledReplicatedMapQueryContext _Chaining_createChaining() { + return new CompiledReplicatedMapQueryContext(this); + } + public final int indexInContextChain; public int indexInContextChain() { return this.indexInContextChain; } - public class BytesReturnValue implements AutoCloseable , ReturnValue { - long startOutputPos; - - TcpSocketChannelEntryWriter output = null; - - public boolean outputInit() { - return (this.output) != null; - } - - public void initOutput(TcpSocketChannelEntryWriter output) { - this.output = output; - startOutputPos = output.in().position(); - } - - public long startOutputPos() { - assert this.outputInit() : "Output should be init"; - return this.startOutputPos; - } - - public TcpSocketChannelEntryWriter output() { - assert this.outputInit() : "Output should be init"; - return this.output; - } - - public void closeOutput() { - if (!(this.outputInit())) - return ; - - this.output = null; - } - - @Override - public void close() { - if ((output().in().position()) == (startOutputPos())) { - output().ensureBufferSize(1L); - output().in().writeBoolean(true); - } - } - - @Override - public void returnValue(@NotNull - Data value) { - long valueSize = value.size(); - long totalSize = (1L + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize))) + valueSize; - output().ensureBufferSize(totalSize); - Bytes out = output().in(); - out.writeBoolean(false); - CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(out, valueSize); - Full outAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(out); - long outPosition = out.position(); - out.skip(valueSize); - value.writeTo(outAccessor, out, outPosition); - } - } - public class DefaultReturnValue implements InstanceReturnValue { @Override public void returnValue(@NotNull - Data value) { + Data value) { initDefaultReturnedValue(value); } @@ -1528,7 +1608,7 @@ public class CompiledReplicatedMapQueryContext value) { + Data value) { defaultReturnedValue = value.getUsing(null); } @@ -1554,7 +1634,7 @@ public class CompiledReplicatedMapQueryContext implements KeyInitableData { + public class InputKeyInstanceData extends CopyingInstanceData implements KeyInitableData { private K key = null; public boolean keyInit() { @@ -1581,7 +1661,12 @@ public class CompiledReplicatedMapQueryContext implements ValueInitableData { + public class InputValueInstanceData extends CopyingInstanceData implements ValueInitableData { private V value = null; public boolean valueInit() { @@ -1654,7 +1734,12 @@ public class CompiledReplicatedMapQueryContext { @Override public void returnValue(@NotNull - Data value) { + Data value) { initReturnedValue(value); } @@ -1733,7 +1813,7 @@ public class CompiledReplicatedMapQueryContext value) { + Data value) { returnedValue = value.getUsing(usingReturnValue()); } @@ -1805,6 +1885,11 @@ public class CompiledReplicatedMapQueryContext _MapQuery_entry() { + this.checkOnEachPublicOperation(); + return entryPresent() ? this : null; + } + public static final int MAX_SEGMENT_CHUNKS = 1 << 30; public static final int MAX_SEGMENT_ENTRIES = 1 << 29; @@ -1847,7 +1932,7 @@ public class CompiledReplicatedMapQueryContext contextChain; + public final List contextChain; public final UpdateLock innerUpdateLock; @@ -1855,10 +1940,16 @@ public class CompiledReplicatedMapQueryContext contextChain() { + public List contextChain() { return this.contextChain; } + @Nullable + private MapAbsentEntry _MapQuery_absentEntry() { + this.checkOnEachPublicOperation(); + return entryPresent() ? null : this.absent(); + } + final BytesReturnValue bytesReturnValue; public BytesReturnValue bytesReturnValue() { @@ -1867,12 +1958,18 @@ public class CompiledReplicatedMapQueryContext entryBytesAccessor; + public final BytesStore entryBS; - public Full entryBytesAccessor() { - return this.entryBytesAccessor; - } - - @SuppressWarnings(value = "unchecked") - public final T entryBytesAccessHandle; - - public T entryBytesAccessHandle() { - return this.entryBytesAccessHandle; + public BytesStore entryBS() { + return this.entryBS; } public final BytesReader valueReader; @@ -2005,19 +2101,22 @@ public class CompiledReplicatedMapQueryContext entryBytesAccess; - - public Access entryBytesAccess() { - return this.entryBytesAccess; - } - public final BytesReader keyReader; public BytesReader keyReader() { return this.keyReader; } + @Override + public MapAbsentEntry absent() { + return this; + } + + @Override + public Data dummyZeroValue() { + return this.dummyValue; + } + @Override public ReplicatedChronicleMap m() { return m; @@ -2028,39 +2127,32 @@ public class CompiledReplicatedMapQueryContext absent() { - return CompiledReplicatedMapQueryContext.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.inputValueInstanceValue.closeBuffer(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); - } - - 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 long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); + public MVI valueMetaInterop(V value) { + return this.m().metaValueInteropProvider.get(this.copies, this.m().originalMetaValueInterop, valueInterop, value); } - public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + public void closeValueBytesInteropValueMetaInteropDependants() { + this.wrappedValueInstanceValue.closeBuffer(); + this.inputValueInstanceValue.closeBuffer(); } - @Override - public Data dummyZeroValue() { - return CompiledReplicatedMapQueryContext.this.dummyValue; + public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { + if (this.m().constantlySizedEntry) { + return this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); + } else if (this.m().couldNotDetermineAlignmentBeforeAllocation) { + return (sizeOfEverythingBeforeValue + (this.m().worstAlignment)) + valueSize; + } else { + return (this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; + } + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); } public void checkAccessingFromOwnerThread() { @@ -2070,19 +2162,7 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - private CompiledReplicatedMapQueryContext _Chaining_createChaining() { - return new CompiledReplicatedMapQueryContext(this); + this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); } public CompiledReplicatedMapQueryContext createChaining() { @@ -2102,41 +2182,64 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); } - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); } public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); + return this.h().metaKeyInteropProvider.get(this.copies, this.h().originalMetaKeyInterop, keyInterop, key); } public void closeKeyBytesInteropKeyMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); + this.inputKeyInstanceValue.closeBuffer(); } - public Data inputKey = null; + public long keyOffset = -1; + + public boolean keyOffsetInit() { + return (this.keyOffset) >= 0; + } + + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); + } + + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; + } + + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { + this.closeReplicatedMapEntryStagesKeyEndDependants(); + this.closeReplicatedMapQueryKeyEqualsDependants(); + this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + } + + public Data inputKey = null; public boolean inputKeyInit() { return (this.inputKey) != null; } - public void initInputKey(Data inputKey) { + public void initInputKey(Data inputKey) { this.inputKey = inputKey; this.closeInputKeyDependants(); } - public Data inputKey() { + public Data inputKey() { assert this.inputKeyInit() : "InputKey should be init"; return this.inputKey; } @@ -2150,8 +2253,8 @@ public class CompiledReplicatedMapQueryContext 0; } - long segmentHeaderAddress; - - SegmentHeader segmentHeader = null; - - public boolean segHeaderInit() { - return (this.segmentHeader) != null; + void initSegment() { + VanillaChronicleHash h = 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(); } - private void initSegHeader() { - segmentHeaderAddress = (CompiledReplicatedMapQueryContext.this.h().ms.address()) + (CompiledReplicatedMapQueryContext.this.h().segmentHeaderOffset(segmentIndex())); - segmentHeader = BigSegmentHeader.INSTANCE; - this.closeSegHeaderDependants(); + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.entrySpaceOffset; } - public long segmentHeaderAddress() { - if (!(this.segHeaderInit())) - this.initSegHeader(); + public SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); - return this.segmentHeaderAddress; + return this.freeList; } - public SegmentHeader segmentHeader() { - if (!(this.segHeaderInit())) - this.initSegHeader(); - - return this.segmentHeader; - } - - public void closeSegHeader() { - if (!(this.segHeaderInit())) + void closeSegment() { + if (!(this.segmentInit())) return ; - this.closeSegHeaderDependants(); - this.segmentHeader = null; + this.closeSegmentDependants(); + entrySpaceOffset = 0; } - public void closeSegHeaderDependants() { - CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); - CompiledReplicatedMapQueryContext.this.closeLocks(); - CompiledReplicatedMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); - } - - public void nextPosToSearchFrom(long nextPosToSearchFrom) { - segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); - } - - public void updateNextPosToSearchFrom(long allocated, int chunks) { - long nextPosToSearchFrom = allocated + chunks; - if (nextPosToSearchFrom >= (CompiledReplicatedMapQueryContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); - } - - public void entries(long size) { - segmentHeader().size(segmentHeaderAddress(), size); - } - - public long entries() { - return segmentHeader().size(segmentHeaderAddress()); - } - - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); - } - - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } - - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { - CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); - if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { - throw new IllegalStateException("Nested context not implemented yet"); - } else { - return false; - } - } - - public void closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants() { - CompiledReplicatedMapQueryContext.this.closeLocks(); - } - - int totalReadLockCount; - - int totalUpdateLockCount; - - int totalWriteLockCount; - - public int latestSameThreadSegmentModCount; - - public int contextModCount; - - CompiledReplicatedMapQueryContext nextNode; - - public boolean concurrentSameThreadContexts; - - LocalLockState localLockState; - - public CompiledReplicatedMapQueryContext rootContextOnThisSegment = null; - - public boolean locksInit() { - return (this.rootContextOnThisSegment) != null; - } - - void initLocks() { - localLockState = LocalLockState.UNLOCKED; - int indexOfThisContext = CompiledReplicatedMapQueryContext.this.indexInContextChain; - for (int i = indexOfThisContext - 1 ; i >= 0 ; i--) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - for (int i = indexOfThisContext + 1, size = CompiledReplicatedMapQueryContext.this.contextChain.size() ; i < size ; i++) { - if (tryFindInitLocksOfThisSegment(this, i)) - return ; - - } - rootContextOnThisSegment = this; - concurrentSameThreadContexts = false; - latestSameThreadSegmentModCount = 0; - contextModCount = 0; - nextNode = null; - totalReadLockCount = 0; - totalUpdateLockCount = 0; - totalWriteLockCount = 0; - this.closeLocksDependants(); - } - - public boolean concurrentSameThreadContexts() { - if (!(this.locksInit())) - this.initLocks(); - - return this.concurrentSameThreadContexts; - } - - public int contextModCount() { - if (!(this.locksInit())) - this.initLocks(); - - return this.contextModCount; - } - - public int latestSameThreadSegmentModCount() { - if (!(this.locksInit())) - this.initLocks(); - - return this.latestSameThreadSegmentModCount; - } - - public LocalLockState localLockState() { - if (!(this.locksInit())) - this.initLocks(); - - return this.localLockState; - } - - public CompiledReplicatedMapQueryContext rootContextOnThisSegment() { - if (!(this.locksInit())) - this.initLocks(); - - return this.rootContextOnThisSegment; - } - - void closeLocks() { - if (!(this.locksInit())) - return ; - - this.closeLocksDependants(); - if ((rootContextOnThisSegment) == this) { - closeRootLocks(); - } else { - closeNestedLocks(); - } - localLockState = null; - rootContextOnThisSegment = null; - } - - public void closeLocksDependants() { - CompiledReplicatedMapQueryContext.this.innerReadLock.closeReadLockLockDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + public void closeSegmentDependants() { + this.closeEntryOffset(); } int hashLookupEntrySize; @@ -2438,8 +2392,8 @@ public class CompiledReplicatedMapQueryContext= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + this.closeHashLookupSearchFoundDependants(); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + this.closeHashLookupHlPosDependants(); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + this.closeSearchKey(); } long entry(long key, long value) { @@ -2533,13 +2528,22 @@ public class CompiledReplicatedMapQueryContext= 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.closeHashLookupSearchFoundDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - 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 stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - public void found() { - CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.stepBack(CompiledReplicatedMapQueryContext.this.hashLookupPos())); - } - - public void closeHashLookupSearchFoundDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public boolean checkSlotIsEmpty() { - return CompiledReplicatedMapQueryContext.this.empty(CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos())); - } - - 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 put(long value) { - CompiledReplicatedMapQueryContext.this.checkValueForPut(value); - CompiledReplicatedMapQueryContext.this.writeEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos(), CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()), searchKey(), value); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - 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(); - } - - 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 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 checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; } public void putValueVolatile(long pos, long value) { @@ -2764,36 +2578,17 @@ public class CompiledReplicatedMapQueryContext 0; + String hashLookupToString() { + final StringBuilder sb = new StringBuilder("{"); + forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); } - 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 void moveChange(long oldPos, long newPos) { + this.m().moveChange(this.segmentIndex(), oldPos, newPos); } - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); + long segmentHeaderAddress; - return this.entrySpaceOffset; + SegmentHeader segmentHeader = null; + + public boolean segHeaderInit() { + return (this.segmentHeader) != null; } - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.freeList; + private void initSegHeader() { + segmentHeaderAddress = (this.h().ms.address()) + (this.h().segmentHeaderOffset(segmentIndex())); + segmentHeader = BigSegmentHeader.INSTANCE; + this.closeSegHeaderDependants(); } - void closeSegment() { - if (!(this.segmentInit())) + 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.closeSegmentDependants(); - entrySpaceOffset = 0; + this.closeSegHeaderDependants(); + this.segmentHeader = null; } - public void closeSegmentDependants() { - CompiledReplicatedMapQueryContext.this.closeEntryOffset(); + public void closeSegHeaderDependants() { + this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); + this.closeLocks(); + this.innerReadLock.closeReadLockLockDependants(); } - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - + public void nextPosToSearchFrom(long nextPosToSearchFrom) { + segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); } - public void clearSegment() { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - CompiledReplicatedMapQueryContext.this.clearHashLookup(); - freeList().clear(); - nextPosToSearchFrom(0L); - entries(0L); + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); } - public void clear() { - clearSegment(); + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); } public long alloc(int chunks) { - VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + VanillaChronicleHash h = this.h(); if (chunks > (h.maxChunksPerEntry)) throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); @@ -2917,26 +2721,303 @@ public class CompiledReplicatedMapQueryContext= 0 ; i--) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + for (int i = indexOfThisContext + 1, size = this.contextChain.size() ; i < size ; i++) { + if (tryFindInitLocksOfThisSegment(this, i)) + return ; + + } + rootContextOnThisSegment = this; + concurrentSameThreadContexts = false; + latestSameThreadSegmentModCount = 0; + contextModCount = 0; + nextNode = null; + totalReadLockCount = 0; + totalUpdateLockCount = 0; + totalWriteLockCount = 0; + this.closeLocksDependants(); + } + + public boolean concurrentSameThreadContexts() { + if (!(this.locksInit())) + this.initLocks(); + + return this.concurrentSameThreadContexts; + } + + public int contextModCount() { + if (!(this.locksInit())) + this.initLocks(); + + return this.contextModCount; + } + + public int latestSameThreadSegmentModCount() { + if (!(this.locksInit())) + this.initLocks(); + + return this.latestSameThreadSegmentModCount; + } + + public LocalLockState localLockState() { + if (!(this.locksInit())) + this.initLocks(); + + return this.localLockState; + } + + public CompiledReplicatedMapQueryContext rootContextOnThisSegment() { + if (!(this.locksInit())) + this.initLocks(); + + return this.rootContextOnThisSegment; + } + + void closeLocks() { + if (!(this.locksInit())) return ; - this.allocatedChunks = 0; + this.closeLocksDependants(); + if ((rootContextOnThisSegment) == (this)) { + closeRootLocks(); + } else { + closeNestedLocks(); + } + localLockState = null; + rootContextOnThisSegment = null; + } + + public void closeLocksDependants() { + this.innerReadLock.closeReadLockLockDependants(); + this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public void clearSegment() { + this.innerWriteLock.lock(); + this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); + } + + public void clear() { + clearSegment(); + } + + long searchKey = UNSET_KEY; + + long searchStartPos; + + public boolean searchKeyInit() { + return (this.searchKey) != (UNSET_KEY); + } + + void initSearchKey() { + searchKey = this.maskUnsetKey(this.h().hashSplitting.segmentHash(this.hashOfKey())); + searchStartPos = 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() { + this.closeHashLookupPos(); + this.closeHashLookupSearchNextPosDependants(); + this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public long hashLookupPos = -1; + + public boolean hashLookupPosInit() { + return (this.hashLookupPos) >= 0; + } + + public void initHashLookupPos() { + this.innerReadLock.lock(); + this.hashLookupPos = 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() { + this.closeHashLookupSearchNextPosDependants(); + this.closeHashLookupSearchFoundDependants(); + this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public void putVolatile(long value) { + this.checkValueForPut(value); + long currentEntry = this.readEntry(this.hashLookupPos()); + assert (this.key(currentEntry)) == (searchKey()); + this.writeEntryVolatile(this.hashLookupPos(), currentEntry, searchKey(), value); + } + + public long nextPos() { + long pos = this.hashLookupPos(); + while (true) { + long entry = this.readEntry(pos); + if (this.empty(entry)) { + this.setHashLookupPosGuarded(pos); + return -1L; + } + pos = this.step(pos); + if (pos == (searchStartPos())) + break; + + if ((this.key(entry)) == (searchKey())) { + this.setHashLookupPosGuarded(pos); + return 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() { + this.closeKeySearch(); + } + + public void putNewVolatile(long value) { + this.checkValueForPut(value); + long currentEntry = this.readEntry(this.hashLookupPos()); + this.writeEntryVolatile(this.hashLookupPos(), currentEntry, searchKey(), value); + } + + void put(long value) { + this.checkValueForPut(value); + this.writeEntry(this.hashLookupPos(), this.readEntry(this.hashLookupPos()), searchKey(), value); + } + + public void found() { + this.setHashLookupPosGuarded(this.stepBack(this.hashLookupPos())); + } + + public void closeHashLookupSearchFoundDependants() { + this.closeKeySearch(); + } + + public boolean checkSlotContainsExpectedKeyAndValue(long value) { + long entry = this.readEntry(this.hashLookupPos()); + return ((this.key(entry)) == (searchKey())) && ((this.value(entry)) == value); + } + + public void closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants() { + this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public void remove() { + this.setHashLookupPosGuarded(this.remove(this.hashLookupPos())); + } + + public boolean checkSlotIsEmpty() { + return this.empty(this.readEntry(this.hashLookupPos())); } public long pos = -1; @@ -2964,18 +3045,12 @@ public class CompiledReplicatedMapQueryContext= 0; - } - - public void initKeyOffset(long keyOffset) { - this.keyOffset = keyOffset; - this.closeKeyOffsetDependants(); - } - - public long keyOffset() { - assert this.keyOffsetInit() : "KeyOffset should be init"; - return this.keyOffset; - } - - public void closeKeyOffset() { - if (!(this.keyOffsetInit())) - return ; - - this.closeKeyOffsetDependants(); - this.keyOffset = -1; - } - - public void closeKeyOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + this.closeReplicatedMapEntryStagesEntrySizeDependants(); + this.closeReplicatedMapEntryStagesReadExistingEntryDependants(); } public void copyExistingEntry(long newPos, long bytesToCopy) { @@ -3060,7 +3090,615 @@ public class CompiledReplicatedMapQueryContext= 0; + } + + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); + } + + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; + } + + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; + } + + public void closeKeySizeDependants() { + this.closeReplicatedMapEntryStagesKeyEndDependants(); + this.closeReplicatedMapQueryKeyEqualsDependants(); + this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + this.closeReplicationState(); + this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + long countValueSizeOffset() { + return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { + this.closeValueSizeOffset(); + } + + public long valueSizeOffset = -1; + + public boolean valueSizeOffsetInit() { + return (this.valueSizeOffset) >= 0; + } + + void initValueSizeOffset() { + valueSizeOffset = countValueSizeOffset(); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + this.closeValSize(); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); + valueSize = this.m().readValueSize(entryBytes); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSize = oldValueSize; + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); + } + + public long valueOffset() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueSize; + } + + public void closeValSize() { + if (!(this.valSizeInit())) + return ; + + this.closeValSizeDependants(); + this.valueSize = -1; + } + + public void closeValSizeDependants() { + this.closeReplicatedMapEntryStagesEntryEndDependants(); + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + public void writeValue(Data value) { + value.writeTo(entryBS, valueOffset()); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.replicationBytesOffset = -1; + } + + void updateReplicationState(long timestamp, byte identifier) { + entryBytes.position(replicationBytesOffset()); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public void updatedReplicationStateOnAbsentEntry() { + if (!(this.replicationUpdateInit())) { + this.innerWriteLock.lock(); + updateReplicationState(this.m().timeProvider.currentTime(), this.m().identifier()); + } + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryDeleted() { + entryBS.writeBoolean(entryDeletedOffset(), true); + } + + public void writeEntryPresent() { + entryBS.writeBoolean(entryDeletedOffset(), false); + } + + public boolean entryDeleted() { + return entryBS.readBoolean(entryDeletedOffset()); + } + + public long timestamp() { + return entryBS.readLong(replicationBytesOffset()); + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + byte identifier() { + return entryBS.readByte(identifierOffset()); + } + + public void updatedReplicationStateOnPresentEntry() { + if (!(this.replicationUpdateInit())) { + this.innerWriteLock.lock(); + long timestamp; + if ((identifier()) != (this.m().identifier())) { + timestamp = Math.max(((timestamp()) + 1), this.m().timeProvider.currentTime()); + } else { + timestamp = this.m().timeProvider.currentTime(); + } + updateReplicationState(timestamp, this.m().identifier()); + } + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeReplicatedMapEntryStagesEntryEndDependants() { + this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + long entrySize() { + return (entryEnd()) - (keySizeOffset()); + } + + public void closeReplicatedMapEntryStagesEntrySizeDependants() { + this.closeTheEntrySizeInChunks(); + } + + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; + } + + void initTheEntrySizeInChunks() { + entrySizeInChunks = this.h().inChunks(entrySize()); + } + + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; + } + + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; + } + + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + return ; + + this.entrySizeInChunks = 0; + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + this.free(pos(), entrySizeInChunks()); + this.entries(((this.entries()) - 1L)); + this.incrementModCountGuarded(); + } + + boolean keyEquals() { + return ((inputKey().size()) == (this.keySize())) && (BytesUtil.bytesEqual(this.entryBS, this.keyOffset(), inputKey().bytes(), inputKey().offset(), this.keySize())); + } + + public void closeReplicatedMapQueryKeyEqualsDependants() { + this.closeKeySearch(); + } + + protected CompiledReplicatedMapQueryContext.SearchState searchState = null; + + boolean keySearchInit() { + return (this.searchState) != null; + } + + void initKeySearch() { + for (long pos ; (pos = this.nextPos()) >= 0L ; ) { + this.readExistingEntry(pos); + if (!(keyEquals())) + continue; + + this.found(); + keyFound(); + return ; + } + searchState = CompiledReplicatedMapQueryContext.SearchState.ABSENT; + this.closeKeySearchDependants(); + } + + public CompiledReplicatedMapQueryContext.SearchState searchState() { + if (!(this.keySearchInit())) + this.initKeySearch(); + + return this.searchState; + } + + void closeKeySearch() { + if (!(this.keySearchInit())) + return ; + + this.closeKeySearchDependants(); + this.searchState = null; + } + + public void closeKeySearchDependants() { + this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public void incrementSegmentEntriesIfNeeded() { + if ((this.searchState()) != (CompiledReplicatedMapQueryContext.SearchState.PRESENT)) { + this.entries(((this.entries()) + 1L)); + } + } + + public void dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed() { + if (this.locksInit()) { + if ((this.concurrentSameThreadContexts()) && ((this.rootContextOnThisSegment().latestSameThreadSegmentModCount()) != (this.contextModCount()))) { + if (keySearchInit()) { + if ((searchState()) == (CompiledReplicatedMapQueryContext.SearchState.PRESENT)) { + if (!(this.checkSlotContainsExpectedKeyAndValue(this.pos()))) + this.closeHashLookupPos(); + + } + } + } + } + } + + public void closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants() { + this.closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + public void checkOnEachPublicOperation() { + _CheckOnEachPublicOperation_checkOnEachPublicOperation(); + this.dropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailed(); + } + + public void closeQueryCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { + this.entryValue.closeEntryValueBytesDataSizeDependants(); + this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.replaceValue(entry, newValue); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + this.checkOnEachPublicOperation(); + return this.innerUpdateLock; + } + + @NotNull + @Override + public Data absentKey() { + this.checkOnEachPublicOperation(); + return this.inputKey(); + } + + @NotNull + @Override + public InterProcessLock readLock() { + this.checkOnEachPublicOperation(); + return this.innerReadLock; + } + + public Data queriedKey() { + this.checkOnEachPublicOperation(); + return inputKey(); + } + + @NotNull + @Override + public Data defaultValue() { + this.checkOnEachPublicOperation(); + return this.wrapValueAsValue(this.m().defaultValue(this.deprecatedMapKeyContext)); + } + + @Override + public void raiseChanged() { + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); + this.raiseChange(); + } + + @NotNull + @Override + public Data key() { + this.checkOnEachPublicOperation(); + return this.entryKey; + } + + @NotNull + @Override + public MapContext context() { + this.checkOnEachPublicOperation(); + return this; + } + + @Override + public R remove(@NotNull + MapEntry entry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + this.checkOnEachPublicOperation(); + return this.innerWriteLock; + } + + @Override + public void updateOrigin(byte newIdentifier, long newTimestamp) { + this.checkOnEachPublicOperation(); + this.innerWriteLock.lock(); + updateReplicationState(newTimestamp, newIdentifier); + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.insert(absentEntry, value); + } + + @Override + public void dropChanged() { + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); + this.dropChange(); + } + + @Override + public Data wrapValueAsValue(V value) { + this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public Data value() { + this.checkOnEachPublicOperation(); + return this.entryValue; + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + this.checkOnEachPublicOperation(); + return this.m().entryOperations.defaultValue(absentEntry); + } + + @Override + public long originTimestamp() { + this.checkOnEachPublicOperation(); + return timestamp(); + } + + @Override + public byte originIdentifier() { + this.checkOnEachPublicOperation(); + return identifier(); + } + + public boolean searchStateDeleted() { + return (((searchState()) == (CompiledReplicatedMapQueryContext.SearchState.DELETED)) && (!(this.concurrentSameThreadContexts()))) && (this.innerUpdateLock.isHeldByCurrentThread()); + } + + public boolean searchStatePresent() { + return (searchState()) == (CompiledReplicatedMapQueryContext.SearchState.PRESENT); + } + + public boolean entryPresent() { + return (_MapQuery_entryPresent()) && (!(this.entryDeleted())); + } + + @Nullable + @Override + public MapAbsentEntry absentEntry() { + this.checkOnEachPublicOperation(); + if (entryPresent()) { + return null; + } else { + if (!(searchStatePresent())) { + return this.absentDelegating; + } else { + assert this.entryDeleted(); + return this.absent(); + } + } + } + + @Override + public MapReplicableEntry entry() { + return ((MapReplicableEntry)(_MapQuery_entry())); + } + + public boolean searchStateAbsent() { + return (!(searchStatePresent())) && (!(searchStateDeleted())); + } + + protected void putPrefix() { + this.checkOnEachPublicOperation(); + boolean underUpdatedLockIsHeld = !(this.innerUpdateLock.isHeldByCurrentThread()); + if (underUpdatedLockIsHeld) + this.innerUpdateLock.lock(); + + boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (this.concurrentSameThreadContexts()); + if (((this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) + this.closeHashLookupPos(); + + } + + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBS, keyOffset()); } public long innerRemoteTimestamp; @@ -3096,757 +3734,82 @@ public class CompiledReplicatedMapQueryContext= 0; - } - - private void initInputKeyOffsets() { - inputKeySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(inputBytes()); - inputKeyOffset = inputBytes().position(); - this.closeInputKeyOffsetsDependants(); - } - - public long inputKeyOffset() { - if (!(this.inputKeyOffsetsInit())) - this.initInputKeyOffsets(); - - return this.inputKeyOffset; - } - - public long inputKeySize() { - if (!(this.inputKeyOffsetsInit())) - this.initInputKeyOffsets(); - - return this.inputKeySize; - } - - public void closeInputKeyOffsets() { - if (!(this.inputKeyOffsetsInit())) - return ; - - this.closeInputKeyOffsetsDependants(); - this.inputKeySize = -1; - } - - public void closeInputKeyOffsetsDependants() { - CompiledReplicatedMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.closeFirstInputValueOffsets(); - } - - public long firstInputValueSize = -1; - - public long firstInputValueOffset; - - public boolean firstInputValueOffsetsInit() { - return (this.firstInputValueSize) >= 0; - } - - private void initFirstInputValueOffsets() { - CompiledReplicatedMapQueryContext.this.inputBytes().position(((CompiledReplicatedMapQueryContext.this.inputKeyOffset()) + (CompiledReplicatedMapQueryContext.this.inputKeySize()))); - firstInputValueSize = CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledReplicatedMapQueryContext.this.inputBytes()); - firstInputValueOffset = CompiledReplicatedMapQueryContext.this.inputBytes().position(); - this.closeFirstInputValueOffsetsDependants(); - } - - public long firstInputValueOffset() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueOffset; - } - - public long firstInputValueSize() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueSize; - } - - public void closeFirstInputValueOffsets() { - if (!(this.firstInputValueOffsetsInit())) - return ; - - this.closeFirstInputValueOffsetsDependants(); - this.firstInputValueSize = -1; - } - - public void closeFirstInputValueOffsetsDependants() { - CompiledReplicatedMapQueryContext.this.closeSecondInputValueOffsets(); - CompiledReplicatedMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); - } - - public long secondInputValueSize = -1; - - public long secondInputValueOffset; - - public boolean secondInputValueOffsetsInit() { - return (this.secondInputValueSize) >= 0; - } - - private void initSecondInputValueOffsets() { - CompiledReplicatedMapQueryContext.this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); - secondInputValueSize = CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledReplicatedMapQueryContext.this.inputBytes()); - secondInputValueOffset = CompiledReplicatedMapQueryContext.this.inputBytes().position(); - this.closeSecondInputValueOffsetsDependants(); - } - - public long secondInputValueOffset() { - if (!(this.secondInputValueOffsetsInit())) - this.initSecondInputValueOffsets(); - - return this.secondInputValueOffset; - } - - public long secondInputValueSize() { - if (!(this.secondInputValueOffsetsInit())) - this.initSecondInputValueOffsets(); - - return this.secondInputValueSize; - } - - public void closeSecondInputValueOffsets() { - if (!(this.secondInputValueOffsetsInit())) - return ; - - this.closeSecondInputValueOffsetsDependants(); - this.secondInputValueSize = -1; - } - - public void closeSecondInputValueOffsetsDependants() { - CompiledReplicatedMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); - } - - public long keySize = -1; - - public boolean keySizeInit() { - return (this.keySize) >= 0; - } - - public void initKeySize(long keySize) { - this.keySize = keySize; - this.closeKeySizeDependants(); - } - - public long keySize() { - assert this.keySizeInit() : "KeySize should be init"; - return this.keySize; - } - - public void closeKeySize() { - if (!(this.keySizeInit())) - return ; - - this.closeKeySizeDependants(); - this.keySize = -1; - } - - public void closeKeySizeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - } - - public void writeNewEntry(long pos, Data key) { - initPos(pos); - initKeySize(key.size()); - entryBytes.position(keySizeOffset()); - CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); - initKeyOffset(entryBytes.position()); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); - } - - 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.readExistingEntry(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.writeNewEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.copyExistingEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); - incrementSegmentEntriesIfNeeded(); - } - - public 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.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); - } - - @NotNull - @Override - public MapContext context() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return this; - } - - public Data queriedKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerWriteLock; - } - @Override public long remoteTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + this.checkOnEachPublicOperation(); return innerRemoteTimestamp(); } - @Override - public Data wrapValueAsValue(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceData wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Data value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public void raiseChanged() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - CompiledReplicatedMapQueryContext.this.raiseChange(); - } - - @NotNull - @Override - public Data absentKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.inputKey(); - } - - @NotNull - @Override - public Data value() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryValue; - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerUpdateLock; - } - - @NotNull - @Override - public Data defaultValue() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Data newValue) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public Data defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @Override - public void dropChanged() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - CompiledReplicatedMapQueryContext.this.dropChange(); + private boolean testTimeStampInSensibleRange() { + if ((this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (this.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (this.innerRemoteTimestamp()); + } + return true; } @Override public byte remoteIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + this.checkOnEachPublicOperation(); return innerRemoteIdentifier(); } - @NotNull - @Override - public InterProcessLock readLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerReadLock; + public int allocatedChunks = 0; + + public boolean allocatedChunksInit() { + return (this.allocatedChunks) != 0; } - @NotNull - @Override - public Data key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryKey; + public void initAllocatedChunks(int allocatedChunks) { + this.allocatedChunks = allocatedChunks; } - public boolean searchStateDeleted() { - return (((searchState()) == (SearchState.DELETED)) && (!(CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); + public int allocatedChunks() { + assert this.allocatedChunksInit() : "AllocatedChunks should be init"; + return this.allocatedChunks; } - public boolean searchStateAbsent() { - return (!(searchStatePresent())) && (!(searchStateDeleted())); - } - - protected void putPrefix() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - boolean underUpdatedLockIsHeld = !(CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); - if (underUpdatedLockIsHeld) - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - - boolean searchResultsNotTrusted = underUpdatedLockIsHeld || (CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()); - if (((CompiledReplicatedMapQueryContext.this.hashLookupPosInit()) && (searchStateAbsent())) && searchResultsNotTrusted) - CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); - - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationState(); - } - - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValueSizeOffset(); - } - - public long valueSizeOffset = -1; - - public boolean valueSizeOffsetInit() { - return (this.valueSizeOffset) >= 0; - } - - void initValueSizeOffset() { - valueSizeOffset = countValueSizeOffset(); - this.closeValueSizeOffsetDependants(); - } - - public long valueSizeOffset() { - if (!(this.valueSizeOffsetInit())) - this.initValueSizeOffset(); - - return this.valueSizeOffset; - } - - public void closeValueSizeOffset() { - if (!(this.valueSizeOffsetInit())) + public void closeAllocatedChunks() { + if (!(this.allocatedChunksInit())) return ; - this.closeValueSizeOffsetDependants(); - this.valueSizeOffset = -1; + this.allocatedChunks = 0; } - public void closeValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValSize(); - } - - public long valueSize = -1; - - public long valueOffset; - - public boolean valSizeInit() { - return (this.valueSize) >= 0; - } - - void initValSize() { - entryBytes.position(valueSizeOffset()); - valueSize = CompiledReplicatedMapQueryContext.this.m().readValueSize(entryBytes); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSize(long valueSize) { - this.valueSize = valueSize; - entryBytes.position(valueSizeOffset()); - CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - countValueOffset(); - this.closeValSizeDependants(); - } - - void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSize = oldValueSize; - valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); - this.closeValSizeDependants(); - } - - public long valueOffset() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valSizeInit())) - this.initValSize(); - - return this.valueSize; - } - - public void closeValSize() { - if (!(this.valSizeInit())) - return ; - - this.closeValSizeDependants(); - this.valueSize = -1; - } - - public void closeValSizeDependants() { - CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeReplicatedMapEntryStagesEntryEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - } - - long entrySize() { - return (entryEnd()) - (keySizeOffset()); - } - - public void closeReplicatedMapEntryStagesEntrySizeDependants() { - CompiledReplicatedMapQueryContext.this.closeTheEntrySizeInChunks(); - } - - public int entrySizeInChunks = 0; - - public boolean theEntrySizeInChunksInit() { - return (this.entrySizeInChunks) != 0; - } - - void initTheEntrySizeInChunks() { - entrySizeInChunks = CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize()); - } - - public void initTheEntrySizeInChunks(int actuallyUsedChunks) { - entrySizeInChunks = actuallyUsedChunks; - } - - public int entrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - this.initTheEntrySizeInChunks(); - - return this.entrySizeInChunks; - } - - public void closeTheEntrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - return ; - - this.entrySizeInChunks = 0; + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { + initAllocatedChunks(this.h().inChunks(entrySize)); + this.copyExistingEntry(this.alloc(allocatedChunks()), bytesToCopy); + incrementSegmentEntriesIfNeeded(); } public final void freeExtraAllocatedChunks() { - if (((!(CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapQueryContext.this.allocatedChunks()))) { - CompiledReplicatedMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); + if (((!(this.m().constantlySizedEntry)) && (this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (this.allocatedChunks()))) { + this.free(((pos()) + (entrySizeInChunks())), ((this.allocatedChunks()) - (entrySizeInChunks()))); } else { - initTheEntrySizeInChunks(CompiledReplicatedMapQueryContext.this.allocatedChunks()); + initTheEntrySizeInChunks(this.allocatedChunks()); } } - public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); - CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - } - - public void writeValue(Data value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); - } - - public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - assert oldValueSize == (value.size()); - initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); - writeValue(value); - } - - public void initValue(Data value) { - entryBytes.position(valueSizeOffset()); - initValSize(value.size()); - writeValue(value); - } - - public void writeValueAndPutPos(Data value) { + public void writeValueAndPutPos(Data value) { initValue(value); freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + this.putValueVolatile(this.hashLookupPos(), pos()); } - private void _MapEntryStages_relocation(Data newValue, long newSizeOfEverythingBeforeValue) { - CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - (keySizeOffset()))); - writeValueAndPutPos(newValue); - } - - protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { long oldPos = pos(); _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); - CompiledReplicatedMapQueryContext.this.moveChange(oldPos, pos()); + this.moveChange(oldPos, pos()); } - void putEntry(Data value) { - assert CompiledReplicatedMapQueryContext.this.searchStateAbsent(); - long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(CompiledReplicatedMapQueryContext.this.inputKey().size(), value.size()); - CompiledReplicatedMapQueryContext.this.initEntryAndKey(entrySize); - CompiledReplicatedMapQueryContext.this.initValue(value); - CompiledReplicatedMapQueryContext.this.freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putNewVolatile(CompiledReplicatedMapQueryContext.this.pos()); - } - - public long newSizeOfEverythingBeforeValue(Data newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - private void _MapEntryStages_putValueDeletedEntry(Data newValue) { - assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); - int newSizeInChunks; - long entryStartOffset = keySizeOffset(); - long newSizeOfEverythingBeforeValue = -1; - boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); - if (newValueSizeIsDifferent) { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - long newValueOffset = CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); - long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; - newSizeInChunks = CompiledReplicatedMapQueryContext.this.m().inChunks(newEntrySize); - } else { - newSizeInChunks = entrySizeInChunks(); - } - if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapQueryContext.this.freeList().size())) && (CompiledReplicatedMapQueryContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { - CompiledReplicatedMapQueryContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - CompiledReplicatedMapQueryContext.this.incrementSegmentEntriesIfNeeded(); - if (newValueSizeIsDifferent) { - initValue(newValue); - } else { - writeValue(newValue); - } - } else { - if (newValueSizeIsDifferent) { - assert newSizeOfEverythingBeforeValue >= 0; - } else { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - } - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - if (newValueSizeIsDifferent) { - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledReplicatedMapQueryContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - public void putValueDeletedEntry(Data newValue) { - throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); - } - - public void innerDefaultReplaceValue(Data newValue) { - assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); + public void innerDefaultReplaceValue(Data newValue) { + assert this.innerUpdateLock.isHeldByCurrentThread(); boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); if (newValueSizeIsDifferent) { long newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); long entryStartOffset = keySizeOffset(); - VanillaChronicleMap m = CompiledReplicatedMapQueryContext.this.m(); + VanillaChronicleMap m = this.m(); long newValueOffset = m.alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; int newSizeInChunks = m.inChunks(newEntrySize); @@ -3854,257 +3817,104 @@ public class CompiledReplicatedMapQueryContext (m.maxChunksPerEntry)) { throw new IllegalArgumentException(((((("Value too large: " + "entry takes ") + newSizeInChunks) + " chunks, ") + (m.maxChunksPerEntry)) + " is maximum.")); } - if (CompiledReplicatedMapQueryContext.this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { - CompiledReplicatedMapQueryContext.this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); + if (this.freeList().allClear(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks))) { + this.freeList().set(((pos()) + (entrySizeInChunks())), ((pos()) + newSizeInChunks)); break newValueDoesNotFit; } relocation(newValue, newSizeOfEverythingBeforeValue); return ; } else if (newSizeInChunks < (entrySizeInChunks())) { - CompiledReplicatedMapQueryContext.this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); + this.freeList().clear(((pos()) + newSizeInChunks), ((pos()) + (entrySizeInChunks()))); } } else { } - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); + this.innerWriteLock.lock(); if (newValueSizeIsDifferent) { initValue(newValue); } else { writeValue(newValue); } - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; - } - - void initReplicationState() { - replicationBytesOffset = keyEnd(); - } - - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) - return ; - - this.replicationBytesOffset = -1; - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - private boolean _MapQuery_entryPresent() { - return searchStatePresent(); - } - - public boolean entryPresent() { - return (_MapQuery_entryPresent()) && (!(CompiledReplicatedMapQueryContext.this.entryDeleted())); - } - - private MapEntry _MapQuery_entry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; + this.putValueVolatile(this.hashLookupPos(), pos()); } @Override - public MapReplicableEntry entry() { - return ((MapReplicableEntry)(_MapQuery_entry())); + public void doReplaceValue(Data newValue) { + _MapQuery_doReplaceValue(newValue); + this.updateChange(); + this.updatedReplicationStateOnPresentEntry(); } - @Nullable - private MapAbsentEntry _MapQuery_absentEntry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledReplicatedMapQueryContext.this.absent(); - } - - @Nullable @Override - public MapAbsentEntry absentEntry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + public void doRemove() { + this.checkOnEachPublicOperation(); + this.innerUpdateLock.lock(); if (entryPresent()) { - return null; + if ((this.valueSize()) > (this.dummyValue.size())) + this.innerDefaultReplaceValue(this.dummyValue); + + this.updatedReplicationStateOnPresentEntry(); + this.writeEntryDeleted(); + this.updateChange(); + this.deleted(((this.deleted()) + 1)); } else { - if (!(searchStatePresent())) { - return CompiledReplicatedMapQueryContext.this.absentDelegating; - } else { - assert CompiledReplicatedMapQueryContext.this.entryDeleted(); - return CompiledReplicatedMapQueryContext.this.absent(); - } + throw new IllegalStateException("Entry is absent in the map when doRemove() is called"); } } - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + public void putValueDeletedEntry(Data newValue) { + throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); } - void updateReplicationState(long timestamp, byte identifier) { - entryBytes.position(replicationBytesOffset()); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); + public void initEntryAndKey(long entrySize) { + initAllocatedChunks(this.h().inChunks(entrySize)); + this.writeNewEntry(this.alloc(allocatedChunks()), this.inputKey()); + incrementSegmentEntriesIfNeeded(); + } + + void putEntry(Data value) { + assert this.searchStateAbsent(); + long entrySize = this.entrySize(this.inputKey().size(), value.size()); + this.initEntryAndKey(entrySize); + this.initValue(value); + this.freeExtraAllocatedChunks(); + this.putNewVolatile(this.pos()); } @Override - public void updateOrigin(byte newIdentifier, long newTimestamp) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - updateReplicationState(newTimestamp, newIdentifier); - } - - public void updatedReplicationStateOnAbsentEntry() { - if (!(CompiledReplicatedMapQueryContext.this.replicationUpdateInit())) { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - updateReplicationState(CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(), CompiledReplicatedMapQueryContext.this.m().identifier()); - } - } - - private void _MapAbsent_doInsert(Data value) { - CompiledReplicatedMapQueryContext.this.putPrefix(); - if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { - if (CompiledReplicatedMapQueryContext.this.searchStateDeleted()) { - CompiledReplicatedMapQueryContext.this.putValueDeletedEntry(value); - } else { + public void doInsert(Data value) { + this.putPrefix(); + if (!(this.entryPresent())) { + if (!(this.searchStatePresent())) { putEntry(value); - } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - CompiledReplicatedMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is present in the map when doInsert() is called"); - } - } - - @Override - public void doInsert(Data value) { - CompiledReplicatedMapQueryContext.this.putPrefix(); - if (!(CompiledReplicatedMapQueryContext.this.entryPresent())) { - if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { - putEntry(value); - CompiledReplicatedMapQueryContext.this.setSearchStateGuarded(SearchState.PRESENT); + this.setSearchStateGuarded(CompiledReplicatedMapQueryContext.SearchState.PRESENT); } else { - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(value); - CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) - 1)); + this.innerDefaultReplaceValue(value); + this.deleted(((this.deleted()) - 1)); } - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - CompiledReplicatedMapQueryContext.this.writeEntryPresent(); - CompiledReplicatedMapQueryContext.this.updateChange(); - CompiledReplicatedMapQueryContext.this.updatedReplicationStateOnAbsentEntry(); + this.incrementModCountGuarded(); + this.writeEntryPresent(); + this.updateChange(); + this.updatedReplicationStateOnAbsentEntry(); } else { throw new IllegalStateException("Entry is absent in the map when doInsert() is called"); } } - private long timestampOffset() { - return replicationBytesOffset(); + boolean used; + + public boolean usedInit() { + return used; } - public long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + public void initUsed(boolean used) { + this.used = used; } - private boolean testTimeStampInSensibleRange() { - if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { - long currentTime = TimeProvider.SYSTEM.currentTime(); - assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); - assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp()); - } - return true; - } + void closeUsed() { + if (!(this.usedInit())) + return ; - @Override - public long originTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - public void updatedReplicationStateOnPresentEntry() { - if (!(CompiledReplicatedMapQueryContext.this.replicationUpdateInit())) { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - long timestamp; - if ((identifier()) != (CompiledReplicatedMapQueryContext.this.m().identifier())) { - timestamp = Math.max(((timestamp()) + 1), CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime()); - } else { - timestamp = CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(); - } - updateReplicationState(timestamp, CompiledReplicatedMapQueryContext.this.m().identifier()); - } - } - - private void _MapQuery_doReplaceValue(Data 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 doReplaceValue(Data newValue) { - _MapQuery_doReplaceValue(newValue); - CompiledReplicatedMapQueryContext.this.updateChange(); - CompiledReplicatedMapQueryContext.this.updatedReplicationStateOnPresentEntry(); - } - - private void _MapQuery_doRemove() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - if (searchStatePresent()) { - CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); - CompiledReplicatedMapQueryContext.this.remove(); - CompiledReplicatedMapQueryContext.this.innerRemoveEntryExceptHashLookupUpdate(); - setSearchStateGuarded(SearchState.DELETED); - } else { - throw new IllegalStateException("Entry is absent when doRemove() is called"); - } - } - - @Override - public void doRemove() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.innerUpdateLock.lock(); - if (entryPresent()) { - if ((CompiledReplicatedMapQueryContext.this.valueSize()) > (CompiledReplicatedMapQueryContext.this.dummyValue.size())) - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(CompiledReplicatedMapQueryContext.this.dummyValue); - - CompiledReplicatedMapQueryContext.this.updatedReplicationStateOnPresentEntry(); - CompiledReplicatedMapQueryContext.this.writeEntryDeleted(); - CompiledReplicatedMapQueryContext.this.updateChange(); - CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) + 1)); - } else { - throw new IllegalStateException("Entry is absent in the map when doRemove() is called"); - } + used = false; } public long riKeySize = -1; @@ -4127,11 +3937,11 @@ public class CompiledReplicatedMapQueryContext= 0; + } + + private void initInputKeyOffsets() { + inputKeySize = this.h().keySizeMarshaller.readSize(inputBytes()); + inputKeyOffset = inputBytes().position(); + this.closeInputKeyOffsetsDependants(); + } + + public long inputKeyOffset() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeyOffset; + } + + public long inputKeySize() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeySize; + } + + public void closeInputKeyOffsets() { + if (!(this.inputKeyOffsetsInit())) + return ; + + this.closeInputKeyOffsetsDependants(); + this.inputKeySize = -1; + } + + public void closeInputKeyOffsetsDependants() { + this.closeFirstInputValueOffsets(); + this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); + this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + } + + public long firstInputValueSize = -1; + + public long firstInputValueOffset; + + public boolean firstInputValueOffsetsInit() { + return (this.firstInputValueSize) >= 0; + } + + private void initFirstInputValueOffsets() { + this.inputBytes().position(((this.inputKeyOffset()) + (this.inputKeySize()))); + firstInputValueSize = this.m().valueSizeMarshaller.readSize(this.inputBytes()); + firstInputValueOffset = this.inputBytes().position(); + this.closeFirstInputValueOffsetsDependants(); + } + + public long firstInputValueOffset() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueOffset; + } + + public long firstInputValueSize() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueSize; + } + + public void closeFirstInputValueOffsets() { + if (!(this.firstInputValueOffsetsInit())) + return ; + + this.closeFirstInputValueOffsetsDependants(); + this.firstInputValueSize = -1; + } + + public void closeFirstInputValueOffsetsDependants() { + this.closeSecondInputValueOffsets(); + this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); + this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + } + + public long secondInputValueSize = -1; + + public long secondInputValueOffset; + + public boolean secondInputValueOffsetsInit() { + return (this.secondInputValueSize) >= 0; + } + + private void initSecondInputValueOffsets() { + this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); + secondInputValueSize = this.m().valueSizeMarshaller.readSize(this.inputBytes()); + secondInputValueOffset = this.inputBytes().position(); + this.closeSecondInputValueOffsetsDependants(); + } + + public long secondInputValueOffset() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueOffset; + } + + public long secondInputValueSize() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueSize; + } + + public void closeSecondInputValueOffsets() { + if (!(this.secondInputValueOffsetsInit())) + return ; + + this.closeSecondInputValueOffsetsDependants(); + this.secondInputValueSize = -1; + } + + public void closeSecondInputValueOffsetsDependants() { + this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); + this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java b/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java index 293808f1f..6fff8179e 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java +++ b/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java @@ -6,19 +6,19 @@ import net.openhft.chronicle.map.ExternalMapQueryContext; import net.openhft.chronicle.map.MapKeyContext; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; -import net.openhft.chronicle.map.impl.value.instance.ValueInitableData; +import net.openhft.chronicle.map.impl.data.instance.ValueInitableData; public interface QueryContextInterface extends ExternalMapQueryContext { - void initInputKey(Data inputKey); + void initInputKey(Data inputKey); - KeyInitableData inputKeyInstanceValue(); + KeyInitableData inputKeyInstanceValue(); InstanceReturnValue defaultReturnValue(); UsableReturnValue usingReturnValue(); - ValueInitableData inputValueInstanceValue(); + ValueInitableData inputValueInstanceValue(); MapKeyContext deprecatedMapKeyContext(); diff --git a/src/main/java/net/openhft/chronicle/map/impl/data/instance/ValueInitableData.java b/src/main/java/net/openhft/chronicle/map/impl/data/instance/ValueInitableData.java new file mode 100644 index 000000000..10990223f --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/impl/data/instance/ValueInitableData.java @@ -0,0 +1,8 @@ +package net.openhft.chronicle.map.impl.data.instance; + +import net.openhft.chronicle.hash.Data; + +public interface ValueInitableData extends Data { + + void initValue(V value); +} diff --git a/src/main/java/net/openhft/chronicle/map/impl/value/instance/ValueInitableData.java b/src/main/java/net/openhft/chronicle/map/impl/value/instance/ValueInitableData.java deleted file mode 100644 index b49ed15e9..000000000 --- a/src/main/java/net/openhft/chronicle/map/impl/value/instance/ValueInitableData.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.openhft.chronicle.map.impl.value.instance; - -import net.openhft.chronicle.hash.Data; - -public interface ValueInitableData extends Data { - - void initValue(V value); -} diff --git a/src/main/java/net/openhft/chronicle/map/replication/MapRemoteOperations.java b/src/main/java/net/openhft/chronicle/map/replication/MapRemoteOperations.java index d396069fd..d8fe5998d 100644 --- a/src/main/java/net/openhft/chronicle/map/replication/MapRemoteOperations.java +++ b/src/main/java/net/openhft/chronicle/map/replication/MapRemoteOperations.java @@ -170,7 +170,7 @@ public interface MapRemoteOperations { * @param q the remote operation context * @param newValue the new value to put */ - default void put(MapRemoteQueryContext q, Data newValue) { + default void put(MapRemoteQueryContext q, Data newValue) { MapReplicableEntry entry = q.entry(); if (entry != null) { if (decideOnRemoteModification(entry, q) == ACCEPT) { diff --git a/src/main/java/net/openhft/chronicle/map/replication/MapRemoteQueryContext.java b/src/main/java/net/openhft/chronicle/map/replication/MapRemoteQueryContext.java index 29ee474ee..795cc676d 100644 --- a/src/main/java/net/openhft/chronicle/map/replication/MapRemoteQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/replication/MapRemoteQueryContext.java @@ -20,7 +20,6 @@ package net.openhft.chronicle.map.replication; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.replication.HashRemoteQueryContext; -import net.openhft.chronicle.hash.replication.RemoteOperationContext; import net.openhft.chronicle.hash.serialization.SizeMarshaller; import net.openhft.chronicle.map.ChronicleMap; import net.openhft.chronicle.map.ChronicleMapBuilder; @@ -54,5 +53,5 @@ public interface MapRemoteQueryContext extends MapQueryContext * * @return dummy value of all zeros, of the minimum possible size. */ - Data dummyZeroValue(); + Data dummyZeroValue(); } diff --git a/src/main/java/net/openhft/chronicle/set/SetFromMap.java b/src/main/java/net/openhft/chronicle/set/SetFromMap.java index 862dc4895..64bb56252 100644 --- a/src/main/java/net/openhft/chronicle/set/SetFromMap.java +++ b/src/main/java/net/openhft/chronicle/set/SetFromMap.java @@ -142,7 +142,7 @@ class SetFromMap extends AbstractSet @NotNull @Override - public ExternalSetQueryContext queryContext(Data key) { + public ExternalSetQueryContext queryContext(Data key) { //TODO throw new UnsupportedOperationException(); } diff --git a/src/test/java/net/openhft/chronicle/map/BiMapTest.java b/src/test/java/net/openhft/chronicle/map/BiMapTest.java index 385510833..3fe1a8e3b 100644 --- a/src/test/java/net/openhft/chronicle/map/BiMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/BiMapTest.java @@ -40,7 +40,7 @@ public class BiMapTest { } @Override - public void put(MapQueryContext q, Data value, + public void put(MapQueryContext q, Data value, ReturnValue returnValue) { while (true) { q.updateLock().lock(); @@ -59,7 +59,7 @@ public class BiMapTest { } @Override - public void putIfAbsent(MapQueryContext q, Data value, + public void putIfAbsent(MapQueryContext q, Data value, ReturnValue returnValue) { while (true) { try { @@ -88,7 +88,7 @@ public class BiMapTest { } @Override - public boolean remove(MapQueryContext q, Data value) { + public boolean remove(MapQueryContext q, Data value) { while (true) { q.updateLock().lock(); MapEntry entry = q.entry(); @@ -116,14 +116,14 @@ public class BiMapTest { } @Override - public void replace(MapQueryContext q, Data value, + public void replace(MapQueryContext q, Data value, ReturnValue returnValue) { throw new UnsupportedOperationException(); } @Override - public boolean replace(MapQueryContext q, Data oldValue, - Data newValue) { + public boolean replace(MapQueryContext q, Data oldValue, + Data newValue) { throw new UnsupportedOperationException(); } @@ -135,7 +135,7 @@ public class BiMapTest { } @Override - public void merge(MapQueryContext q, Data value, + public void merge(MapQueryContext q, Data value, BiFunction remappingFunction, ReturnValue returnValue) { throw new UnsupportedOperationException(); @@ -171,13 +171,13 @@ public class BiMapTest { } @Override - public DualLockSuccess replaceValue(@NotNull MapEntry entry, Data newValue) { + public DualLockSuccess replaceValue(@NotNull MapEntry entry, Data newValue) { throw new UnsupportedOperationException(); } @Override public DualLockSuccess insert(@NotNull MapAbsentEntry absentEntry, - Data value) { + Data value) { try (ExternalMapQueryContext rq = reverse.queryContext(value)) { if (!rq.updateLock().tryLock()) return FAIL; @@ -187,7 +187,7 @@ public class BiMapTest { reverseAbsentEntry.doInsert(absentEntry.absentKey()); return SUCCESS; } else { - Data reverseKey = rq.entry().value(); + Data reverseKey = rq.entry().value(); if (reverseKey.equals(absentEntry.absentKey())) { // recover absentEntry.doInsert(value); diff --git a/src/test/java/net/openhft/chronicle/map/GuavaTest.java b/src/test/java/net/openhft/chronicle/map/GuavaTest.java index 26802a58e..5d96efb78 100644 --- a/src/test/java/net/openhft/chronicle/map/GuavaTest.java +++ b/src/test/java/net/openhft/chronicle/map/GuavaTest.java @@ -141,7 +141,7 @@ public class GuavaTest extends TestCase { @Override public Void replaceValue(@NotNull MapEntry entry, - net.openhft.chronicle.hash.Data newValue) { + net.openhft.chronicle.hash.Data newValue) { Assert.assertEquals(m, entry.context().map()); m.put(entry.key().get().toString(), newValue.get().toString()); return MapEntryOperations.super.replaceValue(entry, newValue); @@ -149,7 +149,7 @@ public class GuavaTest extends TestCase { @Override public Void insert(@NotNull MapAbsentEntry absentEntry, - Data value) { + Data value) { Assert.assertEquals(m, absentEntry.context().map()); m.put(absentEntry.absentKey().get().toString(), value.get().toString()); return MapEntryOperations.super.insert(absentEntry, value); diff --git a/src/test/java/net/openhft/chronicle/map/ListenersTest.java b/src/test/java/net/openhft/chronicle/map/ListenersTest.java index 9d1c03713..1e1577959 100644 --- a/src/test/java/net/openhft/chronicle/map/ListenersTest.java +++ b/src/test/java/net/openhft/chronicle/map/ListenersTest.java @@ -23,13 +23,13 @@ public class ListenersTest { return MapEntryOperations.super.remove(entry); } @Override - public Void replaceValue(@NotNull MapEntry entry, Data newValue) { + public Void replaceValue(@NotNull MapEntry entry, Data newValue) { replaceValueCount.incrementAndGet(); return MapEntryOperations.super.replaceValue(entry, newValue); } @Override - public Void insert(@NotNull MapAbsentEntry absentEntry, Data value) { + public Void insert(@NotNull MapAbsentEntry absentEntry, Data value) { insertCount.incrementAndGet(); return MapEntryOperations.super.insert(absentEntry, value); } @@ -152,7 +152,7 @@ public class ListenersTest { .mapMethods(new MapMethods() { @Override public void put(MapQueryContext q, - net.openhft.chronicle.hash.Data value, + net.openhft.chronicle.hash.Data value, ReturnValue returnValue) { if (q.queriedKey().get() == 2) { MapMethods.super.put(q, value, NullReturnValue.get()); diff --git a/src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java b/src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java index 346149e8a..64ba0e7af 100644 --- a/src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java +++ b/src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java @@ -28,7 +28,7 @@ class LoggingMapEntryOperations implements MapEntryOperations static final Logger LOG = LoggerFactory.getLogger(LoggingMapEntryOperations.class); @Override - public Void replaceValue(@NotNull MapEntry entry, Data newValue) { + public Void replaceValue(@NotNull MapEntry entry, Data newValue) { LOG.info("replace: old key: {}, old value: {}, new value: {}", entry.key(), entry.value(), newValue); entry.doReplaceValue(newValue); diff --git a/src/test/java/net/openhft/chronicle/map/MarkTest.java b/src/test/java/net/openhft/chronicle/map/MarkTest.java index b8faf5928..551ccfc3c 100644 --- a/src/test/java/net/openhft/chronicle/map/MarkTest.java +++ b/src/test/java/net/openhft/chronicle/map/MarkTest.java @@ -34,32 +34,21 @@ public class MarkTest { @Test(timeout = 25000) public void inMemoryTest() { - test(new SerializableFunction, ChronicleMap>() { - @Override - public ChronicleMap apply( - ChronicleMapBuilder builder) { - return builder.create(); - } - }); + test(builder -> builder.create()); } - @Test(timeout = 25000) + @Test public void persistedTest() { int rnd = new Random().nextInt(); final File db = Paths.get(System.getProperty("java.io.tmpdir"), "mark" + rnd).toFile(); if (db.exists()) db.delete(); try { - test(new SerializableFunction, - ChronicleMap>() { - @Override - public ChronicleMap apply( - ChronicleMapBuilder builder) { - try { - return builder.createPersistedTo(db); - } catch (IOException e) { - throw new AssertionError(e); - } + test(builder -> { + try { + return builder.createPersistedTo(db); + } catch (IOException e) { + throw new AssertionError(e); } }); System.out.println(MemoryUnit.BYTES.toMegabytes(db.length()) + " MB"); diff --git a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java index 05f4cf0dd..88413bd53 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java @@ -294,7 +294,7 @@ public class ReplicationCheckingMap implements ChronicleMap { @NotNull @Override - public ExternalMapQueryContext queryContext(net.openhft.chronicle.hash.Data key) { + public ExternalMapQueryContext queryContext(net.openhft.chronicle.hash.Data key) { throw new UnsupportedOperationException(); } diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakCrdtTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakCrdtTest.java index febf33a4b..c88f556e4 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakCrdtTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakCrdtTest.java @@ -6,10 +6,6 @@ import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; import net.openhft.chronicle.map.replication.MapRemoteOperations; import net.openhft.chronicle.map.replication.MapRemoteQueryContext; import net.openhft.chronicle.map.replication.MapReplicableEntry; -import net.openhft.lang.io.ByteBufferBytes; -import net.openhft.lang.model.Byteable; -import net.openhft.lang.model.DataValueClasses; -import net.openhft.lang.values.IntValue; import org.jetbrains.annotations.NotNull; import org.junit.After; import org.junit.Before; @@ -18,13 +14,12 @@ import org.junit.Test; import java.io.Closeable; import java.io.IOException; import java.net.InetSocketAddress; -import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.TimeUnit; -import static net.openhft.lang.MemoryUnit.MEGABYTES; import static net.openhft.chronicle.map.TcpReplicationSoakCrdtTest.GrowOnlySetValuedMapEntryOperations.growOnlySetValuedMapEntryOperations; import static net.openhft.chronicle.map.TcpReplicationSoakCrdtTest.GrowOnlySetValuedMapRemoteOperations.growOnlySetValuedMapRemoteOperations; +import static net.openhft.lang.MemoryUnit.MEGABYTES; import static org.junit.Assert.assertEquals; public class TcpReplicationSoakCrdtTest { @@ -63,7 +58,7 @@ public class TcpReplicationSoakCrdtTest { private GrowOnlySetValuedMapRemoteOperations() {} @Override - public void put(MapRemoteQueryContext, Void> q, Data, ?> newValue) { + public void put(MapRemoteQueryContext, Void> q, Data> newValue) { MapReplicableEntry> entry = q.entry(); if (entry != null) { Set merged = new HashSet<>(entry.value().get()); diff --git a/src/test/java/net/openhft/chronicle/map/example/SimpleMapOperationsListeningTest.java b/src/test/java/net/openhft/chronicle/map/example/SimpleMapOperationsListeningTest.java index 41cce5283..5c8c66f69 100644 --- a/src/test/java/net/openhft/chronicle/map/example/SimpleMapOperationsListeningTest.java +++ b/src/test/java/net/openhft/chronicle/map/example/SimpleMapOperationsListeningTest.java @@ -31,22 +31,22 @@ public class SimpleMapOperationsListeningTest { } @Override - public Void replaceValue(@NotNull MapEntry entry, Data newValue) { + public Void replaceValue(@NotNull MapEntry entry, Data newValue) { System.out.println("replace " + entry.key() + ": " + entry.value() + " -> " + newValue); entry.doReplaceValue(newValue); return null; } @Override - public Void insert(@NotNull MapAbsentEntry absentEntry, Data value) { + public Void insert(@NotNull MapAbsentEntry absentEntry, Data value) { System.out.println("insert " + absentEntry.absentKey() + " -> " + value); absentEntry.doInsert(value); return null; } @Override - public Data defaultValue(@NotNull MapAbsentEntry absentEntry) { - Data defaultValue = absentEntry.defaultValue(); + public Data defaultValue(@NotNull MapAbsentEntry absentEntry) { + Data defaultValue = absentEntry.defaultValue(); System.out.println("default " + absentEntry.absentKey() + " -> " + defaultValue); return defaultValue; } diff --git a/src/test/java/net/openhft/chronicle/map/jsr166/map/StatelessChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/jsr166/map/StatelessChronicleMapTest.java index 727e388b7..52e08b511 100755 --- a/src/test/java/net/openhft/chronicle/map/jsr166/map/StatelessChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/jsr166/map/StatelessChronicleMapTest.java @@ -123,7 +123,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { @NotNull @Override - public ExternalMapQueryContext queryContext(Data key) { + public ExternalMapQueryContext queryContext(Data key) { return d.queryContext(key); }