You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2016/03/05 01:51:18 UTC
[18/38] incubator-geode git commit: methods that access and modify
the data now have Data in their name
methods that access and modify the data now have Data in their name
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/9904fc6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/9904fc6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/9904fc6e
Branch: refs/heads/feature/GEODE-982
Commit: 9904fc6ef8d48cfcc248d0d3bf5b0b36461efe8e
Parents: 58df731
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Mar 1 16:08:42 2016 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Mar 1 16:08:42 2016 -0800
----------------------------------------------------------------------
.../gemfire/internal/offheap/ObjectChunk.java | 47 +++++++++-----------
.../internal/offheap/ObjectStoredOffHeap.java | 37 +++++++++------
.../internal/tcp/ByteBufferInputStream.java | 6 +--
.../offheap/MemoryBlockNodeJUnitTest.java | 8 ++--
.../internal/offheap/ObjectChunkJUnitTest.java | 18 +++-----
.../internal/offheap/OffHeapRegionBase.java | 2 +-
...moryAllocatorFillPatternIntegrationTest.java | 2 +-
...mpleMemoryAllocatorFillPatternJUnitTest.java | 6 +--
8 files changed, 62 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectChunk.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectChunk.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectChunk.java
index 864389a..be45ee9 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectChunk.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectChunk.java
@@ -164,8 +164,8 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
for (i=0; i < mySize-(dataCache1.length-1); i+=dataCache1.length) {
- this.readBytes(i, dataCache1);
- other.readBytes(i, dataCache2);
+ this.readDataBytes(i, dataCache1);
+ other.readDataBytes(i, dataCache2);
for (int j=0; j < dataCache1.length; j++) {
if (dataCache1[j] != dataCache2[j]) {
return false;
@@ -175,8 +175,8 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
int bytesToRead = mySize-i;
if (bytesToRead > 0) {
// need to do one more read which will be less than dataCache.length
- this.readBytes(i, dataCache1, 0, bytesToRead);
- other.readBytes(i, dataCache2, 0, bytesToRead);
+ this.readDataBytes(i, dataCache1, 0, bytesToRead);
+ other.readDataBytes(i, dataCache2, 0, bytesToRead);
for (int j=0; j < bytesToRead; j++) {
if (dataCache1[j] != dataCache2[j]) {
return false;
@@ -187,7 +187,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
}
public boolean isSerializedPdxInstance() {
- byte dsCode = this.readByte(0);
+ byte dsCode = this.readDataByte(0);
return dsCode == DSCODE.PDX || dsCode == DSCODE.PDX_ENUM || dsCode == DSCODE.PDX_INLINE_ENUM;
}
@@ -205,7 +205,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
int i;
SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
for (i=0; i < mySize-(dataCache.length-1); i+=dataCache.length) {
- this.readBytes(i, dataCache);
+ this.readDataBytes(i, dataCache);
for (int j=0; j < dataCache.length; j++) {
if (dataCache[j] != serializedObj[idx++]) {
return false;
@@ -215,7 +215,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
int bytesToRead = mySize-i;
if (bytesToRead > 0) {
// need to do one more read which will be less than dataCache.length
- this.readBytes(i, dataCache, 0, bytesToRead);
+ this.readDataBytes(i, dataCache, 0, bytesToRead);
for (int j=0; j < bytesToRead; j++) {
if (dataCache[j] != serializedObj[idx++]) {
return false;
@@ -258,6 +258,11 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
return this.memoryAddress;
}
+ @Override
+ public long getDataAddress() {
+ return getBaseDataAddress();
+ }
+ @Override
public int getDataSize() {
return getDataSize(this.memoryAddress);
}
@@ -429,25 +434,25 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
}
@Override
- public byte readByte(int offset) {
+ public byte readDataByte(int offset) {
assert offset < getDataSize();
return AddressableMemoryManager.readByte(getBaseDataAddress() + offset);
}
@Override
- public void writeByte(int offset, byte value) {
+ public void writeDataByte(int offset, byte value) {
assert offset < getDataSize();
AddressableMemoryManager.writeByte(getBaseDataAddress() + offset, value);
}
@Override
- public void readBytes(int offset, byte[] bytes) {
- readBytes(offset, bytes, 0, bytes.length);
+ public void readDataBytes(int offset, byte[] bytes) {
+ readDataBytes(offset, bytes, 0, bytes.length);
}
@Override
- public void writeBytes(int offset, byte[] bytes) {
- writeBytes(offset, bytes, 0, bytes.length);
+ public void writeDataBytes(int offset, byte[] bytes) {
+ writeDataBytes(offset, bytes, 0, bytes.length);
}
public long getAddressForReading(int offset, int size) {
@@ -456,13 +461,13 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
}
@Override
- public void readBytes(int offset, byte[] bytes, int bytesOffset, int size) {
+ public void readDataBytes(int offset, byte[] bytes, int bytesOffset, int size) {
assert offset+size <= getDataSize();
AddressableMemoryManager.readBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
}
@Override
- public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) {
+ public void writeDataBytes(int offset, byte[] bytes, int bytesOffset, int size) {
assert offset+size <= getDataSize();
AddressableMemoryManager.writeBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
}
@@ -498,7 +503,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
}
public void setSerializedValue(byte[] value) {
- writeBytes(0, value);
+ writeDataBytes(0, value);
}
public byte[] getDecompressedBytes(RegionEntryContext context) {
@@ -514,7 +519,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
*/
public byte[] getCompressedBytes() {
byte[] result = new byte[getDataSize()];
- readBytes(0, result);
+ readDataBytes(0, result);
//debugLog("reading", true);
SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
return result;
@@ -567,14 +572,6 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
}
@Override
- public void copyBytes(int src, int dst, int size) {
- throw new UnsupportedOperationException("Implement if used");
-// assert src+size <= getDataSize();
-// assert dst+size < getDataSize();
-// getSlabs()[this.getSlabIdx()].copyBytes(getBaseDataAddress()+src, getBaseDataAddress()+dst, size);
- }
-
- @Override
public boolean isSerialized() {
return (AddressableMemoryManager.readInt(this.memoryAddress+REF_COUNT_OFFSET) & IS_SERIALIZED_BIT) != 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredOffHeap.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredOffHeap.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredOffHeap.java
index f108a7c..85626f5 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredOffHeap.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredOffHeap.java
@@ -32,30 +32,39 @@ import com.gemstone.gemfire.internal.offheap.annotations.Retained;
public interface ObjectStoredOffHeap extends StoredObject, Releasable {
/**
- * Returns the off-heap address at which the data is stored.
+ * Returns the address of the memory used to store this object.
+ * This address may not be to the first byte of stored data since
+ * the implementation may store some internal data in the first bytes of the memory.
* This address can be used with AddressableMemoryManager.
*/
public long getMemoryAddress();
/**
- * Returns the size of this memory chunk in bytes.
+ * Returns the number of bytes of memory used by this object to store an object.
+ * This size includes any bytes used for padding and meta-information.
*/
public int getSize();
- public byte readByte(int offset);
- public void writeByte(int offset, byte value);
-
- public void readBytes(int offset, byte[] bytes);
- public void writeBytes(int offset, byte[] bytes);
- public void readBytes(int offset, byte[] bytes, int bytesOffset, int size);
- public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size);
-
/**
- * Read the bytes in this range [src..src+size]
- * and write them to the range that starts at dst.
- * The number of bytes copied is size.
+ * Returns the address of the first byte of memory used to store this object.
+ * This address will not be to any padding or meta-data bytes that precede the
+ * first data byte.
+ * This address can be used with AddressableMemoryManager.
*/
- public void copyBytes(int src, int dst, int size);
+ public long getDataAddress();
+ /**
+ * Returns the number of bytes of memory used to store the object.
+ * This size does not include any bytes used for padding.
+ */
+ public int getDataSize();
+ public byte readDataByte(int offset);
+ public void writeDataByte(int offset, byte value);
+
+ public void readDataBytes(int offset, byte[] bytes);
+ public void writeDataBytes(int offset, byte[] bytes);
+ public void readDataBytes(int offset, byte[] bytes, int bytesOffset, int size);
+ public void writeDataBytes(int offset, byte[] bytes, int bytesOffset, int size);
+
/**
* Call to indicate that this object's memory is in use by the caller.
* The memory will stay allocated until {@link #release()} is called.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
index e2a37a0..bb1535c 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
@@ -474,17 +474,17 @@ public class ByteBufferInputStream extends InputStream implements DataInput, jav
}
int p = this.position;
this.position += length;
- this.chunk.readBytes(p, dst, offset, length);
+ this.chunk.readDataBytes(p, dst, offset, length);
}
@Override
public byte get() {
- return this.chunk.readByte(nextGetIndex());
+ return this.chunk.readDataByte(nextGetIndex());
}
@Override
public byte get(int pos) {
checkIndex(pos);
- return this.chunk.readByte(pos);
+ return this.chunk.readDataByte(pos);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
index 7acc2c9..6edf11b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
@@ -311,7 +311,7 @@ public class MemoryBlockNodeJUnitTest {
storedObject = createValueAsSerializedStoredObject(obj, true);
MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) storedObject);
byte[] storedObjectBytes = new byte[storedObject.getValueSizeInBytes()];
- storedObject.readBytes(0, storedObjectBytes);
+ storedObject.readDataBytes(0, storedObjectBytes);
softly.assertThat(mb.getDataValue()).isEqualTo(storedObjectBytes);
}
@@ -321,7 +321,7 @@ public class MemoryBlockNodeJUnitTest {
storedObject = createValueAsUnserializedStoredObject(obj, true);
MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) storedObject);
byte[] storedObjectBytes = new byte[storedObject.getValueSizeInBytes()];
- storedObject.readBytes(0, storedObjectBytes);
+ storedObject.readDataBytes(0, storedObjectBytes);
softly.assertThat(mb.getDataValue()).isEqualTo(storedObjectBytes);
}
@@ -331,7 +331,7 @@ public class MemoryBlockNodeJUnitTest {
storedObject = createValueAsUnserializedStoredObject(obj, false);
MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) storedObject);
byte[] storedObjectBytes = new byte[storedObject.getValueSizeInBytes()];
- storedObject.readBytes(0, storedObjectBytes);
+ storedObject.readDataBytes(0, storedObjectBytes);
softly.assertThat(mb.getDataValue()).isEqualTo(storedObjectBytes);
}
@@ -339,7 +339,7 @@ public class MemoryBlockNodeJUnitTest {
public void getDataValueWithIllegalDataTypeCatchesIOException() {
Object obj = getValue();
storedObject = createValueAsSerializedStoredObject(obj);
- storedObject.writeByte(0, DSCODE.ILLEGAL);
+ storedObject.writeDataByte(0, DSCODE.ILLEGAL);
MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) storedObject);
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
System.setErr(new PrintStream(errContent));
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
index f66ef2c..09fed2a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
@@ -683,9 +683,9 @@ public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase {
public void readByteAndWriteByteShouldFailIfOffsetIsOutside() {
ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
- chunk.readByte(chunk.getDataSize() + 1);
+ chunk.readDataByte(chunk.getDataSize() + 1);
- chunk.writeByte(chunk.getDataSize() + 1, Byte.MAX_VALUE);
+ chunk.writeDataByte(chunk.getDataSize() + 1, Byte.MAX_VALUE);
chunk.release();
}
@@ -694,12 +694,12 @@ public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase {
public void writeByteShouldWriteAtCorrectLocation() {
ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
- byte valueBeforeWrite = chunk.readByte(2);
+ byte valueBeforeWrite = chunk.readDataByte(2);
Byte expected = Byte.MAX_VALUE;
- chunk.writeByte(2, expected);
+ chunk.writeDataByte(2, expected);
- Byte actual = chunk.readByte(2);
+ Byte actual = chunk.readDataByte(2);
assertThat(actual).isNotEqualTo(valueBeforeWrite);
assertThat(actual).isEqualTo(expected);
@@ -815,14 +815,6 @@ public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase {
}
@Test(expected = UnsupportedOperationException.class)
- public void copyBytesShouldThrowUnSupportedOperationException() {
- ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
- chunk.copyBytes(1, 2, 1);
-
- chunk.release();
- }
-
- @Test(expected = UnsupportedOperationException.class)
public void getSlabIdShouldThrowUnSupportedOperationException() {
ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
chunk.getSlabId();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
index 046f752..b525e2e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
@@ -167,7 +167,7 @@ public abstract class OffHeapRegionBase {
assertEquals(data.length+perObjectOverhead(), ma.getUsedMemory());
assertEquals(offHeapSize-(data.length+perObjectOverhead()), ma.getFreeMemory());
byte[] data2 = new byte[data.length];
- mc1.readBytes(0, data2);
+ mc1.readDataBytes(0, data2);
assertTrue(Arrays.equals(data, data2));
mc1.release();
assertEquals(offHeapSize, ma.getFreeMemory());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
index a744fe2..2763ed0 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternIntegrationTest.java
@@ -201,7 +201,7 @@ public class SimpleMemoryAllocatorFillPatternIntegrationTest {
*/
private void write() {
ObjectChunk chunk = chunks.get(random.nextInt(chunks.size()));
- chunk.writeBytes(0, WRITE_BYTES);
+ chunk.writeDataBytes(0, WRITE_BYTES);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9904fc6e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
index ceef791..4362170 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
@@ -109,7 +109,7 @@ public class SimpleMemoryAllocatorFillPatternJUnitTest {
chunk.validateFill();
// "Dirty" the chunk so the release has something to fill over
- chunk.writeBytes(ObjectChunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
+ chunk.writeDataBytes(ObjectChunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
// This should free the Chunk (ref count == 1)
chunk.release();
@@ -124,14 +124,14 @@ public class SimpleMemoryAllocatorFillPatternJUnitTest {
chunk.validateFill();
// Give the fill code something to write over during the release
- chunk.writeBytes(ObjectChunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
+ chunk.writeDataBytes(ObjectChunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
chunk.release();
// Again, make sure the release implemented the fill
chunk.validateFill();
// "Dirty up" the free chunk
- chunk.writeBytes(ObjectChunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
+ chunk.writeDataBytes(ObjectChunk.MIN_CHUNK_SIZE + 1, WRITE_BYTES);
catchException(chunk).validateFill();
assertTrue(caughtException() instanceof IllegalStateException);