private ByteBuffer readKeyBuffer(long encoding) { int keyLength = readKeySize(encoding); int elemLength = readElementLength(encoding + this.totalChainHeaderSize); return storage.readBuffer(encoding + this.totalChainHeaderSize + ELEMENT_HEADER_SIZE + elemLength, keyLength); }
if (relocated >= 0) { if (relocated < target) { writeBuffer(relocated, readBuffer(target, sizeOfArea)); owner.moved(target, relocated); allocator.free(target);
protected ByteBuffer getExtensionHeader(long chainAddress) { checkExtensionHeaderExists(); return storage.readBuffer(toExtensionAddress(chainAddress), extendedChainHeaderSize); }
if (relocated >= 0) { if (relocated < target) { writeBuffer(relocated, readBuffer(target, sizeOfArea)); owner.moved(target, relocated); allocator.free(target);
@Override public ByteBuffer readBinaryValue(long chain) { // first get total element size and allocate buffer long element = chain + this.totalChainHeaderSize; int totalLength = DETACHED_CONTIGUOUS_CHAIN_HEADER_SIZE; do { totalLength += ELEMENT_HEADER_SIZE + readElementLength(element); element = storage.readLong(element + ELEMENT_HEADER_NEXT_OFFSET); } while (element != chain); final ByteBuffer detachedContiguousBuffer = ByteBuffer.allocate(totalLength); // one way for layers above to extract encoding is to put the encoding of the chain address in the value detachedContiguousBuffer.putLong(chain); // now add the elements to the buffer element = chain + this.totalChainHeaderSize; do { final int startPosition = detachedContiguousBuffer.position(); detachedContiguousBuffer.put(storage.readBuffer(element, ELEMENT_HEADER_SIZE + readElementLength(element))); detachedContiguousBuffer.mark(); detachedContiguousBuffer.putLong(startPosition + ELEMENT_HEADER_NEXT_OFFSET, -1L); detachedContiguousBuffer.reset(); element = storage.readLong(element + ELEMENT_HEADER_NEXT_OFFSET); } while (element != chain); return (ByteBuffer)detachedContiguousBuffer.flip(); }
void replayIntoMap(ReadWriteLockedOffHeapClockCache<K, InternalChain> newMap) { Lock l = newMap.writeLock(); l.lock(); try { chainAddresses.forEach((a) -> { ExtendedHeaderForTest hdr = createAtExtensionAddress(a); long address = hdr.getAddress(); int keyLength = extendedArea.readInt(address + STORAGE_KEY_LENGTH_OFFSET); int valueLength = extendedArea.readInt(address + STORAGE_VALUE_LENGTH_OFFSET); ByteBuffer keyBuffer = extendedArea.readBuffer(address + STORAGE_HEADER_OFFSET, keyLength); ByteBuffer valueBuffer = extendedArea.readBuffer(address + STORAGE_HEADER_OFFSET + keyLength, valueLength); newMap.installMappingForHashAndEncoding(hdr.getHash(), keyBuffer, valueBuffer, 0); }); } finally { l.unlock(); } }
@Override public ByteBuffer readKeyBuffer(long address) { int length = storageArea.readInt(address + KEY_LENGTH_OFFSET); return storageArea.readBuffer(address + DATA_OFFSET, length).asReadOnlyBuffer(); }
@Override public ByteBuffer readKeyBuffer(long address) { int length = storageArea.readInt(address + KEY_LENGTH_OFFSET); return storageArea.readBuffer(address + DATA_OFFSET, length).asReadOnlyBuffer(); }
@Override protected ByteBuffer readBuffer(int address) { int length = storageArea.readInt(address + LENGTH_OFFSET); return storageArea.readBuffer(address + DATA_OFFSET, length); }
@Override protected ByteBuffer readBuffer(int address) { int length = storageArea.readInt(address + LENGTH_OFFSET); return storageArea.readBuffer(address + DATA_OFFSET, length); }
@Override public ByteBuffer readValueBuffer(long address) { int keyLength = storageArea.readInt(address + KEY_LENGTH_OFFSET); int valueLength = storageArea.readInt(address + VALUE_LENGTH_OFFSET); return storageArea.readBuffer(address + DATA_OFFSET + keyLength, valueLength).asReadOnlyBuffer(); }
@Override public ByteBuffer readValueBuffer(long address) { int keyLength = storageArea.readInt(address + KEY_LENGTH_OFFSET); int valueLength = storageArea.readInt(address + VALUE_LENGTH_OFFSET); return storageArea.readBuffer(address + DATA_OFFSET + keyLength, valueLength).asReadOnlyBuffer(); }