diff --git a/src/main/java/net/openhft/chronicle/hash/AbstractValue.java b/src/main/java/net/openhft/chronicle/hash/AbstractData.java similarity index 74% rename from src/main/java/net/openhft/chronicle/hash/AbstractValue.java rename to src/main/java/net/openhft/chronicle/hash/AbstractData.java index b95adf57e..652b4dabd 100644 --- a/src/main/java/net/openhft/chronicle/hash/AbstractValue.java +++ b/src/main/java/net/openhft/chronicle/hash/AbstractData.java @@ -21,20 +21,20 @@ package net.openhft.chronicle.hash; import net.openhft.chronicle.algo.hashing.LongHashFunction; /** - * Defines reasonable defaults for {@code Value}'s {@code equals()}, {@code hashCode()} and - * {@code toString()}. They should be default implementations in the {@code Value} interface itself, + * Defines reasonable defaults for {@code Data}'s {@code equals()}, {@code hashCode()} and + * {@code toString()}. They should be default implementations in the {@code Data} interface itself, * but Java 8 doesn't allow to override {@code Object}'s methods by default implementations * in interfaces. */ -public abstract class AbstractValue implements Value { +public abstract class AbstractData implements Data { /** * Constructor for use by subclasses. */ - protected AbstractValue() {} + protected AbstractData() {} /** - * Computes value's hash code by applying a hash function to {@code Value}'s bytes + * Computes value's hash code by applying a hash function to {@code Data}'s bytes * representation. */ @Override @@ -43,17 +43,17 @@ public abstract class AbstractValue implements Value { } /** - * Compares {@code Value}s' bytes representations. + * Compares {@code Data}s' bytes representations. */ @Override public boolean equals(Object obj) { return obj != null && - obj instanceof Value && - Value.bytesEquivalent(this, (Value) obj); + obj instanceof Data && + Data.bytesEquivalent(this, (Data) obj); } /** - * Delegates to {@code Value}'s object {@code toString()}. + * Delegates to {@code Data}'s object {@code toString()}. */ @Override public String toString() { diff --git a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java index 501800f5a..95d13b3f6 100644 --- a/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java +++ b/src/main/java/net/openhft/chronicle/hash/ChronicleHash.java @@ -19,14 +19,11 @@ package net.openhft.chronicle.hash; import net.openhft.chronicle.map.ChronicleMap; -import net.openhft.chronicle.map.ExternalMapQueryContext; -import net.openhft.chronicle.map.MapEntry; import net.openhft.chronicle.set.ChronicleSet; import org.jetbrains.annotations.NotNull; import java.io.Closeable; import java.io.File; -import java.io.Serializable; import java.util.function.Consumer; import java.util.function.Predicate; @@ -63,7 +60,7 @@ public interface ChronicleHash, EQC extends ExternalH @NotNull EQC queryContext(K key); - @NotNull EQC queryContext(Value 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/Value.java b/src/main/java/net/openhft/chronicle/hash/Data.java similarity index 94% rename from src/main/java/net/openhft/chronicle/hash/Value.java rename to src/main/java/net/openhft/chronicle/hash/Data.java index 172011bb6..5a14cac67 100644 --- a/src/main/java/net/openhft/chronicle/hash/Value.java +++ b/src/main/java/net/openhft/chronicle/hash/Data.java @@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable; * @param type of the accessed objects * @param type of the handle for bytes access */ -public interface Value { +public interface Data { /** * Returns access to the value's bytes. @@ -92,7 +92,7 @@ public interface Value { * Returns "cached" object, generally not eligible for using outside some context, or a block, * synchronized with locks, or lambda, etc. * - * If the {@code Value} is object wrapper -- this method just returns this object. + * If the {@code Data} is object wrapper -- this method just returns this object. */ V get(); @@ -102,7 +102,7 @@ public interface Value { */ V getUsing(@Nullable V usingInstance); - static boolean bytesEquivalent(Value v1, Value v2) { + static boolean bytesEquivalent(Data v1, Data v2) { if (v1.size() != v2.size()) return false; return Access.equivalent(v1.access(), v1.handle(), v1.offset(), diff --git a/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java b/src/main/java/net/openhft/chronicle/hash/HashAbsentEntry.java index d471e085a..f97cfb732 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 - Value 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 e1dd630b5..cee107e9a 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashEntry.java +++ b/src/main/java/net/openhft/chronicle/hash/HashEntry.java @@ -19,7 +19,6 @@ package net.openhft.chronicle.hash; import net.openhft.chronicle.map.MapEntry; -import net.openhft.chronicle.map.MapEntryOperations; import net.openhft.chronicle.set.SetEntry; import org.jetbrains.annotations.NotNull; @@ -41,7 +40,8 @@ public interface HashEntry { /** * Returns the entry key. */ - @NotNull Value key(); + @NotNull + 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 d0529f993..adaa346aa 100644 --- a/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java +++ b/src/main/java/net/openhft/chronicle/hash/HashQueryContext.java @@ -1,11 +1,8 @@ package net.openhft.chronicle.hash; -import net.openhft.chronicle.hash.locks.IllegalInterProcessLockStateException; import net.openhft.chronicle.hash.locks.InterProcessLock; import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; import net.openhft.chronicle.map.MapMethods; -import net.openhft.chronicle.map.MapQueryContext; -import net.openhft.chronicle.map.ReturnValue; /** * Context of {@link ChronicleHash} operations with individual keys. @@ -94,9 +91,9 @@ import net.openhft.chronicle.map.ReturnValue; public interface HashQueryContext extends HashContext, InterProcessReadWriteUpdateLock { /** - * Returns the queried key as a {@code Value}. + * Returns the queried key as a {@code Data}. */ - Value 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/CopyingInstanceValue.java b/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java similarity index 92% rename from src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceValue.java rename to src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java index 5944dc7db..0d82da723 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceValue.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/CopyingInstanceData.java @@ -19,15 +19,14 @@ package net.openhft.chronicle.hash.impl; import net.openhft.chronicle.bytes.ReadAccess; -import net.openhft.chronicle.hash.AbstractValue; -import net.openhft.chronicle.hash.Value; +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 CopyingInstanceValue extends AbstractValue { +public abstract class CopyingInstanceData extends AbstractData { public static DirectBytes getBuffer(DirectBytes b, long capacity) { if (b != null) { 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 new file mode 100644 index 000000000..75bb2dee7 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableData.java @@ -0,0 +1,8 @@ +package net.openhft.chronicle.hash.impl.value.instance; + +import net.openhft.chronicle.hash.Data; + +public interface KeyInitableData extends Data { + + void initKey(K key); +} diff --git a/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableValue.java b/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableValue.java deleted file mode 100644 index 24ac52bd4..000000000 --- a/src/main/java/net/openhft/chronicle/hash/impl/value/instance/KeyInitableValue.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.openhft.chronicle.hash.impl.value.instance; - -import net.openhft.chronicle.hash.Value; - -public interface KeyInitableValue extends Value { - - void initKey(K key); -} diff --git a/src/main/java/net/openhft/chronicle/hash/replication/DefaultEventualConsistencyStrategy.java b/src/main/java/net/openhft/chronicle/hash/replication/DefaultEventualConsistencyStrategy.java index 5614e8b76..94d3b7747 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/DefaultEventualConsistencyStrategy.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/DefaultEventualConsistencyStrategy.java @@ -50,7 +50,7 @@ public final class DefaultEventualConsistencyStrategy { * @return if the remote operation should be accepted or discarded */ public static AcceptanceDecision decideOnRemoteModification( - HashReplicableEntry entry, RemoteOperationContext context) { + ReplicableEntry entry, RemoteOperationContext context) { long remoteTimestamp = context.remoteTimestamp(); long originTimestamp = entry.originTimestamp(); boolean shouldAccept = remoteTimestamp > originTimestamp || diff --git a/src/main/java/net/openhft/chronicle/hash/replication/HashReplicableEntry.java b/src/main/java/net/openhft/chronicle/hash/replication/HashReplicableEntry.java index a7926a0bb..b23d8dc5a 100644 --- a/src/main/java/net/openhft/chronicle/hash/replication/HashReplicableEntry.java +++ b/src/main/java/net/openhft/chronicle/hash/replication/HashReplicableEntry.java @@ -20,9 +20,6 @@ package net.openhft.chronicle.hash.replication; import net.openhft.chronicle.hash.HashEntry; -public interface HashReplicableEntry extends HashEntry { - - byte originIdentifier(); - - long originTimestamp(); +public interface HashReplicableEntry extends HashEntry,ReplicableEntry { + } diff --git a/src/main/java/net/openhft/chronicle/hash/replication/ReplicableEntry.java b/src/main/java/net/openhft/chronicle/hash/replication/ReplicableEntry.java new file mode 100644 index 000000000..43eb977a2 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/hash/replication/ReplicableEntry.java @@ -0,0 +1,7 @@ +package net.openhft.chronicle.hash.replication; + +public interface ReplicableEntry { + byte originIdentifier(); + + long originTimestamp(); +} diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java index 61010ae63..df403a579 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChannelReplicator.java @@ -19,7 +19,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.core.util.CloseablesManager; -import net.openhft.chronicle.hash.replication.HashReplicableEntry; +import net.openhft.chronicle.hash.replication.ReplicableEntry; import net.openhft.chronicle.hash.replication.ThrottlingConfig; import net.openhft.lang.io.ByteBufferBytes; import net.openhft.lang.io.Bytes; @@ -478,7 +478,7 @@ abstract class AbstractChannelReplicator implements Closeable { } @Override - public boolean shouldBeIgnored(final HashReplicableEntry entry, final int chronicleId) { + public boolean shouldBeIgnored(final ReplicableEntry entry, final int chronicleId) { return !externalizable.identifierCheck(entry, chronicleId); } diff --git a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java index dd7e69f7c..d7b96166c 100644 --- a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java @@ -18,10 +18,7 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.replication.HashReplicableEntry; -import net.openhft.chronicle.hash.replication.ReplicationHub; -import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; -import net.openhft.chronicle.hash.replication.UdpTransportConfig; +import net.openhft.chronicle.hash.replication.*; import net.openhft.lang.collection.DirectBitSet; import net.openhft.lang.collection.SingleThreadedDirectBitSet; import net.openhft.lang.io.ByteBufferBytes; @@ -101,7 +98,7 @@ public final class ChannelProvider implements Closeable { } @Override - public boolean identifierCheck(@NotNull HashReplicableEntry entry, int chronicleChannel) { + public boolean identifierCheck(@NotNull ReplicableEntry entry, int chronicleChannel) { channelDataLock.readLock().lock(); try { @@ -504,7 +501,7 @@ public final class ChannelProvider implements Closeable { } @Override - public boolean identifierCheck(@NotNull HashReplicableEntry entry, int chronicleId) { + public boolean identifierCheck(@NotNull ReplicableEntry entry, int chronicleId) { return true; } diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index c29e21864..0015f8ede 100755 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -108,7 +108,7 @@ public final class ChronicleMapBuilder implements ChronicleHashBuilderImpl, ChronicleMapBuilder>, MapBuilder>, Serializable { - static final byte UDP_REPLICATION_MODIFICATION_ITERATOR_ID = (byte) 128; + static final byte UDP_REPLICATION_MODIFICATION_ITERATOR_ID = (byte) 127; private static final int DEFAULT_KEY_OR_VALUE_SIZE = 120; private static final long DEFAULT_ENTRIES = 1 << 20; private static final int MAX_SEGMENTS = (1 << 30); diff --git a/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java b/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java index a7b5bfed0..2d4ae6007 100644 --- a/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/FilePerKeyChronicleMap.java @@ -1,11 +1,8 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.function.SerializableFunction; -import net.openhft.lang.Jvm; import org.jetbrains.annotations.NotNull; -import org.xerial.snappy.SnappyInputStream; -import org.xerial.snappy.SnappyOutputStream; import java.io.File; import java.io.IOException; @@ -14,8 +11,6 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; /** * Created by daniel on 22/04/15. @@ -188,7 +183,7 @@ public class FilePerKeyChronicleMap implements ChronicleMap { @NotNull @Override - public ExternalMapQueryContext queryContext(Value key) { + public ExternalMapQueryContext queryContext(Data key) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java b/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java index a89e65260..741f4a49a 100644 --- a/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java +++ b/src/main/java/net/openhft/chronicle/map/MapAbsentEntry.java @@ -18,8 +18,8 @@ package net.openhft.chronicle.map; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashAbsentEntry; -import net.openhft.chronicle.hash.Value; import org.jetbrains.annotations.NotNull; /** @@ -42,14 +42,14 @@ public interface MapAbsentEntry extends HashAbsentEntry { * value}. * *

This method is the default implementation for {@link MapEntryOperations#insert( - * MapAbsentEntry, Value)}, which might be customized over the default. + * MapAbsentEntry, Data)}, which might be customized over the default. * * @param value the value to insert into the map along with {@link #absentKey() the key} * @throws IllegalStateException if some locking/state conditions required to perform insertion * operation are not met - * @see MapEntryOperations#insert(MapAbsentEntry, Value) + * @see MapEntryOperations#insert(MapAbsentEntry, Data) */ - void doInsert(Value value); + void doInsert(Data value); /** * Returns the default (or nil) value, that should be inserted into the map in @@ -62,5 +62,6 @@ public interface MapAbsentEntry extends HashAbsentEntry { * @return the default value to be inserted into the map * @see MapEntryOperations#defaultValue(MapAbsentEntry) */ - @NotNull Value defaultValue(); + @NotNull + 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 ccf2ca7d0..c59af1c82 100644 --- a/src/main/java/net/openhft/chronicle/map/MapContext.java +++ b/src/main/java/net/openhft/chronicle/map/MapContext.java @@ -19,7 +19,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.HashContext; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; /** * Context, in which {@link MapEntry MapEntries} are accessed. @@ -43,14 +43,14 @@ public interface MapContext extends HashContext, MapEntryOperations< ChronicleMap map(); /** - * Wraps the given value as a {@code Value}. Useful when you need to pass a value - * to some method accepting {@code Value}, for example, {@link MapEntryOperations#replaceValue( - * MapEntry, Value)}, without allocating new objects (i. e. garbage) and {@code ThreadLocals}. + * Wraps the given value as a {@code Data}. Useful when you need to pass a value + * to some method accepting {@code Data}, for example, {@link MapEntryOperations#replaceValue( + * MapEntry, Data)}, without allocating new objects (i. e. garbage) and {@code ThreadLocals}. * - *

The returned {@code Value} object shouldn't outlive this {@code MapContext}. + *

The returned {@code Data} object shouldn't outlive this {@code MapContext}. * * @param value the value object to wrap - * @return the value as {@code Value} + * @return the value as {@code Data} */ - Value 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 357c59abe..184d6b3ca 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEntry.java +++ b/src/main/java/net/openhft/chronicle/map/MapEntry.java @@ -18,8 +18,8 @@ package net.openhft.chronicle.map; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashEntry; -import net.openhft.chronicle.hash.Value; import org.jetbrains.annotations.NotNull; /** @@ -37,20 +37,21 @@ public interface MapEntry extends HashEntry { /** * Returns the entry value. */ - @NotNull Value value(); + @NotNull + Data value(); /** * Replaces the entry's value with the given {@code newValue}. * *

This method is the default implementation for {@link MapEntryOperations#replaceValue( - * MapEntry, Value)}, which might be customized over the default. + * MapEntry, Data)}, which might be customized over the default. * * @param newValue the value to be put into the map instead of the {@linkplain #value() current * value} * @throws IllegalStateException if some locking/state conditions required to perform replace * operation are not met */ - void doReplaceValue(Value 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 d59a05e26..3eeffaba6 100644 --- a/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java +++ b/src/main/java/net/openhft/chronicle/map/MapEntryOperations.java @@ -18,7 +18,7 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import org.jetbrains.annotations.NotNull; /** @@ -56,7 +56,7 @@ public interface MapEntryOperations { * @throws IllegalStateException if some locking/state conditions required to perform replace * operation are not met */ - default R replaceValue(@NotNull MapEntry entry, Value newValue) { + default R replaceValue(@NotNull MapEntry entry, Data newValue) { entry.doReplaceValue(newValue); return null; } @@ -70,7 +70,7 @@ public interface MapEntryOperations { * @throws IllegalStateException if some locking/state conditions required to perform insertion * operation are not met */ - default R insert(@NotNull MapAbsentEntry absentEntry, Value value) { + default R insert(@NotNull MapAbsentEntry absentEntry, Data value) { absentEntry.doInsert(value); return null; } @@ -82,7 +82,7 @@ public interface MapEntryOperations { * * @implNote simply delegates to {@link MapAbsentEntry#defaultValue()}. */ - default Value 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 7ebc2eae5..a6ef293d1 100644 --- a/src/main/java/net/openhft/chronicle/map/MapMethods.java +++ b/src/main/java/net/openhft/chronicle/map/MapMethods.java @@ -18,11 +18,11 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import java.util.function.BiFunction; -import static net.openhft.chronicle.hash.Value.bytesEquivalent; +import static net.openhft.chronicle.hash.Data.bytesEquivalent; import static net.openhft.chronicle.map.MapMethodsSupport.returnCurrentValueIfPresent; import static net.openhft.chronicle.map.MapMethodsSupport.tryReturnCurrentValueIfPresent; @@ -43,7 +43,7 @@ public interface MapMethods { returnCurrentValueIfPresent(q, returnValue); } - default void put(MapQueryContext q, Value 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 @@ -59,7 +59,7 @@ public interface MapMethods { } default void putIfAbsent(MapQueryContext q, - Value value, ReturnValue returnValue) { + Data value, ReturnValue returnValue) { if (tryReturnCurrentValueIfPresent(q, returnValue)) return; // Key is absent @@ -90,7 +90,7 @@ public interface MapMethods { } } - default boolean remove(MapQueryContext q, Value 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: @@ -105,7 +105,7 @@ public interface MapMethods { } default void replace(MapQueryContext q, - Value 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: @@ -118,7 +118,7 @@ public interface MapMethods { } default boolean replace(MapQueryContext q, - Value oldValue, Value 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: @@ -140,23 +140,23 @@ public interface MapMethods { V oldValue = entry != null ? entry.value().get() : null; V newValue = remappingFunction.apply(q.queriedKey().get(), oldValue); if (newValue != null) { - Value newValueValue = q.wrapValueAsValue(newValue); + Data newValueData = q.wrapValueAsValue(newValue); if (entry != null) { - q.replaceValue(entry, newValueValue); + q.replaceValue(entry, newValueData); } else { - q.insert(q.absentEntry(), newValueValue); + q.insert(q.absentEntry(), newValueData); } - returnValue.returnValue(newValueValue); + returnValue.returnValue(newValueData); } else if (entry != null) { q.remove(entry); } } - default void merge(MapQueryContext q, Value value, + default void merge(MapQueryContext q, Data value, BiFunction remappingFunction, ReturnValue returnValue) { q.updateLock().lock(); - Value newValueValue; + Data newValueData; MapEntry entry = q.entry(); if (entry != null) { V oldValue = entry.value().get(); @@ -165,12 +165,12 @@ public interface MapMethods { q.remove(entry); return; } - newValueValue = q.wrapValueAsValue(newValue); - q.replaceValue(entry, newValueValue); + newValueData = q.wrapValueAsValue(newValue); + q.replaceValue(entry, newValueData); } else { - newValueValue = value; - q.insert(q.absentEntry(), newValueValue); + newValueData = value; + q.insert(q.absentEntry(), newValueData); } - returnValue.returnValue(newValueValue); + returnValue.returnValue(newValueData); } } diff --git a/src/main/java/net/openhft/chronicle/map/Replica.java b/src/main/java/net/openhft/chronicle/map/Replica.java index a4edf51dc..8b2ae2b07 100644 --- a/src/main/java/net/openhft/chronicle/map/Replica.java +++ b/src/main/java/net/openhft/chronicle/map/Replica.java @@ -18,7 +18,7 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.replication.HashReplicableEntry; +import net.openhft.chronicle.hash.replication.ReplicableEntry; import net.openhft.lang.io.Bytes; import org.jetbrains.annotations.NotNull; @@ -144,7 +144,7 @@ public interface Replica extends Closeable { * @param chronicleId is the channel id used to identify the canonical map or queue * @return the size of the entry */ - boolean identifierCheck(@NotNull HashReplicableEntry entry, int chronicleId); + boolean identifierCheck(@NotNull ReplicableEntry entry, int chronicleId); /** @@ -213,7 +213,7 @@ public interface Replica extends Closeable { * @param chronicleId only assigned when clustering * @return {@code true} if this entry should be ignored */ - public abstract boolean shouldBeIgnored(final HashReplicableEntry entry, final int chronicleId); + public abstract boolean shouldBeIgnored(final ReplicableEntry entry, final int chronicleId); } diff --git a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java index 62e3992fa..3defb8fce 100644 --- a/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/ReplicatedChronicleMap.java @@ -20,9 +20,8 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.KeyContext; import net.openhft.chronicle.hash.replication.AbstractReplication; -import net.openhft.chronicle.hash.replication.HashReplicableEntry; +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.impl.*; import net.openhft.chronicle.map.replication.MapRemoteOperations; @@ -31,7 +30,6 @@ import net.openhft.lang.Maths; import net.openhft.lang.collection.ATSDirectBitSet; import net.openhft.lang.collection.SingleThreadedDirectBitSet; import net.openhft.lang.io.Bytes; -import net.openhft.lang.threadlocal.ThreadLocalCopies; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -293,7 +291,7 @@ public class ReplicatedChronicleMap entry, int chronicleId) { + public boolean identifierCheck(@NotNull ReplicableEntry entry, int chronicleId) { return entry.originIdentifier() == localIdentifier; } @@ -337,13 +335,11 @@ public class ReplicatedChronicleMap { + c.forEachReplicableEntry(entry -> { + LOG.debug("Bootstrap entry: id {}, key {}, value {}", localIdentifier, + c.key(), c.value()); MapReplicableEntry re = (MapReplicableEntry) entry; assert re.originTimestamp() > 0L; if (re.originIdentifier() >= fromTimeStamp && @@ -612,7 +611,6 @@ public class ReplicatedChronicleMap { - void returnValue(@NotNull Value 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 43b946c90..b6c15201b 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -20,7 +20,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.bytes.IORuntimeException; import net.openhft.chronicle.core.util.CloseablesManager; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.function.SerializableFunction; import net.openhft.chronicle.hash.impl.util.BuildVersion; import net.openhft.chronicle.hash.serialization.BytesReader; @@ -555,7 +555,7 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon @NotNull @Override - public ExternalMapQueryContext queryContext(Value 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/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 9f124b7bd..44944e328 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -697,8 +697,11 @@ public final class TcpReplicator extends AbstractChannelReplicator impleme // now we're finished we can get on with reading the entries attached.remoteModificationIterator.dirtyEntries(attached.remoteBootstrapTimestamp); - reader.entriesFromBuffer(attached, key); - attached.handShakingComplete = true; + try { + reader.entriesFromBuffer(attached, key); + } finally { + attached.handShakingComplete = true; + } } } diff --git a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java index cea0dcfc1..cc68b1d97 100755 --- a/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/VanillaChronicleMap.java @@ -19,7 +19,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.KeyContext; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.impl.VanillaChronicleHash; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.SizeMarshaller; @@ -367,7 +367,7 @@ public class VanillaChronicleMap queryContext(Value 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 904f3c655..3ced7034c 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledMapIterationContext.java @@ -4,9 +4,9 @@ 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.AbstractValue; +import net.openhft.chronicle.hash.AbstractData; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashEntry; -import net.openhft.chronicle.hash.Value; import net.openhft.chronicle.hash.impl.*; import net.openhft.chronicle.hash.impl.hashlookup.EntryConsumer; import net.openhft.chronicle.hash.locks.InterProcessLock; @@ -33,18 +33,18 @@ import java.util.function.Predicate; public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , MapContext , MapEntry , IterationContextInterface , VanillaChronicleMapHolder { public void close() { - CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); CompiledMapIterationContext.this.closeTheSegmentIndex(); - CompiledMapIterationContext.this.closeHashLookupPos(); CompiledMapIterationContext.this.closeAllocatedChunks(); - CompiledMapIterationContext.this.closeUsed(); - CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration(); + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeNext(); CompiledMapIterationContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapIterationContext.this.closeEntryRemovedOnThisIteration(); + CompiledMapIterationContext.this.closeUsed(); + CompiledMapIterationContext.this.closeHashLookupPos(); CompiledMapIterationContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); - CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); - CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + CompiledMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledMapIterationContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); + CompiledMapIterationContext.this.closeMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); } public void incrementModCountGuarded() { @@ -66,7 +66,7 @@ public class CompiledMapIterationContext value) { + public void writeValueGuarded(Data value) { if (!(this.valueInit())) this.initValue(); @@ -83,23 +83,23 @@ public class CompiledMapIterationContext)(entryBytesAccessor.access(entryBytes))); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.owner = Thread.currentThread(); 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.entryKey = new EntryKeyBytesValue(); - this.innerWriteLock = new WriteLock(); - this.owner = Thread.currentThread(); - this.innerReadLock = new ReadLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); - this.innerUpdateLock = new UpdateLock(); - this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.entryValue = new EntryValueBytesValue(); } public CompiledMapIterationContext(CompiledMapIterationContext c) { @@ -107,32 +107,132 @@ public class CompiledMapIterationContext)(c.m)); + this.innerWriteLock = new WriteLock(); + this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); + this.entryValue = new EntryValueBytesData(); + this.innerReadLock = new ReadLock(); + this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.entryKey = new EntryKeyBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.owner = Thread.currentThread(); 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.entryKey = new EntryKeyBytesValue(); - this.innerWriteLock = new WriteLock(); - this.owner = Thread.currentThread(); - this.innerReadLock = new ReadLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); - this.innerUpdateLock = new UpdateLock(); - this.entryBytes = CompiledMapIterationContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.entryValue = new EntryValueBytesValue(); } - public class EntryKeyBytesValue extends AbstractValue { + public class DeprecatedMapKeyContextOnIteration implements MapKeyContext { @Override - public ReadAccess access() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccess; + public void close() { + throw new UnsupportedOperationException("close() is not supported during iteration"); } + @Override + public boolean valueEqualTo(V value) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledMapIterationContext.this.entryValue, CompiledMapIterationContext.this.context().wrapValueAsValue(value)); + } + + @NotNull + @Override + public K key() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.key().get(); + } + + @Override + public V getUsing(V usingValue) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.value().getUsing(usingValue); + } + + @Override + public boolean remove() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + CompiledMapIterationContext.this.remove(CompiledMapIterationContext.this); + return true; + } + + @Override + public boolean containsKey() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return true; + } + + @Override + public boolean put(V newValue) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + CompiledMapIterationContext.this.replaceValue(CompiledMapIterationContext.this, CompiledMapIterationContext.this.context().wrapValueAsValue(newValue)); + return true; + } + + @Override + public V get() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.value().get(); + } + + @NotNull + @Override + public Bytes entry() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryBytes; + } + + @NotNull + private UnsupportedOperationException unsupportedLocks() { + return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + throw unsupportedLocks(); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + throw unsupportedLocks(); + } + + @NotNull + @Override + public InterProcessLock readLock() { + throw unsupportedLocks(); + } + + @Override + public long keyOffset() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.keyOffset(); + } + + @Override + public long keySize() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.keySize(); + } + + @Override + public long valueOffset() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.valueOffset(); + } + + @Override + public long valueSize() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.valueSize(); + } + } + + public class EntryKeyBytesData extends AbstractData { @Override public T handle() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); @@ -140,9 +240,9 @@ public class CompiledMapIterationContext access() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytesAccessOffset(CompiledMapIterationContext.this.keyOffset()); + return CompiledMapIterationContext.this.entryBytesAccess; } @Override @@ -151,8 +251,8 @@ public class CompiledMapIterationContext { + public class EntryValueBytesData extends AbstractData { @Override public ReadAccess access() { CompiledMapIterationContext.this.checkOnEachPublicOperation(); @@ -502,8 +335,8 @@ public class CompiledMapIterationContext { - public WrappedValueInstanceValue getUnusedWrappedValueGuarded() { + public class ReadLock implements InterProcessLock { + @Override + public boolean isHeldByCurrentThread() { + return CompiledMapIterationContext.this.localLockState().read; + } + + @Override + public boolean tryLock() { + if ((CompiledMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledMapIterationContext.this.segmentHeader().tryReadLock(CompiledMapIterationContext.this.segmentHeaderAddress())) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { + return true; + } + } + + @Override + public void unlock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + return ; + case READ_LOCKED : + CompiledMapIterationContext.this.segmentHeader().readUnlock(CompiledMapIterationContext.this.segmentHeaderAddress()); + break; + case UPDATE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().updateUnlock(CompiledMapIterationContext.this.segmentHeaderAddress()); + break; + case WRITE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().writeUnlock(CompiledMapIterationContext.this.segmentHeaderAddress()); + } + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UNLOCKED); + CompiledMapIterationContext.this.closeHashLookupPos(); + CompiledMapIterationContext.this.closeEntry(); + } + + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + if ((CompiledMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledMapIterationContext.this.segmentHeader().tryReadLock(CompiledMapIterationContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { + return true; + } + } + + @Override + public void lock() { + if ((CompiledMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledMapIterationContext.this.segmentHeader().readLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + } + + @Override + public void lockInterruptibly() throws InterruptedException { + if ((CompiledMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledMapIterationContext.this.segmentHeader().readLockInterruptibly(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + } + } + + public class UpdateLock implements InterProcessLock { + @NotNull + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to update lock"); + } + + @Override + public void lock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + CompiledMapIterationContext.this.segmentHeader().updateLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + } + } + + @Override + public boolean isHeldByCurrentThread() { + return CompiledMapIterationContext.this.localLockState().update; + } + + @Override + public void lockInterruptibly() throws InterruptedException { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + CompiledMapIterationContext.this.segmentHeader().updateLockInterruptibly(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + } + } + + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapIterationContext.this.segmentHeader().tryUpdateLock(CompiledMapIterationContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public boolean tryLock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapIterationContext.this.segmentHeader().tryUpdateLock(CompiledMapIterationContext.this.segmentHeaderAddress())) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public void unlock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + return ; + case UPDATE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().downgradeUpdateToReadLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + break; + case WRITE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().downgradeWriteToReadLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + } + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + } + + public class WrappedValueInstanceData extends CopyingInstanceData { + public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); } - public WrappedValueInstanceValue getUnusedWrappedValue() { + public WrappedValueInstanceData getUnusedWrappedValue() { if (!(valueInit())) return this; if ((next) == null) - next = new WrappedValueInstanceValue(); + next = new WrappedValueInstanceData(); return next.getUnusedWrappedValue(); } @@ -600,12 +598,7 @@ public class CompiledMapIterationContext { + public class WriteLock implements InterProcessLock { @NotNull - private UnsupportedOperationException unsupportedLocks() { - return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - throw unsupportedLocks(); - } - - @NotNull - @Override - public InterProcessLock readLock() { - throw unsupportedLocks(); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - throw unsupportedLocks(); - } - - @NotNull - @Override - public Bytes entry() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryBytes; + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to write lock"); } @Override - public boolean containsKey() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return true; - } - - @NotNull - @Override - public K key() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.key().get(); + public boolean isHeldByCurrentThread() { + return CompiledMapIterationContext.this.localLockState().write; } @Override - public V getUsing(V usingValue) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.value().getUsing(usingValue); + public void lock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + CompiledMapIterationContext.this.segmentHeader().writeLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().upgradeUpdateToWriteLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : + } } @Override - public boolean remove() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - CompiledMapIterationContext.this.remove(CompiledMapIterationContext.this); - return true; + public void unlock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + case UPDATE_LOCKED : + return ; + case WRITE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().downgradeWriteToUpdateLock(CompiledMapIterationContext.this.segmentHeaderAddress()); + } + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); } @Override - public V get() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.value().get(); + public boolean tryLock() { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapIterationContext.this.segmentHeader().tryWriteLock(CompiledMapIterationContext.this.segmentHeaderAddress())) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + if (CompiledMapIterationContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledMapIterationContext.this.segmentHeaderAddress())) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); } @Override - public void close() { - throw new UnsupportedOperationException("close() is not supported during iteration"); + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapIterationContext.this.segmentHeader().tryWriteLock(CompiledMapIterationContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + if (CompiledMapIterationContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledMapIterationContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); } @Override - public boolean put(V newValue) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - CompiledMapIterationContext.this.replaceValue(CompiledMapIterationContext.this, CompiledMapIterationContext.this.context().wrapValueAsValue(newValue)); - return true; - } - - @Override - public boolean valueEqualTo(V value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledMapIterationContext.this.entryValue, CompiledMapIterationContext.this.context().wrapValueAsValue(value)); - } - - @Override - public long keyOffset() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.keyOffset(); - } - - @Override - public long keySize() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.keySize(); - } - - @Override - public long valueOffset() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.valueOffset(); - } - - @Override - public long valueSize() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.valueSize(); + public void lockInterruptibly() throws InterruptedException { + switch (CompiledMapIterationContext.this.localLockState()) { + case UNLOCKED : + CompiledMapIterationContext.this.segmentHeader().writeLockInterruptibly(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledMapIterationContext.this.segmentHeader().upgradeUpdateToWriteLockInterruptibly(CompiledMapIterationContext.this.segmentHeaderAddress()); + CompiledMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : + } } } @@ -781,7 +781,7 @@ public class CompiledMapIterationContext value) { + public void writeValue(Data value) { value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); } @@ -864,7 +864,7 @@ public class CompiledMapIterationContext value) { + private void innerInitValue(Data value) { entryBytes.position(valueSizeOffset); valueSize = value.size(); CompiledMapIterationContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); @@ -982,21 +982,21 @@ public class CompiledMapIterationContext defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerUpdateLock; - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerWriteLock; - } - - @NotNull - @Override - public Value key() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryKey; - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Value 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); - } - - @Override - public Value wrapValueAsValue(V value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledMapIterationContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @NotNull - @Override - public Value value() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.entryValue; - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledMapIterationContext.this.innerReadLock; - } - - public boolean entryIsPresent() { - return true; - } - - @Override - public VanillaChronicleMap m() { - return m; - } - - @Override - public ChronicleMap map() { - return m(); - } - - @NotNull - @Override - public MapContext context() { - return CompiledMapIterationContext.this; - } - - public T contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public void incrementSegmentEntriesIfNeeded() { + public void closeMapEntryStagesEntryBytesAccessOffsetDependants() { + CompiledMapIterationContext.this.closeEntry(); + CompiledMapIterationContext.this.closeValue(); } private CompiledMapIterationContext _Chaining_createChaining() { @@ -1246,64 +1092,162 @@ public class CompiledMapIterationContext context() { + return CompiledMapIterationContext.this; + } + + @Override + public VanillaChronicleMap m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + + public MVI valueMetaInterop(V value) { + return CompiledMapIterationContext.this.m().metaValueInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledMapIterationContext.this.wrappedValueInstanceValue.closeBuffer(); + } + + public void checkAccessingFromOwnerThread() { + if ((owner) != (Thread.currentThread())) { + throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + } + } + + public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { + CompiledMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); + } + + private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { + CompiledMapIterationContext.this.checkAccessingFromOwnerThread(); + } + + public void checkOnEachPublicOperation() { + _CheckOnEachPublicOperation_checkOnEachPublicOperation(); + CompiledMapIterationContext.this.checkEntryNotRemovedOnThisIteration(); + } + + public void closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants() { + CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @NotNull + @Override + public Data key() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryKey; + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.remove(entry); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerUpdateLock; + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + } + + @Override + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerReadLock; + } + + @Override + public Data wrapValueAsValue(V value) { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = CompiledMapIterationContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.innerWriteLock; + } + + @NotNull + @Override + public Data value() { + CompiledMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledMapIterationContext.this.entryValue; + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + long sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (((CompiledMapIterationContext.this.m().metaDataBytes) + (CompiledMapIterationContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); + } + public MKI keyMetaInterop(K key) { return CompiledMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledMapIterationContext.this.copies, CompiledMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); } - public boolean entryRemovedOnThisIteration = false; - - boolean entryRemovedOnThisIterationInit() { - return (this.entryRemovedOnThisIteration) != false; + 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; + } } - private void initEntryRemovedOnThisIteration(boolean entryRemovedOnThisIteration) { - this.entryRemovedOnThisIteration = entryRemovedOnThisIteration; + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); } - public void closeEntryRemovedOnThisIteration() { - if (!(this.entryRemovedOnThisIterationInit())) - return ; - - this.entryRemovedOnThisIteration = false; - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; - } - - public int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; - } - - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; - } - - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) - return ; - - this.allocatedChunks = 0; + public boolean entryIsPresent() { + return true; } public long hashLookupPos = -1; @@ -1328,6 +1272,62 @@ 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.closeEntry(); - } - - public long pos = -1; - - public long keySizeOffset; - - public long keySize; - - public long keyOffset; - - public boolean entryInit() { - return (this.pos) >= 0; - } - - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; - } - - public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keySizeOffset; - } - - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) - return ; - - this.closeEntryDependants(); - this.pos = -1; - } - - public void closeEntryDependants() { - CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesKeyEndDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesEntrySizeDependants(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeMapEntryStagesKeyEndDependants() { - CompiledMapIterationContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); - CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); - } - - long countValueSizeOffset() { - return keyEnd(); - } - - public void closeMapEntryStagesCountValueSizeOffsetDependants() { - CompiledMapIterationContext.this.closeValue(); - } - - public long valueSizeOffset; - - public long valueSize; - - public long valueOffset = -1; - - boolean valueInit() { - return (this.valueOffset) >= 0; - } - - void initValue() { - valueSizeOffset = countValueSizeOffset(); - entryBytes.position(valueSizeOffset); - valueSize = CompiledMapIterationContext.this.m().readValueSize(entryBytes); - CompiledMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - this.closeValueDependants(); - } - - public void initValue(Value value) { - valueSizeOffset = countValueSizeOffset(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueAgain(Value value) { - assert valueInit(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueWithoutSize(Value value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSizeOffset = countValueSizeOffset(); - assert oldValueSize == (value.size()); - valueSize = oldValueSize; - valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); - writeValue(value); - this.closeValueDependants(); - } - - public long valueOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSize; - } - - public long valueSizeOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSizeOffset; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - this.valueOffset = -1; - } - - public void closeValueDependants() { - CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); - CompiledMapIterationContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); - CompiledMapIterationContext.this.entryValue.closeEntryValueBytesValueInnerGetUsingDependants(); - } - - 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 long newSizeOfEverythingBeforeValue(Value newValue) { - return ((valueSizeOffset()) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + CompiledMapIterationContext.this.closeSegment(); } int hashLookupEntrySize; @@ -1717,28 +1450,28 @@ public class CompiledMapIterationContext>> (keyBits())) & (valueMask()); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + long indexToPos(long index) { return index * (hashLookupEntrySize()); } - public long key(long entry) { - return entry & (keyMask()); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); } void clearEntry(long pos, long prevEntry) { @@ -1746,17 +1479,12 @@ public class CompiledMapIterationContext= 0 ? pos : capacityMask2(); + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); } - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); + 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 clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; } public long remove(long posToRemove) { @@ -1794,8 +1542,13 @@ public class CompiledMapIterationContext>> (keyBits())) & (valueMask()); - } - - void forEach(EntryConsumer action) { - for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { - long entry = readEntry(pos); - if (!(empty(entry))) - action.accept(key(entry), value(entry)); - - } - } - - String hashLookupToString() { - final StringBuilder sb = new StringBuilder("{"); - forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); - } - long segmentHeaderAddress; SegmentHeader segmentHeader = null; @@ -1870,22 +1603,31 @@ public class CompiledMapIterationContext> action) { CompiledMapIterationContext.this.innerUpdateLock.lock(); - long size = CompiledMapIterationContext.this.size(); - if (size == 0) - return true; - 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)))) { @@ -2037,50 +1762,50 @@ public class CompiledMapIterationContext 0; } - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - + void initSegment() { + VanillaChronicleHash h = CompiledMapIterationContext.this.h(); + long hashLookupOffset = h.segmentOffset(segmentIndex()); + long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); + freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); + freeList.reuse(freeListBytes); + entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); + this.closeSegmentDependants(); } - public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledMapIterationContext.this.free(pos(), entrySizeInChunks()); - CompiledMapIterationContext.this.entries(((CompiledMapIterationContext.this.entries()) - 1L)); - CompiledMapIterationContext.this.incrementModCountGuarded(); + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.entrySpaceOffset; } - @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 SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.freeList; } - 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()); - } + void closeSegment() { + if (!(this.segmentInit())) + return ; + + this.closeSegmentDependants(); + entrySpaceOffset = 0; } - public void writeValueAndPutPos(Value value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); + public void closeSegmentDependants() { + CompiledMapIterationContext.this.closeEntry(); } public long alloc(int chunks) { @@ -2119,7 +1844,261 @@ public class CompiledMapIterationContext newValue) { + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public void clearSegment() { + CompiledMapIterationContext.this.innerWriteLock.lock(); + CompiledMapIterationContext.this.clearHashLookup(); + freeList().clear(); + nextPosToSearchFrom(0L); + entries(0L); + } + + public void clear() { + clearSegment(); + } + + public long pos = -1; + + public long keySizeOffset; + + public long keySize; + + public long keyOffset; + + public boolean entryInit() { + return (this.pos) >= 0; + } + + public void initEntry(long pos) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = CompiledMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes); + keyOffset = entryBytes.position(); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntry(long pos, Data key) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = key.size(); + CompiledMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); + keyOffset = entryBytes.position(); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntryCopying(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset; + initKeySizeOffset(newPos); + long oldKeyOffset = keyOffset; + keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); + pos = newPos; + this.closeEntryDependants(); + } + + public long keyOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keyOffset; + } + + public long keySize() { + assert this.entryInit() : "Entry should be init"; + return this.keySize; + } + + public long keySizeOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keySizeOffset; + } + + public long pos() { + assert this.entryInit() : "Entry should be init"; + return this.pos; + } + + public void closeEntry() { + if (!(this.entryInit())) + return ; + + this.closeEntryDependants(); + this.pos = -1; + } + + public void closeEntryDependants() { + CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + CompiledMapIterationContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + CompiledMapIterationContext.this.closeMapEntryStagesKeyEndDependants(); + CompiledMapIterationContext.this.closeMapEntryStagesEntrySizeDependants(); + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeMapEntryStagesKeyEndDependants() { + CompiledMapIterationContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); + CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); + } + + long countValueSizeOffset() { + return keyEnd(); + } + + public void closeMapEntryStagesCountValueSizeOffsetDependants() { + CompiledMapIterationContext.this.closeValue(); + } + + public long valueSizeOffset; + + public long valueSize; + + public long valueOffset = -1; + + boolean valueInit() { + return (this.valueOffset) >= 0; + } + + void initValue() { + valueSizeOffset = countValueSizeOffset(); + entryBytes.position(valueSizeOffset); + valueSize = CompiledMapIterationContext.this.m().readValueSize(entryBytes); + CompiledMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); + valueOffset = entryBytes.position(); + this.closeValueDependants(); + } + + public void initValue(Data value) { + valueSizeOffset = countValueSizeOffset(); + innerInitValue(value); + this.closeValueDependants(); + } + + public void initValueAgain(Data value) { + assert valueInit(); + innerInitValue(value); + this.closeValueDependants(); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSizeOffset = countValueSizeOffset(); + assert oldValueSize == (value.size()); + valueSize = oldValueSize; + valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); + writeValue(value); + this.closeValueDependants(); + } + + public long valueOffset() { + if (!(this.valueInit())) + this.initValue(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valueInit())) + this.initValue(); + + return this.valueSize; + } + + public long valueSizeOffset() { + if (!(this.valueInit())) + this.initValue(); + + return this.valueSizeOffset; + } + + public void closeValue() { + if (!(this.valueInit())) + return ; + + this.closeValueDependants(); + this.valueOffset = -1; + } + + public void closeValueDependants() { + CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledMapIterationContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + CompiledMapIterationContext.this.closeMapEntryStagesEntryEndDependants(); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + 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 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()); + } + } + + public void writeValueAndPutPos(Data value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledMapIterationContext.this.putValueVolatile(CompiledMapIterationContext.this.hashLookupPos(), pos()); + } + + public void putValueDeletedEntry(Data newValue) { assert CompiledMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; long entryStartOffset = keySizeOffset(); @@ -2164,14 +2143,14 @@ public class CompiledMapIterationContext newValue, long newSizeOfEverythingBeforeValue) { + 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(Value newValue) { + public void innerDefaultReplaceValue(Data newValue) { assert CompiledMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); if (newValueSizeIsDifferent) { @@ -2206,7 +2185,7 @@ public class CompiledMapIterationContext newValue) { + public void doReplaceValue(Data newValue) { CompiledMapIterationContext.this.checkOnEachPublicOperation(); try { CompiledMapIterationContext.this.innerDefaultReplaceValue(newValue); @@ -2214,4 +2193,25 @@ public class CompiledMapIterationContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , VanillaChronicleMapHolder { +public class CompiledMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , VanillaChronicleMapHolder , MapAbsentEntryHolder { public void close() { - CompiledMapQueryContext.this.closeInputKey(); - CompiledMapQueryContext.this.wrappedValueInstanceValue.closeValue(); - CompiledMapQueryContext.this.closeUsed(); - CompiledMapQueryContext.this.closeInputBytes(); - CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); - CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); CompiledMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); + CompiledMapQueryContext.this.wrappedValueInstanceValue.closeValue(); + CompiledMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledMapQueryContext.this.closeInputBytes(); + CompiledMapQueryContext.this.closeUsed(); + CompiledMapQueryContext.this.closeInputKey(); CompiledMapQueryContext.this.closeAllocatedChunks(); CompiledMapQueryContext.this.wrappedValueInstanceValue.closeNext(); - CompiledMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); - CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); CompiledMapQueryContext.this.closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntryBytesAccessOffsetDependants(); + CompiledMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); CompiledMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); } @@ -101,7 +102,7 @@ public class CompiledMapQueryContext value) { + public void writeValueGuarded(Data value) { if (!(this.valueInit())) this.initValue(); @@ -122,31 +123,31 @@ public class CompiledMapQueryContext)(entryBytesAccessor.access(entryBytes))); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.entryValue = new EntryValueBytesValue(); - this.owner = Thread.currentThread(); - this.defaultReturnValue = new DefaultReturnValue(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.innerReadLock = new ReadLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledMapQueryContext.this.m().valueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledMapQueryContext.this.m().valueReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledMapQueryContext.this.h().keyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledMapQueryContext.this.h().keyReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyReader); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.innerWriteLock = new WriteLock(); - this.entryKey = new EntryKeyBytesValue(); - this.usingReturnValue = new UsingReturnValue(); - this.innerUpdateLock = new UpdateLock(); + this.inputKeyBytesValue = new InputKeyBytesData(); + this.defaultReturnValue = new DefaultReturnValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); } public CompiledMapQueryContext(CompiledMapQueryContext c) { @@ -154,107 +155,264 @@ public class CompiledMapQueryContext)(c.m)); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.entryKey = new EntryKeyBytesData(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.entryValue = new EntryValueBytesData(); + this.innerUpdateLock = new UpdateLock(); + this.usingReturnValue = new UsingReturnValue(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); + this.innerWriteLock = new WriteLock(); + this.inputValueInstanceValue = new InputValueInstanceData(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.owner = Thread.currentThread(); this.entryBytes = CompiledMapQueryContext.this.h().ms.bytes(); this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.entryValue = new EntryValueBytesValue(); - this.owner = Thread.currentThread(); - this.defaultReturnValue = new DefaultReturnValue(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.innerReadLock = new ReadLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledMapQueryContext.this.m().valueInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledMapQueryContext.this.m().valueReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledMapQueryContext.this.h().keyInteropProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledMapQueryContext.this.h().keyReaderProvider.get(CompiledMapQueryContext.this.copies, CompiledMapQueryContext.this.h().originalKeyReader); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.innerWriteLock = new WriteLock(); - this.entryKey = new EntryKeyBytesValue(); - this.usingReturnValue = new UsingReturnValue(); - this.innerUpdateLock = new UpdateLock(); + this.inputKeyBytesValue = new InputKeyBytesData(); + this.defaultReturnValue = new DefaultReturnValue(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); } - public class InputKeyBytesValue extends AbstractValue { + public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { + @NotNull @Override - public long size() { - return CompiledMapQueryContext.this.inputKeySize(); + public InterProcessLock writeLock() { + return CompiledMapQueryContext.this.writeLock(); } - public void closeInputKeyBytesValueSizeDependants() { - InputKeyBytesValue.this.closeInputKeyBytesValueGetUsingDependants(); + @NotNull + @Override + public InterProcessLock updateLock() { + return CompiledMapQueryContext.this.updateLock(); + } + + @NotNull + @Override + public InterProcessLock readLock() { + return CompiledMapQueryContext.this.readLock(); } @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); + public long valueSize() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.valueSize(); } @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); + public long keySize() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keySize(); } @Override - public K getUsing(K usingKey) { - Bytes inputBytes = CompiledMapQueryContext.this.inputBytes(); - inputBytes.position(CompiledMapQueryContext.this.inputKeyOffset()); - return CompiledMapQueryContext.this.keyReader.read(inputBytes, size(), usingKey); - } - - public void closeInputKeyBytesValueGetUsingDependants() { - InputKeyBytesValue.this.closeCachedBytesInputKey(); - } - - private K cachedBytesInputKey; - - private boolean cachedBytesInputKeyRead = false; - - public boolean cachedBytesInputKeyInit() { - return (this.cachedBytesInputKeyRead) != false; - } - - private void initCachedBytesInputKey() { - cachedBytesInputKey = getUsing(cachedBytesInputKey); - cachedBytesInputKeyRead = true; - } - - public K cachedBytesInputKey() { - if (!(this.cachedBytesInputKeyInit())) - this.initCachedBytesInputKey(); - - return this.cachedBytesInputKey; - } - - public void closeCachedBytesInputKey() { - if (!(this.cachedBytesInputKeyInit())) - return ; - - this.cachedBytesInputKeyRead = false; + public long keyOffset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keyOffset(); } @Override - public K get() { - return cachedBytesInputKey(); + public boolean containsKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return (CompiledMapQueryContext.this.entry()) != null; } + @Override + public V getUsing(V usingValue) { + return containsKey() ? CompiledMapQueryContext.this.value().getUsing(usingValue) : null; + } + + @Override + public boolean put(V newValue) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + updateLock().lock(); + MapEntry entry = CompiledMapQueryContext.this.entry(); + if (entry != null) { + CompiledMapQueryContext.this.replaceValue(entry, CompiledMapQueryContext.this.wrapValueAsValue(newValue)); + } else { + CompiledMapQueryContext.this.insert(CompiledMapQueryContext.this.absentEntry(), CompiledMapQueryContext.this.wrapValueAsValue(newValue)); + } + return true; + } + + @NotNull + @Override + public Bytes entry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytes; + } + + @Override + public boolean remove() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + updateLock().lock(); + MapEntry entry = CompiledMapQueryContext.this.entry(); + if (entry != null) { + CompiledMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } + } + + @Override + public long valueOffset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.valueOffset(); + } + + @Override + public boolean valueEqualTo(V value) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledMapQueryContext.this.entryValue, CompiledMapQueryContext.this.wrapValueAsValue(value)); + } + + @NotNull + @Override + public K key() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.queriedKey().get(); + } + + @Override + public void close() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + put(CompiledMapQueryContext.this.usingReturnValue.returnValue()); + CompiledMapQueryContext.this.close(); + } + + @Override + public V get() { + assert containsKey(); + return CompiledMapQueryContext.this.usingReturnValue.returnValue(); + } + } + + public class DeprecatedMapKeyContextOnQuery implements MapKeyContext { + @NotNull + @Override + public InterProcessLock writeLock() { + return CompiledMapQueryContext.this.writeLock(); + } + + @NotNull + @Override + public InterProcessLock readLock() { + return CompiledMapQueryContext.this.readLock(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + return CompiledMapQueryContext.this.updateLock(); + } + + @Override + public boolean valueEqualTo(V value) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledMapQueryContext.this.entryValue, CompiledMapQueryContext.this.wrapValueAsValue(value)); + } + + @Override + public long valueOffset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.valueOffset(); + } + + @NotNull + @Override + public Bytes entry() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytes; + } + + @Override + public boolean containsKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return (CompiledMapQueryContext.this.entry()) != null; + } + + @Override + public V get() { + return containsKey() ? CompiledMapQueryContext.this.value().get() : null; + } + + @Override + public V getUsing(V usingValue) { + return containsKey() ? CompiledMapQueryContext.this.value().getUsing(usingValue) : null; + } + + @Override + public long valueSize() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.valueSize(); + } + + @Override + public boolean put(V newValue) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + updateLock().lock(); + MapEntry entry = CompiledMapQueryContext.this.entry(); + if (entry != null) { + CompiledMapQueryContext.this.replaceValue(entry, CompiledMapQueryContext.this.wrapValueAsValue(newValue)); + } else { + CompiledMapQueryContext.this.insert(CompiledMapQueryContext.this.absentEntry(), CompiledMapQueryContext.this.wrapValueAsValue(newValue)); + } + return true; + } + + @Override + public void close() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + CompiledMapQueryContext.this.close(); + } + + @Override + public long keySize() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keySize(); + } + + @Override + public long keyOffset() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.keyOffset(); + } + + @Override + public boolean remove() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + updateLock().lock(); + MapEntry entry = CompiledMapQueryContext.this.entry(); + if (entry != null) { + CompiledMapQueryContext.this.remove(entry); + return true; + } else { + return false; + } + } + + @NotNull + @Override + public K key() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.queriedKey().get(); + } + } + + public class EntryKeyBytesData extends AbstractData { @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.inputKeyOffset()); - } - } - - public class EntryKeyBytesValue extends AbstractValue { - @Override - public T handle() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessHandle; + return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()); } @Override @@ -269,8 +427,8 @@ public class CompiledMapQueryContext { @Override public long offset() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()); - } - } - - public class WriteLock implements InterProcessLock { - @NotNull - private IllegalMonitorStateException forbiddenUpgrade() { - return new IllegalMonitorStateException("Cannot upgrade from read to write lock"); + return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.valueOffset()); } @Override - public void lockInterruptibly() throws InterruptedException { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - CompiledMapQueryContext.this.segmentHeader().writeLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return ; - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().upgradeUpdateToWriteLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - case WRITE_LOCKED : - } + public ReadAccess access() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytesAccess; } @Override - public void lock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - CompiledMapQueryContext.this.segmentHeader().writeLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return ; - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().upgradeUpdateToWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - case WRITE_LOCKED : - } + public T handle() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.entryBytesAccessHandle; } - @Override - public boolean isHeldByCurrentThread() { - return CompiledMapQueryContext.this.localLockState().write; - } - - @Override - public boolean tryLock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - if (CompiledMapQueryContext.this.segmentHeader().tryWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - if (CompiledMapQueryContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case WRITE_LOCKED : - return true; - } - throw new AssertionError(); - } - - @Override - public boolean tryLock(long time, @NotNull - TimeUnit unit) throws InterruptedException { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - if (CompiledMapQueryContext.this.segmentHeader().tryWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - if (CompiledMapQueryContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case WRITE_LOCKED : - return true; - } - throw new AssertionError(); - } - - @Override - public void unlock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - case READ_LOCKED : - case UPDATE_LOCKED : - return ; - case WRITE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().downgradeWriteToUpdateLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - } - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); - } - } - - public class UpdateLock implements InterProcessLock { - @NotNull - private IllegalMonitorStateException forbiddenUpgrade() { - return new IllegalMonitorStateException("Cannot upgrade from read to update lock"); - } - - @Override - public void lockInterruptibly() throws InterruptedException { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - CompiledMapQueryContext.this.segmentHeader().updateLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); - return ; - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - case WRITE_LOCKED : - } - } - - @Override - public boolean tryLock(long time, @NotNull - TimeUnit unit) throws InterruptedException { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - if (CompiledMapQueryContext.this.segmentHeader().tryUpdateLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); - return true; - } else { - return false; - } - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - case WRITE_LOCKED : - return true; - } - throw new AssertionError(); - } - - @Override - public boolean isHeldByCurrentThread() { - return CompiledMapQueryContext.this.localLockState().update; - } - - @Override - public boolean tryLock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - if (CompiledMapQueryContext.this.segmentHeader().tryUpdateLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); - return true; - } else { - return false; - } - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - case WRITE_LOCKED : - return true; - } - throw new AssertionError(); - } - - @Override - public void lock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - CompiledMapQueryContext.this.segmentHeader().updateLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); - return ; - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - case WRITE_LOCKED : - } - } - - @Override - public void unlock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - case READ_LOCKED : - return ; - case UPDATE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().downgradeUpdateToReadLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - break; - case WRITE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().downgradeWriteToReadLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - } - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); - } - } - - public class ReadLock implements InterProcessLock { - @Override - public boolean tryLock() { - if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { - if (CompiledMapQueryContext.this.segmentHeader().tryReadLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); - return true; - } else { - return false; - } - } else { - return true; - } - } - - @Override - public boolean isHeldByCurrentThread() { - return CompiledMapQueryContext.this.localLockState().read; - } - - @Override - public void lock() { - if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { - CompiledMapQueryContext.this.segmentHeader().readLock(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); - } - } - - public void closeReadLockLockDependants() { - CompiledMapQueryContext.this.closeHashLookupPos(); - } - - @Override - public void lockInterruptibly() throws InterruptedException { - if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { - CompiledMapQueryContext.this.segmentHeader().readLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); - } - } - - @Override - public void unlock() { - switch (CompiledMapQueryContext.this.localLockState()) { - case UNLOCKED : - return ; - case READ_LOCKED : - CompiledMapQueryContext.this.segmentHeader().readUnlock(CompiledMapQueryContext.this.segmentHeaderAddress()); - break; - case UPDATE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().updateUnlock(CompiledMapQueryContext.this.segmentHeaderAddress()); - break; - case WRITE_LOCKED : - CompiledMapQueryContext.this.segmentHeader().writeUnlock(CompiledMapQueryContext.this.segmentHeaderAddress()); - } - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UNLOCKED); - CompiledMapQueryContext.this.closeHashLookupPos(); - CompiledMapQueryContext.this.closeEntry(); - } - - @Override - public boolean tryLock(long time, @NotNull - TimeUnit unit) throws InterruptedException { - if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { - if (CompiledMapQueryContext.this.segmentHeader().tryReadLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { - CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); - return true; - } else { - return false; - } - } else { - return true; - } - } - } - - public class EntryValueBytesValue extends AbstractValue { @Override public long size() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); return CompiledMapQueryContext.this.valueSize(); } - public void closeEntryValueBytesValueSizeDependants() { - EntryValueBytesValue.this.closeEntryValueBytesValueInnerGetUsingDependants(); + public void closeEntryValueBytesDataSizeDependants() { + EntryValueBytesData.this.closeEntryValueBytesDataInnerGetUsingDependants(); } private V innerGetUsing(V usingValue) { @@ -621,8 +520,8 @@ public class CompiledMapQueryContext access() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccess; - } - @Override public V get() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); return cachedEntryValue(); } - - @Override - public T handle() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessHandle; - } - - @Override - public long offset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.valueOffset()); - } } - public class InputFirstValueBytesValue extends AbstractValue { - @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); - } - + public class InputFirstValueBytesData extends AbstractData { @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); @@ -704,8 +580,8 @@ public class CompiledMapQueryContext { + public class InputKeyBytesData extends AbstractData { + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).access(CompiledMapQueryContext.this.inputBytes()))); + } + + @Override + public long size() { + return CompiledMapQueryContext.this.inputKeySize(); + } + + public void closeInputKeyBytesDataSizeDependants() { + InputKeyBytesData.this.closeInputKeyBytesDataGetUsingDependants(); + } + + @Override + public K getUsing(K usingKey) { + Bytes inputBytes = CompiledMapQueryContext.this.inputBytes(); + inputBytes.position(CompiledMapQueryContext.this.inputKeyOffset()); + return CompiledMapQueryContext.this.keyReader.read(inputBytes, size(), usingKey); + } + + public void closeInputKeyBytesDataGetUsingDependants() { + InputKeyBytesData.this.closeCachedBytesInputKey(); + } + + private K cachedBytesInputKey; + + private boolean cachedBytesInputKeyRead = false; + + public boolean cachedBytesInputKeyInit() { + return (this.cachedBytesInputKeyRead) != false; + } + + private void initCachedBytesInputKey() { + cachedBytesInputKey = getUsing(cachedBytesInputKey); + cachedBytesInputKeyRead = true; + } + + public K cachedBytesInputKey() { + if (!(this.cachedBytesInputKeyInit())) + this.initCachedBytesInputKey(); + + return this.cachedBytesInputKey; + } + + public void closeCachedBytesInputKey() { + if (!(this.cachedBytesInputKeyInit())) + return ; + + this.cachedBytesInputKeyRead = false; + } + + @Override + public K get() { + return cachedBytesInputKey(); + } + @Override public T handle() { return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).handle(CompiledMapQueryContext.this.inputBytes()))); } + @Override + public long offset() { + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.inputKeyOffset()); + } + } + + public class InputSecondValueBytesData extends AbstractData { @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()))); + } + @Override public long offset() { return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledMapQueryContext.this.inputBytes()).offset(CompiledMapQueryContext.this.inputBytes(), CompiledMapQueryContext.this.secondInputValueOffset()); @@ -772,8 +722,8 @@ public class CompiledMapQueryContext { - public WrappedValueInstanceValue getUnusedWrappedValueGuarded() { + public class ReadLock implements InterProcessLock { + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledMapQueryContext.this.segmentHeader().tryReadLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { + return true; + } + } + + @Override + public void unlock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + return ; + case READ_LOCKED : + CompiledMapQueryContext.this.segmentHeader().readUnlock(CompiledMapQueryContext.this.segmentHeaderAddress()); + break; + case UPDATE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().updateUnlock(CompiledMapQueryContext.this.segmentHeaderAddress()); + break; + case WRITE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().writeUnlock(CompiledMapQueryContext.this.segmentHeaderAddress()); + } + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UNLOCKED); + CompiledMapQueryContext.this.closeHashLookupPos(); + CompiledMapQueryContext.this.closeEntry(); + } + + @Override + public void lockInterruptibly() throws InterruptedException { + if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledMapQueryContext.this.segmentHeader().readLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + } + + @Override + public void lock() { + if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledMapQueryContext.this.segmentHeader().readLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + } + + public void closeReadLockLockDependants() { + CompiledMapQueryContext.this.closeHashLookupPos(); + } + + @Override + public boolean isHeldByCurrentThread() { + return CompiledMapQueryContext.this.localLockState().read; + } + + @Override + public boolean tryLock() { + if ((CompiledMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledMapQueryContext.this.segmentHeader().tryReadLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { + return true; + } + } + } + + public class UpdateLock implements InterProcessLock { + @NotNull + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to update lock"); + } + + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapQueryContext.this.segmentHeader().tryUpdateLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public void unlock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + return ; + case UPDATE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().downgradeUpdateToReadLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + break; + case WRITE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().downgradeWriteToReadLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + } + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + + @Override + public void lock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledMapQueryContext.this.segmentHeader().updateLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + } + } + + @Override + public boolean tryLock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapQueryContext.this.segmentHeader().tryUpdateLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public boolean isHeldByCurrentThread() { + return CompiledMapQueryContext.this.localLockState().update; + } + + @Override + public void lockInterruptibly() throws InterruptedException { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledMapQueryContext.this.segmentHeader().updateLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + } + } + } + + public class WrappedValueInstanceData extends CopyingInstanceData { + public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); } - public WrappedValueInstanceValue getUnusedWrappedValue() { + public WrappedValueInstanceData getUnusedWrappedValue() { if (!(valueInit())) return this; if ((next) == null) - next = new WrappedValueInstanceValue(); + next = new WrappedValueInstanceData(); return next.getUnusedWrappedValue(); } - private WrappedValueInstanceValue next; + private WrappedValueInstanceData next; boolean nextInit() { return true; @@ -876,7 +995,12 @@ public class CompiledMapQueryContext { + public class WriteLock implements InterProcessLock { @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledMapQueryContext.this.writeLock(); - } - - @NotNull - @Override - public InterProcessLock readLock() { - return CompiledMapQueryContext.this.readLock(); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - return CompiledMapQueryContext.this.updateLock(); + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to write lock"); } @Override - public long valueOffset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.valueOffset(); + public void unlock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + case UPDATE_LOCKED : + return ; + case WRITE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().downgradeWriteToUpdateLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + } + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); } @Override - public boolean valueEqualTo(V value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledMapQueryContext.this.entryValue, CompiledMapQueryContext.this.wrapValueAsValue(value)); + public boolean isHeldByCurrentThread() { + return CompiledMapQueryContext.this.localLockState().write; } @Override - public long keyOffset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.keyOffset(); + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapQueryContext.this.segmentHeader().tryWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + if (CompiledMapQueryContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); } @Override - public void close() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - CompiledMapQueryContext.this.close(); - } - - @Override - public long keySize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.keySize(); - } - - @Override - public long valueSize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.valueSize(); - } - - @NotNull - @Override - public K key() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.queriedKey().get(); - } - - @NotNull - @Override - public Bytes entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytes; - } - - @Override - public boolean remove() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry entry = CompiledMapQueryContext.this.entry(); - if (entry != null) { - CompiledMapQueryContext.this.remove(entry); - return true; - } else { - return false; + public void lockInterruptibly() throws InterruptedException { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledMapQueryContext.this.segmentHeader().writeLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().upgradeUpdateToWriteLockInterruptibly(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : } } @Override - public boolean put(V newValue) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry 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 boolean containsKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return (CompiledMapQueryContext.this.entry()) != null; - } - - @Override - public V get() { - return containsKey() ? CompiledMapQueryContext.this.value().get() : null; - } - - @Override - public V getUsing(V usingValue) { - return containsKey() ? CompiledMapQueryContext.this.value().getUsing(usingValue) : null; - } - } - - public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledMapQueryContext.this.writeLock(); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - return CompiledMapQueryContext.this.updateLock(); - } - - @NotNull - @Override - public InterProcessLock readLock() { - return CompiledMapQueryContext.this.readLock(); - } - - @Override - public long valueSize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.valueSize(); - } - - @Override - public long keySize() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.keySize(); - } - - @NotNull - @Override - public Bytes entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryBytes; - } - - @Override - public boolean valueEqualTo(V value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledMapQueryContext.this.entryValue, CompiledMapQueryContext.this.wrapValueAsValue(value)); - } - - @NotNull - @Override - public K key() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.queriedKey().get(); - } - - @Override - public long keyOffset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.keyOffset(); - } - - @Override - public long valueOffset() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.valueOffset(); - } - - @Override - public boolean remove() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry entry = CompiledMapQueryContext.this.entry(); - if (entry != null) { - CompiledMapQueryContext.this.remove(entry); - return true; - } else { - return false; + public void lock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledMapQueryContext.this.segmentHeader().writeLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledMapQueryContext.this.segmentHeader().upgradeUpdateToWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress()); + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : } } @Override - public boolean containsKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return (CompiledMapQueryContext.this.entry()) != null; - } - - @Override - public V get() { - assert containsKey(); - return CompiledMapQueryContext.this.usingReturnValue.returnValue(); - } - - @Override - public V getUsing(V usingValue) { - return containsKey() ? CompiledMapQueryContext.this.value().getUsing(usingValue) : null; - } - - @Override - public boolean put(V newValue) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry 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)); + public boolean tryLock() { + switch (CompiledMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledMapQueryContext.this.segmentHeader().tryWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + if (CompiledMapQueryContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledMapQueryContext.this.segmentHeaderAddress())) { + CompiledMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; } - return true; - } - - @Override - public void close() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - put(CompiledMapQueryContext.this.usingReturnValue.returnValue()); - CompiledMapQueryContext.this.close(); + throw new AssertionError(); } } @@ -1172,7 +1173,7 @@ public class CompiledMapQueryContext value) { + public void writeValue(Data value) { value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); } @@ -1255,7 +1256,7 @@ public class CompiledMapQueryContext value) { + private void innerInitValue(Data value) { entryBytes.position(valueSizeOffset); valueSize = value.size(); CompiledMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); @@ -1283,7 +1284,47 @@ public class CompiledMapQueryContext implements KeyInitableValue { + public class DefaultReturnValue implements InstanceReturnValue { + @Override + public void returnValue(@NotNull + Data value) { + initDefaultReturnedValue(value); + } + + private V defaultReturnedValue = null; + + boolean defaultReturnedValueInit() { + return (this.defaultReturnedValue) != null; + } + + private void initDefaultReturnedValue(@NotNull + Data value) { + defaultReturnedValue = value.getUsing(null); + } + + public V defaultReturnedValue() { + assert this.defaultReturnedValueInit() : "DefaultReturnedValue should be init"; + return this.defaultReturnedValue; + } + + public void closeDefaultReturnedValue() { + if (!(this.defaultReturnedValueInit())) + return ; + + this.defaultReturnedValue = null; + } + + @Override + public V returnValue() { + if (defaultReturnedValueInit()) { + return defaultReturnedValue(); + } else { + return null; + } + } + } + + public class InputKeyInstanceData extends CopyingInstanceData implements KeyInitableData { private K key = null; public boolean keyInit() { @@ -1310,7 +1351,7 @@ public class CompiledMapQueryContext implements ValueInitableValue { + public class InputValueInstanceData extends CopyingInstanceData implements ValueInitableData { private V value = null; public boolean valueInit() { @@ -1383,7 +1424,7 @@ public class CompiledMapQueryContext { - @Override - public void returnValue(@NotNull - Value value) { - initDefaultReturnedValue(value); - } - - private V defaultReturnedValue = null; - - boolean defaultReturnedValueInit() { - return (this.defaultReturnedValue) != null; - } - - private void initDefaultReturnedValue(@NotNull - Value value) { - defaultReturnedValue = value.getUsing(null); - } - - public V defaultReturnedValue() { - assert this.defaultReturnedValueInit() : "DefaultReturnedValue should be init"; - return this.defaultReturnedValue; - } - - public void closeDefaultReturnedValue() { - if (!(this.defaultReturnedValueInit())) - return ; - - this.defaultReturnedValue = null; - } - - @Override - public V returnValue() { - if (defaultReturnedValueInit()) { - return defaultReturnedValue(); - } else { - return null; - } - } - } - public class UsingReturnValue implements UsableReturnValue { @Override public void returnValue(@NotNull - Value value) { + Data value) { initReturnedValue(value); } @@ -1512,7 +1513,7 @@ public class CompiledMapQueryContext value) { + Data value) { returnedValue = value.getUsing(usingReturnValue()); } @@ -1628,9 +1629,9 @@ public class CompiledMapQueryContext m() { - return m; - } - - @Override - public ChronicleMap map() { - return m(); - } - - public T contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); - } - - public void closeMapEntryStagesEntryBytesAccessOffsetDependants() { - CompiledMapQueryContext.this.closeEntry(); - CompiledMapQueryContext.this.closeValue(); - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - } - public void checkAccessingFromOwnerThread() { if ((owner) != (Thread.currentThread())) { throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); @@ -1793,16 +1776,33 @@ public class CompiledMapQueryContext m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + 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 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 final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); } private CompiledMapQueryContext _Chaining_createChaining() { @@ -1826,19 +1826,25 @@ public class CompiledMapQueryContext absent() { + return CompiledMapQueryContext.this; + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeVanillaChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); } public int allocatedChunks = 0; @@ -1863,195 +1869,18 @@ public class CompiledMapQueryContext= 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.closeInputKeyBytesValueSizeDependants(); - CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesValueGetUsingDependants(); - CompiledMapQueryContext.this.closeFirstInputValueOffsets(); - } - - public long firstInputValueSize = -1; - - public long firstInputValueOffset; - - public boolean firstInputValueOffsetsInit() { - return (this.firstInputValueSize) >= 0; - } - - private void initFirstInputValueOffsets() { - CompiledMapQueryContext.this.inputBytes().position(((CompiledMapQueryContext.this.inputKeyOffset()) + (CompiledMapQueryContext.this.inputKeySize()))); - firstInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); - firstInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); - this.closeFirstInputValueOffsetsDependants(); - } - - public long firstInputValueOffset() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueOffset; - } - - public long firstInputValueSize() { - if (!(this.firstInputValueOffsetsInit())) - this.initFirstInputValueOffsets(); - - return this.firstInputValueSize; - } - - public void closeFirstInputValueOffsets() { - if (!(this.firstInputValueOffsetsInit())) - return ; - - this.closeFirstInputValueOffsetsDependants(); - this.firstInputValueSize = -1; - } - - public void closeFirstInputValueOffsetsDependants() { - CompiledMapQueryContext.this.closeSecondInputValueOffsets(); - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesValueSizeDependants(); - CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesValueGetUsingDependants(); - } - - 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.closeInputSecondValueBytesValueSizeDependants(); - CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesValueGetUsingDependants(); - } - - boolean used; - - public boolean usedInit() { - return used; - } - - public void initUsed(boolean used) { - this.used = used; - } - - void closeUsed() { - if (!(this.usedInit())) - return ; - - used = false; - } - - public Value inputKey = null; + public Data inputKey = null; public boolean inputKeyInit() { return (this.inputKey) != null; } - public void initInputKey(Value inputKey) { + public void initInputKey(Data inputKey) { this.inputKey = inputKey; this.closeInputKeyDependants(); } - public Value inputKey() { + public Data inputKey() { assert this.inputKeyInit() : "InputKey should be init"; return this.inputKey; } @@ -2132,9 +1961,586 @@ public class CompiledMapQueryContext= 0; + } + + public void initSegmentHashLookup() { + long hashLookupOffset = CompiledMapQueryContext.this.h().segmentOffset(CompiledMapQueryContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledMapQueryContext.this.h().segmentHashLookupCapacity, CompiledMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledMapQueryContext.this.h().segmentHashLookupValueBits); + this.closeSegmentHashLookupDependants(); + } + + public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { + innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); + this.closeSegmentHashLookupDependants(); + } + + public int hashLookupEntrySize() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.hashLookupEntrySize; + } + + public int keyBits() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyBits; + } + + public long address() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.address; + } + + public long capacityMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask; + } + + public long capacityMask2() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask2; + } + + public long entryMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.entryMask; + } + + public long keyMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyMask; + } + + public long valueMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.valueMask; + } + + public void closeSegmentHashLookup() { + if (!(this.segmentHashLookupInit())) + return ; + + this.closeSegmentHashLookupDependants(); + this.address = -1; + } + + public void closeSegmentHashLookupDependants() { + CompiledMapQueryContext.this.closeHashLookupValueDependants(); + CompiledMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); + CompiledMapQueryContext.this.closeHashLookupIndexToPosDependants(); + CompiledMapQueryContext.this.closeHashLookupKeyDependants(); + CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); + CompiledMapQueryContext.this.closeHashLookupStepBackDependants(); + CompiledMapQueryContext.this.closeHashLookupEmptyDependants(); + CompiledMapQueryContext.this.closeHashLookupReadEntryDependants(); + CompiledMapQueryContext.this.closeHashLookupStepDependants(); + } + + public long value(long entry) { + return (entry >>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + CompiledMapQueryContext.this.closeSearchKey(); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); + } + + public long key(long entry) { + return entry & (keyMask()); + } + + public void closeHashLookupKeyDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); + } + + public void writeEntry(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long hlPos(long key) { + return indexToPos((key & (capacityMask()))); + } + + public void closeHashLookupHlPosDependants() { + CompiledMapQueryContext.this.closeSearchKey(); + } + + long searchKey = UNSET_KEY; + + long searchStartPos; + + public boolean searchKeyInit() { + return (this.searchKey) != (UNSET_KEY); + } + + void initSearchKey() { + searchKey = CompiledMapQueryContext.this.maskUnsetKey(CompiledMapQueryContext.this.h().hashSplitting.segmentHash(CompiledMapQueryContext.this.hashOfKey())); + searchStartPos = CompiledMapQueryContext.this.hlPos(searchKey); + this.closeSearchKeyDependants(); + } + + public long searchKey() { + if (!(this.searchKeyInit())) + this.initSearchKey(); + + return this.searchKey; + } + + public long searchStartPos() { + if (!(this.searchKeyInit())) + this.initSearchKey(); + + return this.searchStartPos; + } + + public void closeSearchKey() { + if (!(this.searchKeyInit())) + return ; + + this.closeSearchKeyDependants(); + this.searchKey = UNSET_KEY; + } + + public void closeSearchKeyDependants() { + CompiledMapQueryContext.this.closeHashLookupPos(); + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); + } + + public void closeHashLookupStepBackDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); + } + + public boolean empty(long entry) { + return (entry & (entryMask())) == (UNSET_ENTRY); + } + + public void closeHashLookupEmptyDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void closeHashLookupReadEntryDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + } + + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); + } + + void forEach(EntryConsumer action) { + for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { + long entry = readEntry(pos); + if (!(empty(entry))) + action.accept(key(entry), value(entry)); + + } + } + + String hashLookupToString() { + final StringBuilder sb = new StringBuilder("{"); + forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); + } + + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; + } + + long entrySpaceOffset = 0; + + MultiStoreBytes freeListBytes = new MultiStoreBytes(); + + public SingleThreadedDirectBitSet freeList = new SingleThreadedDirectBitSet(); + + boolean segmentInit() { + return (entrySpaceOffset) > 0; + } + + void initSegment() { + VanillaChronicleHash h = CompiledMapQueryContext.this.h(); + long hashLookupOffset = h.segmentOffset(segmentIndex()); + long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); + freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); + freeList.reuse(freeListBytes); + entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); + this.closeSegmentDependants(); + } + + public long entrySpaceOffset() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.entrySpaceOffset; + } + + public SingleThreadedDirectBitSet freeList() { + if (!(this.segmentInit())) + this.initSegment(); + + return this.freeList; + } + + void closeSegment() { + if (!(this.segmentInit())) + return ; + + this.closeSegmentDependants(); + entrySpaceOffset = 0; + } + + public void closeSegmentDependants() { + CompiledMapQueryContext.this.closeEntry(); + } + + public long pos = -1; + + public long keySizeOffset; + + public long keySize; + + public long keyOffset; + + public boolean entryInit() { + return (this.pos) >= 0; + } + + public void initEntry(long pos) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); + keyOffset = entryBytes.position(); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntry(long pos, Data key) { + initKeySizeOffset(pos); + entryBytes.position(keySizeOffset); + keySize = key.size(); + CompiledMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); + keyOffset = entryBytes.position(); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset); + this.pos = pos; + this.closeEntryDependants(); + } + + public void initEntryCopying(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset; + initKeySizeOffset(newPos); + long oldKeyOffset = keyOffset; + keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); + pos = newPos; + this.closeEntryDependants(); + } + + public long keyOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keyOffset; + } + + public long keySize() { + assert this.entryInit() : "Entry should be init"; + return this.keySize; + } + + public long keySizeOffset() { + assert this.entryInit() : "Entry should be init"; + return this.keySizeOffset; + } + + public long pos() { + assert this.entryInit() : "Entry should be init"; + return this.pos; + } + + public void closeEntry() { + if (!(this.entryInit())) + return ; + + this.closeEntryDependants(); + this.pos = -1; + } + + public void closeEntryDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); + CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); + CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); + CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeMapEntryStagesKeyEndDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); + CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); + } + + long countValueSizeOffset() { + return keyEnd(); + } + + public void closeMapEntryStagesCountValueSizeOffsetDependants() { + CompiledMapQueryContext.this.closeValue(); + } + + public long valueSizeOffset; + + public long valueSize; + + public long valueOffset = -1; + + boolean valueInit() { + return (this.valueOffset) >= 0; + } + + void initValue() { + valueSizeOffset = countValueSizeOffset(); + entryBytes.position(valueSizeOffset); + valueSize = CompiledMapQueryContext.this.m().readValueSize(entryBytes); + CompiledMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); + valueOffset = entryBytes.position(); + this.closeValueDependants(); + } + + public void initValue(Data value) { + valueSizeOffset = countValueSizeOffset(); + innerInitValue(value); + this.closeValueDependants(); + } + + public void initValueAgain(Data value) { + assert valueInit(); + innerInitValue(value); + this.closeValueDependants(); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSizeOffset = countValueSizeOffset(); + assert oldValueSize == (value.size()); + valueSize = oldValueSize; + valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); + writeValue(value); + this.closeValueDependants(); + } + + public long valueOffset() { + if (!(this.valueInit())) + this.initValue(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valueInit())) + this.initValue(); + + return this.valueSize; + } + + public long valueSizeOffset() { + if (!(this.valueInit())) + this.initValue(); + + return this.valueSizeOffset; + } + + public void closeValue() { + if (!(this.valueInit())) + return ; + + this.closeValueDependants(); + this.valueOffset = -1; + } + + public void closeValueDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); + CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + private long _HashEntryStages_entryEnd() { + return keyEnd(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeMapEntryStagesEntryEndDependants() { + CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); + } + + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); + } + + boolean keyEquals() { + return ((inputKey().size()) == (CompiledMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledMapQueryContext.this.entryBytesAccess)), CompiledMapQueryContext.this.entryBytesAccessHandle, CompiledMapQueryContext.this.entryBytesAccessOffset(CompiledMapQueryContext.this.keyOffset()))); + } + + public void closeMapQueryKeyEqualsDependants() { + CompiledMapQueryContext.this.closeKeySearch(); + } + + long entrySize() { + return (entryEnd()) - (keySizeOffset()); + } + + public void closeMapEntryStagesEntrySizeDependants() { + CompiledMapQueryContext.this.closeTheEntrySizeInChunks(); + } + + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; + } + + void initTheEntrySizeInChunks() { + entrySizeInChunks = CompiledMapQueryContext.this.h().inChunks(entrySize()); + } + + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; + } + + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; + } + + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + return ; + + this.entrySizeInChunks = 0; } long segmentHeaderAddress; @@ -2179,10 +2585,26 @@ public class CompiledMapQueryContext= (CompiledMapQueryContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public long deleted() { - return segmentHeader().deleted(segmentHeaderAddress()); - } - - public long size() { - return (entries()) - (deleted()); - } - - long nextPosToSearchFrom() { - return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); - } - - public void deleted(long deleted) { - segmentHeader().deleted(segmentHeaderAddress(), deleted); - } - int totalReadLockCount; int totalUpdateLockCount; @@ -2324,235 +2718,6 @@ public class CompiledMapQueryContext= 0; - } - - public void initSegmentHashLookup() { - long hashLookupOffset = CompiledMapQueryContext.this.h().segmentOffset(CompiledMapQueryContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledMapQueryContext.this.h().segmentHashLookupCapacity, CompiledMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledMapQueryContext.this.h().segmentHashLookupValueBits); - this.closeSegmentHashLookupDependants(); - } - - public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { - innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); - this.closeSegmentHashLookupDependants(); - } - - public int hashLookupEntrySize() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.hashLookupEntrySize; - } - - public int keyBits() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyBits; - } - - public long address() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.address; - } - - public long capacityMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask; - } - - public long capacityMask2() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask2; - } - - public long entryMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.entryMask; - } - - public long keyMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyMask; - } - - public long valueMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.valueMask; - } - - public void closeSegmentHashLookup() { - if (!(this.segmentHashLookupInit())) - return ; - - this.closeSegmentHashLookupDependants(); - this.address = -1; - } - - public void closeSegmentHashLookupDependants() { - CompiledMapQueryContext.this.closeHashLookupStepBackDependants(); - CompiledMapQueryContext.this.closeHashLookupStepDependants(); - CompiledMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); - CompiledMapQueryContext.this.closeHashLookupReadEntryDependants(); - CompiledMapQueryContext.this.closeHashLookupIndexToPosDependants(); - CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); - CompiledMapQueryContext.this.closeHashLookupValueDependants(); - CompiledMapQueryContext.this.closeHashLookupEmptyDependants(); - CompiledMapQueryContext.this.closeHashLookupKeyDependants(); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - public long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public void closeHashLookupStepDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledMapQueryContext.this.closeSearchKey(); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public void closeHashLookupReadEntryDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - long entry(long key, long value) { - return key | (value << (keyBits())); - } - - public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); - } - - public void writeEntry(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public void closeHashLookupIndexToPosDependants() { - CompiledMapQueryContext.this.closeHashLookupHlPosDependants(); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - public void closeHashLookupHlPosDependants() { - CompiledMapQueryContext.this.closeSearchKey(); - } - - long searchKey = UNSET_KEY; - - long searchStartPos; - - public boolean searchKeyInit() { - return (this.searchKey) != (UNSET_KEY); - } - - void initSearchKey() { - searchKey = CompiledMapQueryContext.this.maskUnsetKey(CompiledMapQueryContext.this.h().hashSplitting.segmentHash(CompiledMapQueryContext.this.hashOfKey())); - searchStartPos = CompiledMapQueryContext.this.hlPos(searchKey); - this.closeSearchKeyDependants(); - } - - public long searchKey() { - if (!(this.searchKeyInit())) - this.initSearchKey(); - - return this.searchKey; - } - - public long searchStartPos() { - if (!(this.searchKeyInit())) - this.initSearchKey(); - - return this.searchStartPos; - } - - public void closeSearchKey() { - if (!(this.searchKeyInit())) - return ; - - this.closeSearchKeyDependants(); - this.searchKey = UNSET_KEY; - } - - public void closeSearchKeyDependants() { - CompiledMapQueryContext.this.closeHashLookupPos(); - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - public long hashLookupPos = -1; public boolean hashLookupPosInit() { @@ -2591,55 +2756,21 @@ public class CompiledMapQueryContext>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + void put(long value) { + CompiledMapQueryContext.this.checkValueForPut(value); + CompiledMapQueryContext.this.writeEntry(CompiledMapQueryContext.this.hashLookupPos(), CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()), searchKey(), value); } public boolean checkSlotIsEmpty() { return CompiledMapQueryContext.this.empty(CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos())); } - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - CompiledMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - } - public void putVolatile(long value) { CompiledMapQueryContext.this.checkValueForPut(value); long currentEntry = CompiledMapQueryContext.this.readEntry(CompiledMapQueryContext.this.hashLookupPos()); @@ -2647,20 +2778,8 @@ public class CompiledMapQueryContext sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); + public void remove() { + CompiledMapQueryContext.this.setHashLookupPosGuarded(CompiledMapQueryContext.this.remove(CompiledMapQueryContext.this.hashLookupPos())); } public long nextPos() { @@ -2696,386 +2815,11 @@ public class CompiledMapQueryContext 0; - } - - void initSegment() { - VanillaChronicleHash h = CompiledMapQueryContext.this.h(); - long hashLookupOffset = h.segmentOffset(segmentIndex()); - long freeListOffset = hashLookupOffset + (h.segmentHashLookupOuterSize); - freeListBytes.storePositionAndSize(h.ms, freeListOffset, h.segmentFreeListInnerSize); - freeList.reuse(freeListBytes); - entrySpaceOffset = (freeListOffset + (h.segmentFreeListOuterSize)) + (h.segmentEntrySpaceInnerOffset); - this.closeSegmentDependants(); - } - - public long entrySpaceOffset() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.entrySpaceOffset; - } - - public SingleThreadedDirectBitSet freeList() { - if (!(this.segmentInit())) - this.initSegment(); - - return this.freeList; - } - - void closeSegment() { - if (!(this.segmentInit())) - return ; - - this.closeSegmentDependants(); - entrySpaceOffset = 0; - } - - public void closeSegmentDependants() { - CompiledMapQueryContext.this.closeEntry(); - } - - public void clearSegment() { - CompiledMapQueryContext.this.innerWriteLock.lock(); - CompiledMapQueryContext.this.clearHashLookup(); - freeList().clear(); - nextPosToSearchFrom(0L); - entries(0L); - } - - public void clear() { - clearSegment(); - } - - public void free(long fromPos, int chunks) { - freeList().clear(fromPos, (fromPos + chunks)); - if (fromPos < (nextPosToSearchFrom())) - nextPosToSearchFrom(fromPos); - - } - - public long pos = -1; - - public long keySizeOffset; - - public long keySize; - - public long keyOffset; - - public boolean entryInit() { - return (this.pos) >= 0; - } - - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; - } - - public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keySizeOffset; - } - - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) - return ; - - this.closeEntryDependants(); - this.pos = -1; - } - - public void closeEntryDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesKeyEndDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); - CompiledMapQueryContext.this.closeMapQueryKeyEqualsDependants(); - CompiledMapQueryContext.this.closeMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - } - - public long keyEnd() { - return (keyOffset()) + (keySize()); - } - - public void closeMapEntryStagesKeyEndDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesCountValueSizeOffsetDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); - } - - long countValueSizeOffset() { - return keyEnd(); - } - - public void closeMapEntryStagesCountValueSizeOffsetDependants() { - CompiledMapQueryContext.this.closeValue(); - } - - public long valueSizeOffset; - - public long valueSize; - - public long valueOffset = -1; - - boolean valueInit() { - return (this.valueOffset) >= 0; - } - - void initValue() { - valueSizeOffset = countValueSizeOffset(); - entryBytes.position(valueSizeOffset); - valueSize = CompiledMapQueryContext.this.m().readValueSize(entryBytes); - CompiledMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - this.closeValueDependants(); - } - - public void initValue(Value value) { - valueSizeOffset = countValueSizeOffset(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueAgain(Value value) { - assert valueInit(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueWithoutSize(Value value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSizeOffset = countValueSizeOffset(); - assert oldValueSize == (value.size()); - valueSize = oldValueSize; - valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); - writeValue(value); - this.closeValueDependants(); - } - - public long valueOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSize; - } - - public long valueSizeOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSizeOffset; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - this.valueOffset = -1; - } - - public void closeValueDependants() { - CompiledMapQueryContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); - CompiledMapQueryContext.this.entryValue.closeEntryValueBytesValueInnerGetUsingDependants(); - CompiledMapQueryContext.this.closeMapEntryStagesEntryEndDependants(); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeMapEntryStagesEntryEndDependants() { - CompiledMapQueryContext.this.closeMapEntryStagesEntrySizeDependants(); - } - - long entrySize() { - return (entryEnd()) - (keySizeOffset()); - } - - public void closeMapEntryStagesEntrySizeDependants() { - CompiledMapQueryContext.this.closeTheEntrySizeInChunks(); - } - - public int entrySizeInChunks = 0; - - public boolean theEntrySizeInChunksInit() { - return (this.entrySizeInChunks) != 0; - } - - void initTheEntrySizeInChunks() { - entrySizeInChunks = CompiledMapQueryContext.this.h().inChunks(entrySize()); - } - - public void initTheEntrySizeInChunks(int actuallyUsedChunks) { - entrySizeInChunks = actuallyUsedChunks; - } - - public int entrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - this.initTheEntrySizeInChunks(); - - return this.entrySizeInChunks; - } - - public void closeTheEntrySizeInChunks() { - if (!(this.theEntrySizeInChunksInit())) - return ; - - this.entrySizeInChunks = 0; - } - - public final void freeExtraAllocatedChunks() { - if (((!(CompiledMapQueryContext.this.m().constantlySizedEntry)) && (CompiledMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledMapQueryContext.this.allocatedChunks()))) { - CompiledMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); - } else { - initTheEntrySizeInChunks(CompiledMapQueryContext.this.allocatedChunks()); - } - } - - public void writeValueAndPutPos(Value value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); - } - - public long newSizeOfEverythingBeforeValue(Value newValue) { - return ((valueSizeOffset()) + (CompiledMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - public void innerRemoveEntryExceptHashLookupUpdate() { - CompiledMapQueryContext.this.free(pos(), entrySizeInChunks()); - CompiledMapQueryContext.this.entries(((CompiledMapQueryContext.this.entries()) - 1L)); - CompiledMapQueryContext.this.incrementModCountGuarded(); - } - - public long alloc(int chunks) { - VanillaChronicleHash h = CompiledMapQueryContext.this.h(); - if (chunks > (h.maxChunksPerEntry)) - throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); - - long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - ret = freeList().setNextNContinuousClearBits(0L, chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - if (chunks == 1) { - throw new IllegalStateException("Segment is full, no free entries found"); - } else { - throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); - } - } - updateNextPosToSearchFrom(ret, chunks); - } else { - if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { - updateNextPosToSearchFrom(ret, chunks); - } - } - return ret; - } - - 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() { + public void closeHashLookupSearchFoundDependants() { CompiledMapQueryContext.this.closeKeySearch(); } @@ -3118,8 +2862,12 @@ public class CompiledMapQueryContext defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); } @NotNull @@ -3163,37 +2918,36 @@ public class CompiledMapQueryContext defaultValue() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.innerUpdateLock; + return CompiledMapQueryContext.this.wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); } @Override - public Value defaultValue(@NotNull - MapAbsentEntry absentEntry) { + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + return CompiledMapQueryContext.this.m().entryOperations.insert(absentEntry, value); } @Override public R replaceValue(@NotNull - MapEntry entry, Value newValue) { + MapEntry entry, Data newValue) { CompiledMapQueryContext.this.checkOnEachPublicOperation(); return CompiledMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); } - @NotNull @Override - public Value key() { + public MapEntry entry() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.entryKey; + return entryPresent() ? this : null; } @NotNull @Override - public Value defaultValue() { + public Data key() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.wrapValueAsValue(CompiledMapQueryContext.this.m().defaultValue(CompiledMapQueryContext.this.deprecatedMapKeyContext)); + return CompiledMapQueryContext.this.entryKey; } @Override @@ -3210,29 +2964,31 @@ public class CompiledMapQueryContext context() { + public MapAbsentEntry absentEntry() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return this; + return entryPresent() ? null : CompiledMapQueryContext.this.absent(); } @NotNull @Override - public Value value() { + public InterProcessLock updateLock() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.innerUpdateLock; + } + + @NotNull + @Override + public Data value() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); return CompiledMapQueryContext.this.entryValue; } - public Value queriedKey() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - @Override - public Value wrapValueAsValue(V value) { + public Data wrapValueAsValue(V value) { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledMapQueryContext.this.wrappedValueInstanceValue; + WrappedValueInstanceData wrapped = CompiledMapQueryContext.this.wrappedValueInstanceValue; wrapped = wrapped.getUnusedWrappedValueGuarded(); wrapped.initValue(value); return wrapped; @@ -3240,37 +2996,13 @@ public class CompiledMapQueryContext absentKey() { + public MapContext context() { CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.inputKey(); + return this; } - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - public boolean searchStatePresent() { - return (searchState()) == (SearchState.PRESENT); - } - - public boolean entryPresent() { - return searchStatePresent(); - } - - @Nullable - @Override - public MapAbsentEntry absentEntry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? null : CompiledMapQueryContext.this; - } - - @Override - public MapEntry entry() { - CompiledMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; + public boolean searchStateDeleted() { + return (((searchState()) == (SearchState.DELETED)) && (!(CompiledMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); } public boolean searchStateAbsent() { @@ -3289,6 +3021,10 @@ public class CompiledMapQueryContext value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); + } + + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (CompiledMapQueryContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledMapQueryContext.this.h(); + if (chunks > (h.maxChunksPerEntry)) + throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); + + long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + ret = freeList().setNextNContinuousClearBits(0L, chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + if (chunks == 1) { + throw new IllegalStateException("Segment is full, no free entries found"); + } else { + throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); + } + } + updateNextPosToSearchFrom(ret, chunks); + } else { + if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { + updateNextPosToSearchFrom(ret, chunks); + } + } + return ret; + } + public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); CompiledMapQueryContext.this.initEntryCopying(CompiledMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); incrementSegmentEntriesIfNeeded(); } - public void putValueDeletedEntry(Value newValue) { + 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) { + initValueAgain(newValue); + } else { + writeValueGuarded(newValue); + } + CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); + } + + @Override + public void doReplaceValue(Data newValue) { + putPrefix(); + if (searchStatePresent()) { + CompiledMapQueryContext.this.innerDefaultReplaceValue(newValue); + CompiledMapQueryContext.this.incrementModCountGuarded(); + setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); + } + } + + public void putValueDeletedEntry(Data newValue) { assert CompiledMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; long entryStartOffset = keySizeOffset(); @@ -3349,54 +3233,25 @@ public class CompiledMapQueryContext 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(Value 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) { - initValueAgain(newValue); - } else { - writeValueGuarded(newValue); - } - CompiledMapQueryContext.this.putValueVolatile(CompiledMapQueryContext.this.hashLookupPos(), pos()); - } - public void initEntryAndKey(long entrySize) { initAllocatedChunks(CompiledMapQueryContext.this.h().inChunks(entrySize)); CompiledMapQueryContext.this.initEntry(CompiledMapQueryContext.this.alloc(allocatedChunks()), CompiledMapQueryContext.this.inputKey()); incrementSegmentEntriesIfNeeded(); } - void putEntry(Value value) { + @NotNull + @Override + public Data absentKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledMapQueryContext.this.inputKey(); + } + + public Data queriedKey() { + CompiledMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } + + void putEntry(Data value) { assert CompiledMapQueryContext.this.searchStateAbsent(); long entrySize = CompiledMapQueryContext.this.entrySize(CompiledMapQueryContext.this.inputKey().size(), value.size()); CompiledMapQueryContext.this.initEntryAndKey(entrySize); @@ -3406,7 +3261,7 @@ public class CompiledMapQueryContext value) { + public void doInsert(Data value) { CompiledMapQueryContext.this.putPrefix(); if (!(CompiledMapQueryContext.this.searchStatePresent())) { if (CompiledMapQueryContext.this.searchStateDeleted()) { @@ -3421,29 +3276,180 @@ public class CompiledMapQueryContext newValue) { - putPrefix(); - if (searchStatePresent()) { - CompiledMapQueryContext.this.innerDefaultReplaceValue(newValue); - CompiledMapQueryContext.this.incrementModCountGuarded(); - setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); - } + boolean used; + + public boolean usedInit() { + return used; } - @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 initUsed(boolean used) { + this.used = used; + } + + void closeUsed() { + if (!(this.usedInit())) + return ; + + used = false; + } + + public Bytes inputBytes = null; + + public boolean inputBytesInit() { + return (this.inputBytes) != null; + } + + public void initInputBytes(Bytes inputBytes) { + this.inputBytes = inputBytes; + this.closeInputBytesDependants(); + } + + public Bytes inputBytes() { + assert this.inputBytesInit() : "InputBytes should be init"; + return this.inputBytes; + } + + public void closeInputBytes() { + if (!(this.inputBytesInit())) + return ; + + this.closeInputBytesDependants(); + this.inputBytes = null; + } + + public void closeInputBytesDependants() { + CompiledMapQueryContext.this.closeInputKeyOffsets(); + CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.closeFirstInputValueOffsets(); + CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.closeSecondInputValueOffsets(); + CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); + } + + public long inputKeySize = -1; + + public long inputKeyOffset; + + public boolean inputKeyOffsetsInit() { + return (this.inputKeySize) >= 0; + } + + private void initInputKeyOffsets() { + inputKeySize = CompiledMapQueryContext.this.h().keySizeMarshaller.readSize(inputBytes()); + inputKeyOffset = inputBytes().position(); + this.closeInputKeyOffsetsDependants(); + } + + public long inputKeyOffset() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeyOffset; + } + + public long inputKeySize() { + if (!(this.inputKeyOffsetsInit())) + this.initInputKeyOffsets(); + + return this.inputKeySize; + } + + public void closeInputKeyOffsets() { + if (!(this.inputKeyOffsetsInit())) + return ; + + this.closeInputKeyOffsetsDependants(); + this.inputKeySize = -1; + } + + public void closeInputKeyOffsetsDependants() { + CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataSizeDependants(); + CompiledMapQueryContext.this.inputKeyBytesValue.closeInputKeyBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.closeFirstInputValueOffsets(); + } + + public long firstInputValueSize = -1; + + public long firstInputValueOffset; + + public boolean firstInputValueOffsetsInit() { + return (this.firstInputValueSize) >= 0; + } + + private void initFirstInputValueOffsets() { + CompiledMapQueryContext.this.inputBytes().position(((CompiledMapQueryContext.this.inputKeyOffset()) + (CompiledMapQueryContext.this.inputKeySize()))); + firstInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); + firstInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); + this.closeFirstInputValueOffsetsDependants(); + } + + public long firstInputValueOffset() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueOffset; + } + + public long firstInputValueSize() { + if (!(this.firstInputValueOffsetsInit())) + this.initFirstInputValueOffsets(); + + return this.firstInputValueSize; + } + + public void closeFirstInputValueOffsets() { + if (!(this.firstInputValueOffsetsInit())) + return ; + + this.closeFirstInputValueOffsetsDependants(); + this.firstInputValueSize = -1; + } + + public void closeFirstInputValueOffsetsDependants() { + CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataSizeDependants(); + CompiledMapQueryContext.this.inputFirstValueBytesValue.closeInputFirstValueBytesDataGetUsingDependants(); + CompiledMapQueryContext.this.closeSecondInputValueOffsets(); + } + + public long secondInputValueSize = -1; + + public long secondInputValueOffset; + + public boolean secondInputValueOffsetsInit() { + return (this.secondInputValueSize) >= 0; + } + + private void initSecondInputValueOffsets() { + CompiledMapQueryContext.this.inputBytes().position(((firstInputValueOffset()) + (firstInputValueSize()))); + secondInputValueSize = CompiledMapQueryContext.this.m().valueSizeMarshaller.readSize(CompiledMapQueryContext.this.inputBytes()); + secondInputValueOffset = CompiledMapQueryContext.this.inputBytes().position(); + this.closeSecondInputValueOffsetsDependants(); + } + + public long secondInputValueOffset() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueOffset; + } + + public long secondInputValueSize() { + if (!(this.secondInputValueOffsetsInit())) + this.initSecondInputValueOffsets(); + + return this.secondInputValueSize; + } + + public void closeSecondInputValueOffsets() { + if (!(this.secondInputValueOffsetsInit())) + return ; + + this.closeSecondInputValueOffsetsDependants(); + this.secondInputValueSize = -1; + } + + public void closeSecondInputValueOffsetsDependants() { + CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataSizeDependants(); + CompiledMapQueryContext.this.inputSecondValueBytesValue.closeInputSecondValueBytesDataGetUsingDependants(); } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java index 00e308a3f..13b8079db 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapIterationContext.java @@ -4,11 +4,11 @@ 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.AbstractValue; +import net.openhft.chronicle.hash.AbstractData; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.HashEntry; -import net.openhft.chronicle.hash.Value; import net.openhft.chronicle.hash.impl.BigSegmentHeader; -import net.openhft.chronicle.hash.impl.CopyingInstanceValue; +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; @@ -17,6 +17,7 @@ import net.openhft.chronicle.hash.impl.hashlookup.EntryConsumer; import net.openhft.chronicle.hash.locks.InterProcessLock; import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; import net.openhft.chronicle.hash.replication.RemoteOperationContext; +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; @@ -43,23 +44,27 @@ import java.util.ArrayList; import java.util.ConcurrentModificationException; import java.util.List; 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 , MapContext , MapEntry , IterationContextInterface , ReplicatedChronicleMapHolder , 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.closeUsed(); - CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); CompiledReplicatedMapIterationContext.this.closeReplicationUpdate(); - CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeValue(); - CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); CompiledReplicatedMapIterationContext.this.closeTheSegmentIndex(); + CompiledReplicatedMapIterationContext.this.closeUsed(); CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); + CompiledReplicatedMapIterationContext.this.closeAllocatedChunks(); + CompiledReplicatedMapIterationContext.this.closeKeyOffset(); + CompiledReplicatedMapIterationContext.this.closeEntryRemovedOnThisIteration(); + CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeValue(); + CompiledReplicatedMapIterationContext.this.closeKeySize(); + CompiledReplicatedMapIterationContext.this.closePos(); CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue.closeNext(); - CompiledReplicatedMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); CompiledReplicatedMapIterationContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); - CompiledReplicatedMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapIterationContext.this.closeReplicatedMapSegmentIterationCheckEntryNotRemovedOnThisIterationDependants(); + CompiledReplicatedMapIterationContext.this.closeValueBytesInteropValueMetaInteropDependants(); + CompiledReplicatedMapIterationContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); + CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockForbiddenUpgradeDependants(); } public void incrementModCountGuarded() { @@ -81,41 +86,29 @@ public class CompiledReplicatedMapIterationContext value) { - if (!(this.valueInit())) - this.initValue(); - - writeValue(value); - } - - void initKeySizeOffset(long pos) { - keySizeOffset = (CompiledReplicatedMapIterationContext.this.entrySpaceOffset()) + (pos * (CompiledReplicatedMapIterationContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - } - public CompiledReplicatedMapIterationContext(ReplicatedChronicleMap m) { contextChain = new ArrayList(); contextChain.add(this); indexInContextChain = 0; this.m = m; - this.entryKey = new EntryKeyBytesValue(); this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.dummyValue = new DummyValueZeroData(); + this.innerUpdateLock = new UpdateLock(); + this.entryKey = new EntryKeyBytesData(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); this.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.entryValue = new EntryValueBytesValue(); this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.owner = Thread.currentThread(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); this.innerWriteLock = new WriteLock(); - this.dummyValue = new DummyValueZeroValue(); + this.owner = Thread.currentThread(); this.innerReadLock = new ReadLock(); - this.innerUpdateLock = new UpdateLock(); + this.entryValue = new EntryValueBytesData(); } public CompiledReplicatedMapIterationContext(CompiledReplicatedMapIterationContext c) { @@ -123,33 +116,165 @@ public class CompiledReplicatedMapIterationContext)(c.m)); - this.entryKey = new EntryKeyBytesValue(); this.entryBytes = CompiledReplicatedMapIterationContext.this.h().ms.bytes(); this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); + this.dummyValue = new DummyValueZeroData(); + this.innerUpdateLock = new UpdateLock(); + this.entryKey = new EntryKeyBytesData(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); this.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.entryValue = new EntryValueBytesValue(); this.deprecatedMapKeyContextOnIteration = new DeprecatedMapKeyContextOnIteration(); - this.owner = Thread.currentThread(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); this.innerWriteLock = new WriteLock(); - this.dummyValue = new DummyValueZeroValue(); + this.owner = Thread.currentThread(); this.innerReadLock = new ReadLock(); - this.innerUpdateLock = new UpdateLock(); + this.entryValue = new EntryValueBytesData(); } - public class EntryKeyBytesValue extends AbstractValue { + public class DeprecatedMapKeyContextOnIteration implements MapKeyContext { @Override - public T handle() { + public boolean put(V newValue) { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; + CompiledReplicatedMapIterationContext.this.replaceValue(CompiledReplicatedMapIterationContext.this, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(newValue)); + return true; } + @Override + public V getUsing(V usingValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.value().getUsing(usingValue); + } + + @Override + public V get() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.value().get(); + } + + @Override + public boolean valueEqualTo(V value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledReplicatedMapIterationContext.this.entryValue, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(value)); + } + + @NotNull + @Override + public Bytes entry() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytes; + } + + @Override + public boolean containsKey() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return true; + } + + @Override + public boolean remove() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + CompiledReplicatedMapIterationContext.this.remove(CompiledReplicatedMapIterationContext.this); + return true; + } + + @NotNull + @Override + public K key() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.key().get(); + } + + @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"); + } + + @NotNull + @Override + public InterProcessLock readLock() { + throw unsupportedLocks(); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + throw unsupportedLocks(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + throw unsupportedLocks(); + } + + @Override + public long keySize() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.keySize(); + } + + @Override + public long valueSize() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.valueSize(); + } + + @Override + public long valueOffset() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.valueOffset(); + } + + @Override + public long keyOffset() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.keyOffset(); + } + } + + public class DummyValueZeroData extends AbstractData { + @Override + public ReadAccess access() { + return ReadAccess.zeros(); + } + + @Override + public V get() { + throw new UnsupportedOperationException(); + } + + @Override + public long size() { + return CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.minEncodableSize(); + } + + @Override + public V getUsing(V usingInstance) { + throw new UnsupportedOperationException(); + } + + @Override + public Void handle() { + return null; + } + + @Override + public long offset() { + return 0; + } + } + + public class EntryKeyBytesData extends AbstractData { @Override public ReadAccess access() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); @@ -157,9 +282,9 @@ public class CompiledReplicatedMapIterationContext { + @Override + public T handle() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; } @Override - public void lockInterruptibly() throws InterruptedException { - switch (CompiledReplicatedMapIterationContext.this.localLockState()) { - case UNLOCKED : - CompiledReplicatedMapIterationContext.this.segmentHeader().writeLockInterruptibly(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return ; - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - CompiledReplicatedMapIterationContext.this.segmentHeader().upgradeUpdateToWriteLockInterruptibly(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - case WRITE_LOCKED : - } + public ReadAccess access() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytesAccess; } @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; - } - throw new AssertionError(); + public long size() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.valueSize(); } + public void closeEntryValueBytesDataSizeDependants() { + EntryValueBytesData.this.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + private V innerGetUsing(V usingValue) { + CompiledReplicatedMapIterationContext.this.entryBytes.position(CompiledReplicatedMapIterationContext.this.valueOffset()); + return CompiledReplicatedMapIterationContext.this.valueReader.read(CompiledReplicatedMapIterationContext.this.entryBytes, size(), usingValue); + } + + public void closeEntryValueBytesDataInnerGetUsingDependants() { + EntryValueBytesData.this.closeCachedEntryValue(); + } + + private V cachedEntryValue; + + private boolean cachedEntryValueRead = false; + + public boolean cachedEntryValueInit() { + return (this.cachedEntryValueRead) != false; + } + + private void initCachedEntryValue() { + cachedEntryValue = innerGetUsing(cachedEntryValue); + cachedEntryValueRead = true; + } + + public V cachedEntryValue() { + if (!(this.cachedEntryValueInit())) + this.initCachedEntryValue(); + + return this.cachedEntryValue; + } + + public void closeCachedEntryValue() { + if (!(this.cachedEntryValueInit())) + return ; + + this.cachedEntryValueRead = false; + } + + @Override + public V get() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return cachedEntryValue(); + } + + @Override + public V getUsing(V usingValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return innerGetUsing(usingValue); + } + + @Override + public long offset() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryBytesAccessOffset(CompiledReplicatedMapIterationContext.this.valueOffset()); + } + } + + public class ReadLock implements InterProcessLock { @Override public boolean isHeldByCurrentThread() { - return CompiledReplicatedMapIterationContext.this.localLockState().write; - } - - @Override - public void lock() { - switch (CompiledReplicatedMapIterationContext.this.localLockState()) { - case UNLOCKED : - CompiledReplicatedMapIterationContext.this.segmentHeader().writeLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return ; - case READ_LOCKED : - throw forbiddenUpgrade(); - case UPDATE_LOCKED : - CompiledReplicatedMapIterationContext.this.segmentHeader().upgradeUpdateToWriteLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - case WRITE_LOCKED : - } - } - - @Override - public boolean tryLock() { - switch (CompiledReplicatedMapIterationContext.this.localLockState()) { - case UNLOCKED : - if (CompiledReplicatedMapIterationContext.this.segmentHeader().tryWriteLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress())) { - 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())) { - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); - return true; - } else { - return false; - } - case WRITE_LOCKED : - return true; - } - throw new AssertionError(); + return CompiledReplicatedMapIterationContext.this.localLockState().read; } @Override public void unlock() { switch (CompiledReplicatedMapIterationContext.this.localLockState()) { case UNLOCKED : - case READ_LOCKED : - case UPDATE_LOCKED : return ; + case READ_LOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().readUnlock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + break; + case UPDATE_LOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().updateUnlock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + break; case WRITE_LOCKED : - CompiledReplicatedMapIterationContext.this.segmentHeader().downgradeWriteToUpdateLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.segmentHeader().writeUnlock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + } + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UNLOCKED); + CompiledReplicatedMapIterationContext.this.closeHashLookupPos(); + CompiledReplicatedMapIterationContext.this.closePos(); + } + + @Override + public void lock() { + if ((CompiledReplicatedMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledReplicatedMapIterationContext.this.segmentHeader().readLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } + } + + @Override + public boolean tryLock() { + if ((CompiledReplicatedMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledReplicatedMapIterationContext.this.segmentHeader().tryReadLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress())) { + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { + return true; + } + } + + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + if ((CompiledReplicatedMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledReplicatedMapIterationContext.this.segmentHeader().tryReadLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress(), time, unit)) { + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { + return true; + } + } + + @Override + public void lockInterruptibly() throws InterruptedException { + if ((CompiledReplicatedMapIterationContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledReplicatedMapIterationContext.this.segmentHeader().readLockInterruptibly(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); } - CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); } } @@ -335,54 +507,6 @@ public class CompiledReplicatedMapIterationContext { - @Override - public T handle() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccessHandle; - } - - @Override - public ReadAccess access() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccess; - } - - @Override - public long size() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.valueSize(); - } - - public void closeEntryValueBytesValueSizeDependants() { - EntryValueBytesValue.this.closeEntryValueBytesValueInnerGetUsingDependants(); - } - - private V innerGetUsing(V usingValue) { - CompiledReplicatedMapIterationContext.this.entryBytes.position(CompiledReplicatedMapIterationContext.this.valueOffset()); - return CompiledReplicatedMapIterationContext.this.valueReader.read(CompiledReplicatedMapIterationContext.this.entryBytes, size(), usingValue); - } - - public void closeEntryValueBytesValueInnerGetUsingDependants() { - EntryValueBytesValue.this.closeCachedEntryValue(); - } - - @Override - public V getUsing(V usingValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return innerGetUsing(usingValue); - } - - private V cachedEntryValue; - - private boolean cachedEntryValueRead = false; - - public boolean cachedEntryValueInit() { - return (this.cachedEntryValueRead) != false; - } - - private void initCachedEntryValue() { - cachedEntryValue = innerGetUsing(cachedEntryValue); - cachedEntryValueRead = true; - } - - public V cachedEntryValue() { - if (!(this.cachedEntryValueInit())) - this.initCachedEntryValue(); - - return this.cachedEntryValue; - } - - public void closeCachedEntryValue() { - if (!(this.cachedEntryValueInit())) - return ; - - this.cachedEntryValueRead = false; - } - - @Override - public V get() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return cachedEntryValue(); - } - - @Override - public long offset() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytesAccessOffset(CompiledReplicatedMapIterationContext.this.valueOffset()); - } - } - - public class WrappedValueInstanceValue extends CopyingInstanceValue { - public WrappedValueInstanceValue getUnusedWrappedValueGuarded() { + public class WrappedValueInstanceData extends CopyingInstanceData { + public WrappedValueInstanceData getUnusedWrappedValueGuarded() { assert this.nextInit() : "Next should be init"; return getUnusedWrappedValue(); } - public WrappedValueInstanceValue getUnusedWrappedValue() { + public WrappedValueInstanceData getUnusedWrappedValue() { if (!(valueInit())) return this; if ((next) == null) - next = new WrappedValueInstanceValue(); + next = new WrappedValueInstanceData(); return next.getUnusedWrappedValue(); } - private WrappedValueInstanceValue next; + private WrappedValueInstanceData next; boolean nextInit() { return true; @@ -629,7 +652,7 @@ public class CompiledReplicatedMapIterationContext { + public class WriteLock implements InterProcessLock { @NotNull - private UnsupportedOperationException unsupportedLocks() { - return new UnsupportedOperationException("Lock operations are not supported (and not needed!) during iteration"); + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to write lock"); } - @NotNull - @Override - public InterProcessLock readLock() { - throw unsupportedLocks(); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - throw unsupportedLocks(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - throw unsupportedLocks(); + public void closeWriteLockForbiddenUpgradeDependants() { + WriteLock.this.closeWriteLockLockDependants(); } @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(); + public void unlock() { + switch (CompiledReplicatedMapIterationContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + case UPDATE_LOCKED : + return ; + case WRITE_LOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().downgradeWriteToUpdateLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + } + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); } @Override - public boolean remove() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.remove(CompiledReplicatedMapIterationContext.this); - return true; + public boolean isHeldByCurrentThread() { + return CompiledReplicatedMapIterationContext.this.localLockState().write; } @Override - public boolean put(V newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapIterationContext.this.replaceValue(CompiledReplicatedMapIterationContext.this, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(newValue)); - return true; + public void lock() { + switch (CompiledReplicatedMapIterationContext.this.localLockState()) { + case UNLOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().writeLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().upgradeUpdateToWriteLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : + } + } + + public void closeWriteLockLockDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); } @Override - public boolean containsKey() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return true; - } - - @NotNull - @Override - public Bytes entry() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryBytes; + public void lockInterruptibly() throws InterruptedException { + switch (CompiledReplicatedMapIterationContext.this.localLockState()) { + case UNLOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().writeLockInterruptibly(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledReplicatedMapIterationContext.this.segmentHeader().upgradeUpdateToWriteLockInterruptibly(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress()); + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : + } } @Override - public boolean valueEqualTo(V value) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledReplicatedMapIterationContext.this.entryValue, CompiledReplicatedMapIterationContext.this.context().wrapValueAsValue(value)); + public boolean tryLock() { + switch (CompiledReplicatedMapIterationContext.this.localLockState()) { + case UNLOCKED : + if (CompiledReplicatedMapIterationContext.this.segmentHeader().tryWriteLock(CompiledReplicatedMapIterationContext.this.segmentHeaderAddress())) { + 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())) { + CompiledReplicatedMapIterationContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); } @Override - public V getUsing(V usingValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.value().getUsing(usingValue); + 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; + } + throw new AssertionError(); } - - @Override - public void close() { - throw new UnsupportedOperationException("close() is not supported during iteration"); - } - - @Override - public long keySize() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.keySize(); - } - - @Override - public long keyOffset() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.keyOffset(); - } - - @Override - public long valueSize() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.valueSize(); - } - - @Override - public long valueOffset() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.valueOffset(); - } - } - - public class DummyValueZeroValue extends AbstractValue { - @Override - public Void handle() { - return null; - } - - @Override - public ReadAccess access() { - return ReadAccess.zeros(); - } - - @Override - public V getUsing(V usingInstance) { - throw new UnsupportedOperationException(); - } - - @Override - public V get() { - throw new UnsupportedOperationException(); - } - - @Override - public long size() { - return CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.minEncodableSize(); - } - - @Override - public long offset() { - return 0; - } - } - - private void _MapEntryStages_writeValue(Value value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); } public void incrementModCount() { @@ -834,12 +831,6 @@ public class CompiledReplicatedMapIterationContext value) { - _MapEntryStages_writeValue(value); - initUpdatedReplicationState(); - CompiledReplicatedMapIterationContext.this.updateChange(); - } - final Thread owner; public Thread owner() { @@ -914,18 +905,9 @@ public class CompiledReplicatedMapIterationContext value) { - entryBytes.position(valueSizeOffset); - valueSize = value.size(); - CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - CompiledReplicatedMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - writeValue(value); + this.keyMask = mask(keyBits); + this.valueMask = mask(valueBits); + this.entryMask = mask((keyBits + valueBits)); } private void unlinkFromSegmentContextsChain() { @@ -1037,27 +1019,32 @@ public class CompiledReplicatedMapIterationContext m() { - return m; + public void checkAccessingFromOwnerThread() { + if ((owner) != (Thread.currentThread())) { + throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); + } } - @Override - public ChronicleMap map() { - return m(); + public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { + CompiledReplicatedMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); } - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); + @NotNull + @Override + public MapContext context() { + return CompiledReplicatedMapIterationContext.this; + } + + 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(); } public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { @@ -1137,12 +1134,6 @@ public class CompiledReplicatedMapIterationContext context() { - return CompiledReplicatedMapIterationContext.this; - } - public void checkEntryNotRemovedOnThisIteration() { if (entryRemovedOnThisIterationInit()) throw new IllegalStateException("Entry was already removed on this iteration"); @@ -1153,56 +1144,6 @@ public class CompiledReplicatedMapIterationContextT contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); - } - - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public void incrementSegmentEntriesIfNeeded() { - } - - private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledReplicatedMapIterationContext.this.m().metaDataBytes) + (CompiledReplicatedMapIterationContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - public long entryBytesAccessOffset(long offset) { - return entryBytesAccessor.offset(entryBytes, offset); - } - - public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeEntry(); - } - - public void checkAccessingFromOwnerThread() { - if ((owner) != (Thread.currentThread())) { - throw new ConcurrentModificationException("Context shouldn\'t be accessed from multiple threads"); - } - } - - public void closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants() { - CompiledReplicatedMapIterationContext.this.closeInterationCheckOnEachPublicOperationCheckOnEachPublicOperationDependants(); - } - private void _CheckOnEachPublicOperation_checkOnEachPublicOperation() { CompiledReplicatedMapIterationContext.this.checkAccessingFromOwnerThread(); } @@ -1213,26 +1154,40 @@ public class CompiledReplicatedMapIterationContext absentEntry, Data value) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); } @NotNull @Override - public InterProcessLock writeLock() { + public Data key() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerWriteLock; + return CompiledReplicatedMapIterationContext.this.entryKey; } @Override - public Value wrapValueAsValue(V value) { + public Data wrapValueAsValue(V value) { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue; + WrappedValueInstanceData wrapped = CompiledReplicatedMapIterationContext.this.wrappedValueInstanceValue; wrapped = wrapped.getUnusedWrappedValueGuarded(); wrapped.initValue(value); return wrapped; } + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); + } + @Override public R remove(@NotNull MapEntry entry) { @@ -1240,34 +1195,6 @@ public class CompiledReplicatedMapIterationContext entry, Value newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @Override - public Value defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); - } - - @NotNull - @Override - public Value value() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryValue; - } - - @NotNull - @Override - public InterProcessLock readLock() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.innerReadLock; - } - @NotNull @Override public InterProcessLock updateLock() { @@ -1277,16 +1204,72 @@ public class CompiledReplicatedMapIterationContext key() { + public InterProcessLock writeLock() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.entryKey; + return CompiledReplicatedMapIterationContext.this.innerWriteLock; + } + + @NotNull + @Override + public InterProcessLock readLock() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.innerReadLock; + } + + @NotNull + @Override + public Data value() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapIterationContext.this.entryValue; } @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { + public Data defaultValue(@NotNull + MapAbsentEntry absentEntry) { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapIterationContext.this.m().entryOperations.insert(absentEntry, value); + return CompiledReplicatedMapIterationContext.this.m().entryOperations.defaultValue(absentEntry); + } + + public void incrementSegmentEntriesIfNeeded() { + } + + public MKI keyMetaInterop(K key) { + return CompiledReplicatedMapIterationContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapIterationContext.this.copies, CompiledReplicatedMapIterationContext.this.h().originalMetaKeyInterop, keyInterop, key); + } + + @Override + public ReplicatedChronicleMap m() { + return m; + } + + @Override + public ChronicleMap map() { + return m(); + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledReplicatedMapIterationContext.this.closeSegmentStagesTryFindInitLocksOfThisSegmentDependants(); + } + + public long entryBytesAccessOffset(long offset) { + return entryBytesAccessor.offset(entryBytes, offset); + } + + private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (((CompiledReplicatedMapIterationContext.this.m().metaDataBytes) + (CompiledReplicatedMapIterationContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); + } + + long sizeOfEverythingBeforeValue(long keySize, long valueSize) { + return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public final long entrySize(long keySize, long valueSize) { + long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); + return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); } private CompiledReplicatedMapIterationContext _Chaining_createChaining() { @@ -1310,6 +1293,378 @@ 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() { + CompiledReplicatedMapIterationContext.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() { + CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + } + + 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(); + this.closeReplicationStateDependants(); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.closeReplicationStateDependants(); + this.replicationBytesOffset = -1; + } + + public void closeReplicationStateDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesIdentifierOffsetDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesUpdateReplicationStateDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesTimestampOffsetDependants(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + private boolean _MapSegmentIteration_entryIsPresent() { + return true; + } + + public boolean entryIsPresent() { + return !(CompiledReplicatedMapIterationContext.this.entryDeleted()); + } + + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + public void closeReplicatedMapEntryStagesIdentifierOffsetDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesIdentifierDependants(); + } + + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); + } + + public void closeReplicatedMapEntryStagesIdentifierDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); + } + + @Override + public byte originIdentifier() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return identifier(); + } + + void updateReplicationState(long timestamp, byte identifier) { + entryBytes.position(replicationBytesOffset()); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public void closeReplicatedMapEntryStagesUpdateReplicationStateDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + public void closeReplicatedMapEntryStagesTimestampOffsetDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesTimestampDependants(); + } + + public long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + public void closeReplicatedMapEntryStagesTimestampDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); + } + + @Override + public long originTimestamp() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return timestamp(); + } + + 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.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + } + + 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); + } + + private long _HashEntryStages_entryEnd() { + return keyEnd(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeReplicatedMapEntryStagesEntryEndDependants() { + CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + public int allocatedChunks = 0; + + public boolean allocatedChunksInit() { + return (this.allocatedChunks) != 0; + } + + public void initAllocatedChunks(int allocatedChunks) { + this.allocatedChunks = allocatedChunks; + } + + public int allocatedChunks() { + assert this.allocatedChunksInit() : "AllocatedChunks should be init"; + return this.allocatedChunks; + } + + public void closeAllocatedChunks() { + if (!(this.allocatedChunksInit())) + return ; + + this.allocatedChunks = 0; + } + public long hashLookupPos = -1; public boolean hashLookupPosInit() { @@ -1332,6 +1687,23 @@ public class CompiledReplicatedMapIterationContext= 0; + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; } - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; + public void initEntryOffset() { + keySizeOffset = (CompiledReplicatedMapIterationContext.this.entrySpaceOffset()) + ((pos()) * (CompiledReplicatedMapIterationContext.this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); } public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + return this.keySizeOffset; } - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) return ; - this.closeEntryDependants(); - this.pos = -1; + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; } - public void closeEntryDependants() { - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapIterationContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicationUpdateDropChangeDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicationUpdateUpdateChangeDependants(); + public void closeEntryOffsetDependants() { CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); } - public long keyEnd() { - return (keyOffset()) + (keySize()); + long entrySize() { + return (entryEnd()) - (keySizeOffset()); } - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapIterationContext.this.closeReplicationState(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + public void closeReplicatedMapEntryStagesEntrySizeDependants() { + CompiledReplicatedMapIterationContext.this.closeTheEntrySizeInChunks(); } - long replicationBytesOffset = -1; + public int entrySizeInChunks = 0; - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; } - void initReplicationState() { - replicationBytesOffset = keyEnd(); + void initTheEntrySizeInChunks() { + entrySizeInChunks = CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize()); } - void initReplicationState(long timestamp, byte identifier) { - replicationBytesOffset = keyEnd(); - entryBytes.position(replicationBytesOffset); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; } - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); - return this.replicationBytesOffset; + return this.entrySizeInChunks; } - public void closeReplicationState() { - if (!(this.replicationStateInit())) + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) return ; - this.replicationBytesOffset = -1; + this.entrySizeInChunks = 0; } - private long timestampOffset() { - return replicationBytesOffset(); + public void copyExistingEntry(long newPos, long bytesToCopy) { + long oldKeySizeOffset = keySizeOffset(); + long oldKeyOffset = keyOffset(); + initPos(newPos); + initKeyOffset(((keySizeOffset()) + (oldKeyOffset - oldKeySizeOffset))); + Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset()), bytesToCopy); } - long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); } - @Override - public long originTimestamp() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return timestamp(); + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); } - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - private boolean _MapSegmentIteration_entryIsPresent() { - return true; - } - - public boolean entryIsPresent() { - return !(CompiledReplicatedMapIterationContext.this.entryDeleted()); - } - - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); - } - - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapIterationContext.this.closeValue(); + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + CompiledReplicatedMapIterationContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); } int hashLookupEntrySize; @@ -1686,28 +1983,38 @@ public class CompiledReplicatedMapIterationContext>> (keyBits())) & (valueMask()); + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public long stepBack(long pos) { + return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); } public boolean empty(long entry) { return (entry & (entryMask())) == (UNSET_ENTRY); } - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); } long entry(long key, long value) { @@ -1719,29 +2026,12 @@ public class CompiledReplicatedMapIterationContext>> (keyBits())) & (valueMask()); } void forEach(EntryConsumer action) { @@ -1760,12 +2050,12 @@ public class CompiledReplicatedMapIterationContext= 0 ? pos : capacityMask2(); + public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); + } + + public void putValueVolatile(long pos, long value) { + checkValueForPut(value); + long currentEntry = readEntry(pos); + writeEntryVolatile(pos, currentEntry, key(currentEntry), value); } long segmentHeaderAddress; @@ -1837,32 +2134,13 @@ public class CompiledReplicatedMapIterationContext> action) { - CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); - try { - long size = CompiledReplicatedMapIterationContext.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); - } - CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); - do { - CompiledReplicatedMapIterationContext.this.setHashLookupPosGuarded(CompiledReplicatedMapIterationContext.this.step(CompiledReplicatedMapIterationContext.this.hashLookupPos())); - long entry = CompiledReplicatedMapIterationContext.this.readEntry(CompiledReplicatedMapIterationContext.this.hashLookupPos()); - if (!(CompiledReplicatedMapIterationContext.this.empty(entry))) { - CompiledReplicatedMapIterationContext.this.initEntry(CompiledReplicatedMapIterationContext.this.value(entry)); - if (entryIsPresent()) { - initEntryRemovedOnThisIteration(false); - if (!(action.test(((MapEntry)(this))))) { - interrupted = true; - break; - } else { - if ((--size) == 0) - break; - - } - } - } - } while ((CompiledReplicatedMapIterationContext.this.hashLookupPos()) != startPos ); - return !interrupted; - } finally { - CompiledReplicatedMapIterationContext.this.innerReadLock.unlock(); - initEntryRemovedOnThisIteration(false); - } + public void closeLocksDependants() { + CompiledReplicatedMapIterationContext.this.innerWriteLock.closeWriteLockLockDependants(); } public void nextPosToSearchFrom(long nextPosToSearchFrom) { segmentHeader().nextPosToSearchFrom(segmentHeaderAddress(), nextPosToSearchFrom); } + public void updateNextPosToSearchFrom(long allocated, int chunks) { + long nextPosToSearchFrom = allocated + chunks; + if (nextPosToSearchFrom >= (CompiledReplicatedMapIterationContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + public void entries(long size) { + segmentHeader().size(segmentHeaderAddress(), size); + } + public void clearSegment() { CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); CompiledReplicatedMapIterationContext.this.clearHashLookup(); @@ -2002,12 +2260,29 @@ public class CompiledReplicatedMapIterationContext= (CompiledReplicatedMapIterationContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; + long nextPosToSearchFrom() { + return segmentHeader().nextPosToSearchFrom(segmentHeaderAddress()); + } - nextPosToSearchFrom(nextPosToSearchFrom); + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public final void freeExtraAllocatedChunks() { + if (((!(CompiledReplicatedMapIterationContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapIterationContext.this.allocatedChunks()))) { + CompiledReplicatedMapIterationContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapIterationContext.this.allocatedChunks()) - (entrySizeInChunks()))); + } else { + initTheEntrySizeInChunks(CompiledReplicatedMapIterationContext.this.allocatedChunks()); + } + } + + public void writeValueAndPutPos(Data value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); } public long alloc(int chunks) { @@ -2040,390 +2315,25 @@ public class CompiledReplicatedMapIterationContext= 0; - } - - void initValue() { - valueSizeOffset = countValueSizeOffset(); - entryBytes.position(valueSizeOffset); - valueSize = CompiledReplicatedMapIterationContext.this.m().readValueSize(entryBytes); - CompiledReplicatedMapIterationContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - this.closeValueDependants(); - } - - public void initValue(Value value) { - valueSizeOffset = countValueSizeOffset(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueAgain(Value value) { - assert valueInit(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueWithoutSize(Value value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSizeOffset = countValueSizeOffset(); - assert oldValueSize == (value.size()); - valueSize = oldValueSize; - valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); - writeValue(value); - this.closeValueDependants(); - } - - public long valueOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSize; - } - - public long valueSizeOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSizeOffset; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - this.valueOffset = -1; - } - - public void closeValueDependants() { - CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); - CompiledReplicatedMapIterationContext.this.entryValue.closeEntryValueBytesValueInnerGetUsingDependants(); - CompiledReplicatedMapIterationContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - } - - public long newSizeOfEverythingBeforeValue(Value newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapIterationContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - private long _HashEntryStages_entryEnd() { - return keyEnd(); - } - - protected long entryEnd() { - return (valueOffset()) + (valueSize()); - } - - public void closeReplicatedMapEntryStagesEntryEndDependants() { - 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 int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; - } - - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; - } - - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) - return ; - - this.allocatedChunks = 0; - } - - public final void freeExtraAllocatedChunks() { - if (((!(CompiledReplicatedMapIterationContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapIterationContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapIterationContext.this.allocatedChunks()))) { - CompiledReplicatedMapIterationContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapIterationContext.this.allocatedChunks()) - (entrySizeInChunks()))); - } else { - initTheEntrySizeInChunks(CompiledReplicatedMapIterationContext.this.allocatedChunks()); - } - } - - public void writeValueAndPutPos(Value value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); - } - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { initAllocatedChunks(CompiledReplicatedMapIterationContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapIterationContext.this.initEntryCopying(CompiledReplicatedMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); + CompiledReplicatedMapIterationContext.this.copyExistingEntry(CompiledReplicatedMapIterationContext.this.alloc(allocatedChunks()), bytesToCopy); incrementSegmentEntriesIfNeeded(); } - private void _MapEntryStages_putValueDeletedEntry(Value 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) { - initValueAgain(newValue); - } else { - writeValueGuarded(newValue); - } - } else { - if (newValueSizeIsDifferent) { - assert newSizeOfEverythingBeforeValue >= 0; - } else { - newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); - } - long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); - if (newValueSizeIsDifferent) { - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); - initValue(newValue); - } else { - long oldValueSizeOffset = valueSizeOffset(); - long oldValueSize = valueSize(); - long oldValueOffset = valueOffset(); - CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); - initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); - } - freeExtraAllocatedChunks(); - } - CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); - } - - public void putValueDeletedEntry(Value newValue) { - throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); - } - - private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { + 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(Value newValue, long newSizeOfEverythingBeforeValue) { + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { CompiledReplicatedMapIterationContext.this.dropChange(); _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); } - public void innerDefaultReplaceValue(Value newValue) { + public void innerDefaultReplaceValue(Data newValue) { assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); if (newValueSizeIsDifferent) { @@ -2450,13 +2360,168 @@ public class CompiledReplicatedMapIterationContext newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + try { + CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); + } finally { + CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); + } + } + + @Override + public void doReplaceValue(Data newValue) { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + try { + CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); + CompiledReplicatedMapIterationContext.this.updateChange(); + CompiledReplicatedMapIterationContext.this.initUpdatedReplicationStateOnPresentEntry(); + } finally { + CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); + } + } + + private void _MapEntryStages_putValueDeletedEntry(Data newValue) { + assert CompiledReplicatedMapIterationContext.this.innerUpdateLock.isHeldByCurrentThread(); + int newSizeInChunks; + long entryStartOffset = keySizeOffset(); + long newSizeOfEverythingBeforeValue = -1; + boolean newValueSizeIsDifferent = (newValue.size()) != (valueSize()); + if (newValueSizeIsDifferent) { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + long newValueOffset = CompiledReplicatedMapIterationContext.this.m().alignment.alignAddr((entryStartOffset + newSizeOfEverythingBeforeValue)); + long newEntrySize = (newValueOffset + (newValue.size())) - entryStartOffset; + newSizeInChunks = CompiledReplicatedMapIterationContext.this.m().inChunks(newEntrySize); + } else { + newSizeInChunks = entrySizeInChunks(); + } + if ((((pos()) + newSizeInChunks) < (CompiledReplicatedMapIterationContext.this.freeList().size())) && (CompiledReplicatedMapIterationContext.this.freeList().allClear(pos(), ((pos()) + newSizeInChunks)))) { + CompiledReplicatedMapIterationContext.this.freeList().set(pos(), ((pos()) + newSizeInChunks)); + CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + CompiledReplicatedMapIterationContext.this.incrementSegmentEntriesIfNeeded(); + if (newValueSizeIsDifferent) { + initValue(newValue); + } else { + writeValue(newValue); + } + } else { + if (newValueSizeIsDifferent) { + assert newSizeOfEverythingBeforeValue >= 0; + } else { + newSizeOfEverythingBeforeValue = newSizeOfEverythingBeforeValue(newValue); + } + long entrySize = innerEntrySize(newSizeOfEverythingBeforeValue, newValue.size()); + if (newValueSizeIsDifferent) { + CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueSizeOffset()) - entryStartOffset)); + initValue(newValue); + } else { + long oldValueSizeOffset = valueSizeOffset(); + long oldValueSize = valueSize(); + long oldValueOffset = valueOffset(); + CompiledReplicatedMapIterationContext.this.initEntryAndKeyCopying(entrySize, ((valueOffset()) - entryStartOffset)); + initValueWithoutSize(newValue, oldValueSizeOffset, oldValueSize, oldValueOffset); + } + freeExtraAllocatedChunks(); + } + CompiledReplicatedMapIterationContext.this.putValueVolatile(CompiledReplicatedMapIterationContext.this.hashLookupPos(), pos()); + } + + public void putValueDeletedEntry(Data newValue) { + throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); + } + + public void deleted(long deleted) { + segmentHeader().deleted(segmentHeaderAddress(), deleted); + } + + public long entries() { + return segmentHeader().size(segmentHeaderAddress()); + } + + public long size() { + return (entries()) - (deleted()); + } + + public boolean forEachRemoving(Predicate> action) { + CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); + try { + long size = CompiledReplicatedMapIterationContext.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); + } + CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); + do { + CompiledReplicatedMapIterationContext.this.setHashLookupPosGuarded(CompiledReplicatedMapIterationContext.this.step(CompiledReplicatedMapIterationContext.this.hashLookupPos())); + long entry = CompiledReplicatedMapIterationContext.this.readEntry(CompiledReplicatedMapIterationContext.this.hashLookupPos()); + if (!(CompiledReplicatedMapIterationContext.this.empty(entry))) { + CompiledReplicatedMapIterationContext.this.readExistingEntry(CompiledReplicatedMapIterationContext.this.value(entry)); + if (entryIsPresent()) { + initEntryRemovedOnThisIteration(false); + if (!(action.test(((MapEntry)(this))))) { + interrupted = true; + break; + } else { + if ((--size) == 0) + break; + + } + } + } + } while ((CompiledReplicatedMapIterationContext.this.hashLookupPos()) != startPos ); + return !interrupted; + } finally { + CompiledReplicatedMapIterationContext.this.innerReadLock.unlock(); + initEntryRemovedOnThisIteration(false); + } + } + + @Override + public void forEachReplicableEntry(Consumer action) { + CompiledReplicatedMapIterationContext.this.innerUpdateLock.lock(); + try { + long entries = CompiledReplicatedMapIterationContext.this.entries(); + if (entries == 0) + return ; + + long startPos = 0L; + while (!(CompiledReplicatedMapIterationContext.this.empty(CompiledReplicatedMapIterationContext.this.readEntry(startPos)))) { + startPos = CompiledReplicatedMapIterationContext.this.step(startPos); + } + CompiledReplicatedMapIterationContext.this.initHashLookupPos(startPos); + do { + CompiledReplicatedMapIterationContext.this.setHashLookupPosGuarded(CompiledReplicatedMapIterationContext.this.step(CompiledReplicatedMapIterationContext.this.hashLookupPos())); + long entry = CompiledReplicatedMapIterationContext.this.readEntry(CompiledReplicatedMapIterationContext.this.hashLookupPos()); + if (!(CompiledReplicatedMapIterationContext.this.empty(entry))) { + CompiledReplicatedMapIterationContext.this.readExistingEntry(CompiledReplicatedMapIterationContext.this.value(entry)); + action.accept(this); + if ((--entries) == 0) + break; + + } + } while ((CompiledReplicatedMapIterationContext.this.hashLookupPos()) != startPos ); + } finally { + CompiledReplicatedMapIterationContext.this.innerReadLock.unlock(); + } + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapIterationContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapIterationContext.this.entries(((CompiledReplicatedMapIterationContext.this.entries()) - 1L)); + CompiledReplicatedMapIterationContext.this.incrementModCountGuarded(); + } + private void _MapSegmentIteration_doRemove() { CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); initEntryRemovedOnThisIteration(true); @@ -2479,7 +2544,7 @@ public class CompiledReplicatedMapIterationContext (CompiledReplicatedMapIterationContext.this.dummyValue.size())) CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(CompiledReplicatedMapIterationContext.this.dummyValue); - CompiledReplicatedMapIterationContext.this.initUpdatedReplicationState(); + CompiledReplicatedMapIterationContext.this.initUpdatedReplicationStateOnPresentEntry(); CompiledReplicatedMapIterationContext.this.writeEntryDeleted(); CompiledReplicatedMapIterationContext.this.updateChange(); CompiledReplicatedMapIterationContext.this.deleted(((CompiledReplicatedMapIterationContext.this.deleted()) + 1)); @@ -2488,34 +2553,102 @@ public class CompiledReplicatedMapIterationContext newValue) { - CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); - try { - CompiledReplicatedMapIterationContext.this.innerDefaultReplaceValue(newValue); - } finally { - CompiledReplicatedMapIterationContext.this.innerWriteLock.unlock(); - } + 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; + this.closeReplicationUpdateDependants(); + } + + 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.closeReplicationUpdateDependants(); + this.innerRemoteIdentifier = ((byte)(0)); + } + + public void closeReplicationUpdateDependants() { + CompiledReplicatedMapIterationContext.this.closeUpdatedReplicationState(); } @Override - public void doReplaceValue(Value newValue) { - _MapSegmentIteration_doReplaceValue(newValue); + public byte remoteIdentifier() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return innerRemoteIdentifier(); } - boolean used; - - public boolean usedInit() { - return used; + @Override + public long remoteTimestamp() { + CompiledReplicatedMapIterationContext.this.checkOnEachPublicOperation(); + return innerRemoteTimestamp(); } - public void initUsed(boolean used) { - this.used = used; + private boolean updatedReplicationState = false; + + public boolean updatedReplicationStateInit() { + return (this.updatedReplicationState) != false; } - void closeUsed() { - if (!(this.usedInit())) + public void initUpdatedReplicationStateOnAbsentEntry() { + CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + if (CompiledReplicatedMapIterationContext.this.replicationUpdateInit()) { + updateReplicationState(CompiledReplicatedMapIterationContext.this.innerRemoteTimestamp(), CompiledReplicatedMapIterationContext.this.innerRemoteIdentifier()); + } else { + updateReplicationState(CompiledReplicatedMapIterationContext.this.m().timeProvider.currentTime(), CompiledReplicatedMapIterationContext.this.m().identifier()); + } + updatedReplicationState = true; + } + + public void initUpdatedReplicationStateOnPresentEntry() { + CompiledReplicatedMapIterationContext.this.innerWriteLock.lock(); + if (CompiledReplicatedMapIterationContext.this.replicationUpdateInit()) { + updateReplicationState(CompiledReplicatedMapIterationContext.this.innerRemoteTimestamp(), CompiledReplicatedMapIterationContext.this.innerRemoteIdentifier()); + } else { + 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()); + } + updatedReplicationState = true; + } + + public void closeUpdatedReplicationState() { + if (!(this.updatedReplicationStateInit())) return ; - used = false; + this.updatedReplicationState = false; + } + + private boolean testTimeStampInSensibleRange() { + if ((CompiledReplicatedMapIterationContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (CompiledReplicatedMapIterationContext.this.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (CompiledReplicatedMapIterationContext.this.innerRemoteTimestamp()); + } + return true; } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java index 02b722fb5..fee22dcb1 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java +++ b/src/main/java/net/openhft/chronicle/map/impl/CompiledReplicatedMapQueryContext.java @@ -5,13 +5,12 @@ 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.AbstractValue; -import net.openhft.chronicle.hash.AcceptanceDecision; -import net.openhft.chronicle.hash.HashEntry; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.*; +import net.openhft.chronicle.hash.AbstractData; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.impl.*; import net.openhft.chronicle.hash.impl.hashlookup.EntryConsumer; -import net.openhft.chronicle.hash.impl.value.instance.KeyInitableValue; +import net.openhft.chronicle.hash.impl.value.instance.KeyInitableData; import net.openhft.chronicle.hash.locks.InterProcessLock; import net.openhft.chronicle.hash.locks.InterProcessReadWriteUpdateLock; import net.openhft.chronicle.hash.replication.RemoteOperationContext; @@ -23,7 +22,7 @@ import net.openhft.chronicle.map.TcpReplicator.TcpSocketChannelEntryWriter; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import net.openhft.chronicle.map.impl.ret.UsableReturnValue; import net.openhft.chronicle.map.impl.stage.query.MapAbsentEntryHolder; -import net.openhft.chronicle.map.impl.value.instance.ValueInitableValue; +import net.openhft.chronicle.map.impl.value.instance.ValueInitableData; import net.openhft.chronicle.map.replication.MapRemoteQueryContext; import net.openhft.chronicle.map.replication.MapReplicableEntry; import net.openhft.lang.Maths; @@ -47,25 +46,29 @@ import java.util.concurrent.TimeUnit; public class CompiledReplicatedMapQueryContext, V, VI, MVI extends MetaBytesInterop, R, T> implements AutoCloseable , HashEntry , InterProcessReadWriteUpdateLock , RemoteOperationContext , ExternalMapQueryContext , MapAbsentEntry , MapContext , MapEntry , QueryContextInterface , ReplicatedChronicleMapHolder , MapAbsentEntryHolder , MapRemoteQueryContext , MapReplicableEntry { public void close() { - CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); - CompiledReplicatedMapQueryContext.this.closeReplicationInput(); - CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); + CompiledReplicatedMapQueryContext.this.closeInputKey(); CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.defaultReturnValue.closeDefaultReturnedValue(); + CompiledReplicatedMapQueryContext.this.closeAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.closeReplicationUpdate(); + CompiledReplicatedMapQueryContext.this.closeKeyOffset(); + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); + CompiledReplicatedMapQueryContext.this.closePos(); + CompiledReplicatedMapQueryContext.this.closeReplicatedInputBytes(); + CompiledReplicatedMapQueryContext.this.closeKeySize(); + CompiledReplicatedMapQueryContext.this.closeReplicationInput(); + CompiledReplicatedMapQueryContext.this.bytesReturnValue.closeOutput(); + CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeNext(); CompiledReplicatedMapQueryContext.this.closeUsed(); - CompiledReplicatedMapQueryContext.this.closeInputKey(); - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); - CompiledReplicatedMapQueryContext.this.bytesReturnValue.closeOutput(); - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeValue(); CompiledReplicatedMapQueryContext.this.closeInputBytes(); - CompiledReplicatedMapQueryContext.this.usingReturnValue.closeUsingReturnValue(); + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeKey(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); + CompiledReplicatedMapQueryContext.this.innerWriteLock.closeWriteLockForbiddenUpgradeDependants(); CompiledReplicatedMapQueryContext.this.closeValueBytesInteropValueMetaInteropDependants(); CompiledReplicatedMapQueryContext.this.closeKeyBytesInteropKeyMetaInteropDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants(); CompiledReplicatedMapQueryContext.this.closeOwnerThreadHolderCheckAccessingFromOwnerThreadDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants(); } public void incrementModCountGuarded() { @@ -96,18 +99,6 @@ public class CompiledReplicatedMapQueryContext value) { - if (!(this.valueInit())) - this.initValue(); - - writeValue(value); - } - - void initKeySizeOffset(long pos) { - keySizeOffset = (CompiledReplicatedMapQueryContext.this.entrySpaceOffset()) + (pos * (CompiledReplicatedMapQueryContext.this.h().chunkSize)); - entryBytes.limit(entryBytes.capacity()); - } - void keyFound() { searchState = SearchState.PRESENT; } @@ -117,36 +108,36 @@ public class CompiledReplicatedMapQueryContext)(entryBytesAccessor.access(entryBytes))); - this.bytesReturnValue = new BytesReturnValue(); - this.innerWriteLock = new WriteLock(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.inputValueInstanceValue = new InputValueInstanceData(); + this.innerReadLock = new ReadLock(); + this.innerUpdateLock = new UpdateLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); this.usingReturnValue = new UsingReturnValue(); - this.defaultReturnValue = new DefaultReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryKey = new EntryKeyBytesValue(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesData(); + this.dummyValue = new DummyValueZeroData(); + this.innerWriteLock = new WriteLock(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.bytesReturnValue = new BytesReturnValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); - this.dummyValue = new DummyValueZeroValue(); } public CompiledReplicatedMapQueryContext(CompiledReplicatedMapQueryContext c) { @@ -154,108 +145,309 @@ public class CompiledReplicatedMapQueryContext)(c.m)); - this.innerUpdateLock = new UpdateLock(); + this.entryKey = new EntryKeyBytesData(); + this.entryValue = new EntryValueBytesData(); + this.defaultReturnValue = new DefaultReturnValue(); this.deprecatedMapKeyContext = new DeprecatedMapKeyContextOnQuery(); - this.inputValueInstanceValue = new InputValueInstanceValue(); - this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); - this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); - this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); - this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); - this.bytesReturnValue = new BytesReturnValue(); - this.innerWriteLock = new WriteLock(); - this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesValue(); - this.inputFirstValueBytesValue = new InputFirstValueBytesValue(); + this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); + this.wrappedValueInstanceValue = new WrappedValueInstanceData(); + this.inputKeyInstanceValue = new InputKeyInstanceData(); + this.inputValueInstanceValue = new InputValueInstanceData(); + this.innerReadLock = new ReadLock(); + this.innerUpdateLock = new UpdateLock(); this.copies = ThreadLocalCopies.get(); this.valueInterop = CompiledReplicatedMapQueryContext.this.m().valueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueInterop); this.valueReader = CompiledReplicatedMapQueryContext.this.m().valueReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalValueReader); this.keyInterop = CompiledReplicatedMapQueryContext.this.h().keyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyInterop); this.keyReader = CompiledReplicatedMapQueryContext.this.h().keyReaderProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalKeyReader); - this.absentDelegating = new ReplicatedMapAbsentDelegating(); - this.inputKeyInstanceValue = new InputKeyInstanceValue(); + this.replicatedInputKeyBytesValue = new ReplicatedInputKeyBytesData(); + this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesData(); + this.inputFirstValueBytesValue = new InputFirstValueBytesData(); this.usingReturnValue = new UsingReturnValue(); - this.defaultReturnValue = new DefaultReturnValue(); - this.inputKeyBytesValue = new InputKeyBytesValue(); - this.inputSecondValueBytesValue = new InputSecondValueBytesValue(); - this.innerReadLock = new ReadLock(); - this.deprecatedMapAcquireContext = new DeprecatedMapAcquireContextOnQuery(); - this.entryKey = new EntryKeyBytesValue(); - this.replicatedInputValueBytesValue = new ReplicatedInputValueBytesValue(); - this.wrappedValueInstanceValue = new WrappedValueInstanceValue(); + this.inputKeyBytesValue = new InputKeyBytesData(); + this.dummyValue = new DummyValueZeroData(); + this.innerWriteLock = new WriteLock(); + this.inputSecondValueBytesValue = new InputSecondValueBytesData(); + this.absentDelegating = new ReplicatedMapAbsentDelegating(); + this.bytesReturnValue = new BytesReturnValue(); + this.entryBytes = CompiledReplicatedMapQueryContext.this.h().ms.bytes(); + this.entryBytesAccessor = JavaLangBytesAccessors.uncheckedBytesAccessor(entryBytes); + this.entryBytesAccessHandle = ((T)(entryBytesAccessor.handle(entryBytes))); + this.entryBytesAccess = ((Access)(entryBytesAccessor.access(entryBytes))); this.owner = Thread.currentThread(); - this.entryValue = new EntryValueBytesValue(); - this.dummyValue = new DummyValueZeroValue(); } - public class InputKeyBytesValue extends AbstractValue { + public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { + @NotNull @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + public InterProcessLock writeLock() { + return CompiledReplicatedMapQueryContext.this.writeLock(); + } + + @NotNull + @Override + public InterProcessLock readLock() { + return CompiledReplicatedMapQueryContext.this.readLock(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + return CompiledReplicatedMapQueryContext.this.updateLock(); + } + + @Override + public long valueSize() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueSize(); + } + + @Override + public boolean valueEqualTo(V value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledReplicatedMapQueryContext.this.entryValue, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(value)); + } + + @Override + public long keyOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.keyOffset(); + } + + @NotNull + @Override + public Bytes entry() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytes; + } + + @Override + public long valueOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueOffset(); + } + + @Override + public long keySize() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.keySize(); + } + + @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(); + return (CompiledReplicatedMapQueryContext.this.entry()) != null; + } + + @Override + public V getUsing(V usingValue) { + return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; + } + + @Override + public V get() { + assert containsKey(); + return CompiledReplicatedMapQueryContext.this.usingReturnValue.returnValue(); + } + + @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(); + put(CompiledReplicatedMapQueryContext.this.usingReturnValue.returnValue()); + CompiledReplicatedMapQueryContext.this.close(); + } + + @NotNull + @Override + public K key() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.queriedKey().get(); + } + } + + public class DeprecatedMapKeyContextOnQuery implements MapKeyContext { + @NotNull + @Override + public InterProcessLock writeLock() { + return CompiledReplicatedMapQueryContext.this.writeLock(); + } + + @NotNull + @Override + public InterProcessLock updateLock() { + return CompiledReplicatedMapQueryContext.this.updateLock(); + } + + @NotNull + @Override + public InterProcessLock readLock() { + return CompiledReplicatedMapQueryContext.this.readLock(); + } + + @Override + public long keySize() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.keySize(); + } + + @Override + public boolean valueEqualTo(V value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return Data.bytesEquivalent(CompiledReplicatedMapQueryContext.this.entryValue, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(value)); + } + + @Override + public long valueOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueOffset(); + } + + @Override + public void close() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + CompiledReplicatedMapQueryContext.this.close(); + } + + @Override + public long keyOffset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.keyOffset(); + } + + @NotNull + @Override + public Bytes entry() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytes; + } + + @Override + public long valueSize() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.valueSize(); + } + + @Override + public boolean containsKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return (CompiledReplicatedMapQueryContext.this.entry()) != null; + } + + @Override + public V getUsing(V usingValue) { + return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; + } + + @Override + public V get() { + return containsKey() ? CompiledReplicatedMapQueryContext.this.value().get() : null; + } + + @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 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; + } + + @NotNull + @Override + public K key() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.queriedKey().get(); + } + } + + public class DummyValueZeroData extends AbstractData { + @Override + public long offset() { + return 0; + } + + @Override + public Void handle() { + return null; + } + + @Override + public V getUsing(V usingInstance) { + throw new UnsupportedOperationException(); + } + + @Override + public V get() { + throw new UnsupportedOperationException(); } @Override public long size() { - return CompiledReplicatedMapQueryContext.this.inputKeySize(); - } - - public void closeInputKeyBytesValueSizeDependants() { - InputKeyBytesValue.this.closeInputKeyBytesValueGetUsingDependants(); + return CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.minEncodableSize(); } @Override - public K getUsing(K usingKey) { - Bytes inputBytes = CompiledReplicatedMapQueryContext.this.inputBytes(); - inputBytes.position(CompiledReplicatedMapQueryContext.this.inputKeyOffset()); - return CompiledReplicatedMapQueryContext.this.keyReader.read(inputBytes, size(), usingKey); - } - - public void closeInputKeyBytesValueGetUsingDependants() { - InputKeyBytesValue.this.closeCachedBytesInputKey(); - } - - private K cachedBytesInputKey; - - private boolean cachedBytesInputKeyRead = false; - - public boolean cachedBytesInputKeyInit() { - return (this.cachedBytesInputKeyRead) != false; - } - - private void initCachedBytesInputKey() { - cachedBytesInputKey = getUsing(cachedBytesInputKey); - cachedBytesInputKeyRead = true; - } - - public K cachedBytesInputKey() { - if (!(this.cachedBytesInputKeyInit())) - this.initCachedBytesInputKey(); - - return this.cachedBytesInputKey; - } - - public void closeCachedBytesInputKey() { - if (!(this.cachedBytesInputKeyInit())) - return ; - - this.cachedBytesInputKeyRead = false; - } - - @Override - public K get() { - return cachedBytesInputKey(); + public ReadAccess access() { + return ReadAccess.zeros(); } + } + public class EntryKeyBytesData extends AbstractData { @Override public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; } @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.inputKeyOffset()); + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()); } - } - public class EntryKeyBytesValue extends AbstractValue { @Override public ReadAccess access() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -268,8 +460,8 @@ public class CompiledReplicatedMapQueryContext { - @NotNull - @Override - public Value defaultValue() { - return CompiledReplicatedMapQueryContext.this.defaultValue(); - } - - @NotNull - @Override - public MapContext context() { - return CompiledReplicatedMapQueryContext.this.context(); - } - - @NotNull - @Override - public Value absentKey() { - return CompiledReplicatedMapQueryContext.this.absentKey(); - } - - @Override - public void doInsert(Value value) { - CompiledReplicatedMapQueryContext.this.doInsert(value); - } - } - - public class EntryValueBytesValue extends AbstractValue { - @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 size() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); return CompiledReplicatedMapQueryContext.this.valueSize(); } - public void closeEntryValueBytesValueSizeDependants() { - EntryValueBytesValue.this.closeEntryValueBytesValueInnerGetUsingDependants(); - } - - @Override - public long offset() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.valueOffset()); + public void closeEntryValueBytesDataSizeDependants() { + EntryValueBytesData.this.closeEntryValueBytesDataInnerGetUsingDependants(); } private V innerGetUsing(V usingValue) { @@ -669,8 +529,8 @@ public class CompiledReplicatedMapQueryContext access() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccess; + } + + @Override + public long offset() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.valueOffset()); + } + + @Override + public T handle() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle; + } } - public class InputFirstValueBytesValue extends AbstractValue { + public class InputFirstValueBytesData extends AbstractData { + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + + @Override + public long offset() { + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.firstInputValueOffset()); + } + @Override public long size() { return CompiledReplicatedMapQueryContext.this.firstInputValueSize(); } - public void closeInputFirstValueBytesValueSizeDependants() { - InputFirstValueBytesValue.this.closeInputFirstValueBytesValueGetUsingDependants(); + public void closeInputFirstValueBytesDataSizeDependants() { + InputFirstValueBytesData.this.closeInputFirstValueBytesDataGetUsingDependants(); } @Override @@ -729,8 +622,8 @@ public class CompiledReplicatedMapQueryContext { @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + public long size() { + return CompiledReplicatedMapQueryContext.this.inputKeySize(); + } + + public void closeInputKeyBytesDataSizeDependants() { + InputKeyBytesData.this.closeInputKeyBytesDataGetUsingDependants(); } @Override public long offset() { - return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.firstInputValueOffset()); + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).offset(CompiledReplicatedMapQueryContext.this.inputBytes(), CompiledReplicatedMapQueryContext.this.inputKeyOffset()); } @Override public T handle() { return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); } - } - public class InputSecondValueBytesValue extends AbstractValue { @Override - public T handle() { - return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + public K getUsing(K usingKey) { + Bytes inputBytes = CompiledReplicatedMapQueryContext.this.inputBytes(); + inputBytes.position(CompiledReplicatedMapQueryContext.this.inputKeyOffset()); + return CompiledReplicatedMapQueryContext.this.keyReader.read(inputBytes, size(), usingKey); + } + + public void closeInputKeyBytesDataGetUsingDependants() { + InputKeyBytesData.this.closeCachedBytesInputKey(); + } + + private K cachedBytesInputKey; + + private boolean cachedBytesInputKeyRead = false; + + public boolean cachedBytesInputKeyInit() { + return (this.cachedBytesInputKeyRead) != false; + } + + private void initCachedBytesInputKey() { + cachedBytesInputKey = getUsing(cachedBytesInputKey); + cachedBytesInputKeyRead = true; + } + + public K cachedBytesInputKey() { + if (!(this.cachedBytesInputKeyInit())) + this.initCachedBytesInputKey(); + + return this.cachedBytesInputKey; + } + + public void closeCachedBytesInputKey() { + if (!(this.cachedBytesInputKeyInit())) + return ; + + this.cachedBytesInputKeyRead = false; + } + + @Override + public K get() { + return cachedBytesInputKey(); } @Override public ReadAccess access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); } + } + + public class InputSecondValueBytesData extends AbstractData { + @Override + public ReadAccess access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).access(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } + + @Override + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.inputBytes()).handle(CompiledReplicatedMapQueryContext.this.inputBytes()))); + } @Override public long offset() { @@ -802,8 +749,8 @@ public class CompiledReplicatedMapQueryContext { - public WrappedValueInstanceValue getUnusedWrappedValueGuarded() { - assert this.nextInit() : "Next should be init"; - return getUnusedWrappedValue(); + public class ReadLock implements InterProcessLock { + @Override + public void lock() { + if ((CompiledReplicatedMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledReplicatedMapQueryContext.this.segmentHeader().readLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + } } - public WrappedValueInstanceValue getUnusedWrappedValue() { - if (!(valueInit())) - return this; - - if ((next) == null) - next = new WrappedValueInstanceValue(); - - return next.getUnusedWrappedValue(); - } - - private V value; - - public boolean valueInit() { - return (value) != null; - } - - public void initValue(V value) { - CompiledReplicatedMapQueryContext.this.m().checkValue(value); - this.value = value; - this.closeValueDependants(); - } - - public V value() { - assert this.valueInit() : "Value should be init"; - return this.value; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - value = null; - if ((next) != null) - next.closeValue(); - - } - - public void closeValueDependants() { - WrappedValueInstanceValue.this.closeBuffer(); - } - - private boolean marshalled = false; - - private DirectBytes buf; - - public boolean bufferInit() { - return (this.marshalled) != false; - } - - private void initBuffer() { - MVI mvi = CompiledReplicatedMapQueryContext.this.valueMetaInterop(value()); - long size = mvi.size(CompiledReplicatedMapQueryContext.this.valueInterop, value()); - buf = CopyingInstanceValue.getBuffer(this.buf, size); - mvi.write(CompiledReplicatedMapQueryContext.this.valueInterop, buf, value()); - buf.flip(); - marshalled = true; - } - - public DirectBytes buf() { - if (!(this.bufferInit())) - this.initBuffer(); - - return this.buf; - } - - public void closeBuffer() { - if (!(this.bufferInit())) - return ; - - this.marshalled = false; + public void closeReadLockLockDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); } @Override - public V getUsing(V usingValue) { - buf().position(0); - return CompiledReplicatedMapQueryContext.this.valueReader.read(buf(), buf().limit(), usingValue); + public boolean isHeldByCurrentThread() { + return CompiledReplicatedMapQueryContext.this.localLockState().read; } @Override - public DirectBytes buffer() { - return buf(); - } - - @Override - public V instance() { - return value(); - } - - private WrappedValueInstanceValue next; - - boolean nextInit() { - return true; - } - - void closeNext() { - if (!(this.nextInit())) - return ; - - } - } - - public class DeprecatedMapKeyContextOnQuery implements MapKeyContext { - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledReplicatedMapQueryContext.this.writeLock(); - } - - @NotNull - @Override - public InterProcessLock readLock() { - return CompiledReplicatedMapQueryContext.this.readLock(); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - return CompiledReplicatedMapQueryContext.this.updateLock(); - } - - @Override - public boolean valueEqualTo(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledReplicatedMapQueryContext.this.entryValue, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(value)); - } - - @Override - public long keySize() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.keySize(); - } - - @Override - public boolean remove() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); + public boolean tryLock() { + if ((CompiledReplicatedMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryReadLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress())) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { 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)); + public void unlock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + return ; + case READ_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().readUnlock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + break; + case UPDATE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().updateUnlock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + break; + case WRITE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().writeUnlock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); } - return true; + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UNLOCKED); + CompiledReplicatedMapQueryContext.this.closeHashLookupPos(); + CompiledReplicatedMapQueryContext.this.closePos(); } @Override - public boolean containsKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return (CompiledReplicatedMapQueryContext.this.entry()) != null; - } - - @Override - public V getUsing(V usingValue) { - return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; - } - - @Override - public V get() { - return containsKey() ? CompiledReplicatedMapQueryContext.this.value().get() : null; - } - - @NotNull - @Override - public Bytes entry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytes; - } - - @Override - public long keyOffset() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.keyOffset(); - } - - @Override - public void close() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - CompiledReplicatedMapQueryContext.this.close(); - } - - @NotNull - @Override - public K key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.queriedKey().get(); - } - - @Override - public long valueSize() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.valueSize(); - } - - @Override - public long valueOffset() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.valueOffset(); - } - } - - public class DeprecatedMapAcquireContextOnQuery implements MapKeyContext { - @NotNull - @Override - public InterProcessLock readLock() { - return CompiledReplicatedMapQueryContext.this.readLock(); - } - - @NotNull - @Override - public InterProcessLock updateLock() { - return CompiledReplicatedMapQueryContext.this.updateLock(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - return CompiledReplicatedMapQueryContext.this.writeLock(); - } - - @NotNull - @Override - public K key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.queriedKey().get(); - } - - @Override - public boolean remove() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - updateLock().lock(); - MapEntry entry = CompiledReplicatedMapQueryContext.this.entry(); - if (entry != null) { - CompiledReplicatedMapQueryContext.this.remove(entry); + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + if ((CompiledReplicatedMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryReadLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); + return true; + } else { + return false; + } + } else { return true; - } else { - return false; } } @Override - public boolean containsKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return (CompiledReplicatedMapQueryContext.this.entry()) != null; - } - - @Override - public V getUsing(V usingValue) { - return containsKey() ? CompiledReplicatedMapQueryContext.this.value().getUsing(usingValue) : null; - } - - @Override - public V get() { - assert containsKey(); - return CompiledReplicatedMapQueryContext.this.usingReturnValue.returnValue(); - } - - @Override - public long keySize() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.keySize(); - } - - @Override - public long keyOffset() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.keyOffset(); - } - - @NotNull - @Override - public Bytes entry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryBytes; - } - - @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)); + public void lockInterruptibly() throws InterruptedException { + if ((CompiledReplicatedMapQueryContext.this.localLockState()) == (LocalLockState.UNLOCKED)) { + CompiledReplicatedMapQueryContext.this.segmentHeader().readLockInterruptibly(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); } - return true; - } - - @Override - public void close() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - put(CompiledReplicatedMapQueryContext.this.usingReturnValue.returnValue()); - CompiledReplicatedMapQueryContext.this.close(); - } - - @Override - public boolean valueEqualTo(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return Value.bytesEquivalent(CompiledReplicatedMapQueryContext.this.entryValue, CompiledReplicatedMapQueryContext.this.wrapValueAsValue(value)); - } - - @Override - public long valueOffset() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.valueOffset(); - } - - @Override - public long valueSize() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.valueSize(); } } - public class ReplicatedInputKeyBytesValue extends AbstractValue { + public class ReplicatedInputKeyBytesData extends AbstractData { @Override public long size() { return CompiledReplicatedMapQueryContext.this.riKeySize(); } - public void closeReplicatedInputKeyBytesValueSizeDependants() { - ReplicatedInputKeyBytesValue.this.closeReplicatedInputKeyBytesValueGetUsingDependants(); + public void closeReplicatedInputKeyBytesDataSizeDependants() { + ReplicatedInputKeyBytesData.this.closeReplicatedInputKeyBytesDataGetUsingDependants(); } @Override @@ -1198,6 +886,11 @@ public class CompiledReplicatedMapQueryContext access() { return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } } - public class ReplicatedInputValueBytesValue extends AbstractValue { + public class ReplicatedInputValueBytesData extends AbstractData { @Override public long size() { return CompiledReplicatedMapQueryContext.this.riValueSize(); } - public void closeReplicatedInputValueBytesValueSizeDependants() { - ReplicatedInputValueBytesValue.this.closeReplicatedInputValueBytesValueGetUsingDependants(); + public void closeReplicatedInputValueBytesDataSizeDependants() { + ReplicatedInputValueBytesData.this.closeReplicatedInputValueBytesDataGetUsingDependants(); } @Override - public ReadAccess access() { - return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + public T handle() { + return ((T)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).handle(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); + } + + @Override + public long offset() { + return JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).offset(CompiledReplicatedMapQueryContext.this.replicatedInputBytes(), CompiledReplicatedMapQueryContext.this.riValueOffset()); } @Override @@ -1274,8 +967,8 @@ public class CompiledReplicatedMapQueryContext access() { + return ((ReadAccess)(JavaLangBytesAccessors.uncheckedBytesAccessor(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()).access(CompiledReplicatedMapQueryContext.this.replicatedInputBytes()))); } } - public class DummyValueZeroValue extends AbstractValue { + public class ReplicatedMapAbsentDelegating implements MapAbsentEntry { + @NotNull @Override - public V getUsing(V usingInstance) { - throw new UnsupportedOperationException(); + public MapContext context() { + return CompiledReplicatedMapQueryContext.this.context(); + } + + @NotNull + @Override + public Data defaultValue() { + return CompiledReplicatedMapQueryContext.this.defaultValue(); + } + + @NotNull + @Override + public Data absentKey() { + return CompiledReplicatedMapQueryContext.this.absentKey(); } @Override - public long offset() { - return 0; + public void doInsert(Data value) { + CompiledReplicatedMapQueryContext.this.doInsert(value); + } + } + + public class UpdateLock implements InterProcessLock { + @NotNull + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to update lock"); } @Override - public long size() { - return CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.minEncodableSize(); + public boolean isHeldByCurrentThread() { + return CompiledReplicatedMapQueryContext.this.localLockState().update; } @Override - public V get() { - throw new UnsupportedOperationException(); + public void unlock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + return ; + case UPDATE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().downgradeUpdateToReadLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + break; + case WRITE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().downgradeWriteToReadLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + } + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.READ_LOCKED); } @Override - public ReadAccess access() { - return ReadAccess.zeros(); + public void lock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().updateLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + } } @Override - public Void handle() { - return null; + public void lockInterruptibly() throws InterruptedException { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().updateLockInterruptibly(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + } + } + + @Override + public boolean tryLock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryUpdateLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress())) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryUpdateLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + } + + public class WrappedValueInstanceData extends CopyingInstanceData { + public WrappedValueInstanceData getUnusedWrappedValueGuarded() { + assert this.nextInit() : "Next should be init"; + return getUnusedWrappedValue(); + } + + public WrappedValueInstanceData getUnusedWrappedValue() { + if (!(valueInit())) + return this; + + if ((next) == null) + next = new WrappedValueInstanceData(); + + return next.getUnusedWrappedValue(); + } + + private WrappedValueInstanceData next; + + boolean nextInit() { + return true; + } + + void closeNext() { + if (!(this.nextInit())) + return ; + + } + + private V value; + + public boolean valueInit() { + return (value) != null; + } + + public void initValue(V value) { + CompiledReplicatedMapQueryContext.this.m().checkValue(value); + this.value = value; + this.closeValueDependants(); + } + + public V value() { + assert this.valueInit() : "Value should be init"; + return this.value; + } + + public void closeValue() { + if (!(this.valueInit())) + return ; + + this.closeValueDependants(); + value = null; + if ((next) != null) + next.closeValue(); + + } + + public void closeValueDependants() { + WrappedValueInstanceData.this.closeBuffer(); + } + + private boolean marshalled = false; + + private DirectBytes buf; + + public boolean bufferInit() { + return (this.marshalled) != false; + } + + private void initBuffer() { + MVI mvi = CompiledReplicatedMapQueryContext.this.valueMetaInterop(value()); + long size = mvi.size(CompiledReplicatedMapQueryContext.this.valueInterop, value()); + buf = CopyingInstanceData.getBuffer(this.buf, size); + mvi.write(CompiledReplicatedMapQueryContext.this.valueInterop, buf, value()); + buf.flip(); + marshalled = true; + } + + public DirectBytes buf() { + if (!(this.bufferInit())) + this.initBuffer(); + + return this.buf; + } + + public void closeBuffer() { + if (!(this.bufferInit())) + return ; + + this.marshalled = false; + } + + @Override + public V getUsing(V usingValue) { + buf().position(0); + return CompiledReplicatedMapQueryContext.this.valueReader.read(buf(), buf().limit(), usingValue); + } + + @Override + public DirectBytes buffer() { + return buf(); + } + + @Override + public V instance() { + return value(); + } + } + + public class WriteLock implements InterProcessLock { + @NotNull + private IllegalMonitorStateException forbiddenUpgrade() { + return new IllegalMonitorStateException("Cannot upgrade from read to write lock"); + } + + public void closeWriteLockForbiddenUpgradeDependants() { + WriteLock.this.closeWriteLockLockDependants(); + } + + @Override + public void lock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().writeLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().upgradeUpdateToWriteLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : + } + } + + public void closeWriteLockLockDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + @Override + public boolean tryLock(long time, @NotNull + TimeUnit unit) throws InterruptedException { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryWriteLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress(), time, unit)) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public boolean isHeldByCurrentThread() { + return CompiledReplicatedMapQueryContext.this.localLockState().write; + } + + @Override + public void lockInterruptibly() throws InterruptedException { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().writeLockInterruptibly(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return ; + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().upgradeUpdateToWriteLockInterruptibly(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + case WRITE_LOCKED : + } + } + + @Override + public boolean tryLock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryWriteLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress())) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case READ_LOCKED : + throw forbiddenUpgrade(); + case UPDATE_LOCKED : + if (CompiledReplicatedMapQueryContext.this.segmentHeader().tryUpgradeUpdateToWriteLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress())) { + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.WRITE_LOCKED); + return true; + } else { + return false; + } + case WRITE_LOCKED : + return true; + } + throw new AssertionError(); + } + + @Override + public void unlock() { + switch (CompiledReplicatedMapQueryContext.this.localLockState()) { + case UNLOCKED : + case READ_LOCKED : + case UPDATE_LOCKED : + return ; + case WRITE_LOCKED : + CompiledReplicatedMapQueryContext.this.segmentHeader().downgradeWriteToUpdateLock(CompiledReplicatedMapQueryContext.this.segmentHeaderAddress()); + } + CompiledReplicatedMapQueryContext.this.setLocalLockStateGuarded(LocalLockState.UPDATE_LOCKED); } } public enum SearchState { PRESENT, DELETED, ABSENT; } - private void _MapEntryStages_writeValue(Value value) { - value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset)); - } - public void incrementModCount() { contextModCount = rootContextOnThisSegment.latestSameThreadSegmentModCount = (rootContextOnThisSegment.latestSameThreadSegmentModCount) + 1; } @@ -1376,12 +1371,6 @@ public class CompiledReplicatedMapQueryContext value) { - _MapEntryStages_writeValue(value); - initUpdatedReplicationState(); - CompiledReplicatedMapQueryContext.this.updateChange(); - } - final Thread owner; public Thread owner() { @@ -1461,15 +1450,6 @@ public class CompiledReplicatedMapQueryContext value) { - entryBytes.position(valueSizeOffset); - valueSize = value.size(); - CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); - CompiledReplicatedMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - writeValue(value); - } - private void unlinkFromSegmentContextsChain() { CompiledReplicatedMapQueryContext prevContext = this.rootContextOnThisSegment; while (true) { @@ -1489,152 +1469,6 @@ public class CompiledReplicatedMapQueryContext implements KeyInitableValue { - private K key = null; - - public boolean keyInit() { - return (this.key) != null; - } - - @Override - public void initKey(K key) { - this.key = key; - this.closeKeyDependants(); - } - - public K key() { - assert this.keyInit() : "Key should be init"; - return this.key; - } - - public void closeKey() { - if (!(this.keyInit())) - return ; - - this.closeKeyDependants(); - this.key = null; - } - - public void closeKeyDependants() { - InputKeyInstanceValue.this.closeBuffer(); - } - - private boolean marshalled = false; - - private DirectBytes buffer; - - public boolean bufferInit() { - return (this.marshalled) != false; - } - - private void initBuffer() { - MKI mki = CompiledReplicatedMapQueryContext.this.keyMetaInterop(key()); - long size = mki.size(CompiledReplicatedMapQueryContext.this.keyInterop, key()); - buffer = CopyingInstanceValue.getBuffer(this.buffer, size); - mki.write(CompiledReplicatedMapQueryContext.this.keyInterop, buffer, key()); - buffer.flip(); - marshalled = true; - } - - public DirectBytes buffer() { - if (!(this.bufferInit())) - this.initBuffer(); - - return this.buffer; - } - - public void closeBuffer() { - if (!(this.bufferInit())) - return ; - - this.marshalled = false; - } - - @Override - public K getUsing(K usingKey) { - buffer().position(0); - return CompiledReplicatedMapQueryContext.this.keyReader.read(buffer(), buffer().limit(), usingKey); - } - - @Override - public K instance() { - return key(); - } - } - - public class InputValueInstanceValue extends CopyingInstanceValue implements ValueInitableValue { - private V value = null; - - public boolean valueInit() { - return (this.value) != null; - } - - @Override - public void initValue(V value) { - this.value = value; - this.closeValueDependants(); - } - - public V value() { - assert this.valueInit() : "Value should be init"; - return this.value; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - this.value = null; - } - - public void closeValueDependants() { - InputValueInstanceValue.this.closeBuffer(); - } - - private boolean marshalled = false; - - private DirectBytes buffer; - - public boolean bufferInit() { - return (this.marshalled) != false; - } - - private void initBuffer() { - MVI mvi = CompiledReplicatedMapQueryContext.this.valueMetaInterop(value()); - long size = mvi.size(CompiledReplicatedMapQueryContext.this.valueInterop, value()); - buffer = CopyingInstanceValue.getBuffer(this.buffer, size); - mvi.write(CompiledReplicatedMapQueryContext.this.valueInterop, buffer, value()); - buffer.flip(); - marshalled = true; - } - - public DirectBytes buffer() { - if (!(this.bufferInit())) - this.initBuffer(); - - return this.buffer; - } - - public void closeBuffer() { - if (!(this.bufferInit())) - return ; - - this.marshalled = false; - } - - @Override - public V getUsing(V usingValue) { - buffer().position(0); - return CompiledReplicatedMapQueryContext.this.valueReader.read(buffer(), buffer().limit(), usingValue); - } - - @Override - public V instance() { - return value(); - } - } - public class BytesReturnValue implements AutoCloseable , ReturnValue { long startOutputPos; @@ -1666,17 +1500,9 @@ public class CompiledReplicatedMapQueryContext value) { + Data value) { long valueSize = value.size(); long totalSize = (1L + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize))) + valueSize; output().ensureBufferSize(totalSize); @@ -1688,12 +1514,20 @@ public class CompiledReplicatedMapQueryContext { @Override public void returnValue(@NotNull - Value value) { + Data value) { initDefaultReturnedValue(value); } @@ -1704,7 +1538,7 @@ public class CompiledReplicatedMapQueryContext value) { + Data value) { defaultReturnedValue = value.getUsing(null); } @@ -1730,10 +1564,156 @@ public class CompiledReplicatedMapQueryContext implements KeyInitableData { + private K key = null; + + public boolean keyInit() { + return (this.key) != null; + } + + @Override + public void initKey(K key) { + this.key = key; + this.closeKeyDependants(); + } + + public K key() { + assert this.keyInit() : "Key should be init"; + return this.key; + } + + public void closeKey() { + if (!(this.keyInit())) + return ; + + this.closeKeyDependants(); + this.key = null; + } + + public void closeKeyDependants() { + InputKeyInstanceData.this.closeBuffer(); + } + + @Override + public K instance() { + return key(); + } + + private boolean marshalled = false; + + private DirectBytes buffer; + + public boolean bufferInit() { + return (this.marshalled) != false; + } + + private void initBuffer() { + MKI mki = CompiledReplicatedMapQueryContext.this.keyMetaInterop(key()); + long size = mki.size(CompiledReplicatedMapQueryContext.this.keyInterop, key()); + buffer = CopyingInstanceData.getBuffer(this.buffer, size); + mki.write(CompiledReplicatedMapQueryContext.this.keyInterop, buffer, key()); + buffer.flip(); + marshalled = true; + } + + public DirectBytes buffer() { + if (!(this.bufferInit())) + this.initBuffer(); + + return this.buffer; + } + + public void closeBuffer() { + if (!(this.bufferInit())) + return ; + + this.marshalled = false; + } + + @Override + public K getUsing(K usingKey) { + buffer().position(0); + return CompiledReplicatedMapQueryContext.this.keyReader.read(buffer(), buffer().limit(), usingKey); + } + } + + public class InputValueInstanceData extends CopyingInstanceData implements ValueInitableData { + private V value = null; + + public boolean valueInit() { + return (this.value) != null; + } + + @Override + public void initValue(V value) { + this.value = value; + this.closeValueDependants(); + } + + public V value() { + assert this.valueInit() : "Value should be init"; + return this.value; + } + + public void closeValue() { + if (!(this.valueInit())) + return ; + + this.closeValueDependants(); + this.value = null; + } + + public void closeValueDependants() { + InputValueInstanceData.this.closeBuffer(); + } + + @Override + public V instance() { + return value(); + } + + private boolean marshalled = false; + + private DirectBytes buffer; + + public boolean bufferInit() { + return (this.marshalled) != false; + } + + private void initBuffer() { + MVI mvi = CompiledReplicatedMapQueryContext.this.valueMetaInterop(value()); + long size = mvi.size(CompiledReplicatedMapQueryContext.this.valueInterop, value()); + buffer = CopyingInstanceData.getBuffer(this.buffer, size); + mvi.write(CompiledReplicatedMapQueryContext.this.valueInterop, buffer, value()); + buffer.flip(); + marshalled = true; + } + + public DirectBytes buffer() { + if (!(this.bufferInit())) + this.initBuffer(); + + return this.buffer; + } + + public void closeBuffer() { + if (!(this.bufferInit())) + return ; + + this.marshalled = false; + } + + @Override + public V getUsing(V usingValue) { + buffer().position(0); + return CompiledReplicatedMapQueryContext.this.valueReader.read(buffer(), buffer().limit(), usingValue); + } + } + public class UsingReturnValue implements UsableReturnValue { @Override public void returnValue(@NotNull - Value value) { + Data value) { initReturnedValue(value); } @@ -1773,7 +1753,7 @@ public class CompiledReplicatedMapQueryContext value) { + Data value) { returnedValue = value.getUsing(usingReturnValue()); } @@ -1901,15 +1881,20 @@ public class CompiledReplicatedMapQueryContext m() { + return m; } - public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeEntry(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + @Override + public ChronicleMap map() { + return m(); } @Override @@ -2057,6 +2043,29 @@ public class CompiledReplicatedMapQueryContext m() { - return m; + public MKI keyMetaInterop(K key) { + return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); } - @Override - public ChronicleMap map() { - return m(); + public void closeKeyBytesInteropKeyMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); } - public long innerEntrySize(long sizeOfEverythingBeforeValue, long valueSize) { - if (CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry) { - return CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr((sizeOfEverythingBeforeValue + valueSize)); - } else if (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation) { - return (sizeOfEverythingBeforeValue + (CompiledReplicatedMapQueryContext.this.m().worstAlignment)) + valueSize; - } else { - return (CompiledReplicatedMapQueryContext.this.m().alignment.alignAddr(sizeOfEverythingBeforeValue)) + valueSize; - } + public MVI valueMetaInterop(V value) { + return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); + } + + public void closeValueBytesInteropValueMetaInteropDependants() { + CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); + CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + } + + public T contextAtIndexInChain(int index) { + return ((T)(contextChain.get(index))); + } + + public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { + CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); } private CompiledReplicatedMapQueryContext _Chaining_createChaining() { @@ -2108,42 +2122,12 @@ public class CompiledReplicatedMapQueryContextT contextAtIndexInChain(int index) { - return ((T)(contextChain.get(index))); + public long entryBytesAccessOffset(long offset) { + return entryBytesAccessor.offset(entryBytes, offset); } - public void closeReplicatedChronicleMapHolderImplContextAtIndexInChainDependants() { - CompiledReplicatedMapQueryContext.this.closeQuerySegmentStagesTryFindInitLocksOfThisSegmentDependants(); - } - - public MKI keyMetaInterop(K key) { - return CompiledReplicatedMapQueryContext.this.h().metaKeyInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.h().originalMetaKeyInterop, keyInterop, key); - } - - public void closeKeyBytesInteropKeyMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.inputKeyInstanceValue.closeBuffer(); - } - - private long _MapEntryStages_sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (((CompiledReplicatedMapQueryContext.this.m().metaDataBytes) + (CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.sizeEncodingSize(keySize))) + keySize) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(valueSize)); - } - - long sizeOfEverythingBeforeValue(long keySize, long valueSize) { - return (_MapEntryStages_sizeOfEverythingBeforeValue(keySize, valueSize)) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); - } - - public final long entrySize(long keySize, long valueSize) { - long sizeOfEverythingBeforeValue = sizeOfEverythingBeforeValue(keySize, valueSize); - return innerEntrySize(sizeOfEverythingBeforeValue, valueSize); - } - - public MVI valueMetaInterop(V value) { - return CompiledReplicatedMapQueryContext.this.m().metaValueInteropProvider.get(CompiledReplicatedMapQueryContext.this.copies, CompiledReplicatedMapQueryContext.this.m().originalMetaValueInterop, valueInterop, value); - } - - public void closeValueBytesInteropValueMetaInteropDependants() { - CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue.closeBuffer(); - CompiledReplicatedMapQueryContext.this.inputValueInstanceValue.closeBuffer(); + public void closeReplicatedMapEntryStagesEntryBytesAccessOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); } public Bytes inputBytes = null; @@ -2172,11 +2156,11 @@ public class CompiledReplicatedMapQueryContext inputKey = null; + 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 riKeySize = -1; + + public long riValueSize; + + public long riKeyOffset; + + public long riValueOffset; + + public long riTimestamp; + + public byte riId; + + public boolean isDeleted; + + public boolean replicationInputInit() { + return (this.riKeySize) >= 0; + } + + public void initReplicationInput(Bytes replicatedInputBytes) { + initReplicatedInputBytes(replicatedInputBytes); + riKeySize = CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.readSize(replicatedInputBytes); + riValueSize = CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.readSize(replicatedInputBytes); + riTimestamp = replicatedInputBytes.readStopBit(); + riId = replicatedInputBytes.readByte(); + CompiledReplicatedMapQueryContext.this.initReplicationUpdate(riTimestamp, riId); + isDeleted = replicatedInputBytes.readBoolean(); + riKeyOffset = replicatedInputBytes.position(); + riValueOffset = (riKeyOffset) + (riKeySize); + this.closeReplicationInputDependants(); + } + + public boolean isDeleted() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.isDeleted; + } + + public byte riId() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riId; + } + + public long riKeyOffset() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riKeyOffset; + } + + public long riKeySize() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riKeySize; + } + + public long riValueOffset() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riValueOffset; + } + + public long riValueSize() { + assert this.replicationInputInit() : "ReplicationInput should be init"; + return this.riValueSize; + } + + public void closeReplicationInput() { + if (!(this.replicationInputInit())) + return ; + + this.closeReplicationInputDependants(); + this.riKeySize = -1; + } + + public void closeReplicationInputDependants() { + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataGetUsingDependants(); + } + + public long keySize = -1; + + public boolean keySizeInit() { + return (this.keySize) >= 0; + } + + public void initKeySize(long keySize) { + this.keySize = keySize; + this.closeKeySizeDependants(); + } + + public long keySize() { + assert this.keySizeInit() : "KeySize should be init"; + return this.keySize; + } + + public void closeKeySize() { + if (!(this.keySizeInit())) + return ; + + this.closeKeySizeDependants(); + this.keySize = -1; + } + + public void closeKeySizeDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataSizeDependants(); + } + + public Bytes replicatedInputBytes = null; + + public boolean replicatedInputBytesInit() { + return (this.replicatedInputBytes) != null; + } + + public void initReplicatedInputBytes(Bytes replicatedInputBytes) { + this.replicatedInputBytes = replicatedInputBytes; + this.closeReplicatedInputBytesDependants(); + } + + public Bytes replicatedInputBytes() { + assert this.replicatedInputBytesInit() : "ReplicatedInputBytes should be init"; + return this.replicatedInputBytes; + } + + public void closeReplicatedInputBytes() { + if (!(this.replicatedInputBytesInit())) + return ; + + this.closeReplicatedInputBytesDependants(); + this.replicatedInputBytes = null; + } + + public void closeReplicatedInputBytesDependants() { + CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesDataGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesDataGetUsingDependants(); + } + + public long pos = -1; + + public boolean posInit() { + return (this.pos) >= 0; + } + + public void initPos(long pos) { + this.pos = pos; + this.closePosDependants(); + } + + public long pos() { + assert this.posInit() : "Pos should be init"; + return this.pos; + } + + public void closePos() { + if (!(this.posInit())) + return ; + + this.closePosDependants(); + this.pos = -1; + } + + public void closePosDependants() { + CompiledReplicatedMapQueryContext.this.closeEntryOffset(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); + } + + public long keyOffset = -1; + + public boolean keyOffsetInit() { + return (this.keyOffset) >= 0; + } + + public void initKeyOffset(long keyOffset) { + this.keyOffset = keyOffset; + this.closeKeyOffsetDependants(); + } + + public long keyOffset() { + assert this.keyOffsetInit() : "KeyOffset should be init"; + return this.keyOffset; + } + + public void closeKeyOffset() { + if (!(this.keyOffsetInit())) + return ; + + this.closeKeyOffsetDependants(); + this.keyOffset = -1; + } + + public void closeKeyOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); + CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesDataInnerGetUsingDependants(); + } + + public long keyEnd() { + return (keyOffset()) + (keySize()); + } + + public void closeReplicatedMapEntryStagesKeyEndDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicationState(); + } + + private long _MapEntryStages_countValueSizeOffset() { + return keyEnd(); + } + + long countValueSizeOffset() { + return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + } + + public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeValueSizeOffset(); + } + + public long valueSizeOffset = -1; + + public boolean valueSizeOffsetInit() { + return (this.valueSizeOffset) >= 0; + } + + void initValueSizeOffset() { + valueSizeOffset = countValueSizeOffset(); + this.closeValueSizeOffsetDependants(); + } + + public long valueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + this.initValueSizeOffset(); + + return this.valueSizeOffset; + } + + public void closeValueSizeOffset() { + if (!(this.valueSizeOffsetInit())) + return ; + + this.closeValueSizeOffsetDependants(); + this.valueSizeOffset = -1; + } + + public void closeValueSizeOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeValSize(); + } + + public long valueSize = -1; + + public long valueOffset; + + public boolean valSizeInit() { + return (this.valueSize) >= 0; + } + + void initValSize() { + entryBytes.position(valueSizeOffset()); + valueSize = CompiledReplicatedMapQueryContext.this.m().readValueSize(entryBytes); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSize(long valueSize) { + this.valueSize = valueSize; + entryBytes.position(valueSizeOffset()); + CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.writeSize(entryBytes, valueSize); + countValueOffset(); + this.closeValSizeDependants(); + } + + void initValSizeEqualToOld(long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + valueSize = oldValueSize; + valueOffset = (valueSizeOffset()) + (oldValueOffset - oldValueSizeOffset); + this.closeValSizeDependants(); + } + + public long valueOffset() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueOffset; + } + + public long valueSize() { + if (!(this.valSizeInit())) + this.initValSize(); + + return this.valueSize; + } + + public void closeValSize() { + if (!(this.valSizeInit())) + return ; + + this.closeValSizeDependants(); + this.valueSize = -1; + } + + public void closeValSizeDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); + CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataSizeDependants(); + CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesDataInnerGetUsingDependants(); + } + + private long _HashEntryStages_entryEnd() { + return keyEnd(); + } + + protected long entryEnd() { + return (valueOffset()) + (valueSize()); + } + + public void closeReplicatedMapEntryStagesEntryEndDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); + } + + public void writeValue(Data value) { + value.writeTo(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(valueOffset())); + } + + public void initValue(Data value) { + entryBytes.position(valueSizeOffset()); + initValSize(value.size()); + writeValue(value); + } + + public void initValueWithoutSize(Data value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { + assert oldValueSize == (value.size()); + initValSizeEqualToOld(oldValueSizeOffset, oldValueSize, oldValueOffset); + writeValue(value); + } + + long replicationBytesOffset = -1; + + public boolean replicationStateInit() { + return (this.replicationBytesOffset) >= 0; + } + + void initReplicationState() { + replicationBytesOffset = keyEnd(); + this.closeReplicationStateDependants(); + } + + public long replicationBytesOffset() { + if (!(this.replicationStateInit())) + this.initReplicationState(); + + return this.replicationBytesOffset; + } + + public void closeReplicationState() { + if (!(this.replicationStateInit())) + return ; + + this.closeReplicationStateDependants(); + this.replicationBytesOffset = -1; + } + + public void closeReplicationStateDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesTimestampOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesIdentifierOffsetDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesUpdateReplicationStateDependants(); + } + + private long timestampOffset() { + return replicationBytesOffset(); + } + + public void closeReplicatedMapEntryStagesTimestampOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesTimestampDependants(); + } + + public long timestamp() { + return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + } + + public void closeReplicatedMapEntryStagesTimestampDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + private long identifierOffset() { + return (replicationBytesOffset()) + 8L; + } + + public void closeReplicatedMapEntryStagesIdentifierOffsetDependants() { + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesIdentifierDependants(); + } + + byte identifier() { + return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); + } + + public void closeReplicatedMapEntryStagesIdentifierDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + void updateReplicationState(long timestamp, byte identifier) { + entryBytes.position(replicationBytesOffset()); + entryBytes.writeLong(timestamp); + entryBytes.writeByte(identifier); + } + + public void closeReplicatedMapEntryStagesUpdateReplicationStateDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + private long entryDeletedOffset() { + return (replicationBytesOffset()) + 9L; + } + + public void writeEntryPresent() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); + } + + public void writeEntryDeleted() { + entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); + } + + public boolean entryDeleted() { + return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); + } + + public long innerRemoteTimestamp; + + public byte innerRemoteIdentifier = ((byte)(0)); + + 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; + this.closeReplicationUpdateDependants(); + } + + 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.closeReplicationUpdateDependants(); + this.innerRemoteIdentifier = ((byte)(0)); + } + + public void closeReplicationUpdateDependants() { + CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); + } + + private boolean testTimeStampInSensibleRange() { + if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { + long currentTime = TimeProvider.SYSTEM.currentTime(); + assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); + assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp())))) <= 100000000 : "unrealistic innerRemoteTimestamp: " + (CompiledReplicatedMapQueryContext.this.innerRemoteTimestamp()); + } + return true; + } + + public int allocatedChunks = 0; + + public boolean allocatedChunksInit() { + return (this.allocatedChunks) != 0; + } + + public void initAllocatedChunks(int allocatedChunks) { + this.allocatedChunks = allocatedChunks; + } + + public int allocatedChunks() { + assert this.allocatedChunksInit() : "AllocatedChunks should be init"; + return this.allocatedChunks; + } + + public void closeAllocatedChunks() { + if (!(this.allocatedChunksInit())) + return ; + + this.allocatedChunks = 0; + } + + public Data inputKey = null; public boolean inputKeyInit() { return (this.inputKey) != null; } - public void initInputKey(Value inputKey) { + public void initInputKey(Data inputKey) { this.inputKey = inputKey; this.closeInputKeyDependants(); } - public Value inputKey() { + public Data inputKey() { assert this.inputKeyInit() : "InputKey should be init"; return this.inputKey; } @@ -2399,10 +2891,8 @@ public class CompiledReplicatedMapQueryContext= 0; + public boolean entryOffsetInit() { + return (this.keySizeOffset) >= 0; } - public void initEntry(long pos) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes); - keyOffset = entryBytes.position(); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntry(long pos, Value key) { - initKeySizeOffset(pos); - entryBytes.position(keySizeOffset); - keySize = key.size(); - CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize); - keyOffset = entryBytes.position(); - key.writeTo(entryBytesAccessor, entryBytes, keyOffset); - this.pos = pos; - this.closeEntryDependants(); - } - - public void initEntryCopying(long newPos, long bytesToCopy) { - long oldKeySizeOffset = keySizeOffset; - initKeySizeOffset(newPos); - long oldKeyOffset = keyOffset; - keyOffset = (keySizeOffset) + (oldKeyOffset - oldKeySizeOffset); - Access.copy(entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(oldKeySizeOffset), entryBytesAccess, entryBytesAccessHandle, entryBytesAccessOffset(keySizeOffset), bytesToCopy); - pos = newPos; - this.closeEntryDependants(); - } - - public long keyOffset() { - assert this.entryInit() : "Entry should be init"; - return this.keyOffset; - } - - public long keySize() { - assert this.entryInit() : "Entry should be init"; - return this.keySize; + public void initEntryOffset() { + keySizeOffset = (CompiledReplicatedMapQueryContext.this.entrySpaceOffset()) + ((pos()) * (CompiledReplicatedMapQueryContext.this.h().chunkSize)); + entryBytes.limit(entryBytes.capacity()); + this.closeEntryOffsetDependants(); } public long keySizeOffset() { - assert this.entryInit() : "Entry should be init"; + if (!(this.entryOffsetInit())) + this.initEntryOffset(); + return this.keySizeOffset; } - public long pos() { - assert this.entryInit() : "Entry should be init"; - return this.pos; - } - - public void closeEntry() { - if (!(this.entryInit())) + public void closeEntryOffset() { + if (!(this.entryOffsetInit())) return ; - this.closeEntryDependants(); - this.pos = -1; + this.closeEntryOffsetDependants(); + this.keySizeOffset = -1; } - public void closeEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryKeyEqualsDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesKeyEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateDropChangeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); + public void closeEntryOffsetDependants() { CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntrySizeDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapQueryDropSearchIfNestedContextsAndPresentHashLookupSlotCheckFailedDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryKey.closeEntryKeyBytesValueInnerGetUsingDependants(); + CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesReadExistingEntryDependants(); } - public long keyEnd() { - return (keyOffset()) + (keySize()); + public void writeNewEntry(long pos, Data key) { + initPos(pos); + initKeySize(key.size()); + entryBytes.position(keySizeOffset()); + CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.writeSize(entryBytes, keySize()); + initKeyOffset(entryBytes.position()); + key.writeTo(entryBytesAccessor, entryBytes, keyOffset()); } - public void closeReplicatedMapEntryStagesKeyEndDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesCountValueSizeOffsetDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicatedMapEntryStagesEntryEndDependants(); - CompiledReplicatedMapQueryContext.this.closeReplicationState(); + 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); } - private long _MapEntryStages_countValueSizeOffset() { - return keyEnd(); + long entrySize() { + return (entryEnd()) - (keySizeOffset()); } - long countValueSizeOffset() { - return (_MapEntryStages_countValueSizeOffset()) + (ReplicatedChronicleMap.ADDITIONAL_ENTRY_BYTES); + public void closeReplicatedMapEntryStagesEntrySizeDependants() { + CompiledReplicatedMapQueryContext.this.closeTheEntrySizeInChunks(); } - public void closeReplicatedMapEntryStagesCountValueSizeOffsetDependants() { - CompiledReplicatedMapQueryContext.this.closeValue(); + public int entrySizeInChunks = 0; + + public boolean theEntrySizeInChunksInit() { + return (this.entrySizeInChunks) != 0; } - long replicationBytesOffset = -1; - - public boolean replicationStateInit() { - return (this.replicationBytesOffset) >= 0; + void initTheEntrySizeInChunks() { + entrySizeInChunks = CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize()); } - void initReplicationState() { - replicationBytesOffset = keyEnd(); + public void initTheEntrySizeInChunks(int actuallyUsedChunks) { + entrySizeInChunks = actuallyUsedChunks; } - void initReplicationState(long timestamp, byte identifier) { - replicationBytesOffset = keyEnd(); - entryBytes.position(replicationBytesOffset); - entryBytes.writeLong(timestamp); - entryBytes.writeByte(identifier); + public int entrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) + this.initTheEntrySizeInChunks(); + + return this.entrySizeInChunks; } - public long replicationBytesOffset() { - if (!(this.replicationStateInit())) - this.initReplicationState(); - - return this.replicationBytesOffset; - } - - public void closeReplicationState() { - if (!(this.replicationStateInit())) + public void closeTheEntrySizeInChunks() { + if (!(this.theEntrySizeInChunksInit())) return ; - this.replicationBytesOffset = -1; + this.entrySizeInChunks = 0; } - private long timestampOffset() { - return replicationBytesOffset(); + public void readExistingEntry(long pos) { + initPos(pos); + entryBytes.position(keySizeOffset()); + initKeySize(CompiledReplicatedMapQueryContext.this.h().keySizeMarshaller.readSize(entryBytes)); + initKeyOffset(entryBytes.position()); } - long timestamp() { - return entryBytesAccess.readLong(entryBytesAccessHandle, timestampOffset()); + public void closeReplicatedMapEntryStagesReadExistingEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeKeySearch(); } - private long entryDeletedOffset() { - return (replicationBytesOffset()) + 9L; - } - - public void writeEntryPresent() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), false); - } - - public boolean entryDeleted() { - return entryBytesAccess.readBoolean(entryBytesAccessHandle, entryDeletedOffset()); - } - - public void writeEntryDeleted() { - entryBytesAccess.writeBoolean(entryBytesAccessHandle, entryDeletedOffset(), true); - } - - private long identifierOffset() { - return (replicationBytesOffset()) + 8L; - } - - byte identifier() { - return entryBytesAccess.readByte(entryBytesAccessHandle, identifierOffset()); - } - - public void dropChange() { - CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); - } - - public void closeReplicationUpdateDropChangeDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - } - - int hashLookupEntrySize; - - int keyBits; - - long address = -1; - - long capacityMask; - - long capacityMask2; - - long keyMask; - - long valueMask; - - long entryMask; - - public boolean segmentHashLookupInit() { - return (this.address) >= 0; - } - - public void initSegmentHashLookup() { - long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); - innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); - this.closeSegmentHashLookupDependants(); - } - - public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { - innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); - this.closeSegmentHashLookupDependants(); - } - - public int hashLookupEntrySize() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.hashLookupEntrySize; - } - - public int keyBits() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyBits; - } - - public long address() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.address; - } - - public long capacityMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask; - } - - public long capacityMask2() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.capacityMask2; - } - - public long entryMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.entryMask; - } - - public long keyMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.keyMask; - } - - public long valueMask() { - if (!(this.segmentHashLookupInit())) - this.initSegmentHashLookup(); - - return this.valueMask; - } - - public void closeSegmentHashLookup() { - if (!(this.segmentHashLookupInit())) - return ; - - this.closeSegmentHashLookupDependants(); - this.address = -1; - } - - public void closeSegmentHashLookupDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); - } - - public long value(long entry) { - return (entry >>> (keyBits())) & (valueMask()); - } - - public void closeHashLookupValueDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long step(long pos) { - return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; - } - - public void closeHashLookupStepDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public long readEntry(long pos) { - return NativeBytes.UNSAFE.getLong(((address()) + pos)); - } - - public void closeHashLookupReadEntryDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public boolean empty(long entry) { - return (entry & (entryMask())) == (UNSET_ENTRY); - } - - public void closeHashLookupEmptyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void checkValueForPut(long value) { - assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; - } - - long entry(long key, long value) { - return key | (value << (keyBits())); - } - - public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); - } - - void writeEntry(long pos, long prevEntry, long anotherEntry) { - long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long stepBack(long pos) { - return (pos -= hashLookupEntrySize()) >= 0 ? pos : capacityMask2(); - } - - public void closeHashLookupStepBackDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchFoundDependants(); - } - - long indexToPos(long index) { - return index * (hashLookupEntrySize()); - } - - public void closeHashLookupIndexToPosDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); - } - - public long hlPos(long key) { - return indexToPos((key & (capacityMask()))); - } - - public void closeHashLookupHlPosDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); - } - - public void clearHashLookup() { - NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); - } - - public long key(long entry) { - return entry & (keyMask()); - } - - public void closeHashLookupKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); - CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); - } - - public void putValueVolatile(long pos, long value) { - checkValueForPut(value); - long currentEntry = readEntry(pos); - writeEntryVolatile(pos, currentEntry, key(currentEntry), value); - } - - void forEach(EntryConsumer action) { - for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { - long entry = readEntry(pos); - if (!(empty(entry))) - action.accept(key(entry), value(entry)); - - } - } - - String hashLookupToString() { - final StringBuilder sb = new StringBuilder("{"); - forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); - sb.append('}'); - return sb.toString(); - } - - public void writeEntry(long pos, long prevEntry, long key, long value) { - long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - void clearEntry(long pos, long prevEntry) { - long entry = prevEntry & (~(entryMask())); - NativeBytes.UNSAFE.putLong(((address()) + pos), entry); - } - - public long remove(long posToRemove) { - long entryToRemove = readEntry(posToRemove); - long posToShift = posToRemove; - while (true) { - posToShift = step(posToShift); - long entryToShift = readEntry(posToShift); - if (empty(entryToShift)) - break; - - long insertPos = hlPos(key(entryToShift)); - boolean cond1 = insertPos <= posToRemove; - boolean cond2 = posToRemove <= posToShift; - if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { - writeEntry(posToRemove, entryToRemove, entryToShift); - posToRemove = posToShift; - entryToRemove = entryToShift; - } - } - clearEntry(posToRemove, entryToRemove); - return posToRemove; - } - - public long maskUnsetKey(long key) { - return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); - } - - public void closeHashLookupMaskUnsetKeyDependants() { - CompiledReplicatedMapQueryContext.this.closeSearchKey(); + public long newSizeOfEverythingBeforeValue(Data newValue) { + return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); } long segmentHeaderAddress; @@ -2922,66 +3080,10 @@ public class CompiledReplicatedMapQueryContext= (CompiledReplicatedMapQueryContext.this.h().actualChunksPerSegment)) - nextPosToSearchFrom = 0L; - - nextPosToSearchFrom(nextPosToSearchFrom); - } - - public long alloc(int chunks) { - VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); - if (chunks > (h.maxChunksPerEntry)) - throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); - - long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - ret = freeList().setNextNContinuousClearBits(0L, chunks); - if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { - if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) - freeList().clear(ret, h.actualChunksPerSegment); - - if (chunks == 1) { - throw new IllegalStateException("Segment is full, no free entries found"); - } else { - throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); - } - } - updateNextPosToSearchFrom(ret, chunks); - } else { - if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { - updateNextPosToSearchFrom(ret, chunks); - } - } - return ret; - } - boolean tryFindInitLocksOfThisSegment(Object thisContext, int index) { CompiledReplicatedMapQueryContext c = CompiledReplicatedMapQueryContext.this.contextAtIndexInChain(index); if ((((c.segmentHeader()) != null) && ((c.segmentHeaderAddress()) == (segmentHeaderAddress()))) && ((c.rootContextOnThisSegment()) != null)) { @@ -2995,6 +3097,14 @@ public class CompiledReplicatedMapQueryContext= (CompiledReplicatedMapQueryContext.this.h().actualChunksPerSegment)) + nextPosToSearchFrom = 0L; + + nextPosToSearchFrom(nextPosToSearchFrom); + } + + public long alloc(int chunks) { + VanillaChronicleHash h = CompiledReplicatedMapQueryContext.this.h(); + if (chunks > (h.maxChunksPerEntry)) + throw new IllegalArgumentException((((("Entry is too large: requires " + chunks) + " entry size chucks, ") + (h.maxChunksPerEntry)) + " is maximum.")); + + long ret = freeList().setNextNContinuousClearBits(nextPosToSearchFrom(), chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + ret = freeList().setNextNContinuousClearBits(0L, chunks); + if ((ret == (DirectBitSet.NOT_FOUND)) || ((ret + chunks) > (h.actualChunksPerSegment))) { + if (((ret != (DirectBitSet.NOT_FOUND)) && ((ret + chunks) > (h.actualChunksPerSegment))) && (ret < (h.actualChunksPerSegment))) + freeList().clear(ret, h.actualChunksPerSegment); + + if (chunks == 1) { + throw new IllegalStateException("Segment is full, no free entries found"); + } else { + throw new IllegalStateException((("Segment is full or has no ranges of " + chunks) + " continuous free chunks")); + } + } + updateNextPosToSearchFrom(ret, chunks); + } else { + if ((chunks == 1) || (freeList().isSet(nextPosToSearchFrom()))) { + updateNextPosToSearchFrom(ret, chunks); + } + } + return ret; + } + + public void free(long fromPos, int chunks) { + freeList().clear(fromPos, (fromPos + chunks)); + if (fromPos < (nextPosToSearchFrom())) + nextPosToSearchFrom(fromPos); + + } + + public void innerRemoveEntryExceptHashLookupUpdate() { + CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + } + + public final void freeExtraAllocatedChunks() { + if (((!(CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapQueryContext.this.allocatedChunks()))) { + CompiledReplicatedMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); + } else { + initTheEntrySizeInChunks(CompiledReplicatedMapQueryContext.this.allocatedChunks()); + } + } + + public long deleted() { + return segmentHeader().deleted(segmentHeaderAddress()); + } + + public long size() { + return (entries()) - (deleted()); + } + + public void raiseChange() { + CompiledReplicatedMapQueryContext.this.m().raiseChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); + } + + public void dropChange() { + CompiledReplicatedMapQueryContext.this.m().dropChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); + } + + public void updateChange() { + if (replicationUpdateInit()) { + dropChange(); + } else { + raiseChange(); + } + } + + int hashLookupEntrySize; + + int keyBits; + + long address = -1; + + long capacityMask; + + long capacityMask2; + + long keyMask; + + long valueMask; + + long entryMask; + + public boolean segmentHashLookupInit() { + return (this.address) >= 0; + } + + public void initSegmentHashLookup() { + long hashLookupOffset = CompiledReplicatedMapQueryContext.this.h().segmentOffset(CompiledReplicatedMapQueryContext.this.segmentIndex()); + innerInitSegmentHashLookup(((CompiledReplicatedMapQueryContext.this.h().ms.address()) + hashLookupOffset), CompiledReplicatedMapQueryContext.this.h().segmentHashLookupCapacity, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupEntrySize, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupKeyBits, CompiledReplicatedMapQueryContext.this.h().segmentHashLookupValueBits); + this.closeSegmentHashLookupDependants(); + } + + public void initSegmentHashLookup(long address, long capacity, int entrySize, int keyBits, int valueBits) { + innerInitSegmentHashLookup(address, capacity, entrySize, keyBits, valueBits); + this.closeSegmentHashLookupDependants(); + } + + public int hashLookupEntrySize() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.hashLookupEntrySize; + } + + public int keyBits() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyBits; + } + + public long address() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.address; + } + + public long capacityMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask; + } + + public long capacityMask2() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.capacityMask2; + } + + public long entryMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.entryMask; + } + + public long keyMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.keyMask; + } + + public long valueMask() { + if (!(this.segmentHashLookupInit())) + this.initSegmentHashLookup(); + + return this.valueMask; + } + + public void closeSegmentHashLookup() { + if (!(this.segmentHashLookupInit())) + return ; + + this.closeSegmentHashLookupDependants(); + this.address = -1; + } + + public void closeSegmentHashLookupDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupIndexToPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupMaskUnsetKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupValueDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupReadEntryDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupStepDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupEmptyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupKeyDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupStepBackDependants(); + } + + long indexToPos(long index) { + return index * (hashLookupEntrySize()); + } + + public void closeHashLookupIndexToPosDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupHlPosDependants(); + } + + public long maskUnsetKey(long key) { + return (key &= keyMask()) != (UNSET_KEY) ? key : keyMask(); + } + + public void closeHashLookupMaskUnsetKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeSearchKey(); + } + + public void checkValueForPut(long value) { + assert (value & (~(valueMask()))) == 0L : "Value out of range, was " + value; + } + + long entry(long key, long value) { + return key | (value << (keyBits())); + } + + public void writeEntry(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public void writeEntryVolatile(long pos, long prevEntry, long key, long value) { + long entry = (prevEntry & (~(entryMask()))) | (entry(key, value)); + NativeBytes.UNSAFE.putLongVolatile(null, ((address()) + pos), entry); + } + + public void clearHashLookup() { + NativeBytes.UNSAFE.setMemory(address(), ((capacityMask2()) + (hashLookupEntrySize())), ((byte)(0))); + } + public void clearSegment() { CompiledReplicatedMapQueryContext.this.innerWriteLock.lock(); CompiledReplicatedMapQueryContext.this.clearHashLookup(); @@ -3107,20 +3497,12 @@ public class CompiledReplicatedMapQueryContext>> (keyBits())) & (valueMask()); + } + + public void closeHashLookupValueDependants() { CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); } - public void putVolatile(long value) { + void writeEntry(long pos, long prevEntry, long anotherEntry) { + long entry = (prevEntry & (~(entryMask()))) | (anotherEntry & (entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long readEntry(long pos) { + return NativeBytes.UNSAFE.getLong(((address()) + pos)); + } + + public void closeHashLookupReadEntryDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + public void putNewVolatile(long value) { CompiledReplicatedMapQueryContext.this.checkValueForPut(value); long currentEntry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); - assert (CompiledReplicatedMapQueryContext.this.key(currentEntry)) == (searchKey()); CompiledReplicatedMapQueryContext.this.writeEntryVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), currentEntry, searchKey(), value); } - public void found() { - CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.stepBack(CompiledReplicatedMapQueryContext.this.hashLookupPos())); - } - - public void closeHashLookupSearchFoundDependants() { - CompiledReplicatedMapQueryContext.this.closeKeySearch(); - } - void put(long value) { CompiledReplicatedMapQueryContext.this.checkValueForPut(value); CompiledReplicatedMapQueryContext.this.writeEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos(), CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()), searchKey(), value); } - public void remove() { - CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.remove(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + public long step(long pos) { + return (pos += hashLookupEntrySize()) <= (capacityMask2()) ? pos : 0L; + } + + public void closeHashLookupStepDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + + 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 long key(long entry) { + return entry & (keyMask()); + } + + public void closeHashLookupKeyDependants() { + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchCheckSlotContainsExpectedKeyAndValueDependants(); + CompiledReplicatedMapQueryContext.this.closeHashLookupSearchNextPosDependants(); + } + public boolean checkSlotContainsExpectedKeyAndValue(long value) { long entry = CompiledReplicatedMapQueryContext.this.readEntry(CompiledReplicatedMapQueryContext.this.hashLookupPos()); return ((CompiledReplicatedMapQueryContext.this.key(entry)) == (searchKey())) && ((CompiledReplicatedMapQueryContext.this.value(entry)) == value); @@ -3240,9 +3657,38 @@ public class CompiledReplicatedMapQueryContext value) { + initValue(value); + freeExtraAllocatedChunks(); + CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); + } + + void forEach(EntryConsumer action) { + for (long pos = 0L ; pos <= (capacityMask2()) ; pos += hashLookupEntrySize()) { + long entry = readEntry(pos); + if (!(empty(entry))) + action.accept(key(entry), value(entry)); + + } + } + + String hashLookupToString() { + final StringBuilder sb = new StringBuilder("{"); + forEach((long key,long value) -> sb.append(key).append('=').append(value).append(',')); + sb.append('}'); + return sb.toString(); + } + + public void 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); } @@ -3270,6 +3716,53 @@ public class CompiledReplicatedMapQueryContext= 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(); + } + + void clearEntry(long pos, long prevEntry) { + long entry = prevEntry & (~(entryMask())); + NativeBytes.UNSAFE.putLong(((address()) + pos), entry); + } + + public long remove(long posToRemove) { + long entryToRemove = readEntry(posToRemove); + long posToShift = posToRemove; + while (true) { + posToShift = step(posToShift); + long entryToShift = readEntry(posToShift); + if (empty(entryToShift)) + break; + + long insertPos = hlPos(key(entryToShift)); + boolean cond1 = insertPos <= posToRemove; + boolean cond2 = posToRemove <= posToShift; + if ((cond1 && cond2) || ((posToShift < insertPos) && (cond1 || cond2))) { + writeEntry(posToRemove, entryToRemove, entryToShift); + posToRemove = posToShift; + entryToRemove = entryToShift; + } + } + clearEntry(posToRemove, entryToRemove); + return posToRemove; + } + + public void remove() { + CompiledReplicatedMapQueryContext.this.setHashLookupPosGuarded(CompiledReplicatedMapQueryContext.this.remove(CompiledReplicatedMapQueryContext.this.hashLookupPos())); + } + boolean keyEquals() { return ((inputKey().size()) == (CompiledReplicatedMapQueryContext.this.keySize())) && (inputKey().equivalent(((ReadAccess)(CompiledReplicatedMapQueryContext.this.entryBytesAccess)), CompiledReplicatedMapQueryContext.this.entryBytesAccessHandle, CompiledReplicatedMapQueryContext.this.entryBytesAccessOffset(CompiledReplicatedMapQueryContext.this.keyOffset()))); } @@ -3286,7 +3779,7 @@ public class CompiledReplicatedMapQueryContext= 0L ; ) { - CompiledReplicatedMapQueryContext.this.initEntry(pos); + CompiledReplicatedMapQueryContext.this.readExistingEntry(pos); if (!(keyEquals())) continue; @@ -3317,35 +3810,6 @@ public class CompiledReplicatedMapQueryContext wrapValueAsValue(V value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + WrappedValueInstanceData wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; + wrapped = wrapped.getUnusedWrappedValueGuarded(); + wrapped.initValue(value); + return wrapped; + } + + @Override + public byte originIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return identifier(); + } + + @NotNull + @Override + public MapContext context() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return this; } @NotNull @@ -3385,26 +3877,11 @@ public class CompiledReplicatedMapQueryContext value() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return timestamp(); - } - - @Override - public Value wrapValueAsValue(V value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - WrappedValueInstanceValue wrapped = CompiledReplicatedMapQueryContext.this.wrappedValueInstanceValue; - wrapped = wrapped.getUnusedWrappedValueGuarded(); - wrapped.initValue(value); - return wrapped; - } - - @Override - public Value defaultValue(@NotNull - MapAbsentEntry absentEntry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + return CompiledReplicatedMapQueryContext.this.entryValue; } @NotNull @@ -3414,6 +3891,96 @@ public class CompiledReplicatedMapQueryContext defaultValue(@NotNull + MapAbsentEntry absentEntry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.defaultValue(absentEntry); + } + + @Override + public R insert(@NotNull + MapAbsentEntry absentEntry, Data value) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); + } + + @NotNull + @Override + public InterProcessLock writeLock() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.innerWriteLock; + } + + @NotNull + @Override + public Data defaultValue() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); + } + + @NotNull + @Override + public Data absentKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.inputKey(); + } + + @NotNull + @Override + public Data key() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.entryKey; + } + + @Override + public R remove(@NotNull + MapEntry entry) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); + } + + @Override + public R replaceValue(@NotNull + MapEntry entry, Data newValue) { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); + } + + @Override + public byte remoteIdentifier() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return innerRemoteIdentifier(); + } + + public boolean searchStatePresent() { + return (searchState()) == (SearchState.PRESENT); + } + + 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; + } + + @Override + public MapReplicableEntry entry() { + return ((MapReplicableEntry)(_MapQuery_entry())); + } + @Nullable private MapAbsentEntry _MapQuery_absentEntry() { CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); @@ -3436,88 +4003,12 @@ public class CompiledReplicatedMapQueryContext _MapQuery_entry() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return entryPresent() ? this : null; + public boolean searchStateDeleted() { + return (((searchState()) == (SearchState.DELETED)) && (!(CompiledReplicatedMapQueryContext.this.concurrentSameThreadContexts()))) && (CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread()); } - @Override - public MapReplicableEntry entry() { - return ((MapReplicableEntry)(_MapQuery_entry())); - } - - @NotNull - @Override - public Value defaultValue() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.wrapValueAsValue(CompiledReplicatedMapQueryContext.this.m().defaultValue(CompiledReplicatedMapQueryContext.this.deprecatedMapKeyContext)); - } - - @NotNull - @Override - public Value value() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryValue; - } - - public Value queriedKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return inputKey(); - } - - @NotNull - @Override - public InterProcessLock writeLock() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.innerWriteLock; - } - - @Override - public R insert(@NotNull - MapAbsentEntry absentEntry, Value value) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.insert(absentEntry, value); - } - - @Override - public R remove(@NotNull - MapEntry entry) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.remove(entry); - } - - @Override - public R replaceValue(@NotNull - MapEntry entry, Value newValue) { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.m().entryOperations.replaceValue(entry, newValue); - } - - @NotNull - @Override - public Value key() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.entryKey; - } - - @NotNull - @Override - public MapContext context() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return this; - } - - @Override - public byte originIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return identifier(); - } - - @NotNull - @Override - public Value absentKey() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return CompiledReplicatedMapQueryContext.this.inputKey(); + public boolean searchStateAbsent() { + return (!(searchStatePresent())) && (!(searchStateDeleted())); } protected void putPrefix() { @@ -3532,446 +4023,34 @@ public class CompiledReplicatedMapQueryContext= 0; - } - - public void initReplicationInput(Bytes replicatedInputBytes) { - initReplicatedInputBytes(replicatedInputBytes); - riKeySize = CompiledReplicatedMapQueryContext.this.m().keySizeMarshaller.readSize(replicatedInputBytes); - riValueSize = CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.readSize(replicatedInputBytes); - riTimestamp = replicatedInputBytes.readStopBit(); - riId = replicatedInputBytes.readByte(); - CompiledReplicatedMapQueryContext.this.initReplicationUpdate(riTimestamp, riId); - isDeleted = replicatedInputBytes.readBoolean(); - riKeyOffset = replicatedInputBytes.position(); - riValueOffset = (riKeyOffset) + (riKeySize); - this.closeReplicationInputDependants(); - } - - public boolean isDeleted() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.isDeleted; - } - - public byte riId() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riId; - } - - public long riKeyOffset() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riKeyOffset; - } - - public long riKeySize() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riKeySize; - } - - public long riValueOffset() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riValueOffset; - } - - public long riValueSize() { - assert this.replicationInputInit() : "ReplicationInput should be init"; - return this.riValueSize; - } - - public void closeReplicationInput() { - if (!(this.replicationInputInit())) - return ; - - this.closeReplicationInputDependants(); - this.riKeySize = -1; - } - - public void closeReplicationInputDependants() { - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueGetUsingDependants(); - } - - public long newTimestamp; - - public byte newIdentifier = ((byte)(0)); - - public boolean replicationUpdateInit() { - return (this.newIdentifier) != ((byte)(0)); - } - - public void initReplicationUpdate() { - newTimestamp = CompiledReplicatedMapQueryContext.this.m().timeProvider.currentTime(); - newIdentifier = CompiledReplicatedMapQueryContext.this.m().identifier(); - this.closeReplicationUpdateDependants(); - } - - public void initReplicationUpdate(long timestamp, byte identifier) { - newTimestamp = timestamp; - if (identifier == 0) - throw new IllegalStateException("identifier can\'t be 0"); - - newIdentifier = identifier; - this.closeReplicationUpdateDependants(); - } - - public void initReplicationUpdateIncrement(long timestamp) { - assert replicationUpdateInit(); - newTimestamp = timestamp + 1; - this.closeReplicationUpdateDependants(); - } - - public byte newIdentifier() { - if (!(this.replicationUpdateInit())) - this.initReplicationUpdate(); - - return this.newIdentifier; - } - - public long newTimestamp() { - if (!(this.replicationUpdateInit())) - this.initReplicationUpdate(); - - return this.newTimestamp; - } - - public void closeReplicationUpdate() { - if (!(this.replicationUpdateInit())) - return ; - - this.closeReplicationUpdateDependants(); - this.newIdentifier = ((byte)(0)); - } - - public void closeReplicationUpdateDependants() { - CompiledReplicatedMapQueryContext.this.closeUpdatedReplicationState(); - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateRemoteUpdateDependants(); - } - - private boolean updatedReplicationState = false; - - public boolean updatedReplicationStateInit() { - return (this.updatedReplicationState) != false; - } - - public void initUpdatedReplicationState() { - initReplicationState(CompiledReplicatedMapQueryContext.this.newTimestamp(), CompiledReplicatedMapQueryContext.this.newIdentifier()); - updatedReplicationState = true; - } - - public void closeUpdatedReplicationState() { - if (!(this.updatedReplicationStateInit())) - return ; - - this.updatedReplicationState = false; - } - - public boolean remoteUpdate() { - return (newIdentifier()) != (CompiledReplicatedMapQueryContext.this.m().identifier()); - } - - public void closeReplicationUpdateRemoteUpdateDependants() { - CompiledReplicatedMapQueryContext.this.closeReplicationUpdateUpdateChangeDependants(); - } - - public void updateChange() { - if (remoteUpdate()) { - dropChange(); - } else { - CompiledReplicatedMapQueryContext.this.m().raiseChange(CompiledReplicatedMapQueryContext.this.segmentIndex(), CompiledReplicatedMapQueryContext.this.pos()); + public void incrementSegmentEntriesIfNeeded() { + if ((CompiledReplicatedMapQueryContext.this.searchState()) != (SearchState.PRESENT)) { + CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) + 1L)); } } - public void closeReplicationUpdateUpdateChangeDependants() { - CompiledReplicatedMapQueryContext.this.closeValue(); - } - - public long valueSizeOffset; - - public long valueSize; - - public long valueOffset = -1; - - boolean valueInit() { - return (this.valueOffset) >= 0; - } - - void initValue() { - valueSizeOffset = countValueSizeOffset(); - entryBytes.position(valueSizeOffset); - valueSize = CompiledReplicatedMapQueryContext.this.m().readValueSize(entryBytes); - CompiledReplicatedMapQueryContext.this.m().alignment.alignPositionAddr(entryBytes); - valueOffset = entryBytes.position(); - this.closeValueDependants(); - } - - public void initValue(Value value) { - valueSizeOffset = countValueSizeOffset(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueAgain(Value value) { - assert valueInit(); - innerInitValue(value); - this.closeValueDependants(); - } - - public void initValueWithoutSize(Value value, long oldValueSizeOffset, long oldValueSize, long oldValueOffset) { - valueSizeOffset = countValueSizeOffset(); - assert oldValueSize == (value.size()); - valueSize = oldValueSize; - valueOffset = (valueSizeOffset) + (oldValueOffset - oldValueSizeOffset); - writeValue(value); - this.closeValueDependants(); - } - - public long valueOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueOffset; - } - - public long valueSize() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSize; - } - - public long valueSizeOffset() { - if (!(this.valueInit())) - this.initValue(); - - return this.valueSizeOffset; - } - - public void closeValue() { - if (!(this.valueInit())) - return ; - - this.closeValueDependants(); - this.valueOffset = -1; - } - - public void closeValueDependants() { - CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesValueSizeDependants(); - CompiledReplicatedMapQueryContext.this.entryValue.closeEntryValueBytesValueInnerGetUsingDependants(); - 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 innerRemoveEntryExceptHashLookupUpdate() { - CompiledReplicatedMapQueryContext.this.free(pos(), entrySizeInChunks()); - CompiledReplicatedMapQueryContext.this.entries(((CompiledReplicatedMapQueryContext.this.entries()) - 1L)); - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - } - - public long newSizeOfEverythingBeforeValue(Value newValue) { - return ((valueSizeOffset()) + (CompiledReplicatedMapQueryContext.this.m().valueSizeMarshaller.sizeEncodingSize(newValue.size()))) - (keySizeOffset()); - } - - @Override - public long remoteTimestamp() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newTimestamp(); - } - - @Override - public byte remoteIdentifier() { - CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); - return newIdentifier(); - } - - private boolean testTimeStampInSensibleRange() { - if ((CompiledReplicatedMapQueryContext.this.m().timeProvider) == (TimeProvider.SYSTEM)) { - long currentTime = TimeProvider.SYSTEM.currentTime(); - assert (Math.abs((currentTime - (timestamp())))) <= 100000000 : "unrealistic timestamp: " + (timestamp()); - assert (Math.abs((currentTime - (CompiledReplicatedMapQueryContext.this.newTimestamp())))) <= 100000000 : "unrealistic newTimestamp: " + (CompiledReplicatedMapQueryContext.this.newTimestamp()); - } - return true; - } - - public Bytes replicatedInputBytes = null; - - public boolean replicatedInputBytesInit() { - return (this.replicatedInputBytes) != null; - } - - public void initReplicatedInputBytes(Bytes replicatedInputBytes) { - this.replicatedInputBytes = replicatedInputBytes; - this.closeReplicatedInputBytesDependants(); - } - - public Bytes replicatedInputBytes() { - assert this.replicatedInputBytesInit() : "ReplicatedInputBytes should be init"; - return this.replicatedInputBytes; - } - - public void closeReplicatedInputBytes() { - if (!(this.replicatedInputBytesInit())) - return ; - - this.closeReplicatedInputBytesDependants(); - this.replicatedInputBytes = null; - } - - public void closeReplicatedInputBytesDependants() { - CompiledReplicatedMapQueryContext.this.replicatedInputKeyBytesValue.closeReplicatedInputKeyBytesValueGetUsingDependants(); - CompiledReplicatedMapQueryContext.this.replicatedInputValueBytesValue.closeReplicatedInputValueBytesValueGetUsingDependants(); - } - - public int allocatedChunks = 0; - - public boolean allocatedChunksInit() { - return (this.allocatedChunks) != 0; - } - - public void initAllocatedChunks(int allocatedChunks) { - this.allocatedChunks = allocatedChunks; - } - - public int allocatedChunks() { - assert this.allocatedChunksInit() : "AllocatedChunks should be init"; - return this.allocatedChunks; - } - - public void closeAllocatedChunks() { - if (!(this.allocatedChunksInit())) - return ; - - this.allocatedChunks = 0; - } - - public final void freeExtraAllocatedChunks() { - if (((!(CompiledReplicatedMapQueryContext.this.m().constantlySizedEntry)) && (CompiledReplicatedMapQueryContext.this.m().couldNotDetermineAlignmentBeforeAllocation)) && ((entrySizeInChunks()) < (CompiledReplicatedMapQueryContext.this.allocatedChunks()))) { - CompiledReplicatedMapQueryContext.this.free(((pos()) + (entrySizeInChunks())), ((CompiledReplicatedMapQueryContext.this.allocatedChunks()) - (entrySizeInChunks()))); - } else { - initTheEntrySizeInChunks(CompiledReplicatedMapQueryContext.this.allocatedChunks()); - } - } - - public void writeValueAndPutPos(Value value) { - initValue(value); - freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putValueVolatile(CompiledReplicatedMapQueryContext.this.hashLookupPos(), pos()); - } - - public void initEntryAndKey(long entrySize) { - initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); - incrementSegmentEntriesIfNeeded(); - } - - void putEntry(Value value) { - assert CompiledReplicatedMapQueryContext.this.searchStateAbsent(); - long entrySize = CompiledReplicatedMapQueryContext.this.entrySize(CompiledReplicatedMapQueryContext.this.inputKey().size(), value.size()); - CompiledReplicatedMapQueryContext.this.initEntryAndKey(entrySize); - CompiledReplicatedMapQueryContext.this.initValue(value); - CompiledReplicatedMapQueryContext.this.freeExtraAllocatedChunks(); - CompiledReplicatedMapQueryContext.this.putNewVolatile(CompiledReplicatedMapQueryContext.this.pos()); - } - public void initEntryAndKeyCopying(long entrySize, long bytesToCopy) { initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); - CompiledReplicatedMapQueryContext.this.initEntryCopying(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); + CompiledReplicatedMapQueryContext.this.copyExistingEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), bytesToCopy); incrementSegmentEntriesIfNeeded(); } - private void _MapEntryStages_relocation(Value newValue, long newSizeOfEverythingBeforeValue) { + 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(Value newValue, long newSizeOfEverythingBeforeValue) { + protected void relocation(Data newValue, long newSizeOfEverythingBeforeValue) { CompiledReplicatedMapQueryContext.this.dropChange(); _MapEntryStages_relocation(newValue, newSizeOfEverythingBeforeValue); } - public void innerDefaultReplaceValue(Value newValue) { + public void innerDefaultReplaceValue(Data newValue) { assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); boolean newValueSizeIsDifferent = (newValue.size()) != (this.valueSize()); if (newValueSizeIsDifferent) { @@ -3998,9 +4077,9 @@ public class CompiledReplicatedMapQueryContext (CompiledReplicatedMapQueryContext.this.dummyValue.size())) CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(CompiledReplicatedMapQueryContext.this.dummyValue); - CompiledReplicatedMapQueryContext.this.initUpdatedReplicationState(); + CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); CompiledReplicatedMapQueryContext.this.writeEntryDeleted(); CompiledReplicatedMapQueryContext.this.updateChange(); CompiledReplicatedMapQueryContext.this.deleted(((CompiledReplicatedMapQueryContext.this.deleted()) + 1)); @@ -4049,10 +4128,9 @@ public class CompiledReplicatedMapQueryContext newValue) { - putPrefix(); - if (searchStatePresent()) { - CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(newValue); - CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); - setSearchStateGuarded(SearchState.PRESENT); - } else { - throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); - } - } - - private void _MapEntryStages_putValueDeletedEntry(Value newValue) { + private void _MapEntryStages_putValueDeletedEntry(Data newValue) { assert CompiledReplicatedMapQueryContext.this.innerUpdateLock.isHeldByCurrentThread(); int newSizeInChunks; long entryStartOffset = keySizeOffset(); @@ -4102,9 +4167,9 @@ public class CompiledReplicatedMapQueryContext newValue) { + public void putValueDeletedEntry(Data newValue) { throw new AssertionError("Replicated Map doesn\'t remove entries truly, yet"); } - private void _MapAbsent_doInsert(Value value) { + public void initEntryAndKey(long entrySize) { + initAllocatedChunks(CompiledReplicatedMapQueryContext.this.h().inChunks(entrySize)); + CompiledReplicatedMapQueryContext.this.writeNewEntry(CompiledReplicatedMapQueryContext.this.alloc(allocatedChunks()), CompiledReplicatedMapQueryContext.this.inputKey()); + incrementSegmentEntriesIfNeeded(); + } + + 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()); + } + + private void _MapAbsent_doInsert(Data value) { CompiledReplicatedMapQueryContext.this.putPrefix(); if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { if (CompiledReplicatedMapQueryContext.this.searchStateDeleted()) { @@ -4148,7 +4228,7 @@ public class CompiledReplicatedMapQueryContext value) { + public void doInsert(Data value) { CompiledReplicatedMapQueryContext.this.putPrefix(); if (!(CompiledReplicatedMapQueryContext.this.entryPresent())) { if (!(CompiledReplicatedMapQueryContext.this.searchStatePresent())) { @@ -4160,8 +4240,33 @@ public class CompiledReplicatedMapQueryContext newValue) { + putPrefix(); + if (searchStatePresent()) { + CompiledReplicatedMapQueryContext.this.innerDefaultReplaceValue(newValue); + CompiledReplicatedMapQueryContext.this.incrementModCountGuarded(); + setSearchStateGuarded(SearchState.PRESENT); + } else { + throw new IllegalStateException("Entry is absent in the map when doReplaceValue() is called"); + } + } + + @Override + public void doReplaceValue(Data newValue) { + _MapQuery_doReplaceValue(newValue); + CompiledReplicatedMapQueryContext.this.updateChange(); + CompiledReplicatedMapQueryContext.this.initUpdatedReplicationStateOnPresentEntry(); + } + + public Data queriedKey() { + CompiledReplicatedMapQueryContext.this.checkOnEachPublicOperation(); + return inputKey(); + } } diff --git a/src/main/java/net/openhft/chronicle/map/impl/NullReturnValue.java b/src/main/java/net/openhft/chronicle/map/impl/NullReturnValue.java index abda70caa..138c6d7a8 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/NullReturnValue.java +++ b/src/main/java/net/openhft/chronicle/map/impl/NullReturnValue.java @@ -1,6 +1,6 @@ package net.openhft.chronicle.map.impl; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.map.impl.ret.InstanceReturnValue; import org.jetbrains.annotations.NotNull; @@ -19,7 +19,7 @@ public final class NullReturnValue implements InstanceReturnValue { } @Override - public void returnValue(@NotNull Value value) { + public void returnValue(@NotNull Data value) { // ignore } } 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 aaad90d2a..293808f1f 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java +++ b/src/main/java/net/openhft/chronicle/map/impl/QueryContextInterface.java @@ -1,24 +1,24 @@ package net.openhft.chronicle.map.impl; -import net.openhft.chronicle.hash.Value; -import net.openhft.chronicle.hash.impl.value.instance.KeyInitableValue; +import net.openhft.chronicle.hash.Data; +import net.openhft.chronicle.hash.impl.value.instance.KeyInitableData; 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.ValueInitableValue; +import net.openhft.chronicle.map.impl.value.instance.ValueInitableData; public interface QueryContextInterface extends ExternalMapQueryContext { - void initInputKey(Value inputKey); + void initInputKey(Data inputKey); - KeyInitableValue inputKeyInstanceValue(); + KeyInitableData inputKeyInstanceValue(); InstanceReturnValue defaultReturnValue(); UsableReturnValue usingReturnValue(); - ValueInitableValue inputValueInstanceValue(); + ValueInitableData inputValueInstanceValue(); MapKeyContext deprecatedMapKeyContext(); @@ -28,7 +28,5 @@ public interface QueryContextInterface extends ExternalMapQueryContext< boolean theSegmentIndexInit(); - void initEntry(long pos); - void clear(); } 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 new file mode 100644 index 000000000..b49ed15e9 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/impl/value/instance/ValueInitableData.java @@ -0,0 +1,8 @@ +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/impl/value/instance/ValueInitableValue.java b/src/main/java/net/openhft/chronicle/map/impl/value/instance/ValueInitableValue.java deleted file mode 100644 index 109a2bd0f..000000000 --- a/src/main/java/net/openhft/chronicle/map/impl/value/instance/ValueInitableValue.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.openhft.chronicle.map.impl.value.instance; - -import net.openhft.chronicle.hash.Value; - -public interface ValueInitableValue extends Value { - - 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 97ed6d723..54dbe3a87 100644 --- a/src/main/java/net/openhft/chronicle/map/replication/MapRemoteOperations.java +++ b/src/main/java/net/openhft/chronicle/map/replication/MapRemoteOperations.java @@ -19,8 +19,8 @@ package net.openhft.chronicle.map.replication; import net.openhft.chronicle.hash.AcceptanceDecision; -import net.openhft.chronicle.hash.Value; -import net.openhft.chronicle.hash.replication.HashReplicableEntry; +import net.openhft.chronicle.hash.Data; +import net.openhft.chronicle.hash.replication.ReplicableEntry; import net.openhft.chronicle.map.MapAbsentEntry; import static net.openhft.chronicle.hash.AcceptanceDecision.ACCEPT; @@ -41,15 +41,17 @@ public interface MapRemoteOperations { } else { MapAbsentEntry absentEntry = q.absentEntry(); assert absentEntry != null; - if (absentEntry instanceof HashReplicableEntry) { - return decideOnRemoteModification((HashReplicableEntry) absentEntry, q); + if (absentEntry instanceof ReplicableEntry) { + AcceptanceDecision decision = + decideOnRemoteModification((ReplicableEntry) absentEntry, q); + return decision; } else { return ACCEPT; } } } - default AcceptanceDecision put(MapRemoteQueryContext q, Value newValue) { + default AcceptanceDecision put(MapRemoteQueryContext q, Data newValue) { MapReplicableEntry entry = q.entry(); if (entry != null) { if (decideOnRemoteModification(entry, q) == ACCEPT) { @@ -61,8 +63,8 @@ public interface MapRemoteOperations { } else { MapAbsentEntry absentEntry = q.absentEntry(); assert absentEntry != null; - if (!(absentEntry instanceof HashReplicableEntry) || - decideOnRemoteModification((HashReplicableEntry) absentEntry, q) == ACCEPT) { + if (!(absentEntry instanceof ReplicableEntry) || + decideOnRemoteModification((ReplicableEntry) absentEntry, q) == ACCEPT) { q.insert(absentEntry, newValue); return ACCEPT; } else { diff --git a/src/main/java/net/openhft/chronicle/set/SetFromMap.java b/src/main/java/net/openhft/chronicle/set/SetFromMap.java index 039d353c8..862dc4895 100644 --- a/src/main/java/net/openhft/chronicle/set/SetFromMap.java +++ b/src/main/java/net/openhft/chronicle/set/SetFromMap.java @@ -18,8 +18,8 @@ package net.openhft.chronicle.set; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.KeyContext; -import net.openhft.chronicle.hash.Value; import net.openhft.chronicle.hash.serialization.internal.DummyValue; import net.openhft.chronicle.map.ChronicleMap; import org.jetbrains.annotations.NotNull; @@ -142,7 +142,7 @@ class SetFromMap extends AbstractSet @NotNull @Override - public ExternalSetQueryContext queryContext(Value key) { + public ExternalSetQueryContext queryContext(Data key) { //TODO throw new UnsupportedOperationException(); } diff --git a/src/main/java/net/openhft/chronicle/set/replication/SetRemoteOperations.java b/src/main/java/net/openhft/chronicle/set/replication/SetRemoteOperations.java index 0bbbd1803..f135f6401 100644 --- a/src/main/java/net/openhft/chronicle/set/replication/SetRemoteOperations.java +++ b/src/main/java/net/openhft/chronicle/set/replication/SetRemoteOperations.java @@ -1,7 +1,7 @@ package net.openhft.chronicle.set.replication; import net.openhft.chronicle.hash.AcceptanceDecision; -import net.openhft.chronicle.hash.replication.HashReplicableEntry; +import net.openhft.chronicle.hash.replication.ReplicableEntry; import net.openhft.chronicle.set.SetAbsentEntry; import static net.openhft.chronicle.hash.AcceptanceDecision.ACCEPT; @@ -22,8 +22,8 @@ public interface SetRemoteOperations { } else { SetAbsentEntry absentEntry = q.absentEntry(); assert absentEntry != null; - if (absentEntry instanceof HashReplicableEntry) { - return decideOnRemoteModification((HashReplicableEntry) absentEntry, q); + if (absentEntry instanceof ReplicableEntry) { + return decideOnRemoteModification((ReplicableEntry) absentEntry, q); } else { return ACCEPT; } @@ -41,8 +41,8 @@ public interface SetRemoteOperations { } else { SetAbsentEntry absentEntry = q.absentEntry(); assert absentEntry != null; - if (!(absentEntry instanceof HashReplicableEntry) || - decideOnRemoteModification((HashReplicableEntry) absentEntry, q) == ACCEPT) { + if (!(absentEntry instanceof ReplicableEntry) || + decideOnRemoteModification((ReplicableEntry) absentEntry, q) == ACCEPT) { q.insert(absentEntry); return ACCEPT; } else { diff --git a/src/test/java/eg/TestNesterInterfaceMarshal.java b/src/test/java/eg/TestNesterInterfaceMarshal.java index 953314bde..6cbf38ff5 100644 --- a/src/test/java/eg/TestNesterInterfaceMarshal.java +++ b/src/test/java/eg/TestNesterInterfaceMarshal.java @@ -14,7 +14,6 @@ import java.util.concurrent.TimeUnit; /** * Created by Vanitha on 12/5/2014. */ -@Ignore("a test written by someone on the google groups") public class TestNesterInterfaceMarshal { @@ -27,87 +26,62 @@ public class TestNesterInterfaceMarshal { @Test public void testReplicatedMap() throws Exception { - ChronicleMap chronicleMap = null; TcpTransportAndNetworkConfig tcpTransportAndNetworkConfig = TcpTransportAndNetworkConfig.of(8076).heartBeatInterval(1L, TimeUnit.SECONDS); - try { - ChronicleMapBuilder builder = ChronicleMapBuilder - .of(CharSequence.class, TestInstrumentVOInterface.class) - .entries(5000L) - .averageKeySize(10) - .replication((byte) 1, tcpTransportAndNetworkConfig); - - chronicleMap = builder.create(); - - } catch (Exception e) { - System.out.println("Error(s) creating instrument cache: " + e); - } - ChronicleMap map = chronicleMap; - - ChronicleMap chronicleMap1 = null; TcpTransportAndNetworkConfig tcpTransportAndNetworkConfig1 = TcpTransportAndNetworkConfig.of(8077, new InetSocketAddress("127.0.0.1", 8076)) .heartBeatInterval(1L, TimeUnit.SECONDS); - try { - ChronicleMapBuilder builder = ChronicleMapBuilder - .of(CharSequence.class, TestInstrumentVOInterface.class) - .putReturnsNull(true) - .removeReturnsNull(true) - .entries(5000L).averageKeySize(10) - .replication((byte) 2, tcpTransportAndNetworkConfig1); + try (ChronicleMap map = + ChronicleMapBuilder + .of(CharSequence.class, TestInstrumentVOInterface.class) + .entries(5000L) + .averageKeySize(10) + .replication((byte) 1, tcpTransportAndNetworkConfig).create(); + + ChronicleMap replicatedMap = + ChronicleMapBuilder + .of(CharSequence.class, TestInstrumentVOInterface.class) + .putReturnsNull(true) + .removeReturnsNull(true) + .entries(5000L).averageKeySize(10) + .replication((byte) 2, tcpTransportAndNetworkConfig1).create()) { + //Store some data into MAP1 + TestInstrumentVOInterface intrumentVOInterface = map.newValueInstance(); - chronicleMap1 = builder.create(); + try (MapKeyContext wc = map.acquireContext + ("KEY1", intrumentVOInterface)) { + intrumentVOInterface.setSymbol("Flyer"); + intrumentVOInterface.setCurrencyCode("USA"); + intrumentVOInterface.setSizeOfInstrumentIDArray(2); - } catch (Exception e) { - System.out.println("*********************Error(s) creating launcher " + - "instrument cache: " + e); + // TestIntrumentVOInterface.TestInstrumentIDVOInterface instrumentIDVOInterface = + intrumentVOInterface.getInstrumentIDAt(0); + // instrumentIDVOInterface.setIdSource("CUSIP"); + // instrumentIDVOInterface.setSecurityId("TEST"); + + // intrumentVOInterface.setInstrumentIDAt(0, instrumentIDVOInterface); + + + // Assert.assertNotNull(map); + // Assert.assertNotNull(replicatedMap); + } + + + int t = 0; + for (; t < 5000; t++) { + if (map.equals(replicatedMap)) + break; + Thread.sleep(1); + } + + Assert.assertEquals(map, replicatedMap); + Assert.assertTrue(!replicatedMap.isEmpty()); + + System.out.println(replicatedMap.get("KEY1")); } - ChronicleMap replicatedMap = chronicleMap1; - - - //Store some data into MAP1 - TestInstrumentVOInterface intrumentVOInterface = map.newValueInstance(); - - - try (MapKeyContext wc = map.acquireContext - ("KEY1", intrumentVOInterface)) { - intrumentVOInterface.setSymbol("Flyer"); - intrumentVOInterface.setCurrencyCode("USA"); - intrumentVOInterface.setSizeOfInstrumentIDArray(2); - - // TestIntrumentVOInterface.TestInstrumentIDVOInterface instrumentIDVOInterface = - intrumentVOInterface.getInstrumentIDAt(0); - // instrumentIDVOInterface.setIdSource("CUSIP"); - // instrumentIDVOInterface.setSecurityId("TEST"); - - // intrumentVOInterface.setInstrumentIDAt(0, instrumentIDVOInterface); - - - // Assert.assertNotNull(map); - // Assert.assertNotNull(replicatedMap); - } - - - int t = 0; - for (; t < 5000; t++) { - if (map.equals(replicatedMap)) - break; - Thread.sleep(1); - } - - Assert.assertEquals(map, replicatedMap); - Assert.assertTrue(!replicatedMap.isEmpty()); - - System.out.println(((TestInstrumentVOInterface.TestInstrumentIDVOInterface) map.get - ("KEY1")).getIdSource()); - System.out.println(replicatedMap.get("KEY1")); - - map.close(); - replicatedMap.close(); - } protected ChronicleMap createReplicatedMap1() { diff --git a/src/test/java/net/openhft/chronicle/map/BiMapTest.java b/src/test/java/net/openhft/chronicle/map/BiMapTest.java index 65e2eb73b..946af1295 100644 --- a/src/test/java/net/openhft/chronicle/map/BiMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/BiMapTest.java @@ -1,6 +1,6 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -11,7 +11,7 @@ import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ThreadLocalRandom; import java.util.function.BiFunction; -import static net.openhft.chronicle.hash.Value.bytesEquivalent; +import static net.openhft.chronicle.hash.Data.bytesEquivalent; import static net.openhft.chronicle.map.BiMapTest.DualLockSuccess.FAIL; import static net.openhft.chronicle.map.BiMapTest.DualLockSuccess.SUCCESS; import static org.junit.Assert.assertEquals; @@ -40,7 +40,7 @@ public class BiMapTest { } @Override - public void put(MapQueryContext q, Value 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, Value 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, Value value) { + public boolean remove(MapQueryContext q, net.openhft.chronicle.hash.Data value) { while (true) { q.updateLock().lock(); MapEntry entry = q.entry(); @@ -116,14 +116,14 @@ public class BiMapTest { } @Override - public void replace(MapQueryContext q, Value value, + public void replace(MapQueryContext q, Data value, ReturnValue returnValue) { throw new UnsupportedOperationException(); } @Override - public boolean replace(MapQueryContext q, Value oldValue, - Value 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, Value 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, Value newValue) { + public DualLockSuccess replaceValue(@NotNull MapEntry entry, Data newValue) { throw new UnsupportedOperationException(); } @Override public DualLockSuccess insert(@NotNull MapAbsentEntry absentEntry, - Value 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 { - Value 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/ChronicleMapSanityCheckTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapSanityCheckTest.java new file mode 100644 index 000000000..2706a4b08 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapSanityCheckTest.java @@ -0,0 +1,117 @@ +/* + * Copyright 2014 Higher Frequency Trading http://www.higherfrequencytrading.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.openhft.chronicle.map; + +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Random; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +/** + * Created by Borislav Ivanov on 5/29/15. + */ +public class ChronicleMapSanityCheckTest { + + enum DummyValue { + DUMMY_VALUE + } + + @Test + public void testSanity1() throws IOException, InterruptedException + { + + String tmp = System.getProperty("java.io.tmpdir"); + + String pathname = tmp + "/testSanity1-" + UUID.randomUUID().toString() + ".dat"; + + File file = new File(pathname); + + System.out.println("Starting sanity test 1. Chronicle file :" + + file.getAbsolutePath().toString()); + + ScheduledExecutorService producerExecutor = + Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() - 1); + + ScheduledExecutorService consumerExecutor = + Executors.newSingleThreadScheduledExecutor(); + + int N = 1000; + + int producerPeriod = 100; + TimeUnit producerTimeUnit = TimeUnit.MILLISECONDS; + + int consumerPeriod = 100; + TimeUnit consumerTimeUnit = TimeUnit.MILLISECONDS; + + int totalTestTimeMS = (consumerPeriod + producerPeriod) * 20; + + try (ChronicleMap map = + ChronicleMapBuilder.of(String.class, DummyValue.class) + .entries(N) + .createPersistedTo(file)) { + + map.clear(); + + producerExecutor.scheduleAtFixedRate(() -> { + + Thread.currentThread().setName("Producer " + Thread.currentThread().getId()); + Random r = new Random(); + + System.out.println("Before PRODUCING size is " + map.size()); + for (int i = 0; i < N; i++) { + LockSupport.parkNanos(r.nextInt(5)); + map.put(String.valueOf(i), DummyValue.DUMMY_VALUE); + } + System.out.println("After PRODUCING size is " + map.size()); + + }, 0, producerPeriod, producerTimeUnit); + + consumerExecutor.scheduleAtFixedRate(() -> { + + Thread.currentThread().setName("Consumer"); + Set keys = map.keySet(); + + Random r = new Random(); + + System.out.println("Before CONSUMING size is " + map.size()); + System.out.println(); + for (String key : keys) { + if (r.nextBoolean()) { + map.remove(key); + } + } + + System.out.println("After CONSUMING size is " + map.size()); + + }, 0, consumerPeriod, consumerTimeUnit); + + Thread.sleep(totalTestTimeMS); + + consumerExecutor.shutdown(); + producerExecutor.shutdown(); + } + + } + +} diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java index 245508b52..2669f3901 100755 --- a/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/ChronicleMapTest.java @@ -210,7 +210,6 @@ public class ChronicleMapTest { } } - @Ignore("HCOLL-265 Chronicle Maps with Identical byte[] & char[] values are not equal") @Test public void testEqualsCharArray() throws Exception { @@ -233,7 +232,6 @@ public class ChronicleMapTest { } - @Ignore("HCOLL-265 Chronicle Maps with Identical byte[] & char[] values are not equal") @Test public void testEqualsByteArray() throws Exception { diff --git a/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java b/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java index 9bc21852f..fb853b8ef 100644 --- a/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java +++ b/src/test/java/net/openhft/chronicle/map/DefaultValueTest.java @@ -18,7 +18,6 @@ package net.openhft.chronicle.map; -import org.junit.Ignore; import org.junit.Test; import java.io.File; diff --git a/src/test/java/net/openhft/chronicle/map/GuavaTest.java b/src/test/java/net/openhft/chronicle/map/GuavaTest.java index 8d2eeb3eb..26802a58e 100644 --- a/src/test/java/net/openhft/chronicle/map/GuavaTest.java +++ b/src/test/java/net/openhft/chronicle/map/GuavaTest.java @@ -26,7 +26,7 @@ import com.google.common.collect.testing.features.CollectionSize; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import org.jetbrains.annotations.NotNull; import org.junit.Assert; @@ -141,7 +141,7 @@ public class GuavaTest extends TestCase { @Override public Void replaceValue(@NotNull MapEntry entry, - Value 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, - Value 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 523ec480c..9d1c03713 100644 --- a/src/test/java/net/openhft/chronicle/map/ListenersTest.java +++ b/src/test/java/net/openhft/chronicle/map/ListenersTest.java @@ -1,6 +1,6 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.map.impl.NullReturnValue; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -23,13 +23,13 @@ public class ListenersTest { return MapEntryOperations.super.remove(entry); } @Override - public Void replaceValue(@NotNull MapEntry entry, Value newValue) { + public Void replaceValue(@NotNull MapEntry entry, Data newValue) { replaceValueCount.incrementAndGet(); return MapEntryOperations.super.replaceValue(entry, newValue); } @Override - public Void insert(@NotNull MapAbsentEntry absentEntry, Value 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, - Value 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 bf4f38f42..346149e8a 100644 --- a/src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java +++ b/src/test/java/net/openhft/chronicle/map/LoggingMapEntryOperations.java @@ -18,7 +18,7 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +28,7 @@ class LoggingMapEntryOperations implements MapEntryOperations static final Logger LOG = LoggerFactory.getLogger(LoggingMapEntryOperations.class); @Override - public Void replaceValue(@NotNull MapEntry entry, Value 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/MaximizingValueRemoteOperations.java b/src/test/java/net/openhft/chronicle/map/MaximizingValueRemoteOperations.java index 5fe2bf3f8..de89d846d 100644 --- a/src/test/java/net/openhft/chronicle/map/MaximizingValueRemoteOperations.java +++ b/src/test/java/net/openhft/chronicle/map/MaximizingValueRemoteOperations.java @@ -19,7 +19,7 @@ package net.openhft.chronicle.map; import net.openhft.chronicle.hash.AcceptanceDecision; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.map.replication.MapRemoteOperations; import net.openhft.chronicle.map.replication.MapRemoteQueryContext; import net.openhft.chronicle.map.replication.MapReplicableEntry; @@ -32,7 +32,7 @@ public class MaximizingValueRemoteOperations, implements MapRemoteOperations { @Override - public AcceptanceDecision put(MapRemoteQueryContext q, Value newValue) { + public AcceptanceDecision put(MapRemoteQueryContext q, Data newValue) { MapReplicableEntry entry = q.entry(); if (entry != null) { int compareResult = newValue.get().compareTo(entry.value().get()); diff --git a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java index d76acf671..05f4cf0dd 100644 --- a/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java +++ b/src/test/java/net/openhft/chronicle/map/ReplicationCheckingMap.java @@ -18,7 +18,6 @@ package net.openhft.chronicle.map; -import net.openhft.chronicle.hash.Value; import net.openhft.chronicle.hash.function.SerializableFunction; import org.jetbrains.annotations.NotNull; import org.junit.Assert; @@ -295,7 +294,7 @@ public class ReplicationCheckingMap implements ChronicleMap { @NotNull @Override - public ExternalMapQueryContext queryContext(Value key) { + public ExternalMapQueryContext queryContext(net.openhft.chronicle.hash.Data key) { throw new UnsupportedOperationException(); } diff --git a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java index fe1e394be..8d229f7ff 100644 --- a/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/TCPSocketReplicationTest.java @@ -137,7 +137,6 @@ public class TCPSocketReplicationTest { waitTillEqual(5000); assertEquals(map1, map2); - assertTrue(!map1.isEmpty()); } @Test @@ -185,6 +184,7 @@ public class TCPSocketReplicationTest { Map map1UnChanged = new HashMap(); Map map2UnChanged = new HashMap(); + long startTime = System.currentTimeMillis(); int numberOfTimesTheSame = 0; for (int t = 0; t < timeOutMs + 100; t++) { if (map1.equals(map2)) { @@ -196,13 +196,15 @@ public class TCPSocketReplicationTest { map2UnChanged = new HashMap(map2); } Thread.sleep(1); - if (numberOfTimesTheSame == 100) { + if (numberOfTimesTheSame == 10) { System.out.println("same"); break; } } Thread.sleep(1); + if (System.currentTimeMillis() - startTime > timeOutMs) + break; } } diff --git a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java index 3daef1239..768002e8b 100644 --- a/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java +++ b/src/test/java/net/openhft/chronicle/map/TcpReplicationSoakTest.java @@ -141,6 +141,7 @@ public class TcpReplicationSoakTest { Map map2UnChanged = new HashMap(); int numberOfTimesTheSame = 0; + long startTime = System.currentTimeMillis(); for (int t = 0; t < timeOutMs + 100; t++) { if (map1.equals(map2)) { if (map1.equals(map1UnChanged) && map2.equals(map2UnChanged)) { @@ -151,13 +152,15 @@ public class TcpReplicationSoakTest { map2UnChanged = new HashMap(map2); } Thread.sleep(1); - if (numberOfTimesTheSame == 100) { + if (numberOfTimesTheSame == 10) { System.out.println("same"); break; } } Thread.sleep(1); + if (System.currentTimeMillis() - startTime > timeOutMs) + break; } } } diff --git a/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java b/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java index 4edcec24b..e489f461b 100644 --- a/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/TimeBasedReplicationTest.java @@ -99,7 +99,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase { waitTillEqual(map, map2, 5000); assertEquals(map.size(), 1); // prove that late update to map2 ignored - assertEquals(map.get("key-1"), "value-1"); + assertEquals("value-1", map.get("key-1")); } } } @@ -218,7 +218,7 @@ public class TimeBasedReplicationTest extends JSR166TestCase { // we'll now flip the time back to the current in order to do the read the result current(timeProvider); waitTillEqual(map, map2, 5000); - assertEquals(map.size(), 0); + assertEquals("map: " + map + ", map2: " + map2, 0, map.size()); // prove that late put was ignored assertEquals(null, map.get("key-1")); } @@ -231,6 +231,6 @@ public class TimeBasedReplicationTest extends JSR166TestCase { private void late(TimeProvider timeProvider) { Mockito.when(timeProvider.currentTime()) - .thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(5)); + .thenReturn(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(10)); } } diff --git a/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java index ba4614e19..21b049bdd 100644 --- a/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java @@ -80,7 +80,7 @@ public class UDPSocketReplicationTest { public void testBufferOverflow() throws IOException, InterruptedException { for (int i = 0; i < 1024; i++) { - Thread.sleep(5000); + Thread.sleep(5); map2.put(i * 2, "E"); System.out.println("" + map2); } 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 f5a64fd73..727e388b7 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 @@ -18,7 +18,7 @@ package net.openhft.chronicle.map.jsr166.map; -import net.openhft.chronicle.hash.Value; +import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.function.SerializableFunction; import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig; import net.openhft.chronicle.map.*; @@ -123,7 +123,7 @@ public class StatelessChronicleMapTest extends JSR166TestCase { @NotNull @Override - public ExternalMapQueryContext queryContext(Value key) { + public ExternalMapQueryContext queryContext(Data key) { return d.queryContext(key); } diff --git a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java index f568c1c43..485851c70 100644 --- a/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java +++ b/src/test/java/net/openhft/chronicle/set/SetForTCPSocketReplication3wayTest.java @@ -39,7 +39,6 @@ import static org.junit.Assert.assertTrue; * * @author Rob Austin. */ -@Ignore public class SetForTCPSocketReplication3wayTest { private ChronicleSet set1; diff --git a/src/test/java/net/openhft/lang/values/DoubleArrayTest.java b/src/test/java/net/openhft/lang/values/DoubleArrayTest.java index 1a466daa6..7ceb3c38e 100755 --- a/src/test/java/net/openhft/lang/values/DoubleArrayTest.java +++ b/src/test/java/net/openhft/lang/values/DoubleArrayTest.java @@ -68,6 +68,7 @@ public class DoubleArrayTest { } @Test + @Ignore public void addToAMap2() { DoubleArray.HACK = false; DoubleArray a = new DoubleArray(10); @@ -76,7 +77,8 @@ public class DoubleArrayTest { DoubleArray b = new DoubleArray(10); b.setData(new double[]{5, 6, 7, 8, 9}); - ChronicleMap proxyMap = ChronicleMapBuilder.of(Integer.class, DoubleArray.class) + ChronicleMap proxyMap = ChronicleMapBuilder + .of(Integer.class, DoubleArray.class) .averageValueSize(6 * 8) .create(); proxyMap.put(1, a);