-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBLevelLogic
More file actions
81 lines (60 loc) · 2.56 KB
/
BLevelLogic
File metadata and controls
81 lines (60 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
while ( (line = reader.readLine() ) != null) {
sanitizeInput(line, myQ);
/*int procNum = Integer.parseInt(line.substring(1,2));
System.out.println("Process : " + procNum);
//String pageRef = line.substring(4,10);
int pageNum = Integer.parseInt(line.substring(4,10),2);
System.out.println("Page referenced: " + pageNum + "\n");
// Check if there is a free frame.
int freeFrame = tbl.checkFreeFrame();
if ( tbl.checkPageInTable(procNum, pageNum) ) { // Check in memory
ctrl.updateReference(procNum, pageNum);
// Print message to the user and updated reference count.
System.out.println("The page is already in physical memory!");
tbl.updateProcessRefCount(procNum);
// Search which frame is associated with the process/page pair.
int frameOfInterest = (tbl.searchAssociatedFrame(procNum, pageNum))[0];
// Add the reference frame to LRU Queue.
tbl.addCandidateFrame(frameOfInterest);
} else if ( freeFrame >= 0) { // Check for free frames.
ctrl.updateReference(procNum, pageNum);
tbl.updateProcessFaultCount(procNum);
tbl.updateProcessRefCount(procNum);
tbl.updateFrameTable(freeFrame, procNum, pageNum);
tbl.updatePageTable(false, procNum, pageNum, freeFrame);
// Controller actions.
ctrl.updatePageTable(procNum);
ctrl.updateFrameTable();
// Add the reference frame to LRU Queue.
tbl.addCandidateFrame(freeFrame);
} else { // Find a victim and replace them.
ctrl.updateReference(procNum, pageNum);
tbl.updateProcessFaultCount(procNum);
tbl.updateProcessRefCount(procNum);
System.out.println("PAGE FAULT!!");
// Find the victim
int victim = tbl.pickVictim();
// Send the victim a message to update their page table.
int [] replacementPair = tbl.searchVictimPair(victim);
int pid = replacementPair[0];
int page = replacementPair[1];
tbl.updatePageTable(true, pid, page, victim);
// Send a message to the replacing process to update their page table.
tbl.updatePageTable(false, procNum, pageNum, victim);
// Update the frame table.
tbl.updateFrameTable(victim, procNum, pageNum);
ctrl.updatePageTable(procNum);
ctrl.updateFrameTable();
// Add the reference frame to LRU Queue
tbl.addCandidateFrame(victim);
}
// Inspect the frame/page table as it currently stands.
System.out.println("Physical Memory \n");
System.out.println("Frame# ProcID Page#");
tbl.printFrameTableState();
ctrl.updateFrameTable();
tbl.printPageTableState(procNum);*/
}
// Report final statistics
//ctrl.updateStats();
//tbl.printFinalStats();