计算机系统结构课程实验1.docx
- 文档编号:7264569
- 上传时间:2023-01-22
- 格式:DOCX
- 页数:24
- 大小:352.82KB
计算机系统结构课程实验1.docx
《计算机系统结构课程实验1.docx》由会员分享,可在线阅读,更多相关《计算机系统结构课程实验1.docx(24页珍藏版)》请在冰豆网上搜索。
计算机系统结构课程实验1
计算机系统结构课程
实验指导书
2016——2017学年
第2学期
姓名:
徐益
学号:
201415725
指导教师:
薛素静
教研室:
计算机系统结构教研室
实验:
存贮层次模拟器1
学时:
4学时
实验类型:
(综合/设计):
设计
一、实验目的与要求
使学生清楚认识虚拟存贮层次结构,熟练掌握常用的几种存储地址映像与变换方法,以及FIFO、LRU等替换算法的工作全过程。
要求用程序实现任意地址流在存储层次上的命中情况,实验结束后提交源程序和实验说明书。
二、实验内容
在模拟器上实现在任意地址流下求出在Cache—主存两层存贮层次上的命中率。
三、实验步骤
1.Cache—主存:
映像方式要实现全相联、直接映象、组相联方式三种方式,并选择每一种映像方式下输出结果;替换算法一般使用LRU算法。
2.要求主存容量、Cache大小、块大小以及组数等可以输入修改。
3.求出命中率;显示替换的全过程;任选一种高级语言来做。
4.要设计简洁、易于操作的界面。
四、实验仪器设备
计算机(装有java、Apachetomcat)
五、实验过程
1、设计思想:
(1)在本次实验中,我使用的是java语言来实现。
(2)首先,建一个web项目,然后将整个实验分为前端和后端两部分,前端为jsp页面,用来输入数据和显示实验结果。
后端为Java,在本次实验我用了一个
MyServlt类,在这个类中用来接收前端的数据,然后进行一系列的逻辑处理;即各个算法的具体实现。
最后将数据传送给前端输出。
(3)将整个cache看成是一个对象,然后建一个实体类Cache。
在这个类中有cache的大小、块大小、块数、块地址、计数器、计时器等属性。
块地址用于存放地址流,计数器用于计算命中率,当命中一次,计数器加1。
计时器用于LRU算法。
当命中时,计时器清零。
每一个循环结束,有地址的块计时器加1;替换时,找到计时器最大的块地址,然后把它替换出去。
(4)将要输出的数据封装成一个类,然后进行输出。
六、实验代码
1、前端代码:
Index.jsp代码(用于输入数据):
在本页面中用到jqurey插件以达到美观效果,其中的js、css等代码就不粘贴出来了。
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+":
//"+request.getServerName()+":
"+request.getServerPort()+path;
%>
DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http:
//www.w3.org/TR/html4/loose.dtd">
body{height:
100%;background:
#16a085;overflow:
hidden;}
canvas{z-index:
-1;position:
absolute;}
$(document).ready(function(){
//粒子背景特效
$('body').particleground({
dotColor:
'#5cbdaa',
lineColor:
'#5cbdaa'
});
$('#FAssociative').click(function(){
varMMC=$("#MMC").val();
varcache=$("#cache").val();
varchunk=$("#chunk").val();
vargroup=$("#group").val();
varaddress=$("#address").val();
form1.action="<%=basePath%>/cache.jsp?
_m=FAssociative";
$("#form1").submit();
})
$('#dMapping').click(function(){
varMMC=$("#MMC").val();
varcache=$("#cache").val();
varchunk=$("#chunk").val();
vargroup=$("#group").val();
varaddress=$("#address").val();
form1.action="<%=basePath%>/cache.jsp?
_m=dMapping";
$("#form1").submit();
})
$('#SAssociative').click(function(){
varMMC=$("#MMC").val();
varcache=$("#cache").val();
varchunk=$("#chunk").val();
vargroup=$("#group").val();
varaddress=$("#address").val();
form1.action="<%=basePath%>/cache.jsp?
_m=SAssociative";
$("#form1").submit();
})
});
存贮层次模拟器1
Memoryhierarchysimulator
来源:
Main.jsp代码(用于输出数据):
在本页面中用到jqurey插件以达到美观效果,其中的js、css等代码就不粘贴出来了。
<%@pageimport="com.xu.entity.OutPut"%>
<%@pageimport="java.util.List"%>
<%@pageimport="com.xu.entity.Cache"%>
<%@pagelanguage="java"contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+":
//"+request.getServerName()+":
"+request.getServerPort()+path;
%>
DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http:
//www.w3.org/TR/html4/loose.dtd">
body{height:
100%;background:
#16a085;overflow:
hidden;}
canvas{z-index:
-1;position:
absolute;}
$(document).ready(function(){
//粒子背景特效
$('body').particleground({
dotColor:
'#5cbdaa',
lineColor:
'#5cbdaa'
});
});
#89cff0;margin-top: 230px;"> <% List floathit=(Float)request.getAttribute("hit"); %>时间流 地址流 状态
<%
for(inti=0;i OutPutoutput=dataList.get(i); %> <%=i%> <%=output.getPageAddress()%> <% for(intj=0;j %> <%=output.getAddressStream().get(j)%> <% } %> <%=output.getState()%>
<%
}
%>
<%=hit%>
2、后端代码:
Cache实体类代码:
packagecom.xu.entity;
importjava.util.ArrayList;
importjava.util.List;
publicclassCache{
privateintsize;//cache大小
privateintblockSize;//块大小
privateintblockNumber;//块数
privateList
privateList
privateintcount;//计数器
publicintgetSize(){
returnsize;
}
publicvoidsetSize(intsize){
this.size=size;
}
publicintgetBlockNumber(){
returnblockNumber;
}
publicvoidsetBlockNumber(){
this.blockNumber=size/blockSize;
}
publicList
returnblockAddress;
}
publicvoidsetBlockAddress(List
this.blockAddress=blockAddress;
}
publicintgetCount(){
returncount;
}
publicvoidsetCount(intcount){
this.count=count;
}
publicintgetBlockSize(){
returnblockSize;
}
publicvoidsetBlockSize(intblockSize){
this.blockSize=blockSize;
}
publicList
returnblockTime;
}
publicvoidsetBlockTime(List
this.blockTime=blockTime;
}
}
Myservlt类代码:
packagecom.xu.web;
importjava.io.IOException;
importjava.util.ArrayList;
importjava.util.List;
importjavax.servlet.ServletException;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importcom.xu.entity.Cache;
importcom.xu.entity.OutPut;
@WebServlet("/cache.jsp")
publicclassMyServltextendsHttpServlet{
privatestaticfinallongserialVersionUID=1L;
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{
Stringmethod=request.getParameter("_m");
if("FAssociative".equals(method)){
FAssociative(request,response);
}elseif("dMapping".equals(method)){
dMapping(request,response);
}elseif("SAssociative".equals(method)){
SAssociative(request,response);
}
}
/**
*页面跳转
*@paramrequest
*@paramresponse
*@paramdataList
*@paramhit
*/
privatevoidskip(HttpServletRequestrequest,HttpServletResponseresponse,floathit,List
request.setAttribute("dataList",dataList);
request.setAttribute("hit",hit);
request.getRequestDispatcher("main.jsp").forward(request,response);
}
/**
*组相联
*@paramrequest
*@paramresponse
*/
privatevoidSAssociative(HttpServletRequestrequest,
HttpServletResponseresponse)throwsServletException,IOException{
intnum=Integer.parseInt(request.getParameter("cache"));
intchunk=Integer.parseInt(request.getParameter("chunk"));
intgroup=Integer.parseInt(request.getParameter("group"));
Stringaddress=request.getParameter("address");
Stringstr[]=address.split("");
int[]ad=newint[str.length];
for(inti=0;i ad[i]=Integer.parseInt(str[i]); } Cachecaches=newCache(); caches.setSize(num);//cache大小 caches.setBlockSize(chunk);//块大小 caches.setBlockNumber();//块数 intgroupSize=caches.getBlockNumber()/group;//组大小 for(intj=0;j caches.getBlockTime().add(0); } for(inta=0;a caches.getBlockAddress().add(-1); } List for(inti
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机系统 结构 课程 实验