(毕业论文)-计算机专业外文翻译(Java垃圾收集器)

上传人:zhuma****mei1 文档编号:54239070 上传时间:2018-09-10 格式:DOC 页数:9 大小:39.50KB
返回 下载 相关 举报
(毕业论文)-计算机专业外文翻译(Java垃圾收集器)_第1页
第1页 / 共9页
(毕业论文)-计算机专业外文翻译(Java垃圾收集器)_第2页
第2页 / 共9页
(毕业论文)-计算机专业外文翻译(Java垃圾收集器)_第3页
第3页 / 共9页
(毕业论文)-计算机专业外文翻译(Java垃圾收集器)_第4页
第4页 / 共9页
(毕业论文)-计算机专业外文翻译(Java垃圾收集器)_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《(毕业论文)-计算机专业外文翻译(Java垃圾收集器)》由会员分享,可在线阅读,更多相关《(毕业论文)-计算机专业外文翻译(Java垃圾收集器)(9页珍藏版)》请在金锄头文库上搜索。

1、 本科生毕业设计(论文) 第 1 页 How a garbage collector works of Java Language If you come from a programming language where allocating objects on the heap is expensive, you may naturally assume that Javas scheme of allocating everything (except primitives) on the heap is also expensive. However, it turns out th

2、at the garbage collector can have a significant impact on increasing the speed of object creation. This might sound a bit odd at firstthat storage release affects storage allocationbut its the way some JVMs work, and it means that allocating storage for heap objects in Java can be nearly as fast as

3、creating storage on the stack in other languages.For example, you can think of the C+ heap as a yard where each stakes out its own piece of turf object. This real estate can become abandoned sometime later and must be reused. In some JVMs, the Java heap is quite different; its more like a conveyor b

4、elt that moves forward every time you allocate a new object. This means that object storage allocation is remarkably rapid. The “heap pointer” is simply moved forward into virgin territory, so its effectively the same as C+s stack allocation. (Of course, theres a little extra overhead for bookkeepin

5、g, but its nothing like searching for storage.) You might observe that the heap isnt in fact a conveyor belt, and if you treat it that way, youll start paging memorymoving it on and off disk, so that you can appear to have more memory than you actually do. Paging significantly impacts performance. E

6、ventually, after you create enough objects, youll run out of memory. The trick is that the garbage collector steps in, and while it collects the garbage it compacts all the objects in the heap so that youve effectively moved the “heap pointer” closer to the beginning of the conveyor belt and farther

7、 away from a page fault. The garbage collector rearranges things and makes it possible for the high-speed, infinite-free-heap model to be used while allocating storage. To understand garbage collection in Java, its helpful learn how garbage-collection schemes work in other systems. A simple but slow

8、 garbage-collection technique is called reference counting. This means that each object contains a reference counter, 本科生毕业设计(论文) 第 2 页 and every time a reference is attached to that object, the reference count is increased. Every time a reference goes out of scope or is set to null, the reference c

9、ount is decreased. Thus, managing reference counts is a small but constant overhead that happens throughout the lifetime of your program. The garbage collector moves through the entire list of objects, and when it finds one with a reference count of zero it releases that storage (however, reference

10、counting schemes often release an object as soon as the count goes to zero). The one drawback is that if objects circularly refer to each other they can have nonzero reference counts while still being garbage. Locating such self-referential groups requires significant extra work for the garbage coll

11、ector. Reference counting is commonly used to explain one kind of garbage collection, but it doesnt seem to be used in any JVM implementations. In faster schemes, garbage collection is not based on reference counting. Instead, it is based on the idea that any non-dead object must ultimately be trace

12、able back to a reference that lives either on the stack or in static storage. The chain might go through several layers of objects. Thus, if you start in the stack and in the static storage area and walk through all the references, youll find all the live objects. For each reference that you find, y

13、ou must trace into the object that it points to and then follow all the references in that object, tracing into the objects they point to, etc., until youve moved through the entire Web that originated with the reference on the stack or in static storage. Each object that you move through must still

14、 be alive. Note that there is no problem with detached self-referential groupsthese are simply not found, and are therefore automatically garbage. In the approach described here, the JVM uses an adaptive garbage-collection scheme, and what it does with the live objects that it locates depends on the

15、 variant currently being used. One of these variants is stop-and-copy. This means thatfor reasons that will become apparentthe program is first stopped (this is not a background collection scheme). Then, each live object is copied from one heap to another, leaving behind all the garbage. In addition

16、, as the objects are copied into the new heap, they are packed end-to-end, thus compacting the new heap (and allowing 本科生毕业设计(论文) 第 3 页 new storage to simply be reeled off the end as previously described).Of course, when an object is moved from one place to another, all references that point at the object must be

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号