Learning Goal: I’m working on a operating systems question and need an explanati
Learning Goal: I'm working on a operating systems question and need an explanation and answer to help me learn.The MemoryMangerFIFO class implements the FIFO page replacements algorithm. You will modify this class so that it implements LRU instead.Modify ONLY the MemoryManagerFIFO class.Only modify code that is enclosed in comments. You need to do the following:1) Declare a variable for the data structure. FIFO uses a queue but LRU will use a stack. I recommend using Java's ArrayList or LinkedList class for the stack.2) Initialize the data structure in the constructor method.3) Update the handlePageFault method. Just add the page number to your data structure.4) Update the pageAccessed method. This method is currently empty of code because FIFO does not use it. LRU must update its data structure by making sure the accessed page is at the top of the stack. Note that the page being accessed is a resident page and should already be in the data structure.5) Update the evictPage method. This method just identifies the page to evict using the data structure.import java.util.LinkedList;import java.util.Queue;/** * This class contains the Memory Management methods called by the Simulator. * * Currently, this class implements the FIFO page replacement algorithm. * Modify this class with your page replacement algorithm. * */public class MemoryManagerFIFO implements MemoryManager { private PageTable table;// Reference to the page table private Simulator sim;// Reference to the simulator //////////////////////////////////////////////////////////////////////////////////////////////////////////////// private Queue q;// Data structure for page replacement////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// private Queue freeList; // Queue of free frame numbers /** * Creates a new MemoryManager. Builds a free list containing all frames. * @param table reference to the page table * @param sim reference to the simulator * @param gui reference to the user interface */ public MemoryManagerFIFO(PageTable table, Simulator sim) {this.table = table;this.sim = sim;//////////////////////////////////////////////////////////////////////////////////////////////q = new LinkedList(); // Create data structure//////////////////////////////////////////////////////////////////////////////////////////////freeList = new LinkedList();for(int i=0; i<sim.getNumberFrames(); i++) {freeList.add(i);} } /** * This method is called by the simulator when a page fault should occur. * The specified page is not currently resident in a frame, so this method * must choose a frame in which to load the page either by finding a free * frame or evicting a resident page. * @param pageNumber page number of page simulator tried to access */ public void handlePageFault(int pageNumber) {int frame;if (freeList.isEmpty()) {frame = evictPage();// Evict a page if no frames are free} else {frame = freeList.remove();// Pick next free frame from free list}PTEntry e = table.getEntry(pageNumber);//////////////////////////////////////////////////////////////////////////////////////////////////////////q.add(pageNumber);// Add page to data structure//////////////////////////////////////////////////////////////////////////////////////////////////////////e.setValid(true);// Set page table entry's Valid bite.setFrame(frame);// Update page table entry's frame numbersim.loadPage(pageNumber, frame); // Tell simulator to load page in a frame } /** * This method is called by the simulator whenever a page is accessed. * This method is not needed for all page replacement algorithms. * @param pageNumber number page being accessed */ public void pageAccessed(int pageNumber) {//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// FIFO does nothing here// Update data structure////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } /** * This method uses a page replacement algorithm to choose which resident page to evict. * Currently implements the FIFO algorithm. * @return the page to evict */ private int evictPage() {////////////////////////////////////////////////////////////////////////////////////////////////////int pageNumber = q.remove();// Choose page to evict////////////////////////////////////////////////////////////////////////////////////////////////////PTEntry e = table.getEntry(pageNumber);e.setValid(false);// Clear page table entry's Valid bite.setModified(false);e.setAccessed(false);sim.evict(pageNumber);return e.getFrame(); }} Requirements: full length | Java

Leave a Reply

Your email address will not be published.