-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
75 lines (64 loc) · 1.93 KB
/
Main.java
File metadata and controls
75 lines (64 loc) · 1.93 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
static PageTable[] ProcessTable = new PageTable[9];
static int num;
static int Access = 0;
static int Hits = 0;
static int Miss = 0;
static int Compulsory_Misses = 0;
static Memory memory = new Memory();
static PageTable PT = new PageTable();
static PageTableEntry PTE = new PageTableEntry();
public static void main(String[] args) {
String Filename = "Input.txt";
String a = "new";
String b = "switch";
String c = "access";
Scanner s;
try {
s = new Scanner(new File(Filename));
while(s.hasNextLine()) {
String str = s.nextLine();
String[] kuang = str.split(" ");
if(kuang[0].equals(a)) {
num = Integer.parseInt(kuang[1]);
ProcessTable[num] = new PageTable();
}else if(kuang[0].equals(b)) {
int z = Integer.parseInt(kuang[1]);
num = z;
}else if(kuang[0].equals(c)) {
int i = Integer.parseInt(kuang[1]);
i = i >> 10;
//System.out.println(i);
if(ProcessTable[num].getPTE(i) != null) {
if(ProcessTable[num].getPTE(i).isinmemory() == false) {
Miss++;
Access++;
memory.FindPageFrame(ProcessTable[num].getPTE(i));
//Page[num].getPTE(i).setinmemory(true);
} else {
Hits++;
Access++;
}
} else {
Miss++;
Compulsory_Misses++;
Access++;
//Set the PTE Here.
ProcessTable[num].setPTE(i, new PageTableEntry());
memory.FindPageFrame(ProcessTable[num].getPTE(i));
}
}
}
System.out.println("Accesses: " + Access);
System.out.println("Hits: " + Hits);
System.out.println("Miss: " + Miss);
System.out.println("Compulsory Misses: " + Compulsory_Misses);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}