Question: Task 1 package memory; import java.io . FileNotFoundException; import java.io . IOException; import java.io . R 1 . Download the code from . and make

Task 1package memory;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.R
1. Download the code from . and make sure that you can compile it. Note that when running the code for the first time, you will get index out of bounds, this due to that getPageNumber(), getPageOffset() and handlePageFault() is not implemented in MemoryManager.class.
2. Note that when running the code for the first time, you will get index out of bounds, this due to that getPageNumber(), getPageOffset() and handlePageFault() is not implemented in MemoryManager.class.
3. Implement the handlePageFault() method such that a page is loaded into a free frame in the physical memory in case of page fault.
4. Run the application and testCaseOne that is supplied in the Seminar3.class. to verify your results.
public class Seminar3{
private static final String BACKING_STORE_FILE = "resources/BACKING_STORE.bin";
private static final int PAGE_SIZE =256;
private static final int NUMBER_OF_PAGES =256;
private static final int NUMBER_OF_FRAMES_256=256;
private static final int NUMBER_OF_FRAMES_128=128;
private static final int NUMBER_OF_FRAMES_64=64;
private static final int NUMBER_OF_FRAMES_32=32;
public static final int NO_PAGE_REPLACEMENT =0;
public static final int FIFO_PAGE_REPLACEMENT =1;
public static final int LRU_PAGE_REPLACEMENT =2;
public static void main(String[] args){
// When running the code for the first time, you will get index out of bounds // This is due to that getPageNumber(), getPageOffset() and handlePageFault() is not implemented in MemoryManager.class
testTaskOne(); //testTaskTwo(); // Uncomment to run tc //testTaskThree(); // Uncomment to run tc}
private static void testTaskOne()
{ System.out.println("Testing task one");
MemoryManager memoryManager = new MemoryManager(NUMBER_OF_PAGES, PAGE_SIZE, NUMBER_OF_FRAMES_256, BACKING_STORE_FILE, NO_PAGE_REPLACEMENT);
MemoryProcess mp = new MemoryProcess("resources/addresses.txt", memoryManager);mp.callMemory(); int numberOfPageFaults = memoryManager.getNumberOfPageFaults();
System.out.println("Number of page faults: "+ numberOfPageFaults);
System.out.println("Expected: "+"244");
if(numberOfPageFaults ==244)
System.out.println("Pass");
else
System.out.println("Assertion Fail");
System.out.println(""); }
private static void testTaskTwo()
{System.out.println("Testing task two");
int numberOfPageFaults = getNumberOfPageFaultsFifo(NUMBER_OF_FRAMES_128);
verifyFifo(numberOfPageFaults,536, NUMBER_OF_FRAMES_128);
numberOfPageFaults = getNumberOfPageFaultsFifo(NUMBER_OF_FRAMES_64); verifyFifo(numberOfPageFaults,759, NUMBER_OF_FRAMES_64); numberOfPageFaults = getNumberOfPageFaultsFifo(NUMBER_OF_FRAMES_32); verifyFifo(numberOfPageFaults,880, NUMBER_OF_FRAMES_32);}
private static void testTaskThree()
{ System.out.println("Testing task three");
int numberOfPageFaults = getNumberOfPageFaultsLRU(NUMBER_OF_FRAMES_128); verifyLRU(numberOfPageFaults,534, NUMBER_OF_FRAMES_128); numberOfPageFaults = getNumberOfPageFaultsLRU(NUMBER_OF_FRAMES_64); verifyLRU(numberOfPageFaults,753, NUMBER_OF_FRAMES_64); numberOfPageFaults = getNumberOfPageFaultsLRU(NUMBER_OF_FRAMES_32); verifyLRU(numberOfPageFaults,878, NUMBER_OF_FRAMES_32); }
private static void verifyFifo(int numberOfPageFaults, int expectedPageFaults, int numberOfFrames)
{ System.out.println("FIFO with "+ numberOfFrames +" frames");
System.out.println("Number of page faults: "+ numberOfPageFaults);
System.out.println("Expected: "+ expectedPageFaults);
if(numberOfPageFaults == expectedPageFaults)
System.out.println("Pass");
else
System.out.println("Assertion Fail");
System.out.println("");}
private static void verifyLRU(int numberOfPageFaults, int expectedPageFaults, int numberOfFrames)
{System.out.println("LRU with "+ numberOfFrames +" frames");
System.out.println("Number of page faults: "+ numberOfPageFaults);
System.out.println("Expected: "+ expectedPageFaults);
if(numberOfPageFaults == expectedPageFaults)
System.out.println("Pass");
else
System.out.println("Assertion Fail");
System.out.println("");
} private static void verifyLRU(int numberOfPageFaults, int expectedPageFaults, int numberOfFrames)
{System.out.println("LRU with "+ numberOfFrames +" frames");
System.out.println("Number of page faults: "+ numberOfPageFaults);
System.out.println("Expected: "+ expectedPageFaults);
if(numberOfPageFaults == expectedPageFaults)
System.out.println("Pass");
else
System.out.println("Assertion Fail");
System.out.println(""); } private static int getNumberOfPageFaultsFifo(int numberOfFrames){MemoryManager memoryManager = new MemoryManager(NUMBER_OF_PAGES, PAGE_SIZE, numberOfFrames, BACKING_STORE_FILE, FIFO_PAGE_REPLACEMENT); MemoryProcess mp =new MemoryProcess("resources/addresses.txt", memoryManager); mp.callMemory(); return memoryManager.getNumberOfPageFaults(); }}
Task 1 package memory; import java.io .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!