系统级编程复习总纲.pdf
1.活动记录图看 key1,key2,-key3,4 流程debug 2.sizeof函数,实验掌握算结构体的size element 规则程序执行流程浮点数编码增值表位操作(bit operation)看实验中涉及的10 个位操作函数3.理解汇编,编译的关系区别answer:都是将一种语言转化为另一种语言。它们分析的语义不同,具有的选择不同。能理解简单C控制语句代码指针:涉及的运算符语义,指针占的字节结构体和联合体answer:结构体储存一系列任意类型的能够通过其定义的名字访问的元素。联合体是一种在申明的数据类型中只表示其中一个组件的数据结构。4.数组和字符串存储:数组元素都是同一类型,编译器将数组元素以增加的顺序一个接一个的连续排列在一起。C 语言中没有字符串类型,字符串是以空字符结尾的字符数组。*5.函数调用过程(活动记录)ebp,esp,eip 等常用 register 6.Buffer overflow 概念,其会带来什么后果?answer:缓冲区溢出是因为放置的变量超过了缓冲区所拥有的空间范围,因而需要重写边界。后果是堆栈容易受到缓冲区溢出攻击。什么叫函数调用规范(Fuction call),为什么要有它?answer:函数调用描述了调用代码的接口,参数被分配的顺序,参数被放置的地方,函数应当使用哪个寄存器,是否caller 和 callee 对于堆栈的循环和返回有作用。作用域answer:an identifer can be used only in a region of program text.7.虚拟内存布局即 memery layout(图)什么叫动态内存与静态内存,内存分配的概念,它们有何不同?answer:动态如栈,堆;动态内存分配在程序运行的时候。静态如程序变量static 声明的字符串常量,静态内存分配发生在编译时间和链接时间。堆,栈上内存分配的区别answer:堆效益低,需显性调用;以后进先出进行调用;用于函数调用和返回。栈效益高不需显性调用;根据用户的需求可进行任意多次的分配。8.理解 malloc()/free()malloc 参数为 int,free 参数为指针eg.sizeof(int)*32=?*垃圾回收类型,实现,算法及基础原理answer:隐藏的动态内存分配算符,动态内存的分配器能够自动释放无用的栈存储空间。算法:mark and sweep collection(标记清除法),在每个存储块的头部放置额外的标记位。copying colection(复制法),用 2 个栈,一个用于程序,另一个用于垃圾回收。reference counting(引用计数法),记录每一个对象的指针数量。generational garbage collection(分布式垃圾回收法),根据经验观察,如果一个对象在长时间中都是可访问的,则说明它仍旧存在。*memery bug(内存错误)-考试要求指出错误并改正9.阿姆达尔公式Speedup(E)=评测:什么是profiler?什么叫timer?answer:Software profiler-a program that benchmarks the execution of one or more pieces of procedural code to help the user understand where the time is being spent in terms of code execution.Timer-a component in computer system/CS,as a hardware or software,which can provide the ability of measure time in some degree.10.有编译器但我们为什么还要自己优化?妨碍优化有哪些因素?answer:妨碍优化的因素,potential memory aliasing(存储器别名使用),potential procedure side-effects(函数副作用)理解 cpu time,wall time answer:CPU time=user CPU time+system CPU timeuser CPU time:the CPU time spent directly executing your program code,system CPU time:the CPU time spent by the operating system on behalf of your program Wall time:is the time an ordinary clock on the wall or a wrist watch shows性能测试的重要性(简答)timer 概念和功能掌握代码优化方法?answer:good algorithms rule,如:代码移动,循环展开*11.内存层次结构图answer:reqisters,cache(on-chip L1,off-chip L2),main memory,local secondary storage,remote secondary storage.Locality(局部性):什么叫局部性原理?answer:Programs tend to reference data items that are near other recently referenced data items,or that were recently referenced 局部性原理类型?answer:时间,空间局部性。局部性原理对程序的影响12.*cache组织填表(实验做过)cache的几种类型answer:Direct cache/直接映像Set associative cache/组相联映像Fully-associative cache/全相联映像*cache miss rate(实验做过)13.目标文件格式answer:可重定位:.coff.obj 可执行:.pe.exe loader 概念及功能answer:copies the code and data in the executable file into memory,and then transfers control to the beginning of the program linker 概念与处理流程与功能answer:Linking is the process of collecting and combining various pieces of code and data into a single file that can be loaded into memory and executed linker 的流程:Symbol Resolution(符号解析),Combination(联合),Relocation(重定位)。14.exception概念,处理流程(图)answer:An exception is an abrupt change in the control flow in response to some change in the processor s state.异常和进程关系(理解)answer:Exceptions provide the basic building blocks that allow the operating system to provide the notion of a process进程,线程,同步,互斥概念answer:进程:有自己的内存地址空间存储数据(包括本地变量的堆栈和子程序的返回地址);有一系列的处理器寄存器(当进程在运行时这些寄存器处于活动状态,当另一个进程运行时这些寄存器就被保存到CPU外部);有一系列操作系统资源,如网络连接、打开文件的句柄。包含在程序内部的是程序计数器,它计算出下一条要执行的指令的位置。线程:While it is possible to use full-scale processes with separate address spaces,it is often more convenient to share a single address space among multiple process-like entities called threads.Threads can eliminate the need to change address spaces after a context/process switch.Due to the fact that threads share memory,they can share data much more easily 同步(synchronization)refers to the ability of multiple processes(or threads)to coordinate their activities by the exchange of information 互斥(Mutual exclusion)refers to the ability of multiple processes(or threads)to share code,resources,or data in such a way that only one process(or threads)has access to the shared object at a time.用户模式,内核模式同步互斥(完善代码)