com.sun.jimi.core.vmem
Class PageMapper

java.lang.Object
  |
  +--com.sun.jimi.core.vmem.PageMapper
Direct Known Subclasses:
BytePageMapper, IntPageMapper

public abstract class PageMapper
extends java.lang.Object

A class for managing the swapping of paged virtual memory. The PageMapper is responsible for providing access to arbitrary fixed-size areas, or "pages", of image data through in-memory buffers, or "page frames". The page mapper maintains a set of page frames which are accessed one at a time, pages of data are then "swapped" in and out of page frames as required. The specific algorithm is this: A set of page frames are created, and when a page is requested it is loaded into one of the frames and passed out. The request will have to ask for a frame explicitly for reading or writing, if it is accessed for writing the page frame is marked as modified so that when it has to be reused, its page data will be committed to secondary storage. When a page is requested and there are no empty page frames, the least-recently-used frame will be swapped out (written if modified, otherwise simply overwritten in memory) and replaced with the data for the requested page. Some useful terms defined: Page: a fixed-size rectangular logical area of data, numbered from from left to right, top down. Page Frame: an in-memory buffer representing a page of data. Page Mapper: object responsible for providing page frames to access paged data in secondary storage and keeping modifications in sync. Page Fault: if a requested page does not exist in memory and has to be read in from disk, a page fault is said to have occured.


Field Summary
protected  java.io.InputStream input
          InputStream representation of the secondary storage
protected  java.awt.Dimension logicalSize
          logical image dimensions in pixels
protected  int numberOfPageFrames
           
protected  java.io.OutputStream output
          OutputStream representation of the secondary storage
protected  java.awt.Dimension pageDimensions
           
protected  int pageFaults
           
protected  int pageFrameMemory
          how many kbytes of memory to use for page frames
protected  RandomAccessStorage storage
          secondary storage to swap to/from
 
Constructor Summary
PageMapper(RandomAccessStorage storage, java.awt.Dimension logicalSize, int pageFrameMemory)
          Construct a page mapper with specified secondary storage and size.
 
Method Summary
 void commitPage(PageFrame pageFrame)
          Commit a page to secondary storage.
protected  void configurePageFrames()
          Determine how many page frames to use, and what sizes they will be.
 java.awt.Dimension getLogicalSize()
          Get the logical size of the image data.
 PageFrame getPageFrame(int logicalPageNumber)
          Return a PageFrame representing a specified logical page number.
 PageFrame getPageFrameForReading(int logicalPageNumber)
          Return a PageFrame representing a specified logical page for read-only use.
 PageFrame getPageFrameForWriting(int logicalPageNumber)
          Return a PageFrame representing a specified logical page for read-write use.
abstract  PageFrame[] getPageFrames()
          Return the page available page frames.
abstract  int getPageSize()
          Return the size in bytes of a page.
protected abstract  int getPixelSize()
          Return the byte-size required to store one pixel.
 int howManyPageFaults()
          Find out how many page faults have occured.
 void readPageIntoFrame(PageFrame pageFrame, int logicalPageNumber)
          Read a page in from secondary storage.
 void resetPageFaultCount()
          Reset the page fault count.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storage

protected RandomAccessStorage storage
secondary storage to swap to/from

logicalSize

protected java.awt.Dimension logicalSize
logical image dimensions in pixels

pageFrameMemory

protected int pageFrameMemory
how many kbytes of memory to use for page frames

pageFaults

protected int pageFaults

output

protected java.io.OutputStream output
OutputStream representation of the secondary storage

input

protected java.io.InputStream input
InputStream representation of the secondary storage

numberOfPageFrames

protected int numberOfPageFrames

pageDimensions

protected java.awt.Dimension pageDimensions
Constructor Detail

PageMapper

public PageMapper(RandomAccessStorage storage,
                  java.awt.Dimension logicalSize,
                  int pageFrameMemory)
Construct a page mapper with specified secondary storage and size.
Parameters:
storage - the storage object to swap pages into
logicalSize - the logical size in pixels of the image
Method Detail

configurePageFrames

protected void configurePageFrames()
Determine how many page frames to use, and what sizes they will be.

getLogicalSize

public java.awt.Dimension getLogicalSize()
Get the logical size of the image data.
Returns:
the logical size in pixels

getPageFrameForReading

public PageFrame getPageFrameForReading(int logicalPageNumber)
                                 throws java.io.IOException
Return a PageFrame representing a specified logical page for read-only use.
Parameters:
logicalPageNumber - the number of the page
Returns:
the page frame

getPageFrameForWriting

public PageFrame getPageFrameForWriting(int logicalPageNumber)
                                 throws java.io.IOException
Return a PageFrame representing a specified logical page for read-write use.
Parameters:
logicalPageNumber - the number of the page
Returns:
the page frame

getPageFrame

public PageFrame getPageFrame(int logicalPageNumber)
                       throws java.io.IOException
Return a PageFrame representing a specified logical page number.
Parameters:
logicalPageNumber - the number of the page

commitPage

public void commitPage(PageFrame pageFrame)
                throws java.io.IOException
Commit a page to secondary storage.

readPageIntoFrame

public void readPageIntoFrame(PageFrame pageFrame,
                              int logicalPageNumber)
                       throws java.io.IOException
Read a page in from secondary storage. The page will have its modification time updated and be marked as unmodified.
Parameters:
pageFrame - the page frame to read data into
logicalPageNumber - the logical page number to read data for

howManyPageFaults

public int howManyPageFaults()
Find out how many page faults have occured.

resetPageFaultCount

public void resetPageFaultCount()
Reset the page fault count.

getPageSize

public abstract int getPageSize()
Return the size in bytes of a page.
Returns:
the number of bytes per page

getPageFrames

public abstract PageFrame[] getPageFrames()
Return the page available page frames.
Returns:
an array containing all page frames

getPixelSize

protected abstract int getPixelSize()
Return the byte-size required to store one pixel.
Returns:
the size of a pixel