Skip to content

Commit

Permalink
Removed trailing blanks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Rhodes committed Oct 5, 2016
1 parent 01d0046 commit d8ec3be
Show file tree
Hide file tree
Showing 59 changed files with 1,661 additions and 1,661 deletions.
72 changes: 36 additions & 36 deletions memory/src/main/java/com/yahoo/memory/AllocMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import static com.yahoo.memory.UnsafeUtil.unsafe;

/**
* The AllocMemory class is a subclass of NativeMemory and is used to allocate direct, off-heap
* native memory, which is then accessed by the NativeMemory methods.
* It is the responsibility of the calling class to free this memory using freeMemory() when done.
*
* <p>The task of direct allocation was moved to this sub-class for performance reasons.
* The AllocMemory class is a subclass of NativeMemory and is used to allocate direct, off-heap
* native memory, which is then accessed by the NativeMemory methods.
* It is the responsibility of the calling class to free this memory using freeMemory() when done.
*
* <p>The task of direct allocation was moved to this sub-class for performance reasons.
*
* @author Lee Rhodes
*/
//@SuppressWarnings("restriction")
public class AllocMemory extends MemoryMappedFile {

/**
* Constructor for allocate native memory.
*
* <p>Allocates and provides access to capacityBytes directly in native (off-heap) memory
* Constructor for allocate native memory.
*
* <p>Allocates and provides access to capacityBytes directly in native (off-heap) memory
* leveraging the Memory interface. The MemoryRequest callback is set to null.
* @param capacityBytes the size in bytes of the native memory
*/
Expand All @@ -32,12 +32,12 @@ public AllocMemory(long capacityBytes) {
super.capacityBytes_ = capacityBytes;
super.memReq_ = null;
}

/**
* Constructor for allocate native memory with MemoryRequest.
*
*
* <p>Allocates and provides access to capacityBytes directly in native (off-heap) memory leveraging
* the Memory interface.
* the Memory interface.
* @param capacityBytes the size in bytes of the native memory
* @param memReq The MemoryRequest callback
*/
Expand All @@ -47,49 +47,49 @@ public AllocMemory(long capacityBytes, MemoryRequest memReq) {
super.capacityBytes_ = capacityBytes;
super.memReq_ = memReq;
}

/**
* Constructor for reallocate native memory.
*
* <p>Reallocates the given off-heap NativeMemory to a new a new native (off-heap) memory
* location and copies the contents of the original given NativeMemory to the new location.
* Any memory beyond the capacity of the original given NativeMemory will be uninitialized.
* Dispose of this new memory by calling {@link NativeMemory#freeMemory()}.
* @param origMem The original NativeMemory that needs to be reallocated and must not be null.
* The OS is free to just expand the capacity of the current allocation at the same native
* address, or reassign a completely different native address in which case the origMem will be
* freed by the OS.
*
* <p>Reallocates the given off-heap NativeMemory to a new a new native (off-heap) memory
* location and copies the contents of the original given NativeMemory to the new location.
* Any memory beyond the capacity of the original given NativeMemory will be uninitialized.
* Dispose of this new memory by calling {@link NativeMemory#freeMemory()}.
* @param origMem The original NativeMemory that needs to be reallocated and must not be null.
* The OS is free to just expand the capacity of the current allocation at the same native
* address, or reassign a completely different native address in which case the origMem will be
* freed by the OS.
* The origMem capacity will be set to zero and must not be used again.
*
*
* @param newCapacityBytes the desired new capacity of the newly allocated memory in bytes
* @param memReq The MemoryRequest callback, which may be null.
*/
public AllocMemory(NativeMemory origMem, long newCapacityBytes, MemoryRequest memReq) {
super(0L, null, null);
super.nativeRawStartAddress_ = unsafe.reallocateMemory(origMem.nativeRawStartAddress_,
super.nativeRawStartAddress_ = unsafe.reallocateMemory(origMem.nativeRawStartAddress_,
newCapacityBytes);
super.capacityBytes_ = newCapacityBytes;
this.memReq_ = memReq;
origMem.nativeRawStartAddress_ = 0; //does not require freeMem
origMem.capacityBytes_ = 0; //Cannot be used again
}

/**
* Constructor for allocate native memory, copy and clear.
*
* <p>Allocate a new native (off-heap) memory with capacityBytes; copy the contents of origMem
*
* <p>Allocate a new native (off-heap) memory with capacityBytes; copy the contents of origMem
* from zero to copyToBytes; clear the new memory from copyToBytes to capacityBytes.
* @param origMem The original NativeMemory, a portion of which will be copied to the
* newly allocated Memory.
* @param origMem The original NativeMemory, a portion of which will be copied to the
* newly allocated Memory.
* The reference must not be null.
* This origMem is not modified in any way, may be reused and must be freed appropriately.
* @param copyToBytes the upper limit of the region to be copied from origMem to the newly
* allocated memory.
* @param capacityBytes the desired new capacity of the newly allocated memory in bytes and the
* upper limit of the region to be cleared.
* @param copyToBytes the upper limit of the region to be copied from origMem to the newly
* allocated memory.
* @param capacityBytes the desired new capacity of the newly allocated memory in bytes and the
* upper limit of the region to be cleared.
* @param memReq The MemoryRequest callback, which may be null.
*/
public AllocMemory(NativeMemory origMem, long copyToBytes, long capacityBytes,
public AllocMemory(NativeMemory origMem, long copyToBytes, long capacityBytes,
MemoryRequest memReq) {
super(0L, null, null);
super.nativeRawStartAddress_ = unsafe.allocateMemory(capacityBytes);
Expand All @@ -98,10 +98,10 @@ public AllocMemory(NativeMemory origMem, long copyToBytes, long capacityBytes,
NativeMemory.copy(origMem, 0, this, 0, copyToBytes);
this.clear(copyToBytes, capacityBytes - copyToBytes);
}

@Override
public void freeMemory() {
super.freeMemory();
}

}
2 changes: 0 additions & 2 deletions memory/src/main/java/com/yahoo/memory/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public interface Memory {
*/
long getAndSetLong(long offsetBytes, long newValue);


/**
* Gets the boolean value at the given offset
* @param offsetBytes offset bytes relative to this Memory start
Expand Down Expand Up @@ -131,7 +130,6 @@ public interface Memory {
*/
void getByteArray(long offsetBytes, byte[] dstArray, int dstOffset, int length);


/**
* Gets the char at the given offset
* @param offsetBytes offset bytes relative to this Memory start
Expand Down
74 changes: 37 additions & 37 deletions memory/src/main/java/com/yahoo/memory/MemoryRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,41 @@
import java.nio.ByteBuffer;

/**
* The MemoryRegion class implements the Memory interface and provides a means of
* hierarchically partitioning a large block of native memory into
* smaller regions of memory, each with their own capacity and offsets.
*
* <p>If asserts are enabled in the JVM, the methods in this class perform bounds checking against
* The MemoryRegion class implements the Memory interface and provides a means of
* hierarchically partitioning a large block of native memory into
* smaller regions of memory, each with their own capacity and offsets.
*
* <p>If asserts are enabled in the JVM, the methods in this class perform bounds checking against
* the region's defined boundaries and then redirect the call to the parent Memory class. If the
* parent class is also a MemoryRegion it does a similar check and then calls its parent.
* parent class is also a MemoryRegion it does a similar check and then calls its parent.
* The root of this hierarchy will be a NativeMemory class that ultimately performs the desired
* task. If asserts are not enabled the JIT compiler will eliminate all the asserts and the
* hierarchical calls should collapse to a call to the NativeMemory method.</p>
*
* <p>Because asserts must be specifically enabled in the JVM, it is incumbent on the user of this
* class to make sure that their code is thoroughly tested.
* task. If asserts are not enabled the JIT compiler will eliminate all the asserts and the
* hierarchical calls should collapse to a call to the NativeMemory method.</p>
*
* <p>Because asserts must be specifically enabled in the JVM, it is incumbent on the user of this
* class to make sure that their code is thoroughly tested.
* Violating memory bounds can cause memory segment faults, which takes
* down the JVM and can be very difficult to debug.</p>
*
*
* @see NativeMemory
* @author Lee Rhodes
*/
public class MemoryRegion implements Memory {
/**
* The parent Memory object from which an offset and capacity is defined by this class.
* This field is used to keep a reference to the parent Memory to
* This field is used to keep a reference to the parent Memory to
* ensure that its memory isn't freed before we are done with it.
*/
private final Memory mem_;
private volatile long memOffsetBytes_;
private volatile long capacityBytes_;
private volatile MemoryRequest memReq_ = null;

/**
* Defines a region of the given parent Memory by defining an offset and capacity that are
* Defines a region of the given parent Memory by defining an offset and capacity that are
* within the boundaries of the parent.
* @param memory the parent Memory
* @param memOffsetBytes the starting offset in bytes of this region with respect to the
* @param memOffsetBytes the starting offset in bytes of this region with respect to the
* start of the parent memory.
* @param capacityBytes the capacity in bytes of this region.
*/
Expand All @@ -71,12 +71,12 @@ public MemoryRegion(Memory memory, long memOffsetBytes, long capacityBytes) {
memOffsetBytes_ = memOffsetBytes;
capacityBytes_ = capacityBytes;
}

/**
* Defines a region of the given parent Memory by defining an offset and capacity that are
* Defines a region of the given parent Memory by defining an offset and capacity that are
* within the boundaries of the parent.
* @param memory the parent Memory
* @param memOffsetBytes the starting offset in bytes of this region with respect to the
* @param memOffsetBytes the starting offset in bytes of this region with respect to the
* start of the parent memory.
* @param capacityBytes the capacity in bytes of this region.
* @param memReq a MemoryRequest object
Expand All @@ -88,7 +88,7 @@ public MemoryRegion(Memory memory, long memOffsetBytes, long capacityBytes, Memo
capacityBytes_ = capacityBytes;
memReq_ = memReq;
}

/**
* Reassign the offset and capacity of this MemoryRegion
* @param memOffsetBytes the given offset from the parent's start
Expand All @@ -99,7 +99,7 @@ public void reassign(long memOffsetBytes, long capacityBytes) {
memOffsetBytes_ = memOffsetBytes;
capacityBytes_ = capacityBytes;
}

@Override
public void clear() {
fill(0, capacityBytes_, (byte) 0);
Expand All @@ -124,7 +124,7 @@ public void copy(long srcOffsetBytes, long dstOffsetBytes, long lengthBytes) {
long max = Math.max(srcOffsetBytes, dstOffsetBytes);
assertBounds(min, lengthBytes, max); //regions must not overlap
long srcAdd = getAddress(srcOffsetBytes);
long dstAdd = getAddress(dstOffsetBytes);
long dstAdd = getAddress(dstOffsetBytes);
mem_.copy(srcAdd, dstAdd, lengthBytes);
}

Expand All @@ -138,7 +138,7 @@ public void fill(long offsetBytes, long lengthBytes, byte value) {
assertBounds(offsetBytes, lengthBytes, capacityBytes_);
mem_.fill(getAddress(offsetBytes), lengthBytes, value);
}

@Override
public int getAndAddInt(long offsetBytes, int delta) {
assertBounds(offsetBytes, ARRAY_INT_INDEX_SCALE, capacityBytes_);
Expand Down Expand Up @@ -278,7 +278,7 @@ public void getShortArray(long offsetBytes, short[] dstArray, int dstOffset, int
@Override
public boolean isAllBitsClear(long offsetBytes, byte bitMask) {
assertBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
int value = ~mem_.getByte(getAddress(offsetBytes)) & bitMask & 0XFF;
int value = ~mem_.getByte(getAddress(offsetBytes)) & bitMask & 0XFF;
return value == bitMask;
}

Expand All @@ -292,7 +292,7 @@ public boolean isAllBitsSet(long offsetBytes, byte bitMask) {
@Override
public boolean isAnyBitsClear(long offsetBytes, byte bitMask) {
assertBounds(offsetBytes, ARRAY_BYTE_INDEX_SCALE, capacityBytes_);
int value = ~mem_.getByte(getAddress(offsetBytes)) & bitMask & 0XFF;
int value = ~mem_.getByte(getAddress(offsetBytes)) & bitMask & 0XFF;
return value != 0;
}

Expand Down Expand Up @@ -429,18 +429,18 @@ public void setBits(long offsetBytes, byte bitMask) {
public Object array() {
return mem_.array();
}

@Override
public Memory asReadOnlyMemory() {
Memory readOnlyMem = mem_.asReadOnlyMemory();
return new MemoryRegionR(readOnlyMem, memOffsetBytes_, capacityBytes_, memReq_);
}

@Override
public ByteBuffer byteBuffer() {
return mem_.byteBuffer();
}

/**
* Returns the start address of this Memory relative to its parent plus the given offsetBytes.
* @param offsetBytes the given offset in bytes from the start address of this Memory
Expand All @@ -461,47 +461,47 @@ public long getCapacity() {
public long getCumulativeOffset(final long offsetBytes) {
return mem_.getCumulativeOffset(0L) + getAddress(offsetBytes);
}

@Override
public MemoryRequest getMemoryRequest() {
return memReq_;
}

@Override
public NativeMemory getNativeMemory() {
return mem_.getNativeMemory();
}

@Override
public Object getParent() {
return mem_;
}

@Override
public boolean hasArray() {
return mem_.hasArray();
}

@Override
public boolean hasByteBuffer() {
return mem_.hasByteBuffer();
}

@Override
public boolean isAllocated() {
return (capacityBytes_ > 0L);
}

@Override
public boolean isDirect() {
return mem_.isDirect();
}

@Override
public boolean isReadOnly() {
return false;
}

@Override
public void setMemoryRequest(MemoryRequest memReq) {
memReq_ = memReq;
Expand Down
Loading

0 comments on commit d8ec3be

Please sign in to comment.