/** * Class to test simulation of page replacement. * *
* Command-line argument gives number of page frames (and, optionally, * debug to produce extra output -- need not implement this). * * Input (from standard input) is a line giving number of pages, followed * by more lines, each giving: * * R/W (read/write reference, single character) * Page number (integer) * * Output is, for each page replacement algorithm implemented, the following * information: * * Total number of page references * Number of page references that changed the page ('W') * Number of page faults * Number of times a page had to be written out * * Assume that all page references are valid -- if the page is not in * memory, it's on disk. **/ import java.util.List; import java.util.ArrayList; import java.util.Scanner; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class PageReplacerTest { /** * Main method. * @param args see description of class */ public static void main(String[] args) { int numPages = 0; int numFrames = 0; // process arguments String usageMsg = "Need argument: numFrames [debug]"; if (args.length < 1) { System.err.println(usageMsg); System.exit(1); } try { numFrames = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println(usageMsg); System.exit(1); } if (numFrames <= 0) { System.err.println(usageMsg); System.exit(1); } boolean dbg = (args.length > 1) && (args[1].equals("debug")); // read input List