Automatic Storage Management.ppt
《Automatic Storage Management.ppt》由会员分享,可在线阅读,更多相关《Automatic Storage Management.ppt(102页珍藏版)》请在麦多课文档分享上搜索。
1、Automatic Storage Management,Patrick Earl Simon Leonard Jack Newton,2,Overview,Terminology Why use Automatic Storage Management? Comparing garbage collection algorithms The “Classic” algorithms Copying garbage collection Incremental Tracing garbage collection Generational garbage collection Conclusi
2、ons,3,Terminology,Stack: a memory area where activation records or frames are pushed onto when a procedure is called and popped off when it returns Heap: a memory area where data structures can be allocated and deallocated in any order.,4,Terminology (Continued),Roots: values that a program can mani
3、pulate directly (i.e. values held in registers, on the program stack, and global variables.) Node/Cell/Object: an individually allocated piece of data in the heap. Children Nodes: the list of pointers that a given node contains. Live Node: a node whose address is held in a root or is the child of a
4、live node.,5,Terminology (Continued),Garbage: nodes that are not live, but are not free either. Garbage collection: the task of recovering (freeing) garbage nodes. Mutator: The program running alongside the garbage collection system.,6,Why Garbage Collect?,Language requirements In some situations it
5、 may be impossible to know when a shared data structure is no longer in use.,7,Why Garbage Collect? (Continued),Software Engineering Garbage collection increases abstraction level of software development. Simplified interfaces and decreases coupling of modules. Studies have shown a significant amoun
6、t of development time is spent on memory management bugs Rovner, 1985.,8,Comparing Garbage Collection Algorithms,Directly comparing garbage collection algorithms is difficult there are many factors to consider. Some factors to consider: Cost of reclaiming cells Cost of allocating cells Storage overh
7、ead How does the algorithm scale with residency? Will user program be suspended during garbage collection? Does an upper bound exist on the pause time? Is locality of data structures maintained (or maybe even improved?),9,Classes of Garbage Collection Algorithms,Direct Garbage Collectors: a record i
8、s associated with each node in the heap. The record for node N indicates how many other nodes or roots point to N. Indirect/Tracing Garbage Collectors: usually invoked when a users request for memory fails because the free list is exhausted. The garbage collector visits all live nodes, and returns a
9、ll other memory to the free list. If sufficient memory has been recovered from this process, the users request for memory is satisfied.,10,Quick Review: Reference Counting,Every cell has an additional field: the reference count. This field represents the number of pointers to that cell from roots or
10、 heap cells. Initially, all cells in the heap are placed in a pool of free cells, the free list.,11,Reference Counting (Continued),When a cell is allocated from the free list, its reference count is set to one. When a pointer is set to reference a cell, the cells reference count is incremented by 1;
11、 if a pointer is to the cell is deleted, its reference count is decremented by 1. When a cells reference count reaches 0, its pointers to its children are deleted and it is returned to the free list.,12,0,1,0,0,0,Reference Counting Example,1,2,1,1,13,2,1,1,1,Reference Counting Example (Continued),0,
12、1,14,2,1,1,1,Reference Counting Example (Continued),0,1,15,2,1,1,1,Reference Counting Example (Continued),0,0,0,1,1,16,Reference Counting: Advantages and Disadvantages,Advantages: Garbage collection overhead is distributed. Locality of reference is no worse than mutator. Free memory is returned to f
13、ree list quickly.,17,Reference Counting: Advantages and Disadvantages (Continued),Disadvantages: High time cost (every time a pointer is changed, reference counts must be updated). Storage overhead for reference counter can be high. Unable to reclaim cyclic data structures. If the reference counter
14、overflows, the object becomes permanent.,18,Reference Counting: Cyclic Data Structure - Before,0,2,0,0,1,2,1,19,Reference Counting: Cyclic Data Structure After,0,1,0,0,1,2,1,20,Deferred Reference Counting,Optimisation Cost can be improved by special treatment of local variables. Only update referenc
15、e counters of objects on the stack at fixed intervals. Reference counts are still affected from pointers from one heap object to another.,21,Quick Review: Mark-Sweep,The first tracing garbage collection algorithm Garbage cells are allowed to build up until heap space is exhausted (i.e. a user progra
16、m requests a memory allocation, but there is insufficient free space on the heap to satisfy the request.) At this point, the mark-sweep algorithm is invoked, and garbage cells are returned to the free list.,22,Mark-Sweep (Continued),Performed in two phases: Mark phase: identifies all live cells by s
17、etting a mark bit. Live cells are cells reachable from a root. Sweep phase: returns garbage cells to the free list.,23,Mark-Sweep Example,24,Mark-Sweep: Advantages and Disadvantages,Advantages: Cyclic data structures can be recovered. Tends to be faster than reference counting.,25,Mark-Sweep: Advant
18、ages and Disadvantages (Continued),Disadvantages: Computation must be halted while garbage collection is being performed Every live cell must be visited in the mark phase, and every cell in the heap must be visited in the sweep phase. Garbage collection becomes more frequent as residency of a progra
19、m increases. May fragment memory.,26,Mark-Sweep: Advantages and Disadvantages (Continued),Disadvantages: Has negative implications for locality of reference. Old objects get surrounded by new ones (not suited for virtual memory applications). However, if objects tend to survive in clusters in memory
20、, as they apparently often do, this can greatly reduce the cost of the sweep phase.,27,Mark-Compact Collection,Remedy the fragmentation and allocation problems of mark-sweep collectors. Two phases: Mark phase: identical to mark sweep. Compaction phase: marked objects are compacted, moving most of th
21、e live objects until all the live objects are contiguous.,28,Mark-Compact: Advantages and Disadvantages (Continued),Advantages: The contiguous free area eliminates fragmentation problem. Allocating objects of various sizes is simple. The garbage space is “squeezed out“, without disturbing the origin
22、al ordering of objects. This ameliorate locality.,29,Mark-Compact: Advantages and Disadvantages (Continued),Disadvantages: Requires several passes over the data are required. “Sliding compactors“ takes two, three or more passes over the live objects. One pass computes the new location Subsequent pas
23、ses update the pointers to refer to new locations, and actually move the objects,30,Copying Garbage Collection,Like mark-compact, copying garbage collection does not really “collect“ garbage. Rather it moves all the live objects into one area and the rest of the heap is know to be available. Copying
24、 collectors integrate the traversal and the copying process, so that objects need only be traversed once. The work needed is proportional to the amount of live date (all of which must be copied).,31,Semispace Collector Using the Cheney Algorithm,The heap is subdivided into two contiguous subspaces (
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AUTOMATICSTORAGEMANAGEMENTPPT
