*********************************************************************************************** /** * Factory class to start five threads. * */ public class Factory {...
/* This class implements a linked list which contains all the page tables in the
system */
public class PageTableList
{
public PageTableList()
{
first = null;
}
/* add a new entry to the head of the linked list */
public void addFirst(PageTable pt)
{
Node newNode = new Node();
newNode.pt = pt;
newNode.next = first;
first = newNode;
}
/* return the page table associated with the thread id */
public PageTable lookup(int id)
{
Node t = first;
while(t != null)
{
if(t.pt.getThreadID() == id)
return t.pt;
t = t.next;
}
return null;
}
/* head of the linked list */
private Node first;
private class Node
{
public PageTable pt;
public Node next;
}
}
Project Description: The goal of this project is to simulate the paging scheme in memory management and get familiar with semaphore/synchronized method. The tester code has been provided in Factory.java and MemoryThread.java. As you can see, 5 threads are created. Each thread requests for a certain number of pages (simulates the load of new process into memory), then accesses a certain page (simulates the memory reference of logical address), then releases the memory request (simulate the termination of a process). You are asked to implement the PhysicalMemory class with the following public interfaces: /* constructor */ public PhysicalMemory(int numofFrames) /* If the memory has enough free frames to serve the memory request from a thread, allocate the free frames to the thread, build the thread's page table, and update free frames state @param id the threadID of the requesting thread @param requestLength the number of pages the thread requests @return If the request can be served (which means the free frames in memory is greater or equal to the requestLength), return true else return false * public boolean requestMemory(int id, int requestLength) /* Convert logical page number to physical frame number. @param id the threadID of the requesting thread @param pageNumber the page number the thread wants to access @return the frameNumber (physical address of the pageNumber (logical address) */ public int access Memory(int id, int pageNumber) /* Set the frames allocated to the calling thread to free @param id the threadID of the calling thread * public void release Memory(int id) You need to think carefully about the data structure for tracking the allocated and free frames in the physical memory, and the data structure for the page table of each thread. You can choose any data structures (for example, array, array list, linked list, etc) you feel necessary and comfortable with. Here is some suggestion: - Use a boolean array to track the memory allocation status. Each frame in the physical memory has a corresponding entry in the boolean array. The entry value false indicates the frame is free. The item value true indicates the frame is occupied (allocated to a thread). If you want more practice, think how to use a list to keep track of all available frames as mentioned in the book. - For page table, use a linked list of page tables of all the thread. Each object in the linked list is a page table for a thread. I have attached the implementation of page tables PageTableList.java and Page Table.java. You can add any new methods you might need for your design. You can also use other data structure such as hashtable to save page tables if you want more practice of programming. Note: 1) You need to modify the tester code to get memory size and frame size from user input. The number of frames is equal to memory size / frame size. 2) In the tester code, I have put the code to print out the page number and frame number for a certain memory access. How do you know whether this mapping is correct or not? Call the method printPageTable in Page Table class to print out the page table for the calling thread, thus you can check whether the mapping is correct or not. 3) This project will take some time to implement and debug. I recommend you start as soon as possible. Think and plan carefully. Know what to do before you start coding. Figure out all the instance fields and the details of each method in the PhysicalMemory class. Since there are multiple threads, if you don't know what are you are doing, you will spend more time on debugging than implementing the correct logic. 4) Since there are multiple threads trying to check and set the memory allocation status at the same time, you need to have a binary semaphore or use synchronized method to protect the checking and setting of memory allocation status. Think carefully which pieces of code need to be protected by the semaphore or synchronized method. Your program will hang if you don't use the semaphore or synchronized method correctly 5) To debug your code, consider adding debugging messages (use System.out.println) in your code Extra Credit (20 points): When a process requests more space than what is available in the memory, block the process instead of returning false and let it keep requesting. This is a synchronization problem. Project Description: The goal of this project is to simulate the paging scheme in memory management and get familiar with semaphore/synchronized method. The tester code has been provided in Factory.java and MemoryThread.java. As you can see, 5 threads are created. Each thread requests for a certain number of pages (simulates the load of new process into memory), then accesses a certain page (simulates the memory reference of logical address), then releases the memory request (simulate the termination of a process). You are asked to implement the PhysicalMemory class with the following public interfaces: /* constructor */ public PhysicalMemory(int numofFrames) /* If the memory has enough free frames to serve the memory request from a thread, allocate the free frames to the thread, build the thread's page table, and update free frames state @param id the threadID of the requesting thread @param requestLength the number of pages the thread requests @return If the request can be served (which means the free frames in memory is greater or equal to the requestLength), return true else return false * public boolean requestMemory(int id, int requestLength) /* Convert logical page number to physical frame number. @param id the threadID of the requesting thread @param pageNumber the page number the thread wants to access @return the frameNumber (physical address of the pageNumber (logical address) */ public int access Memory(int id, int pageNumber) /* Set the frames allocated to the calling thread to free @param id the threadID of the calling thread * public void release Memory(int id) You need to think carefully about the data structure for tracking the allocated and free frames in the physical memory, and the data structure for the page table of each thread. You can choose any data structures (for example, array, array list, linked list, etc) you feel necessary and comfortable with. Here is some suggestion: - Use a boolean array to track the memory allocation status. Each frame in the physical memory has a corresponding entry in the boolean array. The entry value false indicates the frame is free. The item value true indicates the frame is occupied (allocated to a thread). If you want more practice, think how to use a list to keep track of all available frames as mentioned in the book. - For page table, use a linked list of page tables of all the thread. Each object in the linked list is a page table for a thread. I have attached the implementation of page tables PageTableList.java and Page Table.java. You can add any new methods you might need for your design. You can also use other data structure such as hashtable to save page tables if you want more practice of programming. Note: 1) You need to modify the tester code to get memory size and frame size from user input. The number of frames is equal to memory size / frame size. 2) In the tester code, I have put the code to print out the page number and frame number for a certain memory access. How do you know whether this mapping is correct or not? Call the method printPageTable in Page Table class to print out the page table for the calling thread, thus you can check whether the mapping is correct or not. 3) This project will take some time to implement and debug. I recommend you start as soon as possible. Think and plan carefully. Know what to do before you start coding. Figure out all the instance fields and the details of each method in the PhysicalMemory class. Since there are multiple threads, if you don't know what are you are doing, you will spend more time on debugging than implementing the correct logic. 4) Since there are multiple threads trying to check and set the memory allocation status at the same time, you need to have a binary semaphore or use synchronized method to protect the checking and setting of memory allocation status. Think carefully which pieces of code need to be protected by the semaphore or synchronized method. Your program will hang if you don't use the semaphore or synchronized method correctly 5) To debug your code, consider adding debugging messages (use System.out.println) in your code Extra Credit (20 points): When a process requests more space than what is available in the memory, block the process instead of returning false and let it keep requesting. This is a synchronization
Answer & Explanation
Solved by verified expert
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
Unlimited Question Access with detailed Answers
Zin AI - 3 Million Words
10 Dall-E 3 Images
20 Plot Generations
Conversation with Dialogue Memory
No Ads, Ever!
Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!