mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [2/2] incubator-mnemonic git commit: MNEMONIC-382: Make durable object and factory class to accept reclaim context
Date Fri, 13 Oct 2017 21:54:25 GMT
MNEMONIC-382: Make durable object and factory class to accept reclaim context


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

Branch: refs/heads/master
Commit: 4b3d13b96e82cf75dec8c31aa4fcfe454922a111
Parents: 4f5be42
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Fri Oct 13 14:23:12 2017 -0700
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Fri Oct 13 14:23:12 2017 -0700

----------------------------------------------------------------------
 bin/mnemonic-checkstyle.xml                     |   3 +-
 .../collections/DurableArrayFactory.java        |  37 +++++-
 .../mnemonic/collections/DurableArrayImpl.java  |  24 ++--
 .../collections/DurableHashMapFactory.java      |  45 +++++--
 .../collections/DurableHashMapImpl.java         |  58 +++++----
 .../collections/DurableHashSetFactory.java      |  41 +++++-
 .../collections/DurableHashSetImpl.java         |  21 ++--
 .../collections/DurableTreeFactory.java         |  37 +++++-
 .../mnemonic/collections/DurableTreeImpl.java   |  21 ++--
 .../java/org/apache/mnemonic/Allocatable.java   |  10 +-
 .../mnemonic/AnnotatedDurableEntityClass.java   | 126 ++++++++++++++-----
 .../org/apache/mnemonic/CommonAllocator.java    |   4 +-
 .../java/org/apache/mnemonic/GenericField.java  |   7 +-
 .../org/apache/mnemonic/MemBufferHolder.java    |   2 +-
 .../org/apache/mnemonic/MemChunkHolder.java     |   2 +-
 .../java/org/apache/mnemonic/MemHolder.java     |   2 +-
 .../apache/mnemonic/MemoryDurableEntity.java    |   9 +-
 .../mnemonic/NonVolatileMemAllocator.java       |  13 +-
 .../apache/mnemonic/RetrievableAllocator.java   |  10 +-
 .../org/apache/mnemonic/SysMemAllocator.java    |   9 +-
 .../apache/mnemonic/VolatileMemAllocator.java   |  13 +-
 pom.xml                                         |   2 +-
 22 files changed, 346 insertions(+), 150 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/bin/mnemonic-checkstyle.xml
----------------------------------------------------------------------
diff --git a/bin/mnemonic-checkstyle.xml b/bin/mnemonic-checkstyle.xml
index 9beccb4..913cd1b 100644
--- a/bin/mnemonic-checkstyle.xml
+++ b/bin/mnemonic-checkstyle.xml
@@ -96,7 +96,8 @@
             <property name="max" value="200"/>
         </module>
         <module name="ParameterNumber">
-            <property name="max" value="8"/>
+            <property name="max" value="10"/>
+            <property name="ignoreOverriddenMethods" value="true"/>
         </module>
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayFactory.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayFactory.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayFactory.java
index 7e7cd8a..752b6db 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayFactory.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayFactory.java
@@ -22,6 +22,7 @@ import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.OutOfHybridMemory;
 import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.RestoreDurableEntityError;
+import org.flowcomputing.commons.resgc.ReclaimContext;
 
 public class DurableArrayFactory {
   public static <A extends RestorableAllocator<A>, E> DurableArray<E>
@@ -36,15 +37,27 @@ public class DurableArrayFactory {
 
   public static <A extends RestorableAllocator<A>, E> DurableArray<E>
               create(A allocator, int size, boolean autoreclaim) throws OutOfHybridMemory {
-    return create(allocator, null, null, size, autoreclaim);
+    return create(allocator, null, null, size, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableArray<E>
+              create(A allocator, int size, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws OutOfHybridMemory {
+    return create(allocator, null, null, size, autoreclaim, reclaimcontext);
   }
 
   public static <A extends RestorableAllocator<A>, E> DurableArray<E>
               create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
                    int size, boolean autoreclaim) throws OutOfHybridMemory {
+    return create(allocator, factoryproxys, gfields, size, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableArray<E>
+              create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   int size, boolean autoreclaim, ReclaimContext reclaimcontext) throws OutOfHybridMemory {
     DurableArrayImpl<A, E> entity = new DurableArrayImpl<A, E>(size);
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim);
+    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim, reclaimcontext);
     return entity;
   }
 
@@ -55,15 +68,29 @@ public class DurableArrayFactory {
 
   public static <A extends RestorableAllocator<A>, E> DurableArray<E>
               restore(A allocator, long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
-    return restore(allocator, null, null, phandler, autoreclaim);
+    return restore(allocator, null, null, phandler, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableArray<E>
+              restore(A allocator, long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
+    return restore(allocator, null, null, phandler, autoreclaim, reclaimcontext);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableArray<E>
+              restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   long phandler, boolean autoreclaim)
+          throws RestoreDurableEntityError {
+    return restore(allocator, factoryproxys, gfields, phandler, autoreclaim, null);
   }
 
   public static <A extends RestorableAllocator<A>, E> DurableArray<E>
               restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
-                   long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
+                   long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
     DurableArrayImpl<A, E> entity = new DurableArrayImpl<A, E>();
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim);
+    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim, reclaimcontext);
     return entity;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
index 705c8a2..a330937 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableArrayImpl.java
@@ -45,6 +45,7 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
   private EntityFactoryProxy[] factoryProxy;
   private DurableType[] genericType;
   private volatile boolean autoReclaim;
+  private volatile ReclaimContext reclaimcontext;
   private MemChunkHolder<A> holder;
   private A allocator;
 
@@ -77,7 +78,7 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
         throw new RetrieveDurableEntityError("No Generic Field Type Info.");
       }
       genericField[index] = new GenericField<A, E>(proxy, gftype, factoryProxy, genericType, allocator,
-                                  unsafe, autoReclaim, holder.get() + index * MAX_OBJECT_SIZE);
+                                  unsafe, autoReclaim, reclaimcontext, holder.get() + index * MAX_OBJECT_SIZE);
     }
     if (null != genericField[index]) {
       return ((GenericField<A, E>)genericField[index]).get();
@@ -122,7 +123,7 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
         throw new RetrieveDurableEntityError("No Generic Field Type Info.");
       }
       genericField[index] = new GenericField<A, E>(proxy, gftype, factoryProxy, genericType, allocator,
-                                  unsafe, autoReclaim, holder.get() + index * MAX_OBJECT_SIZE);
+                                  unsafe, autoReclaim, reclaimcontext, holder.get() + index * MAX_OBJECT_SIZE);
     }
     if (null != genericField[index]) {
       ((GenericField<A, E>)genericField[index]).set(value, destroy);
@@ -188,13 +189,14 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void registerAutoReclaim() {
-    this.registerAutoReclaim(null);
+    this.registerAutoReclaim(reclaimcontext);
   }
 
   @Override
   public void registerAutoReclaim(ReclaimContext rctx) {
     holder.registerAutoReclaim(rctx);
     autoReclaim = true;
+    reclaimcontext = rctx;
   }
 
   @Override
@@ -204,12 +206,13 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void restoreDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-             DurableType[] gType, long phandler, boolean autoReclaim) throws RestoreDurableEntityError {
-    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim);
+             DurableType[] gType, long phandler, boolean autoReclaim, ReclaimContext rctx)
+          throws RestoreDurableEntityError {
+    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim, reclaimcontext);
     if (0L == phandler) {
       throw new RestoreDurableEntityError("Input handler is null on restoreDurableEntity.");
     }
-    holder = allocator.retrieveChunk(phandler, autoReclaim);
+    holder = allocator.retrieveChunk(phandler, autoReclaim, rctx);
     if (null == holder) {
       throw new RestoreDurableEntityError("Retrieve Entity Failure!");
     }
@@ -221,11 +224,12 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void initializeDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-              DurableType[] gType, boolean autoReclaim) {
+              DurableType[] gType, boolean autoReclaim, ReclaimContext rctx) {
     this.allocator = allocator;
     this.factoryProxy = factoryProxy;
     this.genericType = gType;
     this.autoReclaim = autoReclaim;
+    this.reclaimcontext = rctx;
     try {
       this.unsafe = Utils.getUnsafe();
     } catch (Exception e) {
@@ -235,9 +239,9 @@ public class DurableArrayImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void createDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-              DurableType[] gType, boolean autoReclaim) throws OutOfHybridMemory {
-    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim);
-    this.holder = allocator.createChunk(MAX_OBJECT_SIZE * arraySize, autoReclaim);
+              DurableType[] gType, boolean autoReclaim, ReclaimContext rctx) throws OutOfHybridMemory {
+    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim, rctx);
+    this.holder = allocator.createChunk(MAX_OBJECT_SIZE * arraySize, autoReclaim, reclaimcontext);
     if (null == this.holder) {
       throw new OutOfHybridMemory("Create Durable Entity Error!");
     }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapFactory.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapFactory.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapFactory.java
