Java模拟操作系统实现存储管理.doc_第1页
Java模拟操作系统实现存储管理.doc_第2页
Java模拟操作系统实现存储管理.doc_第3页
Java模拟操作系统实现存储管理.doc_第4页
Java模拟操作系统实现存储管理.doc_第5页
免费预览已结束,剩余11页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

存储器管理1实验内容:模拟请求页式存储管理中硬件的地址转换和缺页中断,并用先进先出调度算法(FIFO)处理缺页中断;2要求: 指令序列的设定可以执行拟定,格式如表3; 在完成了FIFO换页策略后,可以选做LRU的换页策略,并进行比较; 作业允许的页架数m在不同情况下的缺页中断率; 程序运行时显示地址转变和页面调入调出过程。3.实验控制流图:4数据结构核心代码:package xiao.zhang.bean;public class Instruction /* * 指令操作符号 */private String op;/* * 页号 */private int pageId;/* * 页内地址 */private int pageInAddress;public Instruction() public Instruction(String op, int pageId, int pageInAddress) this.op = op;this.pageId = pageId;this.pageInAddress = pageInAddress;public String getOp() return op;public void setOp(String op) this.op = op;public int getPageId() return pageId;public void setPageId(int pageId) this.pageId = pageId;public int getPageInAddress() return pageInAddress;public void setPageInAddress(int pageInAddress) this.pageInAddress = pageInAddress;/* * (non-Javadoc) * * see java.lang.Object#toString() */Overridepublic String toString() return Instruction op= + this.op + , pageId= + this.pageId+ , pageInAddress= + this.pageInAddress + , getOp()=+ this.getOp() + , getPageId()= + this.getPageId()+ , getPageInAddress()= + this.getPageInAddress()+ , getClass()= + this.getClass() + , hashCode()=+ this.hashCode() + , toString()= + super.toString() + ;package xiao.zhang.bean;import java.util.LinkedList;public class ExecuteFiFo /* * 指令队列 */public LinkedList is;/* * 页面存储 */public LinkedList pages;/* * 是否还有存储页架 */private final int isUseablePageFrame;public static int point = 0;/* * 默认设置页架为4个 */public ExecuteFiFo() this.isUseablePageFrame = 4;public ExecuteFiFo(int isUseablePageFrame) is = new LinkedList();pages = new LinkedList();this.isUseablePageFrame = isUseablePageFrame;public ExecuteFiFo(LinkedList is, LinkedList pages,int isUseablePageFrame) this.is = is;this.pages = pages;this.isUseablePageFrame = isUseablePageFrame;/* * 一次性调度完成,装载所有的可用的页 */public void initalExecute() for (int i = 0; i isUseablePageFrame; i+) /* * 从指令队列出一条指令 */Instruction ins = is.poll();/* * 访问指定页号的主存 */Page p = pages.get(i);p.setPageId(ins.getPageId();p.setInMen(true);p.setModifyFlag(isModify(ins.getOp();printINInformation(ins);/* * 执行指令 */public void executeInstruction() /* * 先判断执行的页是否住存 指令序列中将其删除 */while (!is.isEmpty() Instruction ins = is.poll();if (isExistMemeroy(ins) System.out.println(页号为:t + ins.getPageId() + t存在);Page p = pages.get(ins.getPageId();printOUTInformation(p);printINInformation(ins); else System.out.println(页号为:t + ins.getPageId() + t不存在);Page p = pages.get(ins.getPageId();p.setInMen(true);Page outP = pages.get(point % isUseablePageFrame);p.setPageFrameId(outP.getPageFrameId();p.setModifyFlag(isModify(ins.getOp();printOUTInformation(outP);printINInformation(ins);point+;/* * 判断指定序列是否住存 * * return */public boolean isExistMemeroy(Instruction ins) for (int i = 0; i this.pages.size(); i+) if (this.pages.get(i).getPageId() = ins.getPageId()& this.pages.get(i).isInMen() return true;return false;/* * 打印装载信息 * * param ins */public void printINInformation(Instruction ins) System.out.println(页号: + ins.getPageId() + tINt + 执行:+ ins.getOp() + 操作t + 物理地址:+ (1024 * ins.getPageId() + ins.getPageInAddress() + );/* * 打印调出信息 * * param p */public void printOUTInformation(Page p) if (p.isModifyFlag() System.out.println(页号: + p.getPageId() + tOUTt + 页架号:+ p.getPageFrameId() + t修改t + 写回磁盘:+ p.getLocationInDisk() + ); else System.out.println(页号: + p.getPageId() + tOUTt + 页架号:+ p.getPageFrameId() + t未修改t + 不用写回磁盘);/* * 判断指令是否修改主存内容 * * param op * return */public boolean isModify(String op) if (op.equals(R) | op.equals(W) return true;return false;/* * return the isUseablePageFrame */public int getIsUseablePageFrame() return isUseablePageFrame;/* * return the is */public LinkedList getIs() return this.is;/* * return the pages */public LinkedList getPages() return this.pages;/* * param is * the is to set */public void setIs(LinkedList is) this.is = is;/* * param pages * the pages to set */public void setPages(LinkedList pages) this.pages = pages;package xiao.zhang;import xiao.zhang.bean.ExecuteFiFo;import xiao.zhang.bean.Instruction;import xiao.zhang.bean.Page;public class MainExecute public static void main(String args) Instruction i = new Instruction12;i0 = new Instruction(+, 0, 70);i1 = new Instruction(-, 1, 50);i2 = new Instruction(*, 2, 15);i3 = new Instruction(R, 3, 21);i4 = new Instruction(W, 0, 56);i5 = new Instruction(-, 6, 40);i6 = new Instruction(RM, 4, 53);i7 = new Instruction(+, 5, 23);i8 = new Instruction(W, 1, 37);i9 = new Instruction(R, 2, 78);i10 = new Instruction(+, 4, 1);i11 = new Instruction(W, 6, 84);Page p = new Page7;p0 = new Page(0, true, 5, false, 11);p1 = new Page(2, true, 8, false, 12);p2 = new Page(3, true, 9, false, 13);p3 = new Page(4, true, 1, false, 21);p4 = new Page(5, false, 0, false, 22);p5 = new Page(6, false, 0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论