Brush interview questions 25: jvm garbage collection algorithm?

image.png

Garbage collection is the highlight of java language, greatly improving the efficiency of the developer.
That garbage collection GC, when out of memory triggers, different versions of jvm algorithms and mechanisms are different.

I was Li Fuchun, I prepare for the interview, today's question is:

jvm garbage collection algorithm What? What garbage collector?

A: jvm garbage collection first need to mark out the object recyclable, uses up to graph algorithms (starting from objects, draw a graph object references,
when starting from the active object, unreachable objects in the drawing that is recoverable objects may be labeled)

jvm garbage collection algorithm has three, include the following:
1, mark sweep algorithm. (That is marked recyclable objects directly to clean up, it will cause problems of memory fragmentation, but not efficient);
2, mark Collation Algorithm. (That is marked recyclable objects to clean up, finishing the process of cleaning up the memory to solve the memory fragmentation problems);
3, marking replication algorithm. (Copy the marked objects to clean up, no clean-up of the object to the area, then swap referenced to solve the problem of memory fragmentation, but need to maintain object-relational bring a certain price)

Common are the following four garbage collector, with the version of jdk iteration is increasing. Are listed below:
. 1, serialGC, i.e., single-threaded garbage collection, the advantage of simple, the disadvantage is caused stop-the-world problems, and an earlier version of the garbage collector
2, ParallelGC, i.e. parallel garbage collector (the new generation, old age is collected in parallel), for comparing the throughput of the scene;
3, CMSGC, priority response time garbage collector, for web applications, pose a problem of memory fragmentation.
4, G1GC, taking into account the response time and throughput garbage collector for memory consolidation have zoning board way, it is the default garbage collector java8 of;

Garbage collection process

Garbage mainly in two areas: in accordance with the java virtual machine memory model, i.e. heap, the method area the metadata region;

Garbage collection process heap area as follows:

1, the object is created on the heap of a new generation of eden region;

2, when the memory of the time or periodic trigger minorGC, unmarked copy of the object region to survive, marked objects directly recovered;

3, in the life cycle jvm continuous cycle: Trigger minorGC, service area converted From area, constantly copied Eden and From area there are objects to to area,
and organize to prevent fragmentation; the life cycle of more than jvm copy objects to the threshold set by old's old district;

4, when really a heap out of memory, triggering fullGC, rearrange eden, from, to, old district, will generally result in system capacity rapid decline.

Metadata garbage collection area: mainly when certain types no longer in use, unloaded from the metadata area.

summary

Benpian answered marking algorithm for garbage collection, garbage collection algorithm, a common garbage collector, garbage collection process.

image.png

The original is not easy, please indicate the source.

Guess you like

Origin www.cnblogs.com/snidget/p/12611730.html