index 5f04da7..dde17ed 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapFactory.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapFactory.java
@@ -22,6 +22,7 @@ import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.OutOfHybridMemory;
 import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.RestoreDurableEntityError;
+import org.flowcomputing.commons.resgc.ReclaimContext;
 
 public class DurableHashMapFactory {
   public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
@@ -36,16 +37,30 @@ public class DurableHashMapFactory {
 
   public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V> 
               create(A allocator, long initialCapacity, boolean autoreclaim) throws OutOfHybridMemory {
-    return create(allocator, null, null, initialCapacity, autoreclaim);
+    return create(allocator, null, null, initialCapacity, autoreclaim, null);
   }
 
-  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V> 
+  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
+              create(A allocator, long initialCapacity, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws OutOfHybridMemory {
+    return create(allocator, null, null, initialCapacity, autoreclaim, reclaimcontext);
+  }
+
+  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
+              create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   long initialCapacity, boolean autoreclaim)
+          throws OutOfHybridMemory {
+    return create(allocator, factoryproxys, gfields, initialCapacity, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
               create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields, 
-                   long initialCapacity, boolean autoreclaim) throws OutOfHybridMemory {
+                   long initialCapacity, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws OutOfHybridMemory {
     DurableHashMapImpl<A, K, V> entity = new DurableHashMapImpl<A, K, V>();
     entity.setCapacityHint(initialCapacity);
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim);
+    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim, reclaimcontext);
     return entity;
   }
 
@@ -56,15 +71,29 @@ public class DurableHashMapFactory {
 
   public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V> 
               restore(A allocator, long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
-    return restore(allocator, null, null, phandler, autoreclaim);
+    return restore(allocator, null, null, phandler, autoreclaim, null);
   }
 
-  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V> 
+  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
+              restore(A allocator, long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
+    return restore(allocator, null, null, phandler, autoreclaim, reclaimcontext);
+  }
+
+  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
+              restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   long phandler, boolean autoreclaim)
+          throws RestoreDurableEntityError {
+    return restore(allocator, factoryproxys, gfields, phandler, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, K, V> DurableHashMap<K, V>
               restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
-                   long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
+                   long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
     DurableHashMapImpl<A, K, V> entity = new DurableHashMapImpl<A, K, V>();
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim);
+    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim, reclaimcontext);
     return entity;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
index 0c20245..048c1e8 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashMapImpl.java
@@ -51,6 +51,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
   private DurableType[] listgftypes;
   private volatile boolean autoResize = true;
   private volatile boolean autoReclaim;
+  private volatile ReclaimContext reclaimcontext;
   private MemChunkHolder<A> holder;
   private MemChunkHolder<A> chunkAddr;
   private A allocator;
@@ -116,8 +117,8 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
       DurableSinglyLinkedList<MapEntry<K, V>> head = null;
       MapEntry<K, V> entry = null;
       try {
-        head = DurableSinglyLinkedListFactory.create(allocator, listefproxies, listgftypes, false);
-        entry = MapEntryFactory.create(allocator, factoryProxy, genericField, false);
+        head = DurableSinglyLinkedListFactory.create(allocator, listefproxies, listgftypes, false, reclaimcontext);
+        entry = MapEntryFactory.create(allocator, factoryProxy, genericField, false, reclaimcontext);
       } catch (OutOfHybridMemory fe) {
         if (null != head) {
           head.destroy();
@@ -134,7 +135,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
       mapSize++;
     } else {
       DurableSinglyLinkedList<MapEntry<K, V>> head = DurableSinglyLinkedListFactory.restore(allocator,
-          listefproxies, listgftypes, handler, false);
+          listefproxies, listgftypes, handler, false, reclaimcontext);
       DurableSinglyLinkedList<MapEntry<K, V>> prev = head;
       boolean found = false;
       while (null != head) {
@@ -157,8 +158,9 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
         DurableSinglyLinkedList<MapEntry<K, V>> newNode = null;
         MapEntry<K, V> entry = null;
         try {
-          newNode = DurableSinglyLinkedListFactory.create(allocator, listefproxies, listgftypes, false);
-          entry = MapEntryFactory.create(allocator, factoryProxy, genericField, false);
+          newNode = DurableSinglyLinkedListFactory.create(allocator, listefproxies, listgftypes,
+                  false, reclaimcontext);
+          entry = MapEntryFactory.create(allocator, factoryProxy, genericField, false, reclaimcontext);
         } catch (OutOfHybridMemory fe) {
           if (null != newNode) {
             newNode.destroy();
@@ -210,7 +212,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
     long handler = unsafe.getAddress(bucketAddr);
     if (0L != handler) {
       DurableSinglyLinkedList<MapEntry<K, V>> head = DurableSinglyLinkedListFactory.restore(allocator,
-          listefproxies, listgftypes, handler, false);
+          listefproxies, listgftypes, handler, false, reclaimcontext);
       while (null != head) {
         MapEntry<K, V> mapEntry = head.getItem();
         K entryKey = mapEntry.getKey();
@@ -256,7 +258,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
     long handler = unsafe.getAddress(bucketAddr);
     if (0L != handler) {
       DurableSinglyLinkedList<MapEntry<K, V>> head = DurableSinglyLinkedListFactory.restore(allocator,
-          listefproxies, listgftypes, handler, false);
+          listefproxies, listgftypes, handler, false, reclaimcontext);
       DurableSinglyLinkedList<MapEntry<K, V>> prev = null;
       boolean found = false;
       while (null != head) {
@@ -312,7 +314,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
       long handler = unsafe.getAddress(bucketAddr);
       if (0L != handler) {
         DurableSinglyLinkedList<MapEntry<K, V>> head = DurableSinglyLinkedListFactory.restore(allocator,
-            listefproxies, listgftypes, handler, false);
+            listefproxies, listgftypes, handler, false, reclaimcontext);
         DurableSinglyLinkedList<MapEntry<K, V>> curr = head;
         while (null != curr) {
           curr = curr.getNext();
@@ -338,7 +340,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
     long handler = unsafe.getAddress(bucketAddr);
     if (0L != handler) {
       DurableSinglyLinkedList<MapEntry<K, V>> head = DurableSinglyLinkedListFactory.restore(allocator,
-          listefproxies, listgftypes, handler, false);
+          listefproxies, listgftypes, handler, false, reclaimcontext);
       elem.setNext(head, false);
     } else {
       elem.setNext(null, false);
@@ -359,7 +361,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
       long handler = unsafe.getAddress(bucketAddr);
       if (0L != handler) {
         DurableSinglyLinkedList<MapEntry<K, V>> head = DurableSinglyLinkedListFactory.restore(allocator,
-            listefproxies, listgftypes, handler, false);
+            listefproxies, listgftypes, handler, false, reclaimcontext);
         while (null != head) {
           size++;
           head = head.getNext();
@@ -413,7 +415,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
       long handler = unsafe.getAddress(bucketAddr);
       if (0L != handler) {
         head = DurableSinglyLinkedListFactory.restore(allocator,
-            listefproxies, listgftypes, handler, false);
+            listefproxies, listgftypes, handler, false, reclaimcontext);
         prev = head;
         while (null != head) {
           head = head.getNext();
@@ -435,13 +437,14 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
 
   @Override
   public void registerAutoReclaim() {
-    this.registerAutoReclaim(null);
+    this.registerAutoReclaim(reclaimcontext);
   }
 
   @Override
   public void registerAutoReclaim(ReclaimContext rctx) {
     holder.registerAutoReclaim(rctx);
     autoReclaim = true;
+    reclaimcontext = rctx;
   }
 
   @Override
@@ -451,14 +454,15 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
 
   @Override
   public void restoreDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy, 
-             DurableType[] gField, long phandler, boolean autoReclaim) throws RestoreDurableEntityError {
-    initializeDurableEntity(allocator, factoryProxy, gField, autoReclaim);
+             DurableType[] gField, long phandler, boolean autoReclaim, ReclaimContext rctx)
+          throws RestoreDurableEntityError {
+    initializeDurableEntity(allocator, factoryProxy, gField, autoReclaim, rctx);
     if (0L == phandler) {
       throw new RestoreDurableEntityError("Input handler is null on restoreDurableEntity.");
     }
-    chunkAddr = allocator.retrieveChunk(phandler, autoReclaim);
+    chunkAddr = allocator.retrieveChunk(phandler, autoReclaim, reclaimcontext);
     long chunkHandler = unsafe.getLong(chunkAddr.get());
-    holder = allocator.retrieveChunk(chunkHandler, autoReclaim);
+    holder = allocator.retrieveChunk(chunkHandler, autoReclaim, reclaimcontext);
     if (null == holder || null == chunkAddr) {
       throw new RestoreDurableEntityError("Retrieve Entity Failure!");
     }
@@ -470,11 +474,12 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
 
   @Override
   public void initializeDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy, 
-              DurableType[] gField, boolean autoReclaim) {
+              DurableType[] gField, boolean autoReclaim, ReclaimContext rctx) {
     this.allocator = allocator;
     this.factoryProxy = factoryProxy;
     this.genericField = gField;
     this.autoReclaim = autoReclaim;
+    this.reclaimcontext = rctx;
     DurableType gftypes[] = {DurableType.DURABLE};
     this.listgftypes = ArrayUtils.addAll(gftypes, genericField);
     EntityFactoryProxy efproxies[] = {new EntityFactoryProxy() {
@@ -483,27 +488,28 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
           A allocator, EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, long phandler, boolean autoreclaim) {
           Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
-        return MapEntryFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
+        return MapEntryFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim, reclaimcontext);
           }
       @Override
       public <A extends RestorableAllocator<A>> MapEntry<K, V> restore(ParameterHolder<A> ph) {
           Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
               ph.getEntityFactoryProxies(), 1);
         return MapEntryFactory.restore(ph.getAllocator(),
-              dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
+              dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim(), reclaimcontext);
           }
       @Override
       public <A extends RestorableAllocator<A>> MapEntry<K, V> create(
           A allocator, EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, boolean autoreclaim) {
           Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
-        return MapEntryFactory.create(allocator, dpt.getRight(), dpt.getLeft(), autoreclaim);
+        return MapEntryFactory.create(allocator, dpt.getRight(), dpt.getLeft(), autoreclaim, reclaimcontext);
           }
       @Override
       public <A extends RestorableAllocator<A>> MapEntry<K, V> create(ParameterHolder<A> ph) {
           Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
               ph.getEntityFactoryProxies(), 1);
-        return MapEntryFactory.create(ph.getAllocator(), dpt.getRight(), dpt.getLeft(), ph.getAutoReclaim());
+        return MapEntryFactory.create(ph.getAllocator(), dpt.getRight(), dpt.getLeft(),
+                ph.getAutoReclaim(), reclaimcontext);
           }
     }
     };
@@ -517,10 +523,10 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
 
   @Override
   public void createDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy, 
-              DurableType[] gField, boolean autoReclaim) throws OutOfHybridMemory {
-    initializeDurableEntity(allocator, factoryProxy, gField, autoReclaim);
-    this.holder = allocator.createChunk(MAX_OBJECT_SIZE * totalCapacity, autoReclaim);
-    this.chunkAddr = allocator.createChunk(MAX_OBJECT_SIZE, autoReclaim);
+              DurableType[] gField, boolean autoReclaim, ReclaimContext rctx) throws OutOfHybridMemory {
+    initializeDurableEntity(allocator, factoryProxy, gField, autoReclaim, rctx);
+    this.holder = allocator.createChunk(MAX_OBJECT_SIZE * totalCapacity, autoReclaim, reclaimcontext);
+    this.chunkAddr = allocator.createChunk(MAX_OBJECT_SIZE, autoReclaim, reclaimcontext);
     unsafe.putLong(chunkAddr.get(), allocator.getChunkHandler(holder));
     if (null == this.holder || null == this.chunkAddr) {
       throw new OutOfHybridMemory("Create Durable Entity Error!");
@@ -559,7 +565,7 @@ public class DurableHashMapImpl<A extends RestorableAllocator<A>, K, V>
         long handler = unsafe.getAddress(currentBucketAddr);
         if (0L != handler) {
           currentNode = DurableSinglyLinkedListFactory.restore(allocator,
-              listefproxies, listgftypes, handler, false);
+              listefproxies, listgftypes, handler, false, reclaimcontext);
           break;
         }
         currentBucketAddr += MAX_OBJECT_SIZE;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetFactory.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetFactory.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetFactory.java
index f654753..9e9b5e0 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetFactory.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetFactory.java
@@ -22,6 +22,7 @@ import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.OutOfHybridMemory;
 import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.RestoreDurableEntityError;
+import org.flowcomputing.commons.resgc.ReclaimContext;
 
 public class DurableHashSetFactory {
   public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
@@ -36,16 +37,30 @@ public class DurableHashSetFactory {
 
   public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
               create(A allocator, long initialCapacity, boolean autoreclaim) throws OutOfHybridMemory {
-    return create(allocator, null, null, initialCapacity, autoreclaim);
+    return create(allocator, null, null, initialCapacity, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
+              create(A allocator, long initialCapacity, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws OutOfHybridMemory {
+    return create(allocator, null, null, initialCapacity, autoreclaim, reclaimcontext);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
+              create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   long initialCapacity, boolean autoreclaim)
+          throws OutOfHybridMemory {
+    return create(allocator, factoryproxys, gfields, initialCapacity, autoreclaim, null);
   }
 
   public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
               create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
-                   long initialCapacity, boolean autoreclaim) throws OutOfHybridMemory {
+                   long initialCapacity, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws OutOfHybridMemory {
     DurableHashSetImpl<A, E> entity = new DurableHashSetImpl<A, E>();
     entity.setCapacityHint(initialCapacity);
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim);
+    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim, reclaimcontext);
     return entity;
   }
 
@@ -56,15 +71,29 @@ public class DurableHashSetFactory {
 
   public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
               restore(A allocator, long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
-    return restore(allocator, null, null, phandler, autoreclaim);
+    return restore(allocator, null, null, phandler, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
+              restore(A allocator, long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
+    return restore(allocator, null, null, phandler, autoreclaim, reclaimcontext);
+  }
+
+  public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
+  restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+          long phandler, boolean autoreclaim)
+          throws RestoreDurableEntityError {
+    return restore(allocator, factoryproxys, gfields, phandler, autoreclaim, null);
   }
 
   public static <A extends RestorableAllocator<A>, E> DurableHashSet<E>
               restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
-                   long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
+                   long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
     DurableHashSetImpl<A, E> entity = new DurableHashSetImpl<A, E>();
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim);
+    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim, reclaimcontext);
     return entity;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
index 11fb695..3f38c88 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableHashSetImpl.java
@@ -40,6 +40,7 @@ public class DurableHashSetImpl<A extends RestorableAllocator<A>, E>
   private EntityFactoryProxy[] factoryProxy;
   private DurableType[] genericType;
   private volatile boolean autoReclaim;
+  private volatile ReclaimContext reclaimcontext;
   private DurableHashMap<E, Boolean> map;
   private A allocator;
   private long initialCapacity;
@@ -136,13 +137,14 @@ public class DurableHashSetImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void registerAutoReclaim() {
-    this.registerAutoReclaim(null);
+    this.registerAutoReclaim(reclaimcontext);
   }
 
   @Override
   public void registerAutoReclaim(ReclaimContext rctx) {
     map.registerAutoReclaim(rctx);
     autoReclaim = true;
+    reclaimcontext = rctx;
   }
 
   @Override
@@ -152,12 +154,14 @@ public class DurableHashSetImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void restoreDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-             DurableType[] gType, long phandler, boolean autoReclaim) throws RestoreDurableEntityError {
-    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim);
+             DurableType[] gType, long phandler, boolean autoReclaim, ReclaimContext rctx)
+          throws RestoreDurableEntityError {
+    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim, rctx);
     if (0L == phandler) {
       throw new RestoreDurableEntityError("Input handler is null on restoreDurableEntity.");
     }
-    map = DurableHashMapFactory.restore(allocator, this.factoryProxy, this.genericType, phandler, autoReclaim);
+    map = DurableHashMapFactory.restore(allocator, this.factoryProxy, this.genericType, phandler,
+            autoReclaim, reclaimcontext);
     if (null == map) {
       throw new RestoreDurableEntityError("Retrieve Entity Failure!");
     }
@@ -167,7 +171,7 @@ public class DurableHashSetImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void initializeDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-              DurableType[] gType, boolean autoReclaim) {
+              DurableType[] gType, boolean autoReclaim, ReclaimContext rctx) {
     this.allocator = allocator;
     this.autoReclaim = autoReclaim;
     DurableType gftypes[] = {DurableType.BOOLEAN};
@@ -182,9 +186,10 @@ public class DurableHashSetImpl<A extends RestorableAllocator<A>, E>
 
   @Override
   public void createDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-              DurableType[] gType, boolean autoReclaim) throws OutOfHybridMemory {
-    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim);
-    map = DurableHashMapFactory.create(allocator, this.factoryProxy, this.genericType, initialCapacity, autoReclaim);
+              DurableType[] gType, boolean autoReclaim, ReclaimContext rctx) throws OutOfHybridMemory {
+    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim, rctx);
+    map = DurableHashMapFactory.create(allocator, this.factoryProxy, this.genericType, initialCapacity,
+            autoReclaim, reclaimcontext);
     initializeAfterCreate();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeFactory.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeFactory.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeFactory.java
index cb479f4..2be1607 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeFactory.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeFactory.java
@@ -22,6 +22,7 @@ import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.OutOfHybridMemory;
 import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.RestoreDurableEntityError;
+import org.flowcomputing.commons.resgc.ReclaimContext;
 
 public class DurableTreeFactory {
   public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
@@ -31,15 +32,27 @@ public class DurableTreeFactory {
 
   public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
               create(A allocator, boolean autoreclaim) throws OutOfHybridMemory {
-    return create(allocator, null, null, autoreclaim);
+    return create(allocator, null, null, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
+              create(A allocator, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws OutOfHybridMemory {
+    return create(allocator, null, null, autoreclaim, reclaimcontext);
   }
 
   public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
               create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
                    boolean autoreclaim) throws OutOfHybridMemory {
+    return create(allocator, factoryproxys, gfields, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
+              create(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   boolean autoreclaim, ReclaimContext reclaimcontext) throws OutOfHybridMemory {
     DurableTreeImpl<A, E> entity = new DurableTreeImpl<A, E>();
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim);
+    entity.createDurableEntity(allocator, factoryproxys, gfields, autoreclaim, reclaimcontext);
     return entity;
   }
 
@@ -50,15 +63,29 @@ public class DurableTreeFactory {
 
   public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
               restore(A allocator, long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
-    return restore(allocator, null, null, phandler, autoreclaim);
+    return restore(allocator, null, null, phandler, autoreclaim, null);
+  }
+
+  public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
+              restore(A allocator, long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
+    return restore(allocator, null, null, phandler, autoreclaim, reclaimcontext);
+  }
+
+  public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
+              restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
+                   long phandler, boolean autoreclaim)
+          throws RestoreDurableEntityError {
+    return restore(allocator, factoryproxys, gfields, phandler, autoreclaim, null);
   }
 
   public static <A extends RestorableAllocator<A>, E extends Comparable<E>> DurableTree<E>
               restore(A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields,
-                   long phandler, boolean autoreclaim) throws RestoreDurableEntityError {
+                   long phandler, boolean autoreclaim, ReclaimContext reclaimcontext)
+          throws RestoreDurableEntityError {
     DurableTreeImpl<A, E> entity = new DurableTreeImpl<A, E>();
     entity.setupGenericInfo(factoryproxys, gfields);
-    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim);
+    entity.restoreDurableEntity(allocator, factoryproxys, gfields, phandler, autoreclaim, reclaimcontext);
     return entity;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
index df70ff4..df709c1 100644
--- a/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
+++ b/mnemonic-collections/src/main/java/org/apache/mnemonic/collections/DurableTreeImpl.java
@@ -39,6 +39,7 @@ public class DurableTreeImpl<A extends RestorableAllocator<A>, E extends Compara
   private EntityFactoryProxy[] factoryProxy;
   private DurableType[] genericType;
   private volatile boolean autoReclaim;
+  private volatile ReclaimContext reclaimcontext;
   private A allocator;
   private MemChunkHolder<A> holder;
   private static final long MAX_OBJECT_SIZE = 8;
@@ -54,7 +55,7 @@ public class DurableTreeImpl<A extends RestorableAllocator<A>, E extends Compara
    */
   public void insert(E item) throws OutOfHybridMemory {
     TreeNode<E> tmp = root;
-    TreeNode<E> node = TreeNodeFactory.create(allocator, factoryProxy, genericType, autoReclaim);
+    TreeNode<E> node = TreeNodeFactory.create(allocator, factoryProxy, genericType, autoReclaim, reclaimcontext);
     node.setItem(item, false);
     if (null == root) {
       root = node;
@@ -546,12 +547,13 @@ public class DurableTreeImpl<A extends RestorableAllocator<A>, E extends Compara
 
   @Override
   public void registerAutoReclaim() {
-    this.registerAutoReclaim(null);
+    this.registerAutoReclaim(reclaimcontext);
   }
 
   @Override
   public void registerAutoReclaim(ReclaimContext rctx) {
     autoReclaim = true;
+    reclaimcontext = rctx;
   }
 
   @Override
@@ -561,21 +563,22 @@ public class DurableTreeImpl<A extends RestorableAllocator<A>, E extends Compara
 
   @Override
   public void restoreDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-      DurableType[] gType, long phandler, boolean autoReclaim) throws RestoreDurableEntityError {
-    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim);
+      DurableType[] gType, long phandler, boolean autoReclaim, ReclaimContext rctx)
+          throws RestoreDurableEntityError {
+    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim, rctx);
     if (0L == phandler) {
       throw new RestoreDurableEntityError("Input handler is null on restoreDurableEntity.");
     }
     holder = allocator.retrieveChunk(phandler, autoReclaim);
     long rootHandler = unsafe.getLong(holder.get());
-    root = TreeNodeFactory.restore(allocator, factoryProxy, genericType, rootHandler, autoReclaim);
+    root = TreeNodeFactory.restore(allocator, factoryProxy, genericType, rootHandler, autoReclaim, reclaimcontext);
     initializeAfterRestore();
   }
 
 
   @Override
   public void initializeDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-      DurableType[] gType, boolean autoReclaim) {
+      DurableType[] gType, boolean autoReclaim, ReclaimContext rctx) {
     this.allocator = allocator;
     this.factoryProxy = factoryProxy;
     this.genericType = gType;
@@ -589,9 +592,9 @@ public class DurableTreeImpl<A extends RestorableAllocator<A>, E extends Compara
 
   @Override
   public void createDurableEntity(A allocator, EntityFactoryProxy[] factoryProxy,
-      DurableType[] gType, boolean autoReclaim) throws OutOfHybridMemory {
-    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim);
-    this.holder = allocator.createChunk(MAX_OBJECT_SIZE, autoReclaim);
+      DurableType[] gType, boolean autoReclaim, ReclaimContext rctx) throws OutOfHybridMemory {
+    initializeDurableEntity(allocator, factoryProxy, gType, autoReclaim, rctx);
+    this.holder = allocator.createChunk(MAX_OBJECT_SIZE, autoReclaim, reclaimcontext);
     initializeAfterCreate();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/Allocatable.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Allocatable.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Allocatable.java
index 3ea7093..93e4650 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/Allocatable.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Allocatable.java
@@ -19,8 +19,6 @@ package org.apache.mnemonic;
 
 import org.flowcomputing.commons.resgc.ReclaimContext;
 
-import java.nio.ByteBuffer;
-
 /**
  * an interface to allocate memory resources from any underlying memory kind of
  * storage.
@@ -65,7 +63,7 @@ public interface Allocatable<A extends CommonAllocator<A>> {
    *
    * @return a holder contains a memory chunk
    */
-  MemChunkHolder<A> createChunk(long size, boolean autoreclaim, ReclaimContext<Long> rctx);
+  MemChunkHolder<A> createChunk(long size, boolean autoreclaim, ReclaimContext rctx);
 
   /**
    * create a memory buffer that is managed by its holder.
@@ -104,7 +102,7 @@ public interface Allocatable<A extends CommonAllocator<A>> {
    *
    * @return a holder contains a memory buffer
    */
-  MemBufferHolder<A> createBuffer(long size, boolean autoreclaim, ReclaimContext<ByteBuffer> rctx);
+  MemBufferHolder<A> createBuffer(long size, boolean autoreclaim, ReclaimContext rctx);
 
   /**
    * register a memory chunk for auto-reclaim
@@ -115,7 +113,7 @@ public interface Allocatable<A extends CommonAllocator<A>> {
    * @param rctx
    *          specify a reclaim context
    */
-  void registerChunkAutoReclaim(MemChunkHolder<A> mholder, ReclaimContext<Long> rctx);
+  void registerChunkAutoReclaim(MemChunkHolder<A> mholder, ReclaimContext rctx);
 
     /**
      * register a memory chunk for auto-reclaim
@@ -134,7 +132,7 @@ public interface Allocatable<A extends CommonAllocator<A>> {
    * @param rctx
    *          specify a reclaim context
    */
-  void registerBufferAutoReclaim(MemBufferHolder<A> mholder, ReclaimContext<ByteBuffer> rctx);
+  void registerBufferAutoReclaim(MemBufferHolder<A> mholder, ReclaimContext rctx);
 
   /**
    * register a memory buffer for auto-reclaim

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java b/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
index 87b45f4..3c12463 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
@@ -55,6 +55,7 @@ import com.squareup.javapoet.TypeName;
 import com.squareup.javapoet.TypeSpec;
 import com.squareup.javapoet.TypeVariableName;
 
+import org.flowcomputing.commons.resgc.ReclaimContext;
 import sun.misc.Unsafe;
 
 /**
@@ -107,6 +108,7 @@ public class AnnotatedDurableEntityClass {
   private TypeVariableName m_alloctypevarname = TypeVariableName.get(cALLOCTYPENAME,
       ParameterizedTypeName.get(ClassName.get(RestorableAllocator.class), m_alloctypename));
   private TypeName m_parameterholder = ParameterizedTypeName.get(ClassName.get(ParameterHolder.class), m_alloctypename);
+  private TypeName m_reclaimctxtypename = TypeName.get(ReclaimContext.class);
 
   private Map<String, MethodInfo> m_gettersinfo = new HashMap<String, MethodInfo>();
   private Map<String, MethodInfo> m_settersinfo = new HashMap<String, MethodInfo>();
@@ -238,6 +240,12 @@ public class AnnotatedDurableEntityClass {
     m_fieldsinfo.put("autoreclaim", fieldinfo);
 
     fieldinfo = new FieldInfo();
+    fieldinfo.name = String.format("m_reclaimcontext_%s", Utils.genRandomString());
+    fieldinfo.type = m_reclaimctxtypename;
+    fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE, Modifier.VOLATILE);
+    m_fieldsinfo.put("reclaimcontext", fieldinfo);
+
+    fieldinfo = new FieldInfo();
     fieldinfo.name = String.format("m_allocator_%s", Utils.genRandomString());
     fieldinfo.type = m_alloctypename;
     fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
@@ -475,6 +483,7 @@ public class AnnotatedDurableEntityClass {
     String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
     String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
     String genericfieldname = m_fieldsinfo.get("genericfield").name;
+    String reclaimctxname = m_fieldsinfo.get("reclaimcontext").name;
     FieldInfo dynfieldinfo;
     CodeBlock.Builder code;
     String codefmt;
@@ -497,8 +506,8 @@ public class AnnotatedDurableEntityClass {
           code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)", unsafename, holdername,
               dynfieldinfo.fieldoff);
           code.beginControlFlow("if (0L != phandler)");
-          code.addStatement("$1N = $2N.retrieveChunk(phandler, $3N)",
-              dynfieldinfo.name, allocname, autoreclaimname);
+          code.addStatement("$1N = $2N.retrieveChunk(phandler, $3N, $4N)",
+              dynfieldinfo.name, allocname, autoreclaimname, reclaimctxname);
           code.endControlFlow();
           code.endControlFlow();
           code.addStatement("return $1N", dynfieldinfo.name);
@@ -507,8 +516,8 @@ public class AnnotatedDurableEntityClass {
           code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)", unsafename, holdername,
               dynfieldinfo.fieldoff);
           code.beginControlFlow("if (0L != phandler)");
-          code.addStatement("$1N = $2N.retrieveBuffer(phandler, $3N)",
-              dynfieldinfo.name, allocname, autoreclaimname);
+          code.addStatement("$1N = $2N.retrieveBuffer(phandler, $3N, $4N)",
+              dynfieldinfo.name, allocname, autoreclaimname, reclaimctxname);
           code.endControlFlow();
           code.endControlFlow();
           code.addStatement("return $1N", dynfieldinfo.name);
@@ -517,7 +526,8 @@ public class AnnotatedDurableEntityClass {
           code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)", unsafename, holdername,
               dynfieldinfo.fieldoff);
           code.beginControlFlow("if (0L != phandler)");
-          code.addStatement("$1N = $2N.retrieveBuffer(phandler, $3N)", dynfieldinfo.name, allocname, autoreclaimname);
+          code.addStatement("$1N = $2N.retrieveBuffer(phandler, $3N, $4N)",
+              dynfieldinfo.name, allocname, autoreclaimname, reclaimctxname);
           code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
           code.addStatement("throw new RetrieveDurableEntityError(\"Retrieve String Buffer Failure.\")");
           code.endControlFlow();
@@ -537,9 +547,9 @@ public class AnnotatedDurableEntityClass {
           code.nextControlFlow("else");
           code.addStatement("throw new RetrieveDurableEntityError(\"No Generic Field Type Info.\")");
           code.endControlFlow();
-          code.addStatement("$1N = new $2T(proxy, gftype, $8L, $9L, $3N, $4N, $5N, $6N.get() + $7L)", dynfieldinfo.name,
-              dynfieldinfo.type, allocname, unsafename, autoreclaimname, holdername, dynfieldinfo.fieldoff,
-              dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
+          code.addStatement("$1N = new $2T(proxy, gftype, $9L, $10L, $3N, $4N, $5N, $6N, $7N.get() + $8L)",
+                  dynfieldinfo.name, dynfieldinfo.type, allocname, unsafename, autoreclaimname, reclaimctxname,
+                  holdername, dynfieldinfo.fieldoff, dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
           code.endControlFlow();
           code.addStatement("return $1N.get()", dynfieldinfo.name);
         } else {
@@ -547,8 +557,8 @@ public class AnnotatedDurableEntityClass {
           code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)", unsafename, holdername,
               dynfieldinfo.fieldoff);
           code.beginControlFlow("if (0L != phandler)");
-          code.addStatement("$1N = $4N.restore($2N, $5L, $6L, phandler, $3N)", dynfieldinfo.name, allocname,
-              autoreclaimname, String.format("%s%s",
+          code.addStatement("$1N = $5N.restore($2N, $6L, $7L, phandler, $3N, $4N)", dynfieldinfo.name, allocname,
+              autoreclaimname, reclaimctxname, String.format("%s%s",
                   m_typeutils.asElement(methodinfo.elem.getReturnType()).getSimpleName(), cFACTORYNAMESUFFIX),
               dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
           code.endControlFlow();
@@ -575,6 +585,7 @@ public class AnnotatedDurableEntityClass {
     String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
     String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
     String genericfieldname = m_fieldsinfo.get("genericfield").name;
+    String reclaimctxname = m_fieldsinfo.get("reclaimcontext").name;
     FieldInfo dynfieldinfo;
     CodeBlock.Builder code;
     VariableElement arg0;
@@ -623,9 +634,9 @@ public class AnnotatedDurableEntityClass {
               unsafename, holdername, dynfieldinfo.fieldoff, dynfieldinfo.name);
           code.beginControlFlow("if (null != $1L)", dynfieldinfo.name);
           code.beginControlFlow("if ($1N)", autoreclaimname);
-          code.addStatement("$1N.registerAutoReclaim();", dynfieldinfo.name);
+          code.addStatement("$1N.registerAutoReclaim()", dynfieldinfo.name);
           code.nextControlFlow("else");
-          code.addStatement("$1N.cancelAutoReclaim();", dynfieldinfo.name);
+          code.addStatement("$1N.cancelAutoReclaim()", dynfieldinfo.name);
           code.endControlFlow();
           code.endControlFlow();
         } else if (valtname.toString().startsWith(DurableBuffer.class.getCanonicalName())) {
@@ -642,9 +653,9 @@ public class AnnotatedDurableEntityClass {
               unsafename, holdername, dynfieldinfo.fieldoff, dynfieldinfo.name);
           code.beginControlFlow("if (null != $1L)", dynfieldinfo.name);
           code.beginControlFlow("if ($1N)", autoreclaimname);
-          code.addStatement("$1N.registerAutoReclaim();", dynfieldinfo.name);
+          code.addStatement("$1N.registerAutoReclaim()", dynfieldinfo.name);
           code.nextControlFlow("else");
-          code.addStatement("$1N.cancelAutoReclaim();", dynfieldinfo.name);
+          code.addStatement("$1N.cancelAutoReclaim()", dynfieldinfo.name);
           code.endControlFlow();
           code.endControlFlow();
         } else if (valtname.toString().equals(String.class.getCanonicalName())) {
@@ -678,9 +689,9 @@ public class AnnotatedDurableEntityClass {
           code.nextControlFlow("else");
           code.addStatement("throw new RetrieveDurableEntityError(\"No Generic Field Type Info.\")");
           code.endControlFlow();
-          code.addStatement("$1N = new $2T(proxy, gftype, $8L, $9L, $3N, $4N, $5N, $6N.get() + $7L)", dynfieldinfo.name,
-              dynfieldinfo.type, allocname, unsafename, autoreclaimname, holdername, dynfieldinfo.fieldoff,
-              dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
+          code.addStatement("$1N = new $2T(proxy, gftype, $9L, $10L, $3N, $4N, $5N, $6N, $7N.get() + $8L)",
+                  dynfieldinfo.name, dynfieldinfo.type, allocname, unsafename, autoreclaimname, reclaimctxname,
+                  holdername, dynfieldinfo.fieldoff, dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
           code.endControlFlow();
           code.beginControlFlow("if (null != $1L)", dynfieldinfo.name);
           code.addStatement("$1N.set($2L, $3L)", dynfieldinfo.name, arg0, arg1);
@@ -719,6 +730,7 @@ public class AnnotatedDurableEntityClass {
     String holdername = m_fieldsinfo.get("holder").name;
     String allocname = m_fieldsinfo.get("allocator").name;
     String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
+    String reclaimctxname = m_fieldsinfo.get("reclaimcontext").name;
     for (String name : m_durablemtdinfo.keySet()) {
       for (MethodInfo methodinfo : m_durablemtdinfo.get(name)) {
         code = CodeBlock.builder();
@@ -748,8 +760,9 @@ public class AnnotatedDurableEntityClass {
                 }
               }
               code.addStatement("$1N = true", autoreclaimname);
+              code.addStatement("$1N = $2L", reclaimctxname, arg0);
             } else {
-              code.addStatement("this.registerAutoReclaim(null)");
+              code.addStatement("this.registerAutoReclaim($1N)", reclaimctxname);
             }
             break;
           case "getHandler":
@@ -793,13 +806,14 @@ public class AnnotatedDurableEntityClass {
   protected void buildEntityMethodSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
     MethodInfo methodinfo;
     CodeBlock.Builder code;
-    VariableElement arg0, arg1, arg2, arg3, arg4;
+    VariableElement arg0, arg1, arg2, arg3, arg4, arg5;
     String unsafename = m_fieldsinfo.get("unsafe").name;
     String holdername = m_fieldsinfo.get("holder").name;
     String allocname = m_fieldsinfo.get("allocator").name;
     String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
     String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
     String genericfieldname = m_fieldsinfo.get("genericfield").name;
+    String reclaimctxname = m_fieldsinfo.get("reclaimcontext").name;
     for (String name : m_entitymtdinfo.keySet()) {
       methodinfo = m_entitymtdinfo.get(name);
       code = CodeBlock.builder();
@@ -809,10 +823,12 @@ public class AnnotatedDurableEntityClass {
       switch (name) {
       case "initializeDurableEntity":
         arg3 = methodinfo.elem.getParameters().get(3);
+        arg4 = methodinfo.elem.getParameters().get(4);
         code.addStatement("$1N = $2L", allocname, arg0);
         code.addStatement("$1N = $2L", factoryproxyname, arg1);
         code.addStatement("$1N = $2L", genericfieldname, arg2);
         code.addStatement("$1N = $2L", autoreclaimname, arg3);
+        code.addStatement("$1N = $2L", reclaimctxname, arg4);
         code.beginControlFlow("try");
         code.addStatement("$1N = $2T.getUnsafe()", unsafename, Utils.class);
         code.nextControlFlow("catch (Exception e)");
@@ -821,8 +837,10 @@ public class AnnotatedDurableEntityClass {
         break;
       case "createDurableEntity":
         arg3 = methodinfo.elem.getParameters().get(3);
-        code.addStatement("initializeDurableEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2, arg3);
-        code.addStatement("$1N = $2N.createChunk($3L, $4N)", holdername, allocname, m_holdersize, autoreclaimname);
+        arg4 = methodinfo.elem.getParameters().get(4);
+        code.addStatement("initializeDurableEntity($1L, $2L, $3L, $4L, $5L)", arg0, arg1, arg2, arg3, arg4);
+        code.addStatement("$1N = $2N.createChunk($3L, $4N, $5N)",
+                holdername, allocname, m_holdersize, autoreclaimname, reclaimctxname);
         code.beginControlFlow("if (null == $1N)", holdername);
         code.addStatement("throw new OutOfHybridMemory(\"Create Durable Entity Error!\")");
         code.endControlFlow();
@@ -843,16 +861,18 @@ public class AnnotatedDurableEntityClass {
       case "restoreDurableEntity":
         arg3 = methodinfo.elem.getParameters().get(3);
         arg4 = methodinfo.elem.getParameters().get(4);
+        arg5 = methodinfo.elem.getParameters().get(5);
 //        code.beginControlFlow("if ($1L instanceof RestorableAllocator)", arg0);
 //        code.addStatement(
 //               "throw new RestoreDurableEntityError(\"Allocator does not support restore operation in $1N.\")",
 //               name);
 //        code.endControlFlow();
-        code.addStatement("initializeDurableEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2, arg4);
+        code.addStatement("initializeDurableEntity($1L, $2L, $3L, $4L, $5L)", arg0, arg1, arg2, arg4, arg5);
         code.beginControlFlow("if (0L == $1L)", arg3);
         code.addStatement("throw new RestoreDurableEntityError(\"Input handler is null on $1N.\")", name);
         code.endControlFlow();
-        code.addStatement("$1N = $2N.retrieveChunk($3L, $4N)", holdername, allocname, arg3, autoreclaimname);
+        code.addStatement("$1N = $2N.retrieveChunk($3L, $4N, $5N)",
+                holdername, allocname, arg3, autoreclaimname, reclaimctxname);
         code.beginControlFlow("if (null == $1N)", holdername);
         code.addStatement("throw new RestoreDurableEntityError(\"Retrieve Entity Failure!\")");
         code.endControlFlow();
@@ -888,7 +908,7 @@ public class AnnotatedDurableEntityClass {
         .addStatement("entity.setupGenericInfo($1N.getEntityFactoryProxies(), $1N.getGenericTypes())",
                 parameterhold.name)
         .addStatement("entity.createDurableEntity($1L.getAllocator(), $1L.getEntityFactoryProxies(), "
-                    + "$1L.getGenericTypes(), $1L.getAutoReclaim())", parameterhold.name)
+                    + "$1L.getGenericTypes(), $1L.getAutoReclaim(), null)", parameterhold.name)
         .addStatement("return entity").build();
     methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
         .addException(OutOfHybridMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
@@ -904,24 +924,45 @@ public class AnnotatedDurableEntityClass {
 
     ParameterSpec autoreclaimparam = ParameterSpec.builder(TypeName.BOOLEAN, "autoreclaim").build();
     code = CodeBlock.builder()
-        .addStatement("return create($1L, null, null, $2L)", allocparam.name, autoreclaimparam.name).build();
+        .addStatement("return create($1L, null, null, $2L, null)", allocparam.name, autoreclaimparam.name).build();
     methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
         .addException(OutOfHybridMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
         .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(autoreclaimparam).addCode(code)
         .build();
     typespecbuilder.addMethod(methodspec);
 
+    ParameterSpec reclaimctxparam = ParameterSpec.builder(m_reclaimctxtypename, "reclaimcontext").build();
+    code = CodeBlock.builder()
+            .addStatement("return create($1L, null, null, $2L, $3L)",
+                    allocparam.name, autoreclaimparam.name, reclaimctxparam.name).build();
+    methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
+            .addException(OutOfHybridMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+            .returns(TypeName.get(m_elem.asType())).addParameter(allocparam)
+            .addParameter(autoreclaimparam).addParameter(reclaimctxparam).addCode(code)
+            .build();
+    typespecbuilder.addMethod(methodspec);
+
     ParameterSpec factoryproxysparam = ParameterSpec.builder(m_factoryproxystypename, "factoryproxys").build();
     ParameterSpec gfieldsparam = ParameterSpec.builder(m_gfieldstypename, "gfields").build();
+    code = CodeBlock.builder()
+            .addStatement("return create($1L, $2L, $3L, $4L, null)",
+                    allocparam.name, factoryproxysparam.name, gfieldsparam.name, autoreclaimparam.name).build();
+    methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
+            .addException(OutOfHybridMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+            .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(factoryproxysparam)
+            .addParameter(gfieldsparam).addParameter(autoreclaimparam).addCode(code).build();
+    typespecbuilder.addMethod(methodspec);
+
     code = CodeBlock.builder().addStatement("$1T entity = new $1T()", entitytn)
         .addStatement("entity.setupGenericInfo($1N, $2N)", factoryproxysparam.name, gfieldsparam.name)
-        .addStatement("entity.createDurableEntity($1L, $2L, $3L, $4L)", allocparam.name, factoryproxysparam.name,
-            gfieldsparam.name, autoreclaimparam.name)
+        .addStatement("entity.createDurableEntity($1L, $2L, $3L, $4L, $5L)",
+                allocparam.name, factoryproxysparam.name, gfieldsparam.name,
+                autoreclaimparam.name, reclaimctxparam.name)
         .addStatement("return entity").build();
     methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
         .addException(OutOfHybridMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
         .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(factoryproxysparam)
-        .addParameter(gfieldsparam).addParameter(autoreclaimparam).addCode(code).build();
+        .addParameter(gfieldsparam).addParameter(autoreclaimparam).addParameter(reclaimctxparam).addCode(code).build();
     typespecbuilder.addMethod(methodspec);
 
     ParameterSpec phandlerparam = ParameterSpec.builder(TypeName.LONG, "phandler").build();
@@ -937,14 +978,14 @@ public class AnnotatedDurableEntityClass {
         .addStatement("entity.setupGenericInfo($1N.getEntityFactoryProxies(), $1N.getGenericTypes())",
                 parameterhold.name)
         .addStatement("entity.restoreDurableEntity($1L.getAllocator(), $1L.getEntityFactoryProxies(),"
-                    + "$1L.getGenericTypes(), $1L.getHandler(), $1L.getAutoReclaim())", parameterhold.name)
+                    + "$1L.getGenericTypes(), $1L.getHandler(), $1L.getAutoReclaim(), null)", parameterhold.name)
         .addStatement("return entity").build();
     methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
             .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
             .returns(TypeName.get(m_elem.asType())).addParameter(parameterhold).addCode(code).build();
     typespecbuilder.addMethod(methodspec);
 
-    code = CodeBlock.builder().addStatement("return restore($1L, null, null, $2L, $3L)", allocparam.name,
+    code = CodeBlock.builder().addStatement("return restore($1L, null, null, $2L, $3L, null)", allocparam.name,
         phandlerparam.name, autoreclaimparam.name).build();
     methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
         .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
@@ -952,15 +993,34 @@ public class AnnotatedDurableEntityClass {
         .addParameter(autoreclaimparam).addCode(code).build();
     typespecbuilder.addMethod(methodspec);
 
+    code = CodeBlock.builder().addStatement("return restore($1L, null, null, $2L, $3L, $4L)", allocparam.name,
+            phandlerparam.name, autoreclaimparam.name, reclaimctxparam.name).build();
+    methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
+            .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+            .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(phandlerparam)
+            .addParameter(autoreclaimparam).addParameter(reclaimctxparam).addCode(code).build();
+    typespecbuilder.addMethod(methodspec);
+
+    code = CodeBlock.builder().addStatement("return restore($1L, $2L, $3L, $4L, $5L, null)", allocparam.name,
+                    factoryproxysparam.name, gfieldsparam.name, phandlerparam.name, autoreclaimparam.name).build();
+    methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
+            .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+            .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(factoryproxysparam)
+            .addParameter(gfieldsparam).addParameter(phandlerparam)
+            .addParameter(autoreclaimparam).addCode(code).build();
+    typespecbuilder.addMethod(methodspec);
+
     code = CodeBlock.builder().addStatement("$1T entity = new $1T()", entitytn)
         .addStatement("entity.setupGenericInfo($1N, $2N)", factoryproxysparam.name, gfieldsparam.name)
-        .addStatement("entity.restoreDurableEntity($1L, $2L, $3L, $4L, $5L)", allocparam.name,
-            factoryproxysparam.name, gfieldsparam.name, phandlerparam.name, autoreclaimparam.name)
+        .addStatement("entity.restoreDurableEntity($1L, $2L, $3L, $4L, $5L, $6L)", allocparam.name,
+                factoryproxysparam.name, gfieldsparam.name, phandlerparam.name,
+                autoreclaimparam.name, reclaimctxparam.name)
         .addStatement("return entity").build();
     methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
         .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
         .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(factoryproxysparam)
-        .addParameter(gfieldsparam).addParameter(phandlerparam).addParameter(autoreclaimparam).addCode(code).build();
+        .addParameter(gfieldsparam).addParameter(phandlerparam)
+        .addParameter(autoreclaimparam).addParameter(reclaimctxparam).addCode(code).build();
     typespecbuilder.addMethod(methodspec);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
index 1e0cdf5..ec0ca46 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/CommonAllocator.java
@@ -152,7 +152,7 @@ public abstract class CommonAllocator<A extends CommonAllocator<A>> implements A
    *          specify a reclaim context
    */
   @Override
-  public void registerChunkAutoReclaim(MemChunkHolder<A> mholder, ReclaimContext<Long> rctx) {
+  public void registerChunkAutoReclaim(MemChunkHolder<A> mholder, ReclaimContext rctx) {
     m_chunkcollector.register(mholder, rctx);
   }
 
@@ -177,7 +177,7 @@ public abstract class CommonAllocator<A extends CommonAllocator<A>> implements A
    *          specify a reclaim context
    */
   @Override
-  public void registerBufferAutoReclaim(MemBufferHolder<A> mholder, ReclaimContext<ByteBuffer> rctx) {
+  public void registerBufferAutoReclaim(MemBufferHolder<A> mholder, ReclaimContext rctx) {
     m_bufcollector.register(mholder, rctx);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java b/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
index b66da34..6ca1921 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
@@ -38,6 +38,7 @@ public class GenericField<A extends RestorableAllocator<A>, E> implements Durabl
   private A m_allocator;
   private Persistence<A> m_persistOps = null;
   private boolean m_autoreclaim;
+  private ReclaimContext m_reclaimcontext = null;
   private EntityFactoryProxy m_defproxy = null;
   private EntityFactoryProxy[] m_efproxies;
   private DurableType[] m_gftypes;
@@ -72,11 +73,12 @@ public class GenericField<A extends RestorableAllocator<A>, E> implements Durabl
    */
   public GenericField(EntityFactoryProxy defproxy, DurableType dgftype,
       EntityFactoryProxy[] efproxies, DurableType[] gftypes,
-      A allocator, Unsafe unsafe, boolean autoreclaim, Long fpos) {
+      A allocator, Unsafe unsafe, boolean autoreclaim, ReclaimContext rctx, Long fpos) {
     m_unsafe = unsafe;
     m_fpos = fpos;
     m_allocator = allocator;
     m_autoreclaim = autoreclaim;
+    m_reclaimcontext = rctx;
     m_efproxies = efproxies;
     m_gftypes = gftypes;
     m_defproxy = defproxy;
@@ -133,7 +135,8 @@ public class GenericField<A extends RestorableAllocator<A>, E> implements Durabl
       if (null == str) {
         m_unsafe.putAddress(m_fpos, 0L);
       } else {
-        m_strfield = m_allocator.createBuffer(str.length() * 2, m_autoreclaim);
+        m_strfield = m_allocator.createBuffer(str.length() * 2,
+                m_autoreclaim, m_reclaimcontext);
         if (null == m_strfield) {
           throw new OutOfHybridMemory("Create Durable String Error!");
         }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/MemBufferHolder.java b/mnemonic-core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
index 79e7f25..f4e821e 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
@@ -78,7 +78,7 @@ public class MemBufferHolder<A extends CommonAllocator<A>> extends MemHolder<A,
    *          specify a reclaim context to register
    */
   @Override
-  public void registerAutoReclaim(ReclaimContext<ByteBuffer> rctx) {
+  public void registerAutoReclaim(ReclaimContext rctx) {
     m_allocator.registerBufferAutoReclaim(this, rctx);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/MemChunkHolder.java b/mnemonic-core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
index 71d06d1..e0fb132 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
@@ -81,7 +81,7 @@ public class MemChunkHolder<A extends CommonAllocator<A>> extends MemHolder<A, L
    *          specify a reclaim context to register
    */
   @Override
-  public void registerAutoReclaim(ReclaimContext<Long> rctx) {
+  public void registerAutoReclaim(ReclaimContext rctx) {
     m_allocator.registerChunkAutoReclaim(this, rctx);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/MemHolder.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/MemHolder.java b/mnemonic-core/src/main/java/org/apache/mnemonic/MemHolder.java
index d6fdcff..e8e313a 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/MemHolder.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/MemHolder.java
@@ -81,5 +81,5 @@ public abstract class MemHolder<A extends CommonAllocator<A>, T, H extends MemHo
    * @param rctx
    *          specify a reclaim context to register
    */
-  public abstract void registerAutoReclaim(ReclaimContext<T> rctx);
+  public abstract void registerAutoReclaim(ReclaimContext rctx);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java b/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
index 97e5fe9..bf41010 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
@@ -17,6 +17,8 @@
 
 package org.apache.mnemonic;
 
+import org.flowcomputing.commons.resgc.ReclaimContext;
+
 /**
  *
  *
@@ -25,12 +27,13 @@ package org.apache.mnemonic;
 public interface MemoryDurableEntity<ALLOC_PMem3C93D24F59 extends RestorableAllocator<ALLOC_PMem3C93D24F59>> {
 
   void initializeDurableEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
-      DurableType[] gfields, boolean autoreclaim);
+                               DurableType[] gfields, boolean autoreclaim, ReclaimContext rctx);
 
   void createDurableEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
-      DurableType[] gfields, boolean autoreclaim) throws OutOfHybridMemory;
+      DurableType[] gfields, boolean autoreclaim, ReclaimContext rctx) throws OutOfHybridMemory;
 
   void restoreDurableEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
-      DurableType[] gfields, long phandler, boolean autoreclaim) throws RestoreDurableEntityError;
+      DurableType[] gfields, long phandler, boolean autoreclaim, ReclaimContext rctx)
+          throws RestoreDurableEntityError;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
index 4058139..be545f7 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
@@ -23,6 +23,7 @@ import org.apache.mnemonic.query.memory.ResultSet;
 import org.apache.mnemonic.service.computing.ValueInfo;
 import org.apache.mnemonic.service.memory.MemoryServiceFeature;
 import org.apache.mnemonic.service.memory.NonVolatileMemoryAllocatorService;
+import org.flowcomputing.commons.resgc.ContextWrapper;
 import org.flowcomputing.commons.resgc.ResCollector;
 import org.flowcomputing.commons.resgc.ResReclaim;
 import org.flowcomputing.commons.resgc.ReclaimContext;
@@ -94,7 +95,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
      */
     m_chunkcollector = new ResCollector<MemChunkHolder<NonVolatileMemAllocator>, Long>(new ResReclaim<Long>() {
       @Override
-      public void reclaim(ReclaimContext<Long> rctx) {
+      public void reclaim(ContextWrapper<Long> rctx) {
         Long mres = rctx.getRes();
         // System.out.println(String.format("Reclaim: %X", mres));
         boolean cb_reclaimed = false;
@@ -115,7 +116,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
     m_bufcollector = new ResCollector<MemBufferHolder<NonVolatileMemAllocator>, ByteBuffer>(
         new ResReclaim<ByteBuffer>() {
           @Override
-          public void reclaim(ReclaimContext<ByteBuffer> rctx) {
+          public void reclaim(ContextWrapper<ByteBuffer> rctx) {
             ByteBuffer mres = rctx.getRes();
             boolean cb_reclaimed = false;
             if (null != m_bufferreclaimer) {
@@ -261,7 +262,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
    */
   @Override
   public DurableChunk<NonVolatileMemAllocator> createChunk(long size, boolean autoreclaim,
-                                                           ReclaimContext<Long> rctx) {
+                                                           ReclaimContext rctx) {
     DurableChunk<NonVolatileMemAllocator> ret = null;
     Long addr = m_nvmasvc.allocate(m_nid, size, true);
     if ((null == addr || 0 == addr) && m_activegc) {
@@ -294,7 +295,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
    */
   @Override
   public DurableBuffer<NonVolatileMemAllocator> createBuffer(long size, boolean autoreclaim,
-                                                             ReclaimContext<ByteBuffer> rctx) {
+                                                             ReclaimContext rctx) {
     DurableBuffer<NonVolatileMemAllocator> ret = null;
     ByteBuffer bb = m_nvmasvc.createByteBuffer(m_nid, size);
     if (null == bb && m_activegc) {
@@ -328,7 +329,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
    */
   @Override
   public DurableBuffer<NonVolatileMemAllocator> retrieveBuffer(long phandler, boolean autoreclaim,
-                                                               ReclaimContext<ByteBuffer> rctx) {
+                                                               ReclaimContext rctx) {
     DurableBuffer<NonVolatileMemAllocator> ret = null;
     ByteBuffer bb = m_nvmasvc.retrieveByteBuffer(m_nid, getEffectiveAddress(phandler));
     if (null != bb) {
@@ -358,7 +359,7 @@ public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemA
    */
   @Override
   public DurableChunk<NonVolatileMemAllocator> retrieveChunk(long phandler, boolean autoreclaim,
-                                                             ReclaimContext<Long> rctx) {
+                                                             ReclaimContext rctx) {
     DurableChunk<NonVolatileMemAllocator> ret = null;
     long eaddr = getEffectiveAddress(phandler);
     long sz = m_nvmasvc.retrieveSize(m_nid, eaddr);

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
index fd30dc4..667fcda 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
@@ -19,8 +19,6 @@ package org.apache.mnemonic;
 
 import org.flowcomputing.commons.resgc.ReclaimContext;
 
-import java.nio.ByteBuffer;
-
 public abstract class RetrievableAllocator<A extends RetrievableAllocator<A>> extends CommonAllocator<A>
   implements AddressTranslator, HandlerStore, Transaction {
 
@@ -66,7 +64,7 @@ public abstract class RetrievableAllocator<A extends RetrievableAllocator<A>> ex
    * @return a durable chunk contains a memory chunk
    */
   @Override
-  public abstract DurableChunk<A> createChunk(long size, boolean autoreclaim, ReclaimContext<Long> rctx);
+  public abstract DurableChunk<A> createChunk(long size, boolean autoreclaim, ReclaimContext rctx);
 
   /**
    * create a durable buffer that is managed by its holder.
@@ -110,7 +108,7 @@ public abstract class RetrievableAllocator<A extends RetrievableAllocator<A>> ex
    * @return a durable buffer contains a memory buffer
    */
   @Override
-  public abstract DurableBuffer<A> createBuffer(long size, boolean autoreclaim, ReclaimContext<ByteBuffer> rctx);
+  public abstract DurableBuffer<A> createBuffer(long size, boolean autoreclaim, ReclaimContext rctx);
 
   /**
    * retrieve a memory buffer from its backed memory allocator.
@@ -183,7 +181,7 @@ public abstract class RetrievableAllocator<A extends RetrievableAllocator<A>> ex
    *
    * @return a durable buffer contains the retrieved memory buffer
    */
-  public abstract DurableBuffer<A> retrieveBuffer(long phandler, boolean autoreclaim, ReclaimContext<ByteBuffer> rctx);
+  public abstract DurableBuffer<A> retrieveBuffer(long phandler, boolean autoreclaim, ReclaimContext rctx);
 
   /**
    * retrieve a memory chunk from its backed memory allocator.
@@ -200,7 +198,7 @@ public abstract class RetrievableAllocator<A extends RetrievableAllocator<A>> ex
    *
    * @return a durable chunk contains the retrieved memory chunk
    */
-  public abstract DurableChunk<A> retrieveChunk(long phandler, boolean autoreclaim, ReclaimContext<Long> rctx);
+  public abstract DurableChunk<A> retrieveChunk(long phandler, boolean autoreclaim, ReclaimContext rctx);
 
   /**
    * re-size a specified chunk on its backed memory pool.

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/4b3d13b9/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
index 37f06a2..286189d 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
@@ -17,6 +17,7 @@
 
 package org.apache.mnemonic;
 
+import org.flowcomputing.commons.resgc.ContextWrapper;
 import org.flowcomputing.commons.resgc.ResCollector;
 import org.flowcomputing.commons.resgc.ResReclaim;
 import org.flowcomputing.commons.resgc.ReclaimContext;
@@ -70,7 +71,7 @@ public class SysMemAllocator extends CommonAllocator<SysMemAllocator> {
      */
     m_bufcollector = new ResCollector<MemBufferHolder<SysMemAllocator>, ByteBuffer>(new ResReclaim<ByteBuffer>() {
       @Override
-      public synchronized void reclaim(ReclaimContext<ByteBuffer> rctx) {
+      public synchronized void reclaim(ContextWrapper<ByteBuffer> rctx) {
         ByteBuffer mres = rctx.getRes();
         Long sz = Long.valueOf(mres.capacity());
         boolean cb_reclaimed = false;
@@ -99,7 +100,7 @@ public class SysMemAllocator extends CommonAllocator<SysMemAllocator> {
      */
     m_chunkcollector = new ResCollector<MemChunkHolder<SysMemAllocator>, Long>(new ResReclaim<Long>() {
       @Override
-      public synchronized void reclaim(ReclaimContext<Long> rctx) {
+      public synchronized void reclaim(ContextWrapper<Long> rctx) {
         Long mres = rctx.getRes();
         // System.out.println(String.format("Reclaim: %X ...", mres));
         Long sz = m_chunksize.remove(mres);
@@ -290,7 +291,7 @@ public class SysMemAllocator extends CommonAllocator<SysMemAllocator> {
    */
   @Override
   public MemChunkHolder<SysMemAllocator> createChunk(long size, boolean autoreclaim,
-                                                     ReclaimContext<Long> rctx) {
+                                                     ReclaimContext rctx) {
     MemChunkHolder<SysMemAllocator> ret = null;
     Long addr = null;
     if (currentMemory.get() + size > maxStoreCapacity) {
@@ -326,7 +327,7 @@ public class SysMemAllocator extends CommonAllocator<SysMemAllocator> {
    */
   @Override
   public MemBufferHolder<SysMemAllocator> createBuffer(long size, boolean autoreclaim,
-                                                       ReclaimContext<ByteBuffer> rctx) {
+                                                       ReclaimContext rctx) {
     MemBufferHolder<SysMemAllocator> ret = null;
     ByteBuffer bb = null;
     if (currentMemory.get() + size > maxStoreCapacity) {



Mime
View raw message