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/01/27 01:20:08 UTC

[09/11] incubator-geode git commit: refactored the allocation code

refactored the allocation code


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

Branch: refs/heads/feature/GEODE-831
Commit: 8da4dd9da22ff86fb452c5c39ed463c2ffefb927
Parents: b6fb344
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon Jan 25 16:24:42 2016 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon Jan 25 16:24:42 2016 -0800

----------------------------------------------------------------------
 .../internal/offheap/FreeListManager.java       |  8 +------
 .../offheap/SimpleMemoryAllocatorImpl.java      | 23 +++++++++++++-------
 2 files changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8da4dd9d/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 ed4b533..55eea8c 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
@@ -168,14 +168,8 @@ public class FreeListManager {
     Chunk result = basicAllocate(size, true);
 
     result.setDataSize(size);
-    OffHeapMemoryStats stats = this.ma.getStats();
-    stats.incObjects(1);
-    int resultSize = result.getSize();
-    this.allocatedSize.addAndGet(resultSize);
-    stats.incUsedMemory(resultSize);
-    stats.incFreeMemory(-resultSize);
+    this.allocatedSize.addAndGet(result.getSize());
     result.initializeUseCount();
-    this.ma.notifyListeners();
 
     return result;
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8da4dd9d/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 6d2391c..7b58884 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
@@ -317,17 +317,27 @@ public class SimpleMemoryAllocatorImpl implements MemoryAllocator {
     }
   }
 
-  @Override
-  public MemoryChunk allocate(int size) {
-    //System.out.println("allocating " + size);
+  private Chunk allocateChunk(int size) {
     Chunk result = this.freeList.allocate(size);
-    //("allocated off heap object of size " + size + " @" + Long.toHexString(result.getMemoryAddress()), true);
+    int resultSize = result.getSize();
+    stats.incObjects(1);
+    stats.incUsedMemory(resultSize);
+    stats.incFreeMemory(-resultSize);
+    notifyListeners();
     if (ReferenceCountHelper.trackReferenceCounts()) {
       ReferenceCountHelper.refCountChanged(result.getMemoryAddress(), false, 1);
     }
     return result;
   }
   
+  @Override
+  public MemoryChunk allocate(int size) {
+    //System.out.println("allocating " + size);
+    Chunk result = allocateChunk(size);
+    //("allocated off heap object of size " + size + " @" + Long.toHexString(result.getMemoryAddress()), true);
+    return result;
+  }
+  
   public static void debugLog(String msg, boolean logStack) {
     if (logStack) {
       logger.info(msg, new RuntimeException(msg));
@@ -342,12 +352,9 @@ public class SimpleMemoryAllocatorImpl implements MemoryAllocator {
     if (addr != 0L) {
       return new DataAsAddress(addr);
     }
-    Chunk result = this.freeList.allocate(v.length);
+    Chunk result = allocateChunk(v.length);
     //debugLog("allocated off heap object of size " + v.length + " @" + Long.toHexString(result.getMemoryAddress()), true);
     //debugLog("allocated off heap object of size " + v.length + " @" + Long.toHexString(result.getMemoryAddress()) +  "chunkSize=" + result.getSize() + " isSerialized=" + isSerialized + " v=" + Arrays.toString(v), true);
-    if (ReferenceCountHelper.trackReferenceCounts()) {
-      ReferenceCountHelper.refCountChanged(result.getMemoryAddress(), false, 1);
-    }
     result.setSerializedValue(v);
     result.setSerialized(isSerialized);
     result.setCompressed(isCompressed);