This is an automated email from the ASF dual-hosted git repository. leerho pushed a commit to branch CreateInternal2 in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit 4d357ed5dfa84193d855553047124242dc3a7dc2 Author: Lee Rhodes <[email protected]> AuthorDate: Mon May 17 10:04:25 2021 -0700 Refactored BaseState to BaseStateImpl, created interface BaseState. --- .../org/apache/datasketches/memory/BaseState.java | 253 +++++++++++++++++++++ .../org/apache/datasketches/memory/Memory.java | 28 +++ .../memory/internal/AllocateDirect.java | 10 +- .../memory/internal/AllocateDirectMap.java | 10 +- .../datasketches/memory/internal/BaseBuffer.java | 2 +- .../{BaseState.java => BaseStateImpl.java} | 182 +++------------ .../memory/internal/CompareAndCopy.java | 14 +- .../datasketches/memory/internal/Memory.java | 2 +- .../test/AllocateDirectWritableMapMemoryTest.java | 2 +- .../datasketches/memory/test/ReflectUtil.java | 26 +-- .../datasketches/memory/test/XxHash64Test.java | 2 +- 11 files changed, 349 insertions(+), 182 deletions(-) diff --git a/src/main/java/org/apache/datasketches/memory/BaseState.java b/src/main/java/org/apache/datasketches/memory/BaseState.java new file mode 100644 index 0000000..ac1e4f2 --- /dev/null +++ b/src/main/java/org/apache/datasketches/memory/BaseState.java @@ -0,0 +1,253 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.datasketches.memory; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import org.apache.datasketches.memory.internal.BaseStateImpl; + +/** + * Keeps key configuration state for Memory and Buffer plus some common static variables + * and check methods. + * + * @author Lee Rhodes + */ +public interface BaseState { + + //Byte Order Related + + /** + * Gets the current Type ByteOrder. + * This may be different from the ByteOrder of the backing resource and of the Native Byte Order. + * @return the current Type ByteOrder. + */ + ByteOrder getTypeByteOrder(); + + /** + * Returns true if the Native ByteOrder is the same as the ByteOrder of the + * current Buffer or Memory and the same ByteOrder as the given byteOrder. + * @param byteOrder the given ByteOrder + * @return true if the Native ByteOrder is the same as the ByteOrder of the + * current Buffer or Memory and the same ByteOrder as the given byteOrder. + */ + boolean isByteOrderCompatible(final ByteOrder byteOrder); + + /** + * Returns true if the given object is an instance of this class and has equal data contents. + * @param that the given object + * @return true if the given Object is an instance of this class and has equal data contents. + */ + @Override + boolean equals(final Object that); + + /** + * Returns true if the given object is an instance of this class and has equal contents to + * this object in the given range of bytes. This will also check two distinct ranges within the + * same object for eauals. + * @param thisOffsetBytes the starting offset in bytes for this object. + * @param that the given object + * @param thatOffsetBytes the starting offset in bytes for the given object + * @param lengthBytes the size of the range in bytes + * @return true if the given object has equal contents to this object in the given range of + * bytes. + */ + boolean equalTo(final long thisOffsetBytes, final Object that, + final long thatOffsetBytes, final long lengthBytes); + + /** + * Gets the backing ByteBuffer if it exists, otherwise returns null. + * @return the backing ByteBuffer if it exists, otherwise returns null. + */ + ByteBuffer getByteBuffer(); + + /** + * Gets the capacity of this object in bytes + * @return the capacity of this object in bytes + */ + long getCapacity(); + + /** + * Gets the cumulative offset in bytes of this object from the backing resource. + * This offset may also include other offset components such as the native off-heap + * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets. + * + * @return the cumulative offset in bytes of this object from the backing resource. + */ + long getCumulativeOffset(); + + /** + * Gets the cumulative offset in bytes of this object from the backing resource including the given + * offsetBytes. This offset may also include other offset components such as the native off-heap + * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets. + * + * @param offsetBytes offset to be added to the cumulative offset. + * @return the cumulative offset in bytes of this object from the backing resource including the + * given offsetBytes. + */ + long getCumulativeOffset(final long offsetBytes); + + /** + * Returns the offset of address zero of this object relative to the address zero of the + * backing resource but not including the size of any Java object header. + * @return the offset of address zero of this object relative to the address zero of the + * backing resource but not including the size of any Java object header. + */ + long getRegionOffset(); + + /** + * Returns the offset of address zero of this object relative to the address zero of the + * backing resource plus the given offsetBytes but not including the size of any Java object + * header. + * @param offsetBytes the given offsetBytes + * @return the offset of address zero of this object relative to the address zero of the + * backing resource plus the given offsetBytes but not including the size of any Java object + * header. + */ + long getRegionOffset(final long offsetBytes); + + /** + * Returns true if this object is backed by an on-heap primitive array + * @return true if this object is backed by an on-heap primitive array + */ + boolean hasArray(); + + /** + * Returns the hashCode of this object. + * + * <p>The hash code of this object depends upon all of its contents. + * Because of this, it is inadvisable to use these objects as keys in hash maps + * or similar data structures unless it is known that their contents will not change.</p> + * + * <p>If it is desirable to use these objects in a hash map depending only on object identity, + * than the {@link java.util.IdentityHashMap} can be used.</p> + * + * @return the hashCode of this object. + */ + @Override + int hashCode(); + + /** + * Returns the 64-bit hash of the sequence of bytes in this object specified by + * <i>offsetBytes</i>, <i>lengthBytes</i> and a <i>seed</i>. Note that the sequence of bytes is + * always processed in the same order independent of endianness. + * + * @param offsetBytes the given offset in bytes to the first byte of the byte sequence. + * @param lengthBytes the given length in bytes of the byte sequence. + * @param seed the given long seed. + * @return the 64-bit hash of the sequence of bytes in this object specified by + * <i>offsetBytes</i> and <i>lengthBytes</i>. + */ + long xxHash64(final long offsetBytes, final long lengthBytes, final long seed); + + /** + * Returns true if this Memory is backed by a ByteBuffer. + * @return true if this Memory is backed by a ByteBuffer. + */ + boolean hasByteBuffer(); + + /** + * Returns true if the backing resource is direct (off-heap) memory. + * This is the case for allocated direct memory, memory mapped files, + * @return true if the backing resource is direct (off-heap) memory. + */ + boolean isDirect(); + + /** + * Returns true if this object or the backing resource is read-only. + * @return true if this object or the backing resource is read-only. + */ + boolean isReadOnly(); + + /** + * Returns true if the backing resource of <i>this</i> is identical with the backing resource + * of <i>that</i>. The capacities must be the same. If <i>this</i> is a region, + * the region offset must also be the same. + * @param that A different non-null object + * @return true if the backing resource of <i>this</i> is the same as the backing resource + * of <i>that</i>. + */ + boolean isSameResource(final Object that); + + /** + * Returns true if this object is valid and has not been closed. + * This is relevant only for direct (off-heap) memory and Mapped Files. + * @return true if this object is valid and has not been closed. + */ + boolean isValid(); + + /** + * Checks that the specified range of bytes is within bounds of this object, throws + * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes < 0, or length < 0, + * or offsetBytes + length > {@link #getCapacity()}. + * @param offsetBytes the given offset in bytes of this object + * @param lengthBytes the given length in bytes of this object + */ + void checkValidAndBounds(final long offsetBytes, final long lengthBytes); + + //Monitoring + + /** + * Gets the current number of active direct memory allocations. + * @return the current number of active direct memory allocations. + */ + static long getCurrentDirectMemoryAllocations() { + return BaseStateImpl.getCurrentDirectMemoryAllocations(); + } + + /** + * Gets the current size of active direct memory allocated. + * @return the current size of active direct memory allocated. + */ + static long getCurrentDirectMemoryAllocated() { + return BaseStateImpl.getCurrentDirectMemoryAllocated(); + } + + /** + * Gets the current number of active direct memory map allocations. + * @return the current number of active direct memory map allocations. + */ + static long getCurrentDirectMemoryMapAllocations() { + return BaseStateImpl.getCurrentDirectMemoryMapAllocations(); + } + + /** + * Gets the current size of active direct memory map allocated. + * @return the current size of active direct memory map allocated. + */ + static long getCurrentDirectMemoryMapAllocated() { + return BaseStateImpl.getCurrentDirectMemoryMapAllocated(); + } + + //TO STRING + + /** + * Returns a formatted hex string of a range of this object. + * Used primarily for testing. + * @param header a descriptive header + * @param offsetBytes offset bytes relative to this object start + * @param lengthBytes number of bytes to convert to a hex string + * @return a formatted hex string in a human readable array + */ + String toHexString(final String header, final long offsetBytes, + final int lengthBytes); + +} diff --git a/src/main/java/org/apache/datasketches/memory/Memory.java b/src/main/java/org/apache/datasketches/memory/Memory.java new file mode 100644 index 0000000..b170ad9 --- /dev/null +++ b/src/main/java/org/apache/datasketches/memory/Memory.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.datasketches.memory; + + +public interface Memory { + +} + + diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java index 97cdaf1..aef0b98 100644 --- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java +++ b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirect.java @@ -88,7 +88,7 @@ final class AllocateDirect implements AutoCloseable { return false; } finally { - BaseState.reachabilityFence(this); + BaseStateImpl.reachabilityFence(this); } } @@ -108,8 +108,8 @@ final class AllocateDirect implements AutoCloseable { private final StepBoolean valid = new StepBoolean(true); //only place for this private Deallocator(final long nativeAddress, final long allocationSize, final long capacity) { - BaseState.currentDirectMemoryAllocations_.incrementAndGet(); - BaseState.currentDirectMemoryAllocated_.addAndGet(capacity); + BaseStateImpl.currentDirectMemoryAllocations_.incrementAndGet(); + BaseStateImpl.currentDirectMemoryAllocated_.addAndGet(capacity); this.nativeAddress = nativeAddress; this.allocationSize = allocationSize; this.capacity = capacity; @@ -133,8 +133,8 @@ final class AllocateDirect implements AutoCloseable { } unsafe.freeMemory(nativeAddress); NioBits.unreserveMemory(allocationSize, capacity); - BaseState.currentDirectMemoryAllocations_.decrementAndGet(); - BaseState.currentDirectMemoryAllocated_.addAndGet(-capacity); + BaseStateImpl.currentDirectMemoryAllocations_.decrementAndGet(); + BaseStateImpl.currentDirectMemoryAllocated_.addAndGet(-capacity); return true; } return false; diff --git a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java index eaa2d38..b5528a5 100644 --- a/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java +++ b/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java @@ -167,7 +167,7 @@ class AllocateDirectMap implements Map { } return false; } finally { - BaseState.reachabilityFence(this); + BaseStateImpl.reachabilityFence(this); } } @@ -257,8 +257,8 @@ class AllocateDirectMap implements Map { Deallocator(final long nativeBaseOffset, final long capacityBytes, final RandomAccessFile raf) { - BaseState.currentDirectMemoryMapAllocations_.incrementAndGet(); - BaseState.currentDirectMemoryMapAllocated_.addAndGet(capacityBytes); + BaseStateImpl.currentDirectMemoryMapAllocations_.incrementAndGet(); + BaseStateImpl.currentDirectMemoryMapAllocated_.addAndGet(capacityBytes); myRaf = raf; assert myRaf != null; myFc = myRaf.getChannel(); @@ -287,8 +287,8 @@ class AllocateDirectMap implements Map { unmap(); } finally { - BaseState.currentDirectMemoryMapAllocations_.decrementAndGet(); - BaseState.currentDirectMemoryMapAllocated_.addAndGet(-myCapacity); + BaseStateImpl.currentDirectMemoryMapAllocations_.decrementAndGet(); + BaseStateImpl.currentDirectMemoryMapAllocated_.addAndGet(-myCapacity); } return true; } diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java b/src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java index 1b04f21..901002b 100644 --- a/src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java +++ b/src/main/java/org/apache/datasketches/memory/internal/BaseBuffer.java @@ -36,7 +36,7 @@ package org.apache.datasketches.memory.internal; * * @author Lee Rhodes */ -public abstract class BaseBuffer extends BaseState { +public abstract class BaseBuffer extends BaseStateImpl { private long capacity; private long start = 0; private long pos = 0; diff --git a/src/main/java/org/apache/datasketches/memory/internal/BaseState.java b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java similarity index 66% rename from src/main/java/org/apache/datasketches/memory/internal/BaseState.java rename to src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java index 791a31d..caa3e99 100644 --- a/src/main/java/org/apache/datasketches/memory/internal/BaseState.java +++ b/src/main/java/org/apache/datasketches/memory/internal/BaseStateImpl.java @@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.datasketches.memory.DefaultMemoryRequestServer; import org.apache.datasketches.memory.MemoryRequestServer; +import org.apache.datasketches.memory.BaseState; /** * Keeps key configuration state for Memory and Buffer plus some common static variables @@ -38,7 +39,7 @@ import org.apache.datasketches.memory.MemoryRequestServer; * @author Lee Rhodes */ @SuppressWarnings({"restriction"}) -abstract class BaseState { +public abstract class BaseStateImpl implements BaseState { //Monitoring static final AtomicLong currentDirectMemoryAllocations_ = new AtomicLong(); @@ -88,7 +89,7 @@ abstract class BaseState { * This offset does not include the size of an object array header, if there is one. * @param capacityBytes the capacity of this object. Used by all methods when checking bounds. */ - BaseState(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset, + BaseStateImpl(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset, final long capacityBytes) { capacityBytes_ = capacityBytes; cumBaseOffset_ = regionOffset + (unsafeObj == null @@ -98,11 +99,7 @@ abstract class BaseState { //Byte Order Related - /** - * Gets the current Type ByteOrder. - * This may be different from the ByteOrder of the backing resource and of the Native Byte Order. - * @return the current Type ByteOrder. - */ + @Override public final ByteOrder getTypeByteOrder() { return isNonNativeType() ? Util.nonNativeByteOrder : Util.nativeByteOrder; } @@ -119,88 +116,47 @@ abstract class BaseState { return Util.nativeByteOrder == byteOrder; } - /** - * Returns true if the Native ByteOrder is the same as the ByteOrder of the - * current Buffer or Memory and the same ByteOrder as the given byteOrder. - * @param byteOrder the given ByteOrder - * @return true if the Native ByteOrder is the same as the ByteOrder of the - * current Buffer or Memory and the same ByteOrder as the given byteOrder. - */ + @Override public final boolean isByteOrderCompatible(final ByteOrder byteOrder) { final ByteOrder typeBO = getTypeByteOrder(); return typeBO == Util.nativeByteOrder && typeBO == byteOrder; } - /** - * Returns true if the given object is an instance of this class and has equal data contents. - * @param that the given object - * @return true if the given Object is an instance of this class and has equal data contents. - */ @Override public final boolean equals(final Object that) { if (this == that) { return true; } - return that instanceof BaseState - ? CompareAndCopy.equals(this, (BaseState) that) + return that instanceof BaseStateImpl + ? CompareAndCopy.equals(this, (BaseStateImpl) that) : false; } - /** - * Returns true if the given object is an instance of this class and has equal contents to - * this object in the given range of bytes. This will also check two distinct ranges within the - * same object for eauals. - * @param thisOffsetBytes the starting offset in bytes for this object. - * @param that the given object - * @param thatOffsetBytes the starting offset in bytes for the given object - * @param lengthBytes the size of the range in bytes - * @return true if the given object has equal contents to this object in the given range of - * bytes. - */ + @Override public final boolean equalTo(final long thisOffsetBytes, final Object that, final long thatOffsetBytes, final long lengthBytes) { - return that instanceof BaseState - ? CompareAndCopy.equals(this, thisOffsetBytes, (BaseState) that, thatOffsetBytes, lengthBytes) + return that instanceof BaseStateImpl + ? CompareAndCopy.equals(this, thisOffsetBytes, (BaseStateImpl) that, thatOffsetBytes, lengthBytes) : false; } - /** - * Gets the backing ByteBuffer if it exists, otherwise returns null. - * @return the backing ByteBuffer if it exists, otherwise returns null. - */ //Overridden by ByteBuffer Leafs + @Override public ByteBuffer getByteBuffer() { return null; } - /** - * Gets the capacity of this object in bytes - * @return the capacity of this object in bytes - */ + @Override public final long getCapacity() { assertValid(); return capacityBytes_; } - /** - * Gets the cumulative offset in bytes of this object from the backing resource. - * This offset may also include other offset components such as the native off-heap - * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets. - * - * @return the cumulative offset in bytes of this object from the backing resource. - */ + @Override public final long getCumulativeOffset() { assertValid(); return cumBaseOffset_; } - /** - * Gets the cumulative offset in bytes of this object from the backing resource including the given - * offsetBytes. This offset may also include other offset components such as the native off-heap - * memory address, DirectByteBuffer split offsets, region offsets, and unsafe arrayBaseOffsets. - * - * @param offsetBytes offset to be added to the cumulative offset. - * @return the cumulative offset in bytes of this object from the backing resource including the - * given offsetBytes. - */ + @Override public final long getCumulativeOffset(final long offsetBytes) { assertValid(); return cumBaseOffset_ + offsetBytes; @@ -214,12 +170,7 @@ abstract class BaseState { return 0; } - /** - * Returns the offset of address zero of this object relative to the address zero of the - * backing resource but not including the size of any Java object header. - * @return the offset of address zero of this object relative to the address zero of the - * backing resource but not including the size of any Java object header. - */ + @Override public final long getRegionOffset() { final Object unsafeObj = getUnsafeObject(); return unsafeObj == null @@ -227,15 +178,7 @@ abstract class BaseState { : cumBaseOffset_ - UnsafeUtil.getArrayBaseOffset(unsafeObj.getClass()); } - /** - * Returns the offset of address zero of this object relative to the address zero of the - * backing resource plus the given offsetBytes but not including the size of any Java object - * header. - * @param offsetBytes the given offsetBytes - * @return the offset of address zero of this object relative to the address zero of the - * backing resource plus the given offsetBytes but not including the size of any Java object - * header. - */ + @Override public final long getRegionOffset(final long offsetBytes) { return getRegionOffset() + offsetBytes; } @@ -249,87 +192,45 @@ abstract class BaseState { return null; } - /** - * Returns true if this object is backed by an on-heap primitive array - * @return true if this object is backed by an on-heap primitive array - */ + @Override public final boolean hasArray() { assertValid(); return getUnsafeObject() != null; } - /** - * Returns the hashCode of this object. - * - * <p>The hash code of this object depends upon all of its contents. - * Because of this, it is inadvisable to use these objects as keys in hash maps - * or similar data structures unless it is known that their contents will not change.</p> - * - * <p>If it is desirable to use these objects in a hash map depending only on object identity, - * than the {@link java.util.IdentityHashMap} can be used.</p> - * - * @return the hashCode of this object. - */ @Override public final int hashCode() { return (int) xxHash64(0, capacityBytes_, 0); //xxHash64() calls checkValid() } - /** - * Returns the 64-bit hash of the sequence of bytes in this object specified by - * <i>offsetBytes</i>, <i>lengthBytes</i> and a <i>seed</i>. Note that the sequence of bytes is - * always processed in the same order independent of endianness. - * - * @param offsetBytes the given offset in bytes to the first byte of the byte sequence. - * @param lengthBytes the given length in bytes of the byte sequence. - * @param seed the given long seed. - * @return the 64-bit hash of the sequence of bytes in this object specified by - * <i>offsetBytes</i> and <i>lengthBytes</i>. - */ + @Override public final long xxHash64(final long offsetBytes, final long lengthBytes, final long seed) { checkValid(); return XxHash64.hash(getUnsafeObject(), cumBaseOffset_ + offsetBytes, lengthBytes, seed); } - /** - * Returns true if this Memory is backed by a ByteBuffer. - * @return true if this Memory is backed by a ByteBuffer. - */ + @Override public final boolean hasByteBuffer() { assertValid(); return getByteBuffer() != null; } - /** - * Returns true if the backing resource is direct (off-heap) memory. - * This is the case for allocated direct memory, memory mapped files, - * @return true if the backing resource is direct (off-heap) memory. - */ + @Override public final boolean isDirect() { return getUnsafeObject() == null; } - /** - * Returns true if this object or the backing resource is read-only. - * @return true if this object or the backing resource is read-only. - */ + @Override public final boolean isReadOnly() { assertValid(); return isReadOnlyType(); } - /** - * Returns true if the backing resource of <i>this</i> is identical with the backing resource - * of <i>that</i>. The capacities must be the same. If <i>this</i> is a region, - * the region offset must also be the same. - * @param that A different non-null object - * @return true if the backing resource of <i>this</i> is the same as the backing resource - * of <i>that</i>. - */ + @Override public final boolean isSameResource(final Object that) { checkValid(); if (that == null) { return false; } - final BaseState that1 = (BaseState) that; + final BaseStateImpl that1 = (BaseStateImpl) that; that1.checkValid(); if (this == that1) { return true; } @@ -339,12 +240,8 @@ abstract class BaseState { && getByteBuffer() == that1.getByteBuffer(); } - /** - * Returns true if this object is valid and has not been closed. - * This is relevant only for direct (off-heap) memory and Mapped Files. - * @return true if this object is valid and has not been closed. - */ //Overridden by Direct and Map leafs + @Override public boolean isValid() { return true; } @@ -377,13 +274,7 @@ abstract class BaseState { assert !isReadOnly() : "Memory is read-only."; } - /** - * Checks that the specified range of bytes is within bounds of this object, throws - * {@link IllegalArgumentException} if it's not: i. e. if offsetBytes < 0, or length < 0, - * or offsetBytes + length > {@link #getCapacity()}. - * @param offsetBytes the given offset in bytes of this object - * @param lengthBytes the given length in bytes of this object - */ + @Override public final void checkValidAndBounds(final long offsetBytes, final long lengthBytes) { checkValid(); //read capacityBytes_ directly to eliminate extra checkValid() call @@ -437,12 +328,13 @@ abstract class BaseState { } //MONITORING + /** * Gets the current number of active direct memory allocations. * @return the current number of active direct memory allocations. */ public static final long getCurrentDirectMemoryAllocations() { - return BaseState.currentDirectMemoryAllocations_.get(); + return BaseStateImpl.currentDirectMemoryAllocations_.get(); } /** @@ -450,7 +342,7 @@ abstract class BaseState { * @return the current size of active direct memory allocated. */ public static final long getCurrentDirectMemoryAllocated() { - return BaseState.currentDirectMemoryAllocated_.get(); + return BaseStateImpl.currentDirectMemoryAllocated_.get(); } /** @@ -458,7 +350,7 @@ abstract class BaseState { * @return the current number of active direct memory map allocations. */ public static final long getCurrentDirectMemoryMapAllocations() { - return BaseState.currentDirectMemoryMapAllocations_.get(); + return BaseStateImpl.currentDirectMemoryMapAllocations_.get(); } /** @@ -466,21 +358,15 @@ abstract class BaseState { * @return the current size of active direct memory map allocated. */ public static final long getCurrentDirectMemoryMapAllocated() { - return BaseState.currentDirectMemoryMapAllocated_.get(); + return BaseStateImpl.currentDirectMemoryMapAllocated_.get(); } //REACHABILITY FENCE static void reachabilityFence(@SuppressWarnings("unused") final Object obj) { } //TO STRING - /** - * Returns a formatted hex string of a range of this object. - * Used primarily for testing. - * @param header a descriptive header - * @param offsetBytes offset bytes relative to this object start - * @param lengthBytes number of bytes to convert to a hex string - * @return a formatted hex string in a human readable array - */ + + @Override public final String toHexString(final String header, final long offsetBytes, final int lengthBytes) { checkValid(); @@ -498,13 +384,13 @@ abstract class BaseState { /** * Returns a formatted hex string of an area of this object. * Used primarily for testing. - * @param state the BaseState + * @param state the BaseStateImpl * @param preamble a descriptive header * @param offsetBytes offset bytes relative to the Memory start * @param lengthBytes number of bytes to convert to a hex string * @return a formatted hex string in a human readable array */ - static final String toHex(final BaseState state, final String preamble, final long offsetBytes, + static final String toHex(final BaseStateImpl state, final String preamble, final long offsetBytes, final int lengthBytes) { final long capacity = state.getCapacity(); UnsafeUtil.checkBounds(offsetBytes, lengthBytes, capacity); diff --git a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java index fa6662a..0baf90a 100644 --- a/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java +++ b/src/main/java/org/apache/datasketches/memory/internal/CompareAndCopy.java @@ -38,8 +38,8 @@ final class CompareAndCopy { private CompareAndCopy() { } static int compare( - final BaseState state1, final long offsetBytes1, final long lengthBytes1, - final BaseState state2, final long offsetBytes2, final long lengthBytes2) { + final BaseStateImpl state1, final long offsetBytes1, final long lengthBytes1, + final BaseStateImpl state2, final long offsetBytes2, final long lengthBytes2) { state1.checkValid(); checkBounds(offsetBytes1, lengthBytes1, state1.getCapacity()); state2.checkValid(); @@ -60,7 +60,7 @@ final class CompareAndCopy { return Long.compare(lengthBytes1, lengthBytes2); } - static boolean equals(final BaseState state1, final BaseState state2) { + static boolean equals(final BaseStateImpl state1, final BaseStateImpl state2) { final long cap1 = state1.getCapacity(); final long cap2 = state2.getCapacity(); return (cap1 == cap2) && equals(state1, 0, state2, 0, cap1); @@ -70,8 +70,8 @@ final class CompareAndCopy { // stop if the arrays and offsets are the same as there is only one length. Also this can take // advantage of chunking with longs, while compare cannot. static boolean equals( - final BaseState state1, final long offsetBytes1, - final BaseState state2, final long offsetBytes2, long lengthBytes) { + final BaseStateImpl state1, final long offsetBytes1, + final BaseStateImpl state2, final long offsetBytes2, long lengthBytes) { state1.checkValid(); checkBounds(offsetBytes1, lengthBytes, state1.getCapacity()); state2.checkValid(); @@ -112,8 +112,8 @@ final class CompareAndCopy { return true; } - static void copy(final BaseState srcState, final long srcOffsetBytes, - final BaseState dstState, final long dstOffsetBytes, final long lengthBytes) { + static void copy(final BaseStateImpl srcState, final long srcOffsetBytes, + final BaseStateImpl dstState, final long dstOffsetBytes, final long lengthBytes) { srcState.checkValid(); checkBounds(srcOffsetBytes, lengthBytes, srcState.getCapacity()); dstState.checkValid(); diff --git a/src/main/java/org/apache/datasketches/memory/internal/Memory.java b/src/main/java/org/apache/datasketches/memory/internal/Memory.java index 2802aef..25fbdbb 100644 --- a/src/main/java/org/apache/datasketches/memory/internal/Memory.java +++ b/src/main/java/org/apache/datasketches/memory/internal/Memory.java @@ -41,7 +41,7 @@ import org.apache.datasketches.memory.MapHandle; * * @see org.apache.datasketches.memory.internal */ -public abstract class Memory extends BaseState { +public abstract class Memory extends BaseStateImpl { //Pass-through ctor Memory(final Object unsafeObj, final long nativeBaseOffset, final long regionOffset, diff --git a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java index f58caa4..a6b8640 100644 --- a/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java +++ b/src/test/java/org/apache/datasketches/memory/test/AllocateDirectWritableMapMemoryTest.java @@ -248,7 +248,7 @@ public class AllocateDirectWritableMapMemoryTest { @AfterClass public void checkDirectCounter() { long count = getCurrentDirectMemoryMapAllocations(); - //final long count = BaseState.getCurrentDirectMemoryMapAllocations(); + //final long count = BaseStateImpl.getCurrentDirectMemoryMapAllocations(); if (count != 0) { println(""+count); fail(); diff --git a/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java b/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java index b567aae..daea055 100644 --- a/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java +++ b/src/test/java/org/apache/datasketches/memory/test/ReflectUtil.java @@ -35,24 +35,24 @@ public final class ReflectUtil { static final Class<?> ALLOCATE_DIRECT_MAP; static final Class<?> NIO_BITS; - static final Method CHECK_VALID; //BaseState + static final Method CHECK_VALID; //BaseStateImpl static final Method GET_DIRECT_ALLOCATIONS_COUNT; //NioBits static final Method GET_MAX_DIRECT_BYTE_BUFFER_MEMORY; //NioBits - static final Method GET_NATIVE_BASE_OFFSET; //BaseState + static final Method GET_NATIVE_BASE_OFFSET; //BaseStateImpl static final Method GET_RESERVED_MEMORY; //NioBits static final Method GET_TOTAL_CAPACITY; //NioBits - static final Method GET_UNSAFE_OBJECT; //BaseState - static final Method IS_BB_TYPE; //BaseState - static final Method IS_BUFFER_TYPE; //BaseState - static final Method IS_DIRECT_TYPE; //BaseState - static final Method IS_DUPLICATE_TYPE; //BaseState + static final Method GET_UNSAFE_OBJECT; //BaseStateImpl + static final Method IS_BB_TYPE; //BaseStateImpl + static final Method IS_BUFFER_TYPE; //BaseStateImpl + static final Method IS_DIRECT_TYPE; //BaseStateImpl + static final Method IS_DUPLICATE_TYPE; //BaseStateImpl static final Method IS_FILE_READ_ONLY; //AllocateDirectMap - static final Method IS_HEAP_TYPE; //BaseState - static final Method IS_MAP_TYPE; //BaseState - static final Method IS_NON_NATIVE_TYPE; //BaseState + static final Method IS_HEAP_TYPE; //BaseStateImpl + static final Method IS_MAP_TYPE; //BaseStateImpl + static final Method IS_NON_NATIVE_TYPE; //BaseStateImpl static final Method IS_PAGE_ALIGHED; //NioBits - static final Method IS_READ_ONLY_TYPE; //BaseState - static final Method IS_REGION_TYPE; //BaseState + static final Method IS_READ_ONLY_TYPE; //BaseStateImpl + static final Method IS_REGION_TYPE; //BaseStateImpl static final Method PAGE_COUNT; //NioBits static final Method PAGE_SIZE; //NioBits static final Method RESERVE_MEMORY; //NioBits @@ -61,7 +61,7 @@ public final class ReflectUtil { static { BASE_STATE = - getClass("org.apache.datasketches.memory.internal.BaseState"); + getClass("org.apache.datasketches.memory.internal.BaseStateImpl"); BASE_WRITABLE_MEMORY_IMPL = getClass("org.apache.datasketches.memory.internal.BaseWritableMemoryImpl"); ALLOCATE_DIRECT_MAP = diff --git a/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java b/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java index 81f6c82..bf7924e 100644 --- a/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java +++ b/src/test/java/org/apache/datasketches/memory/test/XxHash64Test.java @@ -100,7 +100,7 @@ public class XxHash64Test { } /** - * This simple test compares the output of {@link BaseState#xxHash64(long, long, long)} with the + * This simple test compares the output of {@link BaseStateImpl#xxHash64(long, long, long)} with the * output of {@link net.openhft.hashing.LongHashFunction}, that itself is tested against the * reference implementation in C. This increase confidence that the xxHash function implemented * in this package is in fact the same xxHash function implemented in C. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
