Java模拟操作系统实现存储管理文档格式.docx
- 文档编号:19856665
- 上传时间:2023-01-11
- 格式:DOCX
- 页数:11
- 大小:237.29KB
Java模拟操作系统实现存储管理文档格式.docx
《Java模拟操作系统实现存储管理文档格式.docx》由会员分享,可在线阅读,更多相关《Java模拟操作系统实现存储管理文档格式.docx(11页珍藏版)》请在冰豆网上搜索。
this.op=op;
this.pageId=pageId;
this.pageInAddress=pageInAddress;
publicStringgetOp(){
returnop;
publicvoidsetOp(Stringop){
publicintgetPageId(){
returnpageId;
publicvoidsetPageId(intpageId){
publicintgetPageInAddress(){
returnpageInAddress;
publicvoidsetPageInAddress(intpageInAddress){
/*
*(non-Javadoc)
*
*@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()+"
]"
;
}
importjava.util.LinkedList;
publicclassExecuteFiFo{
*指令队列
publicLinkedList<
Instruction>
is;
*页面存储
Page>
pages;
*是否还有存储页架
privatefinalintisUseablePageFrame;
publicstaticintpoint=0;
*默认设置页架为4个
publicExecuteFiFo(){
this.isUseablePageFrame=4;
publicExecuteFiFo(intisUseablePageFrame){
is=newLinkedList<
();
pages=newLinkedList<
this.isUseablePageFrame=isUseablePageFrame;
publicExecuteFiFo(LinkedList<
is,LinkedList<
pages,
intisUseablePageFrame){
this.is=is;
this.pages=pages;
*一次性调度完成,装载所有的可用的页
publicvoidinitalExecute(){
for(inti=0;
i<
isUseablePageFrame;
i++){
/**
*从指令队列出一条指令
*/
Instructionins=is.poll();
*访问指定页号的主存
Pagep=pages.get(i);
p.setPageId(ins.getPageId());
p.setInMen(true);
p.setModifyFlag(isModify(ins.getOp()));
printINInformation(ins);
}
*执行指令
publicvoidexecuteInstruction(){
/**
*先判断执行的页是否住存指令序列中将其删除
*/
while(!
is.isEmpty()){
if(isExistMemeroy(ins)){
System.out.println("
[页号为:
\t"
+ins.getPageId()+"
\t存在]"
);
Pagep=pages.get(ins.getPageId());
printOUTInformation(p);
printINInformation(ins);
}else{
\t不存在]"
p.setInMen(true);
PageoutP=pages.get(point%isUseablePageFrame);
p.setPageFrameId(outP.getPageFrameId());
p.setModifyFlag(isModify(ins.getOp()));
printOUTInformation(outP);
}
point++;
*判断指定序列是否住存
*@return
publicbooleanisExistMemeroy(Instructionins){
this.pages.size();
if(this.pages.get(i).getPageId()==ins.getPageId()
&
&
this.pages.get(i).isInMen()){
returntrue;
returnfalse;
*打印装载信息
*@paramins
publicvoidprintINInformation(Instructionins){
System.out.println("
[页号:
"
\tIN\t"
+"
执行:
+ins.getOp()+"
操作\t"
物理地址:
+(1024*ins.getPageId()+ins.getPageInAddress())+"
*打印调出信息
*@paramp
publicvoidprintOUTInformation(Pagep){
if(p.isModifyFlag()){
System.out.println("
+p.getPageId()+"
\tOUT\t"
页架号:
+p.getPageFrameId()+"
\t修改\t"
写回磁盘:
+p.getLocationInDisk()+"
}else{
\t未修改\t"
不用写回磁盘]"
*判断指令是否修改主存内容
*@paramop
publicbooleanisModify(Stringop){
if(op.equals("
R"
)||op.equals("
W"
)){
returntrue;
*@returntheisUseablePageFrame
publicintgetIsUseablePageFrame(){
returnisUseablePageFrame;
*@returntheis
getIs(){
returnthis.is;
*@returnthepages
getPages(){
returnthis.pages;
*@paramis
*theistoset
publicvoidsetIs(LinkedList<
is){
*@parampages
*thepagestoset
publicvoidsetPages(LinkedList<
pages){
packagexiao.zhang;
importxiao.zhang.bean.ExecuteFiFo;
importxiao.zhang.bean.Instruction;
importxiao.zhang.bean.Page;
publicclassMainExecute{
publicstaticvoidmain(String[]args){
Instruction[]i=newInstruction[12];
i[0]=newInstruction("
+"
0,70);
i[1]=newInstruction("
-"
1,50);
i[2]=newInstruction("
*"
2,15);
i[3]=newInstruction("
3,21);
i[4]=newInstruction("
0,56);
i[5]=newInstruction("
6,40);
i[6]=newInstruction("
RM"
4,53);
i[7]=newInstruction("
5,23);
i[8]=newInstruction("
1,37);
i[9]=newInstruction("
2,78);
i[10]=newInstruction("
4,1);
i[11]=newInstruction("
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(intj=0;
j<
p.length;
j++){
xf.getPages().add(p[j]);
i.length;
xf.getIs().add(i[j]);
xf.initalExecute();
xf.executeInstruction();
6.程序运行结构截图:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 模拟 操作系统 实现 存储 管理
![提示](https://static.bdocx.com/images/bang_tan.gif)