That day, the two guys in the computer quarreled...

One weekend, CPU and JVM chatted...




905fc8426ef559fdf3c20b794a16f57f.png

Brother, I heard that you are very popular recently

Brother laughed, how dare you dare

6d2af2aec17e9b7e203f8581ed37352e.png



2f5047d0002b46bac0a5803df234da3f.png

Dare you? I think you dare to make a set of virtual machines yourself, it almost emptied me

Brother, you see what you said, I am a Java virtual machine, and eventually I have to send the code instructions to you for execution. I can’t do without you at all, so how can I take you up?

1477929206e1ce1783310b7f55fd17e0.png



6d2af2aec17e9b7e203f8581ed37352e.png

I am very curious. Since I still have to execute instructions in the end, what is the meaning of your existence?

You don't know this. As a middleman, I provide programs with the best quality and convenient service. If you let them directly deal with you, you have to understand your instruction set, your I/O method, and your memory management method, which can be troublesome.

6d2af2aec17e9b7e203f8581ed37352e.png




1477929206e1ce1783310b7f55fd17e0.png

Don't fool me, what you said, the operating system is packaged, and the programs can be called directly. How can it be so troublesome?

。。。。。。

1477929206e1ce1783310b7f55fd17e0.png

You are right, but there is a fatal problem, that is, the operating system cannot help.

1477929206e1ce1783310b7f55fd17e0.png





1477929206e1ce1783310b7f55fd17e0.png

what is the problem?

Cross-platform porting

6d2af2aec17e9b7e203f8581ed37352e.png




6d2af2aec17e9b7e203f8581ed37352e.png

Are you talking about porting to different operating systems?

Not only the operating system, but also may be ported to other architecture CPUs. In this way, the original program cannot be executed.

1477929206e1ce1783310b7f55fd17e0.png




550e7b5576e461698f345fefba76ae97.jpeg

6d2af2aec17e9b7e203f8581ed37352e.png


1477929206e1ce1783310b7f55fd17e0.png

It is easy to ask questions, so what good solutions do you have?

My solution is not to compile the program code into instructions of your instruction set, but to generate an intermediate code defined by me. When running, I will be responsible for translating them into the corresponding CPU instructions under the current platform and handing them to your CPU for execution.

6d2af2aec17e9b7e203f8581ed37352e.png




6d2af2aec17e9b7e203f8581ed37352e.png

Good guy, you didn't say that you didn't take me empty, so that you, the middleman, can make the difference.

But there is no loss to you, anyway, you still can't avoid your level in the end.

1477929206e1ce1783310b7f55fd17e0.png



6d2af2aec17e9b7e203f8581ed37352e.png

c9fc5742a25cca715a19a21a023858fc.png759d585f8616700f3a48bea9fa7bc22b.png44af75a1ed5ea50c079555f8d4d15379.png71107a96a8140c39db7d7170152b7e92.png


6d2af2aec17e9b7e203f8581ed37352e.png

I listen to you, if other languages ​​can be compiled into your intermediate code, you can also execute it?

Well, in addition to Java, we can also execute Groovy, Scala, and yes, we can also execute Python. Isn’t this the same as you? No matter what high-level language it is, it will be compiled into your instruction set and you can execute it. Isn’t this a truth?

1477929206e1ce1783310b7f55fd17e0.png




1477929206e1ce1783310b7f55fd17e0.png

It's a bit 6. What is your middle code like? It is so powerful, how is it different from my instruction set?

It is very similar to your instruction set. The difference is that my "instructions" are not as long or short as your instructions. My unity is all one byte, so it is also called bytecode!

1477929206e1ce1783310b7f55fd17e0.png




6d2af2aec17e9b7e203f8581ed37352e.png

Are all one byte? Don't fool me, the memory address is more than one byte.

Really, I basically use zero-address instructions. The data to be used is on the top of the stack. Just operate directly.

6d2af2aec17e9b7e203f8581ed37352e.png




303c5db5df7950a19a525e67ad634a87.png

All on the top of the stack? How to perform data operations without registers?

Who said there must be registers? I don't need registers, you are based on the register architecture, and I am based on the stack architecture. You can directly manipulate the data on the top of the stack during calculations.


6d2af2aec17e9b7e203f8581ed37352e.png

1477929206e1ce1783310b7f55fd17e0.png




