This is the third day of my participation in the August More text Challenge. For details, see:August is more challenging

Program counter

  • Thread private
  • Points to the address of the executing virtual machine bytecode instruction. If it is a local method, the value is null
  • There is no OutOfMemoryError area

Java virtual machine stack

  • Thread private;
  • The life cycle is the same as the thread;
  • Represents a memory model for Java method execution: each method executes while creating a Stack Frame to hold itLocal scale, operand stack, dynamic link, method exitAnd other information.
    • The process of each method from call to completion corresponds to the process of each stack frame from the virtual machine stack to the stack.
  • Request if the thread stack depth is greater than the depth of the virtual machine allows, ran out of the StackOverflowError exception; Failed to obtain enough memory, throwing an OutOfMemoryError.

Local method stack

  • Thread private;
  • Similar to the Java virtual machine stack, but for Native methods.

The Java heap

  • Thread sharing;
  • The largest chunk of memory in the Java virtual machine.
  • Its only function is to store object instances:All object instances and arrays are allocated on the heap;
  • Is the primary area of the garbage collector. In detail, it can be divided into new generation and old age. In detail, it can be divided into Eden space, From Surivor space and To Surivor space.
  • The Java heap can be in a physically discontinuous memory space, as long as the logic is continuous. Mainstream virtual machines pass-XmsAnd *** -xmx *** control;
  • An OutOfMemoryError is thrown if there is no memory in the heap to complete instance allocation and the heap cannot grow any further.

Methods area

  • Thread sharing;
  • Stores data such as class information, constants, static variables, and code compiled by the real-time compiler that has been loaded by the VM.
  • Has been called non-heap;
  • Sometimes calledPermanent belt, cause: HotSpot virtual machine expands GC band collection to method area;
  • An OutOfMemoryError is thrown when the method area memory cannot meet the memory allocation requirements.

    Runtime constant pool

    • Part of a method area;
    • Stores various literal and symbolic references generated at compile time;
    • OOM error is the same as the method area.