2727import java .nio .ByteBuffer ;
2828
2929/**
30- * The MemoryRegion class implements the Memory interface and provides a means of
31- * hierarchically partitioning a large block of native memory into
32- * smaller regions of memory, each with their own capacity and offsets.
33- *
34- * <p>If asserts are enabled in the JVM, the methods in this class perform bounds checking against
30+ * The MemoryRegion class implements the Memory interface and provides a means of
31+ * hierarchically partitioning a large block of native memory into
32+ * smaller regions of memory, each with their own capacity and offsets.
33+ *
34+ * <p>If asserts are enabled in the JVM, the methods in this class perform bounds checking against
3535 * the region's defined boundaries and then redirect the call to the parent Memory class. If the
36- * parent class is also a MemoryRegion it does a similar check and then calls its parent.
36+ * parent class is also a MemoryRegion it does a similar check and then calls its parent.
3737 * The root of this hierarchy will be a NativeMemory class that ultimately performs the desired
38- * task. If asserts are not enabled the JIT compiler will eliminate all the asserts and the
39- * hierarchical calls should collapse to a call to the NativeMemory method.</p>
40- *
41- * <p>Because asserts must be specifically enabled in the JVM, it is incumbent on the user of this
42- * class to make sure that their code is thoroughly tested.
38+ * task. If asserts are not enabled the JIT compiler will eliminate all the asserts and the
39+ * hierarchical calls should collapse to a call to the NativeMemory method.</p>
40+ *
41+ * <p>Because asserts must be specifically enabled in the JVM, it is incumbent on the user of this
42+ * class to make sure that their code is thoroughly tested.
4343 * Violating memory bounds can cause memory segment faults, which takes
4444 * down the JVM and can be very difficult to debug.</p>
45- *
45+ *
4646 * @see NativeMemory
4747 * @author Lee Rhodes
4848 */
4949public class MemoryRegion implements Memory {
5050 /**
5151 * The parent Memory object from which an offset and capacity is defined by this class.
52- * This field is used to keep a reference to the parent Memory to
52+ * This field is used to keep a reference to the parent Memory to
5353 * ensure that its memory isn't freed before we are done with it.
5454 */
5555 private final Memory mem_ ;
5656 private volatile long memOffsetBytes_ ;
5757 private volatile long capacityBytes_ ;
5858 private volatile MemoryRequest memReq_ = null ;
59-
59+
6060 /**
61- * Defines a region of the given parent Memory by defining an offset and capacity that are
61+ * Defines a region of the given parent Memory by defining an offset and capacity that are
6262 * within the boundaries of the parent.
6363 * @param memory the parent Memory
64- * @param memOffsetBytes the starting offset in bytes of this region with respect to the
64+ * @param memOffsetBytes the starting offset in bytes of this region with respect to the
6565 * start of the parent memory.
6666 * @param capacityBytes the capacity in bytes of this region.
6767 */
@@ -71,12 +71,12 @@ public MemoryRegion(Memory memory, long memOffsetBytes, long capacityBytes) {
7171 memOffsetBytes_ = memOffsetBytes ;
7272 capacityBytes_ = capacityBytes ;
7373 }
74-
74+
7575 /**
76- * Defines a region of the given parent Memory by defining an offset and capacity that are
76+ * Defines a region of the given parent Memory by defining an offset and capacity that are
7777 * within the boundaries of the parent.
7878 * @param memory the parent Memory
79- * @param memOffsetBytes the starting offset in bytes of this region with respect to the
79+ * @param memOffsetBytes the starting offset in bytes of this region with respect to the
8080 * start of the parent memory.
8181 * @param capacityBytes the capacity in bytes of this region.
8282 * @param memReq a MemoryRequest object
@@ -88,7 +88,7 @@ public MemoryRegion(Memory memory, long memOffsetBytes, long capacityBytes, Memo
8888 capacityBytes_ = capacityBytes ;
8989 memReq_ = memReq ;
9090 }
91-
91+
9292 /**
9393 * Reassign the offset and capacity of this MemoryRegion
9494 * @param memOffsetBytes the given offset from the parent's start
@@ -99,7 +99,7 @@ public void reassign(long memOffsetBytes, long capacityBytes) {
9999 memOffsetBytes_ = memOffsetBytes ;
100100 capacityBytes_ = capacityBytes ;
101101 }
102-
102+
103103 @ Override
104104 public void clear () {
105105 fill (0 , capacityBytes_ , (byte ) 0 );
@@ -124,7 +124,7 @@ public void copy(long srcOffsetBytes, long dstOffsetBytes, long lengthBytes) {
124124 long max = Math .max (srcOffsetBytes , dstOffsetBytes );
125125 assertBounds (min , lengthBytes , max ); //regions must not overlap
126126 long srcAdd = getAddress (srcOffsetBytes );
127- long dstAdd = getAddress (dstOffsetBytes );
127+ long dstAdd = getAddress (dstOffsetBytes );
128128 mem_ .copy (srcAdd , dstAdd , lengthBytes );
129129 }
130130
@@ -138,7 +138,7 @@ public void fill(long offsetBytes, long lengthBytes, byte value) {
138138 assertBounds (offsetBytes , lengthBytes , capacityBytes_ );
139139 mem_ .fill (getAddress (offsetBytes ), lengthBytes , value );
140140 }
141-
141+
142142 @ Override
143143 public int getAndAddInt (long offsetBytes , int delta ) {
144144 assertBounds (offsetBytes , ARRAY_INT_INDEX_SCALE , capacityBytes_ );
@@ -278,7 +278,7 @@ public void getShortArray(long offsetBytes, short[] dstArray, int dstOffset, int
278278 @ Override
279279 public boolean isAllBitsClear (long offsetBytes , byte bitMask ) {
280280 assertBounds (offsetBytes , ARRAY_BYTE_INDEX_SCALE , capacityBytes_ );
281- int value = ~mem_ .getByte (getAddress (offsetBytes )) & bitMask & 0XFF ;
281+ int value = ~mem_ .getByte (getAddress (offsetBytes )) & bitMask & 0XFF ;
282282 return value == bitMask ;
283283 }
284284
@@ -292,7 +292,7 @@ public boolean isAllBitsSet(long offsetBytes, byte bitMask) {
292292 @ Override
293293 public boolean isAnyBitsClear (long offsetBytes , byte bitMask ) {
294294 assertBounds (offsetBytes , ARRAY_BYTE_INDEX_SCALE , capacityBytes_ );
295- int value = ~mem_ .getByte (getAddress (offsetBytes )) & bitMask & 0XFF ;
295+ int value = ~mem_ .getByte (getAddress (offsetBytes )) & bitMask & 0XFF ;
296296 return value != 0 ;
297297 }
298298
@@ -429,18 +429,18 @@ public void setBits(long offsetBytes, byte bitMask) {
429429 public Object array () {
430430 return mem_ .array ();
431431 }
432-
432+
433433 @ Override
434434 public Memory asReadOnlyMemory () {
435435 Memory readOnlyMem = mem_ .asReadOnlyMemory ();
436436 return new MemoryRegionR (readOnlyMem , memOffsetBytes_ , capacityBytes_ , memReq_ );
437437 }
438-
438+
439439 @ Override
440440 public ByteBuffer byteBuffer () {
441441 return mem_ .byteBuffer ();
442442 }
443-
443+
444444 /**
445445 * Returns the start address of this Memory relative to its parent plus the given offsetBytes.
446446 * @param offsetBytes the given offset in bytes from the start address of this Memory
@@ -461,47 +461,47 @@ public long getCapacity() {
461461 public long getCumulativeOffset (final long offsetBytes ) {
462462 return mem_ .getCumulativeOffset (0L ) + getAddress (offsetBytes );
463463 }
464-
464+
465465 @ Override
466466 public MemoryRequest getMemoryRequest () {
467467 return memReq_ ;
468468 }
469-
469+
470470 @ Override
471471 public NativeMemory getNativeMemory () {
472472 return mem_ .getNativeMemory ();
473473 }
474-
474+
475475 @ Override
476476 public Object getParent () {
477477 return mem_ ;
478478 }
479-
479+
480480 @ Override
481481 public boolean hasArray () {
482482 return mem_ .hasArray ();
483483 }
484-
484+
485485 @ Override
486486 public boolean hasByteBuffer () {
487487 return mem_ .hasByteBuffer ();
488488 }
489-
489+
490490 @ Override
491491 public boolean isAllocated () {
492492 return (capacityBytes_ > 0L );
493493 }
494-
494+
495495 @ Override
496496 public boolean isDirect () {
497497 return mem_ .isDirect ();
498498 }
499-
499+
500500 @ Override
501501 public boolean isReadOnly () {
502502 return false ;
503503 }
504-
504+
505505 @ Override
506506 public void setMemoryRequest (MemoryRequest memReq ) {
507507 memReq_ = memReq ;
0 commit comments