C #, Java This type of interpretation is never compiletable in C / C .
Especially in the 64-bit computer in the future.
I have seen the definition of Byte Code, the virtual machine is very similar to the previous PCode machine.
All virtual machines have only one arithmetic / logical computer, that is, in the case of two operands,
Two operand must first be stack, and then store it in the arithmetic / logical operator after calculation.
Or may also store the results into the stack.
For example, you have to calculate the value of A B C,
Virtual machine generally defined this
Push a (Pressing a Press)
Push b (put B stack)
Add (add two numbers in the stack to the arithmetic / logical computer, assume that it is REGA)
PUSH REGA (press the result to enter the stack for the next step)
PUSH C
Add (add the result with C)
It should be seen that the virtual machine is also called STACK COMPUTER.
Instead of indirect code like C / C
Load Reg1, A
Load Reg2, B
Add Rega, Reg1, REG2
Load reg3, c
Add Rega, Rega, REG3
This shows that the code generated by C / C compiles is close to the actual computer, because of the actual computer
It is Register Computer.
The above operation seems to appear the number of statements, but the speed is different.
The add in the virtual machine is to take out two numbers from the memory (stack), while C / C generated code
Add Rega, Reg1, REG2 is a direct register operation.
We know that the register is in the CPU, and his access speed is better than the memory accesses.
Although now there is now the Cache in the tablets, the speed is still slow, and the data within Cache may
Switched to memory.
There are hundreds of CPU-in-chip registers in Intel's new 64-bit ITANIUM. If you use it for this
The CPU design C / C compiler generated code will have most operations in the register, and its execution speed is greatly improved.
Since REGISTER COMPUTER is so used, isn't it used in a virtual machine?
The reason is not self-cleaning, in order to cross the platform (cross-CPU)! In actual life, most of the server chips are
Register compute (such as Intel, AMD, PowerPC), and most embedded chips are stack
Computer, because the embedded CPU should be designed with small, Stack Computer is only one in the film.
The register makes the CPU smaller.
There is a class of algorithms called register allocation in the code optimization theory of compilation principles, (of course, there are many actual algorithms)
Its basic idea is to set a certain number of registers and then assign to the register when variable allocation. If send
The number of depuses is not enough to assign memory. But these algorithms (based on process, coloring graphics) are quite complicated. So in Java and
C # is not adopted.
Therefore, it is strictly that the Java program in some embedded computers may operate on the same order as C / C .
However, in the server (especially in the 64-bit computer with a large number of registers), its operational efficiency may differ.
Several order levels (especially in the arithmetic intensive application).