Local method stack of runtime memory data area

  • The Java virtual machine stack is used to manage the calls of Java methods, and the native method stack is used to manage the calls of native methods.
  • The native method stack is also thread-private.
  • Allows to be implemented as fixed or dynamically expandable memory size. (same in terms of out-of-memory)
    • If the stack capacity requested by the thread exceeds the maximum capacity allowed by the native method stack, the Java virtual machine will throw a StackoverflowError exception.
    • If the native method stack can be dynamically expanded, and cannot apply for enough memory when trying to expand, or if there is not enough memory to create the corresponding native method stack when creating a new thread, then the Java virtual machine will throw an outofMemoryError abnormal.
  • Native methods are implemented using the C language.
  • Its specific method is to register the native method in the Native Method Stack, and load the native method library when the Execution Engine executes.

  • When a thread calls a native method, it enters a whole new world that is no longer limited by the virtual machine. It has the same permissions as the virtual machine.
    • Native methods can access the runtime data area inside the virtual machine through the native method interface.
    • It can even directly use registers in the local processor
    • Allocate any amount of memory directly from the heap in native memory.
  • Not all JVMs support native methods. Because the Java virtual machine specification does not clearly require the language used, specific implementation methods, data structures, etc. of the local method stack. If the JVM product does not plan to support native methods, it is not necessary to implement the native method stack.
  • In the Hotspot JVM, the local method stack and the virtual machine stack are directly combined into one.

 

Guess you like

Origin blog.csdn.net/m0_73843666/article/details/130096007