Class PageManager

java.lang.Object
com.kenai.jffi.PageManager

public abstract class PageManager
extends java.lang.Object
Manages allocation, disposal and protection of native memory pages
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int PROT_EXEC
    The memory should be executable
    static int PROT_READ
    The memory should be readable
    static int PROT_WRITE
    The memory should be writable
  • Constructor Summary

    Constructors
    Constructor Description
    PageManager()  
  • Method Summary

    Modifier and Type Method Description
    abstract long allocatePages​(int npages, int protection)
    Allocates native memory pages.
    abstract void freePages​(long address, int npages)
    Free pages allocated via allocatePages(int, int)
    static PageManager getInstance()
    Gets the page manager for the current platform.
    long pageSize()
    Gets the system page size.
    abstract void protectPages​(long address, int npages, int protection)
    Sets the protection mask on a memory region.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROT_EXEC

      public static final int PROT_EXEC
      The memory should be executable
      See Also:
      Constant Field Values
    • PROT_READ

      public static final int PROT_READ
      The memory should be readable
      See Also:
      Constant Field Values
    • PROT_WRITE

      public static final int PROT_WRITE
      The memory should be writable
      See Also:
      Constant Field Values
  • Constructor Details

    • PageManager

      public PageManager()
  • Method Details

    • getInstance

      public static PageManager getInstance()
      Gets the page manager for the current platform.
      Returns:
      An instance of PageManager
    • pageSize

      public final long pageSize()
      Gets the system page size.
      Returns:
      The size of a page on the current system, in bytes.
    • allocatePages

      public abstract long allocatePages​(int npages, int protection)
      Allocates native memory pages. The memory allocated is aligned on a page boundary, and the size of the allocated memory is npages * pageSize.
      Parameters:
      npages - The number of pages to allocate.
      protection - The initial protection for the page. This must be a bitmask of PROT_READ, PROT_WRITE and PROT_EXEC.
      Returns:
      The native address of the allocated memory.
    • freePages

      public abstract void freePages​(long address, int npages)
      Free pages allocated via allocatePages(int, int)
      Parameters:
      address - The memory address as returned from allocatePages(int, int)
      npages - The number of pages to free.
    • protectPages

      public abstract void protectPages​(long address, int npages, int protection)
      Sets the protection mask on a memory region.
      Parameters:
      address - The start of the memory region.
      npages - The number of pages to protect.
      protection - The protection mask.