Interest due, find some simple introduction about the JVM, be it literacy.
1. JVM implementation mechanism
Java Virtual Machine is a small computer, has its own instruction set, with its own file system, management, and data within the table is responsible for reading the byte code class file inside, and then converted into different operating system, CPU instructions, making Java programs on different operating systems up and running smoothly. Therefore, the JVM can Window into bytecode instruction set Window system, Linux's JVM byte code can convert the bytes into Linux systems, the same token there is Solaris, which is not common among.
Although a prototype first developed by Sun, but in fact, developed to any vendor can implement themselves to a virtual machine, used to read the byte code into the OS command. We can think even with the Java programming language, JVM does not matter, because even if you use Notepad to write a string of byte code, but also allows to parse the JVM to run, as long as you pass the JVM byte code verification.
JVM verification is very strict, they talk about some interesting places here. Members will recall that the icon is a cup of Java coffee? Study its history we might find out why, but there are even more obvious way is how to determine whether a file JVM is the class file? JVM approach is to read the first 4 bytes into a hexadecimal number 16, to determine whether this number is equal to 0xCAFEBABE. Noticed the word begin?
"Cafebabe", represents a foreign coffee brand, called Peet'scoffee-baristas seem to like. In order to facilitate creation of Java memory of those who choose such a class of 16 hexadecimal numbers as a standard file header, so any class file must have the 4 bytes in the head. We can implement this interface DataInput class to test, read any one of the first class file int, int in Java which is four bytes. 16 hex will be converted into a 0xcafebabe's. So here to tell you is, JVM is actually not so mysterious, we can fully understand its structure. Introductions over and then look at the JVM JVM implementation mechanism within the basic concept.
2.JVM the basic concept of the internal
Java virtual machine inside an idea, all the enumeration is unrealistic, too complicated and no meaning. Unless you really want to do yourself a JVM. I only listed some concepts:
First we look at a variable called ReturnAddress, which is used to store method JVM or to jump the export basis, to any address stored in the variable will be in accordance with the address to jump. We need to note that finally there is a higher return than the method of the priority assigned to ReturnAddress. Method of return and finallyreturn exist, it must be inside by finally return prevail.
Have their own JVM Heap, can be shared for all threads, all objects are stored, the memory is allocated dynamically. For each thread has its own Stack, stack inside the storage unit called Frame (frame). Frame inside to record the zero variable, object reference address, method return values and other data. JVM There is also a place called MethodArea, store the executable code section by section, each section is a method body, can also be shared for all threads. In fact, we say that a thread running from the run way up, it is saying the class is declared in the other two concepts. Because all other methods, including the object, this time as a resource to be threads.
JVM has its own memory management program, because it has the function of the file system, we can as a small database, the inside has lots of different tables. The field may be another table a table of address can also store the data value is the address of a value. JVM when the class of all running calculation of the analytical verification management, are actually changes in the management of these tables, if the point of view from the database, JVM does is based on your code to handle multiple tables then the final the results of the process is returned to you. Inside the table structure including the class of the table, field table, method table, attribute table and so on.