Skip to content

Commit

Permalink
Merge pull request #498 from OpenHFT/remove-internalNumberBuffer
Browse files Browse the repository at this point in the history
Remove internalNumberBuffer
  • Loading branch information
peter-lawrey authored Oct 30, 2023
2 parents 9269d4d + bf1d65f commit 79f6c10
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 106 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<artifactId>chronicle-core</artifactId>
</dependency>

<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bytes</artifactId>
</dependency>

<dependency>
<groupId>net.openhft</groupId>
<artifactId>posix</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ public VanillaChronicleHash(@NotNull final ChronicleMapBuilder<K, ?> builder) {

preShutdownAction = privateAPI.getPreShutdownAction();
skipCloseOnExitHook = privateAPI.skipCloseOnExitHook();

disableThreadSafetyCheck(true);
}

public static IOException throwRecoveryOrReturnIOException(@NotNull final File file,
Expand Down Expand Up @@ -934,8 +932,7 @@ private void allocateTierBulk() {
globalMutableState.addDataStoreSize(tierBulkSizeInBytes);
}

// TODO: x.25 remove throws IOException
public void msync() throws IOException {
public void msync() {
throwExceptionIfClosed();

if (persisted()) {
Expand Down Expand Up @@ -1073,7 +1070,8 @@ private void mapTierBulksMapped(final int upToBulkIndex) throws IOException {
* @see net.openhft.chronicle.bytes.MappedFile#acquireByteStore(ReferenceOwner, long, BytesStore, MappedBytesStoreFactory)
*/
private BytesStore map(long mapSize, final long mappingOffsetInFile) throws IOException {
mapSize = pageAlign(mapSize);
int pageSize = (int) OS.mapAlignment();
mapSize = pageAlign(mapSize, pageSize);
final long minFileSize = mappingOffsetInFile + mapSize;
final FileChannel fileChannel = raf.getChannel();
if (fileChannel.size() < minFileSize) {
Expand All @@ -1094,7 +1092,7 @@ private BytesStore map(long mapSize, final long mappingOffsetInFile) throws IOEx
fallocate(mappingOffsetInFile, minFileSize - mappingOffsetInFile);
}
}
final long address = OS.map(fileChannel, READ_WRITE, mappingOffsetInFile, mapSize);
final long address = OS.map(fileChannel, READ_WRITE, mappingOffsetInFile, mapSize, pageSize);
resources.addMemoryResource(address, mapSize);
return BytesStore.wrap(address, mapSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

import static net.openhft.chronicle.bytes.NoBytesStore.NO_BYTES_STORE;

@Staged
public class InputKeyBytesData<K> extends AbstractData<K> {

Expand Down Expand Up @@ -66,7 +64,7 @@ void initInputKeyBytes() {
}

void closeInputKeyBytes() {
inputKeyBytes.bytesStore(NO_BYTES_STORE, 0, 0);
inputKeyBytes.bytesStore(BytesStore.empty(), 0, 0);
inputKeyBytesUsed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package net.openhft.chronicle.hash.impl.util;

import net.openhft.chronicle.core.CleaningRandomAccessFile;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.io.CleaningRandomAccessFile;
import net.openhft.chronicle.hash.ChronicleFileLockException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void writeTo(RandomDataOutput target, long targetOffset) {
target.capacity() - targetOffset);
targetBytes.writePosition(targetOffset);
instance.writeMarshallable(targetBytes);
targetBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
targetBytes.bytesStore(BytesStore.empty(), 0, 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void writeTo(RandomDataOutput target, long targetOffset) {
targetBytes.bytesStore((BytesStore) target, targetOffset, size);
targetBytes.writePosition(targetOffset);
sizedWriter.write(targetBytes, size, instance);
targetBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
targetBytes.bytesStore(BytesStore.empty(), 0, 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
package net.openhft.chronicle.map.impl;

import net.openhft.chronicle.hash.AbstractData;
import net.openhft.chronicle.algo.bytes.Access;
import net.openhft.chronicle.hash.impl.stage.entry.Alloc;
import java.util.ArrayList;
import java.util.function.BiFunction;
import net.openhft.chronicle.hash.impl.BigSegmentHeader;
import net.openhft.chronicle.algo.MemoryUnit;
import net.openhft.chronicle.algo.bitset.BitSetFrame;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.bytes.BytesUtil;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.ChecksumEntry;
import net.openhft.chronicle.hash.impl.stage.entry.ChecksumStrategy;
import net.openhft.chronicle.hash.ChronicleHash;
import net.openhft.chronicle.hash.ChronicleHashCorruption;
import net.openhft.chronicle.map.ChronicleHashCorruptionImpl;
import net.openhft.chronicle.hash.ChronicleHashRecoveryFailedException;
import net.openhft.chronicle.map.ChronicleMap;
import net.openhft.chronicle.set.ChronicleSet;
import net.openhft.chronicle.hash.impl.CompactOffHeapLinearHashTable;
import java.util.ConcurrentModificationException;
import java.util.function.Consumer;
import net.openhft.chronicle.hash.Data;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.map.ExternalMapQueryContext;
import net.openhft.chronicle.hash.HashEntry;
import net.openhft.chronicle.hash.HashSegmentContext;
import net.openhft.chronicle.algo.bitset.ReusableBitSet;
import net.openhft.chronicle.algo.bitset.SingleThreadedFlatBitSetFrame;
import net.openhft.chronicle.algo.bytes.Access;
import net.openhft.chronicle.algo.hashing.LongHashFunction;
import net.openhft.chronicle.bytes.*;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.hash.*;
import net.openhft.chronicle.hash.impl.*;
import net.openhft.chronicle.hash.impl.stage.entry.*;
import net.openhft.chronicle.hash.impl.stage.hash.ChainingInterface;
import net.openhft.chronicle.hash.impl.util.Objects;
import net.openhft.chronicle.hash.locks.InterProcessDeadLockException;
import net.openhft.chronicle.hash.locks.InterProcessLock;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.hash.impl.stage.entry.KeyHashCode;
import java.util.List;
import net.openhft.chronicle.hash.impl.LocalLockState;
import net.openhft.chronicle.hash.impl.stage.entry.LocksInterface;
import net.openhft.chronicle.algo.hashing.LongHashFunction;
import net.openhft.chronicle.map.MapAbsentEntry;
import net.openhft.chronicle.map.MapContext;
import net.openhft.chronicle.map.MapEntry;
import net.openhft.chronicle.algo.MemoryUnit;
import net.openhft.chronicle.bytes.NoBytesStore;
import net.openhft.chronicle.hash.impl.stage.entry.NoChecksumStrategy;
import org.jetbrains.annotations.NotNull;
import net.openhft.chronicle.hash.impl.util.Objects;
import net.openhft.chronicle.bytes.PointerBytesStore;
import java.util.function.Predicate;
import net.openhft.chronicle.bytes.RandomDataInput;
import net.openhft.chronicle.algo.bitset.ReusableBitSet;
import net.openhft.chronicle.hash.impl.SegmentHeader;
import net.openhft.chronicle.hash.SegmentLock;
import net.openhft.chronicle.set.SetContext;
import net.openhft.chronicle.algo.bitset.SingleThreadedFlatBitSetFrame;
import net.openhft.chronicle.hash.serialization.DataAccess;
import net.openhft.chronicle.hash.serialization.SizedReader;
import net.openhft.chronicle.hash.impl.TierCountersArea;
import net.openhft.chronicle.map.*;
import net.openhft.chronicle.set.ChronicleSet;
import net.openhft.chronicle.set.SetContext;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import net.openhft.chronicle.bytes.VanillaBytes;
import net.openhft.chronicle.hash.impl.VanillaChronicleHash;
import net.openhft.chronicle.map.VanillaChronicleMap;
import net.openhft.chronicle.hash.VanillaGlobalMutableState;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Predicate;

import static net.openhft.chronicle.hash.impl.LocalLockState.UNLOCKED;

Expand Down Expand Up @@ -911,8 +882,8 @@ public void doCloseNext() {
public void doCloseWrappedValueBytes() {
if (!(this.wrappedValueBytesInit()))
return ;
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);

wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down Expand Up @@ -1047,7 +1018,7 @@ void closeWrappedValueBytes() {
return ;

this.closeWrappedValueBytesDependants();
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ public void doCloseCachedInputKey() {
public void doCloseInputKeyBytes() {
if (!(this.inputKeyBytesInit()))
return ;
inputKeyBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);

inputKeyBytes.bytesStore(BytesStore.empty(), 0, 0);
inputKeyBytesUsed = false;
}

Expand Down Expand Up @@ -793,7 +793,7 @@ void closeInputKeyBytes() {
return ;

this.closeInputKeyBytesDependants();
inputKeyBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
inputKeyBytes.bytesStore(BytesStore.empty(), 0, 0);
inputKeyBytesUsed = false;
}

Expand Down Expand Up @@ -1155,8 +1155,8 @@ public void doCloseNext() {
public void doCloseWrappedValueBytes() {
if (!(this.wrappedValueBytesInit()))
return ;
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);

wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down Expand Up @@ -1291,7 +1291,7 @@ void closeWrappedValueBytes() {
return ;

this.closeWrappedValueBytesDependants();
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,8 @@ public void doCloseNext() {
public void doCloseWrappedValueBytes() {
if (!(this.wrappedValueBytesInit()))
return ;
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);

wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down Expand Up @@ -1186,7 +1186,7 @@ void closeWrappedValueBytes() {
return ;

this.closeWrappedValueBytesDependants();
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ public void doCloseCachedInputKey() {
public void doCloseInputKeyBytes() {
if (!(this.inputKeyBytesInit()))
return ;
inputKeyBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);

inputKeyBytes.bytesStore(BytesStore.empty(), 0, 0);
inputKeyBytesUsed = false;
}

Expand Down Expand Up @@ -822,7 +822,7 @@ void closeInputKeyBytes() {
return ;

this.closeInputKeyBytesDependants();
inputKeyBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
inputKeyBytes.bytesStore(BytesStore.empty(), 0, 0);
inputKeyBytesUsed = false;
}

Expand Down Expand Up @@ -1215,8 +1215,8 @@ public void doCloseNext() {
public void doCloseWrappedValueBytes() {
if (!(this.wrappedValueBytesInit()))
return ;
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);

wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down Expand Up @@ -1351,7 +1351,7 @@ void closeWrappedValueBytes() {
return ;

this.closeWrappedValueBytesDependants();
wrappedValueBytes.bytesStore(NoBytesStore.NO_BYTES_STORE, 0, 0);
wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ public boolean compareAndSwapLong(long offset, long expected, long value) {
return true;
}

@Override
public byte[] internalNumberBuffer() {
throw new UnsupportedOperationException();
}

@Override
public void reserve(ReferenceOwner id) throws IllegalStateException {
}
Expand All @@ -172,11 +167,6 @@ public boolean tryReserve(ReferenceOwner id) throws IllegalStateException {
return false;
}

@Override
public boolean reservedBy(ReferenceOwner owner) {
return true;
}

@Override
public void release(ReferenceOwner id) throws IllegalStateException {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import net.openhft.sg.StageRef;
import net.openhft.sg.Staged;

import static net.openhft.chronicle.bytes.NoBytesStore.NO_BYTES_STORE;

@Staged
public class WrappedValueBytesData<V> extends AbstractData<V> {

Expand Down Expand Up @@ -95,7 +93,7 @@ void initWrappedValueBytes() {
}

void closeWrappedValueBytes() {
wrappedValueBytes.bytesStore(NO_BYTES_STORE, 0, 0);
wrappedValueBytes.bytesStore(BytesStore.empty(), 0, 0);
wrappedValueBytesUsed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ public void testByteBufferDirectByteBufferMap()
.asReadOnlyBuffer();

final ByteBuffer key2 = ByteBuffer.wrap(new byte[]{2, 2, 2, 2});
// Apparently, asReadOnlyBuffer cannot be used as keys because the backing array cannot be exposed;
// Apparently, asReadOnlyBuffer cannot be used as keys because the backing array cannot be exposed;

final ByteBuffer value1 = ((ByteBuffer) ByteBuffer.allocateDirect(4)
.put(new byte[]{11, 11, 11, 11})
Expand Down
13 changes: 5 additions & 8 deletions src/test/java/net/openhft/chronicle/map/MemoryLeaksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package net.openhft.chronicle.map;

import com.google.common.collect.Lists;
import net.openhft.chronicle.bytes.NoBytesStore;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.values.IntValue;
Expand Down Expand Up @@ -91,11 +90,6 @@ private static String named(final List<Boolean> flags) {
(!flags.get(2) ? "not " : "") + "closed within context";
}

@Before
public void initNoBytesStore() {
Assert.assertNotEquals(0, NoBytesStore.NO_PAGE);
}

@Before
public void resetSerializerCount() {
System.err.println("This test is expect to print 'ChronicleMap ... is not closed manually, cleaned up from Cleaner'");
Expand All @@ -120,8 +114,11 @@ public void testChronicleMapCollectedAndDirectMemoryReleased() throws IOExceptio
// the purpose of the test is to find maps which are not closed properly.
ChronicleMap<IntValue, String> map = getMap();
long expectedNativeMemory = nativeMemoryUsedBeforeMap + map.offHeapMemoryUsed();
assertEquals(expectedNativeMemory, nativeMemoryUsed());
tryCloseFromContext(map);
try {
assertEquals(expectedNativeMemory, nativeMemoryUsed());
} finally {
tryCloseFromContext(map);
}
WeakReference<ChronicleMap<IntValue, String>> ref = new WeakReference<>(map);
Assert.assertNotNull(ref.get());
//noinspection UnusedAssignment
Expand Down
Loading

0 comments on commit 79f6c10

Please sign in to comment.