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:36 UTC
[01/20] incubator-geode git commit: remove unused classes from
off-heap
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-580 [created] 3e7da9371
remove unused classes from off-heap
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/91d90276
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/91d90276
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/91d90276
Branch: refs/heads/feature/GEODE-580
Commit: 91d90276826a5f6fe89e70d92df0003bb7b989d8
Parents: 59ab8cf
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:13:01 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:13:01 2015 -0800
----------------------------------------------------------------------
.../offheap/SimpleMemoryAllocatorImpl.java | 545 +------------------
.../offheap/ConcurrentBagJUnitTest.java | 130 -----
2 files changed, 5 insertions(+), 670 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/91d90276/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 c800335..7288e55 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
@@ -74,8 +74,6 @@ import com.gemstone.gemfire.internal.cache.RegionEntry;
import com.gemstone.gemfire.internal.cache.RegionEntryContext;
import com.gemstone.gemfire.internal.lang.StringUtils;
import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ConcurrentBag.Node;
import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
import com.gemstone.gemfire.internal.shared.StringPrintWriter;
@@ -787,21 +785,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
public class FreeListManager {
private final AtomicReferenceArray<SyncChunkStack> tinyFreeLists = new AtomicReferenceArray<SyncChunkStack>(TINY_FREE_LIST_COUNT);
- // Deadcoding the BIG stuff. Idea is to have a bigger TINY list by default
-// /**
-// * Every allocated chunk smaller than BIG_MULTIPLE*BIG_FREE_LIST_COUNT but that is not tiny will allocate a chunk of memory that is a multiple of this value.
-// * Sizes are always rounded up to the next multiple of this constant
-// * so internal fragmentation will be limited to BIG_MULTIPLE-1 bytes per allocation
-// * and on average will be BIG_MULTIPLE/2 given a random distribution of size requests.
-// */
-// public final static int BIG_MULTIPLE = TINY_MULTIPLE*8;
-// /**
-// * Number of free lists to keep for big allocations.
-// */
-// private final static int BIG_FREE_LIST_COUNT = 2048;
-// private final static int BIG_OFFSET = (MAX_TINY/BIG_MULTIPLE*BIG_MULTIPLE);
-// public final static int MAX_BIG = (BIG_MULTIPLE*BIG_FREE_LIST_COUNT) + BIG_OFFSET;
-// private final AtomicReferenceArray<ConcurrentChunkStack> bigFreeLists = new AtomicReferenceArray<ConcurrentChunkStack>(BIG_FREE_LIST_COUNT);
// hugeChunkSet is sorted by chunk size in ascending order. It will only contain chunks larger than MAX_TINY.
private final ConcurrentSkipListSet<Chunk> hugeChunkSet = new ConcurrentSkipListSet<Chunk>();
private final AtomicLong allocatedSize = new AtomicLong(0L);
@@ -849,10 +832,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
public long getFreeMemory() {
return getTotalMemory() - getUsedMemory();
-// long result = getFreeFragmentMemory();
-// result += getFreeTinyMemory();
-// result += getFreeHugeMemory();
-// return result;
}
public long getFreeFragmentMemory() {
long result = 0;
@@ -874,16 +853,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
return tinyFree;
}
-// public long getFreeBigMemory() {
-// long bigFree = 0;
-// for (int i=0; i < this.bigFreeLists.length(); i++) {
-// ConcurrentChunkStack cl = this.bigFreeLists.get(i);
-// if (cl != null) {
-// bigFree += cl.computeTotalSize();
-// }
-// }
-// return bigFree;
-// }
public long getFreeHugeMemory() {
long hugeFree = 0;
for (Chunk c: this.hugeChunkSet) {
@@ -891,16 +860,9 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
return hugeFree;
}
-// private int getNearestBigMultiple(int size) {
-// return (size-1-BIG_OFFSET)/BIG_MULTIPLE;
-// }
/**
- * Each long in this array tells us how much of the corresponding slab is allocated.
- */
- //private final AtomicIntegerArray slabOffsets = new AtomicIntegerArray(getSlabs().length);
- /**
- * The slab id of the last slab we allocated from.
+ * The id of the last fragment we allocated from.
*/
private final AtomicInteger lastFragmentAllocation = new AtomicInteger(0);
@@ -928,11 +890,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
/**
- * This is a bit of a hack. TODO add some timeout logic in case this thread never does another off heap allocation.
- */
-// private final ThreadLocal<Chunk> tlCache = new ThreadLocal<Chunk>();
-
- /**
* Allocate a chunk of memory of at least the given size.
* The basic algorithm is:
* 1. Look for a previously allocated and freed chunk close to the size requested.
@@ -950,11 +907,8 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
*/
@SuppressWarnings("synthetic-access")
public Chunk allocate(int size, ChunkType chunkType) {
- Chunk result = null; /*tlCache.get();
-
- if (result != null && result.getDataSize() == size) {
- tlCache.set(null);
- } else */{
+ Chunk result = null;
+ {
assert size > 0;
if (chunkType == null) {
chunkType = GemFireChunk.TYPE;
@@ -983,8 +937,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
if (size <= MAX_TINY) {
return allocateTiny(size, useSlabs, chunkType);
-// } else if (size <= MAX_BIG) {
-// return allocateBig(size, useSlabs);
} else {
return allocateHuge(size, useSlabs, chunkType);
}
@@ -1446,22 +1398,8 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
stats.incFreeMemory(cSize);
notifyListeners();
}
- /*Chunk oldTlChunk = this.tlCache.get();
- this.tlCache.set(c);
- if (oldTlChunk != null) {
- int oldTlcSize = oldTlChunk.getSize();
- if (oldTlcSize <= MAX_TINY) {
- freeTiny(oldTlChunk);
- } else if (oldTlcSize <= MAX_BIG) {
- freeBig(oldTlChunk);
- } else {
- freeHuge(oldTlChunk);
- }
- }*/
if (cSize <= MAX_TINY) {
freeTiny(addr, cSize);
-// } else if (cSize <= MAX_BIG) {
-// freeBig(addr, cSize);
} else {
freeHuge(addr, cSize);
}
@@ -1469,9 +1407,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
private void freeTiny(long addr, int cSize) {
basicFree(addr, getNearestTinyMultiple(cSize), this.tinyFreeLists);
}
-// private void freeBig(long addr, int cSize) {
-// basicFree(addr, getNearestBigMultiple(cSize), this.bigFreeLists);
-// }
private void basicFree(long addr, int idx, AtomicReferenceArray<SyncChunkStack> freeLists) {
SyncChunkStack clq = freeLists.get(idx);
if (clq != null) {
@@ -1491,13 +1426,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
-
-
-
- /*private Chunk newChunk(long addr, int chunkSize) {
- return this.chunkFactory.newChunk(addr, chunkSize);
- }*/
-
private Chunk newFakeChunk(int chunkSize) {
return new FakeChunk(chunkSize);
}
@@ -1675,7 +1603,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
* to it in the cache. Instead the memoryAddress is stored in a primitive field in
* the cache and if used it will then, if needed, create an instance of this class.
*/
- public static abstract class Chunk extends OffHeapCachedDeserializable implements Comparable<Chunk>, ConcurrentBag.Node, MemoryBlock {
+ public static abstract class Chunk extends OffHeapCachedDeserializable implements Comparable<Chunk>, MemoryBlock {
/**
* The unsafe memory address of the first byte of this chunk
*/
@@ -2160,19 +2088,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
return getRefCount(this.memoryAddress);
}
- // By adding this one object ref to Chunk we are able to have free lists that only have memory overhead of a single objref per free item.
- //private Node cbNodeNext;
- @Override
- public void setNextCBNode(Node next) {
- throw new UnsupportedOperationException();
- //this.cbNodeNext = next;
- }
-
- @Override
- public Node getNextCBNode() {
- throw new UnsupportedOperationException();
- //return this.cbNodeNext;
- }
public static int getSize(long memAddr) {
validateAddress(memAddr);
return UnsafeMemoryChunk.readAbsoluteInt(memAddr+CHUNK_SIZE_OFFSET);
@@ -2452,122 +2367,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
return this.size;
}
}
- /**
- * Simple stack structure.
- * The chunk in the top of this stack is pointed to by topAddr.
- * Each next chunk is found be reading a long from the data in the previous chunk.
- * An address of 0L means it is then end of the stack.
- * This class has a subtle race condition in it between
- * one thread doing a poll, allocating data into the chunk returned by poll,
- * and then offering it back. Meanwhile another thread did a poll of the same head chunk,
- * read some of the allocating data as the "next" address and then did the compareAndSet
- * call and it worked because the first thread had already put it back in.
- * So this class should not be used. Instead use SyncChunkStack.
- *
- * @author darrel
- *
- */
- public static class BuggyConcurrentChunkStack {
- // all uses of topAddr are done using topAddrUpdater
- @SuppressWarnings("unused")
- private volatile long topAddr;
- private static final AtomicLongFieldUpdater<BuggyConcurrentChunkStack> topAddrUpdater = AtomicLongFieldUpdater.newUpdater(BuggyConcurrentChunkStack.class, "topAddr");
-
- public BuggyConcurrentChunkStack(long addr) {
- if (addr != 0L) validateAddress(addr);
- this.topAddr = addr;
- }
- public BuggyConcurrentChunkStack() {
- this.topAddr = 0L;
- }
- public boolean isEmpty() {
- return topAddrUpdater.get(this) == 0L;
- }
- public void offer(long e) {
- assert e != 0;
- validateAddress(e);
- long curHead;
- do {
- curHead = topAddrUpdater.get(this);
- Chunk.setNext(e, curHead);
- } while (!topAddrUpdater.compareAndSet(this, curHead, e));
- }
- public long poll() {
- long result;
- long newHead;
- do {
- result = topAddrUpdater.get(this);
- if (result == 0L) return 0L;
- newHead = Chunk.getNext(result);
-
- } while (!topAddrUpdater.compareAndSet(this, result, newHead));
- if (newHead != 0L) validateAddress(newHead);
- return result;
- }
- /**
- * Removes all the Chunks from this stack
- * and returns the address of the first chunk.
- * The caller owns all the Chunks after this call.
- */
- public long clear() {
- long result;
- do {
- result = topAddrUpdater.get(this);
- if (result == 0L) return 0L;
- } while (!topAddrUpdater.compareAndSet(this, result, 0L));
- return result;
- }
- public void logSizes(LogWriter lw, String msg) {
- long headAddr = topAddrUpdater.get(this);
- long addr;
- boolean concurrentModDetected;
- do {
- concurrentModDetected = false;
- addr = headAddr;
- while (addr != 0L) {
- int curSize = Chunk.getSize(addr);
- addr = Chunk.getNext(addr);
- long curHead = topAddrUpdater.get(this);
- if (curHead != headAddr) {
- headAddr = curHead;
- concurrentModDetected = true;
- // Someone added or removed from the stack.
- // So we break out of the inner loop and start
- // again at the new head.
- break;
- }
- // TODO construct a single log msg
- // that gets reset on the concurrent mad.
- lw.info(msg + curSize);
- }
- } while (concurrentModDetected);
- }
- public long computeTotalSize() {
- long result;
- long headAddr = topAddrUpdater.get(this);
- long addr;
- boolean concurrentModDetected;
- do {
- concurrentModDetected = false;
- result = 0;
- addr = headAddr;
- while (addr != 0L) {
- result += Chunk.getSize(addr);
- addr = Chunk.getNext(addr);
- long curHead = topAddrUpdater.get(this);
- if (curHead != headAddr) {
- headAddr = curHead;
- concurrentModDetected = true;
- // Someone added or removed from the stack.
- // So we break out of the inner loop and start
- // again at the new head.
- break;
- }
- }
- } while (concurrentModDetected);
- return result;
- }
- }
public static class SyncChunkStack {
// Ok to read without sync but must be synced on write
private volatile long topAddr;
@@ -2714,7 +2513,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
/**
- * A fragment is a chunk of memory that can have chunks allocated from it.
+ * A fragment is a block of memory that can have chunks allocated from it.
* The allocations are always from the front so the free memory is always
* at the end. The freeIdx keeps track of the first byte of free memory in
* the fragment.
@@ -2819,330 +2618,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public static class ConcurrentBag<E extends ConcurrentBag.Node> implements Iterable<E> {
- public interface Node {
- public void setNextCBNode(Node next);
- public Node getNextCBNode();
- }
- private final AtomicReference<E> root = new AtomicReference<E>(null);
-
- public ConcurrentBag() {
- }
- public ConcurrentBag(int initialSize) {
- }
- @Override
- public Iterator<E> iterator() {
- // TODO this iterator is used a bunch in the compactor.
- // If a concurrent poll is done while iterating then the
- // iterator may return a element that has been removed from
- // the bag by the poll call. This is ok currently because
- // the next field on Node is only used by the bag and is not
- // nulled out by the poll call.
- return new Iterator<E>() {
- private E nextElem = root.get();
-
- @Override
- public boolean hasNext() {
- return this.nextElem != null;
- }
-
- @Override
- public E next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
- E result = this.nextElem;
- this.nextElem = (E)this.nextElem.getNextCBNode();
- return result;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
- public void offer(E e) {
- E tmp;
- do {
- tmp = this.root.get();
- e.setNextCBNode(tmp);
- } while (!this.root.compareAndSet(tmp, e));
- }
- public E poll() {
- E result;
- do {
- result = this.root.get();
- if (result == null) return null;
- } while (!this.root.compareAndSet(result, (E)result.getNextCBNode()));
- // we should probably do
- // result.setNextCBNode(null);
- // but this could mess up a concurrent iterator so for now leave it set.
- // Since the objects added to the bag are never garbage having an extra
- // reference to one is no big deal.
- return result;
- }
- }
-
- public static class ConcurrentBagABQ<E> implements Iterable<E> {
- private static final int FREE_LIST_SIZE = Integer.getInteger("gemfire.FREE_LIST_SIZE", 1024);
- private final ArrayBlockingQueue<E> data;
-
- public ConcurrentBagABQ() {
- this.data = new ArrayBlockingQueue<E>(FREE_LIST_SIZE);
- }
- public ConcurrentBagABQ(int initialSize) {
- this.data = new ArrayBlockingQueue<E>(initialSize);
- }
- @Override
- public Iterator<E> iterator() {
- return this.data.iterator();
- }
- public void offer(E e) {
- this.data.add(e);
- }
- public E poll() {
- return this.data.poll();
- }
- }
- /**
- * The idea of this data structure is for it to be somewhat concurrent but to also not produce garbage.
- * Since this bag is used to implement each free list it can contain entries that get promoted to oldgen.
- * Note when used concurrently this structure does not maintain a pure FIFO ordering. That is why it is
- * called a Bag instead of a List.
- *
- * @author darrel
- */
- public static class ConcurrentBagBroken<E> implements Iterable<E> {
- private static final int FREE_LIST_SIZE = Integer.getInteger("gemfire.FREE_LIST_SIZE", 1024);
- private volatile AtomicReferenceArray<E> data;
- private final AtomicInteger size = new AtomicInteger(0);
-
- public ConcurrentBagBroken() {
- this.data = new AtomicReferenceArray<E>(FREE_LIST_SIZE);
- }
- public ConcurrentBagBroken(int initialSize) {
- this.data = new AtomicReferenceArray<E>(initialSize);
- }
- @Override
- public Iterator<E> iterator() {
- return new Iterator<E>() {
- private final AtomicReferenceArray<E> itData = data;
- private int idx = 0;
- private E nextElem = null;
-
- @Override
- public boolean hasNext() {
- E next = null;
- do {
- if (this.idx >= this.itData.length()) {
- next = null;
- break;
- }
- next = this.itData.get(this.idx);
- if (next == null) {
- this.idx++;
- }
- } while (next == null);
- this.nextElem = next;
- return next != null;
- }
-
- @Override
- public E next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
- this.idx++;
- return this.nextElem;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
- public void offer(E e) {
- int idx = this.size.get();
- int dataLength = this.data.length();
- while (idx >= dataLength) {
- grow(dataLength);
- idx = this.size.get();
- dataLength = this.data.length();
- }
- while (!this.data.compareAndSet(idx, null, e)) {
- dataLength = this.data.length();
- if (idx >= dataLength) {
- grow(dataLength);
- }
- int oldIdx = idx;
- idx = this.size.get();
- if (oldIdx == idx && idx < dataLength-1) {
- idx++;
- }
- }
- // At this point we have put e in the data array.
- // Now update the size pointer to help the next guy find
- // the next slot.
- // If concurrent offers have already happened then they will
- // have set size to something even greater.
- // if concurrent polls have already happened then they will
- // have set size to something even less.
- this.size.compareAndSet(idx, idx+1);
- }
- public E poll() {
- int idx = -1;
- E result;
- do {
- int oldIdx = idx;
- idx = this.size.get();
- if (idx == oldIdx && idx > 0) {
- idx--;
- }
- if (idx == 0) {
- // sync in case a concurrent grow is happening.
- // this allows us to switch over to the new data array.
- synchronized (this) {
- idx = this.size.get();
- if (idx == 0) {
- return null;
- }
- }
- }
- result = this.data.getAndSet(idx-1, null);
- } while (result == null);
- // At this point we have taken result from the data array.
- // Now update the size pointer to help the next guy.
- // If concurrent polls have already happened then they will
- // have set size to something even less.
- // If concurrent offers have already happened then they will
- // have set size to something even greater.
- this.size.compareAndSet(idx, idx-1);
- return result;
- }
- private synchronized void grow(int oldDataLength) {
- // Note that concurrent polls may happen while we are in grow.
- // So we need to use the atomic operations to copy the data.
- if (this.data.length() != oldDataLength) return;
- AtomicReferenceArray<E> newData = new AtomicReferenceArray<E>(oldDataLength*2);
- int idx = 0;
- for (int i=0; i < oldDataLength; i++) {
- E e = this.data.getAndSet(i, null);
- if (e != null) {
- newData.lazySet(idx++, e);
- }
- }
- this.data = newData;
- this.size.set(idx);
- }
- }
- public static class ConcurrentBagLQ<E> implements Iterable<E> {
- private final ConcurrentLinkedQueue<E> delegate = new ConcurrentLinkedQueue<E>();
-// private final CopyOnWriteArrayList<ArrayBlockingQueue<E>> metaList = new CopyOnWriteArrayList<ArrayBlockingQueue<E>>();
-// private final AtomicInteger offerIdx = new AtomicInteger(0);
-// private final AtomicInteger pollIdx = new AtomicInteger(0);
-// private static final int CHUNK_SIZE = 1024;
-
- public ConcurrentBagLQ() {
-// this.metaList.add(new ArrayBlockingQueue<E>(CHUNK_SIZE));
- }
- public ConcurrentBagLQ(int size) {
- }
-
- @Override
- public Iterator<E> iterator() {
- // This impl does not support concurrent updates
-// return new Iterator<E>() {
-// private final Iterator<ArrayBlockingQueue<E>> metaListIterator = metaList.iterator();
-// private Iterator<E> qIterator = null;
-//
-// @Override
-// public boolean hasNext() {
-// do {
-// if (this.qIterator != null && this.qIterator.hasNext()) {
-// return true;
-// }
-// if (this.metaListIterator.hasNext()) {
-// this.qIterator = metaListIterator.next().iterator();
-// } else {
-// this.qIterator = null;
-// }
-// } while (this.qIterator != null);
-// return false;
-// }
-//
-// @Override
-// public E next() {
-// if (!hasNext()) {
-// throw new NoSuchElementException("No more values in iterator");
-// }
-// return this.qIterator.next();
-// }
-//
-// @Override
-// public void remove() {
-// if (this.qIterator == null) {
-// throw new IllegalStateException("next has not been called.");
-// }
-// this.qIterator.remove();
-// }
-// };
- return this.delegate.iterator();
- }
-
- public void offer(E e) {
-// int start = this.offerIdx.get();
-// for (int i=start; i >= 0; i--) {
-// ArrayBlockingQueue<E> q = this.metaList.get(i);
-// if (q.offer(e)) {
-// if (i != start) {
-// this.offerIdx.set(i);
-// }
-// return;
-// }
-// }
-// for (int i=this.metaList.size()-1; i > start; i--) {
-// ArrayBlockingQueue<E> q = this.metaList.get(i);
-// if (q.offer(e)) {
-// this.offerIdx.set(i);
-// return;
-// }
-// }
-// ArrayBlockingQueue<E> q = new ArrayBlockingQueue<E>(CHUNK_SIZE);
-// q.offer(e);
-// this.metaList.add(q);
-// this.offerIdx.set(this.metaList.size()-1);
- if (!this.delegate.offer(e)) {
- throw new IllegalStateException("offer returned false");
- }
- }
- public E poll() {
-// int start = this.pollIdx.get();
-// int end = this.metaList.size()-1;
-// for (int i=start; i <= end; i++) {
-// ArrayBlockingQueue<E> q = this.metaList.get(i);
-// E result = q.poll();
-// if (result != null) {
-// if (i != start) {
-// this.pollIdx.set(i);
-// }
-// return result;
-// }
-// }
-// for (int i=0; i < start; i++) {
-// ArrayBlockingQueue<E> q = this.metaList.get(i);
-// E result = q.poll();
-// if (result != null) {
-// this.pollIdx.set(i);
-// return result;
-// }
-// }
-// return null;
- return this.delegate.poll();
- }
- }
-
private void printSlabs() {
for (int i =0; i < this.slabs.length; i++) {
logger.info(slabs[i]);
@@ -3231,19 +2706,16 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
@Override
public List<MemoryBlock> getDeallocatedBlocks() {
- // TODO Auto-generated method stub
return null;
}
@Override
public List<MemoryBlock> getUnusedBlocks() {
- // TODO Auto-generated method stub
return null;
}
@Override
public MemoryBlock getBlockContaining(long memoryAddress) {
- // TODO Auto-generated method stub
return null;
}
@@ -3272,13 +2744,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
@Override
public int compare(MemoryBlock o1, MemoryBlock o2) {
return Long.valueOf(o1.getMemoryAddress()).compareTo(o2.getMemoryAddress());
- /*if (o1.getMemoryAddress() < o2.getMemoryAddress()) {
- return -1;
- } else if (o1.getMemoryAddress() == o2.getMemoryAddress()) {
- return 0;
- } else {
- return 1;
- }*/
}
});
return value;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/91d90276/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/ConcurrentBagJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/ConcurrentBagJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/ConcurrentBagJUnitTest.java
deleted file mode 100644
index 8bba8db..0000000
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/ConcurrentBagJUnitTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ConcurrentBag.Node;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class ConcurrentBagJUnitTest {
-
- public static class IntNode implements SimpleMemoryAllocatorImpl.ConcurrentBag.Node {
-
- private final int data;
-
- public IntNode(int i) {
- this.data = i;
- }
-
- public Integer getData() {
- return this.data;
- }
-
- private Node next;
- @Override
- public void setNextCBNode(Node next) {
- this.next = next;
- }
- @Override
- public Node getNextCBNode() {
- return this.next;
- }
-
- }
- @Test
- public void testBasicFreeList() {
- SimpleMemoryAllocatorImpl.ConcurrentBag<IntNode> l = new SimpleMemoryAllocatorImpl.ConcurrentBag<IntNode>(5000);
- assertEquals(false, l.iterator().hasNext());
- try {
- l.iterator().next();
- fail("expected NoSuchElementException");
- } catch (NoSuchElementException expected) {
- }
- assertEquals(null, l.poll());
-
- l.offer(new IntNode(1));
- assertEquals(true, l.iterator().hasNext());
-
- assertEquals(Integer.valueOf(1), l.iterator().next().getData());
- assertEquals(Integer.valueOf(1), l.poll().getData());
- assertEquals(false, l.iterator().hasNext());
- assertEquals(null, l.poll());
-
- try {
- l.iterator().remove();
- fail("expected UnsupportedOperationException");
- } catch (UnsupportedOperationException expected) {
- }
-// {
-// l.offer(new IntNode(1));
-// l.offer(new IntNode(2));
-// Iterator<IntNode> it = l.iterator();
-// assertEquals(true, it.hasNext());
-// assertEquals(Integer.valueOf(1), it.next().getData());
-// assertEquals(true, it.hasNext());
-// assertEquals(Integer.valueOf(2), it.next().getData());
-// assertEquals(false, it.hasNext());
-//
-// it = l.iterator();
-// try {
-// it.remove();
-// fail("expected IllegalStateException");
-// } catch (IllegalStateException expected) {
-// }
-// it.next();
-// it.remove();
-// try {
-// it.remove();
-// fail("expected IllegalStateException");
-// } catch (IllegalStateException expected) {
-// }
-// assertEquals(Integer.valueOf(2), it.next());
-// assertEquals(false, it.hasNext());
-//
-// assertEquals(Integer.valueOf(2), l.poll());
-// assertEquals(null, l.poll());
-// }
-
- for (int i=1; i <= 3999; i++) {
- l.offer(new IntNode(i));
- }
- {
- Iterator<IntNode> it = l.iterator();
-// for (int i=1; i <= 3999; i++) {
- for (int i=3999; i >= 1; i--) {
- assertEquals(true, it.hasNext());
- assertEquals(Integer.valueOf(i), it.next().getData());
- }
- assertEquals(false, it.hasNext());
- }
-// for (int i=1; i <= 3999; i++) {
- for (int i=3999; i >= 1; i--) {
- assertEquals(Integer.valueOf(i), l.poll().getData());
- }
- assertEquals(null, l.poll());
- }
-
-}
[18/20] incubator-geode git commit: move FakeChunk from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move FakeChunk 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/27b2aeb9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/27b2aeb9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/27b2aeb9
Branch: refs/heads/feature/GEODE-580
Commit: 27b2aeb9ae2cfe2b76222432c11b61f7d2fdefa7
Parents: d63f65d
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:50:04 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:50:04 2015 -0800
----------------------------------------------------------------------
.../gemfire/internal/offheap/FakeChunk.java | 34 ++++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 18 +----------
2 files changed, 35 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/27b2aeb9/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FakeChunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FakeChunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FakeChunk.java
new file mode 100644
index 0000000..5a36270
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FakeChunk.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+/**
+ * Used by the FreeListManager to easily search its
+ * ConcurrentSkipListSet. This is not a real chunk
+ * but only used for searching.
+ */
+public class FakeChunk extends Chunk {
+ private final int size;
+ public FakeChunk(int size) {
+ super();
+ this.size = size;
+ }
+ @Override
+ public int getSize() {
+ return this.size;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/27b2aeb9/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 458ddef..6303f5b 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
@@ -1150,7 +1150,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
private Chunk allocateHuge(int size, boolean useFragments, ChunkType chunkType) {
// sizeHolder is a fake Chunk used to search our sorted hugeChunkSet.
- Chunk sizeHolder = newFakeChunk(size);
+ Chunk sizeHolder = new FakeChunk(size);
NavigableSet<Chunk> ts = this.hugeChunkSet.tailSet(sizeHolder);
Chunk result = ts.pollFirst();
if (result != null) {
@@ -1223,22 +1223,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- private Chunk newFakeChunk(int chunkSize) {
- return new FakeChunk(chunkSize);
- }
-
-
- public static class FakeChunk extends Chunk {
- private final int size;
- public FakeChunk(int size) {
- super();
- this.size = size;
- }
- @Override
- public int getSize() {
- return this.size;
- }
- }
public static class SyncChunkStack {
// Ok to read without sync but must be synced on write
private volatile long topAddr;
[09/20] incubator-geode git commit: move GemFireChunk out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move GemFireChunk out of 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/4d10de4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/4d10de4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/4d10de4c
Branch: refs/heads/feature/GEODE-580
Commit: 4d10de4c4c400f9e2faf4e27e8e037d118df54f1
Parents: 944e186
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:48:09 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:48:09 2015 -0800
----------------------------------------------------------------------
.../internal/cache/AbstractRegionEntry.java | 2 +-
.../gemfire/internal/offheap/GemFireChunk.java | 56 ++++++++++++++++++++
.../internal/offheap/GemFireChunkFactory.java | 1 -
.../offheap/SimpleMemoryAllocatorImpl.java | 31 -----------
4 files changed, 57 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4d10de4c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
index 0078f66..cd6218a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
@@ -62,11 +62,11 @@ import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
import com.gemstone.gemfire.internal.offheap.Chunk;
+import com.gemstone.gemfire.internal.offheap.GemFireChunk;
import com.gemstone.gemfire.internal.offheap.MemoryAllocator;
import com.gemstone.gemfire.internal.offheap.OffHeapCachedDeserializable;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunkType;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4d10de4c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
new file mode 100644
index 0000000..d0d41a6
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
@@ -0,0 +1,56 @@
+/*
+ * 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 com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunkSlice;
+
+/**
+ * A chunk that stores a GemFire object.
+ * Currently the object stored in this chunk
+ * is always an entry value of a Region.
+ */
+public class GemFireChunk extends Chunk {
+ public static final ChunkType TYPE = new ChunkType() {
+ @Override
+ public int getSrcType() {
+ return Chunk.SRC_TYPE_GFE;
+ }
+ @Override
+ public Chunk newChunk(long memoryAddress) {
+ return new GemFireChunk(memoryAddress);
+ }
+ @Override
+ public Chunk newChunk(long memoryAddress, int chunkSize) {
+ return new GemFireChunk(memoryAddress, chunkSize);
+ }
+ };
+ public GemFireChunk(long memoryAddress, int chunkSize) {
+ super(memoryAddress, chunkSize, TYPE);
+ }
+
+ public GemFireChunk(long memoryAddress) {
+ super(memoryAddress);
+ // chunkType may be set by caller when it calls readyForAllocation
+ }
+ public GemFireChunk(GemFireChunk chunk) {
+ super(chunk);
+ }
+ @Override
+ public Chunk slice(int position, int limit) {
+ return new GemFireChunkSlice(this, position, limit);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4d10de4c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
index e8e80aa..c3f3bcc 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
@@ -16,7 +16,6 @@
*/
package com.gemstone.gemfire.internal.offheap;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunk;
/**
* A ChunkFactory that produces chunks of type GemFireChunk.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4d10de4c/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 b492bb5..7f2d6e8 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
@@ -1471,37 +1471,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
return new GemFireChunk(memoryAddress, chunkSize);
}
}
- public static class GemFireChunk extends Chunk {
- public static final ChunkType TYPE = new ChunkType() {
- @Override
- public int getSrcType() {
- return Chunk.SRC_TYPE_GFE;
- }
- @Override
- public Chunk newChunk(long memoryAddress) {
- return new GemFireChunk(memoryAddress);
- }
- @Override
- public Chunk newChunk(long memoryAddress, int chunkSize) {
- return new GemFireChunk(memoryAddress, chunkSize);
- }
- };
- public GemFireChunk(long memoryAddress, int chunkSize) {
- super(memoryAddress, chunkSize, TYPE);
- }
-
- public GemFireChunk(long memoryAddress) {
- super(memoryAddress);
- // chunkType may be set by caller when it calls readyForAllocation
- }
- public GemFireChunk(GemFireChunk chunk) {
- super(chunk);
- }
- @Override
- public Chunk slice(int position, int limit) {
- return new GemFireChunkSlice(this, position, limit);
- }
- }
public static class GemFireChunkSlice extends GemFireChunk {
private final int offset;
private final int capacity;
[17/20] incubator-geode git commit: move MemoryBlockNode from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
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.
[15/20] incubator-geode git commit: move RefCountChangeInfo from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
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 {
[13/20] incubator-geode git commit: move DataAsAddress from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move DataAsAddress 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/ff64d0b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/ff64d0b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/ff64d0b0
Branch: refs/heads/feature/GEODE-580
Commit: ff64d0b0708c7b3ee38d60b3f82de595c6543c39
Parents: e7b29ce
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:00:09 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:00:09 2015 -0800
----------------------------------------------------------------------
.../internal/cache/tier/sockets/Part.java | 2 +-
.../gemfire/internal/offheap/DataAsAddress.java | 205 +++++++++++++++++++
.../offheap/OffHeapRegionEntryHelper.java | 1 -
.../offheap/SimpleMemoryAllocatorImpl.java | 185 -----------------
.../cache/OldValueImporterTestBase.java | 2 +-
.../OffHeapWriteObjectAsByteArrayJUnitTest.java | 1 -
6 files changed, 207 insertions(+), 189 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
index 0bbcc6b..5418c68 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
@@ -19,7 +19,7 @@ package com.gemstone.gemfire.internal.cache.tier.sockets;
import com.gemstone.gemfire.internal.*;
import com.gemstone.gemfire.internal.cache.CachedDeserializable;
import com.gemstone.gemfire.internal.offheap.Chunk;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
+import com.gemstone.gemfire.internal.offheap.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
new file mode 100644
index 0000000..61204ba
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
@@ -0,0 +1,205 @@
+/*
+ * 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.DataOutput;
+import java.io.IOException;
+
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.internal.DataSerializableFixedID;
+import com.gemstone.gemfire.internal.InternalDataSerializer;
+import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
+import com.gemstone.gemfire.internal.cache.EntryBits;
+import com.gemstone.gemfire.internal.cache.RegionEntry;
+import com.gemstone.gemfire.internal.cache.RegionEntryContext;
+import com.gemstone.gemfire.internal.lang.StringUtils;
+
+/**
+ * Used to represent offheap addresses whose
+ * value encodes actual data instead a memory
+ * location.
+ * Instances of this class have a very short lifetime.
+ */
+public class DataAsAddress implements StoredObject {
+ private final long address;
+
+ public DataAsAddress(long addr) {
+ this.address = addr;
+ }
+
+ public long getEncodedAddress() {
+ return this.address;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof DataAsAddress) {
+ return getEncodedAddress() == ((DataAsAddress) o).getEncodedAddress();
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ long value = getEncodedAddress();
+ return (int)(value ^ (value >>> 32));
+ }
+
+ @Override
+ public int getSizeInBytes() {
+ return 0;
+ }
+
+ public byte[] getDecompressedBytes(RegionEntryContext r) {
+ return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address, true, r);
+ }
+
+ /**
+ * If we contain a byte[] return it.
+ * Otherwise return the serialize bytes in us in a byte array.
+ */
+ public byte[] getRawBytes() {
+ return OffHeapRegionEntryHelper.encodedAddressToRawBytes(this.address);
+ }
+
+ @Override
+ public byte[] getSerializedValue() {
+ return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address);
+ }
+
+ @Override
+ public Object getDeserializedValue(Region r, RegionEntry re) {
+ return OffHeapRegionEntryHelper.encodedAddressToObject(this.address);
+ }
+
+ @Override
+ public Object getDeserializedForReading() {
+ return getDeserializedValue(null,null);
+ }
+
+ @Override
+ public Object getValueAsDeserializedHeapObject() {
+ return getDeserializedValue(null,null);
+ }
+
+ @Override
+ public byte[] getValueAsHeapByteArray() {
+ if (isSerialized()) {
+ return getSerializedValue();
+ } else {
+ return (byte[])getDeserializedForReading();
+ }
+ }
+
+ @Override
+ public String getStringForm() {
+ try {
+ return StringUtils.forceToString(getDeserializedForReading());
+ } catch (RuntimeException ex) {
+ return "Could not convert object to string because " + ex;
+ }
+ }
+
+ @Override
+ public Object getDeserializedWritableCopy(Region r, RegionEntry re) {
+ return getDeserializedValue(null,null);
+ }
+
+ @Override
+ public Object getValue() {
+ if (isSerialized()) {
+ return getSerializedValue();
+ } else {
+ throw new IllegalStateException("Can not call getValue on StoredObject that is not serialized");
+ }
+ }
+
+ @Override
+ public void writeValueAsByteArray(DataOutput out) throws IOException {
+ DataSerializer.writeByteArray(getSerializedValue(), out);
+ }
+
+ @Override
+ public void fillSerializedValue(BytesAndBitsForCompactor wrapper,
+ byte userBits) {
+ byte[] value;
+ if (isSerialized()) {
+ value = getSerializedValue();
+ userBits = EntryBits.setSerialized(userBits, true);
+ } else {
+ value = (byte[]) getDeserializedForReading();
+ }
+ wrapper.setData(value, userBits, value.length, true);
+ }
+
+ @Override
+ public int getValueSizeInBytes() {
+ return 0;
+ }
+
+ @Override
+ public void sendTo(DataOutput out) throws IOException {
+ if (isSerialized()) {
+ out.write(getSerializedValue());
+ } else {
+ Object objToSend = (byte[]) getDeserializedForReading(); // deserialized as a byte[]
+ DataSerializer.writeObject(objToSend, out);
+ }
+ }
+
+ @Override
+ public void sendAsByteArray(DataOutput out) throws IOException {
+ byte[] bytes;
+ if (isSerialized()) {
+ bytes = getSerializedValue();
+ } else {
+ bytes = (byte[]) getDeserializedForReading();
+ }
+ DataSerializer.writeByteArray(bytes, out);
+
+ }
+
+ @Override
+ public void sendAsCachedDeserializable(DataOutput out) throws IOException {
+ if (!isSerialized()) {
+ throw new IllegalStateException("sendAsCachedDeserializable can only be called on serialized StoredObjects");
+ }
+ InternalDataSerializer.writeDSFIDHeader(DataSerializableFixedID.VM_CACHED_DESERIALIZABLE, out);
+ sendAsByteArray(out);
+ }
+
+ @Override
+ public boolean isSerialized() {
+ return OffHeapRegionEntryHelper.isSerialized(this.address);
+ }
+
+ @Override
+ public boolean isCompressed() {
+ return OffHeapRegionEntryHelper.isCompressed(this.address);
+ }
+
+ @Override
+ public boolean retain() {
+ // nothing needed
+ return true;
+ }
+ @Override
+ public void release() {
+ // nothing needed
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
index 6cb43ad..34c3468 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
@@ -24,7 +24,6 @@ import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.OffHeapRegionEntry;
import com.gemstone.gemfire.internal.cache.RegionEntryContext;
import com.gemstone.gemfire.internal.cache.Token;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/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 98be355..40a01b5 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
@@ -17,7 +17,6 @@
package com.gemstone.gemfire.internal.offheap;
import java.io.ByteArrayOutputStream;
-import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
@@ -53,19 +52,13 @@ import com.gemstone.gemfire.OutOfOffHeapMemoryException;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.DataSerializableFixedID;
-import com.gemstone.gemfire.internal.InternalDataSerializer;
import com.gemstone.gemfire.internal.cache.BucketRegion;
-import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
-import com.gemstone.gemfire.internal.cache.EntryBits;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegionDataStore;
import com.gemstone.gemfire.internal.cache.RegionEntry;
-import com.gemstone.gemfire.internal.cache.RegionEntryContext;
-import com.gemstone.gemfire.internal.lang.StringUtils;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
@@ -398,184 +391,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
return result;
}
- /**
- * Used to represent offheap addresses whose
- * value encodes actual data instead a memory
- * location.
- * Instances of this class have a very short lifetime.
- *
- * @author darrel
- *
- */
- public static class DataAsAddress implements StoredObject {
- private final long address;
-
- public DataAsAddress(long addr) {
- this.address = addr;
- }
-
- public long getEncodedAddress() {
- return this.address;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof DataAsAddress) {
- return getEncodedAddress() == ((DataAsAddress) o).getEncodedAddress();
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- long value = getEncodedAddress();
- return (int)(value ^ (value >>> 32));
- }
-
- @Override
- public int getSizeInBytes() {
- return 0;
- }
-
- public byte[] getDecompressedBytes(RegionEntryContext r) {
- return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address, true, r);
- }
-
- /**
- * If we contain a byte[] return it.
- * Otherwise return the serialize bytes in us in a byte array.
- */
- public byte[] getRawBytes() {
- return OffHeapRegionEntryHelper.encodedAddressToRawBytes(this.address);
- }
-
- @Override
- public byte[] getSerializedValue() {
- return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address);
- }
-
- @Override
- public Object getDeserializedValue(Region r, RegionEntry re) {
- return OffHeapRegionEntryHelper.encodedAddressToObject(this.address);
- }
-
- @Override
- public Object getDeserializedForReading() {
- return getDeserializedValue(null,null);
- }
-
- @Override
- public Object getValueAsDeserializedHeapObject() {
- return getDeserializedValue(null,null);
- }
-
- @Override
- public byte[] getValueAsHeapByteArray() {
- if (isSerialized()) {
- return getSerializedValue();
- } else {
- return (byte[])getDeserializedForReading();
- }
- }
-
- @Override
- public String getStringForm() {
- try {
- return StringUtils.forceToString(getDeserializedForReading());
- } catch (RuntimeException ex) {
- return "Could not convert object to string because " + ex;
- }
- }
-
- @Override
- public Object getDeserializedWritableCopy(Region r, RegionEntry re) {
- return getDeserializedValue(null,null);
- }
-
- @Override
- public Object getValue() {
- if (isSerialized()) {
- return getSerializedValue();
- } else {
- throw new IllegalStateException("Can not call getValue on StoredObject that is not serialized");
- }
- }
-
- @Override
- public void writeValueAsByteArray(DataOutput out) throws IOException {
- DataSerializer.writeByteArray(getSerializedValue(), out);
- }
-
- @Override
- public void fillSerializedValue(BytesAndBitsForCompactor wrapper,
- byte userBits) {
- byte[] value;
- if (isSerialized()) {
- value = getSerializedValue();
- userBits = EntryBits.setSerialized(userBits, true);
- } else {
- value = (byte[]) getDeserializedForReading();
- }
- wrapper.setData(value, userBits, value.length, true);
- }
-
- @Override
- public int getValueSizeInBytes() {
- return 0;
- }
-
- @Override
- public void sendTo(DataOutput out) throws IOException {
- if (isSerialized()) {
- out.write(getSerializedValue());
- } else {
- Object objToSend = (byte[]) getDeserializedForReading(); // deserialized as a byte[]
- DataSerializer.writeObject(objToSend, out);
- }
- }
-
- @Override
- public void sendAsByteArray(DataOutput out) throws IOException {
- byte[] bytes;
- if (isSerialized()) {
- bytes = getSerializedValue();
- } else {
- bytes = (byte[]) getDeserializedForReading();
- }
- DataSerializer.writeByteArray(bytes, out);
-
- }
-
- @Override
- public void sendAsCachedDeserializable(DataOutput out) throws IOException {
- if (!isSerialized()) {
- throw new IllegalStateException("sendAsCachedDeserializable can only be called on serialized StoredObjects");
- }
- InternalDataSerializer.writeDSFIDHeader(DataSerializableFixedID.VM_CACHED_DESERIALIZABLE, out);
- sendAsByteArray(out);
- }
-
- @Override
- public boolean isSerialized() {
- return OffHeapRegionEntryHelper.isSerialized(this.address);
- }
-
- @Override
- public boolean isCompressed() {
- return OffHeapRegionEntryHelper.isCompressed(this.address);
- }
-
- @Override
- public boolean retain() {
- // nothing needed
- return true;
- }
- @Override
- public void release() {
- // nothing needed
- }
- }
-
@SuppressWarnings("unused")
public static void debugLog(String msg, boolean logStack) {
if (logStack) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
index 2889b0c..f7d0714 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
@@ -27,10 +27,10 @@ import org.junit.Test;
import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.cache.EntryEventImpl.OldValueImporter;
import com.gemstone.gemfire.internal.offheap.Chunk;
+import com.gemstone.gemfire.internal.offheap.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
import com.gemstone.gemfire.internal.util.BlobHelper;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
index e371231..daebefa 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
@@ -34,7 +34,6 @@ import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
[20/20] incubator-geode git commit: move FreeListManager from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move FreeListManager 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/3e7da937
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3e7da937
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3e7da937
Branch: refs/heads/feature/GEODE-580
Commit: 3e7da9371d61d23c4f785d5e721f2c4b05c47514
Parents: 18f5e9d
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 17:06:56 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 17:06:56 2015 -0800
----------------------------------------------------------------------
.../internal/offheap/FreeListManager.java | 679 +++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 661 +-----------------
2 files changed, 685 insertions(+), 655 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3e7da937/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
new file mode 100644
index 0000000..f335b4b
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
@@ -0,0 +1,679 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.NavigableSet;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+
+import com.gemstone.gemfire.LogWriter;
+import com.gemstone.gemfire.OutOfOffHeapMemoryException;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+
+/**
+ * Manages the free lists for a SimpleMemoryAllocatorImpl
+ */
+public class FreeListManager {
+ final AtomicReferenceArray<SyncChunkStack> tinyFreeLists = new AtomicReferenceArray<SyncChunkStack>(SimpleMemoryAllocatorImpl.TINY_FREE_LIST_COUNT);
+ // hugeChunkSet is sorted by chunk size in ascending order. It will only contain chunks larger than MAX_TINY.
+ final ConcurrentSkipListSet<Chunk> hugeChunkSet = new ConcurrentSkipListSet<Chunk>();
+ private final AtomicLong allocatedSize = new AtomicLong(0L);
+
+ private int getNearestTinyMultiple(int size) {
+ return (size-1)/SimpleMemoryAllocatorImpl.TINY_MULTIPLE;
+ }
+ public List<Chunk> getLiveChunks() {
+ ArrayList<Chunk> result = new ArrayList<Chunk>();
+ UnsafeMemoryChunk[] slabs = this.ma.getSlabs();
+ for (int i=0; i < slabs.length; i++) {
+ getLiveChunks(slabs[i], result);
+ }
+ return result;
+ }
+ private void getLiveChunks(UnsafeMemoryChunk slab, List<Chunk> result) {
+ long addr = slab.getMemoryAddress();
+ while (addr <= (slab.getMemoryAddress() + slab.getSize() - Chunk.MIN_CHUNK_SIZE)) {
+ Fragment f = isAddrInFragmentFreeSpace(addr);
+ if (f != null) {
+ addr = f.getMemoryAddress() + f.getSize();
+ } else {
+ int curChunkSize = Chunk.getSize(addr);
+ int refCount = Chunk.getRefCount(addr);
+ if (refCount > 0) {
+ result.add(this.ma.chunkFactory.newChunk(addr));
+ }
+ addr += curChunkSize;
+ }
+ }
+ }
+ /**
+ * If addr is in the free space of a fragment then return that fragment; otherwise return null.
+ */
+ private Fragment isAddrInFragmentFreeSpace(long addr) {
+ for (Fragment f: this.fragmentList) {
+ if (addr >= (f.getMemoryAddress() + f.getFreeIndex()) && addr < (f.getMemoryAddress() + f.getSize())) {
+ return f;
+ }
+ }
+ return null;
+ }
+ public long getUsedMemory() {
+ return this.allocatedSize.get();
+ }
+ public long getFreeMemory() {
+ return this.ma.getTotalMemory() - getUsedMemory();
+ }
+ public long getFreeFragmentMemory() {
+ long result = 0;
+ for (Fragment f: this.fragmentList) {
+ int freeSpace = f.freeSpace();
+ if (freeSpace >= Chunk.MIN_CHUNK_SIZE) {
+ result += freeSpace;
+ }
+ }
+ return result;
+ }
+ public long getFreeTinyMemory() {
+ long tinyFree = 0;
+ for (int i=0; i < this.tinyFreeLists.length(); i++) {
+ SyncChunkStack cl = this.tinyFreeLists.get(i);
+ if (cl != null) {
+ tinyFree += cl.computeTotalSize();
+ }
+ }
+ return tinyFree;
+ }
+ public long getFreeHugeMemory() {
+ long hugeFree = 0;
+ for (Chunk c: this.hugeChunkSet) {
+ hugeFree += c.getSize();
+ }
+ return hugeFree;
+ }
+
+ /**
+ * The id of the last fragment we allocated from.
+ */
+ private final AtomicInteger lastFragmentAllocation = new AtomicInteger(0);
+ final CopyOnWriteArrayList<Fragment> fragmentList;
+ private final SimpleMemoryAllocatorImpl ma;
+
+ public FreeListManager(SimpleMemoryAllocatorImpl ma) {
+ this.ma = ma;
+ UnsafeMemoryChunk[] slabs = ma.getSlabs();
+ Fragment[] tmp = new Fragment[slabs.length];
+ for (int i=0; i < slabs.length; i++) {
+ tmp[i] = new Fragment(slabs[i].getMemoryAddress(), slabs[i].getSize());
+ }
+ this.fragmentList = new CopyOnWriteArrayList<Fragment>(tmp);
+
+ if(ma.validateMemoryWithFill) {
+ fillFragments();
+ }
+ }
+
+ /**
+ * Fills all fragments with a fill used for data integrity validation.
+ */
+ private void fillFragments() {
+ for(Fragment fragment : this.fragmentList) {
+ fragment.fill();
+ }
+ }
+
+ /**
+ * Allocate a chunk of memory of at least the given size.
+ * The basic algorithm is:
+ * 1. Look for a previously allocated and freed chunk close to the size requested.
+ * 2. See if the original chunk is big enough to split. If so do so.
+ * 3. Look for a previously allocated and freed chunk of any size larger than the one requested.
+ * If we find one split it.
+ * <p>
+ * It might be better not to include step 3 since we expect and freed chunk to be reallocated in the future.
+ * Maybe it would be better for 3 to look for adjacent free blocks that can be merged together.
+ * For now we will just try 1 and 2 and then report out of mem.
+ * @param size minimum bytes the returned chunk must have.
+ * @param chunkType TODO
+ * @return the allocated chunk
+ * @throws IllegalStateException if a chunk can not be allocated.
+ */
+ @SuppressWarnings("synthetic-access")
+ public Chunk allocate(int size, ChunkType chunkType) {
+ Chunk result = null;
+ {
+ assert size > 0;
+ if (chunkType == null) {
+ chunkType = GemFireChunk.TYPE;
+ }
+ result = basicAllocate(size, true, chunkType);
+ result.setDataSize(size);
+ }
+ this.ma.stats.incObjects(1);
+ int resultSize = result.getSize();
+ this.allocatedSize.addAndGet(resultSize);
+ this.ma.stats.incUsedMemory(resultSize);
+ this.ma.stats.incFreeMemory(-resultSize);
+ result.initializeUseCount();
+ this.ma.notifyListeners();
+
+ return result;
+ }
+
+ private Chunk basicAllocate(int size, boolean useSlabs, ChunkType chunkType) {
+ if (useSlabs) {
+ // Every object stored off heap has a header so we need
+ // to adjust the size so that the header gets allocated.
+ // If useSlabs is false then the incoming size has already
+ // been adjusted.
+ size += Chunk.OFF_HEAP_HEADER_SIZE;
+ }
+ if (size <= SimpleMemoryAllocatorImpl.MAX_TINY) {
+ return allocateTiny(size, useSlabs, chunkType);
+ } else {
+ return allocateHuge(size, useSlabs, chunkType);
+ }
+ }
+
+ private Chunk allocateFromFragments(int chunkSize, ChunkType chunkType) {
+ do {
+ final int lastAllocationId = this.lastFragmentAllocation.get();
+ for (int i=lastAllocationId; i < this.fragmentList.size(); i++) {
+ Chunk result = allocateFromFragment(i, chunkSize, chunkType);
+ if (result != null) {
+ return result;
+ }
+ }
+ for (int i=0; i < lastAllocationId; i++) {
+ Chunk result = allocateFromFragment(i, chunkSize, chunkType);
+ if (result != null) {
+ return result;
+ }
+ }
+ } while (compact(chunkSize));
+ // We tried all the fragments and didn't find any free memory.
+ logOffHeapState(chunkSize);
+ final OutOfOffHeapMemoryException failure = new OutOfOffHeapMemoryException("Out of off-heap memory. Could not allocate size of " + chunkSize);
+ try {
+ throw failure;
+ } finally {
+ this.ma.ooohml.outOfOffHeapMemory(failure);
+ }
+ }
+
+ private void logOffHeapState(int chunkSize) {
+ if (InternalDistributedSystem.getAnyInstance() != null) {
+ LogWriter lw = InternalDistributedSystem.getAnyInstance().getLogWriter();
+ lw.info("OutOfOffHeapMemory allocating size of " + chunkSize + ". allocated=" + this.allocatedSize.get() + " compactions=" + this.compactCount.get() + " objects=" + this.ma.stats.getObjects() + " free=" + this.ma.stats.getFreeMemory() + " fragments=" + this.ma.stats.getFragments() + " largestFragment=" + this.ma.stats.getLargestFragment() + " fragmentation=" + this.ma.stats.getFragmentation());
+ logFragmentState(lw);
+ logTinyState(lw);
+// logBigState(lw);
+ logHugeState(lw);
+ }
+ }
+
+ private void logHugeState(LogWriter lw) {
+ for (Chunk c: this.hugeChunkSet) {
+ lw.info("Free huge of size " + c.getSize());
+ }
+ }
+// private void logBigState(LogWriter lw) {
+// for (int i=0; i < this.bigFreeLists.length(); i++) {
+// ConcurrentChunkStack cl = this.bigFreeLists.get(i);
+// if (cl != null) {
+// cl.logSizes(lw, "Free big of size ");
+// }
+// }
+// }
+ private void logTinyState(LogWriter lw) {
+ for (int i=0; i < this.tinyFreeLists.length(); i++) {
+ SyncChunkStack cl = this.tinyFreeLists.get(i);
+ if (cl != null) {
+ cl.logSizes(lw, "Free tiny of size ");
+ }
+ }
+ }
+ private void logFragmentState(LogWriter lw) {
+ for (Fragment f: this.fragmentList) {
+ int freeSpace = f.freeSpace();
+ if (freeSpace > 0) {
+ lw.info("Fragment at " + f.getMemoryAddress() + " of size " + f.getSize() + " has " + freeSpace + " bytes free.");
+ }
+ }
+ }
+
+ private final AtomicInteger compactCount = new AtomicInteger();
+ /**
+ * Compacts memory and returns true if enough memory to allocate chunkSize
+ * is freed. Otherwise returns false;
+ * TODO OFFHEAP: what should be done about contiguous chunks that end up being bigger than 2G?
+ * Currently if we are given slabs bigger than 2G or that just happen to be contiguous and add
+ * up to 2G then the compactor may unify them together into a single Chunk and our 32-bit chunkSize
+ * field will overflow. This code needs to detect this and just create a chunk of 2G and then start
+ * a new one.
+ * Or to prevent it from happening we could just check the incoming slabs and throw away a few bytes
+ * to keep them from being contiguous.
+ */
+ boolean compact(int chunkSize) {
+ final long startCompactionTime = this.ma.getStats().startCompaction();
+ final int countPreSync = this.compactCount.get();
+ try {
+ synchronized (this) {
+ if (this.compactCount.get() != countPreSync) {
+ // someone else did a compaction while we waited on the sync.
+ // So just return true causing the caller to retry the allocation.
+ return true;
+ }
+ ArrayList<SyncChunkStack> freeChunks = new ArrayList<SyncChunkStack>();
+ collectFreeChunks(freeChunks);
+ final int SORT_ARRAY_BLOCK_SIZE = 128;
+ long[] sorted = new long[SORT_ARRAY_BLOCK_SIZE];
+ int sortedSize = 0;
+ boolean result = false;
+ int largestFragment = 0;
+ for (SyncChunkStack l: freeChunks) {
+ long addr = l.poll();
+ while (addr != 0) {
+ int idx = Arrays.binarySearch(sorted, 0, sortedSize, addr);
+ //System.out.println("DEBUG addr=" + addr + " size=" + Chunk.getSize(addr) + " idx="+idx + " sortedSize=" + sortedSize);
+ if (idx >= 0) {
+ throw new IllegalStateException("duplicate memory address found during compaction!");
+ }
+ idx = -idx;
+ idx--;
+ if (idx == sortedSize) {
+ // addr is > everything in the array
+ if (sortedSize == 0) {
+ // nothing was in the array
+ sorted[0] = addr;
+ sortedSize++;
+ } else {
+ // see if we can conflate into sorted[idx]
+ long lowAddr = sorted[idx-1];
+ int lowSize = Chunk.getSize(lowAddr);
+ if (lowAddr + lowSize == addr) {
+ // append the addr chunk to lowAddr
+ Chunk.setSize(lowAddr, lowSize + Chunk.getSize(addr));
+ } else {
+ if (sortedSize >= sorted.length) {
+ long[] newSorted = new long[sorted.length+SORT_ARRAY_BLOCK_SIZE];
+ System.arraycopy(sorted, 0, newSorted, 0, sorted.length);
+ sorted = newSorted;
+ }
+ sortedSize++;
+ sorted[idx] = addr;
+ }
+ }
+ } else {
+ int addrSize = Chunk.getSize(addr);
+ long highAddr = sorted[idx];
+ if (addr + addrSize == highAddr) {
+ // append highAddr chunk to addr
+ Chunk.setSize(addr, addrSize + Chunk.getSize(highAddr));
+ sorted[idx] = addr;
+ } else {
+ boolean insert = idx==0;
+ if (!insert) {
+ long lowAddr = sorted[idx-1];
+ // if (lowAddr == 0L) {
+ // long[] tmp = Arrays.copyOf(sorted, sortedSize);
+ // throw new IllegalStateException("addr was zero at idx=" + (idx-1) + " sorted="+ Arrays.toString(tmp));
+ // }
+ int lowSize = Chunk.getSize(lowAddr);
+ if (lowAddr + lowSize == addr) {
+ // append the addr chunk to lowAddr
+ Chunk.setSize(lowAddr, lowSize + addrSize);
+ } else {
+ insert = true;
+ }
+ }
+ if (insert) {
+ if (sortedSize >= sorted.length) {
+ long[] newSorted = new long[sorted.length+SORT_ARRAY_BLOCK_SIZE];
+ System.arraycopy(sorted, 0, newSorted, 0, idx);
+ newSorted[idx] = addr;
+ System.arraycopy(sorted, idx, newSorted, idx+1, sortedSize-idx);
+ sorted = newSorted;
+ } else {
+ System.arraycopy(sorted, idx, sorted, idx+1, sortedSize-idx);
+ sorted[idx] = addr;
+ }
+ sortedSize++;
+ }
+ }
+ }
+ addr = l.poll();
+ }
+ }
+ for (int i=sortedSize-1; i > 0; i--) {
+ long addr = sorted[i];
+ long lowAddr = sorted[i-1];
+ int lowSize = Chunk.getSize(lowAddr);
+ if (lowAddr + lowSize == addr) {
+ // append addr chunk to lowAddr
+ Chunk.setSize(lowAddr, lowSize + Chunk.getSize(addr));
+ sorted[i] = 0L;
+ }
+ }
+ this.lastFragmentAllocation.set(0);
+ ArrayList<Fragment> tmp = new ArrayList<Fragment>();
+ for (int i=sortedSize-1; i >= 0; i--) {
+ long addr = sorted[i];
+ if (addr == 0L) continue;
+ int addrSize = Chunk.getSize(addr);
+ Fragment f = new Fragment(addr, addrSize);
+ if (addrSize >= chunkSize) {
+ result = true;
+ }
+ if (addrSize > largestFragment) {
+ largestFragment = addrSize;
+ // TODO it might be better to sort them biggest first
+ tmp.add(0, f);
+ } else {
+ tmp.add(f);
+ }
+ }
+ this.fragmentList.addAll(tmp);
+
+ // Reinitialize fragments with fill pattern data
+ if(this.ma.validateMemoryWithFill) {
+ fillFragments();
+ }
+
+ // Signal any waiters that a compaction happened.
+ this.compactCount.incrementAndGet();
+
+ this.ma.getStats().setLargestFragment(largestFragment);
+ this.ma.getStats().setFragments(tmp.size());
+ updateFragmentation();
+
+ return result;
+ } // sync
+ } finally {
+ this.ma.getStats().endCompaction(startCompactionTime);
+ }
+ }
+
+ private void updateFragmentation() {
+ long freeSize = this.ma.getStats().getFreeMemory();
+
+ // Calculate free space fragmentation only if there is free space available.
+ if(freeSize > 0) {
+ long largestFragment = this.ma.getStats().getLargestFragment();
+ long numerator = freeSize - largestFragment;
+
+ double percentage = (double) numerator / (double) freeSize;
+ percentage *= 100d;
+
+ int wholePercentage = (int) Math.rint(percentage);
+ this.ma.getStats().setFragmentation(wholePercentage);
+ } else {
+ // No free space? Then we have no free space fragmentation.
+ this.ma.getStats().setFragmentation(0);
+ }
+ }
+
+ private void collectFreeChunks(List<SyncChunkStack> l) {
+ collectFreeFragmentChunks(l);
+ collectFreeHugeChunks(l);
+// collectFreeBigChunks(l);
+ collectFreeTinyChunks(l);
+ }
+ private void collectFreeFragmentChunks(List<SyncChunkStack> l) {
+ if (this.fragmentList.size() == 0) return;
+ SyncChunkStack result = new SyncChunkStack();
+ for (Fragment f: this.fragmentList) {
+ int offset;
+ int diff;
+ do {
+ offset = f.getFreeIndex();
+ diff = f.getSize() - offset;
+ } while (diff >= Chunk.MIN_CHUNK_SIZE && !f.allocate(offset, offset+diff));
+ if (diff < Chunk.MIN_CHUNK_SIZE) {
+ if (diff > 0) {
+ SimpleMemoryAllocatorImpl.logger.debug("Lost memory of size {}", diff);
+ }
+ // fragment is too small to turn into a chunk
+ // TODO we need to make sure this never happens
+ // by keeping sizes rounded. I think I did this
+ // by introducing MIN_CHUNK_SIZE and by rounding
+ // the size of huge allocations.
+ continue;
+ }
+ long chunkAddr = f.getMemoryAddress()+offset;
+ Chunk.setSize(chunkAddr, diff);
+ result.offer(chunkAddr);
+ }
+ // All the fragments have been turned in to chunks so now clear them
+ // The compaction will create new fragments.
+ this.fragmentList.clear();
+ if (!result.isEmpty()) {
+ l.add(result);
+ }
+ }
+ private void collectFreeTinyChunks(List<SyncChunkStack> l) {
+ for (int i=0; i < this.tinyFreeLists.length(); i++) {
+ SyncChunkStack cl = this.tinyFreeLists.get(i);
+ if (cl != null) {
+ long head = cl.clear();
+ if (head != 0L) {
+ l.add(new SyncChunkStack(head));
+ }
+ }
+ }
+ }
+// private void collectFreeBigChunks(List<ConcurrentChunkStack> l) {
+// for (int i=0; i < this.bigFreeLists.length(); i++) {
+// ConcurrentChunkStack cl = this.bigFreeLists.get(i);
+// if (cl != null) {
+// long head = cl.clear();
+// if (head != 0L) {
+// l.add(new ConcurrentChunkStack(head));
+// }
+// }
+// }
+// }
+ public void collectFreeHugeChunks(List<SyncChunkStack> l) {
+ Chunk c = this.hugeChunkSet.pollFirst();
+ SyncChunkStack result = null;
+ while (c != null) {
+ if (result == null) {
+ result = new SyncChunkStack();
+ l.add(result);
+ }
+ result.offer(c.getMemoryAddress());
+ c = this.hugeChunkSet.pollFirst();
+ }
+ }
+
+ private Chunk allocateFromFragment(final int fragIdx, final int chunkSize, ChunkType chunkType) {
+ if (fragIdx >= this.fragmentList.size()) return null;
+ final Fragment fragment;
+ try {
+ fragment = this.fragmentList.get(fragIdx);
+ } catch (IndexOutOfBoundsException ignore) {
+ // A concurrent compaction can cause this.
+ return null;
+ }
+ boolean retryFragment;
+ do {
+ retryFragment = false;
+ int oldOffset = fragment.getFreeIndex();
+ int fragmentSize = fragment.getSize();
+ int fragmentFreeSize = fragmentSize - oldOffset;
+ if (fragmentFreeSize >= chunkSize) {
+ // this fragment has room
+ // Try to allocate up to BATCH_SIZE more chunks from it
+ int allocSize = chunkSize * SimpleMemoryAllocatorImpl.BATCH_SIZE;
+ if (allocSize > fragmentFreeSize) {
+ allocSize = (fragmentFreeSize / chunkSize) * chunkSize;
+ }
+ int newOffset = oldOffset + allocSize;
+ int extraSize = fragmentSize - newOffset;
+ if (extraSize < Chunk.MIN_CHUNK_SIZE) {
+ // include these last few bytes of the fragment in the allocation.
+ // If we don't then they will be lost forever.
+ // The extraSize bytes only apply to the first chunk we allocate (not the batch ones).
+ newOffset += extraSize;
+ } else {
+ extraSize = 0;
+ }
+ if (fragment.allocate(oldOffset, newOffset)) {
+ // We did the allocate!
+ this.lastFragmentAllocation.set(fragIdx);
+ Chunk result = this.ma.chunkFactory.newChunk(fragment.getMemoryAddress()+oldOffset, chunkSize+extraSize, chunkType);
+ allocSize -= chunkSize+extraSize;
+ oldOffset += extraSize;
+ while (allocSize > 0) {
+ oldOffset += chunkSize;
+ // we add the batch ones immediately to the freelist
+ result.readyForFree();
+ free(result.getMemoryAddress(), false);
+ result = this.ma.chunkFactory.newChunk(fragment.getMemoryAddress()+oldOffset, chunkSize, chunkType);
+ allocSize -= chunkSize;
+ }
+
+ if(this.ma.validateMemoryWithFill) {
+ result.validateFill();
+ }
+
+ return result;
+ } else {
+ // TODO OFFHEAP: if batch allocations are disabled should we not call basicAllocate here?
+ // Since we know another thread did a concurrent alloc
+ // that possibly did a batch check the free list again.
+ Chunk result = basicAllocate(chunkSize, false, chunkType);
+ if (result != null) {
+ return result;
+ }
+ retryFragment = true;
+ }
+ }
+ } while (retryFragment);
+ return null; // did not find enough free space in this fragment
+ }
+
+ private int round(int multiple, int value) {
+ return (int) ((((long)value + (multiple-1)) / multiple) * multiple);
+ }
+ private Chunk allocateTiny(int size, boolean useFragments, ChunkType chunkType) {
+ return basicAllocate(getNearestTinyMultiple(size), SimpleMemoryAllocatorImpl.TINY_MULTIPLE, 0, this.tinyFreeLists, useFragments, chunkType);
+ }
+// private Chunk allocateBig(int size, boolean useFragments) {
+// return basicAllocate(getNearestBigMultiple(size), BIG_MULTIPLE, BIG_OFFSET, this.bigFreeLists, useFragments);
+// }
+ private Chunk basicAllocate(int idx, int multiple, int offset, AtomicReferenceArray<SyncChunkStack> freeLists, boolean useFragments, ChunkType chunkType) {
+ SyncChunkStack clq = freeLists.get(idx);
+ if (clq != null) {
+ long memAddr = clq.poll();
+ if (memAddr != 0) {
+ Chunk result = this.ma.chunkFactory.newChunk(memAddr, chunkType);
+
+ // Data integrity check.
+ if(this.ma.validateMemoryWithFill) {
+ result.validateFill();
+ }
+
+ result.readyForAllocation(chunkType);
+ return result;
+ }
+ }
+ if (useFragments) {
+ return allocateFromFragments(((idx+1)*multiple)+offset, chunkType);
+ } else {
+ return null;
+ }
+ }
+ private Chunk allocateHuge(int size, boolean useFragments, ChunkType chunkType) {
+ // sizeHolder is a fake Chunk used to search our sorted hugeChunkSet.
+ Chunk sizeHolder = new FakeChunk(size);
+ NavigableSet<Chunk> ts = this.hugeChunkSet.tailSet(sizeHolder);
+ Chunk result = ts.pollFirst();
+ if (result != null) {
+ if (result.getSize() - (SimpleMemoryAllocatorImpl.HUGE_MULTIPLE - Chunk.OFF_HEAP_HEADER_SIZE) < size) {
+ // close enough to the requested size; just return it.
+
+ // Data integrity check.
+ if(this.ma.validateMemoryWithFill) {
+ result.validateFill();
+ }
+ if (chunkType.getSrcType() != Chunk.getSrcType(result.getMemoryAddress())) {
+ // The java wrapper class that was cached in the huge chunk list is the wrong type.
+ // So allocate a new one and garbage collect the old one.
+ result = this.ma.chunkFactory.newChunk(result.getMemoryAddress(), chunkType);
+ }
+ result.readyForAllocation(chunkType);
+ return result;
+ } else {
+ this.hugeChunkSet.add(result);
+ }
+ }
+ if (useFragments) {
+ // We round it up to the next multiple of TINY_MULTIPLE to make
+ // sure we always have chunks allocated on an 8 byte boundary.
+ return allocateFromFragments(round(SimpleMemoryAllocatorImpl.TINY_MULTIPLE, size), chunkType);
+ } else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("synthetic-access")
+ public void free(long addr) {
+ free(addr, true);
+ }
+
+ private void free(long addr, boolean updateStats) {
+ int cSize = Chunk.getSize(addr);
+ if (updateStats) {
+ this.ma.stats.incObjects(-1);
+ this.allocatedSize.addAndGet(-cSize);
+ this.ma.stats.incUsedMemory(-cSize);
+ this.ma.stats.incFreeMemory(cSize);
+ this.ma.notifyListeners();
+ }
+ if (cSize <= SimpleMemoryAllocatorImpl.MAX_TINY) {
+ freeTiny(addr, cSize);
+ } else {
+ freeHuge(addr, cSize);
+ }
+ }
+ private void freeTiny(long addr, int cSize) {
+ basicFree(addr, getNearestTinyMultiple(cSize), this.tinyFreeLists);
+ }
+ private void basicFree(long addr, int idx, AtomicReferenceArray<SyncChunkStack> freeLists) {
+ SyncChunkStack clq = freeLists.get(idx);
+ if (clq != null) {
+ clq.offer(addr);
+ } else {
+ clq = new SyncChunkStack();
+ clq.offer(addr);
+ if (!freeLists.compareAndSet(idx, null, clq)) {
+ clq = freeLists.get(idx);
+ clq.offer(addr);
+ }
+ }
+
+ }
+ private void freeHuge(long addr, int cSize) {
+ this.hugeChunkSet.add(this.ma.chunkFactory.newChunk(addr)); // TODO make this a collection of longs
+ }
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3e7da937/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 0cb7068..688fbe0 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
@@ -24,25 +24,19 @@ import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.NavigableSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentSkipListSet;
-import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
import org.apache.logging.log4j.Logger;
import com.gemstone.gemfire.LogWriter;
-import com.gemstone.gemfire.OutOfOffHeapMemoryException;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
import com.gemstone.gemfire.internal.cache.BucketRegion;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
@@ -68,7 +62,7 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
*/
public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryInspector {
- private static final Logger logger = LogService.getLogger();
+ static final Logger logger = LogService.getLogger();
public static final String FREE_OFF_HEAP_MEMORY_PROPERTY = "gemfire.free-off-heap-memory";
@@ -91,9 +85,9 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
public final static int MAX_TINY = TINY_MULTIPLE*TINY_FREE_LIST_COUNT;
public final static int HUGE_MULTIPLE = 256;
- private volatile OffHeapMemoryStats stats;
+ volatile OffHeapMemoryStats stats;
- private volatile OutOfOffHeapMemoryListener ooohml;
+ volatile OutOfOffHeapMemoryListener ooohml;
/** The MemoryChunks that this allocator is managing by allocating smaller chunks of them.
* The contents of this array never change.
@@ -108,7 +102,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
private static SimpleMemoryAllocatorImpl singleton = null;
private static final AtomicReference<Thread> asyncCleanupThread = new AtomicReference<Thread>();
- private final ChunkFactory chunkFactory;
+ final ChunkFactory chunkFactory;
public static SimpleMemoryAllocatorImpl getAllocator() {
SimpleMemoryAllocatorImpl result = singleton;
@@ -296,7 +290,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
this.stats.incMaxMemory(this.totalSlabSize);
this.stats.incFreeMemory(this.totalSlabSize);
- this.freeList = new FreeListManager();
+ this.freeList = new FreeListManager(this);
}
public List<Chunk> getLostChunks() {
@@ -567,7 +561,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- private void notifyListeners() {
+ void notifyListeners() {
final MemoryUsageListener[] savedListeners = this.memoryUsageListeners;
if (savedListeners.length == 0) {
@@ -580,649 +574,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public class FreeListManager {
- private final AtomicReferenceArray<SyncChunkStack> tinyFreeLists = new AtomicReferenceArray<SyncChunkStack>(TINY_FREE_LIST_COUNT);
- // hugeChunkSet is sorted by chunk size in ascending order. It will only contain chunks larger than MAX_TINY.
- private final ConcurrentSkipListSet<Chunk> hugeChunkSet = new ConcurrentSkipListSet<Chunk>();
- private final AtomicLong allocatedSize = new AtomicLong(0L);
-
- private int getNearestTinyMultiple(int size) {
- return (size-1)/TINY_MULTIPLE;
- }
- public List<Chunk> getLiveChunks() {
- ArrayList<Chunk> result = new ArrayList<Chunk>();
- UnsafeMemoryChunk[] slabs = getSlabs();
- for (int i=0; i < slabs.length; i++) {
- getLiveChunks(slabs[i], result);
- }
- return result;
- }
- private void getLiveChunks(UnsafeMemoryChunk slab, List<Chunk> result) {
- long addr = slab.getMemoryAddress();
- while (addr <= (slab.getMemoryAddress() + slab.getSize() - Chunk.MIN_CHUNK_SIZE)) {
- Fragment f = isAddrInFragmentFreeSpace(addr);
- if (f != null) {
- addr = f.getMemoryAddress() + f.getSize();
- } else {
- int curChunkSize = Chunk.getSize(addr);
- int refCount = Chunk.getRefCount(addr);
- if (refCount > 0) {
- result.add(SimpleMemoryAllocatorImpl.this.chunkFactory.newChunk(addr));
- }
- addr += curChunkSize;
- }
- }
- }
- /**
- * If addr is in the free space of a fragment then return that fragment; otherwise return null.
- */
- private Fragment isAddrInFragmentFreeSpace(long addr) {
- for (Fragment f: this.fragmentList) {
- if (addr >= (f.getMemoryAddress() + f.getFreeIndex()) && addr < (f.getMemoryAddress() + f.getSize())) {
- return f;
- }
- }
- return null;
- }
- public long getUsedMemory() {
- return this.allocatedSize.get();
- }
- public long getFreeMemory() {
- return getTotalMemory() - getUsedMemory();
- }
- public long getFreeFragmentMemory() {
- long result = 0;
- for (Fragment f: this.fragmentList) {
- int freeSpace = f.freeSpace();
- if (freeSpace >= Chunk.MIN_CHUNK_SIZE) {
- result += freeSpace;
- }
- }
- return result;
- }
- public long getFreeTinyMemory() {
- long tinyFree = 0;
- for (int i=0; i < this.tinyFreeLists.length(); i++) {
- SyncChunkStack cl = this.tinyFreeLists.get(i);
- if (cl != null) {
- tinyFree += cl.computeTotalSize();
- }
- }
- return tinyFree;
- }
- public long getFreeHugeMemory() {
- long hugeFree = 0;
- for (Chunk c: this.hugeChunkSet) {
- hugeFree += c.getSize();
- }
- return hugeFree;
- }
-
- /**
- * The id of the last fragment we allocated from.
- */
- private final AtomicInteger lastFragmentAllocation = new AtomicInteger(0);
-
- private final CopyOnWriteArrayList<Fragment> fragmentList;
- public FreeListManager() {
- UnsafeMemoryChunk[] slabs = getSlabs();
- Fragment[] tmp = new Fragment[slabs.length];
- for (int i=0; i < slabs.length; i++) {
- tmp[i] = new Fragment(slabs[i].getMemoryAddress(), slabs[i].getSize());
- }
- this.fragmentList = new CopyOnWriteArrayList<Fragment>(tmp);
-
- if(validateMemoryWithFill) {
- fillFragments();
- }
- }
-
- /**
- * Fills all fragments with a fill used for data integrity validation.
- */
- private void fillFragments() {
- for(Fragment fragment : this.fragmentList) {
- fragment.fill();
- }
- }
-
- /**
- * Allocate a chunk of memory of at least the given size.
- * The basic algorithm is:
- * 1. Look for a previously allocated and freed chunk close to the size requested.
- * 2. See if the original chunk is big enough to split. If so do so.
- * 3. Look for a previously allocated and freed chunk of any size larger than the one requested.
- * If we find one split it.
- * <p>
- * It might be better not to include step 3 since we expect and freed chunk to be reallocated in the future.
- * Maybe it would be better for 3 to look for adjacent free blocks that can be merged together.
- * For now we will just try 1 and 2 and then report out of mem.
- * @param size minimum bytes the returned chunk must have.
- * @param chunkType TODO
- * @return the allocated chunk
- * @throws IllegalStateException if a chunk can not be allocated.
- */
- @SuppressWarnings("synthetic-access")
- public Chunk allocate(int size, ChunkType chunkType) {
- Chunk result = null;
- {
- assert size > 0;
- if (chunkType == null) {
- chunkType = GemFireChunk.TYPE;
- }
- result = basicAllocate(size, true, chunkType);
- result.setDataSize(size);
- }
- stats.incObjects(1);
- int resultSize = result.getSize();
- this.allocatedSize.addAndGet(resultSize);
- stats.incUsedMemory(resultSize);
- stats.incFreeMemory(-resultSize);
- result.initializeUseCount();
- notifyListeners();
-
- return result;
- }
-
- private Chunk basicAllocate(int size, boolean useSlabs, ChunkType chunkType) {
- if (useSlabs) {
- // Every object stored off heap has a header so we need
- // to adjust the size so that the header gets allocated.
- // If useSlabs is false then the incoming size has already
- // been adjusted.
- size += Chunk.OFF_HEAP_HEADER_SIZE;
- }
- if (size <= MAX_TINY) {
- return allocateTiny(size, useSlabs, chunkType);
- } else {
- return allocateHuge(size, useSlabs, chunkType);
- }
- }
-
- private Chunk allocateFromFragments(int chunkSize, ChunkType chunkType) {
- do {
- final int lastAllocationId = this.lastFragmentAllocation.get();
- for (int i=lastAllocationId; i < this.fragmentList.size(); i++) {
- Chunk result = allocateFromFragment(i, chunkSize, chunkType);
- if (result != null) {
- return result;
- }
- }
- for (int i=0; i < lastAllocationId; i++) {
- Chunk result = allocateFromFragment(i, chunkSize, chunkType);
- if (result != null) {
- return result;
- }
- }
- } while (compact(chunkSize));
- // We tried all the fragments and didn't find any free memory.
- logOffHeapState(chunkSize);
- final OutOfOffHeapMemoryException failure = new OutOfOffHeapMemoryException("Out of off-heap memory. Could not allocate size of " + chunkSize);
- try {
- throw failure;
- } finally {
- SimpleMemoryAllocatorImpl.this.ooohml.outOfOffHeapMemory(failure);
- }
- }
-
- private void logOffHeapState(int chunkSize) {
- if (InternalDistributedSystem.getAnyInstance() != null) {
- LogWriter lw = InternalDistributedSystem.getAnyInstance().getLogWriter();
- lw.info("OutOfOffHeapMemory allocating size of " + chunkSize + ". allocated=" + this.allocatedSize.get() + " compactions=" + this.compactCount.get() + " objects=" + stats.getObjects() + " free=" + stats.getFreeMemory() + " fragments=" + stats.getFragments() + " largestFragment=" + stats.getLargestFragment() + " fragmentation=" + stats.getFragmentation());
- logFragmentState(lw);
- logTinyState(lw);
-// logBigState(lw);
- logHugeState(lw);
- }
- }
-
- private void logHugeState(LogWriter lw) {
- for (Chunk c: this.hugeChunkSet) {
- lw.info("Free huge of size " + c.getSize());
- }
- }
-// private void logBigState(LogWriter lw) {
-// for (int i=0; i < this.bigFreeLists.length(); i++) {
-// ConcurrentChunkStack cl = this.bigFreeLists.get(i);
-// if (cl != null) {
-// cl.logSizes(lw, "Free big of size ");
-// }
-// }
-// }
- private void logTinyState(LogWriter lw) {
- for (int i=0; i < this.tinyFreeLists.length(); i++) {
- SyncChunkStack cl = this.tinyFreeLists.get(i);
- if (cl != null) {
- cl.logSizes(lw, "Free tiny of size ");
- }
- }
- }
- private void logFragmentState(LogWriter lw) {
- for (Fragment f: this.fragmentList) {
- int freeSpace = f.freeSpace();
- if (freeSpace > 0) {
- lw.info("Fragment at " + f.getMemoryAddress() + " of size " + f.getSize() + " has " + freeSpace + " bytes free.");
- }
- }
- }
-
- private final AtomicInteger compactCount = new AtomicInteger();
- /**
- * Compacts memory and returns true if enough memory to allocate chunkSize
- * is freed. Otherwise returns false;
- * TODO OFFHEAP: what should be done about contiguous chunks that end up being bigger than 2G?
- * Currently if we are given slabs bigger than 2G or that just happen to be contiguous and add
- * up to 2G then the compactor may unify them together into a single Chunk and our 32-bit chunkSize
- * field will overflow. This code needs to detect this and just create a chunk of 2G and then start
- * a new one.
- * Or to prevent it from happening we could just check the incoming slabs and throw away a few bytes
- * to keep them from being contiguous.
- */
- private boolean compact(int chunkSize) {
- final long startCompactionTime = getStats().startCompaction();
- final int countPreSync = this.compactCount.get();
- try {
- synchronized (this) {
- if (this.compactCount.get() != countPreSync) {
- // someone else did a compaction while we waited on the sync.
- // So just return true causing the caller to retry the allocation.
- return true;
- }
- ArrayList<SyncChunkStack> freeChunks = new ArrayList<SyncChunkStack>();
- collectFreeChunks(freeChunks);
- final int SORT_ARRAY_BLOCK_SIZE = 128;
- long[] sorted = new long[SORT_ARRAY_BLOCK_SIZE];
- int sortedSize = 0;
- boolean result = false;
- int largestFragment = 0;
- for (SyncChunkStack l: freeChunks) {
- long addr = l.poll();
- while (addr != 0) {
- int idx = Arrays.binarySearch(sorted, 0, sortedSize, addr);
- //System.out.println("DEBUG addr=" + addr + " size=" + Chunk.getSize(addr) + " idx="+idx + " sortedSize=" + sortedSize);
- if (idx >= 0) {
- throw new IllegalStateException("duplicate memory address found during compaction!");
- }
- idx = -idx;
- idx--;
- if (idx == sortedSize) {
- // addr is > everything in the array
- if (sortedSize == 0) {
- // nothing was in the array
- sorted[0] = addr;
- sortedSize++;
- } else {
- // see if we can conflate into sorted[idx]
- long lowAddr = sorted[idx-1];
- int lowSize = Chunk.getSize(lowAddr);
- if (lowAddr + lowSize == addr) {
- // append the addr chunk to lowAddr
- Chunk.setSize(lowAddr, lowSize + Chunk.getSize(addr));
- } else {
- if (sortedSize >= sorted.length) {
- long[] newSorted = new long[sorted.length+SORT_ARRAY_BLOCK_SIZE];
- System.arraycopy(sorted, 0, newSorted, 0, sorted.length);
- sorted = newSorted;
- }
- sortedSize++;
- sorted[idx] = addr;
- }
- }
- } else {
- int addrSize = Chunk.getSize(addr);
- long highAddr = sorted[idx];
- if (addr + addrSize == highAddr) {
- // append highAddr chunk to addr
- Chunk.setSize(addr, addrSize + Chunk.getSize(highAddr));
- sorted[idx] = addr;
- } else {
- boolean insert = idx==0;
- if (!insert) {
- long lowAddr = sorted[idx-1];
- // if (lowAddr == 0L) {
- // long[] tmp = Arrays.copyOf(sorted, sortedSize);
- // throw new IllegalStateException("addr was zero at idx=" + (idx-1) + " sorted="+ Arrays.toString(tmp));
- // }
- int lowSize = Chunk.getSize(lowAddr);
- if (lowAddr + lowSize == addr) {
- // append the addr chunk to lowAddr
- Chunk.setSize(lowAddr, lowSize + addrSize);
- } else {
- insert = true;
- }
- }
- if (insert) {
- if (sortedSize >= sorted.length) {
- long[] newSorted = new long[sorted.length+SORT_ARRAY_BLOCK_SIZE];
- System.arraycopy(sorted, 0, newSorted, 0, idx);
- newSorted[idx] = addr;
- System.arraycopy(sorted, idx, newSorted, idx+1, sortedSize-idx);
- sorted = newSorted;
- } else {
- System.arraycopy(sorted, idx, sorted, idx+1, sortedSize-idx);
- sorted[idx] = addr;
- }
- sortedSize++;
- }
- }
- }
- addr = l.poll();
- }
- }
- for (int i=sortedSize-1; i > 0; i--) {
- long addr = sorted[i];
- long lowAddr = sorted[i-1];
- int lowSize = Chunk.getSize(lowAddr);
- if (lowAddr + lowSize == addr) {
- // append addr chunk to lowAddr
- Chunk.setSize(lowAddr, lowSize + Chunk.getSize(addr));
- sorted[i] = 0L;
- }
- }
- this.lastFragmentAllocation.set(0);
- ArrayList<Fragment> tmp = new ArrayList<Fragment>();
- for (int i=sortedSize-1; i >= 0; i--) {
- long addr = sorted[i];
- if (addr == 0L) continue;
- int addrSize = Chunk.getSize(addr);
- Fragment f = new Fragment(addr, addrSize);
- if (addrSize >= chunkSize) {
- result = true;
- }
- if (addrSize > largestFragment) {
- largestFragment = addrSize;
- // TODO it might be better to sort them biggest first
- tmp.add(0, f);
- } else {
- tmp.add(f);
- }
- }
- this.fragmentList.addAll(tmp);
-
- // Reinitialize fragments with fill pattern data
- if(validateMemoryWithFill) {
- fillFragments();
- }
-
- // Signal any waiters that a compaction happened.
- this.compactCount.incrementAndGet();
-
- getStats().setLargestFragment(largestFragment);
- getStats().setFragments(tmp.size());
- updateFragmentation();
-
- return result;
- } // sync
- } finally {
- getStats().endCompaction(startCompactionTime);
- }
- }
-
- private void updateFragmentation() {
- long freeSize = getStats().getFreeMemory();
-
- // Calculate free space fragmentation only if there is free space available.
- if(freeSize > 0) {
- long largestFragment = getStats().getLargestFragment();
- long numerator = freeSize - largestFragment;
-
- double percentage = (double) numerator / (double) freeSize;
- percentage *= 100d;
-
- int wholePercentage = (int) Math.rint(percentage);
- getStats().setFragmentation(wholePercentage);
- } else {
- // No free space? Then we have no free space fragmentation.
- getStats().setFragmentation(0);
- }
- }
-
- private void collectFreeChunks(List<SyncChunkStack> l) {
- collectFreeFragmentChunks(l);
- collectFreeHugeChunks(l);
-// collectFreeBigChunks(l);
- collectFreeTinyChunks(l);
- }
- private void collectFreeFragmentChunks(List<SyncChunkStack> l) {
- if (this.fragmentList.size() == 0) return;
- SyncChunkStack result = new SyncChunkStack();
- for (Fragment f: this.fragmentList) {
- int offset;
- int diff;
- do {
- offset = f.getFreeIndex();
- diff = f.getSize() - offset;
- } while (diff >= Chunk.MIN_CHUNK_SIZE && !f.allocate(offset, offset+diff));
- if (diff < Chunk.MIN_CHUNK_SIZE) {
- if (diff > 0) {
- logger.debug("Lost memory of size {}", diff);
- }
- // fragment is too small to turn into a chunk
- // TODO we need to make sure this never happens
- // by keeping sizes rounded. I think I did this
- // by introducing MIN_CHUNK_SIZE and by rounding
- // the size of huge allocations.
- continue;
- }
- long chunkAddr = f.getMemoryAddress()+offset;
- Chunk.setSize(chunkAddr, diff);
- result.offer(chunkAddr);
- }
- // All the fragments have been turned in to chunks so now clear them
- // The compaction will create new fragments.
- this.fragmentList.clear();
- if (!result.isEmpty()) {
- l.add(result);
- }
- }
- private void collectFreeTinyChunks(List<SyncChunkStack> l) {
- for (int i=0; i < this.tinyFreeLists.length(); i++) {
- SyncChunkStack cl = this.tinyFreeLists.get(i);
- if (cl != null) {
- long head = cl.clear();
- if (head != 0L) {
- l.add(new SyncChunkStack(head));
- }
- }
- }
- }
-// private void collectFreeBigChunks(List<ConcurrentChunkStack> l) {
-// for (int i=0; i < this.bigFreeLists.length(); i++) {
-// ConcurrentChunkStack cl = this.bigFreeLists.get(i);
-// if (cl != null) {
-// long head = cl.clear();
-// if (head != 0L) {
-// l.add(new ConcurrentChunkStack(head));
-// }
-// }
-// }
-// }
- public void collectFreeHugeChunks(List<SyncChunkStack> l) {
- Chunk c = this.hugeChunkSet.pollFirst();
- SyncChunkStack result = null;
- while (c != null) {
- if (result == null) {
- result = new SyncChunkStack();
- l.add(result);
- }
- result.offer(c.getMemoryAddress());
- c = this.hugeChunkSet.pollFirst();
- }
- }
-
- private Chunk allocateFromFragment(final int fragIdx, final int chunkSize, ChunkType chunkType) {
- if (fragIdx >= this.fragmentList.size()) return null;
- final Fragment fragment;
- try {
- fragment = this.fragmentList.get(fragIdx);
- } catch (IndexOutOfBoundsException ignore) {
- // A concurrent compaction can cause this.
- return null;
- }
- boolean retryFragment;
- do {
- retryFragment = false;
- int oldOffset = fragment.getFreeIndex();
- int fragmentSize = fragment.getSize();
- int fragmentFreeSize = fragmentSize - oldOffset;
- if (fragmentFreeSize >= chunkSize) {
- // this fragment has room
- // Try to allocate up to BATCH_SIZE more chunks from it
- int allocSize = chunkSize * BATCH_SIZE;
- if (allocSize > fragmentFreeSize) {
- allocSize = (fragmentFreeSize / chunkSize) * chunkSize;
- }
- int newOffset = oldOffset + allocSize;
- int extraSize = fragmentSize - newOffset;
- if (extraSize < Chunk.MIN_CHUNK_SIZE) {
- // include these last few bytes of the fragment in the allocation.
- // If we don't then they will be lost forever.
- // The extraSize bytes only apply to the first chunk we allocate (not the batch ones).
- newOffset += extraSize;
- } else {
- extraSize = 0;
- }
- if (fragment.allocate(oldOffset, newOffset)) {
- // We did the allocate!
- this.lastFragmentAllocation.set(fragIdx);
- Chunk result = chunkFactory.newChunk(fragment.getMemoryAddress()+oldOffset, chunkSize+extraSize, chunkType);
- allocSize -= chunkSize+extraSize;
- oldOffset += extraSize;
- while (allocSize > 0) {
- oldOffset += chunkSize;
- // we add the batch ones immediately to the freelist
- result.readyForFree();
- free(result.getMemoryAddress(), false);
- result = chunkFactory.newChunk(fragment.getMemoryAddress()+oldOffset, chunkSize, chunkType);
- allocSize -= chunkSize;
- }
-
- if(validateMemoryWithFill) {
- result.validateFill();
- }
-
- return result;
- } else {
- // TODO OFFHEAP: if batch allocations are disabled should we not call basicAllocate here?
- // Since we know another thread did a concurrent alloc
- // that possibly did a batch check the free list again.
- Chunk result = basicAllocate(chunkSize, false, chunkType);
- if (result != null) {
- return result;
- }
- retryFragment = true;
- }
- }
- } while (retryFragment);
- return null; // did not find enough free space in this fragment
- }
-
- private int round(int multiple, int value) {
- return (int) ((((long)value + (multiple-1)) / multiple) * multiple);
- }
- private Chunk allocateTiny(int size, boolean useFragments, ChunkType chunkType) {
- return basicAllocate(getNearestTinyMultiple(size), TINY_MULTIPLE, 0, this.tinyFreeLists, useFragments, chunkType);
- }
-// private Chunk allocateBig(int size, boolean useFragments) {
-// return basicAllocate(getNearestBigMultiple(size), BIG_MULTIPLE, BIG_OFFSET, this.bigFreeLists, useFragments);
-// }
- private Chunk basicAllocate(int idx, int multiple, int offset, AtomicReferenceArray<SyncChunkStack> freeLists, boolean useFragments, ChunkType chunkType) {
- SyncChunkStack clq = freeLists.get(idx);
- if (clq != null) {
- long memAddr = clq.poll();
- if (memAddr != 0) {
- Chunk result = SimpleMemoryAllocatorImpl.this.chunkFactory.newChunk(memAddr, chunkType);
-
- // Data integrity check.
- if(validateMemoryWithFill) {
- result.validateFill();
- }
-
- result.readyForAllocation(chunkType);
- return result;
- }
- }
- if (useFragments) {
- return allocateFromFragments(((idx+1)*multiple)+offset, chunkType);
- } else {
- return null;
- }
- }
- private Chunk allocateHuge(int size, boolean useFragments, ChunkType chunkType) {
- // sizeHolder is a fake Chunk used to search our sorted hugeChunkSet.
- Chunk sizeHolder = new FakeChunk(size);
- NavigableSet<Chunk> ts = this.hugeChunkSet.tailSet(sizeHolder);
- Chunk result = ts.pollFirst();
- if (result != null) {
- if (result.getSize() - (HUGE_MULTIPLE - Chunk.OFF_HEAP_HEADER_SIZE) < size) {
- // close enough to the requested size; just return it.
-
- // Data integrity check.
- if(validateMemoryWithFill) {
- result.validateFill();
- }
- if (chunkType.getSrcType() != Chunk.getSrcType(result.getMemoryAddress())) {
- // The java wrapper class that was cached in the huge chunk list is the wrong type.
- // So allocate a new one and garbage collect the old one.
- result = SimpleMemoryAllocatorImpl.this.chunkFactory.newChunk(result.getMemoryAddress(), chunkType);
- }
- result.readyForAllocation(chunkType);
- return result;
- } else {
- this.hugeChunkSet.add(result);
- }
- }
- if (useFragments) {
- // We round it up to the next multiple of TINY_MULTIPLE to make
- // sure we always have chunks allocated on an 8 byte boundary.
- return allocateFromFragments(round(TINY_MULTIPLE, size), chunkType);
- } else {
- return null;
- }
- }
-
- @SuppressWarnings("synthetic-access")
- public void free(long addr) {
- free(addr, true);
- }
-
- private void free(long addr, boolean updateStats) {
- int cSize = Chunk.getSize(addr);
- if (updateStats) {
- stats.incObjects(-1);
- this.allocatedSize.addAndGet(-cSize);
- stats.incUsedMemory(-cSize);
- stats.incFreeMemory(cSize);
- notifyListeners();
- }
- if (cSize <= MAX_TINY) {
- freeTiny(addr, cSize);
- } else {
- freeHuge(addr, cSize);
- }
- }
- private void freeTiny(long addr, int cSize) {
- basicFree(addr, getNearestTinyMultiple(cSize), this.tinyFreeLists);
- }
- private void basicFree(long addr, int idx, AtomicReferenceArray<SyncChunkStack> freeLists) {
- SyncChunkStack clq = freeLists.get(idx);
- if (clq != null) {
- clq.offer(addr);
- } else {
- clq = new SyncChunkStack();
- clq.offer(addr);
- if (!freeLists.compareAndSet(idx, null, clq)) {
- clq = freeLists.get(idx);
- clq.offer(addr);
- }
- }
-
- }
- private void freeHuge(long addr, int cSize) {
- this.hugeChunkSet.add(SimpleMemoryAllocatorImpl.this.chunkFactory.newChunk(addr)); // TODO make this a collection of longs
- }
- }
-
static void validateAddress(long addr) {
validateAddressAndSize(addr, -1);
}
[14/20] incubator-geode git commit: move Fragment from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move Fragment 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/082b09af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/082b09af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/082b09af
Branch: refs/heads/feature/GEODE-580
Commit: 082b09afc272c99a79241eadd3fccd8b1c6e134d
Parents: ff64d0b
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:07:04 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:07:04 2015 -0800
----------------------------------------------------------------------
.../gemfire/internal/offheap/Fragment.java | 125 +++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 107 ----------------
2 files changed, 125 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/082b09af/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Fragment.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Fragment.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Fragment.java
new file mode 100644
index 0000000..bd05ddb
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Fragment.java
@@ -0,0 +1,125 @@
+/*
+ * 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.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+
+/**
+ * A fragment is a block of memory that can have chunks allocated from it.
+ * The allocations are always from the front so the free memory is always
+ * at the end. The freeIdx keeps track of the first byte of free memory in
+ * the fragment.
+ * The base memory address and the total size of a fragment never change.
+ * During compaction fragments go away and are recreated.
+ *
+ * @author darrel
+ *
+ */
+public class Fragment implements MemoryBlock {
+ private static final byte FILL_BYTE = Chunk.FILL_BYTE;
+ private final long baseAddr;
+ private final int size;
+ @SuppressWarnings("unused")
+ private volatile int freeIdx;
+ private static AtomicIntegerFieldUpdater<Fragment> freeIdxUpdater = AtomicIntegerFieldUpdater.newUpdater(Fragment.class, "freeIdx");
+
+ public Fragment(long addr, int size) {
+ SimpleMemoryAllocatorImpl.validateAddress(addr);
+ this.baseAddr = addr;
+ this.size = size;
+ freeIdxUpdater.set(this, 0);
+ }
+
+ public int freeSpace() {
+ return getSize() - getFreeIndex();
+ }
+
+ public boolean allocate(int oldOffset, int newOffset) {
+ return freeIdxUpdater.compareAndSet(this, oldOffset, newOffset);
+ }
+
+ public int getFreeIndex() {
+ return freeIdxUpdater.get(this);
+ }
+
+ public int getSize() {
+ return this.size;
+ }
+
+ public long getMemoryAddress() {
+ return this.baseAddr;
+ }
+
+ @Override
+ public State getState() {
+ return State.UNUSED;
+ }
+
+ @Override
+ public MemoryBlock getNextBlock() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getBlockSize() {
+ return freeSpace();
+ }
+
+ @Override
+ public int getSlabId() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int getFreeListId() {
+ return -1;
+ }
+
+ @Override
+ public int getRefCount() {
+ return 0;
+ }
+
+ @Override
+ public String getDataType() {
+ return "N/A";
+ }
+
+ @Override
+ public boolean isSerialized() {
+ return false;
+ }
+
+ @Override
+ public boolean isCompressed() {
+ return false;
+ }
+
+ @Override
+ public Object getDataValue() {
+ return null;
+ }
+
+ public void fill() {
+ UnsafeMemoryChunk.fill(this.baseAddr, this.size, FILL_BYTE);
+ }
+
+ @Override
+ public ChunkType getChunkType() {
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/082b09af/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 40a01b5..a50c823 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
@@ -38,7 +38,6 @@ import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;
@@ -1395,112 +1394,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- /**
- * A fragment is a block of memory that can have chunks allocated from it.
- * The allocations are always from the front so the free memory is always
- * at the end. The freeIdx keeps track of the first byte of free memory in
- * the fragment.
- * The base memory address and the total size of a fragment never change.
- * During compaction fragments go away and are recreated.
- *
- * @author darrel
- *
- */
- public static class Fragment implements MemoryBlock {
- private static long FILL_PATTERN = Chunk.FILL_PATTERN;
- private static byte FILL_BYTE = Chunk.FILL_BYTE;
- private final long baseAddr;
- private final int size;
- private volatile int freeIdx;
- private static AtomicIntegerFieldUpdater<Fragment> freeIdxUpdater = AtomicIntegerFieldUpdater.newUpdater(Fragment.class, "freeIdx");
-
- public Fragment(long addr, int size) {
- validateAddress(addr);
- this.baseAddr = addr;
- this.size = size;
- freeIdxUpdater.set(this, 0);
- }
-
- public int freeSpace() {
- return getSize() - getFreeIndex();
- }
-
- public boolean allocate(int oldOffset, int newOffset) {
- return freeIdxUpdater.compareAndSet(this, oldOffset, newOffset);
- }
-
- public int getFreeIndex() {
- return freeIdxUpdater.get(this);
- }
-
- public int getSize() {
- return this.size;
- }
-
- public long getMemoryAddress() {
- return this.baseAddr;
- }
-
- @Override
- public State getState() {
- return State.UNUSED;
- }
-
- @Override
- public MemoryBlock getNextBlock() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getBlockSize() {
- return freeSpace();
- }
-
- @Override
- public int getSlabId() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int getFreeListId() {
- return -1;
- }
-
- @Override
- public int getRefCount() {
- return 0;
- }
-
- @Override
- public String getDataType() {
- return "N/A";
- }
-
- @Override
- public boolean isSerialized() {
- return false;
- }
-
- @Override
- public boolean isCompressed() {
- return false;
- }
-
- @Override
- public Object getDataValue() {
- return null;
- }
-
- public void fill() {
- UnsafeMemoryChunk.fill(this.baseAddr, this.size, FILL_BYTE);
- }
-
- @Override
- public ChunkType getChunkType() {
- return null;
- }
- }
-
private void printSlabs() {
for (int i =0; i < this.slabs.length; i++) {
logger.info(slabs[i]);
[19/20] incubator-geode git commit: move SyncChunkStack from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move SyncChunkStack 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/18f5e9d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/18f5e9d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/18f5e9d5
Branch: refs/heads/feature/GEODE-580
Commit: 18f5e9d53725609a2b94a4335a2403681120ae2f
Parents: 27b2aeb
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:58:04 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:58:04 2015 -0800
----------------------------------------------------------------------
.../offheap/SimpleMemoryAllocatorImpl.java | 101 +-------------
.../internal/offheap/SyncChunkStack.java | 130 +++++++++++++++++++
2 files changed, 131 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/18f5e9d5/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 6303f5b..0cb7068 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
@@ -1223,105 +1223,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public static class SyncChunkStack {
- // Ok to read without sync but must be synced on write
- private volatile long topAddr;
-
- public SyncChunkStack(long addr) {
- if (addr != 0L) validateAddress(addr);
- this.topAddr = addr;
- }
- public SyncChunkStack() {
- this.topAddr = 0L;
- }
- public boolean isEmpty() {
- return this.topAddr == 0L;
- }
- public void offer(long e) {
- assert e != 0;
- validateAddress(e);
- synchronized (this) {
- Chunk.setNext(e, this.topAddr);
- this.topAddr = e;
- }
- }
- public long poll() {
- long result;
- synchronized (this) {
- result = this.topAddr;
- if (result != 0L) {
- this.topAddr = Chunk.getNext(result);
- }
- }
- return result;
- }
- /**
- * Removes all the Chunks from this stack
- * and returns the address of the first chunk.
- * The caller owns all the Chunks after this call.
- */
- public long clear() {
- long result;
- synchronized (this) {
- result = this.topAddr;
- if (result != 0L) {
- this.topAddr = 0L;
- }
- }
- return result;
- }
- public void logSizes(LogWriter lw, String msg) {
- long headAddr = this.topAddr;
- long addr;
- boolean concurrentModDetected;
- do {
- concurrentModDetected = false;
- addr = headAddr;
- while (addr != 0L) {
- int curSize = Chunk.getSize(addr);
- addr = Chunk.getNext(addr);
- long curHead = this.topAddr;
- if (curHead != headAddr) {
- headAddr = curHead;
- concurrentModDetected = true;
- // Someone added or removed from the stack.
- // So we break out of the inner loop and start
- // again at the new head.
- break;
- }
- // TODO construct a single log msg
- // that gets reset on the concurrent mad.
- lw.info(msg + curSize);
- }
- } while (concurrentModDetected);
- }
- public long computeTotalSize() {
- long result;
- long headAddr = this.topAddr;
- long addr;
- boolean concurrentModDetected;
- do {
- concurrentModDetected = false;
- result = 0;
- addr = headAddr;
- while (addr != 0L) {
- result += Chunk.getSize(addr);
- addr = Chunk.getNext(addr);
- long curHead = this.topAddr;
- if (curHead != headAddr) {
- headAddr = curHead;
- concurrentModDetected = true;
- // Someone added or removed from the stack.
- // So we break out of the inner loop and start
- // again at the new head.
- break;
- }
- }
- } while (concurrentModDetected);
- return result;
- }
- }
-
static void validateAddress(long addr) {
validateAddressAndSize(addr, -1);
}
@@ -1522,7 +1423,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
AtomicReferenceArray<SyncChunkStack> chunkStacks = this.freeList.tinyFreeLists;
for (int i = 0; i < chunkStacks.length(); i++) {
if (chunkStacks.get(i) == null) continue;
- long addr = chunkStacks.get(i).topAddr;
+ long addr = chunkStacks.get(i).getTopAddress();
final int size = Chunk.getSize(addr);
final long address = addr;
final int freeListId = i;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/18f5e9d5/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java
new file mode 100644
index 0000000..a615af0
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SyncChunkStack.java
@@ -0,0 +1,130 @@
+/*
+ * 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 com.gemstone.gemfire.LogWriter;
+
+/**
+ * A "stack" of "chunk" instances. The chunks are not kept
+ * in java object form but instead each "chunk" is just an
+ * off-heap address.
+ * This class is used for each "tiny" free-list of the off-heap memory allocator.
+ */
+public class SyncChunkStack {
+ // Ok to read without sync but must be synced on write
+ private volatile long topAddr;
+
+ public SyncChunkStack(long addr) {
+ if (addr != 0L) SimpleMemoryAllocatorImpl.validateAddress(addr);
+ this.topAddr = addr;
+ }
+ public SyncChunkStack() {
+ this.topAddr = 0L;
+ }
+ public boolean isEmpty() {
+ return this.topAddr == 0L;
+ }
+ public void offer(long e) {
+ assert e != 0;
+ SimpleMemoryAllocatorImpl.validateAddress(e);
+ synchronized (this) {
+ Chunk.setNext(e, this.topAddr);
+ this.topAddr = e;
+ }
+ }
+ public long poll() {
+ long result;
+ synchronized (this) {
+ result = this.topAddr;
+ if (result != 0L) {
+ this.topAddr = Chunk.getNext(result);
+ }
+ }
+ return result;
+ }
+ /**
+ * Returns the address of the "top" item in this stack.
+ */
+ public long getTopAddress() {
+ return this.topAddr;
+ }
+ /**
+ * Removes all the Chunks from this stack
+ * and returns the address of the first chunk.
+ * The caller owns all the Chunks after this call.
+ */
+ public long clear() {
+ long result;
+ synchronized (this) {
+ result = this.topAddr;
+ if (result != 0L) {
+ this.topAddr = 0L;
+ }
+ }
+ return result;
+ }
+ public void logSizes(LogWriter lw, String msg) {
+ long headAddr = this.topAddr;
+ long addr;
+ boolean concurrentModDetected;
+ do {
+ concurrentModDetected = false;
+ addr = headAddr;
+ while (addr != 0L) {
+ int curSize = Chunk.getSize(addr);
+ addr = Chunk.getNext(addr);
+ long curHead = this.topAddr;
+ if (curHead != headAddr) {
+ headAddr = curHead;
+ concurrentModDetected = true;
+ // Someone added or removed from the stack.
+ // So we break out of the inner loop and start
+ // again at the new head.
+ break;
+ }
+ // TODO construct a single log msg
+ // that gets reset on the concurrent mad.
+ lw.info(msg + curSize);
+ }
+ } while (concurrentModDetected);
+ }
+ public long computeTotalSize() {
+ long result;
+ long headAddr = this.topAddr;
+ long addr;
+ boolean concurrentModDetected;
+ do {
+ concurrentModDetected = false;
+ result = 0;
+ addr = headAddr;
+ while (addr != 0L) {
+ result += Chunk.getSize(addr);
+ addr = Chunk.getNext(addr);
+ long curHead = this.topAddr;
+ if (curHead != headAddr) {
+ headAddr = curHead;
+ concurrentModDetected = true;
+ // Someone added or removed from the stack.
+ // So we break out of the inner loop and start
+ // again at the new head.
+ break;
+ }
+ }
+ } while (concurrentModDetected);
+ return result;
+ }
+}
\ No newline at end of file
[05/20] incubator-geode git commit: move Chunk out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move Chunk out of 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/419b017b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/419b017b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/419b017b
Branch: refs/heads/feature/GEODE-580
Commit: 419b017ba48286608f791eb7b9bee22a9e58cd41
Parents: d4991d0
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:33:45 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:33:45 2015 -0800
----------------------------------------------------------------------
.../internal/GetOperationContextImpl.java | 2 +-
.../query/internal/index/AbstractIndex.java | 2 +-
.../query/internal/index/DummyQRegion.java | 2 +-
.../cache/query/internal/index/HashIndex.java | 2 +-
.../internal/cache/AbstractRegionEntry.java | 3 +-
.../internal/cache/AbstractRegionMap.java | 2 +-
.../cache/BytesAndBitsForCompactor.java | 2 +-
.../gemfire/internal/cache/DiskEntry.java | 2 +-
.../internal/cache/DistributedRegion.java | 2 +-
.../gemfire/internal/cache/EntryEventImpl.java | 3 +-
.../gemfire/internal/cache/LocalRegion.java | 2 +-
.../internal/cache/PartitionedRegion.java | 2 +-
.../internal/cache/tier/sockets/Part.java | 2 +-
.../cache/wan/GatewaySenderEventImpl.java | 2 +-
.../gemfire/internal/offheap/Chunk.java | 794 +++++++++++++++++++
.../offheap/OffHeapCachedDeserializable.java | 1 -
.../offheap/OffHeapRegionEntryHelper.java | 1 -
.../offheap/SimpleMemoryAllocatorImpl.java | 778 +-----------------
.../internal/tcp/ByteBufferInputStream.java | 2 +-
.../tcp/ImmutableByteBufferInputStream.java | 2 +-
.../gemfire/internal/util/BlobHelper.java | 2 +-
.../gemfire/pdx/internal/PdxInputStream.java | 2 +-
.../cache/ChunkValueWrapperJUnitTest.java | 2 +-
.../cache/OldValueImporterTestBase.java | 2 +-
.../offheap/FreeListOffHeapRegionJUnitTest.java | 2 +-
.../internal/offheap/OffHeapRegionBase.java | 1 -
.../offheap/OffHeapValidationJUnitTest.java | 1 -
.../OffHeapWriteObjectAsByteArrayJUnitTest.java | 1 -
.../OldFreeListOffHeapRegionJUnitTest.java | 2 +-
...mpleMemoryAllocatorFillPatternJUnitTest.java | 2 -
.../offheap/SimpleMemoryAllocatorJUnitTest.java | 9 +-
.../OffHeapByteBufferByteSourceJUnitTest.java | 2 +-
.../gemfire/pdx/OffHeapByteSourceJUnitTest.java | 2 +-
33 files changed, 830 insertions(+), 808 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImpl.java
index fd2a944..d973cd7 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImpl.java
@@ -18,8 +18,8 @@ package com.gemstone.gemfire.cache.operations.internal;
import com.gemstone.gemfire.SerializationException;
import com.gemstone.gemfire.cache.operations.GetOperationContext;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.Releasable;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
index 7ddacde..b65dc7e 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/AbstractIndex.java
@@ -74,7 +74,7 @@ import com.gemstone.gemfire.internal.cache.RegionEntry;
import com.gemstone.gemfire.internal.cache.persistence.query.CloseableIterator;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.gemstone.gemfire.pdx.PdxInstance;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/DummyQRegion.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/DummyQRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/DummyQRegion.java
index 1e1da4b..3577e38 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/DummyQRegion.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/DummyQRegion.java
@@ -41,7 +41,7 @@ import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.RegionEntry;
import com.gemstone.gemfire.internal.cache.RegionEntryContext;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/HashIndex.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/HashIndex.java b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/HashIndex.java
index dd9cffd..911fd6e 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/HashIndex.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/HashIndex.java
@@ -79,7 +79,7 @@ import com.gemstone.gemfire.internal.cache.Token;
import com.gemstone.gemfire.internal.cache.persistence.query.CloseableIterator;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.gemstone.gemfire.pdx.internal.PdxString;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
index f250bd2..ab83cf4 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Arrays;
import org.apache.logging.log4j.Logger;
+
import static com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier.ABSTRACT_REGION_ENTRY_FILL_IN_VALUE;
import static com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier.ABSTRACT_REGION_ENTRY_PREPARE_VALUE_FOR_CACHE;
@@ -60,11 +61,11 @@ import com.gemstone.gemfire.internal.lang.StringUtils;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.MemoryAllocator;
import com.gemstone.gemfire.internal.offheap.OffHeapCachedDeserializable;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunkType;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
index 80b55d5..5a2a89e 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java
@@ -74,10 +74,10 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.OffHeapRegionEntryHelper;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/BytesAndBitsForCompactor.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/BytesAndBitsForCompactor.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/BytesAndBitsForCompactor.java
index 8e46605..3a3b5a1 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/BytesAndBitsForCompactor.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/BytesAndBitsForCompactor.java
@@ -16,7 +16,7 @@
*/
package com.gemstone.gemfire.internal.cache;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskEntry.java
index 3973556..b64b6a0 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DiskEntry.java
@@ -40,11 +40,11 @@ import com.gemstone.gemfire.internal.cache.versions.VersionStamp;
import com.gemstone.gemfire.internal.cache.versions.VersionTag;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.Releasable;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
index 7295ad9..0e6bc4a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/DistributedRegion.java
@@ -121,8 +121,8 @@ import com.gemstone.gemfire.internal.cache.wan.parallel.ConcurrentParallelGatewa
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.gemstone.gemfire.internal.sequencelog.RegionLogger;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
index 0786a69..fe9a4ac 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
@@ -22,6 +22,7 @@ import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.IOException;
+
import org.apache.logging.log4j.Logger;
import com.gemstone.gemfire.CopyHelper;
@@ -72,11 +73,11 @@ import com.gemstone.gemfire.internal.lang.StringUtils;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.OffHeapRegionEntryHelper;
import com.gemstone.gemfire.internal.offheap.Releasable;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
index 1900297..9d88834 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
@@ -203,9 +203,9 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PartitionedRegion.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PartitionedRegion.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PartitionedRegion.java
index 29137fc..09262cc 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PartitionedRegion.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PartitionedRegion.java
@@ -252,7 +252,7 @@ import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.LoggingThreadGroup;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
import com.gemstone.gemfire.internal.sequencelog.RegionLogger;
import com.gemstone.gemfire.internal.util.TransformUtils;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
index 6af005e..0bbcc6b 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
@@ -18,7 +18,7 @@ package com.gemstone.gemfire.internal.cache.tier.sockets;
import com.gemstone.gemfire.internal.*;
import com.gemstone.gemfire.internal.cache.CachedDeserializable;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
index c4f0c87..fc234e3 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
@@ -50,10 +50,10 @@ import com.gemstone.gemfire.internal.cache.WrappedCallbackArgument;
import com.gemstone.gemfire.internal.cache.lru.Sizeable;
import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerHelper;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.Releasable;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkWithHeapForm;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
new file mode 100644
index 0000000..714ac6f
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
@@ -0,0 +1,794 @@
+/*
+ * 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.DataOutput;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.internal.DSCODE;
+import com.gemstone.gemfire.internal.HeapDataOutputStream;
+import com.gemstone.gemfire.internal.InternalDataSerializer;
+import com.gemstone.gemfire.internal.cache.EntryEventImpl;
+import com.gemstone.gemfire.internal.cache.RegionEntry;
+import com.gemstone.gemfire.internal.cache.RegionEntryContext;
+import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
+import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
+
+/**
+ * Note: this class has a natural ordering that is inconsistent with equals.
+ * Instances of this class should have a short lifetime. We do not store references
+ * to it in the cache. Instead the memoryAddress is stored in a primitive field in
+ * the cache and if used it will then, if needed, create an instance of this class.
+ */
+ public abstract class Chunk extends OffHeapCachedDeserializable implements Comparable<Chunk>, MemoryBlock {
+ /**
+ * The unsafe memory address of the first byte of this chunk
+ */
+ private final long memoryAddress;
+
+ /**
+ * The useCount, chunkSize, dataSizeDelta, isSerialized, and isCompressed
+ * are all stored in off heap memory in a HEADER. This saves heap memory
+ * by using off heap.
+ */
+ public final static int OFF_HEAP_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;
+ /**
+ * int field.
+ * The number of bytes in this chunk.
+ */
+ private final static int CHUNK_SIZE_OFFSET = 0;
+ /**
+ * Volatile int field
+ * The upper two bits are used for the isSerialized
+ * and isCompressed flags.
+ * The next three bits are used to encode the SRC_TYPE enum.
+ * The lower 3 bits of the most significant byte contains a magic number to help us detect
+ * if we are changing the ref count of an object that has been released.
+ * The next byte contains the dataSizeDelta.
+ * The number of bytes of logical data in this chunk.
+ * Since the number of bytes of logical data is always <= chunkSize
+ * and since chunkSize never changes, we have dataSize be
+ * a delta whose max value would be HUGE_MULTIPLE-1.
+ * The lower two bytes contains the use count.
+ */
+ private final static int REF_COUNT_OFFSET = 4;
+ /**
+ * The upper two bits are used for the isSerialized
+ * and isCompressed flags.
+ */
+ private final static int IS_SERIALIZED_BIT = 0x80000000;
+ private final static int IS_COMPRESSED_BIT = 0x40000000;
+ private final static int SRC_TYPE_MASK = 0x38000000;
+ private final static int SRC_TYPE_SHIFT = 16/*refCount*/+8/*dataSize*/+3/*magicSize*/;
+ private final static int MAGIC_MASK = 0x07000000;
+ private final static int MAGIC_NUMBER = 0x05000000;
+ private final static int DATA_SIZE_DELTA_MASK = 0x00ff0000;
+ private final static int DATA_SIZE_SHIFT = 16;
+ private final static int REF_COUNT_MASK = 0x0000ffff;
+ private final static int MAX_REF_COUNT = 0xFFFF;
+ final static long FILL_PATTERN = 0x3c3c3c3c3c3c3c3cL;
+ final static byte FILL_BYTE = 0x3c;
+
+ // The 8 bits reserved for SRC_TYPE are basically no longer used.
+ // So we could free up these 8 bits for some other use or we could
+ // keep them for future extensions.
+ // If we ever want to allocate other "types" into a chunk of off-heap
+ // memory then the SRC_TYPE would be the way to go.
+ // For example we may want to allocate the memory for the off-heap
+ // RegionEntry in off-heap memory without it being of type GFE.
+ // When it is of type GFE then it either needs to be the bytes
+ // of a byte array or it needs to be a serialized java object.
+ // For the RegionEntry we may want all the primitive fields of
+ // the entry at certain offsets in the off-heap memory so we could
+ // access them directly in native byte format (i.e. no serialization).
+ // Note that for every SRC_TYPE we should have a ChunkType subclass.
+ public final static int SRC_TYPE_UNUSED0 = 0 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_UNUSED1 = 1 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_UNUSED2 = 2 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_UNUSED3 = 3 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_GFE = 4 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_UNUSED5 = 5 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_UNUSED6 = 6 << SRC_TYPE_SHIFT;
+ public final static int SRC_TYPE_UNUSED7 = 7 << SRC_TYPE_SHIFT;
+
+ protected Chunk(long memoryAddress, int chunkSize, ChunkType chunkType) {
+ SimpleMemoryAllocatorImpl.validateAddressAndSize(memoryAddress, chunkSize);
+ this.memoryAddress = memoryAddress;
+ setSize(chunkSize);
+ UnsafeMemoryChunk.writeAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET, MAGIC_NUMBER|chunkType.getSrcType());
+ }
+ public void readyForFree() {
+ UnsafeMemoryChunk.writeAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET, 0);
+ }
+ public void readyForAllocation(ChunkType chunkType) {
+ if (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET, 0, MAGIC_NUMBER|chunkType.getSrcType())) {
+ throw new IllegalStateException("Expected 0 but found " + Integer.toHexString(UnsafeMemoryChunk.readAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET)));
+ }
+ }
+ /**
+ * Should only be used by FakeChunk subclass
+ */
+ protected Chunk() {
+ this.memoryAddress = 0L;
+ }
+
+ /**
+ * Used to create a Chunk given an existing, already allocated,
+ * memoryAddress. The off heap header has already been initialized.
+ */
+ protected Chunk(long memoryAddress) {
+ SimpleMemoryAllocatorImpl.validateAddress(memoryAddress);
+ this.memoryAddress = memoryAddress;
+ }
+
+ protected Chunk(Chunk chunk) {
+ this.memoryAddress = chunk.memoryAddress;
+ }
+
+ /**
+ * Throw an exception if this chunk is not allocated
+ */
+ public void checkIsAllocated() {
+ int originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
+ if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
+ }
+ }
+
+ public void incSize(int inc) {
+ setSize(getSize()+inc);
+ }
+
+ protected void beforeReturningToAllocator() {
+
+ }
+
+ @Override
+ public int getSize() {
+ return getSize(this.memoryAddress);
+ }
+
+ public void setSize(int size) {
+ setSize(this.memoryAddress, size);
+ }
+
+ public long getMemoryAddress() {
+ return this.memoryAddress;
+ }
+
+ public int getDataSize() {
+ /*int dataSizeDelta = UnsafeMemoryChunk.readAbsoluteInt(this.memoryAddress+REF_COUNT_OFFSET);
+ dataSizeDelta &= DATA_SIZE_DELTA_MASK;
+ dataSizeDelta >>= DATA_SIZE_SHIFT;
+ return getSize() - dataSizeDelta;*/
+ return getDataSize(this.memoryAddress);
+ }
+
+ protected static int getDataSize(long memoryAdress) {
+ int dataSizeDelta = UnsafeMemoryChunk.readAbsoluteInt(memoryAdress+REF_COUNT_OFFSET);
+ dataSizeDelta &= DATA_SIZE_DELTA_MASK;
+ dataSizeDelta >>= DATA_SIZE_SHIFT;
+ return getSize(memoryAdress) - dataSizeDelta;
+ }
+
+ protected long getBaseDataAddress() {
+ return this.memoryAddress+OFF_HEAP_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.
+ */
+ @Unretained
+ public ByteBuffer createDirectByteBuffer() {
+ return basicCreateDirectByteBuffer(getBaseDataAddress(), getDataSize());
+ }
+ @Override
+ public void sendTo(DataOutput out) throws IOException {
+ if (!this.isCompressed() && out instanceof HeapDataOutputStream) {
+ ByteBuffer bb = createDirectByteBuffer();
+ if (bb != null) {
+ HeapDataOutputStream hdos = (HeapDataOutputStream) out;
+ if (this.isSerialized()) {
+ hdos.write(bb);
+ } else {
+ hdos.writeByte(DSCODE.BYTE_ARRAY);
+ InternalDataSerializer.writeArrayLength(bb.remaining(), hdos);
+ hdos.write(bb);
+ }
+ return;
+ }
+ }
+ super.sendTo(out);
+ }
+
+ @Override
+ public void sendAsByteArray(DataOutput out) throws IOException {
+ if (!isCompressed() && out instanceof HeapDataOutputStream) {
+ ByteBuffer bb = createDirectByteBuffer();
+ if (bb != null) {
+ HeapDataOutputStream hdos = (HeapDataOutputStream) out;
+ InternalDataSerializer.writeArrayLength(bb.remaining(), hdos);
+ hdos.write(bb);
+ return;
+ }
+ }
+ super.sendAsByteArray(out);
+ }
+
+ private static volatile Class dbbClass = null;
+ private static volatile Constructor dbbCtor = null;
+ private static volatile boolean dbbCreateFailed = false;
+
+ /**
+ * @return the created direct byte buffer or null if it could not be created.
+ */
+ private static ByteBuffer basicCreateDirectByteBuffer(long baseDataAddress, int dataSize) {
+ if (dbbCreateFailed) {
+ return null;
+ }
+ Constructor ctor = dbbCtor;
+ if (ctor == null) {
+ Class c = dbbClass;
+ if (c == null) {
+ try {
+ c = Class.forName("java.nio.DirectByteBuffer");
+ } catch (ClassNotFoundException e) {
+ //throw new IllegalStateException("Could not find java.nio.DirectByteBuffer", e);
+ dbbCreateFailed = true;
+ dbbAddressFailed = true;
+ return null;
+ }
+ dbbClass = c;
+ }
+ try {
+ ctor = c.getDeclaredConstructor(long.class, int.class);
+ } catch (NoSuchMethodException | SecurityException e) {
+ //throw new IllegalStateException("Could not get constructor DirectByteBuffer(long, int)", e);
+ dbbClass = null;
+ dbbCreateFailed = true;
+ return null;
+ }
+ ctor.setAccessible(true);
+ dbbCtor = ctor;
+ }
+ try {
+ return (ByteBuffer)ctor.newInstance(baseDataAddress, dataSize);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ //throw new IllegalStateException("Could not create an instance using DirectByteBuffer(long, int)", e);
+ dbbClass = null;
+ dbbCtor = null;
+ dbbCreateFailed = true;
+ return null;
+ }
+ }
+ private static volatile Method dbbAddressMethod = null;
+ private static volatile boolean dbbAddressFailed = false;
+
+ /**
+ * Returns the address of the Unsafe memory for the first byte of a direct ByteBuffer.
+ * If the buffer is not direct or the address can not be obtained return 0.
+ */
+ public static long getDirectByteBufferAddress(ByteBuffer bb) {
+ if (!bb.isDirect()) {
+ return 0L;
+ }
+ if (dbbAddressFailed) {
+ return 0L;
+ }
+ Method m = dbbAddressMethod;
+ if (m == null) {
+ Class c = dbbClass;
+ if (c == null) {
+ try {
+ c = Class.forName("java.nio.DirectByteBuffer");
+ } catch (ClassNotFoundException e) {
+ //throw new IllegalStateException("Could not find java.nio.DirectByteBuffer", e);
+ dbbCreateFailed = true;
+ dbbAddressFailed = true;
+ return 0L;
+ }
+ dbbClass = c;
+ }
+ try {
+ m = c.getDeclaredMethod("address");
+ } catch (NoSuchMethodException | SecurityException e) {
+ //throw new IllegalStateException("Could not get method DirectByteBuffer.address()", e);
+ dbbClass = null;
+ dbbAddressFailed = true;
+ return 0L;
+ }
+ m.setAccessible(true);
+ dbbAddressMethod = m;
+ }
+ try {
+ return (Long)m.invoke(bb);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ //throw new IllegalStateException("Could not create an invoke DirectByteBuffer.address()", e);
+ dbbClass = null;
+ dbbAddressMethod = null;
+ dbbAddressFailed = true;
+ return 0L;
+ }
+ }
+ /**
+ * Returns an address that can be used with unsafe apis to access this chunks memory.
+ * @param offset the offset from this chunk's first byte of the byte the returned address should point to. Must be >= 0.
+ * @param size the number of bytes that will be read using the returned address. Assertion will use this to verify that all the memory accessed belongs to this chunk. Must be > 0.
+ * @return a memory address that can be used with unsafe apis
+ */
+ public long getUnsafeAddress(int offset, int size) {
+ assert offset >= 0 && offset + size <= getDataSize(): "Offset=" + offset + ",size=" + size + ",dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset + size must be <= " + getDataSize();
+ assert size > 0;
+ long result = getBaseDataAddress() + offset;
+ // validateAddressAndSizeWithinSlab(result, size);
+ return result;
+ }
+
+ @Override
+ public byte readByte(int offset) {
+ assert offset < getDataSize();
+ return UnsafeMemoryChunk.readAbsoluteByte(getBaseDataAddress() + offset);
+ }
+
+ @Override
+ public void writeByte(int offset, byte value) {
+ assert offset < getDataSize();
+ UnsafeMemoryChunk.writeAbsoluteByte(getBaseDataAddress() + offset, value);
+ }
+
+ @Override
+ public void readBytes(int offset, byte[] bytes) {
+ readBytes(offset, bytes, 0, bytes.length);
+ }
+
+ @Override
+ public void writeBytes(int offset, byte[] bytes) {
+ writeBytes(offset, bytes, 0, bytes.length);
+ }
+
+ public long getAddressForReading(int offset, int size) {
+ assert offset+size <= getDataSize();
+ return getBaseDataAddress() + offset;
+ }
+
+ @Override
+ public void readBytes(int offset, byte[] bytes, int bytesOffset, int size) {
+ assert offset+size <= getDataSize();
+ UnsafeMemoryChunk.readAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
+ }
+
+ @Override
+ public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) {
+ assert offset+size <= getDataSize();
+ SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(getBaseDataAddress() + offset, size);
+ UnsafeMemoryChunk.writeAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
+ }
+
+ @Override
+ public void release() {
+ release(this.memoryAddress, true);
+ }
+
+ @Override
+ public int compareTo(Chunk o) {
+ int result = Integer.signum(getSize() - o.getSize());
+ if (result == 0) {
+ // For the same sized chunks we really don't care about their order
+ // but we need compareTo to only return 0 if the two chunks are identical
+ result = Long.signum(getMemoryAddress() - o.getMemoryAddress());
+ }
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Chunk) {
+ return getMemoryAddress() == ((Chunk) o).getMemoryAddress();
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ long value = this.getMemoryAddress();
+ return (int)(value ^ (value >>> 32));
+ }
+
+ // OffHeapCachedDeserializable methods
+
+ @Override
+ public void setSerializedValue(byte[] value) {
+ writeBytes(0, value);
+ }
+
+ public byte[] getDecompressedBytes(RegionEntryContext context) {
+ byte[] result = getCompressedBytes();
+ long time = context.getCachePerfStats().startDecompression();
+ result = context.getCompressor().decompress(result);
+ context.getCachePerfStats().endDecompression(time);
+ return result;
+ }
+
+ /**
+ * Returns the raw possibly compressed bytes of this chunk
+ */
+ public byte[] getCompressedBytes() {
+ byte[] result = new byte[getDataSize()];
+ readBytes(0, result);
+ //debugLog("reading", true);
+ SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads();
+ return result;
+ }
+ protected byte[] getRawBytes() {
+ byte[] result = getCompressedBytes();
+ // TODO OFFHEAP: change the following to assert !isCompressed();
+ if (isCompressed()) {
+ throw new UnsupportedOperationException();
+ }
+ return result;
+ }
+
+ @Override
+ public byte[] getSerializedValue() {
+ byte [] result = getRawBytes();
+ if (!isSerialized()) {
+ // The object is a byte[]. So we need to make it look like a serialized byte[] in our result
+ result = EntryEventImpl.serialize(result);
+ }
+ return result;
+ }
+
+ @Override
+ public Object getDeserializedValue(Region r, RegionEntry re) {
+ if (isSerialized()) {
+ // TODO OFFHEAP: debug deserializeChunk
+ return EntryEventImpl.deserialize(getRawBytes());
+ //assert !isCompressed();
+ //return EntryEventImpl.deserializeChunk(this);
+ } else {
+ return getRawBytes();
+ }
+ }
+
+ /**
+ * We want this to include memory overhead so use getSize() instead of getDataSize().
+ */
+ @Override
+ public int getSizeInBytes() {
+ // Calling getSize includes the off heap header size.
+ // We do not add anything to this since the size of the reference belongs to the region entry size
+ // not the size of this object.
+ return getSize();
+ }
+
+ @Override
+ public int getValueSizeInBytes() {
+ return getDataSize();
+ }
+
+ @Override
+ public void copyBytes(int src, int dst, int size) {
+ throw new UnsupportedOperationException("Implement if used");
+// assert src+size <= getDataSize();
+// assert dst+size < getDataSize();
+// getSlabs()[this.getSlabIdx()].copyBytes(getBaseDataAddress()+src, getBaseDataAddress()+dst, size);
+ }
+
+ @Override
+ public boolean isSerialized() {
+ return (UnsafeMemoryChunk.readAbsoluteInt(this.memoryAddress+REF_COUNT_OFFSET) & IS_SERIALIZED_BIT) != 0;
+ }
+
+ @Override
+ public boolean isCompressed() {
+ return (UnsafeMemoryChunk.readAbsoluteInt(this.memoryAddress+REF_COUNT_OFFSET) & IS_COMPRESSED_BIT) != 0;
+ }
+
+ @Override
+ public boolean retain() {
+ return retain(this.memoryAddress);
+ }
+
+ @Override
+ public int getRefCount() {
+ return getRefCount(this.memoryAddress);
+ }
+
+ public static int getSize(long memAddr) {
+ SimpleMemoryAllocatorImpl.validateAddress(memAddr);
+ return UnsafeMemoryChunk.readAbsoluteInt(memAddr+CHUNK_SIZE_OFFSET);
+ }
+ public static void setSize(long memAddr, int size) {
+ SimpleMemoryAllocatorImpl.validateAddressAndSize(memAddr, size);
+ UnsafeMemoryChunk.writeAbsoluteInt(memAddr+CHUNK_SIZE_OFFSET, size);
+ }
+ public static long getNext(long memAddr) {
+ SimpleMemoryAllocatorImpl.validateAddress(memAddr);
+ return UnsafeMemoryChunk.readAbsoluteLong(memAddr+OFF_HEAP_HEADER_SIZE);
+ }
+ public static void setNext(long memAddr, long next) {
+ SimpleMemoryAllocatorImpl.validateAddress(memAddr);
+ UnsafeMemoryChunk.writeAbsoluteLong(memAddr+OFF_HEAP_HEADER_SIZE, next);
+ }
+ @Override
+ public ChunkType getChunkType() {
+ return SimpleMemoryAllocatorImpl.getAllocator().getChunkFactory().getChunkTypeForAddress(getMemoryAddress());
+ }
+ public static int getSrcTypeOrdinal(long memAddr) {
+ return getSrcType(memAddr) >> SRC_TYPE_SHIFT;
+ }
+ public static int getSrcType(long memAddr) {
+ return getSrcTypeFromRawBits(UnsafeMemoryChunk.readAbsoluteInt(memAddr+REF_COUNT_OFFSET));
+ }
+ public static int getSrcTypeFromRawBits(int rawBits) {
+ return rawBits & SRC_TYPE_MASK;
+ }
+ public static int getSrcTypeOrdinalFromRawBits(int rawBits) {
+ return getSrcTypeFromRawBits(rawBits) >> SRC_TYPE_SHIFT;
+ }
+
+ /**
+ * Fills the chunk with a repeated byte fill pattern.
+ * @param baseAddress the starting address for a {@link Chunk}.
+ */
+ public static void fill(long baseAddress) {
+ long startAddress = baseAddress + MIN_CHUNK_SIZE;
+ int size = getSize(baseAddress) - MIN_CHUNK_SIZE;
+
+ UnsafeMemoryChunk.fill(startAddress, size, FILL_BYTE);
+ }
+
+ /**
+ * Validates that the fill pattern for this chunk has not been disturbed. This method
+ * assumes the TINY_MULTIPLE is 8 bytes.
+ * @throws IllegalStateException when the pattern has been violated.
+ */
+ public void validateFill() {
+ assert SimpleMemoryAllocatorImpl.TINY_MULTIPLE == 8;
+
+ long startAddress = getMemoryAddress() + MIN_CHUNK_SIZE;
+ int size = getSize() - MIN_CHUNK_SIZE;
+
+ for(int i = 0;i < size;i += SimpleMemoryAllocatorImpl.TINY_MULTIPLE) {
+ if(UnsafeMemoryChunk.readAbsoluteLong(startAddress + i) != FILL_PATTERN) {
+ throw new IllegalStateException("Fill pattern violated for chunk " + getMemoryAddress() + " with size " + getSize());
+ }
+ }
+ }
+
+ public void setSerialized(boolean isSerialized) {
+ if (isSerialized) {
+ int bits;
+ int originalBits;
+ do {
+ originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
+ if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
+ }
+ bits = originalBits | IS_SERIALIZED_BIT;
+ } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, originalBits, bits));
+ }
+ }
+ public void setCompressed(boolean isCompressed) {
+ if (isCompressed) {
+ int bits;
+ int originalBits;
+ do {
+ originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
+ if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
+ }
+ bits = originalBits | IS_COMPRESSED_BIT;
+ } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, originalBits, bits));
+ }
+ }
+ public void setDataSize(int dataSize) { // KIRK
+ assert dataSize <= getSize();
+ int delta = getSize() - dataSize;
+ assert delta <= (DATA_SIZE_DELTA_MASK >> DATA_SIZE_SHIFT);
+ delta <<= DATA_SIZE_SHIFT;
+ int bits;
+ int originalBits;
+ do {
+ originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
+ if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
+ }
+ bits = originalBits;
+ bits &= ~DATA_SIZE_DELTA_MASK; // clear the old dataSizeDelta bits
+ bits |= delta; // set the dataSizeDelta bits to the new delta value
+ } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, originalBits, bits));
+ }
+
+ public void initializeUseCount() {
+ int rawBits;
+ do {
+ rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
+ if ((rawBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(rawBits));
+ }
+ int uc = rawBits & REF_COUNT_MASK;
+ if (uc != 0) {
+ throw new IllegalStateException("Expected use count to be zero but it was: " + uc + " rawBits=0x" + Integer.toHexString(rawBits));
+ }
+ } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, rawBits, rawBits+1));
+ }
+
+ public static int getRefCount(long memAddr) {
+ return UnsafeMemoryChunk.readAbsoluteInt(memAddr+REF_COUNT_OFFSET) & REF_COUNT_MASK;
+ }
+
+ public static boolean retain(long memAddr) {
+ SimpleMemoryAllocatorImpl.validateAddress(memAddr);
+ int uc;
+ int rawBits;
+ int retryCount = 0;
+ do {
+ rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET);
+ if ((rawBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ // same as uc == 0
+ // TODO MAGIC_NUMBER rethink its use and interaction with compactor fragments
+ return false;
+ }
+ uc = rawBits & REF_COUNT_MASK;
+ if (uc == MAX_REF_COUNT) {
+ throw new IllegalStateException("Maximum use count exceeded. rawBits=" + Integer.toHexString(rawBits));
+ } else if (uc == 0) {
+ return false;
+ }
+ retryCount++;
+ if (retryCount > 1000) {
+ throw new IllegalStateException("tried to write " + (rawBits+1) + " to @" + Long.toHexString(memAddr) + " 1,000 times.");
+ }
+ } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET, rawBits, rawBits+1));
+ //debugLog("use inced ref count " + (uc+1) + " @" + Long.toHexString(memAddr), true);
+ if (SimpleMemoryAllocatorImpl.trackReferenceCounts()) {
+ SimpleMemoryAllocatorImpl.refCountChanged(memAddr, false, uc+1);
+ }
+
+ return true;
+ }
+ public static void release(final long memAddr, boolean issueOnReturnCallback) {
+ SimpleMemoryAllocatorImpl.validateAddress(memAddr);
+ int newCount;
+ int rawBits;
+ boolean returnToAllocator;
+ do {
+ returnToAllocator = false;
+ rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET);
+ if ((rawBits&MAGIC_MASK) != MAGIC_NUMBER) {
+ String msg = "It looks like off heap memory @" + Long.toHexString(memAddr) + " was already freed. rawBits=" + Integer.toHexString(rawBits) + " history=" + SimpleMemoryAllocatorImpl.getFreeRefCountInfo(memAddr);
+ //debugLog(msg, true);
+ throw new IllegalStateException(msg);
+ }
+ int curCount = rawBits&REF_COUNT_MASK;
+ if ((curCount) == 0) {
+ //debugLog("too many frees @" + Long.toHexString(memAddr), true);
+ throw new IllegalStateException("Memory has already been freed." + " history=" + SimpleMemoryAllocatorImpl.getFreeRefCountInfo(memAddr) /*+ System.identityHashCode(this)*/);
+ }
+ if (curCount == 1) {
+ newCount = 0; // clear the use count, bits, and the delta size since it will be freed.
+ returnToAllocator = true;
+ } else {
+ newCount = rawBits-1;
+ }
+ } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET, rawBits, newCount));
+ //debugLog("free deced ref count " + (newCount&USE_COUNT_MASK) + " @" + Long.toHexString(memAddr), true);
+ if (returnToAllocator ) {
+ /*
+ if(issueOnReturnCallback) {
+ final GemFireCacheImpl.StaticSystemCallbacks sysCb =
+ GemFireCacheImpl.FactoryStatics.systemCallbacks;
+ if(sysCb != null ) {
+ ChunkType ct = SimpleMemoryAllocatorImpl.getAllocator().getChunkFactory().getChunkTypeForRawBits(rawBits);
+ int dataSizeDelta = computeDataSizeDelta(rawBits);
+ sysCb.beforeReturningOffHeapMemoryToAllocator(memAddr, ct, dataSizeDelta);
+ }
+ }
+ */
+
+ if (SimpleMemoryAllocatorImpl.trackReferenceCounts()) {
+ if (SimpleMemoryAllocatorImpl.trackFreedReferenceCounts()) {
+ SimpleMemoryAllocatorImpl.refCountChanged(memAddr, true, newCount&REF_COUNT_MASK);
+ }
+ SimpleMemoryAllocatorImpl.freeRefCountInfo(memAddr);
+ }
+
+ // Use fill pattern for free list data integrity check.
+ if(SimpleMemoryAllocatorImpl.getAllocator().validateMemoryWithFill) {
+ fill(memAddr);
+ }
+
+ SimpleMemoryAllocatorImpl.getAllocator().freeChunk(memAddr);
+ } else {
+ if (SimpleMemoryAllocatorImpl.trackReferenceCounts()) {
+ SimpleMemoryAllocatorImpl.refCountChanged(memAddr, true, newCount&REF_COUNT_MASK);
+ }
+ }
+ }
+
+ private static int computeDataSizeDelta(int rawBits) {
+ int dataSizeDelta = rawBits;
+ dataSizeDelta &= DATA_SIZE_DELTA_MASK;
+ dataSizeDelta >>= DATA_SIZE_SHIFT;
+ return dataSizeDelta;
+ }
+
+ @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()) + ">";
+ }
+
+ @Override
+ public State getState() {
+ if (getRefCount() > 0) {
+ return State.ALLOCATED;
+ } else {
+ return State.DEALLOCATED;
+ }
+ }
+ @Override
+ public MemoryBlock getNextBlock() {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public int getBlockSize() {
+ return getSize();
+ }
+ @Override
+ public int getSlabId() {
+ throw new UnsupportedOperationException();
+ }
+ @Override
+ public int getFreeListId() {
+ return -1;
+ }
+ @Override
+ public String getDataType() {
+ return null;
+ }
+ @Override
+ public Object getDataValue() {
+ return null;
+ }
+ public Chunk slice(int position, int limit) {
+ throw new UnsupportedOperationException();
+ }
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapCachedDeserializable.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapCachedDeserializable.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapCachedDeserializable.java
index 1bc2cdf..143fb25 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapCachedDeserializable.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapCachedDeserializable.java
@@ -30,7 +30,6 @@ import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
import com.gemstone.gemfire.internal.cache.EntryBits;
import com.gemstone.gemfire.internal.cache.RegionEntry;
import com.gemstone.gemfire.internal.lang.StringUtils;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
index 4fcacbf..6cb43ad 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
@@ -24,7 +24,6 @@ import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.OffHeapRegionEntry;
import com.gemstone.gemfire.internal.cache.RegionEntryContext;
import com.gemstone.gemfire.internal.cache.Token;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
[08/20] incubator-geode git commit: move ChunkType out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move ChunkType out of 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/944e1860
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/944e1860
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/944e1860
Branch: refs/heads/feature/GEODE-580
Commit: 944e186026bdf11681e78db6109358d37c6b16cf
Parents: b4cbd4a
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:44:02 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:44:02 2015 -0800
----------------------------------------------------------------------
.../internal/cache/AbstractRegionEntry.java | 1 -
.../gemfire/internal/offheap/Chunk.java | 1 -
.../gemfire/internal/offheap/ChunkFactory.java | 1 -
.../gemfire/internal/offheap/ChunkType.java | 26 ++++++++++++++++++++
.../internal/offheap/GemFireChunkFactory.java | 1 -
.../internal/offheap/MemoryAllocator.java | 1 -
.../gemfire/internal/offheap/MemoryBlock.java | 1 -
.../offheap/SimpleMemoryAllocatorImpl.java | 6 -----
8 files changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
index ab83cf4..0078f66 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
@@ -66,7 +66,6 @@ import com.gemstone.gemfire.internal.offheap.MemoryAllocator;
import com.gemstone.gemfire.internal.offheap.OffHeapCachedDeserializable;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunkType;
import com.gemstone.gemfire.internal.offheap.StoredObject;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
index 714ac6f..d2c79c0 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
@@ -30,7 +30,6 @@ import com.gemstone.gemfire.internal.InternalDataSerializer;
import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.RegionEntry;
import com.gemstone.gemfire.internal.cache.RegionEntryContext;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
index 467649e..f7d4ba8 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
@@ -16,7 +16,6 @@
*/
package com.gemstone.gemfire.internal.offheap;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
/**
* ChunkFactory can be used to create Chunk instances.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkType.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkType.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkType.java
new file mode 100644
index 0000000..9841368
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkType.java
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+/**
+ * Used to create new chunks of a certain type.
+ */
+public abstract class ChunkType {
+ public abstract int getSrcType();
+ public abstract Chunk newChunk(long memoryAddress);
+ public abstract Chunk newChunk(long memoryAddress, int chunkSize);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
index b60013d..e8e80aa 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
@@ -16,7 +16,6 @@
*/
package com.gemstone.gemfire.internal.offheap;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunk;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryAllocator.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryAllocator.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryAllocator.java
index bf38089..231ff3a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryAllocator.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryAllocator.java
@@ -17,7 +17,6 @@
package com.gemstone.gemfire.internal.offheap;
import com.gemstone.gemfire.compression.Compressor;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
/**
* Basic contract for a heap that manages off heap memory. Any MemoryChunks allocated from a heap
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlock.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlock.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlock.java
index 05cc796..3ad9283 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlock.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/MemoryBlock.java
@@ -16,7 +16,6 @@
*/
package com.gemstone.gemfire.internal.offheap;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
/**
* Basic size and usage information about an off-heap memory block under
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/944e1860/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 c13842a..b492bb5 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
@@ -1450,12 +1450,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public static abstract class ChunkType {
- public abstract int getSrcType();
- public abstract Chunk newChunk(long memoryAddress);
- public abstract Chunk newChunk(long memoryAddress, int chunkSize);
- }
-
public static class GemFireChunkType extends ChunkType {
private static final GemFireChunkType singleton = new GemFireChunkType();
public static GemFireChunkType singleton() { return singleton; }
[11/20] incubator-geode git commit: move GemFireChunkSlice out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move GemFireChunkSlice out of 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/2364dd12
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/2364dd12
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/2364dd12
Branch: refs/heads/feature/GEODE-580
Commit: 2364dd12cf5345121bfa761ebafc46ef5c2cc0b4
Parents: 84de915
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:54:04 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:54:04 2015 -0800
----------------------------------------------------------------------
.../gemfire/internal/offheap/GemFireChunk.java | 1 -
.../internal/offheap/GemFireChunkSlice.java | 44 ++++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 22 ----------
3 files changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2364dd12/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
index d0d41a6..3167613 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunk.java
@@ -16,7 +16,6 @@
*/
package com.gemstone.gemfire.internal.offheap;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunkSlice;
/**
* A chunk that stores a GemFire object.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2364dd12/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkSlice.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkSlice.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkSlice.java
new file mode 100644
index 0000000..0c27aa3
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkSlice.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Represents a slice of a GemFireChunk.
+ * A slice is a subsequence of the bytes stored in a GemFireChunk.
+ */
+public class GemFireChunkSlice extends GemFireChunk {
+ private final int offset;
+ private final int capacity;
+ public GemFireChunkSlice(GemFireChunk gemFireChunk, int position, int limit) {
+ super(gemFireChunk);
+ this.offset = gemFireChunk.getBaseDataOffset() + position;
+ this.capacity = limit - position;
+ }
+ @Override
+ public int getDataSize() {
+ return this.capacity;
+ }
+
+ @Override
+ protected long getBaseDataAddress() {
+ return super.getBaseDataAddress() + this.offset;
+ }
+ @Override
+ protected int getBaseDataOffset() {
+ return this.offset;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2364dd12/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 0f91803..a5de17e 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
@@ -1450,28 +1450,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public static class GemFireChunkSlice extends GemFireChunk {
- private final int offset;
- private final int capacity;
- public GemFireChunkSlice(GemFireChunk gemFireChunk, int position, int limit) {
- super(gemFireChunk);
- this.offset = gemFireChunk.getBaseDataOffset() + position;
- this.capacity = limit - position;
- }
- @Override
- public int getDataSize() {
- return this.capacity;
- }
-
- @Override
- protected long getBaseDataAddress() {
- return super.getBaseDataAddress() + this.offset;
- }
- @Override
- protected int getBaseDataOffset() {
- return this.offset;
- }
- }
public static class FakeChunk extends Chunk {
private final int size;
public FakeChunk(int size) {
[06/20] incubator-geode git commit: move ChunkFactory out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move ChunkFactory out of 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/9d5905d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/9d5905d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/9d5905d6
Branch: refs/heads/feature/GEODE-580
Commit: 9d5905d62864f74a21ad20dbb65469fcf61122e4
Parents: 419b017
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:38:07 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:38:07 2015 -0800
----------------------------------------------------------------------
.../gemfire/internal/offheap/ChunkFactory.java | 52 ++++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 28 -----------
2 files changed, 52 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d5905d6/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
new file mode 100644
index 0000000..467649e
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkFactory.java
@@ -0,0 +1,52 @@
+/*
+ * 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 com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
+
+/**
+ * ChunkFactory can be used to create Chunk instances.
+ * It can also be used to determine the ChunkType given a Chunk address
+ * or the object header bits from an existing Chunk.
+ */
+public interface ChunkFactory {
+ /**
+ * Create a new chunk of the given size and type at the given address.
+ */
+ Chunk newChunk(long address, int chunkSize, ChunkType chunkType);
+ /**
+ * Create a new chunk for a block of memory (identified by address)
+ * that has already been allocated.
+ * The size and type are derived from the existing object header.
+ */
+ Chunk newChunk(long address);
+ /**
+ * Create a new chunk of the given type for a block of memory (identified by address)
+ * that has already been allocated.
+ * The size is derived from the existing object header.
+ */
+ Chunk newChunk(long address, ChunkType chunkType);
+ /**
+ * Given the address of an existing chunk return its ChunkType.
+ */
+ ChunkType getChunkTypeForAddress(long address);
+ /**
+ * Given the rawBits from the object header of an existing chunk
+ * return its ChunkType.
+ */
+ ChunkType getChunkTypeForRawBits(int bits);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d5905d6/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 ed67b8b..86cba3b 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
@@ -1424,34 +1424,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
- public static interface ChunkFactory {
- /**
- * Create a new chunk of the given size and type at the given address.
- */
- Chunk newChunk(long address, int chunkSize, ChunkType chunkType);
- /**
- * Create a new chunk for a block of memory (identified by address)
- * that has already been allocated.
- * The size and type are derived from the existing object header.
- */
- Chunk newChunk(long address);
- /**
- * Create a new chunk of the given type for a block of memory (identified by address)
- * that has already been allocated.
- * The size is derived from the existing object header.
- */
- Chunk newChunk(long address, ChunkType chunkType);
- /**
- * Given the address of an existing chunk return its ChunkType.
- */
- ChunkType getChunkTypeForAddress(long address);
- /**
- * Given the rawBits from the object header of an existing chunk
- * return its ChunkType.
- */
- ChunkType getChunkTypeForRawBits(int bits);
- }
-
private static class GemFireChunkFactory implements ChunkFactory {
@Override
public Chunk newChunk(long address, int chunkSize, ChunkType chunkType) {
[02/20] incubator-geode git commit: fixed imports
Posted by ds...@apache.org.
fixed imports
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f4dd17dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f4dd17dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f4dd17dc
Branch: refs/heads/feature/GEODE-580
Commit: f4dd17dc41efa9ad714ebaf66635add3a993f850
Parents: 91d9027
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:19:42 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:19:42 2015 -0800
----------------------------------------------------------------------
.../com/gemstone/gemfire/internal/cache/VMThinRegionEntry.java | 5 -----
1 file changed, 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f4dd17dc/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/VMThinRegionEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/VMThinRegionEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/VMThinRegionEntry.java
index 6317fbc..bdc05c3 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/VMThinRegionEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/VMThinRegionEntry.java
@@ -17,11 +17,6 @@
package com.gemstone.gemfire.internal.cache;
-import java.util.UUID;
-
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ConcurrentBag;
-
-
/**
* Implementation class of RegionEntry interface.
* VM -> entries stored in VM memory
[04/20] incubator-geode git commit: move Chunk out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/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 5113cc3..ed67b8b 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
@@ -20,10 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutput;
import java.io.IOException;
import java.io.PrintStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -57,15 +53,12 @@ import com.gemstone.gemfire.OutOfOffHeapMemoryException;
import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.DSCODE;
import com.gemstone.gemfire.internal.DataSerializableFixedID;
-import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.InternalDataSerializer;
import com.gemstone.gemfire.internal.cache.BucketRegion;
import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
import com.gemstone.gemfire.internal.cache.EntryBits;
-import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
@@ -708,7 +701,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
// asyncCleanupThread.set(t);
}
- private void freeChunk(long addr) {
+ void freeChunk(long addr) {
this.freeList.free(addr);
}
@@ -1597,765 +1590,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
return this.offset;
}
}
- /**
- * Note: this class has a natural ordering that is inconsistent with equals.
- * Instances of this class should have a short lifetime. We do not store references
- * to it in the cache. Instead the memoryAddress is stored in a primitive field in
- * the cache and if used it will then, if needed, create an instance of this class.
- */
- public static abstract class Chunk extends OffHeapCachedDeserializable implements Comparable<Chunk>, MemoryBlock {
- /**
- * The unsafe memory address of the first byte of this chunk
- */
- private final long memoryAddress;
-
- /**
- * The useCount, chunkSize, dataSizeDelta, isSerialized, and isCompressed
- * are all stored in off heap memory in a HEADER. This saves heap memory
- * by using off heap.
- */
- public final static int OFF_HEAP_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;
- /**
- * int field.
- * The number of bytes in this chunk.
- */
- private final static int CHUNK_SIZE_OFFSET = 0;
- /**
- * Volatile int field
- * The upper two bits are used for the isSerialized
- * and isCompressed flags.
- * The next three bits are used to encode the SRC_TYPE enum.
- * The lower 3 bits of the most significant byte contains a magic number to help us detect
- * if we are changing the ref count of an object that has been released.
- * The next byte contains the dataSizeDelta.
- * The number of bytes of logical data in this chunk.
- * Since the number of bytes of logical data is always <= chunkSize
- * and since chunkSize never changes, we have dataSize be
- * a delta whose max value would be HUGE_MULTIPLE-1.
- * The lower two bytes contains the use count.
- */
- private final static int REF_COUNT_OFFSET = 4;
- /**
- * The upper two bits are used for the isSerialized
- * and isCompressed flags.
- */
- private final static int IS_SERIALIZED_BIT = 0x80000000;
- private final static int IS_COMPRESSED_BIT = 0x40000000;
- private final static int SRC_TYPE_MASK = 0x38000000;
- private final static int SRC_TYPE_SHIFT = 16/*refCount*/+8/*dataSize*/+3/*magicSize*/;
- private final static int MAGIC_MASK = 0x07000000;
- private final static int MAGIC_NUMBER = 0x05000000;
- private final static int DATA_SIZE_DELTA_MASK = 0x00ff0000;
- private final static int DATA_SIZE_SHIFT = 16;
- private final static int REF_COUNT_MASK = 0x0000ffff;
- private final static int MAX_REF_COUNT = 0xFFFF;
- final static long FILL_PATTERN = 0x3c3c3c3c3c3c3c3cL;
- final static byte FILL_BYTE = 0x3c;
-
- // The 8 bits reserved for SRC_TYPE are basically no longer used.
- // So we could free up these 8 bits for some other use or we could
- // keep them for future extensions.
- // If we ever want to allocate other "types" into a chunk of off-heap
- // memory then the SRC_TYPE would be the way to go.
- // For example we may want to allocate the memory for the off-heap
- // RegionEntry in off-heap memory without it being of type GFE.
- // When it is of type GFE then it either needs to be the bytes
- // of a byte array or it needs to be a serialized java object.
- // For the RegionEntry we may want all the primitive fields of
- // the entry at certain offsets in the off-heap memory so we could
- // access them directly in native byte format (i.e. no serialization).
- // Note that for every SRC_TYPE we should have a ChunkType subclass.
- public final static int SRC_TYPE_UNUSED0 = 0 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_UNUSED1 = 1 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_UNUSED2 = 2 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_UNUSED3 = 3 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_GFE = 4 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_UNUSED5 = 5 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_UNUSED6 = 6 << SRC_TYPE_SHIFT;
- public final static int SRC_TYPE_UNUSED7 = 7 << SRC_TYPE_SHIFT;
-
- protected Chunk(long memoryAddress, int chunkSize, ChunkType chunkType) {
- validateAddressAndSize(memoryAddress, chunkSize);
- this.memoryAddress = memoryAddress;
- setSize(chunkSize);
- UnsafeMemoryChunk.writeAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET, MAGIC_NUMBER|chunkType.getSrcType());
- }
- public void readyForFree() {
- UnsafeMemoryChunk.writeAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET, 0);
- }
- public void readyForAllocation(ChunkType chunkType) {
- if (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET, 0, MAGIC_NUMBER|chunkType.getSrcType())) {
- throw new IllegalStateException("Expected 0 but found " + Integer.toHexString(UnsafeMemoryChunk.readAbsoluteIntVolatile(getMemoryAddress()+REF_COUNT_OFFSET)));
- }
- }
- /**
- * Should only be used by FakeChunk subclass
- */
- protected Chunk() {
- this.memoryAddress = 0L;
- }
-
- /**
- * Used to create a Chunk given an existing, already allocated,
- * memoryAddress. The off heap header has already been initialized.
- */
- protected Chunk(long memoryAddress) {
- validateAddress(memoryAddress);
- this.memoryAddress = memoryAddress;
- }
-
- protected Chunk(Chunk chunk) {
- this.memoryAddress = chunk.memoryAddress;
- }
-
- /**
- * Throw an exception if this chunk is not allocated
- */
- public void checkIsAllocated() {
- int originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
- if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
- throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
- }
- }
-
- public void incSize(int inc) {
- setSize(getSize()+inc);
- }
-
- protected void beforeReturningToAllocator() {
-
- }
-
- @Override
- public int getSize() {
- return getSize(this.memoryAddress);
- }
-
- public void setSize(int size) {
- setSize(this.memoryAddress, size);
- }
-
- public long getMemoryAddress() {
- return this.memoryAddress;
- }
-
- public int getDataSize() {
- /*int dataSizeDelta = UnsafeMemoryChunk.readAbsoluteInt(this.memoryAddress+REF_COUNT_OFFSET);
- dataSizeDelta &= DATA_SIZE_DELTA_MASK;
- dataSizeDelta >>= DATA_SIZE_SHIFT;
- return getSize() - dataSizeDelta;*/
- return getDataSize(this.memoryAddress);
- }
-
- protected static int getDataSize(long memoryAdress) {
- int dataSizeDelta = UnsafeMemoryChunk.readAbsoluteInt(memoryAdress+REF_COUNT_OFFSET);
- dataSizeDelta &= DATA_SIZE_DELTA_MASK;
- dataSizeDelta >>= DATA_SIZE_SHIFT;
- return getSize(memoryAdress) - dataSizeDelta;
- }
-
- protected long getBaseDataAddress() {
- return this.memoryAddress+OFF_HEAP_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.
- */
- @Unretained
- public ByteBuffer createDirectByteBuffer() {
- return basicCreateDirectByteBuffer(getBaseDataAddress(), getDataSize());
- }
- @Override
- public void sendTo(DataOutput out) throws IOException {
- if (!this.isCompressed() && out instanceof HeapDataOutputStream) {
- ByteBuffer bb = createDirectByteBuffer();
- if (bb != null) {
- HeapDataOutputStream hdos = (HeapDataOutputStream) out;
- if (this.isSerialized()) {
- hdos.write(bb);
- } else {
- hdos.writeByte(DSCODE.BYTE_ARRAY);
- InternalDataSerializer.writeArrayLength(bb.remaining(), hdos);
- hdos.write(bb);
- }
- return;
- }
- }
- super.sendTo(out);
- }
-
- @Override
- public void sendAsByteArray(DataOutput out) throws IOException {
- if (!isCompressed() && out instanceof HeapDataOutputStream) {
- ByteBuffer bb = createDirectByteBuffer();
- if (bb != null) {
- HeapDataOutputStream hdos = (HeapDataOutputStream) out;
- InternalDataSerializer.writeArrayLength(bb.remaining(), hdos);
- hdos.write(bb);
- return;
- }
- }
- super.sendAsByteArray(out);
- }
-
- private static volatile Class dbbClass = null;
- private static volatile Constructor dbbCtor = null;
- private static volatile boolean dbbCreateFailed = false;
-
- /**
- * @return the created direct byte buffer or null if it could not be created.
- */
- private static ByteBuffer basicCreateDirectByteBuffer(long baseDataAddress, int dataSize) {
- if (dbbCreateFailed) {
- return null;
- }
- Constructor ctor = dbbCtor;
- if (ctor == null) {
- Class c = dbbClass;
- if (c == null) {
- try {
- c = Class.forName("java.nio.DirectByteBuffer");
- } catch (ClassNotFoundException e) {
- //throw new IllegalStateException("Could not find java.nio.DirectByteBuffer", e);
- dbbCreateFailed = true;
- dbbAddressFailed = true;
- return null;
- }
- dbbClass = c;
- }
- try {
- ctor = c.getDeclaredConstructor(long.class, int.class);
- } catch (NoSuchMethodException | SecurityException e) {
- //throw new IllegalStateException("Could not get constructor DirectByteBuffer(long, int)", e);
- dbbClass = null;
- dbbCreateFailed = true;
- return null;
- }
- ctor.setAccessible(true);
- dbbCtor = ctor;
- }
- try {
- return (ByteBuffer)ctor.newInstance(baseDataAddress, dataSize);
- } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- //throw new IllegalStateException("Could not create an instance using DirectByteBuffer(long, int)", e);
- dbbClass = null;
- dbbCtor = null;
- dbbCreateFailed = true;
- return null;
- }
- }
- private static volatile Method dbbAddressMethod = null;
- private static volatile boolean dbbAddressFailed = false;
-
- /**
- * Returns the address of the Unsafe memory for the first byte of a direct ByteBuffer.
- * If the buffer is not direct or the address can not be obtained return 0.
- */
- public static long getDirectByteBufferAddress(ByteBuffer bb) {
- if (!bb.isDirect()) {
- return 0L;
- }
- if (dbbAddressFailed) {
- return 0L;
- }
- Method m = dbbAddressMethod;
- if (m == null) {
- Class c = dbbClass;
- if (c == null) {
- try {
- c = Class.forName("java.nio.DirectByteBuffer");
- } catch (ClassNotFoundException e) {
- //throw new IllegalStateException("Could not find java.nio.DirectByteBuffer", e);
- dbbCreateFailed = true;
- dbbAddressFailed = true;
- return 0L;
- }
- dbbClass = c;
- }
- try {
- m = c.getDeclaredMethod("address");
- } catch (NoSuchMethodException | SecurityException e) {
- //throw new IllegalStateException("Could not get method DirectByteBuffer.address()", e);
- dbbClass = null;
- dbbAddressFailed = true;
- return 0L;
- }
- m.setAccessible(true);
- dbbAddressMethod = m;
- }
- try {
- return (Long)m.invoke(bb);
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- //throw new IllegalStateException("Could not create an invoke DirectByteBuffer.address()", e);
- dbbClass = null;
- dbbAddressMethod = null;
- dbbAddressFailed = true;
- return 0L;
- }
- }
- /**
- * Returns an address that can be used with unsafe apis to access this chunks memory.
- * @param offset the offset from this chunk's first byte of the byte the returned address should point to. Must be >= 0.
- * @param size the number of bytes that will be read using the returned address. Assertion will use this to verify that all the memory accessed belongs to this chunk. Must be > 0.
- * @return a memory address that can be used with unsafe apis
- */
- public long getUnsafeAddress(int offset, int size) {
- assert offset >= 0 && offset + size <= getDataSize(): "Offset=" + offset + ",size=" + size + ",dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset + size must be <= " + getDataSize();
- assert size > 0;
- long result = getBaseDataAddress() + offset;
- // validateAddressAndSizeWithinSlab(result, size);
- return result;
- }
-
- @Override
- public byte readByte(int offset) {
- assert offset < getDataSize();
- return UnsafeMemoryChunk.readAbsoluteByte(getBaseDataAddress() + offset);
- }
-
- @Override
- public void writeByte(int offset, byte value) {
- assert offset < getDataSize();
- UnsafeMemoryChunk.writeAbsoluteByte(getBaseDataAddress() + offset, value);
- }
-
- @Override
- public void readBytes(int offset, byte[] bytes) {
- readBytes(offset, bytes, 0, bytes.length);
- }
-
- @Override
- public void writeBytes(int offset, byte[] bytes) {
- writeBytes(offset, bytes, 0, bytes.length);
- }
-
- public long getAddressForReading(int offset, int size) {
- assert offset+size <= getDataSize();
- return getBaseDataAddress() + offset;
- }
-
- @Override
- public void readBytes(int offset, byte[] bytes, int bytesOffset, int size) {
- assert offset+size <= getDataSize();
- UnsafeMemoryChunk.readAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
- }
-
- @Override
- public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) {
- assert offset+size <= getDataSize();
- validateAddressAndSizeWithinSlab(getBaseDataAddress() + offset, size);
- UnsafeMemoryChunk.writeAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size);
- }
-
- @Override
- public void release() {
- release(this.memoryAddress, true);
- }
-
- @Override
- public int compareTo(Chunk o) {
- int result = Integer.signum(getSize() - o.getSize());
- if (result == 0) {
- // For the same sized chunks we really don't care about their order
- // but we need compareTo to only return 0 if the two chunks are identical
- result = Long.signum(getMemoryAddress() - o.getMemoryAddress());
- }
- return result;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof Chunk) {
- return getMemoryAddress() == ((Chunk) o).getMemoryAddress();
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- long value = this.getMemoryAddress();
- return (int)(value ^ (value >>> 32));
- }
-
- // OffHeapCachedDeserializable methods
-
- @Override
- public void setSerializedValue(byte[] value) {
- writeBytes(0, value);
- }
-
- public byte[] getDecompressedBytes(RegionEntryContext context) {
- byte[] result = getCompressedBytes();
- long time = context.getCachePerfStats().startDecompression();
- result = context.getCompressor().decompress(result);
- context.getCachePerfStats().endDecompression(time);
- return result;
- }
-
- /**
- * Returns the raw possibly compressed bytes of this chunk
- */
- public byte[] getCompressedBytes() {
- byte[] result = new byte[getDataSize()];
- readBytes(0, result);
- //debugLog("reading", true);
- getAllocator().getStats().incReads();
- return result;
- }
- protected byte[] getRawBytes() {
- byte[] result = getCompressedBytes();
- // TODO OFFHEAP: change the following to assert !isCompressed();
- if (isCompressed()) {
- throw new UnsupportedOperationException();
- }
- return result;
- }
-
- @Override
- public byte[] getSerializedValue() {
- byte [] result = getRawBytes();
- if (!isSerialized()) {
- // The object is a byte[]. So we need to make it look like a serialized byte[] in our result
- result = EntryEventImpl.serialize(result);
- }
- return result;
- }
-
- @Override
- public Object getDeserializedValue(Region r, RegionEntry re) {
- if (isSerialized()) {
- // TODO OFFHEAP: debug deserializeChunk
- return EntryEventImpl.deserialize(getRawBytes());
- //assert !isCompressed();
- //return EntryEventImpl.deserializeChunk(this);
- } else {
- return getRawBytes();
- }
- }
-
- /**
- * We want this to include memory overhead so use getSize() instead of getDataSize().
- */
- @Override
- public int getSizeInBytes() {
- // Calling getSize includes the off heap header size.
- // We do not add anything to this since the size of the reference belongs to the region entry size
- // not the size of this object.
- return getSize();
- }
-
- @Override
- public int getValueSizeInBytes() {
- return getDataSize();
- }
-
- @Override
- public void copyBytes(int src, int dst, int size) {
- throw new UnsupportedOperationException("Implement if used");
-// assert src+size <= getDataSize();
-// assert dst+size < getDataSize();
-// getSlabs()[this.getSlabIdx()].copyBytes(getBaseDataAddress()+src, getBaseDataAddress()+dst, size);
- }
-
- @Override
- public boolean isSerialized() {
- return (UnsafeMemoryChunk.readAbsoluteInt(this.memoryAddress+REF_COUNT_OFFSET) & IS_SERIALIZED_BIT) != 0;
- }
-
- @Override
- public boolean isCompressed() {
- return (UnsafeMemoryChunk.readAbsoluteInt(this.memoryAddress+REF_COUNT_OFFSET) & IS_COMPRESSED_BIT) != 0;
- }
-
- @Override
- public boolean retain() {
- return retain(this.memoryAddress);
- }
-
- @Override
- public int getRefCount() {
- return getRefCount(this.memoryAddress);
- }
-
- public static int getSize(long memAddr) {
- validateAddress(memAddr);
- return UnsafeMemoryChunk.readAbsoluteInt(memAddr+CHUNK_SIZE_OFFSET);
- }
- public static void setSize(long memAddr, int size) {
- validateAddressAndSize(memAddr, size);
- UnsafeMemoryChunk.writeAbsoluteInt(memAddr+CHUNK_SIZE_OFFSET, size);
- }
- public static long getNext(long memAddr) {
- validateAddress(memAddr);
- return UnsafeMemoryChunk.readAbsoluteLong(memAddr+OFF_HEAP_HEADER_SIZE);
- }
- public static void setNext(long memAddr, long next) {
- validateAddress(memAddr);
- UnsafeMemoryChunk.writeAbsoluteLong(memAddr+OFF_HEAP_HEADER_SIZE, next);
- }
- @Override
- public ChunkType getChunkType() {
- return getAllocator().getChunkFactory().getChunkTypeForAddress(getMemoryAddress());
- }
- public static int getSrcTypeOrdinal(long memAddr) {
- return getSrcType(memAddr) >> SRC_TYPE_SHIFT;
- }
- public static int getSrcType(long memAddr) {
- return getSrcTypeFromRawBits(UnsafeMemoryChunk.readAbsoluteInt(memAddr+REF_COUNT_OFFSET));
- }
- public static int getSrcTypeFromRawBits(int rawBits) {
- return rawBits & SRC_TYPE_MASK;
- }
- public static int getSrcTypeOrdinalFromRawBits(int rawBits) {
- return getSrcTypeFromRawBits(rawBits) >> SRC_TYPE_SHIFT;
- }
-
- /**
- * Fills the chunk with a repeated byte fill pattern.
- * @param baseAddress the starting address for a {@link Chunk}.
- */
- public static void fill(long baseAddress) {
- long startAddress = baseAddress + MIN_CHUNK_SIZE;
- int size = getSize(baseAddress) - MIN_CHUNK_SIZE;
-
- UnsafeMemoryChunk.fill(startAddress, size, FILL_BYTE);
- }
-
- /**
- * Validates that the fill pattern for this chunk has not been disturbed. This method
- * assumes the TINY_MULTIPLE is 8 bytes.
- * @throws IllegalStateException when the pattern has been violated.
- */
- public void validateFill() {
- assert TINY_MULTIPLE == 8;
-
- long startAddress = getMemoryAddress() + MIN_CHUNK_SIZE;
- int size = getSize() - MIN_CHUNK_SIZE;
-
- for(int i = 0;i < size;i += TINY_MULTIPLE) {
- if(UnsafeMemoryChunk.readAbsoluteLong(startAddress + i) != FILL_PATTERN) {
- throw new IllegalStateException("Fill pattern violated for chunk " + getMemoryAddress() + " with size " + getSize());
- }
- }
- }
-
- public void setSerialized(boolean isSerialized) {
- if (isSerialized) {
- int bits;
- int originalBits;
- do {
- originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
- if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
- throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
- }
- bits = originalBits | IS_SERIALIZED_BIT;
- } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, originalBits, bits));
- }
- }
- public void setCompressed(boolean isCompressed) {
- if (isCompressed) {
- int bits;
- int originalBits;
- do {
- originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
- if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
- throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
- }
- bits = originalBits | IS_COMPRESSED_BIT;
- } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, originalBits, bits));
- }
- }
- public void setDataSize(int dataSize) { // KIRK
- assert dataSize <= getSize();
- int delta = getSize() - dataSize;
- assert delta <= (DATA_SIZE_DELTA_MASK >> DATA_SIZE_SHIFT);
- delta <<= DATA_SIZE_SHIFT;
- int bits;
- int originalBits;
- do {
- originalBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
- if ((originalBits&MAGIC_MASK) != MAGIC_NUMBER) {
- throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(originalBits));
- }
- bits = originalBits;
- bits &= ~DATA_SIZE_DELTA_MASK; // clear the old dataSizeDelta bits
- bits |= delta; // set the dataSizeDelta bits to the new delta value
- } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, originalBits, bits));
- }
-
- public void initializeUseCount() {
- int rawBits;
- do {
- rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET);
- if ((rawBits&MAGIC_MASK) != MAGIC_NUMBER) {
- throw new IllegalStateException("It looks like this off heap memory was already freed. rawBits=" + Integer.toHexString(rawBits));
- }
- int uc = rawBits & REF_COUNT_MASK;
- if (uc != 0) {
- throw new IllegalStateException("Expected use count to be zero but it was: " + uc + " rawBits=0x" + Integer.toHexString(rawBits));
- }
- } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(this.memoryAddress+REF_COUNT_OFFSET, rawBits, rawBits+1));
- }
-
- public static int getRefCount(long memAddr) {
- return UnsafeMemoryChunk.readAbsoluteInt(memAddr+REF_COUNT_OFFSET) & REF_COUNT_MASK;
- }
-
- public static boolean retain(long memAddr) {
- validateAddress(memAddr);
- int uc;
- int rawBits;
- int retryCount = 0;
- do {
- rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET);
- if ((rawBits&MAGIC_MASK) != MAGIC_NUMBER) {
- // same as uc == 0
- // TODO MAGIC_NUMBER rethink its use and interaction with compactor fragments
- return false;
- }
- uc = rawBits & REF_COUNT_MASK;
- if (uc == MAX_REF_COUNT) {
- throw new IllegalStateException("Maximum use count exceeded. rawBits=" + Integer.toHexString(rawBits));
- } else if (uc == 0) {
- return false;
- }
- retryCount++;
- if (retryCount > 1000) {
- throw new IllegalStateException("tried to write " + (rawBits+1) + " to @" + Long.toHexString(memAddr) + " 1,000 times.");
- }
- } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET, rawBits, rawBits+1));
- //debugLog("use inced ref count " + (uc+1) + " @" + Long.toHexString(memAddr), true);
- if (trackReferenceCounts()) {
- refCountChanged(memAddr, false, uc+1);
- }
-
- return true;
- }
- public static void release(final long memAddr, boolean issueOnReturnCallback) {
- validateAddress(memAddr);
- int newCount;
- int rawBits;
- boolean returnToAllocator;
- do {
- returnToAllocator = false;
- rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET);
- if ((rawBits&MAGIC_MASK) != MAGIC_NUMBER) {
- String msg = "It looks like off heap memory @" + Long.toHexString(memAddr) + " was already freed. rawBits=" + Integer.toHexString(rawBits) + " history=" + getFreeRefCountInfo(memAddr);
- //debugLog(msg, true);
- throw new IllegalStateException(msg);
- }
- int curCount = rawBits&REF_COUNT_MASK;
- if ((curCount) == 0) {
- //debugLog("too many frees @" + Long.toHexString(memAddr), true);
- throw new IllegalStateException("Memory has already been freed." + " history=" + getFreeRefCountInfo(memAddr) /*+ System.identityHashCode(this)*/);
- }
- if (curCount == 1) {
- newCount = 0; // clear the use count, bits, and the delta size since it will be freed.
- returnToAllocator = true;
- } else {
- newCount = rawBits-1;
- }
- } while (!UnsafeMemoryChunk.writeAbsoluteIntVolatile(memAddr+REF_COUNT_OFFSET, rawBits, newCount));
- //debugLog("free deced ref count " + (newCount&USE_COUNT_MASK) + " @" + Long.toHexString(memAddr), true);
- if (returnToAllocator ) {
- /*
- if(issueOnReturnCallback) {
- final GemFireCacheImpl.StaticSystemCallbacks sysCb =
- GemFireCacheImpl.FactoryStatics.systemCallbacks;
- if(sysCb != null ) {
- ChunkType ct = SimpleMemoryAllocatorImpl.getAllocator().getChunkFactory().getChunkTypeForRawBits(rawBits);
- int dataSizeDelta = computeDataSizeDelta(rawBits);
- sysCb.beforeReturningOffHeapMemoryToAllocator(memAddr, ct, dataSizeDelta);
- }
- }
- */
-
- if (trackReferenceCounts()) {
- if (trackFreedReferenceCounts()) {
- refCountChanged(memAddr, true, newCount&REF_COUNT_MASK);
- }
- freeRefCountInfo(memAddr);
- }
-
- // Use fill pattern for free list data integrity check.
- if(SimpleMemoryAllocatorImpl.getAllocator().validateMemoryWithFill) {
- fill(memAddr);
- }
-
- getAllocator().freeChunk(memAddr);
- } else {
- if (trackReferenceCounts()) {
- refCountChanged(memAddr, true, newCount&REF_COUNT_MASK);
- }
- }
- }
-
- private static int computeDataSizeDelta(int rawBits) {
- int dataSizeDelta = rawBits;
- dataSizeDelta &= DATA_SIZE_DELTA_MASK;
- dataSizeDelta >>= DATA_SIZE_SHIFT;
- return dataSizeDelta;
- }
-
- @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()) + ">";
- }
-
- @Override
- public State getState() {
- if (getRefCount() > 0) {
- return State.ALLOCATED;
- } else {
- return State.DEALLOCATED;
- }
- }
- @Override
- public MemoryBlock getNextBlock() {
- throw new UnsupportedOperationException();
- }
- @Override
- public int getBlockSize() {
- return getSize();
- }
- @Override
- public int getSlabId() {
- throw new UnsupportedOperationException();
- }
- @Override
- public int getFreeListId() {
- return -1;
- }
- @Override
- public String getDataType() {
- return null;
- }
- @Override
- public Object getDataValue() {
- return null;
- }
- public Chunk slice(int position, int limit) {
- throw new UnsupportedOperationException();
- }
- }
public static class FakeChunk extends Chunk {
private final int size;
public FakeChunk(int size) {
@@ -2466,11 +1700,11 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- private static void validateAddress(long addr) {
+ static void validateAddress(long addr) {
validateAddressAndSize(addr, -1);
}
- private static void validateAddressAndSize(long addr, int size) {
+ static void validateAddressAndSize(long addr, int size) {
// if the caller does not have a "size" to provide then use -1
if ((addr & 7) != 0) {
StringBuilder sb = new StringBuilder();
@@ -2492,7 +1726,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
validateAddressAndSizeWithinSlab(addr, size);
}
- private static void validateAddressAndSizeWithinSlab(long addr, int size) {
+ static void validateAddressAndSizeWithinSlab(long addr, int size) {
if (DO_EXPENSIVE_VALIDATION) {
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.singleton;
if (ma != null) {
@@ -2966,7 +2200,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
* Set this to "true" to perform data integrity checks on allocated and reused Chunks. This may clobber
* performance so turn on only when necessary.
*/
- private final boolean validateMemoryWithFill = Boolean.getBoolean("gemfire.validateOffHeapWithFill");
+ final boolean validateMemoryWithFill = Boolean.getBoolean("gemfire.validateOffHeapWithFill");
private final static boolean trackRefCounts = Boolean.getBoolean("gemfire.trackOffHeapRefCounts");
private final static boolean trackFreedRefCounts = Boolean.getBoolean("gemfire.trackOffHeapFreedRefCounts");
@@ -3123,7 +2357,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
setReferenceCountOwner(null);
}
- private static void refCountChanged(Long address, boolean decRefCount, int rc) {
+ static void refCountChanged(Long address, boolean decRefCount, int rc) {
final Object owner = refCountOwner.get();
if (owner == SKIP_REF_COUNT_TRACKING) {
return;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
index 8577569..8a7d351 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ByteBufferInputStream.java
@@ -31,8 +31,8 @@ import java.nio.ByteOrder;
import com.gemstone.gemfire.internal.ByteBufferWriter;
import com.gemstone.gemfire.internal.HeapDataOutputStream;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
/**
* <p>
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ImmutableByteBufferInputStream.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ImmutableByteBufferInputStream.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ImmutableByteBufferInputStream.java
index 4f16c8a..52f332f 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ImmutableByteBufferInputStream.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tcp/ImmutableByteBufferInputStream.java
@@ -18,7 +18,7 @@ package com.gemstone.gemfire.internal.tcp;
import java.nio.ByteBuffer;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
/**
* You should only create an instance of this class if the bytes this buffer reads
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/util/BlobHelper.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/util/BlobHelper.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/util/BlobHelper.java
index 6665e55..7a4840e 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/util/BlobHelper.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/util/BlobHelper.java
@@ -27,7 +27,7 @@ import com.gemstone.gemfire.internal.DSCODE;
import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.Version;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
import com.gemstone.gemfire.pdx.internal.PdxInputStream;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/main/java/com/gemstone/gemfire/pdx/internal/PdxInputStream.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/pdx/internal/PdxInputStream.java b/gemfire-core/src/main/java/com/gemstone/gemfire/pdx/internal/PdxInputStream.java
index 66d4887..85e078d 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/pdx/internal/PdxInputStream.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/pdx/internal/PdxInputStream.java
@@ -26,7 +26,7 @@ import java.util.Date;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.InternalGemFireException;
import com.gemstone.gemfire.pdx.PdxSerializationException;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.tcp.ByteBufferInputStream;
import com.gemstone.gemfire.internal.tcp.ImmutableByteBufferInputStream;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ChunkValueWrapperJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ChunkValueWrapperJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ChunkValueWrapperJUnitTest.java
index 428b205..0606387 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ChunkValueWrapperJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ChunkValueWrapperJUnitTest.java
@@ -29,10 +29,10 @@ import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.internal.cache.DiskEntry.Helper.ChunkValueWrapper;
import com.gemstone.gemfire.internal.cache.DiskEntry.Helper.Flushable;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
index 727a59c..2889b0c 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
@@ -26,10 +26,10 @@ import org.junit.Test;
import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.cache.EntryEventImpl.OldValueImporter;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
import com.gemstone.gemfire.internal.util.BlobHelper;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
index 2d38a26..93f2039 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FreeListOffHeapRegionJUnitTest.java
+++ b/gemfire-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 SimpleMemoryAllocatorImpl.Chunk.OFF_HEAP_HEADER_SIZE;
+ return Chunk.OFF_HEAP_HEADER_SIZE;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
index 73fb51d..2f539d5 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
@@ -38,7 +38,6 @@ import com.gemstone.gemfire.compression.Compressor;
import com.gemstone.gemfire.compression.SnappyCompressor;
import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapValidationJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapValidationJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapValidationJUnitTest.java
index a47d42d..b9e8456 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapValidationJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapValidationJUnitTest.java
@@ -61,7 +61,6 @@ import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.Version;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
index e19f4cb..e371231 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
@@ -34,7 +34,6 @@ import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
index 3636c79..6e26b2f 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OldFreeListOffHeapRegionJUnitTest.java
+++ b/gemfire-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 SimpleMemoryAllocatorImpl.Chunk.OFF_HEAP_HEADER_SIZE;
+ return Chunk.OFF_HEAP_HEADER_SIZE;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
index 745d2c0..c8b1834 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorFillPatternJUnitTest.java
@@ -29,10 +29,8 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import static org.junit.Assert.*;
-
import junit.framework.TestCase;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
index ea90bdc..19dfebb 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorJUnitTest.java
@@ -31,7 +31,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.OutOfOffHeapMemoryException;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -46,7 +45,7 @@ public class SimpleMemoryAllocatorJUnitTest {
int TINY_MULTIPLE = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.TINY_MULTIPLE;
// int BIG_MULTIPLE = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.FreeListManager.BIG_MULTIPLE;
int HUGE_MULTIPLE = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.HUGE_MULTIPLE;
- int perObjectOverhead = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk.OFF_HEAP_HEADER_SIZE;
+ int perObjectOverhead = com.gemstone.gemfire.internal.offheap.Chunk.OFF_HEAP_HEADER_SIZE;
int maxTiny = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.MAX_TINY-perObjectOverhead;
// int MIN_BIG_SIZE = round(BIG_MULTIPLE, maxTiny+perObjectOverhead+1)-perObjectOverhead;
// int maxBig = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.FreeListManager.MAX_BIG-perObjectOverhead;
@@ -167,7 +166,7 @@ public class SimpleMemoryAllocatorJUnitTest {
@Test
public void testCompaction() {
- final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk.OFF_HEAP_HEADER_SIZE;
+ final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.Chunk.OFF_HEAP_HEADER_SIZE;
final int BIG_ALLOC_SIZE = 150000;
final int SMALL_ALLOC_SIZE = BIG_ALLOC_SIZE/2;
final int TOTAL_MEM = BIG_ALLOC_SIZE;
@@ -283,7 +282,7 @@ public class SimpleMemoryAllocatorJUnitTest {
boolean memoryUsageEventReceived;
@Test
public void testUsageEventListener() {
- final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk.OFF_HEAP_HEADER_SIZE;
+ final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.Chunk.OFF_HEAP_HEADER_SIZE;
final int SMALL_ALLOC_SIZE = 1000;
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(3000);
try {
@@ -326,7 +325,7 @@ public class SimpleMemoryAllocatorJUnitTest {
@Test
public void testOutOfOffHeapMemory() {
- final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk.OFF_HEAP_HEADER_SIZE;
+ final int perObjectOverhead = com.gemstone.gemfire.internal.offheap.Chunk.OFF_HEAP_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/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteBufferByteSourceJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteBufferByteSourceJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteBufferByteSourceJUnitTest.java
index b3a4ab5..c7c7b7b 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteBufferByteSourceJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteBufferByteSourceJUnitTest.java
@@ -22,8 +22,8 @@ import java.nio.ByteBuffer;
import org.junit.experimental.categories.Category;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.tcp.ByteBufferInputStream.ByteSource;
import com.gemstone.gemfire.internal.tcp.ByteBufferInputStream.ByteSourceFactory;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/419b017b/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteSourceJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteSourceJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteSourceJUnitTest.java
index d0e1986..543ef94 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteSourceJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/pdx/OffHeapByteSourceJUnitTest.java
@@ -20,12 +20,12 @@ import org.junit.After;
import org.junit.Before;
import org.junit.experimental.categories.Category;
+import com.gemstone.gemfire.internal.offheap.Chunk;
import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.Chunk;
import com.gemstone.gemfire.internal.tcp.ByteBufferInputStream.ByteSource;
import com.gemstone.gemfire.internal.tcp.ByteBufferInputStream.ByteSourceFactory;
import com.gemstone.gemfire.internal.tcp.ByteBufferInputStream.OffHeapByteSource;
[12/20] incubator-geode git commit: move ChunkWithHeapForm from
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move ChunkWithHeapForm 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/e7b29ce1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e7b29ce1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e7b29ce1
Branch: refs/heads/feature/GEODE-580
Commit: e7b29ce18d4fd244ee43a37ba00fd013b5c1d4e0
Parents: 2364dd1
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:55:35 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:55:35 2015 -0800
----------------------------------------------------------------------
.../internal/cache/AbstractRegionEntry.java | 3 +-
.../cache/wan/GatewaySenderEventImpl.java | 2 +-
.../internal/offheap/ChunkWithHeapForm.java | 40 ++++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 26 -------------
4 files changed, 43 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7b29ce1/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
index 55ecdb1..97c2371 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
@@ -62,6 +62,7 @@ import com.gemstone.gemfire.internal.logging.LogService;
import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
import com.gemstone.gemfire.internal.offheap.Chunk;
+import com.gemstone.gemfire.internal.offheap.ChunkWithHeapForm;
import com.gemstone.gemfire.internal.offheap.GemFireChunk;
import com.gemstone.gemfire.internal.offheap.MemoryAllocator;
import com.gemstone.gemfire.internal.offheap.OffHeapCachedDeserializable;
@@ -1347,7 +1348,7 @@ public abstract class AbstractRegionEntry implements RegionEntry,
val = ma.allocateAndInitialize(compressedData, isSerialized, isCompressed, GemFireChunk.TYPE); // TODO:KIRK:48068 race happens right after this line
SimpleMemoryAllocatorImpl.setReferenceCountOwner(null);
if (val instanceof GemFireChunk) {
- val = new com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkWithHeapForm((GemFireChunk)val, data);
+ val = new com.gemstone.gemfire.internal.offheap.ChunkWithHeapForm((GemFireChunk)val, data);
}
// if (val instanceof Chunk && r instanceof LocalRegion) {
// Chunk c = (Chunk) val;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7b29ce1/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
index fc234e3..f7bf976 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/wan/GatewaySenderEventImpl.java
@@ -51,10 +51,10 @@ import com.gemstone.gemfire.internal.cache.lru.Sizeable;
import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerHelper;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
import com.gemstone.gemfire.internal.offheap.Chunk;
+import com.gemstone.gemfire.internal.offheap.ChunkWithHeapForm;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.Releasable;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkWithHeapForm;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7b29ce1/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkWithHeapForm.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkWithHeapForm.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkWithHeapForm.java
new file mode 100644
index 0000000..d7e65f7
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/ChunkWithHeapForm.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * Used to keep the heapForm around while an operation is still in progress.
+ * This allows the operation to access the serialized heap form instead of copying
+ * it from offheap. See bug 48135.
+ */
+public class ChunkWithHeapForm extends GemFireChunk {
+ private final byte[] heapForm;
+
+ public ChunkWithHeapForm(GemFireChunk chunk, byte[] heapForm) {
+ super(chunk);
+ this.heapForm = heapForm;
+ }
+
+ @Override
+ protected byte[] getRawBytes() {
+ return this.heapForm;
+ }
+
+ public Chunk getChunkWithoutHeapForm() {
+ return new GemFireChunk(this);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e7b29ce1/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 a5de17e..98be355 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
@@ -1424,32 +1424,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
- /**
- * Used to keep the heapForm around while an operation is still in progress.
- * This allows the operation to access the serialized heap form instead of copying
- * it from offheap. See bug 48135.
- *
- * @author darrel
- *
- */
- public static class ChunkWithHeapForm extends GemFireChunk {
- private final byte[] heapForm;
-
- public ChunkWithHeapForm(GemFireChunk chunk, byte[] heapForm) {
- super(chunk);
- this.heapForm = heapForm;
- }
-
- @Override
- protected byte[] getRawBytes() {
- return this.heapForm;
- }
-
- public Chunk getChunkWithoutHeapForm() {
- return new GemFireChunk(this);
- }
- }
-
public static class FakeChunk extends Chunk {
private final int size;
public FakeChunk(int size) {
[03/20] incubator-geode git commit: move LifeCycleListener out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move LifeCycleListener out of 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/d4991d00
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/d4991d00
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/d4991d00
Branch: refs/heads/feature/GEODE-580
Commit: d4991d00395b020ba59d1f58a6a780ed61679e4e
Parents: f4dd17d
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:21:16 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:21:16 2015 -0800
----------------------------------------------------------------------
.../internal/offheap/LifecycleListener.java | 55 ++++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 38 --------------
...moryAllocatorLifecycleListenerJUnitTest.java | 1 -
3 files changed, 55 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d4991d00/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
new file mode 100644
index 0000000..b171408
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+/**
+ * Used by tests to get notifications about the lifecycle of a
+ * SimpleMemoryAllocatorImpl.
+ *
+ * @author Kirk Lund
+ */
+public interface LifecycleListener {
+ /**
+ * Callback is invoked after creating a new SimpleMemoryAllocatorImpl.
+ *
+ * Create occurs during the first initialization of an
+ * InternalDistributedSystem within the JVM.
+ *
+ * @param allocator the instance that has just been created
+ */
+ public void afterCreate(SimpleMemoryAllocatorImpl allocator);
+ /**
+ * Callback is invoked after reopening an existing SimpleMemoryAllocatorImpl
+ * for reuse.
+ *
+ * Reuse occurs during any intialization of an
+ * InternalDistributedSystem after the first one was connected and then
+ * disconnected within the JVM.
+ *
+ * @param allocator the instance that has just been reopened for reuse
+ */
+ public void afterReuse(SimpleMemoryAllocatorImpl allocator);
+ /**
+ * Callback is invoked before closing the SimpleMemoryAllocatorImpl
+ *
+ * Close occurs after the InternalDistributedSystem and DistributionManager
+ * have completely disconnected.
+ *
+ * @param allocator the instance that is about to be closed
+ */
+ public void beforeClose(SimpleMemoryAllocatorImpl allocator);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d4991d00/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 7288e55..5113cc3 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
@@ -3259,42 +3259,4 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
listener.beforeClose(allocator);
}
}
-
- /**
- * Used by tests to get notifications about the lifecycle of a
- * SimpleMemoryAllocatorImpl.
- *
- * @author Kirk Lund
- */
- public interface LifecycleListener {
- /**
- * Callback is invoked after creating a new SimpleMemoryAllocatorImpl.
- *
- * Create occurs during the first initialization of an
- * InternalDistributedSystem within the JVM.
- *
- * @param allocator the instance that has just been created
- */
- public void afterCreate(SimpleMemoryAllocatorImpl allocator);
- /**
- * Callback is invoked after reopening an existing SimpleMemoryAllocatorImpl
- * for reuse.
- *
- * Reuse occurs during any intialization of an
- * InternalDistributedSystem after the first one was connected and then
- * disconnected within the JVM.
- *
- * @param allocator the instance that has just been reopened for reuse
- */
- public void afterReuse(SimpleMemoryAllocatorImpl allocator);
- /**
- * Callback is invoked before closing the SimpleMemoryAllocatorImpl
- *
- * Close occurs after the InternalDistributedSystem and DistributionManager
- * have completely disconnected.
- *
- * @param allocator the instance that is about to be closed
- */
- public void beforeClose(SimpleMemoryAllocatorImpl allocator);
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d4991d00/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
index 38f969e..4ace307 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
@@ -26,7 +26,6 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.LifecycleListener;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
[16/20] incubator-geode git commit: moved all LifeCycleListener
static methods to that interface
Posted by ds...@apache.org.
moved all LifeCycleListener static methods to that interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/cd4ebb76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/cd4ebb76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/cd4ebb76
Branch: refs/heads/feature/GEODE-580
Commit: cd4ebb76c72b847293abdc085ce8599524ac7823
Parents: 8c5d5a7
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 16:35:51 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 16:35:51 2015 -0800
----------------------------------------------------------------------
.../internal/offheap/LifecycleListener.java | 43 ++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 52 ++------------------
...moryAllocatorLifecycleListenerJUnitTest.java | 8 +--
3 files changed, 51 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd4ebb76/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
index b171408..613b12a 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/LifecycleListener.java
@@ -16,6 +16,10 @@
*/
package com.gemstone.gemfire.internal.offheap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
/**
* Used by tests to get notifications about the lifecycle of a
* SimpleMemoryAllocatorImpl.
@@ -23,6 +27,7 @@ package com.gemstone.gemfire.internal.offheap;
* @author Kirk Lund
*/
public interface LifecycleListener {
+
/**
* Callback is invoked after creating a new SimpleMemoryAllocatorImpl.
*
@@ -52,4 +57,42 @@ public interface LifecycleListener {
* @param allocator the instance that is about to be closed
*/
public void beforeClose(SimpleMemoryAllocatorImpl allocator);
+
+ static void invokeBeforeClose(SimpleMemoryAllocatorImpl allocator) {
+ for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
+ LifecycleListener listener = iter.next();
+ listener.beforeClose(allocator);
+ }
+ }
+ static void invokeAfterReuse(SimpleMemoryAllocatorImpl allocator) {
+ for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
+ LifecycleListener listener = iter.next();
+ listener.afterReuse(allocator);
+ }
+ }
+ static void invokeAfterCreate(SimpleMemoryAllocatorImpl allocator) {
+ for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
+ LifecycleListener listener = iter.next();
+ listener.afterCreate(allocator);
+ }
+ }
+ /**
+ * Removes a LifecycleListener. Does nothing if the instance has not been added.
+ * @param listener the instance to remove
+ */
+ public static void removeLifecycleListener(LifecycleListener listener) {
+ lifecycleListeners.remove(listener);
+ }
+ /**
+ * Adds a LifecycleListener.
+ * @param listener the instance to add
+ */
+ public static void addLifecycleListener(LifecycleListener listener) {
+ LifecycleListener.lifecycleListeners.add(listener);
+ }
+
+ /**
+ * Following should be private but java 8 does not support that.
+ */
+ static final List<LifecycleListener> lifecycleListeners = new CopyOnWriteArrayList<LifecycleListener>();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd4ebb76/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 e761a10..b0d2b07 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
@@ -26,18 +26,14 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
-import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
@@ -50,7 +46,6 @@ import com.gemstone.gemfire.cache.CacheClosedException;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
import com.gemstone.gemfire.internal.cache.BucketRegion;
-import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
@@ -137,7 +132,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
result.reuse(ooohml, lw, stats, offHeapMemorySize);
lw.config("Reusing " + result.getTotalMemory() + " bytes of off-heap memory. The maximum size of a single off-heap object is " + result.largestSlab + " bytes.");
created = true;
- invokeAfterReuse(result);
+ LifecycleListener.invokeAfterReuse(result);
} else {
// allocate memory chunks
//SimpleMemoryAllocatorImpl.cleanupPreviousAllocator();
@@ -169,7 +164,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
result = new SimpleMemoryAllocatorImpl(ooohml, stats, slabs);
created = true;
singleton = result;
- invokeAfterCreate(result);
+ LifecycleListener.invokeAfterCreate(result);
}
} finally {
if (!created) {
@@ -183,7 +178,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
public static SimpleMemoryAllocatorImpl create(OutOfOffHeapMemoryListener oooml, OffHeapMemoryStats stats, UnsafeMemoryChunk[] slabs) {
SimpleMemoryAllocatorImpl result = new SimpleMemoryAllocatorImpl(oooml, stats, slabs);
singleton = result;
- invokeAfterCreate(result);
+ LifecycleListener.invokeAfterCreate(result);
return result;
}
@@ -437,7 +432,7 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
@Override
public void close() {
try {
- invokeBeforeClose(this);
+ LifecycleListener.invokeBeforeClose(this);
} finally {
this.ooohml.close();
if (Boolean.getBoolean(FREE_OFF_HEAP_MEMORY_PROPERTY)) {
@@ -1913,43 +1908,4 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
public static void forceCompaction() {
getAllocator().freeList.compact(0);
}
-
- private static final List<LifecycleListener> lifecycleListeners = new CopyOnWriteArrayList<LifecycleListener>();
-
- /**
- * Adds a LifecycleListener.
- * @param listener the instance to add
- */
- public static void addLifecycleListener(LifecycleListener listener) {
- lifecycleListeners.add(listener);
- }
-
- /**
- * Removes a LifecycleListener. Does nothing if the instance has not been added.
- * @param listener the instance to remove
- */
- public static void removeLifecycleListener(LifecycleListener listener) {
- lifecycleListeners.remove(listener);
- }
-
- static void invokeAfterCreate(SimpleMemoryAllocatorImpl allocator) {
- for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
- LifecycleListener listener = iter.next();
- listener.afterCreate(allocator);
- }
- }
-
- static void invokeAfterReuse(SimpleMemoryAllocatorImpl allocator) {
- for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
- LifecycleListener listener = iter.next();
- listener.afterReuse(allocator);
- }
- }
-
- static void invokeBeforeClose(SimpleMemoryAllocatorImpl allocator) {
- for (Iterator<LifecycleListener> iter = lifecycleListeners.iterator(); iter.hasNext();) {
- LifecycleListener listener = iter.next();
- listener.beforeClose(allocator);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cd4ebb76/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
index 4ace307..2df8656 100755
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorLifecycleListenerJUnitTest.java
@@ -44,7 +44,7 @@ public class SimpleMemoryAllocatorLifecycleListenerJUnitTest {
@After
public void tearDown() throws Exception {
- SimpleMemoryAllocatorImpl.removeLifecycleListener(this.listener);
+ LifecycleListener.removeLifecycleListener(this.listener);
this.afterCreateCallbacks.clear();
this.afterReuseCallbacks.clear();
this.beforeCloseCallbacks.clear();
@@ -53,8 +53,8 @@ public class SimpleMemoryAllocatorLifecycleListenerJUnitTest {
@Test
public void testAddRemoveListener() {
- SimpleMemoryAllocatorImpl.addLifecycleListener(this.listener);
- SimpleMemoryAllocatorImpl.removeLifecycleListener(this.listener);
+ LifecycleListener.addLifecycleListener(this.listener);
+ LifecycleListener.removeLifecycleListener(this.listener);
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[]{slab});
@@ -72,7 +72,7 @@ public class SimpleMemoryAllocatorLifecycleListenerJUnitTest {
@Test
public void testCallbacksAreCalledAfterCreate() {
- SimpleMemoryAllocatorImpl.addLifecycleListener(this.listener);
+ LifecycleListener.addLifecycleListener(this.listener);
UnsafeMemoryChunk slab = new UnsafeMemoryChunk(1024); // 1k
SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.create(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new UnsafeMemoryChunk[]{slab});
[10/20] incubator-geode git commit: remove GemFireChunkType
Posted by ds...@apache.org.
remove GemFireChunkType
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/84de9152
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/84de9152
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/84de9152
Branch: refs/heads/feature/GEODE-580
Commit: 84de915218af45059d859d57abd30e916bdd67c1
Parents: 4d10de4
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:50:38 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:50:38 2015 -0800
----------------------------------------------------------------------
.../internal/cache/AbstractRegionEntry.java | 1 -
.../offheap/SimpleMemoryAllocatorImpl.java | 21 --------------------
2 files changed, 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/84de9152/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
index cd6218a..55ecdb1 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionEntry.java
@@ -67,7 +67,6 @@ import com.gemstone.gemfire.internal.offheap.MemoryAllocator;
import com.gemstone.gemfire.internal.offheap.OffHeapCachedDeserializable;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunkType;
import com.gemstone.gemfire.internal.offheap.StoredObject;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/84de9152/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 7f2d6e8..0f91803 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
@@ -1450,27 +1450,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
}
- public static class GemFireChunkType extends ChunkType {
- private static final GemFireChunkType singleton = new GemFireChunkType();
- public static GemFireChunkType singleton() { return singleton; }
-
- private GemFireChunkType() {}
-
- @Override
- public int getSrcType() {
- return Chunk.SRC_TYPE_GFE;
- }
-
- @Override
- public Chunk newChunk(long memoryAddress) {
- return new GemFireChunk(memoryAddress);
- }
-
- @Override
- public Chunk newChunk(long memoryAddress, int chunkSize) {
- return new GemFireChunk(memoryAddress, chunkSize);
- }
- }
public static class GemFireChunkSlice extends GemFireChunk {
private final int offset;
private final int capacity;
[07/20] incubator-geode git commit: move GemFireChunkFactory out of
SimpleMemoryAllocatorImpl
Posted by ds...@apache.org.
move GemFireChunkFactory out of 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/b4cbd4a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/b4cbd4a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/b4cbd4a6
Branch: refs/heads/feature/GEODE-580
Commit: b4cbd4a6d0d4953a5b51b8acd1f6dcabfe7bced6
Parents: 9d5905d
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Thu Nov 19 15:41:13 2015 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Thu Nov 19 15:41:13 2015 -0800
----------------------------------------------------------------------
.../internal/offheap/GemFireChunkFactory.java | 54 ++++++++++++++++++++
.../offheap/SimpleMemoryAllocatorImpl.java | 32 ------------
2 files changed, 54 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b4cbd4a6/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
new file mode 100644
index 0000000..b60013d
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/GemFireChunkFactory.java
@@ -0,0 +1,54 @@
+/*
+ * 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 com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.ChunkType;
+import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.GemFireChunk;
+
+/**
+ * A ChunkFactory that produces chunks of type GemFireChunk.
+ */
+public class GemFireChunkFactory implements ChunkFactory {
+ @Override
+ public Chunk newChunk(long address, int chunkSize, ChunkType chunkType) {
+ assert chunkType.equals(GemFireChunk.TYPE);
+ return new GemFireChunk(address,chunkSize);
+ }
+
+ @Override
+ public Chunk newChunk(long address) {
+ return new GemFireChunk(address);
+ }
+
+ @Override
+ public Chunk newChunk(long address, ChunkType chunkType) {
+ assert chunkType.equals(GemFireChunk.TYPE);
+ return new GemFireChunk(address);
+ }
+
+ @Override
+ public ChunkType getChunkTypeForAddress(long address) {
+ assert Chunk.getSrcType(address) == Chunk.SRC_TYPE_GFE;
+ return GemFireChunk.TYPE;
+ }
+
+ @Override
+ public ChunkType getChunkTypeForRawBits(int bits) {
+ assert Chunk.getSrcTypeFromRawBits(bits) == Chunk.SRC_TYPE_GFE;
+ return GemFireChunk.TYPE;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b4cbd4a6/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 86cba3b..c13842a 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
@@ -1424,38 +1424,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator, MemoryI
}
- private static class GemFireChunkFactory implements ChunkFactory {
- @Override
- public Chunk newChunk(long address, int chunkSize, ChunkType chunkType) {
- assert chunkType.equals(GemFireChunk.TYPE);
- return new GemFireChunk(address,chunkSize);
- }
-
- @Override
- public Chunk newChunk(long address) {
- return new GemFireChunk(address);
- }
-
- @Override
- public Chunk newChunk(long address, ChunkType chunkType) {
- assert chunkType.equals(GemFireChunk.TYPE);
- return new GemFireChunk(address);
- }
-
- @Override
- public ChunkType getChunkTypeForAddress(long address) {
- assert Chunk.getSrcType(address) == Chunk.SRC_TYPE_GFE;
- return GemFireChunk.TYPE;
- }
-
- @Override
- public ChunkType getChunkTypeForRawBits(int bits) {
- assert Chunk.getSrcTypeFromRawBits(bits) == Chunk.SRC_TYPE_GFE;
- return GemFireChunk.TYPE;
- }
- }
-
-
/**
* Used to keep the heapForm around while an operation is still in progress.
* This allows the operation to access the serialized heap form instead of copying