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() {
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() {
public static byte[] getBaseRowBytes(final UnsafeWrapper unsafe, final long baseAddr, final int bytesLen) { // If the row does not have any lobs, the offheap byte source is not // serialized, else it is serialized byte[] result = new byte[bytesLen]; UnsafeMemoryChunk.readUnsafeBytes(unsafe, baseAddr, result, bytesLen); SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads(); 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() {
@Override public ChunkType getChunkType() { return getAllocator().getChunkFactory().getChunkTypeForAddress(getMemoryAddress()); } public static int getSrcTypeOrdinal(long memAddr) {
@Override public ChunkType getChunkType() { return SimpleMemoryAllocatorImpl.getAllocator().getChunkFactory().getChunkTypeForAddress(getMemoryAddress()); } public static int getSrcTypeOrdinal(long memAddr) {
@Override public void writeByte(int offset, byte value) { assert offset >= 0 && offset < getDataSize(): "Offset=" + offset + ", dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset must be < dataSize"; UnsafeMemoryChunk.writeAbsoluteByte(getBaseDataAddress() + offset, value); }
@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 (trackRefCounts) { refCountChanged(result.getMemoryAddress(), false, 1); } return result; }
public static long getNext(long memAddr) { validateAddress(memAddr); return UnsafeMemoryChunk.readAbsoluteLong(memAddr+OFF_HEAP_HEADER_SIZE); } public static void setNext(long memAddr, long next) {
public static int getSize(long memAddr) { SimpleMemoryAllocatorImpl.validateAddress(memAddr); return UnsafeMemoryChunk.readAbsoluteInt(memAddr+CHUNK_SIZE_OFFSET); } public static void setSize(long memAddr, int size) {
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) {
public void testParseOffHeapMemorySizeBytes() { assertEquals(MEGABYTE, OffHeapStorage.parseOffHeapMemorySize("1")); assertEquals(Integer.MAX_VALUE * MEGABYTE, OffHeapStorage.parseOffHeapMemorySize("" + Integer.MAX_VALUE)); } public void testParseOffHeapMemorySizeKiloBytes() {
@Override public byte readByte(int offset) { assert SimpleMemoryAllocatorImpl.validateAddressAndSizeWithinSlab(this.data+offset, 1); return readAbsoluteByte(this.data+offset); }
@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; }
@Override public void writeByte(int offset, byte value) { assert offset < getDataSize(); UnsafeMemoryChunk.writeAbsoluteByte(getBaseDataAddress() + offset, value); }
@Override public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) { assert offset+size <= getDataSize(); UnsafeMemoryChunk.writeAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size); }
void notifyListeners() { final MemoryUsageListener[] savedListeners = this.memoryUsageListeners; if (savedListeners.length == 0) { return; } final long bytesUsed = getUsedMemory(); for (int i = 0; i < savedListeners.length; i++) { savedListeners[i].updateMemoryUsed(bytesUsed); } }
public static byte[] getBaseRowBytes(final UnsafeWrapper unsafe, final long baseAddr, final int bytesLen) { // If the row does not have any lobs, the offheap byte source is not // serialized, else it is serialized byte[] result = new byte[bytesLen]; UnsafeMemoryChunk.readUnsafeBytes(unsafe, baseAddr, result, bytesLen); SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads(); return result; }
public void testParseOffHeapMemorySizeGigaBytes() { assertEquals(GIGABYTE, OffHeapStorage.parseOffHeapMemorySize("1g")); assertEquals(Integer.MAX_VALUE * GIGABYTE, OffHeapStorage.parseOffHeapMemorySize("" + Integer.MAX_VALUE + "g")); } }
public static byte[] getBaseRowBytes(final long baseAddr, final int bytesLen) { // If the row does not have any lobs, the offheap byte source is not // serialized, else it is serialized byte[] result = new byte[bytesLen]; UnsafeMemoryChunk.readUnsafeBytes(baseAddr, result, bytesLen); SimpleMemoryAllocatorImpl.getAllocator().getStats().incReads(); return result; }