You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2015/11/20 02:07:50 UTC

[15/20] incubator-geode git commit: move RefCountChangeInfo from SimpleMemoryAllocatorImpl

move RefCountChangeInfo from SimpleMemoryAllocatorImpl


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

Branch: refs/heads/feature/GEODE-580
Commit: 8c5d5a77929c799ad10905e2da4b7c553c005a2a
Parents: 082b09a
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:16:08 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:16:08 2015 -0800

----------------------------------------------------------------------
 .../internal/offheap/RefCountChangeInfo.java    | 112 +++++++++++++++++++
 .../offheap/SimpleMemoryAllocatorImpl.java      |  97 ++--------------
 .../gemfire/internal/cache/OffHeapTestUtil.java |   2 +-
 3 files changed, 120 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8c5d5a77/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
new file mode 100644
index 0000000..47cc139
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.offheap;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import com.gemstone.gemfire.internal.shared.StringPrintWriter;
+
+@SuppressWarnings("serial")
+/**
+ * Used by SimpleMemoryAllocatorImpl to debug off-heap memory leaks.
+ */
+public class RefCountChangeInfo extends Throwable {
+  private final String threadName;
+  private final int rc;
+  private final Object owner;
+  private int dupCount;
+  
+  public RefCountChangeInfo(boolean decRefCount, int rc) {
+    super(decRefCount ? "FREE" : "USED");
+    this.threadName = Thread.currentThread().getName();
+    this.rc = rc;
+    this.owner = SimpleMemoryAllocatorImpl.refCountOwner.get();
+  }
+  
+  public Object getOwner() {
+    return this.owner;
+  }
+  
+  public int getDupCount() {
+    return this.dupCount;
+  }
+  public void decDupCount() {
+    this.dupCount--;
+  }
+
+  @Override
+  public String toString() {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream(64*1024);
+    PrintStream ps = new PrintStream(baos);
+    ps.print(this.getMessage());
+    ps.print(" rc=");
+    ps.print(this.rc);
+    if (this.dupCount > 0) {
+      ps.print(" dupCount=");
+      ps.print(this.dupCount);
+    }
+    ps.print(" by ");
+    ps.print(this.threadName);
+    if (this.owner != null) {
+      ps.print(" owner=");
+      ps.print(this.owner.getClass().getName());
+      ps.print("@");
+      ps.print(System.identityHashCode(this.owner));
+    }
+    ps.println(": ");
+    StackTraceElement[] trace = getStackTrace();
+    // skip the initial elements from SimpleMemoryAllocatorImpl
+    int skip=0;
+    for (int i=0; i < trace.length; i++) {
+      if (!trace[i].getClassName().contains("SimpleMemoryAllocatorImpl")) {
+        skip = i;
+        break;
+      }
+    }
+    for (int i=skip; i < trace.length; i++) {
+      ps.println("\tat " + trace[i]);
+    }
+    ps.flush();
+    return baos.toString();
+  }
+  
+  public boolean isDuplicate(RefCountChangeInfo other) {
+    if (!getMessage().equals(other.getMessage())) return false;
+    String trace = getStackTraceString();
+    String traceOther = other.getStackTraceString();
+    if (trace.hashCode() != traceOther.hashCode()) return false;
+    if (trace.equals(traceOther)) {
+      this.dupCount++;
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  private String stackTraceString;
+  private String getStackTraceString() {
+    String result = this.stackTraceString;
+    if (result == null) {
+      StringPrintWriter spr = new StringPrintWriter();
+      printStackTrace(spr);
+      result = spr.getBuilder().toString();
+      this.stackTraceString = result;
+    }
+    return result;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8c5d5a77/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 a50c823..e761a10 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
@@ -16,9 +16,7 @@
  */
 package com.gemstone.gemfire.internal.offheap;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -61,7 +59,6 @@ import com.gemstone.gemfire.internal.cache.RegionEntry;
 import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
 import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
-import com.gemstone.gemfire.internal.shared.StringPrintWriter;
 
 /**
  * This allocator is somewhat like an Arena allocator.
@@ -1748,7 +1745,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
   private final static boolean trackFreedRefCounts = Boolean.getBoolean("gemfire.trackOffHeapFreedRefCounts");
   private final static ConcurrentMap<Long, List<RefCountChangeInfo>> stacktraces;
   private final static ConcurrentMap<Long, List<RefCountChangeInfo>> freedStacktraces;
-  private final static ThreadLocal<Object> refCountOwner;
+  final static ThreadLocal<Object> refCountOwner;
   private final static ThreadLocal<AtomicInteger> refCountReenterCount;
   static {
     if (trackRefCounts) {
@@ -1810,86 +1807,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
     return result;
   }
   
-  @SuppressWarnings("serial")
-  public static class RefCountChangeInfo extends Throwable {
-    private final String threadName;
-    private final int rc;
-    private final Object owner;
-    private int dupCount;
-    
-    public RefCountChangeInfo(boolean decRefCount, int rc) {
-      super(decRefCount ? "FREE" : "USED");
-      this.threadName = Thread.currentThread().getName();
-      this.rc = rc;
-      this.owner = refCountOwner.get();
-    }
-    
-    public Object getOwner() {
-      return this.owner;
-    }
-
-    @Override
-    public String toString() {
-      ByteArrayOutputStream baos = new ByteArrayOutputStream(64*1024);
-      PrintStream ps = new PrintStream(baos);
-      ps.print(this.getMessage());
-      ps.print(" rc=");
-      ps.print(this.rc);
-      if (this.dupCount > 0) {
-        ps.print(" dupCount=");
-        ps.print(this.dupCount);
-      }
-      ps.print(" by ");
-      ps.print(this.threadName);
-      if (this.owner != null) {
-        ps.print(" owner=");
-        ps.print(this.owner.getClass().getName());
-        ps.print("@");
-        ps.print(System.identityHashCode(this.owner));
-      }
-      ps.println(": ");
-      StackTraceElement[] trace = getStackTrace();
-      // skip the initial elements from SimpleMemoryAllocatorImpl
-      int skip=0;
-      for (int i=0; i < trace.length; i++) {
-        if (!trace[i].getClassName().contains("SimpleMemoryAllocatorImpl")) {
-          skip = i;
-          break;
-        }
-      }
-      for (int i=skip; i < trace.length; i++) {
-        ps.println("\tat " + trace[i]);
-      }
-      ps.flush();
-      return baos.toString();
-    }
-    
-    public boolean isDuplicate(RefCountChangeInfo other) {
-      if (!getMessage().equals(other.getMessage())) return false;
-      String trace = getStackTraceString();
-      String traceOther = other.getStackTraceString();
-      if (trace.hashCode() != traceOther.hashCode()) return false;
-      if (trace.equals(traceOther)) {
-        this.dupCount++;
-        return true;
-      } else {
-        return false;
-      }
-    }
-
-    private String stackTraceString;
-    private String getStackTraceString() {
-      String result = this.stackTraceString;
-      if (result == null) {
-        StringPrintWriter spr = new StringPrintWriter();
-        printStackTrace(spr);
-        result = spr.getBuilder().toString();
-        this.stackTraceString = result;
-      }
-      return result;
-    }
-  }
-  
   private static final Object SKIP_REF_COUNT_TRACKING = new Object();
   
   public static void skipRefCountTracking() {
@@ -1921,17 +1838,17 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
             RefCountChangeInfo info = list.get(i);
             if (owner instanceof RegionEntry) {
               // use identity comparison on region entries since sqlf does some wierd stuff in the equals method
-              if (owner == info.owner) {
-                if (info.dupCount > 0) {
-                  info.dupCount--;
+              if (owner == info.getOwner()) {
+                if (info.getDupCount() > 0) {
+                  info.decDupCount();
                 } else {
                   list.remove(i);
                 }
                 return;
               }
-            } else if (owner.equals(info.owner)) {
-              if (info.dupCount > 0) {
-                info.dupCount--;
+            } else if (owner.equals(info.getOwner())) {
+              if (info.getDupCount() > 0) {
+                info.decDupCount();
               } else {
                 list.remove(i);
               }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8c5d5a77/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapTestUtil.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapTestUtil.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapTestUtil.java
index 2fc3c82..b14d815 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapTestUtil.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OffHeapTestUtil.java
@@ -23,8 +23,8 @@ import junit.framework.Assert;
 
 import com.gemstone.gemfire.cache.CacheClosedException;
 import com.gemstone.gemfire.internal.offheap.MemoryBlock;
+import com.gemstone.gemfire.internal.offheap.RefCountChangeInfo;
 import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.RefCountChangeInfo;
 
 @SuppressWarnings("deprecation")
 public class OffHeapTestUtil {