Question
Must comment on the code at every /* Comment Here */ section about what the code is doing. /* Comment Here */ public VM() {
Must comment on the code at every "/* Comment Here */" section about what the code is doing.
/* Comment Here */ public VM() { // create the page table pageTable = new PageTableEntry[PAGE_TABLE_ENTRIES]; for (int i = 0; i < PAGE_TABLE_ENTRIES; i++) pageTable[i] = new PageTableEntry();
// create the TLB TLB = new TLBEntry[TLB_SIZE]; for (int i = 0; i < TLB_SIZE; i++) TLB[i] = new TLBEntry();
// allocate the physical memory physicalMemory = new Frame[NUMBER_OF_FRAMES]; for (int i = 0; i < NUMBER_OF_FRAMES; i++) physicalMemory[i] = new Frame();
// initialize the next frame number nextFrameNumber = 0;
// initialize the next available entry in the TLB nextTLBEntry = 0;
// allocate a temporary buffer for reading in from disk buffer = new byte[PAGE_SIZE];
// initialize the statistics counters pageFaults = 0; TLBHits = 0; }
/* Comment Here */ public int getNextFrame() { return nextFrameNumber++; }
/* Comment Here */ public int checkTLB(int pageNumber) { int frameNumber = -1;
/* Comment Here */ for (int i = 0; i < TLB_SIZE; i++) { if (TLB[i].checkPageNumber(pageNumber)) { frameNumber = TLB[i].getFrameNumber(); TLBHits++;
break; } }
return frameNumber; }
public void setTLBMapping(int pageNumber, int frameNumber) { // establish the mapping TLB[nextTLBEntry].setMapping(pageNumber, frameNumber);
/* Comment Here */ nextTLBEntry = (nextTLBEntry + 1) % TLB_SIZE; }
public int getPhysicalAddress(int virtualAddress) throws java.io.IOException { // determine the page number pageNumber = getPageNumber(virtualAddress); //System.out.println("Page number = " + pageNumber);
// determine the offset offset = getOffset(virtualAddress); //System.out.println("offset = " + offset);
/* Comment Here */ if ( (frameNumber = checkTLB(pageNumber)) == -1 ) { /** TLB Miss **/ // Check the page table if (pageTable[pageNumber].getValidBit() == true) { /** Page Table Hit **/ frameNumber = pageTable[pageNumber].getFrameNumber(); } else { /** Page Fault **/
// get a free frame frameNumber = getNextFrame();
/* Comment Here */
// seek to the appropriate page in the BACKING_STORE file disk.seek(pageNumber * PAGE_SIZE); // read in a page-size chunk from BACKING_STORE // into a temporary buffer disk.readFully(buffer);
// copy the contents of the buffer // to the appropriate physical frame physicalMemory[frameNumber].setFrame(buffer);
// now establish a mapping // of the frame in the page table pageTable[pageNumber].setMapping(frameNumber);
pageFaults++; //System.out.print(" * "); }
// lastly, update the TLB setTLBMapping(pageNumber, frameNumber); }
public byte getValue(int physicalAddress) throws java.io.IOException { /* Comment Here */ return physicalMemory[((physicalAddress & 0x0000ff00) >> 8)].readWord(physicalAddress & 0x000000ff);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started