/** * Frees a random chunk from the Chunk list. */ private void free() { Chunk chunk = chunks.remove(random.nextInt(chunks.size())); totalAllocation -= chunk.getSize(); /* * Chunk is filled here but another thread may have already grabbed it so we * cannot validate the fill. */ chunk.release(); }
/** * Frees a random chunk from the Chunk list. */ private void free() { Chunk chunk = chunks.remove(random.nextInt(chunks.size())); totalAllocation -= chunk.getSize(); /* * Chunk is filled here but another thread may have already grabbed it so we * cannot validate the fill. */ chunk.release(); }
@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; }
/** * Allocates a chunk and adds it to the thread's Chunk list. */ private void allocate() { int allocation = allocationSize(); Chunk chunk = (Chunk) allocator.allocate(allocation, null); // This should always work just after allocation chunk.validateFill(allocator.TINY_MULTIPLE); chunks.add(chunk); totalAllocation += chunk.getSize(); }
@Override public int getSizeInBytes() { int size = super.getSizeInBytes(); int numLobs = readNumLobsColumns(false); for (int i = 1; i <= numLobs; ++i) { long address = readAddressForLob(i); if (address != 0l && OffHeapRegionEntryHelper.isOffHeap(address)) { size += Chunk.getSize(address); } } return size; }
@Override public int getSizeInBytes() { int size = super.getSizeInBytes(); int numLobs = readNumLobsColumns(false); for (int i = 1; i <= numLobs; ++i) { long address = readAddressForLob(i); if (address != 0l && OffHeapRegionEntryHelper.isOffHeap(address)) { size += Chunk.getSize(address); } } return size; }
/** * 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); }
/** * Just get the length of each lob fields instead of creating a * OffHeapByteSource object. see ObjectSizer where a scan periodically tries * to estimate the valueSize. */ public int getLobDataSizeLength(int index) { long address = readAddressForLob(index); if (address != 0x0L && OffHeapRegionEntryHelper.isOffHeap(address)) { return Chunk.getSize(address); } return 0; }
@Override public int getBlockSize() { return getSize(); } @Override
@Override public void readBytes(int offset, byte[] bytes, int bytesOffset, int size) { assert offset >= 0 && offset + size <= getDataSize(): "Offset=" + offset + ",size=" + size + ",dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset + size must be <= " + getDataSize(); UnsafeMemoryChunk.readAbsoluteBytes(getBaseDataAddress(), offset, bytes, bytesOffset, size); }
/** * Allocates a chunk and adds it to the thread's Chunk list. */ private void allocate() { int allocation = allocationSize(); Chunk chunk = (Chunk) allocator.allocate(allocation, null); // This should always work just after allocation chunk.validateFill(allocator.TINY_MULTIPLE); chunks.add(chunk); totalAllocation += chunk.getSize(); }
@Override public int getSizeInBytes() { int size = super.getSizeInBytes(); int numLobs = readNumLobsColumns(false); for (int i = 1; i <= numLobs; ++i) { long address = readAddressForLob(i); if (address != 0l && OffHeapRegionEntryHelper.isOffHeap(address)) { size += Chunk.getSize(address); } } return size; }
@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); }
public long getFreeHugeMemory() { long hugeFree = 0; for (Chunk c: this.hugeChunkSet) { hugeFree += c.getSize(); } return hugeFree; } // private int getNearestBigMultiple(int size) {
/** * Just get the length of each lob fields instead of creating a * OffHeapByteSource object. see ObjectSizer where a scan periodically tries * to estimate the valueSize. */ public int getLobDataSizeLength(int index) { long address = readAddressForLob(index); if (address != 0x0L && OffHeapRegionEntryHelper.isOffHeap(address)) { return Chunk.getSize(address); } return 0; }
/** * Just get the length of each lob fields instead of creating a * OffHeapByteSource object. see ObjectSizer where a scan periodically tries * to estimate the valueSize. */ public int getLobDataSizeLength(int index) { long address = readAddressForLob(index); if (address != 0x0L && OffHeapRegionEntryHelper.isOffHeap(address)) { return Chunk.getSize(address); } return 0; }
@Override public void writeBytes(int offset, byte[] bytes, int bytesOffset, int size) { assert offset >= 0 && offset + size <= getDataSize(): "Offset=" + offset + ",size=" + size + ",dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset + size must be <= " + getDataSize(); UnsafeMemoryChunk.writeAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size); }
@Override public byte readByte(int offset) { assert offset >= 0 && offset < getDataSize(): "Offset=" + offset + ", dataSize=" + getDataSize() + ", chunkSize=" + getSize() + ", but offset must be < dataSize"; return UnsafeMemoryChunk.readAbsoluteByte(getBaseDataAddress() + offset); }
private void logHugeState(LogWriter lw) { for (Chunk c: this.hugeChunkSet) { lw.info("Free huge of size " + c.getSize()); } } // private void logBigState(LogWriter lw) {
/** * 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(); }