In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the knowledge of java virtual machine". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the knowledge of java virtual machine".
1. Take a brief look at the operating system
The level is limited, it is impossible to understand the operating system so thoroughly, just talk about my own understanding!
When it comes to the operating system, we must be both strange and familiar, why? Because we often use operating systems, such as windows series, unix series, macos and so on, we start an operating system automatically as soon as we turn on the computer every day, but how many people really understand the operating system thoroughly? We always use some of the most common applications in the operating system, such as qq, LOL, Taobao, 360and Youku, etc. However, we pay little attention to what the operating system can do and what will happen if there is no operating system?
All the computer structures we use today have evolved from the von Neumann computer, so let's take a brief look at the von Neumann computer structure:
We can see that we basically use these parts when we use computers, and these parts are enough for us to run a program. So, why do we need an operating system?
First of all, we have to consider that because the arithmetic unit can recognize the binary code, we can only enter a lot of code consisting of zeros and ones in the input device, which is simply a mudslide and desperate. However, this is how the early computers were programmed. We manually write a lot of zeros and ones to give instructions to the drivers of those screens, cpu and other hardware (such as sound drivers, graphics card drivers, and then the underlying drivers actually use high and low potentials to change the hardware). There is no thread or cpu waiting time at this time. It is conceivable that the efficiency is touching!
Programming is really painful when the operating system does not come out, and most people really can't do it! After many years, we finally have an operating system, which is essentially a piece of software. we can simply think of the operating system as an encapsulation of these drivers, providing two types of interfaces inside the operating system (which can be called the kernel). One is that as long as those hardware drivers implement these interfaces, the operating system uses those hardware devices through these interfaces. Then another kind of interface is for us programmers to implement, we only need to program for these interfaces and we can operate the hardware indirectly!
The JVM we are familiar with implements the kind of interface provided by the operating system for programmers, and JVM provides some java api to JAVA programmers. We only need to control the operating system indirectly through jvm according to java api, and then issue instructions to the driver. Finally, we can process the data in those hardware.
So we can take a look at the following diagram (ignoring UNIX commands and libraries for the time being). The application written by the user can be seen as that JVM,JVM can issue some instructions to the operating system kernel according to the system call interface provided by the operating system, and the kernel will call the hardware driver to perform some operations on the hardware, such as reading file data, writing data to the file, and so on.
Because the operating system provides such a powerful function, almost all of our programming languages are programmed on the basis of the operating system, and then through things such as interpreters, we convert the programs we write into machine code that the computer can recognize, and then call the operating system interface, and finally realize the operation of the hardware.
By the way, the applications written by users here can be regarded as QQ, Youku, KuGou Music and other software. if it is a single-core cpu, and you open multiple applications at the same time, then cpu will switch back and forth in multiple applications, but because the switching time is too short, we can't feel it, and we thought it was running at the same time! Just like a movie, in fact, the movie is a picture to turn the page every few seconds, but our eyes can not detect it, and we move the mouse on the screen, why is it so smooth? Because our screen refreshes every few seconds, of course we don't notice it.
Now let's take a look at the definition of the operating system: a set of control and management of computer hardware and software resources, reasonable scheduling of all kinds of jobs, and a collection of user-friendly programs. "do you understand? let's move on!"
two。 Memory structure of operating system
We can simply take a look at the memory structure of the operating system, generally look up the information we see is like the following picture, we certainly do not understand! What the heck is all this, Madd? I don't know what to do except that stack and pile!
So we can modify it slightly to get rid of some things that are not conducive to our understanding, as shown in the following figure, whether we are familiar with it a little bit, it seems to be very similar to the memory structure of jvm!
Let's add the PC registers of the hard disk and the operating system to try the effect, as shown in the following figure! Is there any sense of deja vu? yes, jvm is almost exactly the same as this. The hard disk here is actually equivalent to the method area of jvm (the method area is also called permanent generation, and you can tell by its name that it can be saved forever! ), and the local method stack in jvm is not in the memory structure of jvm, which actually refers to the stack of the operating system.
The PC register of the operating system is similar to the PC register of jvm, which records the address of the current CPU running command.
The role of 3.jvm in operating system
To take a simple example, when we double-click QQ on the computer desktop, the QQ application starts, the operating system creates a process, and then opens up space in the operating system heap for the process to store the data generated in the process.
For the operating system, JVM is the same as the QQ application, so we can get a picture like this:
Finally, we improve the memory structure in jvm, as shown in the following figure:
Seeing this, we can't help laughing. It turns out that jvm is done according to the appearance of the operating system. If we look at it from the point of view of the operating system, jvm is actually a normal application. If we look at the java bytecode file from the point of view, in fact, jvm is equivalent to an operating system, putting the bytecode file into the hard disk (method area) of the virtual operating system jvm, and then reading the data in the other method area in jvm, creating objects and other subsequent operations.
The operating system stack is basically the same as the jvm stack; the operating system stack and the jvm stack are basically the same, but the way of releasing memory is a little different. The operating system stack is released manually by the programmer, while the jvm heap is automatically cleaned by gc.
Now let's take a look at Baidu's definition of jvm. We should know what jvm is by now. Ha ha
4. Information in the method area
Although we briefly said earlier that the data in the method area has basic information about classes, static variables and constant pools, it is quite general.
Now let's look back at the specific information stored in the jvm method area:
(1) Class information
(2) Field information
(3) method information
(4) constant pool
(5) static variable
(6) A reference to the Class object
(7) A reference to the classloader that loads the class
(8) method table (some JVM has, some JVM does not): this is an array that holds references to instance methods of all objects created in the heap of this class, but is memory-intensive, so some jvm designers do not design this method table.
The corresponding java code is as follows:
Public final class com.wyq.test.ClassStruct extends Object implements Serializable {/ / 1. Class information: including access modifier, full class name, parent class name, implementation interface, etc. / / 2. Object field information: including access modifier, type, field name private String name; private int id; / / 4. Constant pool: constants and some symbols refer to public final int CONST_INT=0; public final String CONST_STR= "CONST_STR"; / / 5. Static variable public static String static_str= "static_str"; / / 3. Method information: including modifiers, method return value, method name, local variable, method body (content in curly braces) public static final String getStatic_str () {return ClassStruct.static_str;}}
You can clearly see that what is saved in the method area is all the information in the bytecode file!
5.java program execution flow
Now let's combine the knowledge of the operating system and the picture above to see what is going on in the computer when we run a java program. Forget about caching.
1. When we finish writing a java source program in Eclpse, we must save it in Ctrl+S. This action is to save the source program to the computer's hard disk.
two。 Then we run a main method, at which time the compiler will read the source program from the hard disk into memory and compile it into a bytecode file (note that this bytecode file does not have to be compiled by this computer, as long as it is a bytecode file that conforms to the bytecode file format, as long as it is a bytecode file format, which can be sent to you by someone else's computer; this is in line with the principle of java compiling and running everywhere.)
3. When we run a main method, for the operating system, we create a new process and request the memory space of the process in the operating system heap. We call this memory space JVM (note that if you run two java programs, then two jvm memory space will be created here)
If a 4.jvm instance is created successfully, the memory space in the instance will be allocated, such as java stack, java heap, method area, etc.
5. Because of the class loading subsystem, the class loader is first loaded into the java heap, and then the class loader specifies the path to load the bytecode file (parent delegation mechanism) according to the class name of our java source program, and puts it into the method area.
6. The bytecode file is executed by the execution engine, along with validation, preparation, parsing, and initialization, resulting in the generation of Class objects and instantiated objects in the java heap.
7. If you call the local method (that is, the Native modified method) will involve the local method stack (similar to the function of the java stack, pressing the stack and the bullet stack), press the stack frame in the operating system stack, and if the method in the local method is also called java, at this time press a stack frame in the operating system stack, and then the next stack frame goes to the jvm stack, a very interesting thing.
8. When our method call is finished, the stack frame pops up and the stack is cleaned up; then gc will reclaim the objects in the java heap and release the memory space, and then gc will clean up the method area, and then the memory space in the jvm will be cleaned up.
9 the operating system heap jvm is cleaned and the jvm process ends.
Thank you for your reading, the above is the content of "what is the knowledge of java virtual machine". After the study of this article, I believe you have a deeper understanding of what is the knowledge of java virtual machine, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.