[GC]-depth understanding of JVM garbage collection interview hotspot

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/sinat_27933301/article/details/76222089

  "Heap" is a "run-time" data area, etc. are established by the new directive, the Java heap is Java's garbage collection mechanism responsible for processing. The heap is dynamically allocated memory size, the garbage collector may automatically reclaims the memory space is no longer in use. The so-called memory refuse means to open up the heap memory space, when not to become a "garbage."
  Java, this part of the "junk" program may be a Java virtual machine discovery and automatically removed. Java language provides a system-level thread-level - the garbage collector thread to keep track of every piece of memory space allocated out, when the JVM is idle loop, automatic recovery of each piece of memory that can be recycled.
  The garbage collector is entirely automatically performed, it can not be enforced. Programmers can do is call System.gc () to "recommend" the garbage collector program. The object reference variables are initialized to null value, to suggest the garbage collector to collect the object.
  finalize () Called before the object is garbage collection.
  JVM using a generational garbage collection the way, mainly because when the program is running will have the following characteristics:
  1. Most objects created soon after the object is not to use it. (98% of target)
  2. Most of the objects have been used rarely go to reference the newly created object.
  So will Java objects into objects of young and old objects. JVM memory is divided into two areas called "new generation" and "old year." "New Generation" area in the vast majority of newly created objects are stored in a region where, in general, smaller and higher frequency of garbage collection. "Old Age" area is stored in the object survived a long time in the "new generation", these objects will be transferred to "Old Age" zone.

1, what objects need to be collected

  The object is to collect memory there is no reference position.

2, how to locate the object is not referenced?

  Reference count (which is stored in the heap data objects (object header)): once an object is referenced, then the application is increased by one count, if there is no reference, the reference count minus 1 equals 0, it means that the object need to be recycled.

3. Under what timing GC recycling it?

  When a new object is created, when insufficient memory space, the recovery began Gc (the deleted object instance).

4. What are the characteristics?

  Will in the end all the threads of execution, a program to reduce response time.

5, which has a garbage collection algorithm?

[GC]-depth understanding of JVM garbage collection algorithm

6, the difference between the Minor GC and Full GC

  • New Generation GC (Minor GC): refers to the place in the new generation garbage collection action, because most of Java objects have properties Chaosheng evening off, so Minor GC very frequently, usually recover relatively fast speed. Minor GC is triggered when the young generation is full, full of the young generation here refers to the generation of full Eden, Survivor will not lead to full GC.
  • Old's GC (Major GC / Full GC): GC refers to occur in old age, there was Major GC, often accompanied by at least one of the Minor GC (but not absolute, it is directly in the collection policy ParallelScavenge collector's Major GC strategy selection process). MajorGC generally slower than the speed of more than 10 times Minor GC.

7, at what time to trigger full GC?

Less than (1) year old space
  new generation of objects into, and created large object, large arrays, can not find a large enough contiguous space to allocate the current object.
(2) lack of permanent generation of space
  for the class of some of the information stored in the permanent generation, etc., when the system is in the class to load, when more reflective of classes and method calls, perpetual generations may be full.
Promotion failed concurrent mode failure occurs and (3) CMS GC when
(4) statistically obtained Minor GC promoted to an average size of old generation is larger than the remaining space of the old generation)
call (5) System.gc () method

Guess you like

Origin blog.csdn.net/sinat_27933301/article/details/76222089