geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [25/38] incubator-geode git commit: more cleanup to get rid of off-heap stuff in ObjectStoredInMemory.
Date Sat, 05 Mar 2016 00:51:25 GMT
more cleanup to get rid of off-heap stuff in ObjectStoredInMemory.


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

Branch: refs/heads/feature/GEODE-982
Commit: 7dd27db5671a9a100e7ce57a11945fb94f2ec8c0
Parents: b75d040
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Tue Mar 1 17:14:05 2016 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Tue Mar 1 17:14:05 2016 -0800

----------------------------------------------------------------------
 .../offheap/AddressableStoredObject.java        | 12 +++++++++
 .../internal/offheap/FreeListManager.java       |  4 +--
 .../internal/offheap/ObjectStoredInMemory.java  | 28 ++++++--------------
 .../internal/offheap/FreeListManagerTest.java   |  2 +-
 .../offheap/FreeListOffHeapRegionJUnitTest.java |  2 +-
 .../internal/offheap/ObjectChunkJUnitTest.java  | 13 +++------
 .../OldFreeListOffHeapRegionJUnitTest.java      |  2 +-
 .../offheap/SimpleMemoryAllocatorJUnitTest.java |  8 +++---
 .../management/OffHeapManagementDUnitTest.java  |  6 ++---
 9 files changed, 36 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/AddressableStoredObject.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/AddressableStoredObject.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/AddressableStoredObject.java
index 597eec4..666070c 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/AddressableStoredObject.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/AddressableStoredObject.java
@@ -16,7 +16,10 @@
  */
 package com.gemstone.gemfire.internal.offheap;
 
+import java.nio.ByteBuffer;
+
 import com.gemstone.gemfire.internal.offheap.annotations.Retained;
+import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
 
 /**
  * Represents a stored object whose stored data is also addressable.
@@ -64,6 +67,15 @@ public interface AddressableStoredObject extends StoredObject, Releasable
{
   public void writeDataBytes(int offset, byte[] bytes);
   public void readDataBytes(int offset, byte[] bytes, int bytesOffset, int size);
   public void writeDataBytes(int offset, byte[] bytes, int bytesOffset, int size);
+  /**
+   * Creates and returns a direct ByteBuffer that contains the data of this stored object.
+   * Note that the returned ByteBuffer has a reference to the
+   * address of this stored object so it can only be used while this stored object is retained.
+   * @return the created direct byte buffer or null if it could not be created.
+   */
+  @Unretained
+  public ByteBuffer createDirectByteBuffer();
+
   
   /**
    * Call to indicate that this object's memory is in use by the caller.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
index 048372b..7d927b0 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
@@ -196,7 +196,7 @@ public class FreeListManager {
       // to adjust the size so that the header gets allocated.
       // If useSlabs is false then the incoming size has already
       // been adjusted.
-      size += ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+      size += ObjectStoredInMemory.HEADER_SIZE;
     }
     if (size <= MAX_TINY) {
       return allocateTiny(size, useSlabs);
@@ -635,7 +635,7 @@ public class FreeListManager {
     NavigableSet<ObjectStoredInMemory> ts = this.hugeChunkSet.tailSet(sizeHolder);
     ObjectStoredInMemory result = ts.pollFirst();
     if (result != null) {
-      if (result.getSize() - (HUGE_MULTIPLE - ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE)
< size) {
+      if (result.getSize() - (HUGE_MULTIPLE - ObjectStoredInMemory.HEADER_SIZE) < size)
{
         // close enough to the requested size; just return it.
         checkDataIntegrity(result);
         result.readyForAllocation();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredInMemory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredInMemory.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredInMemory.java
index a26db69..aa5da80 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredInMemory.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/ObjectStoredInMemory.java
@@ -53,15 +53,15 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
     
     /**
      * The useCount, chunkSize, dataSizeDelta, isSerialized, and isCompressed
-     * are all stored in off heap memory in a HEADER. This saves heap memory
+     * are all stored in addressable memory in a HEADER. This saves heap memory
      * by using off heap.
      */
-    public final static int OFF_HEAP_HEADER_SIZE = 4 + 4;
+    public final static int HEADER_SIZE = 4 + 4;
     /**
      * We need to smallest chunk to at least have enough room for a hdr
      * and for an off heap ref (which is a long).
      */
