Process
We know that the program is static on disk, and when he is loaded into memory, it becomes a dynamic, called a process, as the program is loaded into memory, the distribution in memory is as follows
this figure from http://blog.csdn.net/woshinia/article/details/41722085 specific each paragraph of the role can refer to this article, here we just want to know about , when the program is loaded into memory, it is divided into code snippets, data segments, heap segments, and stack segments. The code snippet is the storage data, the data segment holds some global and static data, the heap segment holds the dynamically created memory object, and the stack segment is the area where the thread stack runs. java virtual machines Java virtual machines (Java VM abbreviation JVM) is an abstract computer that runs all Java programs and is the operating environment of the Java language. This is the official explanation for him, Java Virtual machine can run Java program, where Java Virtual machine is also a program, so when he was loaded into memory also has the above characteristics, in the code snippet to store the JVM's code, in the data area to hold the JVM's data, heap and stack is also used by the JVM. Java programs In some of the blogs that introduce Java programs, we can often see some examples of how Java memory is distributed, such as this article http://www.cnblogs.com/gw811/archive/2012/10/18/ 2730117.html also introduces the Java heap and stack, What is the difference between heap and stack and JVM heap and stack here, and introduce a picture as follows (image from http:// www.importnew.com/14486.html) This diagram clearly expresses the difference between two stacks, which is the memory distribution of a normal process within the operating system, and you can see that the distribution is similar to what we just described. The JVM is also a normal process, so code snippets and data segments are also stored in the JVM's code and data, primarily in the heap and stack. First, the heap, the first permanent generation, the permanent generation is essentially a Java program code area and data area. Classes in Java programs are loaded into different data structures throughout the region, including constant pools, fields, method data, method bodies, constructors, and specialized methods in classes, instance initialization, interface initialization, and so on. This area is a part of the heap for the operating system, and for Java programs It is a space for the program itself and for static resources, allowing the JVM to interpret the execution of Java programs. Next is the new generation and the old age. The new generation and the old era is the Java program really use the heap space, mainly for memory object storage, but its management and ordinary processes have a fundamental difference, the ordinary procedure is requiredDynamic applications, and the JVM is a one-time application, and then is allocated to the Java program successively, so it is more efficient than the normal program. We can see from the above description that the JVM is simulating a "process" in its own heap, which has a code area, a data area, and a "heap" in the "process". Here we can also understand why we can set the memory size of the running virtual machine, we can set the heap size by parameters such as-XMS,-XMX when the program starts. Its nature is still controlled by the JVM in the JVM's heap area through malloc to allocate the specified memory to the Java program for use. Of course is just a simplified model, the JVM's memory allocation is more complex than the above, if according to the allocation, the program will be quite slow, the JVM itself has done a lot of optimizations to improve performance, such as early application of memory. In. NET, the CLR is optimized for different native code based on different CPU type compilation, and runs the local code directly the second time it runs.
Java programs-processes in process