Lars behind

(1) Let’s start with smalltalk

In the last book " Alan Kay" , we talked about Smalltalk, the world's first language virtual machine-based programming language, and its creator: Alan Kay. Today I will follow the path of the language virtual machine, then go to the system virtual machine "Virtual Machine : IBM-S/360-OS/2 ", and finally go to the container technology we are going to talk about today, and I still go through a god-man To tie these things together, this guy is: Lars bak.

This man of God, like Alan Kay, also came from Xerox Laboratories. Although Alan created Smalltalk and the language virtual machine, the performance of the computer at that time was too poor to run the language virtual machine with high performance, so Smalltalk could only be played in the laboratory and could not be popularized to the industrial and commercial circles on a large scale. I thought about it. When I was learning Java in 1999, I felt that the java virtual machine was very slow. I remember that it was only after 2004 that the Java virtual machine felt faster, so it was even more wishful thinking to use virtual machine technology for programming languages ​​​​in the 1980s. So Alan Kay's main contribution is not Smalltalk and language virtual machines, but GUI-MVC-object-oriented.

I said in my last book:

C++ is borrowed from Simula, the originator of the object-oriented programming language, rather than Smalltalk. I think the root cause may be that C++ authors feel that they appreciate object-oriented thinking but not language virtual machines. After all, C language is known for its high performance.

Apple's Object C borrowed from SmallTalk. I didn't understand this connection at first, and I didn't quite understand when I saw Apple doing LLVM in the past. Now, Ojbect C-Smalltalk-LLVM, in such a series, I am right. Are you right? Do you understand Apple's intention to do LLVM?

In fact, a language virtual machine is divided into several layers:

  • programming language layer

  • Forward compiler: In fact, it contains four parts: checker-optimizer-compiler-linker. This forward compiler is to compile the source code into intermediate bytecode

  • Intermediate Bytecode - Virtual Instruction Set Layer

  • Backward compiler: such as compiling into binary code that the machine can recognize, or object code (such as JS code)

  • Executing a virtual machine: In fact, it is the same as a virtual computer, doing core application loading-execution, calculation (thread-concurrency-lock), memory (memory allocation-recycling)

As for other things such as file system and memory-file exchange, they are all handed over to the operating system, and IO driver control is also handed over to the operating system.

So everyone sees that those who engage in programming language-compiler-language virtual machine-operating system are all knowledge sharing. So Microsoft, a company that develops BASIC interpreters on personal computers, also developed an operating system later.

(2)JVM

Closer to home, let's come back and talk about our great god Lars bak.

This great master took over Smalltalk and has always had a dream to promote this programming language to the business community, so he set a goal: to make Smalltalk run at 75% of the performance of C language.

So he made a magic change: at the programming language level-forward compiler level-backward compiler level-execution virtual machine level, he modified it everywhere, and changed it to one thing: StrongTalk. So I thought about Java, Scala, Kotlin, don't they all lead to the same goal?

Why am I talking about Java here? Well, everyone knows that Java's development of JVM is actually based on the idea of ​​Smalltalk language virtual machine, in order to uniformly shield Japanese home appliances with huge differences in hardware. But people from Sun are good at operating systems (Unix-Solaris), and not good at programming languages-virtual machines. So the Java virtual machine was still interpreted in 1997, just like the Dbase, VBasic, and JavaScript we played in the early years, of course the performance was slow.

What to do? You have to find the originator, whoever invented it. As a result, Sun Corporation acquired the great god Lars bak. This is later Sun's official JVM: Hotspot JIT just-in-time compiler.

This great master has not been idle after solving the biggest performance problem of java. He is responsible for the J2ME specification design at Sun. You must know that J2ME is the original intention of Java's origin, and it is also the most demanding hardware condition. If you can run the slow java with high performance on the smallest hardware resources, then you will realize the original intention of Java. So, lars started to engage in J2ME CLDC. CLDC refers to Connected Limited Device Configuration, limited connection device configuration, this version is mainly aimed at devices with small batteries, small size, and limited hardware resources. Such as mobile phones.

The language virtual machine included in the J2ME CLDC version is the KVM that everyone has heard of in the past. This is the masterpiece of the Great God. Think about how many games were written in KVM before iPhone and Android. However, if you think about it, the master has created the language virtual machine so many times in a row, and you can understand it. The master has thoroughly played with the virtual machine.

(3) V8

After the master finished J2ME and KVM, he realized that it was boring, so he went to Google. After going to Google, it was a blockbuster, and the Chrome browser was born, and it immediately swept the IE market with lightning performance. Why is Chrome so fast? It is because the great god has created a JS execution engine: V8.

We just said that JavaScript is interpreted, and a JS interpreter is built into the browser, so the performance must be slow. But it is more difficult for programmers to replace interpreted JavaScript with compiled JavaScript. This is the power of habit. The Great God didn't dare to touch everyone's cheese at that time. So the master thought about it: I can't make troubles at the programming language-compiler level, then I will make troubles at the next level. The great god's enthusiasm for changing Smalltalk back then has come out again.

The Great God built a V8 language virtual machine. The principle is actually: After the browser downloads the JS code from the server, it enters the Great God's vision. Great God treats JS source code as Java source code, and performs checker-optimizer-forward compilation into bytecode-backward compilation into machine code-language virtual machine to load and execute. That is to say, what you see is JS source code, but what is actually executed internally is binary code. Don't look at the great master with so many steps, but we don't feel slow at all. We can imagine the engineering skills of the great master in the compiler-language virtual machine.