-    public final static int MIN_CHUNK_SIZE = OFF_HEAP_HEADER_SIZE + 8;
+    public final static int MIN_CHUNK_SIZE = HEADER_SIZE + 8;
     /**
      * int field.
      * The number of bytes in this chunk.
@@ -162,7 +162,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
       final byte[] dataCache2 = new byte[dataCache1.length];
       // TODO OFFHEAP: no need to copy to heap. Just get the address of each and compare
each byte. No need to call incReads when reading from address.
       int i;
-      // inc it twice since we are reading two different off-heap objects
+      // inc it twice since we are reading two different objects
       SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
       SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
       for (i=0; i < mySize-(dataCache1.length-1); i+=dataCache1.length) {
@@ -277,18 +277,13 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
     }
     
     protected long getBaseDataAddress() {
-      return this.memoryAddress+OFF_HEAP_HEADER_SIZE;
+      return this.memoryAddress+HEADER_SIZE;
     }
     protected int getBaseDataOffset() {
       return 0;
     }
     
-    /**
-     * Creates and returns a direct ByteBuffer that contains the contents of this Chunk.
-     * Note that the returned ByteBuffer has a reference to this chunk's
-     * off-heap address so it can only be used while this Chunk is retained.
-     * @return the created direct byte buffer or null if it could not be created.
-     */
+    @Override
     @Unretained
     public ByteBuffer createDirectByteBuffer() {
       return basicCreateDirectByteBuffer(getBaseDataAddress(), getDataSize());
@@ -603,11 +598,11 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
     }
     public static long getNext(long memAddr) {
       SimpleMemoryAllocatorImpl.validateAddress(memAddr);
-      return AddressableMemoryManager.readLong(memAddr+OFF_HEAP_HEADER_SIZE);
+      return AddressableMemoryManager.readLong(memAddr+HEADER_SIZE);
     }
     public static void setNext(long memAddr, long next) {
       SimpleMemoryAllocatorImpl.validateAddress(memAddr);
-      AddressableMemoryManager.writeLong(memAddr+OFF_HEAP_HEADER_SIZE, next);
+      AddressableMemoryManager.writeLong(memAddr+HEADER_SIZE, next);
     }
     
     /**
@@ -780,13 +775,6 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
     
     @Override
     public String toString() {
-      return toStringForOffHeapByteSource();
-      // This old impl is not safe because it calls getDeserializedForReading and we have
code that call toString that does not inc the refcount.
-      // Also if this Chunk is compressed we don't know how to decompress it.
-      //return super.toString() + ":<dataSize=" + getDataSize() + " refCount=" + getRefCount()
+ " addr=" + getMemoryAddress() + " storedObject=" + getDeserializedForReading() + ">";
-    }
-    
-    protected String toStringForOffHeapByteSource() {
       return super.toString() + ":<dataSize=" + getDataSize() + " refCount=" + getRefCount()
+ " addr=" + Long.toHexString(getMemoryAddress()) + ">";
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
index b7151e8..35befc4 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListManagerTest.java
@@ -251,7 +251,7 @@ public class FreeListManagerTest {
   }
   
   private int computeExpectedSize(int dataSize) {
-    return ((dataSize + ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE + 7) / 8) * 8;
+    return ((dataSize + ObjectStoredInMemory.HEADER_SIZE + 7) / 8) * 8;
   }
 
   @Test(expected = AssertionError.class)

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
index 5f80939..eb4096b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
@@ -40,7 +40,7 @@ public class FreeListOffHeapRegionJUnitTest extends OffHeapRegionBase {
 
   @Override
   public int perObjectOverhead() {
-    return ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+    return ObjectStoredInMemory.HEADER_SIZE;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
index e7cd408..6603867 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
@@ -201,7 +201,7 @@ public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase
{
   @Test
   public void getShortClassNameShouldReturnShortClassName() {
     ObjectStoredInMemory chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getShortClassName()).isEqualTo("ObjectChunk");
+    assertThat(chunk.getShortClassName()).isEqualTo("ObjectStoredInMemory");
 
     chunk.release();
   }
@@ -610,7 +610,7 @@ public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase
{
     long bufferAddress = ObjectStoredInMemory.getDirectByteBufferAddress(buffer);
 
     // returned address should be starting of the value (after skipping HEADER_SIZE bytes)
-    assertEquals(chunk.getMemoryAddress() + ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE, bufferAddress);
+    assertEquals(chunk.getMemoryAddress() + ObjectStoredInMemory.HEADER_SIZE, bufferAddress);
 
     chunk.release();
   }
@@ -769,16 +769,11 @@ public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase
{
   }
 
   @Test
-  public void testToStringForOffHeapByteSource() {
+  public void testToString() {
     ObjectStoredInMemory chunk = createValueAsUnserializedStoredObject(getValue());
 
     String expected = ":<dataSize=" + chunk.getDataSize() + " refCount=" + chunk.getRefCount()
+ " addr=" + Long.toHexString(chunk.getMemoryAddress()) + ">";
-    assertThat(chunk.toStringForOffHeapByteSource()).endsWith(expected);
-
-    // test toString
-    ObjectStoredInMemory spy = spy(chunk);
-    spy.toString();
-    verify(spy, times(1)).toStringForOffHeapByteSource();
+    assertThat(chunk.toString()).endsWith(expected);
 
     chunk.release();
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
index a58a421..8fecf8a 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
@@ -41,7 +41,7 @@ public class OldFreeListOffHeapRegionJUnitTest extends OffHeapRegionBase
{
 
   @Override
   public int perObjectOverhead() {
-    return ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+    return ObjectStoredInMemory.HEADER_SIZE;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
index d5a7fe8..72bee62 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
@@ -191,7 +191,7 @@ public class SimpleMemoryAllocatorJUnitTest {
     int BATCH_SIZE = 1;
     int TINY_MULTIPLE = com.gemstone.gemfire.internal.offheap.FreeListManager.TINY_MULTIPLE;
     int HUGE_MULTIPLE = com.gemstone.gemfire.internal.offheap.FreeListManager.HUGE_MULTIPLE;
-    int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+    int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.HEADER_SIZE;
     int maxTiny = com.gemstone.gemfire.internal.offheap.FreeListManager.MAX_TINY-perObjectOverhead;
     int minHuge = maxTiny+1;
     int TOTAL_MEM = (maxTiny+perObjectOverhead)*BATCH_SIZE /*+ (maxBig+perObjectOverhead)*BATCH_SIZE*/
