JAVA Foundation (1)

1. What is JVM?
JVM is a virtual machine, a virtual computer that can run programs written in JAVA and interact with real computers by imitating real computers.
2. JVM memory structure
The JVM memory structure is divided into three blocks: heap memory, method area, and stack.
3. In JVM, the difference between heap, stack, method area, direct memory, heap and stack
write picture description here
write picture description here
3.1 JAVA memory subdivision: JAVA heap, JAVA stack, method area, local method stack.

3.2 The method area is an area shared by each thread, which stores class information, constants, and static variables.

3.3 The JAVA heap is also an area shared by threads. The instance of our class is placed in this area. It is conceivable that your system will generate many instances, so the space of the java heap is also the largest. If the java heap space is insufficient, the program will throw an OutOfMemoryError exception.

3.4 The java stack is a private area for each thread. Its life cycle is the same as that of a thread. A thread corresponds to a java stack. Every time a method is executed, an element is pushed into the stack. This element is called a "stack frame", and the stack The frame includes the local variables in the method and the operation stack used to store the intermediate state value. There are many details in this, which we will talk about later. If the java stack space is insufficient, the program will throw a StackOverflowError exception. Think about the circumstances under which this error is likely to occur. Yes, recursion. If the recursion depth is deep, a large number of methods will be executed. The more methods, the more java stacks are occupied. The bigger the space.

3.5 The role of the native method stack is similar to that of the Java stack, except that it is used to represent the execution of native methods. The methods stored in the native method stack call the native method interface, and finally call the native method library to achieve the purpose of interacting with the operating system and hardware.

3.6 PC register, here our class has been loaded, and the instance objects, methods, and static variables have all gone to the places where they have been changed, so the question is, how to execute the program, which method is executed first, and which method is executed later, The order in which these instructions are executed is controlled by the PC register, and its function is to control the execution order of program instructions.

3.7 The execution engine, of course, executes the program instructions in sequence according to the order of instructions allocated by the PC registers

Guess you like

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