JAVA virtual machine architecture

JAVA virtual machine architecture

        J


        The java stack is composed of many stack frames or frames, and a stack frame contains the state of a java method invocation. When a thread calls a java method, the virtual machine pushes a new stack frame onto the thread's java stack; when the method returns, the stack frame is popped from the java stack and discarded.

1. Method area (when the virtual machine runs a java program, it will look up the type information in the method area)

      1) Store the class information that has been loaded by the virtual machine (including the fully qualified name of this type, the fully qualified name of the direct superclass, whether it is a class type or an interface type, access modifiers (public, abstract), and the full name of any direct superinterface. An ordered list of qualified names.),

        2) Constant (constant pool),

                  ----The virtual machine must maintain a constant pool for each type to be reproduced. A constant pool is an ordered collection of constants used by that type.

                        Includes direct constants (string, integer and floating point constants) and symbolic references to other types, fields and methods.

        3) Field information,

                  ---- Field name, field type, field modifier (a subset of public, private, protected, static, final, volatile, transient)

        4) Method information,

       ---Include (method name, method return type, number and type of method parameters, method modifiers (a subset of private, public, protected, static, final, sysnchronized, native, abstract))

                       If the method is not local and abstract, it also needs to store the bytecode of the method, the size of the operand stack and the local variable area in the stack frame of the method, and the exception table.

        

        5) Static variables (all class (static) variables except constants), data such as code compiled by the just-in-time compiler.

        6) A reference to the class ClassLoader,

        7) A reference to the Class class.

  2. Heap

         A java virtual machine has only one heap space, all threads share this heap, each java program has its own heap space, and they do not interfere with each other, but multiple threads of the same java program share a heap, and multi-threaded access to the heap needs to be considered data synchronization problem

        The java heap is the main area of ​​garbage collection, which can be divided into: the new generation and the old generation, and more subdivided into: Eden space, From Survivor space, To Survivor space. Storage: Objects and arrays, etc, each array object in the heap (also holds the length of the array, array data, and some references to array-like data)


3. Program counter

      For a java program, each thread has its own PC register (program counter), which is created when the thread starts. This counter records the address of the virtual machine bytecode instruction being executed. If a Native method is being executed, this counter value is empty (undefined).

4. Java stack

     Whenever a new thread is started, the java virtual machine will allocate a java stack for it. The java stack saves the running state of the thread in units of frames. The virtual machine will only perform two operations directly on the java stack: press the frame as a unit. stack and pop.

      Whenever a thread calls a java method, the virtual machine will push a new frame in the java stack of the changed thread, and use this frame to store parameters, local variables, intermediate operation results, and so on.

5. Native method stack

       Native methods can access the runtime data area of ​​the virtual machine through the native method interface, and can directly use the registers in the local processor. They have the same permissions or capabilities as the virtual machine. Any native method interface will call the native method stack. When the thread calls When the java method is used, the virtual machine creates a new stack frame and pushes it into the java stack. When it calls a native method, the virtual machine keeps the java stack unchanged, and no longer pushes a new stack into the java stack of the thread. Just simply connect dynamically and call the specified native method directly. The memory area occupied by the native method stack is not necessarily of a fixed size, and can be dynamically expanded or contracted.

       

                       


                          

              

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325388937&siteId=291194637