📄 pagetable.java
字号:
/* * PageTable.java * * Created on 2006年3月15日, 下午9:57 * */package os.memory;/** * * @author Vernkin */import java.util.LinkedList;/** * 页表页,包含程序上下文 */public class PageTable{ /** * Store the orig-real reflection table */ private LinkedList store = new LinkedList(); /** * The PSW space(Process Context) */ private int contextPage = 0;//the first index of contextPrt /** * A PageTable refers a MyProcess */ private os.process.MyProcess pro; /** * Constructor * @param id A new Process * @param context The context space */ public PageTable(os.process.MyProcess id,int context){ pro = id; contextPage = context; } /** * Whether the param pp is the same as the pro in thisPageTable * @param pp other Process * @return whether the param pp is the same as the pro in thisPageTable */ public boolean sameProcess(os.process.MyProcess pp){ return pro == pp; } /** * 看该物理页是否 属于该进程 * @param page the physical page * @return whether this physical page belongs to this process */ public boolean isBelonged(int page){ PageUnit pu; for(int i=0;i<store.size();i++){ pu = (PageUnit)store.get(i); if(pu.real == page) return true; } return false; } /** * get all the momory page that current process occupied * including the context page * @return all the momory page that current process occupied */ public int[] getAllUsedPage(){ int[] ret = new int[store.size()+1]; for(int i=0;i<store.size();i++){ ret[i] = ((PageUnit)store.get(i)).real; } ret[store.size()] = contextPage; return ret; } /** * Get the process ID * @return process ID */ public int getID(){ return pro.getID(); } /** * add a new orig-real pair to store * @param orig logic page * @param real physical page */ public void add(int orig,int real){ // System.out.println(pro+" orig: "+orig+" real: "+real); store.add(new PageUnit(orig,real)); } /**获得逻辑页数对应的物理页数**/ /** * Get the real page indicate by a logic page * @param orig the logic page * @return the physical page */ public int getPhysicalPage(int orig){ PageUnit pu; for(int i=0;i<store.size();i++){ pu = (PageUnit)store.get(i); if(pu.orig == orig) return pu.real; } return -1; } /** * Get the process context page * @return the process context page */ public int getContextPage(){ return contextPage; } public int getSize(){ return store.size() + 1; } public os.process.MyProcess getProcess(){ return pro; } /** * A base page unit */ private class PageUnit{ int orig = -1; int real = -1; private PageUnit(int orig,int real){ this.orig = orig; this.real = real; } /** * convert to String form */ public String toString(){ return "Orig "+orig+" :Real "+real; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -