/** * @param addr Address. * @param off Offset. * @return Value. */ public static long getLong(long addr, int off) { assert addr > 0 : addr; assert off >= 0; return GridUnsafe.getLong(addr + off); }
/** {@inheritDoc} */ @Override protected long readLongFast() { long off = GridUnsafe.BYTE_ARR_OFF + pos; return BIG_ENDIAN ? GridUnsafe.getLongLE(data, off) : GridUnsafe.getLong(data, off); }
/** * @param base Bucket base address. * @return value stored in bucket. */ private long getValue(long base) { return getLong(base + VALUE_OFFSET); }
/** * @param ptr Pointer. * @param off Offset. * @return Value. */ public static long readLong(long ptr, int off) { long addr = ptr + off; return BIG_ENDIAN ? GridUnsafe.getLongLE(addr) : GridUnsafe.getLong(addr); }
/** * @param addr Address of buffer start. * @return Saved value in {@link TrackingPageIO#LAST_SNAPSHOT_TAG_OFFSET}. */ private long getLastSnapshotTag0(long addr) { return GridUnsafe.getLong(addr + LAST_SNAPSHOT_TAG_OFFSET); }
/** {@inheritDoc} */ @Override protected long readLongFast() { long addr = ptr + pos; return BIG_ENDIAN ? GridUnsafe.getLongLE(addr) : GridUnsafe.getLong(addr); }
/** * @param base Address of current cell. * @return Page ID saved in cell. */ private long getPageId(long base) { return getLong(base + PAGE_ID_OFFSET); }
/** {@inheritDoc} */ @Override public long readLong() throws IOException { fromStream(8); long off = BYTE_ARR_OFF + offset(8); return BIG_ENDIAN ? GridUnsafe.getLongLE(buf, off) : GridUnsafe.getLong(buf, off); }
/** * Read for timestamp from page in {@code absAddr} address. * * @param absPtr Absolute page address. * @return Timestamp. */ private static long readTimestamp(final long absPtr) { long markerAndTs = GridUnsafe.getLong(absPtr); // Clear last byte as it is occupied by page marker. return markerAndTs & ~0xFF; }
/** * Gets pointer to checkpoint buffer or {@link #INVALID_REL_PTR} if page is not copied to checkpoint buffer. * * @param absPtr Page absolute pointer. * @return Temp buffer relative pointer. */ private static long tempBufferPointer(long absPtr) { return GridUnsafe.getLong(absPtr + PAGE_TMP_BUF_OFFSET); }
/** * @param idx Item number. * @return Update counter delta. */ public long updatesCount(int idx){ if (idx >= size) throw new ArrayIndexOutOfBoundsException(); long off = GridUnsafe.BYTE_ARR_OFF + idx * ITEM_SIZE + 12; return GridUnsafe.getLong(data, off); }
/** * @param absPtr Absolute pointer. * @param flag Flag mask. * @return Flag value. */ private static boolean flag(long absPtr, long flag) { assert (flag & 0xFFFFFFFFFFFFFFL) == 0; assert Long.bitCount(flag) == 1; long relPtrWithFlags = GridUnsafe.getLong(absPtr + RELATIVE_PTR_OFFSET); return (relPtrWithFlags & flag) != 0; }
/** {@inheritDoc} */ @Override public long readLong() { lastFinished = buf.remaining() >= 8; if (lastFinished) { int pos = buf.position(); buf.position(pos + 8); return GridUnsafe.getLong(heapArr, baseOff + pos); } else return 0; }
/** * @param ptr Pointer to update. * @param delta Delta. */ private static long updateAtomicLong(long ptr, long delta) { while (true) { long old = GridUnsafe.getLong(ptr); long updated = old + delta; if (GridUnsafe.compareAndSwapLong(null, ptr, old, updated)) return updated; } }
/** {@inheritDoc} */ @Override public long getLong(int idx) { ensure(idx, 8); return GridUnsafe.getLong(ptr + idx); }
/** * @param index Entry index. * @return Value. */ private long valueAt(int index) { return GridUnsafe.getLong(entryBase(index) + VALUE_OFFSET); }
/** {@inheritDoc} */ @Override public void forEach(BiConsumer<FullPageId, Long> act) { for (int i = 0; i < capacity; i++) { if (isValuePresentAt(i)) { long base = entryBase(i); int cacheId = GridUnsafe.getInt(base); long pageId = GridUnsafe.getLong(base + PAGE_ID_OFFSET); long val = GridUnsafe.getLong(base + VALUE_OFFSET); act.accept(new FullPageId(pageId, cacheId), val); } } }
/** {@inheritDoc} */ @Override public long readLong() { ensureEnoughData(8); long res = GridUnsafe.getLong(data + pos); shift(8); return res; }
/** * @param idx cell index, normalized. * @return {@code true} if cell with index idx has state 'Empty'. */ private boolean isEmpty(int idx) { long base = entryBase(idx); int grpId = GridUnsafe.getInt(base); long pageId = GridUnsafe.getLong(base + PAGE_ID_OFFSET); return isEmpty(grpId, pageId); }
/** * @param idx Index to test. * @return {@code True} if value set for index. */ private boolean isValuePresentAt(final int idx) { long base = entryBase(idx); int grpId = GridUnsafe.getInt(base); long pageId = GridUnsafe.getLong(base + PAGE_ID_OFFSET); return !isRemoved(grpId, pageId) && !isEmpty(grpId, pageId); }