【正文】
preted by the JVM and thus runs much faster. When a class must be loaded (typically, the first time you want to create an object of that class), the .class file is located, and the byte codes for that class are brought into memory. At this point, one approach is to simply JIT pile all the code, but this has two drawbacks: It takes a little more time, which, pounded throughout the life of the program, can add up。 Cleanup that will be encountered later during the “walk.” These are fixed up as they are found (you could imagine a table that maps old addresses to new ones). There are two issues that make these socalled “copy collectors” inefficient. The first is the idea that you have two heaps and you slosh all the memory back and forth between these two separate heaps, maintaining twice as much memory as you actually need. Some JVMs deal with this by allocating the heap in chunks as needed and simply copying from one chunk to another. The second issue is the copying process itself. Once your program bees stable, it might be generating little or no garbage. Despite that, a copy collector will still copy all the memory from one place to another, which is wasteful. To prevent this, some JVMs detect that no new garbage is being generated and switch to a different scheme (this is the “adaptive” part). This other scheme is called markandsweep, and it’s what earlier versions of Sun’s JVM used all the time. For general use, markandsweep is fairly slow, but when you know you’re generating little or no garbage, it’s fast. Markandsweep follows the same logic of starting from the stack and static storage, and tracing through all the references to find live objects. However, each time it finds a live object, that object is marked by setting a flag in it, but the object isn’t collected yet. Only when the marking process is finished does the sweep occur. During the sweep, the dead objects are released. However, no copying happens, so if the collector chooses to pact a fragmented heap, it does so by shuffling objects around. “Stopandcopy” refers to the idea that this type of garbage collection is not done in the background。 畢業(yè)設(shè)計(jì) (論文 ) 外文文獻(xiàn)翻譯 專業(yè) 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué) 生 姓 名 班級(jí) B 計(jì)算機(jī) 083 學(xué)號(hào) 0810704318 指 導(dǎo) 教 師 信息工程學(xué)院 1 英文原文 How a garbage collector works of Java Language If you e 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