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 2015/12/02 01:06:19 UTC
[10/13] incubator-geode git commit: added testValidateAddressAndSize
added testValidateAddressAndSize
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/e5d84829
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e5d84829
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e5d84829
Branch: refs/heads/feature/GEODE-607
Commit: e5d84829435c35267d8bd1336ad42cf8ebc60922
Parents: 14125c8
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon Nov 30 10:07:24 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon Nov 30 10:07:24 2015 -0800
----------------------------------------------------------------------
.../gemfire/internal/offheap/Chunk.java | 1 -
.../offheap/SimpleMemoryAllocatorImpl.java | 8 ++---
.../offheap/SimpleMemoryAllocatorJUnitTest.java | 37 ++++++++++++++++++++
3 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e5d84829/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
index e32a1c6..ed4bc43 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
@@ -389,7 +389,6 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
@Override
public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) {
assert offset+size <= getDataSize();
- SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(getBaseDataAddress() + offset, size);
UnsafeMemoryChunk.writeAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e5d84829/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
index 84361c9..88a3e22 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
@@ -108,7 +108,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
private static final boolean PRETOUCH = Boolean.getBoolean("gemfire.OFF_HEAP_PRETOUCH_PAGES");
static final int OFF_HEAP_PAGE_SIZE = Integer.getInteger("gemfire.OFF_HEAP_PAGE_SIZE", UnsafeMemoryChunk.getPageSize());
- private static final boolean DO_EXPENSIVE_VALIDATION = Boolean.getBoolean("gemfire.OFF_HEAP_DO_EXPENSIVE_VALIDATION");;
+ private static final boolean DO_EXPENSIVE_VALIDATION = Boolean.getBoolean("gemfire.OFF_HEAP_DO_EXPENSIVE_VALIDATION");
public static MemoryAllocator create(OutOfOffHeapMemoryListener ooohml, OffHeapMemoryStats stats, LogWriter lw, int slabCount, long offHeapMemorySize, long maxSlabSize) {
SimpleMemoryAllocatorImpl result = singleton;
@@ -577,11 +577,11 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
if (addr >= 0 && addr < 1024) {
throw new IllegalStateException("addr was smaller than expected 0x" + addr);
}
- validateAddressAndSizeWithinSlab(addr, size);
+ validateAddressAndSizeWithinSlab(addr, size, DO_EXPENSIVE_VALIDATION);
}
- static void validateAddressAndSizeWithinSlab(long addr, int size) {
- if (DO_EXPENSIVE_VALIDATION) {
+ static void validateAddressAndSizeWithinSlab(long addr, int size, boolean doExpensiveValidation) {
+ if (doExpensiveValidation) {
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.singleton;
if (ma != null) {
for (int i=0; i < ma.slabs.length; i++) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e5d84829/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
index 7d02157..0d701d7 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
@@ -187,6 +187,43 @@ public class SimpleMemoryAllocatorJUnitTest {
}
}
@Test
+ public void testValidateAddressAndSize() {
+ final int SLAB_SIZE = 1024*1024;
+ UnsafeMemoryChunk slab = new UnsafeMemoryChunk(SLAB_SIZE);
+ try {
+ SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[]{slab});
+ try {
+ SimpleMemoryAllocatorImpl.validateAddress(0L);
+ fail("expected IllegalStateException");
+ } catch (IllegalStateException expected) {
+ assertEquals("Unexpected exception message: " + expected.getMessage(), true, expected.getMessage().contains("addr was smaller than expected"));
+ }
+ try {
+ SimpleMemoryAllocatorImpl.validateAddress(1L);
+ fail("expected IllegalStateException");
+ } catch (IllegalStateException expected) {
+ assertEquals("Unexpected exception message: " + expected.getMessage(), true, expected.getMessage().contains("Valid addresses must be in one of the following ranges:"));
+ }
+ SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(slab.getMemoryAddress(), SLAB_SIZE, false);
+ SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(slab.getMemoryAddress(), SLAB_SIZE, true);
+ SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(slab.getMemoryAddress(), -1, true);
+ try {
+ SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(slab.getMemoryAddress()-1, SLAB_SIZE, true);
+ fail("expected IllegalStateException");
+ } catch (IllegalStateException expected) {
+ assertEquals("Unexpected exception message: " + expected.getMessage(), true, expected.getMessage().equals(" address 0x" + Long.toString(slab.getMemoryAddress()-1, 16) + " does not address the original slab memory"));
+ }
+ try {
+ SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(slab.getMemoryAddress(), SLAB_SIZE+1, true);
+ fail("expected IllegalStateException");
+ } catch (IllegalStateException expected) {
+ assertEquals("Unexpected exception message: " + expected.getMessage(), true, expected.getMessage().equals(" address 0x" + Long.toString(slab.getMemoryAddress()+SLAB_SIZE, 16) + " does not address the original slab memory"));
+ }
+ } finally {
+ SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+ }
+ }
+ @Test
public void testClose() {
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024*1024);
boolean freeSlab = true;