In-depth understanding of virtual machine reading notes-runtime data area

Runtime data area

  • Program counter (pc register)
    • The thread is private and the space is small, which is the line number indicator of the bytecode executed by the current thread
    • When the bytecode interpreter is working, the next bytecode instruction is obtained by changing the value of the counter.
    • Dependence on operations such as branching, looping, jumping, exception handling, and thread recovery.
    • Java method: the address of the current bytecode instruction;
    • The Native method is empty.
    • The only memory area without OutOfMemoryError
  • Java Virtual Machine Stack
    • The thread is private and describes the memory model when the Java method is executed
    • When the method is executed, the stack frame is created and pushed onto the stack.
    • Stack frame: used to store local variable table, operand stack, dynamic link, method entry and exit, etc.
      • Local variable table
        • Store the data known at compile time, the memory space is completely determined at compile time, and will not change during operation
        • Various basic data types, 64-bit long and double stack two local variable spaces (slot), the remaining one
        • Object reference (reference type, a pointer directly to the address of the object, or a handle to the object)
        • returnAddress type (pointing to the address of a bytecode instruction)
    • abnormal situation
      • The stack depth requested by the thread is greater than the running depth of the virtual machine, and StackOverflowError is thrown
      • If the virtual machine stack runs dynamically, when the expansion fails to apply for enough memory, an OutOfMemoryError is thrown
  • Native method stack
    • Similar to the virtual machine stack, but serves the Native method
    • The exception is the same as the virtual machine stack
    • The virtual machine specification does not mandate the language, method and data structure used in this area, and can be implemented freely
  • Java heap
    • The largest space, thread sharing, created when the virtual machine starts, used to store object instances
    • Memory space is physically discontinuous
    • Java Virtual Machine Specification: All object instances and arrays must be allocated on the heap
    • When unable to dynamically expand, throw OutOfMemoryError
    • Memory partition
      • young: old defaults to 1: 2
      • Young generation
        • Eden : Survivor = 8 : 1
        • There is an Eden area and two Survivors
        • Eden
          • The newly created object is stored, when the part is exhausted, young gc (Minor gc) is performed.
        • Survivor
          • Every time young gc, the objects that survived eden and the objects of another Survivor are sorted into the current servivor to ensure the continuity of the storage space of the storage itself and the idleness of other space.
      • Old age
        • By default, objects in Survivor that have passed through Minor gc 15 times are stored
        • Or when Minor gc, Survivor has insufficient memory, relying on the old generation to make allocation guarantee, and directly transfer the object into this area
        • Or when the object is larger than a certain size, it is allocated directly in the old generation
  • Method area
    • Thread sharing, used to store loaded constants, static variables, code compiled by just-in-time compiler, etc.
    • Thread safety, when the class is loaded, only one thread is allowed to load certain class information into the method area
    • Permanent generation (removed after 1.8): Hotspot extends gc generation collection to the method area to facilitate memory management like a heap
    • When the memory allocation requirement cannot be met, an OutOfMemoryError is thrown
    • Runtime constant pool
      • Class files store literals and symbol references generated during compilation, and are stored in this area after class loading.
      • Also store the translated direct references
      • Dynamic: allows new variable zones to be run during operation
      • When the memory allocation requirement cannot be met, an OutOfMemoryError is thrown
  • Direct memory
    • Off-heap memory, not defined by the virtual machine specification, not restricted by the virtual machine itself
    • No garbage collection management
    • 1.4 The NIO class introduced, based on the IO method of channel and buffer Buffer, uses the Native function to directly allocate off-heap memory
    • Operate the DirectByteBuffer object in Java as a reference to this memory.
    • Specify the size by parameters, the default is the same as the maximum value of the heap
    • If a memory overflow occurs when allocating memory, it is not to apply for memory allocation, but to calculate the lack of memory and manually throw an exception
  • Metaspace
    • Store loaded class information
    • The metadata area replaces the permanent generation. The essence is similar to that of the permanent generation. They all implement the method area in the JVM specification. The difference is that the metadata area is not in the virtual machine, but uses local memory. The metadata area is frequently used, and an OutOfMemory exception may also occur.
    • The dynamic expansion of the metadata area, the default –XX: MetaspaceSize value is 21MB high water mark. Once touched, Full GC will be triggered and unused classes will be unloaded (the class loader corresponding to the class is no longer alive), then the high water mark will be reset. The value of the new high-water mark depends on the meta space released after GC. If there is little space released, this high water mark rises. If there is too much free space, the high water mark drops.
Published 24 original articles · praised 0 · visits 107

Guess you like

Origin blog.csdn.net/jiangxiayouyu/article/details/105606948