/** * Frees the memory space pointed to by {@code addr} - address of buffer, which must have been returned by a * previous call {@link #allocate(int, int)}. * * @param addr direct buffer address to free. */ public static void free(long addr) { IgniteNativeIoLib.free(new Pointer(addr)); } }
public void munlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); int ret = LibC.INSTANCE.munlock(pointer, new NativeLong(this.fileSize)); log.info("munlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); }
/** * Gets address in memory for direct aligned buffer taking into account its current {@code position()} as offset. * Produces warnings if data or offset seems to be not aligned. * * @param buf Direct aligned buffer. * @param pos position, used as offset for resulting pointer. * @return Buffer memory address. */ @NotNull private Pointer bufferPtrAtPosition(ByteBuffer buf, int pos) { long alignedPointer = GridUnsafe.bufferAddress(buf); if (pos < 0) throw new IllegalArgumentException(); if (pos > buf.capacity()) throw new BufferOverflowException(); if ((alignedPointer + pos) % ioBlockSize != 0) { U.warn(log, String.format("IO Buffer Pointer [%d] and/or offset [%d] seems to be not aligned " + "for IO block size [%d]. Direct IO may fail.", alignedPointer, buf.position(), ioBlockSize)); } return new Pointer(alignedPointer + pos); }
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
public void destroy() { for (ByteBuffer byteBuffer : availableBuffers) { final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize)); } }
public void mlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); { int ret = LibC.INSTANCE.mlock(pointer, new NativeLong(this.fileSize)); log.info("mlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); } { int ret = LibC.INSTANCE.madvise(pointer, new NativeLong(this.fileSize), LibC.MADV_WILLNEED); log.info("madvise {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); } }
/** * Map the given region of the given file descriptor into memory. * Returns a Pointer to the newly mapped memory throws an * IOException on error. */ public static Pointer mmap(long len, int prot, int flags, int fildes, long off) throws IOException { // we don't really have a need to change the recommended pointer. Pointer addr = new Pointer(0); Pointer result = Delegate.mmap(addr, new NativeLong(len), prot, flags, fildes, new NativeLong(off)); if(Pointer.nativeValue(result) == -1) { if(logger.isDebugEnabled()) logger.debug(errno.strerror()); throw new IOException("mmap failed: " + errno.strerror()); } return result; }
/** Provide a view of this memory using the given offset to calculate a * new base address, bounds-limiting the memory with the given size. */ public Pointer share(long offset, long sz) { if (offset == 0L) { return this; } return new Pointer(peer + offset); }
/** Utility method to get the native window pointer for a Java * {@link Window} as a {@link Pointer} value. This method is primarily for * w32, which uses the <code>HANDLE</code> type (actually * <code>void *</code>) to identify windows. * @throws HeadlessException if the current VM is running headless */ public static Pointer getWindowPointer(Window w) throws HeadlessException { return new Pointer(AWT.getWindowID(w)); }
/** Utility method to get the native window pointer for a heavyweight Java * {@link Component} as a {@link Pointer} value. This method is primarily * for w32, which uses the <code>HWND</code> type (actually * <code>void *</code>) to identify windows. * @throws HeadlessException if the current VM is running headless */ public static Pointer getComponentPointer(Component c) throws HeadlessException { return new Pointer(AWT.getComponentID(c)); }
/** Convert a direct {@link Buffer} into a {@link Pointer}. * @throws IllegalArgumentException if the buffer is not direct. */ public static Pointer getDirectBufferPointer(Buffer b) { long peer = _getDirectBufferPointer(b); return peer == 0 ? null : new Pointer(peer); }
static Pointer getPointer(long addr) { long peer = _getPointer(addr); return peer == 0 ? null : new Pointer(peer); }
private Pointer invokePointer(int callFlags, Object[] args) { long ptr = Native.invokePointer(this, this.peer, callFlags, args); return ptr == 0 ? null : new Pointer(ptr); }
/** Look up the given global variable within this library. * @param symbolName * @return Pointer representing the global variable address * @throws UnsatisfiedLinkError if the symbol is not found */ public Pointer getGlobalVariableAddress(String symbolName) { try { return new Pointer(getSymbolAddress(symbolName)); } catch(UnsatisfiedLinkError e) { throw new UnsatisfiedLinkError("Error looking up '" + symbolName + "': " + e.getMessage()); } }
public void munlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); int ret = LibC.INSTANCE.munlock(pointer, new NativeLong(this.fileSize)); log.info("munlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); }
/** Called from native code only; same as {@link * #newInstance(Class,Pointer)}, except that it additionally calls * {@link #conditionalAutoRead()}. */ private static <T extends Structure> T newInstance(Class<T> type, long init) { try { T s = newInstance(type, init == 0 ? PLACEHOLDER_MEMORY : new Pointer(init)); if (init != 0) { s.conditionalAutoRead(); } return s; } catch(Throwable e) { LOG.log(Level.WARNING, "JNA: Error creating structure", e); return null; } }
public void mlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); { int ret = LibC.INSTANCE.mlock(pointer, new NativeLong(this.fileSize)); log.info("mlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); } { int ret = LibC.INSTANCE.madvise(pointer, new NativeLong(this.fileSize), LibC.MADV_WILLNEED); log.info("madvise {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); } }
public void destroy() { for (ByteBuffer byteBuffer : availableBuffers) { final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize)); } }
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation(); long address = 0; while (kernel.VirtualQueryEx(process, new Pointer(address), memInfo, memInfo.size()) != 0) { boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_NOACCESS) != JNAKernel32Library.PAGE_NOACCESS