Run-time data areas

  • The Java runtime data area includes the following areas (note: I oneNote notes, to ensure formatting, most of the text in the article is shown as images)

  • The stack frame
    • Unavailable Table, Local Veriable table
      • The size of the local variable table is determined when the program code is compiled, as can be seen in the compiled class file
      • Hotspot’s Local Veriable table is very much like a register, storing some data temporarily, then storing it back when the calculations are done
      • The minimum unit of the unavailable variable table is veriable slot, and each slot has 32 bytes of memory
      • The remaining parameters are arranged in parameter list order, occupying the local variable slot starting from 1
      • The basic data types, along with reference and return address, occupy one variable slot, while long and double require two
    • Operand Stack
      • Each local variable has its own operand stack.
      • The size can also be determined at the compiler
      • When Frame is created, the action stack is empty. Each entry in the operation stack can hold various types of JVM data, with longs and doubles (64-bit data) occupying two stack depths
      • Method execution, there will be each bytecode instructions to write and extract content in the operation stack, that is, the process of loading and unloading the stack
      • When the operation stack calls another method that has a return value, it pushes the return result onto the stack (passing parameters through the operation stack).
    • B: Dynamic Linking
      • Each stack frame contains a reference to the method that the stack frame belongs to in the runtime constant pool, and this reference is held to support dynamic linking during method calls
      • The parsing phase in the class loading phase converts symbolic references to direct references, also known as static parsing. The other part is converted to direct references at run time, called dynamic linking
    • Return Address (Return value Address)
      • Once a method has started executing, there are only two ways to exit: a method returns an instruction, or an exception exits
    • The frame data area
      • The size of the frame data area depends on the implementation of the JVM
  • The specific process is shown in the figure below

  • Invoke directive (figure below)

  • Mtehod Area: FGC does not clear Mtehod area if it is smaller than 1.8. Mtehod Area automatically clears Mtehod area if it is larger than 1.8. Mtehod Area generates OOM if it is smaller than 1.8
    • Perm Space (<1.8)
      • String constants are located in Perm Space
      • FGC will not clean up
      • The size is specified at startup and cannot be modified
    • Meta Space (>=1.8)
      • String constants are in the heap
      • FGC garbage cleanup is triggered
      • Maximum physical memory if not specified
  • Runtime Constant Pool: Runtime Constant Pool
  • Direct Memory Direct Memory (added after 1.4)
    • Memory of kernel space directly accessible by the JVM (OS-managed memory)
    • NIO, improve efficiency to achieve zero copy