java垃圾收集器的工作方式 -------毕业设计外文文献翻译.doc
约10页DOC格式手机打开展开
java垃圾收集器的工作方式 -------毕业设计外文文献翻译,if you come from a programming language where allocating objects on the heap is expensive, you may naturally assume that java’s scheme of allocating everything ...
内容介绍
此文档由会员 wanli1988go 发布
If you come from a programming language where allocating objects on the heap is expensive, you may naturally assume that Java’s scheme of allocating everything (except primitives) on the heap is also expensive. However, it turns out that the garbage collector can have a significant impact on increasing the speed of object creation. This might sound a bit odd at first—that storage release affects storage allocation—but it’s the way some JVMs work, and it means that allocating storage for heap objects in Java can be nearly as fast as 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; it’s more like a conveyor belt 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 it’s effectively the same as C++’s stack allocation. (Of course, there’s a little extra overhead for bookkeeping, but it’s nothing like searching for storage.)
如果你学下过一种因为在堆里分配对象所以开销过大的编程语言,很自然你可能会假定 Java 在堆里为每一样东西(除了 primitives)分配内存资源的机制开销也会很大。不过,事实上垃圾收集器能够深刻影响对象的加速创建。 一开始听起来有些奇怪——存贮空间的释放会影响存贮空间的分配,但是这的确是一些 JVMs 的工作方式,并且这意味着 Java 为堆对象分配存贮空间几乎和别的语言里为栈分配存贮空间一样地快。
举个例子,你可以认为 C++的堆就如同一个堆放的工场,在这个工场里,每一个对象都立有的地皮占有权不久会被废除无效,并且这块地皮必须重新加以利用。在Java 的 JVM 里,堆的工作方式完全不同;每次为一个新的对象分配存贮空间的时候,它就更像是一个不断向前移动的传送带。 这就意味着对象存贮空间的分配速度明显加快。 在这个过程中,“堆指针”简单地向还没被占用的空间领域移动,所以非常像 C++里栈的分配方式。(当然,记录工作会有一点额外的开销,但是完全不同于 C++里那种在堆放工场里为寻找没被利用的存贮空间而付出的开销。)
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; it’s more like a conveyor belt 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 it’s effectively the same as C++’s stack allocation. (Of course, there’s a little extra overhead for bookkeeping, but it’s nothing like searching for storage.)
如果你学下过一种因为在堆里分配对象所以开销过大的编程语言,很自然你可能会假定 Java 在堆里为每一样东西(除了 primitives)分配内存资源的机制开销也会很大。不过,事实上垃圾收集器能够深刻影响对象的加速创建。 一开始听起来有些奇怪——存贮空间的释放会影响存贮空间的分配,但是这的确是一些 JVMs 的工作方式,并且这意味着 Java 为堆对象分配存贮空间几乎和别的语言里为栈分配存贮空间一样地快。
举个例子,你可以认为 C++的堆就如同一个堆放的工场,在这个工场里,每一个对象都立有的地皮占有权不久会被废除无效,并且这块地皮必须重新加以利用。在Java 的 JVM 里,堆的工作方式完全不同;每次为一个新的对象分配存贮空间的时候,它就更像是一个不断向前移动的传送带。 这就意味着对象存贮空间的分配速度明显加快。 在这个过程中,“堆指针”简单地向还没被占用的空间领域移动,所以非常像 C++里栈的分配方式。(当然,记录工作会有一点额外的开销,但是完全不同于 C++里那种在堆放工场里为寻找没被利用的存贮空间而付出的开销。)