Fixed some bugs in VanillaChronicleMap & ReplicatedChronicleMap

This commit is contained in:
leventov
2015-01-19 07:10:50 +07:00
parent dda6fcbaa7
commit ffb239fc94
3 changed files with 26 additions and 11 deletions
@@ -409,6 +409,12 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
}
}
@Override
boolean freeListBitsSet() {
// As of now, ReplicatedChMap's remove() never clear the bits
return true;
}
@Override
void initPutDependencies() {
super.initPutDependencies();
@@ -21,10 +21,15 @@ package net.openhft.chronicle.map;
import net.openhft.chronicle.hash.KeyContext;
import net.openhft.chronicle.hash.serialization.BytesReader;
import net.openhft.chronicle.hash.serialization.SizeMarshaller;
import net.openhft.chronicle.hash.serialization.internal.*;
import net.openhft.chronicle.hash.serialization.internal.BytesBytesInterop;
import net.openhft.chronicle.hash.serialization.internal.DelegatingMetaBytesInterop;
import net.openhft.chronicle.hash.serialization.internal.MetaBytesInterop;
import net.openhft.chronicle.hash.serialization.internal.MetaProvider;
import net.openhft.chronicle.map.VanillaContext.ContextFactory;
import net.openhft.lang.Jvm;
import net.openhft.lang.io.*;
import net.openhft.lang.io.Bytes;
import net.openhft.lang.io.BytesStore;
import net.openhft.lang.io.MappedStore;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.model.DataValueClasses;
import net.openhft.lang.threadlocal.Provider;
@@ -39,7 +44,6 @@ import java.io.ObjectInputStream;
import java.nio.channels.FileChannel;
import static java.lang.Long.numberOfTrailingZeros;
import static java.lang.Long.valueOf;
import static java.lang.Math.max;
import static net.openhft.chronicle.map.ChronicleMapBuilder.RUNTIME_PAGE_SIZE;
import static net.openhft.chronicle.map.ChronicleMapBuilder.greatestCommonDivisor;
@@ -1458,9 +1458,9 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
entrySizeInChunks = 0;
}
void checkUpdateLocked() {
void updateLockIfNeeded() {
if (!isUpdateLocked())
throw new IllegalStateException("At least update lock should be held");
updateLock().lock();
}
public boolean put(V newValue) {
@@ -1476,7 +1476,7 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
void initPutDependencies() {
initLocks();
checkUpdateLocked();
updateLockIfNeeded();
initKeySearch();
initValueModel();
initKeyModel();
@@ -1547,13 +1547,13 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
m.maxChunksPerEntry + " is maximum.");
}
if (freeList.allClear(pos + entrySizeInChunks, pos + newSizeInChunks)) {
long setFrom = state == PRESENT ? pos + entrySizeInChunks : pos;
long setFrom = freeListBitsSet() ? pos + entrySizeInChunks : pos;
freeList.set(setFrom, pos + newSizeInChunks);
break newValueDoesNotFit;
}
// RELOCATION
beforeRelocation();
if (state == PRESENT)
if (freeListBitsSet())
free(pos, entrySizeInChunks);
int allocatedChunks =
inChunks(innerEntrySize(newSizeOfEverythingBeforeValue, newValueSize));
@@ -1564,7 +1564,7 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
return;
} else if (newSizeInChunks < entrySizeInChunks) {
// Freeing extra chunks
if (state == PRESENT)
if (freeListBitsSet())
freeList.clear(pos + newSizeInChunks, pos + entrySizeInChunks);
lesserChunks = newSizeInChunks;
// Do NOT reset nextPosToSearchFrom, because if value
@@ -1600,7 +1600,8 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
}
writeNewValueAndSwitch();
if (state != PRESENT) {
freeList.set(pos, entrySizeInChunks);
if (!freeListBitsSet())
freeList.set(pos, pos + entrySizeInChunks);
size(size() + 1L);
beforePutPos();
hashLookup.putVolatile(pos);
@@ -1609,6 +1610,10 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
freeExtraAllocatedChunks(lesserChunks);
}
boolean freeListBitsSet() {
return state == PRESENT;
}
void beforeRelocation() {
}
@@ -1654,7 +1659,7 @@ class VanillaContext<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
void initRemoveDependencies() {
initSegment();
initLocks();
checkUpdateLocked();
updateLockIfNeeded();
}
void closeRemove() {