geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [03/11] incubator-geode git commit: moved validateMemoryWithFill to FreeListManager
Date Wed, 27 Jan 2016 00:20:02 GMT
moved validateMemoryWithFill to FreeListManager


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/c9031b6b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/c9031b6b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/c9031b6b

Branch: refs/heads/feature/GEODE-831
Commit: c9031b6bbc6be8f1472c581f9ff73d7de80fa4b2
Parents: ad31878
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Mon Jan 25 10:55:23 2016 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Mon Jan 25 10:55:23 2016 -0800

----------------------------------------------------------------------
 .../gemfire/internal/offheap/Chunk.java         |  5 ---
 .../internal/offheap/FreeListManager.java       | 19 ++++++++---
 .../offheap/SimpleMemoryAllocatorImpl.java      |  6 ----
 .../internal/offheap/FreeListManagerTest.java   | 33 ++++++++++++++++++--
 4 files changed, 44 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c9031b6b/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 f38a3dc..f130b6e 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
@@ -722,11 +722,6 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
           ReferenceCountHelper.freeRefCountInfo(memAddr);
         }
         
-        // Use fill pattern for free list data integrity check.
-        if(SimpleMemoryAllocatorImpl.getAllocator().validateMemoryWithFill) {
-          fill(memAddr);
-        }
-        
         SimpleMemoryAllocatorImpl.getAllocator().freeChunk(memAddr);
       } else {
         if (ReferenceCountHelper.trackReferenceCounts()) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c9031b6b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
index e470692..37a5260 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
@@ -131,7 +131,7 @@ public class FreeListManager {
     }
     this.fragmentList = new CopyOnWriteArrayList<Fragment>(tmp);
 
-    if(ma.validateMemoryWithFill) {
+    if(this.validateMemoryWithFill) {
       fillFragments();
     }
   }
@@ -259,6 +259,11 @@ public class FreeListManager {
   }
 
   private final AtomicInteger compactCount = new AtomicInteger();
+  /*
+   * Set this to "true" to perform data integrity checks on allocated and reused Chunks.
 This may clobber 
+   * performance so turn on only when necessary.
+   */
+  final boolean validateMemoryWithFill = Boolean.getBoolean("gemfire.validateOffHeapWithFill");
   /**
    * How many extra allocations to do for each actual slab allocation.
    * Is this really a good idea?
@@ -427,7 +432,7 @@ public class FreeListManager {
         this.fragmentList.addAll(tmp);
 
         // Reinitialize fragments with fill pattern data
-        if(this.ma.validateMemoryWithFill) {
+        if(this.validateMemoryWithFill) {
           fillFragments();
         }
 
@@ -599,7 +604,7 @@ public class FreeListManager {
             allocSize -= chunkSize;
           }
 
-          if(this.ma.validateMemoryWithFill) {
+          if(this.validateMemoryWithFill) {
             result.validateFill();
           }
 
@@ -633,7 +638,7 @@ public class FreeListManager {
         Chunk result = this.ma.getChunkFactory().newChunk(memAddr, chunkType);
 
         // Data integrity check.
-        if(this.ma.validateMemoryWithFill) {          
+        if(this.validateMemoryWithFill) {          
           result.validateFill();
         }
 
@@ -657,7 +662,7 @@ public class FreeListManager {
         // close enough to the requested size; just return it.
 
         // Data integrity check.
-        if(this.ma.validateMemoryWithFill) {          
+        if(this.validateMemoryWithFill) {          
           result.validateFill();
         }
         if (chunkType.getSrcType() != Chunk.getSrcType(result.getMemoryAddress())) {
@@ -699,6 +704,10 @@ public class FreeListManager {
 
   @SuppressWarnings("synthetic-access")
   public void free(long addr) {
+    if (this.validateMemoryWithFill) {
+      Chunk.fill(addr);
+    }
+    
     free(addr, true);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c9031b6b/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 40233d3..b8f9a8b 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
@@ -568,11 +568,5 @@ public class SimpleMemoryAllocatorImpl implements MemoryAllocator {
   public MemoryInspector getMemoryInspector() {
     return this.memoryInspector;
   }
-
-  /*
-   * Set this to "true" to perform data integrity checks on allocated and reused Chunks.
 This may clobber 
-   * performance so turn on only when necessary.
-   */
-  final boolean validateMemoryWithFill = Boolean.getBoolean("gemfire.validateOffHeapWithFill");
   
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c9031b6b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
index 4cf883e..f544cd6 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
@@ -7,6 +7,7 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class FreeListManagerTest {
@@ -56,10 +57,36 @@ public class FreeListManagerTest {
   
   @Test
   public void allocateTinyChunkHasCorrectSize() {
-    Chunk c = this.freeListManager.allocate(10, null);
+    int tinySize = 10;
+    Chunk c = this.freeListManager.allocate(tinySize, null);
     assertNotNull(c);
-    assertEquals(10, c.getDataSize());
-    assertEquals(24, c.getSize());
+    assertEquals(tinySize, c.getDataSize());
+    assertEquals(computeExpectedSize(tinySize), c.getSize());
+  }
+
+  @Ignore
+  @Test
+  public void allocateTinyChunkFromFreeListHasCorrectSize() {
+    int tinySize = 10;
+    Chunk c = this.freeListManager.allocate(tinySize, null);
+    assertNotNull(c);
+    this.freeListManager.free(c.getMemoryAddress()); // TODO can't call free here
+    c = this.freeListManager.allocate(tinySize, null);
+    assertEquals(tinySize, c.getDataSize());
+    assertEquals(computeExpectedSize(tinySize), c.getSize());
+  }
+
+  @Test
+  public void allocateHugeChunkHasCorrectSize() {
+    int hugeSize = FreeListManager.MAX_TINY+1;
+    Chunk c = this.freeListManager.allocate(hugeSize, null);
+    assertNotNull(c);
+    assertEquals(hugeSize, c.getDataSize());
+    assertEquals(computeExpectedSize(hugeSize), c.getSize());
+  }
+  
+  private int computeExpectedSize(int dataSize) {
+    return ((dataSize + Chunk.OFF_HEAP_HEADER_SIZE + 7) / 8) * 8;
   }
 
   @Test


Mime
View raw message