@Override public MemoryChunk allocate(int size, ChunkType chunkType) { //System.out.println("allocating " + size); Chunk result = this.freeList.allocate(size, chunkType); //("allocated off heap object of size " + size + " @" + Long.toHexString(result.getMemoryAddress()), true); if (ReferenceCountHelper.trackReferenceCounts()) { ReferenceCountHelper.refCountChanged(result.getMemoryAddress(), false, 1); } return result; }
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 (ReferenceCountHelper.trackReferenceCounts()) { ReferenceCountHelper.refCountChanged(memAddr, false, uc+1); } return true; } public static void release(final long memAddr, boolean issueOnReturnCallback) {
ReferenceCountHelper.refCountChanged(memAddr, true, newCount&REF_COUNT_MASK); } else { if (ReferenceCountHelper.trackReferenceCounts()) { ReferenceCountHelper.refCountChanged(memAddr, true, newCount&REF_COUNT_MASK);
@Override public StoredObject allocateAndInitialize(byte[] v, boolean isSerialized, boolean isCompressed, ChunkType chunkType) { long addr = OffHeapRegionEntryHelper.encodeDataAsAddress(v, isSerialized, isCompressed); if (addr != 0L) { return new DataAsAddress(addr); } if (chunkType == null) { chunkType = GemFireChunk.TYPE; } Chunk result = this.freeList.allocate(v.length, chunkType); //debugLog("allocated off heap object of size " + v.length + " @" + Long.toHexString(result.getMemoryAddress()), true); //debugLog("allocated off heap object of size " + v.length + " @" + Long.toHexString(result.getMemoryAddress()) + "chunkSize=" + result.getSize() + " isSerialized=" + isSerialized + " v=" + Arrays.toString(v), true); if (ReferenceCountHelper.trackReferenceCounts()) { ReferenceCountHelper.refCountChanged(result.getMemoryAddress(), false, 1); } assert result.getChunkType() == chunkType: "chunkType=" + chunkType + " getChunkType()=" + result.getChunkType(); result.setSerializedValue(v); result.setSerialized(isSerialized); result.setCompressed(isCompressed); return result; }