Java模拟操作系统实现存储管理.docx
- 文档编号:29191762
- 上传时间:2023-07-21
- 格式:DOCX
- 页数:11
- 大小:16.71KB
Java模拟操作系统实现存储管理.docx
《Java模拟操作系统实现存储管理.docx》由会员分享,可在线阅读,更多相关《Java模拟操作系统实现存储管理.docx(11页珍藏版)》请在冰豆网上搜索。
Java模拟操作系统实现存储管理
存储器管理
1.实验内容:
模拟请求页式存储管理中硬件的地址转换和缺页中断,并用先进先出调度算法〔FIFO处理缺页中断;
2.要求:
①指令序列的设定可以执行拟定,格式如表3;
②在完成了FIFO换页策略后,可以选做LRU的换页策略,并进行比较;
③作业允许的页架数m在不同情况下的缺页中断率;
④程序运行时显示地址转变和页面调入调出过程。
3.实验控制流图:
4.数据结构核心代码:
packagexiao.zhang.bean;
publicclassInstruction{
/**
*指令操作符号
*/
privateStringop;
/**
*页号
*/
privateintpageId;
/**
*页内地址
*/
privateintpageInAddress;
publicInstruction<>{
}
publicInstruction
this.op=op;
this.pageId=pageId;
this.pageInAddress=pageInAddress;
}
publicStringgetOp<>{
returnop;
}
publicvoidsetOp
this.op=op;
}
publicintgetPageId<>{
returnpageId;
}
publicvoidsetPageId
this.pageId=pageId;
}
publicintgetPageInAddress<>{
returnpageInAddress;
}
publicvoidsetPageInAddress
this.pageInAddress=pageInAddress;
}
/*
*
*
*@seejava.lang.Object#toString<>
*/
@Override
publicStringtoString<>{
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<>+"]";
}
}
packagexiao.zhang.bean;
importjava.util.LinkedList;
publicclassExecuteFiFo{
/**
*指令队列
*/
publicLinkedList
/**
*页面存储
*/
publicLinkedList
/**
*是否还有存储页架
*/
privatefinalintisUseablePageFrame;
publicstaticintpoint=0;
/**
*默认设置页架为4个
*/
publicExecuteFiFo<>{
this.isUseablePageFrame=4;
}
publicExecuteFiFo
is=newLinkedList
pages=newLinkedList
this.isUseablePageFrame=isUseablePageFrame;
}
publicExecuteFiFo
intisUseablePageFrame>{
this.is=is;
this.pages=pages;
this.isUseablePageFrame=isUseablePageFrame;
}
/**
*一次性调度完成,装载所有的可用的页
*/
publicvoidinitalExecute<>{
for
/**
*从指令队列出一条指令
*/
Instructionins=is.poll<>;
/**
*访问指定页号的主存
*/
Pagep=pages.get;
p.setPageId
p.setInMen
p.setModifyFlag
printINInformation;
}
}
/**
*执行指令
*/
publicvoidexecuteInstruction<>{
/**
*先判断执行的页是否住存指令序列中将其删除
*/
while
is.isEmpty<>>{
Instructionins=is.poll<>;
if
System.out.println<"[页号为:
\t"+ins.getPageId<>+"\t存在]">;
Pagep=pages.get
printOUTInformation
;
printINInformation;
}else{
System.out.println<"[页号为:
\t"+ins.getPageId<>+"\t不存在]">;
Pagep=pages.get
p.setInMen
PageoutP=pages.get
p.setPageFrameId
p.setModifyFlag
printOUTInformation
printINInformation;
}
point++;
}
}
/**
*判断指定序列是否住存
*
*@return
*/
publicbooleanisExistMemeroy
for
if
&&this.pages.get.isInMen<>>{
returntrue;
}
}
returnfalse;
}
/**
*打印装载信息
*
*@paramins
*/
publicvoidprintINInformation
System.out.println<"[页号:
"+ins.getPageId<>+"\tIN\t"+"执行:
"
+ins.getOp<>+"操作\t"+"物理地址:
"
+<1024*ins.getPageId<>+ins.getPageInAddress<>>+"]">;
}
/**
*打印调出信息
*
*@paramp
*/
publicvoidprintOUTInformation
if
System.out.println<"[页号:
"+p.getPageId<>+"\tOUT\t"+"页架号:
"
+p.getPageFrameId<>+"\t修改\t"+"写回磁盘:
"
+p.getLocationInDisk<>+"]">;
}else{
System.out.println<"[页号:
"+p.getPageId<>+"\tOUT\t"+"页架号:
"
+p.getPageFrameId<>+"\t未修改\t"+"不用写回磁盘]">;
}
}
/**
*判断指令是否修改主存内容
*
*@paramop
*@return
*/
publicbooleanisModify
if
returntrue;
}
returnfalse;
}
/**
*@returntheisUseablePageFrame
*/
publicintgetIsUseablePageFrame<>{
returnisUseablePageFrame;
}
/**
*@returntheis
*/
publicLinkedList
returnthis.is;
}
/**
*@returnthepages
*/
publicLinkedList
returnthis.pages;
}
/**
*@paramis
*theistoset
*/
publicvoidsetIs
this.is=is;
}
/**
*@parampages
*thepagestoset
*/
publicvoidsetPages
this.pages=pages;
}
}
packagexiao.zhang;
importxiao.zhang.bean.ExecuteFiFo;
importxiao.zhang.bean.Instruction;
importxiao.zhang.bean.Page;
publicclassMainExecute{
publicstaticvoidmain
Instruction[]i=newInstruction[12];
i[0]=newInstruction<"+",0,70>;
i[1]=newInstruction<"-",1,50>;
i[2]=newInstruction<"*",2,15>;
i[3]=newInstruction<"R",3,21>;
i[4]=newInstruction<"W",0,56>;
i[5]=newInstruction<"-",6,40>;
i[6]=newInstruction<"RM",4,53>;
i[7]=newInstruction<"+",5,23>;
i[8]=newInstruction<"W",1,37>;
i[9]=newInstruction<"R",2,78>;
i[10]=newInstruction<"+",4,1>;
i[11]=newInstruction<"W",6,84>;
Page[]p=newPage[7];
p[0]=newPage<0,true,5,false,11>;
p[1]=newPage<2,true,8,false,12>;
p[2]=newPage<3,true,9,false,13>;
p[3]=newPage<4,true,1,false,21>;
p[4]=newPage<5,false,0,false,22>;
p[5]=newPage<6,false,0,false,23>;
p[6]=newPage<7,false,0,false,121>;
ExecuteFiFoxf=newExecuteFiFo<4>;
for
xf.getPages<>.add
;
}
for
xf.getIs<>.add;
}
xf.initalExecute<>;
xf.executeInstruction<>;
}
}
6.程序运行结构截图:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 模拟 操作系统 实现 存储 管理
![提示](https://static.bdocx.com/images/bang_tan.gif)