1477929206e1ce1783310b7f55fd17e0.png

Based on the stack? Are you saying that the data used in your instructions is placed on the stack? This stack is in memory, so if data keeps coming in and out, it will frequently access the memory. It must be slow?

It must be slower than you, but I also have an optimization method.

6d2af2aec17e9b7e203f8581ed37352e.png




1477929206e1ce1783310b7f55fd17e0.png

Any way, let me hear

Top-Of-Stack-CAching, TOSCA for short, is the top-of-stack cache. Although the data at the top of the stack is nominally at the top of the stack, but in actual implementation, I secretly put it in your register, which not only reduces the number of memory accesses, but also accesses it faster when you execute it. many.

6d2af2aec17e9b7e203f8581ed37352e.png




6d2af2aec17e9b7e203f8581ed37352e.png

Good guy, you guys have a set in front of you and a set behind your back.

1477929206e1ce1783310b7f55fd17e0.png

2646a7e57e7d8243f3c9b2c1225e4195.png




1477929206e1ce1783310b7f55fd17e0.png

You started talking about "translation". How do you translate and execute these bytecodes?

We have prepared corresponding assembly instructions for each bytecode to complete the behavior defined by this bytecode. Then integrate all the assembler instruction entries of the bytecode into one table, and I will dispatch them for distribution. These assembly instructions will be directly handed over to your CPU for execution.

6d2af2aec17e9b7e203f8581ed37352e.png



0ada451c175c55e9c2d36c76ea7a52a4.png

1477929206e1ce1783310b7f55fd17e0.png

I see, the key to your cross-platform is to generate corresponding assembly instructions on different platforms, right?

6d2af2aec17e9b7e203f8581ed37352e.png

5a81af4f18731bdc3e31259de880b677.png




1477929206e1ce1783310b7f55fd17e0.png

But this sounds a bit like interpretation and execution, which is similar to interpretation and execution of scripting languages.

The bottom layer of the scripting language you mentioned is executed in a "simulation" with a high-level language, and I directly translated the bytecode into assembly instructions, which is much faster than them.

6d2af2aec17e9b7e203f8581ed37352e.png




6d2af2aec17e9b7e203f8581ed37352e.png

No matter how fast it is, that is also interpretation executionfa922b4fae7312bd9a210e5ab5e00651.png

Well, it looks like a unique skill!

1477929206e1ce1783310b7f55fd17e0.png




6d2af2aec17e9b7e203f8581ed37352e.png

What?

JIT, just-in-time compilation, just-in-time compilation technology.

1477929206e1ce1783310b7f55fd17e0.png




6d2af2aec17e9b7e203f8581ed37352e.png

What is this? It looks amazing

In the process of dispatching and distributing, I find that there are frequently executed functions or code blocks. I will start the just-in-time compilation mechanism to directly compile this part of the code into instructions of your CPU. There is no need to use the bytecode dispatch table to execute later.

1477929206e1ce1783310b7f55fd17e0.png




6d2af2aec17e9b7e203f8581ed37352e.png

Frequently executed functions are easy to understand. What does the frequently executed code block mean?

For example, a loop body in a function is executed many times in a loop. Although the function may not be called many times, if the loop is executed a lot, it will also trigger my just-in-time compilation mechanism.





6d2af2aec17e9b7e203f8581ed37352e.png

How do you determine whether it is frequent? Isn’t it intuitive?

Of course not. I don’t know how to count them frequently. This number is the counter. I will count the number of function calls and the number of executions of the loop body.

1477929206e1ce1783310b7f55fd17e0.png



6d2af2aec17e9b7e203f8581ed37352e.png

Good boy, there are two brushes, and I didn’t spend much time

I'm not a fool639b8c67cf2d6ac3071cdb8456df9535.gif

d413bd8c31f0fdd60c1e99149434ab88.png




1477929206e1ce1783310b7f55fd17e0.png




f8c0e9d1f6f3db638d25df5b8ed33a31.png

Yeah! Stop talking, the programmer is turned on and is going to work

Isn't it weekend today? Why is he here?6d2af2aec17e9b7e203f8581ed37352e.pngf8c0e9d1f6f3db638d25df5b8ed33a31.png

5ebc270849872aeef26eb4c7b73e0fb8.png




Guess you like

Origin blog.51cto.com/14886635/2550036