@Test @DisplayName("getIntVolatile(long) && putIntVolatile(long, int)") void getIntVolatile_putIntVolatile() { val address = assumeAllocate(Integer.BYTES); val delta = 1 + random.nextInt(Integer.MAX_VALUE); val softly = new SoftAssertions(); val value = mmanager.getIntVolatile(address); mmanager.putIntVolatile(address, delta); softly.assertThat(mmanager.getIntVolatile(address)).isEqualTo(delta); mmanager.putIntVolatile(address, value + delta); softly.assertThat(mmanager.getIntVolatile(address)).isEqualTo(value + delta); mmanager.putIntVolatile(address, value); softly.assertThat(mmanager.getIntVolatile(address)).isEqualTo(value); mmanager.free(address, Integer.BYTES, false, false); softly.assertAll(); }
@Override @SuppressWarnings("BooleanParameter") public void free(long address, long bytes, final boolean huge, final boolean lock) { if (!OPTIMIZED) { if (unsafe == null) throw new NullPointerException("The Unsafe object is not available."); if (address == 0) throw new IllegalArgumentException("The parameter 'address' MUST NOT be 0."); if (bytes <= 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); } if (huge) { if (hugepageSize <= 0) { if (DEBUG >= LOG_TRACE) log.trace("Freeing {} hugepage-based bytes @ 0x{}.", bytes, leftPad(address)); return; } if (DEBUG >= LOG_TRACE) { val xaddressCopy = leftPad(address); val bytesCopy = bytes; val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; log.trace("Freeing {} hugepage-based bytes @ 0x{} (originally {} bytes @ 0x{}).", bytes, leftPad(address), bytesCopy, xaddressCopy); } else { val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; } } else { unsafe.freeMemory(address); return; } c_free(address, bytes, huge, lock); }
SmartUnsafeMemoryManager extends UnsafeMemoryManager { @Override @SuppressWarnings("BooleanParameter") public void free(long address, long bytes, final boolean huge, final boolean lock) { if (!OPTIMIZED) { if (unsafe == null) throw new NullPointerException("The Unsafe object is not available."); if (address == 0) throw new IllegalArgumentException("The parameter 'address' MUST NOT be 0."); if (bytes <= 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); } if (huge) { if (hugepageSize <= 0) { if (DEBUG >= LOG_TRACE) log.trace("Freeing {} hugepage-based bytes @ 0x{}.", bytes, leftPad(address)); return; } if (DEBUG >= LOG_TRACE) { val xaddressCopy = leftPad(address); val bytesCopy = bytes; val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; log.trace("Freeing {} hugepage-based bytes @ 0x{} (originally {} bytes @ 0x{}).", bytes, leftPad(address), bytesCopy, xaddressCopy); } else { val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; } } else { unsafe.freeMemory(address); return; } c_free(address, bytes, huge, lock); } }
SmartUnsafeMemoryManager extends UnsafeMemoryManager { @Override @SuppressWarnings("BooleanParameter") public void free(long address, long bytes, final boolean huge, final boolean lock) { if (!OPTIMIZED) { if (unsafe == null) throw new NullPointerException("The Unsafe object is not available."); if (address == 0) throw new IllegalArgumentException("The parameter 'address' MUST NOT be 0."); if (bytes <= 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); } if (huge) { if (hugepageSize <= 0) { if (DEBUG >= LOG_TRACE) log.trace("Freeing {} hugepage-based bytes @ 0x{}.", bytes, leftPad(address)); return; } if (DEBUG >= LOG_TRACE) { val xaddressCopy = leftPad(address); val bytesCopy = bytes; val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; log.trace("Freeing {} hugepage-based bytes @ 0x{} (originally {} bytes @ 0x{}).", bytes, leftPad(address), bytesCopy, xaddressCopy); } else { val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; } } else { unsafe.freeMemory(address); return; } c_free(address, bytes, huge, lock); } private  SmartUnsafeMemoryManager(); }
SmartUnsafeMemoryManager extends UnsafeMemoryManager { @Override @SuppressWarnings("BooleanParameter") public void free(long address, long bytes, final boolean huge, final boolean lock) { if (!OPTIMIZED) { if (unsafe == null) throw new NullPointerException("The Unsafe object is not available."); if (address == 0) throw new IllegalArgumentException("The parameter 'address' MUST NOT be 0."); if (bytes <= 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); } if (huge) { if (hugepageSize <= 0) { if (DEBUG >= LOG_TRACE) log.trace("Freeing {} hugepage-based bytes @ 0x{}.", bytes, leftPad(address)); return; } if (DEBUG >= LOG_TRACE) { val xaddressCopy = leftPad(address); val bytesCopy = bytes; val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; log.trace("Freeing {} hugepage-based bytes @ 0x{} (originally {} bytes @ 0x{}).", bytes, leftPad(address), bytesCopy, xaddressCopy); } else { val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; } } else { unsafe.freeMemory(address); return; } c_free(address, bytes, huge, lock); } private  SmartUnsafeMemoryManager(); @Override @Contract(pure = true) boolean isValid(); @Override @Contract(pure = true) long getPageSize(); @Override @Contract(value = " -> fail", pure = true) @SuppressWarnings({"deprecation", "PMD.DataflowAnomalyAnalysis"}) long getHugepageSize(); @Override @Contract(pure = true) @SuppressWarnings("BooleanParameter") long allocate(long bytes, boolean huge, boolean lock); @Override @SuppressWarnings("BooleanParameter") void free(long address, long bytes, final boolean huge, final boolean lock); @Override @Contract(pure = true) @SuppressWarnings({"deprecation", "BooleanParameter", "IOResourceOpenedButNotSafelyClosed", "resource"}) long mmap(final @NotNull File file, final boolean huge, final boolean lock); @Override @SuppressWarnings({"deprecation", "BooleanParameter", "PMD.DataflowAnomalyAnalysis"}) void munmap(final long address, final @NotNull File file, final boolean huge, final boolean lock); @Override @Contract(pure = true) @SuppressWarnings("deprecation") @SuppressFBWarnings("") long virt2phys(final long address); @Override @Contract(value = "_, _, _ -> fail", pure = true) @SuppressWarnings({"deprecation", "BooleanParameter"}) @NotNull DmaMemory dmaAllocate(final long bytes, final boolean huge, final boolean lock); }
SmartUnsafeMemoryManager extends UnsafeMemoryManager { @Override @SuppressWarnings("BooleanParameter") public void free(long address, long bytes, final boolean huge, final boolean lock) { if (!OPTIMIZED) { if (unsafe == null) throw new NullPointerException("The Unsafe object is not available."); if (address == 0) throw new IllegalArgumentException("The parameter 'address' MUST NOT be 0."); if (bytes <= 0) throw new IllegalArgumentException("The parameter 'bytes' MUST be positive."); } if (huge) { if (hugepageSize <= 0) { if (DEBUG >= LOG_TRACE) log.trace("Freeing {} hugepage-based bytes @ 0x{}.", bytes, leftPad(address)); return; } if (DEBUG >= LOG_TRACE) { val xaddressCopy = leftPad(address); val bytesCopy = bytes; val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; log.trace("Freeing {} hugepage-based bytes @ 0x{} (originally {} bytes @ 0x{}).", bytes, leftPad(address), bytesCopy, xaddressCopy); } else { val mask = (hugepageSize - 1); address = (address & mask) == 0 ? address : address & ~mask; bytes = (bytes & mask) == 0 ? bytes : (bytes + hugepageSize) & ~mask; } } else { unsafe.freeMemory(address); return; } c_free(address, bytes, huge, lock); } private  SmartUnsafeMemoryManager(); @Override @Contract(pure = true) boolean isValid(); @Override @Contract(pure = true) long getPageSize(); @Override @Contract(value = " -> fail", pure = true) @SuppressWarnings({"deprecation", "PMD.DataflowAnomalyAnalysis"}) long getHugepageSize(); @Override @Contract(pure = true) @SuppressWarnings("BooleanParameter") long allocate(long bytes, boolean huge, boolean lock); @Override @SuppressWarnings("BooleanParameter") void free(long address, long bytes, final boolean huge, final boolean lock); @Override @Contract(pure = true) @SuppressWarnings({"deprecation", "BooleanParameter", "IOResourceOpenedButNotSafelyClosed", "resource"}) long mmap(final @NotNull File file, final boolean huge, final boolean lock); @Override @SuppressWarnings({"deprecation", "BooleanParameter", "PMD.DataflowAnomalyAnalysis"}) void munmap(final long address, final @NotNull File file, final boolean huge, final boolean lock); @Override @Contract(pure = true) @SuppressWarnings("deprecation") @SuppressFBWarnings("") long virt2phys(final long address); @Override @Contract(value = "_, _, _ -> fail", pure = true) @SuppressWarnings({"deprecation", "BooleanParameter"}) @NotNull DmaMemory dmaAllocate(final long bytes, final boolean huge, final boolean lock);  }