a垃圾收集器中英文毕业论文

上传人:w****y 文档编号:47060158 上传时间:2018-06-29 格式:DOC 页数:16 大小:57.04KB
返回 下载 相关 举报
a垃圾收集器中英文毕业论文_第1页
第1页 / 共16页
a垃圾收集器中英文毕业论文_第2页
第2页 / 共16页
a垃圾收集器中英文毕业论文_第3页
第3页 / 共16页
a垃圾收集器中英文毕业论文_第4页
第4页 / 共16页
a垃圾收集器中英文毕业论文_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《a垃圾收集器中英文毕业论文》由会员分享,可在线阅读,更多相关《a垃圾收集器中英文毕业论文(16页珍藏版)》请在金锄头文库上搜索。

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 that the garbage col

2、lector 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 creating storage o

3、n 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 belt that moves for

4、ward 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 bookkeeping, but its nothing

5、 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. Eventually, after y

6、ou 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 away from a page

7、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 garbage-collectio

8、n technique is called reference counting. This means that each object contains a reference counter, 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 count is decreased. Thus, managing re

9、ference 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 counting schemes often release an ob

10、ject 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 collector. Reference counting is commonl

11、y 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 traceable back to a reference that lives

12、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, you must trace into the object that i

13、t 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 be alive. Note that there is no pro

14、blem 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 variant currently being used. One o

15、f 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, as the objects are copied into the

16、 new heap, they are packed end-to-end, thus compacting the new heap (and allowing 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 changed. The reference that goes from the heap or the static storage area to the object can be changed right away, but there can be other references pointing to this object Initialization Instead, the program is s

展开阅读全文
相关资源
相关搜索

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

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