+ round(TINY_MULTIPLE, minHuge+1+perObjectOverhead)*BATCH_SIZE + (TINY_MULTIPLE+perObjectOverhead)*BATCH_SIZE
/*+ (MIN_BIG_SIZE+perObjectOverhead)*BATCH_SIZE*/ + round(TINY_MULTIPLE, minHuge+perObjectOverhead+1);
@@ -427,7 +427,7 @@ public class SimpleMemoryAllocatorJUnitTest {
   
   @Test
   public void testCompaction() {
-    final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+    final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.HEADER_SIZE;
     final int BIG_ALLOC_SIZE = 150000;
     final int SMALL_ALLOC_SIZE = BIG_ALLOC_SIZE/2;
     final int TOTAL_MEM = BIG_ALLOC_SIZE;
@@ -543,7 +543,7 @@ public class SimpleMemoryAllocatorJUnitTest {
   boolean memoryUsageEventReceived;
   @Test
   public void testUsageEventListener() {
-    final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+    final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.HEADER_SIZE;
     final int SMALL_ALLOC_SIZE = 1000;
     SlabImpl slab = new SlabImpl(3000);
     try {
@@ -596,7 +596,7 @@ public class SimpleMemoryAllocatorJUnitTest {
   
   @Test
   public void testOutOfOffHeapMemory() {
-    final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+    final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.ObjectStoredInMemory.HEADER_SIZE;
     final int BIG_ALLOC_SIZE = 150000;
     final int SMALL_ALLOC_SIZE = BIG_ALLOC_SIZE/2;
     final int TOTAL_MEM = BIG_ALLOC_SIZE;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7dd27db5/geode-core/src/test/java/com/gemstone/gemfire/management/OffHeapManagementDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/OffHeapManagementDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/management/OffHeapManagementDUnitTest.java
index ab1fce7..fc7f124 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/OffHeapManagementDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/OffHeapManagementDUnitTest.java
@@ -240,7 +240,7 @@ public class OffHeapManagementDUnitTest extends CacheTestCase {
       
       // After allocating large chunk (equal to total memory) 
       // we should still have no fragmentation
-      int largeChunk = (int) TOTAL_MEMORY - ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+      int largeChunk = (int) TOTAL_MEMORY - ObjectStoredInMemory.HEADER_SIZE;
       doPutOnVm(vm, KEY, new byte[largeChunk], OFF_HEAP_REGION_NAME, false);
       // No compaction has run, so fragmentation should be zero
       assertFragmentationStatOnVm(vm,0,ASSERT_OP.EQUAL);
@@ -255,7 +255,7 @@ public class OffHeapManagementDUnitTest extends CacheTestCase {
       assertFragmentationStatOnVm(vm,0,ASSERT_OP.EQUAL);
       
       // Allocate HALF_TOTAL_MEMORY twice and release one to create one fragment
-      int halfChunk = HALF_TOTAL_MEMORY - ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+      int halfChunk = HALF_TOTAL_MEMORY - ObjectStoredInMemory.HEADER_SIZE;
       doPutOnVm(vm, KEY + "0", new byte[halfChunk], OFF_HEAP_REGION_NAME, false);
       doPutOnVm(vm, KEY + "1", new byte[halfChunk], OFF_HEAP_REGION_NAME, false);
       doDestroyOnVm(vm, KEY + "0", OFF_HEAP_REGION_NAME);
@@ -267,7 +267,7 @@ public class OffHeapManagementDUnitTest extends CacheTestCase {
       
       // Consume the available fragment as below
       // [16][262120][16][262120][16] = [524288] (HALF_TOTAL_MEMORY)
-      int smallChunk = ObjectStoredInMemory.MIN_CHUNK_SIZE - ObjectStoredInMemory.OFF_HEAP_HEADER_SIZE;
+      int smallChunk = ObjectStoredInMemory.MIN_CHUNK_SIZE - ObjectStoredInMemory.HEADER_SIZE;
       int mediumChunk = 262112; //(262120 - ObjectChunk.OFF_HEAP_HEADER_SIZE)
       doPutOnVm(vm, KEY + "S1", new byte[smallChunk], OFF_HEAP_REGION_NAME, false);
       doPutOnVm(vm, KEY + "M1", new byte[mediumChunk], OFF_HEAP_REGION_NAME, false);


Mime
View raw message