What garbage collection algorithm is the latest Java virtual machine using?
-
Hi all, just going inside the java virtual machine found very interesting information on it. Inside java virtual machine (book) says train algorithm is used for garbage collection of old generation. Now reading the book i found everything Bill explained is keeping in mind the older versions of java virtual machine. not the latest. My question is what current algorithms are used in 1.6 and 1.7 versions of jvm releases.
-
Answer:
Java 7 (the current version of the JVM / JDK / libraries as of October 2012) includes a new supported algorithm for Garbage Collection (GC) called "Garbage First" (aka G1 Garbage Collector, from Sun's Hotspot JVM). This is a similar concept to the "real time" garbage collector from jRockit (Appeal Virtual Machines, acquired by BEA, acquired by Oracle). The challenge in Garbage Collection is to keep up with the rate of allocation. You can get lots of fun stories and technical details by searching up presentations done by some of the engineers at Azul Systems, e.g. Gil Tene and Cliff Click. What the G1 collector does is to (rightly) assume that under most scenarios, most allocations are garbage almost instantly, and to focus its collection technology on these very short-lived objects. It does this by cutting the overall memory available up into blocks, using those blocks to hold objects (allocations) -- probably in a heap data structure, continuously performing the "mark" phase of the mark&sweep algorithm, and then collecting within the blocks that statistically will yield the highest gain (i.e. the most memory freed). See: http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html There is another concept, called "escape analysis", which uses analysis of the code to determine which allocations may escape a method, may escape the stack, and may escape the thread. Basically, that means that the native code compiler can choose to allocate objects "on the stack" (basically free from a clock cycle perspective) instead of from a memory manager. This is available in the Hotspot JVM, and from what I can tell, it's now on by default. See: http://weblogs.java.net/blog/forax/archive/2009/10/06/jdk7-do-escape-analysis-default
Cameron Purdy at Quora Visit the source
Other answers
The Hotspot VM's GC is incredibly complex and sophisticated. Sun literally went out and hired the best experts in the world when they built the hotspot team. If you really want to understand all the different techniques involved in Hotspot GC you are going to have to start with the Master's thesis of the guy who at least used to be Sun's primary GC architect. He gave me a copy when I was at Sun. I understood maybe 20% of it.
Jeff Kesselman
Related Q & A:
- How to install Windows 8 as Virtualbox's (Virtual) Machine?Best solution by wikihow.com
- How do i create virtual subdomain using htaccess?Best solution by Stack Overflow
- How to connect to host from virtual machine on a specific port?Best solution by Super User
- How can I connect my VMware virtual machine to the Internet?Best solution by Yahoo! Answers
- How can I find out what my ranking is for the latest NJ civil service exam?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.