GitHub github.com/wangzhiwubi…
Big Data into the Road of God series:
GitHub github.com/wangzhiwubi…
Java Advanced Feature Enhancements – Collection
Java Advanced Feature enhancements – Multithreading
Java advanced features enhancements -Synchronized
Java Advanced feature enhancements – Volatile
Java Advanced Feature Enhancements – Concurrent Collections framework
Java Advanced Features enhancement – Distributed
Java Advanced Feature enhancements -Zookeeper
Java Advanced Features enhancements -JVM
Java Advanced Feature Enhancements -NIO
The public,
-
The only net from 0 to help Java developers to do big data domain public number ~
-
Http://import_bigdata/import_bigdata/import_bigdata/import_bigdata/import_bigdata/import_bigdata/import_bigdata
Memory allocation and reclamation policies
Memory allocation of objects, is allocated on the heap (may also be separated after the JIT compiler for scalar type and indirect allocated on the stack), object mainly distribute on the new generation of Eden area, a few cases may be directly allocated in old age, distribution rules are not fixed, depends on the current configuration and related parameters using a combination of the garbage collector.
Here are some of the most common memory allocation rules for you to learn.
Objects are allocated in Eden first
In most cases, objects are allocated in the Eden region of the new generation. When the Eden area does not have enough space to allocate, the virtual machine will initiate a Minor GC.
👇Minor GC vs Major GC/Full GC:
- Minor GC: Collect the new generation (including Eden and Survivor regions). Because Java objects are mostly ephemeral, Minor GC is very frequent and generally fast.
- In the old days, there were Major GC’s, often accompanied by at least one Minor GC, but not always. Major GC is typically 10 times slower than Minor GC.
There is no formal definition of either Major or Full GC in the JVM specification, so it is simply assumed that the Major GC cleans up old ages and the Full GC cleans up the entire heap.
Big object goes straight to the old age
Large objects are Java objects that require a large amount of contiguous memory space, such as very long strings or data.
The probability that a large object can be stored in Eden area is relatively small, and the probability of allocation guarantee is relatively high. However, allocation guarantee involves a large amount of replication, resulting in low efficiency.
Virtual machine provides a – XX: PretenureSizeThreshold parameters, make more than the set value of object directly in old age distribution, the aim is to avoid happen between Eden area and two Survivor area a lot of memory copy. (Remember, the new generation uses copying algorithms to recycle garbage?)
Long-lived objects will enter the old age
The JVM defines an object age counter for each object. After a Minor GC occurs in the Cenozoic, the age of the surviving objects is +1, and when the age exceeds a certain value, all objects beyond that value are moved to the old age.
Use -xxMaxTenuringThreshold to set the maximum age of the new generation. Any object that exceeds this threshold will be moved to the old age.
Dynamic object age determination
If the total size of all objects of the same age in Survivor of the current generation is greater than half of Survivor space, objects of age >= this age can enter the old age directly without waiting until the age specified in MaxTenuringThreshold.
Space allocation guarantee
Before JDK 6 Update 24, the virtual machine checks to see if the maximum available contiguous space of the old generation is greater than the total space of all objects of the new generation. If this condition is true, the Minor GC is guaranteed to be safe. If not, the virtual machine checks to see if HandlePromotionFailure is set to allow guarantee failure. If so, the virtual machine continues to check if the maximum contiguous space available in the old age is greater than the average size of objects promoted to the old age over time. If so, A Minor GC will be attempted, although this Minor GC is risky; If less than, or if the HandlePromotionFailure setting does not allow risk, then do a Full GC instead.
After JDK 6 Update 24 the rule changes to: Minor GC is performed whenever the contiguous space of the old generation is greater than the total size of the new generation or the average size of the successive promotions, otherwise Full GC is performed.
By removing discarded data from the old to expand the free space of the old, so as to guarantee the new generation.
The process is to assign the guarantee.
👇 summarizes the circumstances in which the JVM might be triggered for Full GC.
-
This method is called to advise the JVM to do Full GC. Note that this is a recommendation rather than a rule, but in many cases it will trigger Full GC, increasing the frequency of Full GC. Normally we just need to let the virtual machine manage the memory itself. We can disable system.gc () by using -xx :+ DisableExplicitGC.
-
There is insufficient space on the old s Old s space will trigger a Full GC, if after the operation space is still insufficient, will throw out the following error: Java. Lang. OutOfMemoryError: Java heap space
-
Permanet Generation The method area of the runtime data area in the JVM specification, also known as Permanet Generation in the HotSpot VIRTUAL machine, stores class information, constants, static variables, etc. When the system has a large number of classes to load, reflected classes, and called methods. The permanent generation may be Full, triggering the Full GC. If after the Full GC can’t recycle, then the JVM throws the following error message: Java. Lang. OutOfMemoryError: PermGen space
-
Promotion failed and Concurrent mode failure promotion failed occur during CMS GC, which is the guarantee failure mentioned above. Concurrent mode failure is the result of running out of space in the old age when an object needs to be put into the old age during the CMS GC.
-
The average size of the Minor GC promoted to the old generation is larger than the remaining space of the old generation
(after)
Please stamp: making the original https://github.com/wangzhiwubigdata/God-Of-BigData pay close attention to the public, push, interview, download resources, focus on more big data technology ~ data into the way of god ~ update is expected to 500 + articles, has been updated 50 + ~Copy the code