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); }
@Override public int getLength() { return this.chunk.getDataSize(); } @Override
@Override public int getValueSizeInBytes() { return getDataSize(); }
@Override public int capacity() { return this.chunk.getDataSize(); }
/** * 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 readBytes(int offset, byte[] bytes, int bytesOffset, int size) { assert offset+size <= getDataSize(); UnsafeMemoryChunk.readAbsoluteBytes(getBaseDataAddress() + offset, bytes, bytesOffset, size); }
@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); }
protected String toStringForOffHeapByteSource() { return super.toString() + ":<dataSize=" + getDataSize() + " refCount=" + getRefCount() + " addr=" + Long.toHexString(getMemoryAddress()) + ">"; }
/** * 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 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() {
int len = c.getDataSize(); long addr = c.getAddressForReading(0, len); buf.clear();
/** * 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() {
buf.put(bb); } else { int bytesToSend = c.getDataSize(); long addr = c.getAddressForReading(0, bytesToSend); while (bytesToSend > 0) {
/** * A blob is a serialized Object. This method * returns the deserialized object. * If a PdxInstance is returned then it will refer to Chunk's off-heap memory * with an unretained reference. */ public static @Unretained Object deserializeOffHeapBlob(Chunk blob) throws IOException, ClassNotFoundException { Object result; final long start = startDeserialization(); // For both top level and nested pdxs we just want a reference to this off-heap blob. // No copies. // For non-pdx we want a stream that will read directly from the chunk. PdxInputStream is = new PdxInputStream(blob); result = DataSerializer.readObject(is); endDeserialization(start, blob.getDataSize()); return result; }
HeapDataOutputStream.writeByteBufferToStream(out, buf, cbb); } else { int bytesToSend = c.getDataSize(); long addr = c.getAddressForReading(0, bytesToSend); while (bytesToSend > 0) {