1. The JVM class loading mechanism, what does the class do at each step:

Load (for binary byte streams, convert them into data structures into memory), link (validate (validate metadata, file format), prepare (formally allocate memory for class variables and do initial assignment _), parse (convert symbolic references to virtual machine constant pools into direct references)) _, initialize

2. JVM runtime data area, garbage collection algorithm, determination of cleared objects:

Program counters, Java Virtual Machine stack, local method stack, Method area (shared), heap (shared)

The permanent generation is at risk of running out of memory because it depends on vm memory, whereas the meta space depends on local memory.

1. String exists in permanent generation, which is prone to performance problems and memory overflow.

2. It is difficult to determine the size of class and method information, so it is difficult to specify the size of permanent generation. If the size is too small, it is easy to overflow the permanent generation, while if the size is too large, it is easy to overflow the old generation.

3. Persistent generation can introduce unnecessary complexity to the GC and low collection efficiency.

Oracle may merge HotSpot with JRockit.

Recycling algorithm: mark clearing, mark sorting, copy

GCROOT:

  1. The object referenced in the local variable table in the current virtual machine stack
  2. The object referenced by the class static property in the method area
  3. The object referenced by a constant in the method area

Garbage collector enumeration

Serial/Serial Old, suitable for single-CPU server -XX:+UseSerialGC both new generation and Old generation use Serial collector

ParNew: Shorter than Serial’s STW, multi-threaded, multi-CPU

The ParallelScavenge avenge. The high throughput garbage collector uses CPU time efficiently and performs applications as quickly as possible. It is ideal for performing operations in the background without much interaction.

CMS: Collector is a collector whose goal is to obtain the shortest collection pause time; Four stages: initial marking, concurrent marking, re-marking, and concurrent clearing

Advantages: High efficiency, short pause time

Disadvantages:

CPU resource is sensitive, floating garbage is generated in concurrent cleaning phase, and the use of mark-clean algorithm will cause memory fragmentation problems.

G1: The heap is divided into independent regions of equal size, so that Cenozoic and old age are no longer physically separated

  • Based on the mark-de-clutter algorithm, there is no space fragmentation, and allocating large objects does not trigger a full GC in advance because they cannot get contiguous space

  • Pause times: G1 can control garbage collection times by setting Pause times, but only as much as possible, not always

    **

G1 tracks the value of Garbage accumulation in each Region (the amount of space collected and the empirical value of the collection time), maintains a priority list in the background, and collects the most valuable Region (hence the name garbage-first) based on the allowed collection time. This use of regions and prioritized Region collection ensures that the G1 collector is as efficient as possible in a limited amount of time

Collection process: initial tag, concurrent tag, final tag, filter collection

Compared with CMS, which is suitable for applications with large memory, applications with more than 8GB are generally better than CMS. Predictable pauses are also an advantage

4. Three-color marking algorithm:

White: not accessed

Grey: Accessed, but the reference object has not been accessed

Black: accessed, its reference object has been accessed is not garbage

All concurrent tokens have the problem of missing tokens :(references change during tokens)

Two necessary conditions:

  • Condition 1: The gray object breaks the reference to the white object. That is, the reference to the original member variable of the gray object has changed

  • Condition 2: The black object re-references the white object. That is, the black object member variable adds a new reference.

G1: Write barrier + SATB (need to be maintained after the reference is removed and disconnected, damage condition 1) ZGC: Read barrier (any read will be recorded)

5. Occurrence timing of MinorGC and FullGC:

Minor GC occurs: Minor GC occurs when the JVM is unable to allocate space for new objects, so the more frequently objects are allocated, the more likely Minor GC occurs

Full GC: A MinorGC can occur when the old generation is unable to allocate memory, and a Full GC can occur when the old generation is guaranteed to the young generation. Since the old generation cannot determine how many objects are alive until a garbage collection is performed, Therefore, the old age cannot clear how much space it needs to guarantee, so dynamic estimation is adopted: This is the average of the capacity of objects promoted to the old age at the time of the last collection send as the empirical value, so there is a problem that when a Minor GC occurs, the number of living objects increases significantly (assuming small objects), while the old age is not Full, but the average increases, causing a Full GC to occur

6. Common causes of FullGC:

  1. Active call in the applicationSystem.gc()

    It is unlikely that this is the case. First of all, no one has time to call this method. Second of all, even if someone did call thisSystem.gc()Go to theadviceJVM to support FullGC,Our service turns this parameter on in the startup parameter**-XX:ExplicitGCInvokesConcurrent**, the meaning of this parameter is to display the called**System.gc()**Concurrent GC to CMS, so it does not trigger FullGC.
  2. The common reason for the insufficient space of the method area (meta space) is that the code uses a large number of dynamic agents and generates a large number of proxy classes occupying the method area. If this is the reason, all services will report FullGC problems, but the memory of other machines is very stable in the old age, so check
  3. Insufficient direct memory space is usually caused by code such as NIO
  4. The object was born in the new generation, survived the minorGC and survived to the old age, and continued to eat and wait for death in the old age, until a large number of objects did so. When the old age was filled up, FullGC would be triggered