In 2004, the speed of ADSL network accelerated, the wave of Web2.0 emerged, and AJAX brought a silky experience of refreshing data. Adobe's heart itch. The same is the three major plug-in technologies: Flash, Applet, and ActiveX. Applet is the first to exit (Java has embarked on the Servlet-JSP road), ActiveX is unwilling to embark on the path of Silverlight, and Flash has embarked on the road of Flex RIA. Google is also not reconciled, so they built a set of GWT, which is also an RIA rich web application, but Google did not engage in a plug-in model, but developed a rich web UI with Java, and then provided a compiler to compile the Java source code into Javascript code. Hehehe, we always see the source code compiled into binary, but rarely see the source code compiled into another programming language. Google is also really amazing.

But I personally understand Google's approach. After all, Google's rendering engine initially used Opera's Presto rendering engine, and later replaced it with the Webkit WebCore rendering engine used by Apple's Safari browser. Later, Apple replaced the Webkit engine with the Webkit2 engine, and Google changed Webkit2 magic to Blink. rendering engine. The rendering engine Webkit of Apple's Safari browser is actually the work of the famous Unix GUI desktop team KDE in the Internet era: KHTML technology hopes to make the web page UI the same as the local GUI.

But Google translates the Java source code into JavaScript source code through the checker-optimizer-compiler and hands it to the browser V8 JS engine. V8 then relays the JS checker-optimizer-forward compilation into bytecode-post to compile to machine code.

So I also want to understand why Google farts and takes off its pants when it is working on Android. It first compiles the Android code into Java bytecode, then compiles the Java bytecode into its own dex bytecode, and then compiles the dex bytecode The code is handed over to DavlikVM, a language virtual machine modified by oneself, for execution, and since Android 5.0, JIT compilation has been replaced with AOT pre-compiled into binary. Can you understand why Google wants to take off their pants and fart to add an extra layer? Hehehe, I leave this question to you, I will not tell you the answer.

I don't know if GWT has the participation of Lars, but this idea is very similar to the idea of ​​the master. Of course, the master is not willing to make trouble at the level of programming open source framework-compiler-language virtual machine. If you want to get things done thoroughly, you have to do it at the programming language level, and this missing link must be filled.

The great gods all said that there must be light, so there is light. So the Dart development language was released in 2010. This is naturally the work of the great god Lars. This is no longer the translation of Java's strongly typed language into JavaScript's weakly typed language, but the magical transformation of JavaScript into a strongly typed language. Finally, JavaScript needs a compiler in the development stage, but it is naturally compiled into intermediate bytecode, and then handed over to the V8 language virtual machine in the Chrome browser for execution.

That's why you can see that V8 can be independent from the shell Chrome and become a NodeJS execution environment, which can be deployed to the server side and use the NodeJS programming language (JavaScript-like) to write business logic codes. I remember that in the windows era, I used Delphi to develop both the client layer UI and the middle layer business logic. One language conquered the world. Now programmers need two programming languages ​​​​JavaScript+Java to do things.

After thinking about it, Google, as the leader of the Web era, can really toss, almost tossing every layer of the Web:

  • GWT UI component-compiler-bytecode, Flutter UI component, Android UI component

  • AngularJS MVVM programming framework

  • WebGPU rendering technology standard

  • Dart programming language-compiler-bytecode, Kotlin programming language-compiler-bytecode

  • Chrome browser-V8 execution engine-JS language virtual machine, DavlikVM language virtual machine

  • HTTP/2 transmission technology, gRPC-Protobuf calling technology

By the way, the Flutter UI components are developed using the Dart programming language invented by the great god.

(4) Internet of Everything

Everyone knows that Netscape was the leader of the browser back then, but was killed by Microsoft IE bundled with Windows for free. In 2003, Netscape was dissolved and the Mozilla Foundation was established. Firefox is an open source browser produced by the Mozilla Foundation. That is to say: Mozilla is equivalent to Netscape, and Firefox is equivalent to Netscape browser.

The Firefox browser consists of several parts:

  • Rendering engine: Gecko

  • JS forward compiler: Rhino, which can compile JS source code into Java bytecode

  • Code optimizer: IonMonkey

  • Backward compiler: OdinMonkey, compiles asmJS bytecode into binary

  • Language virtual machine: JaegerMonkey

Look at this idea, isn't this the idea of ​​the great master to engage in V8?

Now this technology is collectively called WebAssembly. Like the V8 language virtual machine technology, it has been stripped from the browser, and is now used in addition to the edge cloud container technology, which is faster and smaller than the Docker container technology running on the server side. You see, a technology was originally used to solve JS security and JS performance, but now it is used to solve container security and container performance. If the author knows now, he doesn't know whether to cry or laugh.

Docker co-founder Solomon Hykes said in a tweet that if Wasm + WASI existed in 2008, there would be no need to create Docker.

In fact, the Docker container is a package with a very clever idea. It mainly relies on a modification submitted by Google to the Linux kernel in 2007: Cgroups. Hehehe, Intel as a chip supports virtual machine technology at the chip level, Linux as an operating system supports multi-user resource quotas at the kernel level of the operating system, and VMWare as a system virtual machine does more at the system virtual machine level User resource quotas, and Docker not only absorbs the idea of ​​multi-user resource quotas but also absorbs the idea of ​​JAR unified packaging. Everyone shows their talents in their own field of expertise.

You said that the development of the WASM+K8S+Servless+ service grid led by Google is in full swing, so where did the master go? .

Dashen has now established a startup company as a co-founder and chief scientist, engaged in ToitWare, an IoT platform:

  • Toit programming language - bytecode virtual instruction set

  • Checker-Optimizer-Compiler

  • language virtual machine

It seems that we are back to the good old days when the big guys tossed J2ME-CLDC-KVM.

f4c4b8e2266ee521225f3b2b4839299f.jpeg

Guess you like

Origin blog.csdn.net/david_lv/article/details/130120523