The total of the virtual machines is divided into three generations: young Generation, old Generation , and persistent (Permanent Generation). The persistent generation primarily stores the class information of the Java class, which is not related to the Java objects collected by garbage collection. The division of the younger generation and the old generation is
Garbage collection and several common garbage collection algorithms and several garbage collection algorithmsPreface:
First, think about three things that need to be done by Garbage
-XX:USEG1GCJVM parameter to open the use of the G1 garbage collector.
Optimization of Java 8
When using the G1 garbage collector, open the use-XX:+USESTRINGDEDUPLACATONJVM parameter. It optimizes heap memory usage by moving duplicate string values to the same char[] array. This is the option introduced by Java 8 U 20.
The above four Java garbage collector, when t
every time garbage collection is made, and the data that is always fetched by the Get method of the virtual reference is null and is therefore also a phantom reference.
A virtual reference is primarily used to detect whether an object has been removed from memory. 1.3. The method area will also be recycled
。 However, the recovery conditions for the method area are very harsh and are recycled only if the fo
divided into different generations based on the State or size of objects that are prone to spam. They can be divided into "Young Generation", "Old Generation", and "permanent generation ". "Permanent generation" is not in the heap. We will not discuss it again. Based on the characteristics of generational garbage collection, the following figure is shown.
In the
The first thing to say is garbage, what's the name garbage?All is garbage, also first,second, I am not against who, everyone here is rubbish!!!HotSpotWTF, hot pots? What about my grandmother's heat, heat,you know?In short, the hotspot is a Java virtual machine to follow the specification of a realization, it was not sun company, but another company, was later acq
-sorting algorithm moves Objects Based on the tag-clearing algorithm. Therefore, the cost is higher, but the memory fragmentation problem is solved.Generational collection Algorithm
The GenerationalCollecting algorithm is based on the garbage collection algorithm obtained after object lifecycle analysis.
As we have discussed earlier, the memory is mainly divide
this option to Java standard implementation. Different implementations use different algorithms.
Undoubtedly, we know that the garbage collection process cannot be enforced. I just found a callSystem.gc()Meaningful scenarios. This article describes how to call System. gc.Java garbage collection process
Garbage collector
Garbage collector for hotspot virtual machines
There is no provision in the Java Virtual Machine specification for how the garbage collector can be implemented, so different versions of the virtual machine provide a large difference in the garbage collector, and will provide the paramet
I believe in the same procedure. Apes often encounter garbage collection problems in their daily work or interviews, and are there any details in the dead of the dead of night on the JVM garbage collection mechanism? It doesn't matter if you don't have time to do it, because it will be smoothed out next.
I. Te
is required. This step is to remembered the application thread exists in the contents of the set logs, and modify the corresponding remembered sets, this step needs to pause the application, parallel running.Survival object calculation and cleanup (live Data counting and Cleanup)It should be noted that in G1, it is not that final marking pause is executed, it is certain to perform cleanup this step, because this step needs to suspend the application, G1 in order to achieve quasi-real-time requi
surface (so that there is no idle hole between the memory occupied by the activity object ), in this way, the idle surface becomes the object surface, and the original object surface becomes the idle surface. The program will allocate memory in the new object surface. A typical garbage collection Algorithm Based on the coping algorithm is the stop-and-copy algorithm, which divides the heap into the object
experience, the vast majority of object creation will soon be discarded and have a short lifespan.、Above is an example.As you can see, the objects that are still being referenced are getting smaller over time. Most objects have a very short life cycle.Based on the above analysis, the performance of the JVM can be improved by the method of heap generation (generations). Heap memory is divided into three chunks: young Generation, older (old Generation)
many surviving objects, the efficiency of the Copying algorithm will be greatly reduced.
3. Mark-Compact Algorithm
To solve the Copying algorithm defect and make full use of the memory space, the Mark-Compact algorithm is proposed. The algorithm Mark phase is the same as Mark-Sweep, but after the Mark is completed, it does not directly clear the recyclable object, but moves the surviving object to one end, then, the memory outside the end boundary is cleared. The specific process is shown in:
For the basic content of the JVM garbage collection mechanism, refer to the previous blog garbage collection mechanism (garbage Collection) IntroductionOn a blog, the memory of the heap is divided into three parts: The
executed, the user object is useless, so it is junk.
Ii. Why is garbage collection required?
We know that objects are stored on the heap. How big is the heap? Although the command parameters can be adjusted, in a 32-bit system, the Java heap size is usually set to 2 GB, and 500 MB is allocated to the new generation (YoungGen) 1.5 GB is allocated to the OldGen space. Even if it is 64-bit, think about ho
old object, and the FGC will be executed, not necessarily because the Old is full. In the first group of data, the FGC will be executed, however, the O zone only has 74.12 of the data
To view the memory of the java Virtual Machine, run the following command: java-stat.
The following is the principle, thanks to the http://jefferent.iteye.com/blog/1123677 here to facilitate viewing, you can also directly copy the url on his blog to view
Virtual machines are divided into three generations:
it does not guarantee that the requests will actually invoke garbage collection. This is the decision taken by the JVM based on the use of the Eden area in memory heap space. The JVM specification leaves this choice to the specific implementations of the various JVMs, so the actual JVM is chosen depending on the implementation of the different JVMs (but remember that you cannot rely on the invocation of th
PHP's garbage collection mechanism is very important in any development language, and PHP's garbage collection mechanism allows developers to avoid memory leaks as much as possible during the development process, and to automatically reclaim variables by reference counting, but there are still memory leaks in certain,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.