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:52 UTC

[17/20] incubator-geode git commit: move MemoryBlockNode from SimpleMemoryAllocatorImpl

move MemoryBlockNode 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/d63f65d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/d63f65d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/d63f65d8

Branch: refs/heads/feature/GEODE-580
Commit: d63f65d8839bccdabb1a210c4f82bbefe543d2a0
Parents: cd4ebb7
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:46:24 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:46:24 2015 -0800

----------------------------------------------------------------------
 .../internal/offheap/MemoryBlockNode.java       | 158 +++++++++++++++++++
 .../offheap/SimpleMemoryAllocatorImpl.java      | 141 +----------------
 2 files changed, 163 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d63f65d8/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNode.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNode.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNode.java
new file mode 100644
index 0000000..3f5f4dc
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNode.java
@@ -0,0 +1,158 @@
+/*
+ * 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.IOException;
+import java.util.Arrays;
+
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.cache.CacheClosedException;
+import com.gemstone.gemfire.internal.offheap.MemoryBlock.State;
+
+/**
+ * Basic implementation of MemoryBlock for test validation only.
+ */
+public class MemoryBlockNode implements MemoryBlock {
+  private final SimpleMemoryAllocatorImpl ma;
+  private final MemoryBlock block;
+  MemoryBlockNode(SimpleMemoryAllocatorImpl ma, MemoryBlock block) {
+    this.ma = ma;
+    this.block = block;
+  }
+  @Override
+  public State getState() {
+    return this.block.getState();
+  }
+  @Override
+  public long getMemoryAddress() {
+    return this.block.getMemoryAddress();
+  }
+  @Override
+  public int getBlockSize() {
+    return this.block.getBlockSize();
+  }
+  @Override
+  public MemoryBlock getNextBlock() {
+    return this.ma.getBlockAfter(this);
+  }
+  public int getSlabId() {
+    return this.ma.findSlab(getMemoryAddress());
+  }
+  @Override
+  public int getFreeListId() {
+    return this.block.getFreeListId();
+  }
+  public int getRefCount() {
+    return this.block.getRefCount(); // delegate to fix GEODE-489
+  }
+  public String getDataType() {
+    if (this.block.getDataType() != null) {
+      return this.block.getDataType();
+    }
+    if (!isSerialized()) {
+      // byte array
+      if (isCompressed()) {
+        return "compressed byte[" + ((Chunk)this.block).getDataSize() + "]";
+      } else {
+        return "byte[" + ((Chunk)this.block).getDataSize() + "]";
+      }
+    } else if (isCompressed()) {
+      return "compressed object of size " + ((Chunk)this.block).getDataSize();
+    }
+    //Object obj = EntryEventImpl.deserialize(((Chunk)this.block).getRawBytes());
+    byte[] bytes = ((Chunk)this.block).getRawBytes();
+    return DataType.getDataType(bytes);
+  }
+  public boolean isSerialized() {
+    return this.block.isSerialized();
+  }
+  public boolean isCompressed() {
+    return this.block.isCompressed();
+  }
+  @Override
+  public Object getDataValue() {
+    String dataType = getDataType();
+    if (dataType == null || dataType.equals("N/A")) {
+      return null;
+    } else if (isCompressed()) {
+      return ((Chunk)this.block).getCompressedBytes();
+    } else if (!isSerialized()) {
+      // byte array
+      //return "byte[" + ((Chunk)this.block).getDataSize() + "]";
+      return ((Chunk)this.block).getRawBytes();
+    } else {
+      try {
+        byte[] bytes = ((Chunk)this.block).getRawBytes();
+        return DataSerializer.readObject(DataType.getDataInput(bytes));
+      } catch (IOException e) {
+        e.printStackTrace();
+        return "IOException:" + e.getMessage();
+      } catch (ClassNotFoundException e) {
+        e.printStackTrace();
+        return "ClassNotFoundException:" + e.getMessage();
+      } catch (CacheClosedException e) {
+        e.printStackTrace();
+        return "CacheClosedException:" + e.getMessage();
+      }
+    }
+  }
+  @Override
+  public String toString() {
+    final StringBuilder sb = new StringBuilder(MemoryBlock.class.getSimpleName());
+    sb.append("{");
+    sb.append("MemoryAddress=").append(getMemoryAddress());
+    sb.append(", State=").append(getState());
+    sb.append(", BlockSize=").append(getBlockSize());
+    sb.append(", SlabId=").append(getSlabId());
+    sb.append(", FreeListId=");
+    if (getState() == State.UNUSED || getState() == State.ALLOCATED) {
+      sb.append("NONE");
+    } else if (getFreeListId() == -1) {
+      sb.append("HUGE");
+    } else {
+      sb.append(getFreeListId());
+    }
+    sb.append(", RefCount=").append(getRefCount());
+    ChunkType ct = this.getChunkType();
+    if (ct != null) {
+      sb.append(", " + ct);
+    }
+    sb.append(", isSerialized=").append(isSerialized());
+    sb.append(", isCompressed=").append(isCompressed());
+    sb.append(", DataType=").append(getDataType());
+    {
+      sb.append(", DataValue=");
+      Object dataValue = getDataValue();
+      if (dataValue instanceof byte[]) {
+        byte[] ba = (byte[]) dataValue;
+        if (ba.length < 1024) {
+          sb.append(Arrays.toString(ba));
+        } else {
+          sb.append("<byte array of length " + ba.length + ">");
+        }
+      } else {
+        sb.append(dataValue);
+      }
+    }
+    sb.append("}");
+    return sb.toString();
+  }
+  @Override
+  public ChunkType getChunkType() {
+    return this.block.getChunkType();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d63f65d8/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 b0d2b07..458ddef 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,7 +16,6 @@
  */
 package com.gemstone.gemfire.internal.offheap;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -39,7 +38,6 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
 
 import org.apache.logging.log4j.Logger;
 
-import com.gemstone.gemfire.DataSerializer;
 import com.gemstone.gemfire.LogWriter;
 import com.gemstone.gemfire.OutOfOffHeapMemoryException;
 import com.gemstone.gemfire.cache.CacheClosedException;
@@ -1430,7 +1428,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
     liveChunks.removeAll(regionChunks);
     List<MemoryBlock> orphans = new ArrayList<MemoryBlock>();
     for (Chunk chunk: liveChunks) {
-      orphans.add(new MemoryBlockNode(chunk));
+      orphans.add(new MemoryBlockNode(this, chunk));
     }
     Collections.sort(orphans, 
         new Comparator<MemoryBlock>() {
@@ -1519,19 +1517,19 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
   
   private void addBlocksFromFragments(Collection<Fragment> src, List<MemoryBlock> dest) {
     for (MemoryBlock block : src) {
-      dest.add(new MemoryBlockNode(block));
+      dest.add(new MemoryBlockNode(this, block));
     }
   }
   
   private void addBlocksFromChunks(Collection<Chunk> src, List<MemoryBlock> dest) {
     for (Chunk chunk : src) {
-      dest.add(new MemoryBlockNode(chunk));
+      dest.add(new MemoryBlockNode(this, chunk));
     }
   }
   
   private void addMemoryBlocks(Collection<MemoryBlock> src, List<MemoryBlock> dest) {
     for (MemoryBlock block : src) {
-      dest.add(new MemoryBlockNode(block));
+      dest.add(new MemoryBlockNode(this, block));
     }
   }
   
@@ -1545,7 +1543,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
       final long address = addr;
       final int freeListId = i;
       while (addr != 0L) {
-        value.add(new MemoryBlockNode(new MemoryBlock() {
+        value.add(new MemoryBlockNode(this, new MemoryBlock() {
           @Override
           public State getState() {
             return State.DEALLOCATED;
@@ -1601,135 +1599,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
     return value;
   }
   
-  public class MemoryBlockNode implements MemoryBlock {
-    private final MemoryBlock block;
-    MemoryBlockNode(MemoryBlock block) {
-      this.block = block;
-    }
-    @Override
-    public State getState() {
-      return this.block.getState();
-    }
-    @Override
-    public long getMemoryAddress() {
-      return this.block.getMemoryAddress();
-    }
-    @Override
-    public int getBlockSize() {
-      return this.block.getBlockSize();
-    }
-    @Override
-    public MemoryBlock getNextBlock() {
-      return getBlockAfter(this);
-    }
-    public int getSlabId() {
-      return findSlab(getMemoryAddress());
-    }
-    @Override
-    public int getFreeListId() {
-      return this.block.getFreeListId();
-    }
-    public int getRefCount() {
-      return this.block.getRefCount(); // delegate to fix GEODE-489
-    }
-    public String getDataType() {
-      if (this.block.getDataType() != null) {
-        return this.block.getDataType();
-      }
-      if (!isSerialized()) {
-        // byte array
-        if (isCompressed()) {
-          return "compressed byte[" + ((Chunk)this.block).getDataSize() + "]";
-        } else {
-          return "byte[" + ((Chunk)this.block).getDataSize() + "]";
-        }
-      } else if (isCompressed()) {
-        return "compressed object of size " + ((Chunk)this.block).getDataSize();
-      }
-      //Object obj = EntryEventImpl.deserialize(((Chunk)this.block).getRawBytes());
-      byte[] bytes = ((Chunk)this.block).getRawBytes();
-      return DataType.getDataType(bytes);
-    }
-    public boolean isSerialized() {
-      return this.block.isSerialized();
-    }
-    public boolean isCompressed() {
-      return this.block.isCompressed();
-    }
-    @Override
-    public Object getDataValue() {
-      String dataType = getDataType();
-      if (dataType == null || dataType.equals("N/A")) {
-        return null;
-      } else if (isCompressed()) {
-        return ((Chunk)this.block).getCompressedBytes();
-      } else if (!isSerialized()) {
-        // byte array
-        //return "byte[" + ((Chunk)this.block).getDataSize() + "]";
-        return ((Chunk)this.block).getRawBytes();
-      } else {
-        try {
-          byte[] bytes = ((Chunk)this.block).getRawBytes();
-          return DataSerializer.readObject(DataType.getDataInput(bytes));
-        } catch (IOException e) {
-          e.printStackTrace();
-          return "IOException:" + e.getMessage();
-        } catch (ClassNotFoundException e) {
-          e.printStackTrace();
-          return "ClassNotFoundException:" + e.getMessage();
-        } catch (CacheClosedException e) {
-          e.printStackTrace();
-          return "CacheClosedException:" + e.getMessage();
-        }
-      }
-    }
-    @Override
-    public String toString() {
-      final StringBuilder sb = new StringBuilder(MemoryBlock.class.getSimpleName());
-      sb.append("{");
-      sb.append("MemoryAddress=").append(getMemoryAddress());
-      sb.append(", State=").append(getState());
-      sb.append(", BlockSize=").append(getBlockSize());
-      sb.append(", SlabId=").append(getSlabId());
-      sb.append(", FreeListId=");
-      if (getState() == State.UNUSED || getState() == State.ALLOCATED) {
-        sb.append("NONE");
-      } else if (getFreeListId() == -1) {
-        sb.append("HUGE");
-      } else {
-        sb.append(getFreeListId());
-      }
-      sb.append(", RefCount=").append(getRefCount());
-      ChunkType ct = this.getChunkType();
-      if (ct != null) {
-        sb.append(", " + ct);
-      }
-      sb.append(", isSerialized=").append(isSerialized());
-      sb.append(", isCompressed=").append(isCompressed());
-      sb.append(", DataType=").append(getDataType());
-      {
-        sb.append(", DataValue=");
-        Object dataValue = getDataValue();
-        if (dataValue instanceof byte[]) {
-          byte[] ba = (byte[]) dataValue;
-          if (ba.length < 1024) {
-            sb.append(Arrays.toString(ba));
-          } else {
-            sb.append("<byte array of length " + ba.length + ">");
-          }
-        } else {
-          sb.append(dataValue);
-        }
-      }
-      sb.append("}");
-      return sb.toString();
-    }
-    @Override
-    public ChunkType getChunkType() {
-      return this.block.getChunkType();
-    }
-  }
-  
   /*
    * Set this to "true" to perform data integrity checks on allocated and reused Chunks.  This may clobber 
    * performance so turn on only when necessary.