Some things and thoughts learned recently

Origin

After 3-4 days of researching DukTape, I regained my confidence in QuickJS. Why do you say that? DukTape is developed by a company and the documentation is very, very detailed and complete. The QuickJS and DukTape implementation principles are similar. So, DukTape actually assisted my understanding of QuickJS. But I can’t say whether QuickJS will eventually win them all. So, I think I should leave something first. Even if I put it down completely later, there is at least a place to record what I did for QuickJS, which people can use as a reference later.

What has been done for QuickJS

The research on QuickJS (hereinafter referred to as QJS) is mainly to make up for the regret I left in the book "In-depth understanding of Android Java Virtual Machine ART", that is, I am still in the realm of a user of programming language, not standing in the designer From a different perspective. Through the research of QJS, I want to figure out the JS language specification (so I read it in conjunction with the ECMAScript specification), and then learn how QJS implements this specification. In this way, maybe I can become an expert in the JS language and also master how to implement this language. This is my direct, grand idea.

The beginning of learning QJS is to look at the code. I am still at a moderately low level in the field of JS language. I understand part of the syntax, but I don't know many details. However, this does not affect the code of QJS. But the whole feeling is more painful. For example, QJS considers complete JS syntax rules when parsing js code. It was just a user before, just use it correctly. Now it is from the perspective of the implementer. These rules need to be very clear. Note that QJS does not use ready-made tools such as yacc and lex, but a parser written manually.

Pain is a good thing. I deeply realize that I don't know enough about JS language. To this end, I read the following books in total, in order:

  1. "JavaScript You Don't Know", three books, Chinese version. The first and second volumes of this book are carefully read, and the second volume is relatively rough. I have this experience in reading books. New knowledge will be a little slower at the beginning. Once the basic knowledge is supplemented to 60%-70%, the rest of the content will be read quickly. These three books helped me supplement some language foundations of ES6.

  2. "How JavaScript Works", this book is currently only available in English, available on the Kindle e-book. I thought it was an introduction to the internal implementation of the JS engine. Actually not, it is still used in JS language, and then some technical details will be mentioned in some places (but this content is not much).

  3. "In-depth understanding of ES6", I read the English version of this book intensively.

For JS, I read about the above five books. Now I can only say that I have some understanding of the JS language. With this foundation, I feel that I will no longer be so guilty when I look at the QJS code.

QJS code I have basically read the JS code parsing part, and I have 80% understanding of the related data structure, but when converting the JS code into the bytecode inside QJS, I can no longer go deep-this is what I said before The root cause of wanting to give up QJS. Although in the field of compilation, after grammar/grammar parsing, the source code will be converted into intermediate expressions, but how to convert it is not covered in the ART book. I vaguely remember that there was a book that said that although this conversion work is a routine, it seems to be more artistic than technical. In particular, on the one hand, I still lack a deep understanding of the JS language, and on the other hand, I have no knowledge of even the simplest implementation of the JS engine.

This difficulty is quite difficult to overcome. Moreover, QJS does not have a little documentation description of bytecode... It seems to be a dead end. However, I also thought, since it is a routine, will there be some books? For this reason, I read two more books (it seems that books are really good friends...)

  1. American computer science textbook "Concepts of Programming Languages ​​(11th)". About half of the book has been intensively read. It is probably an introduction to the development history of various languages, as well as the characteristics of various languages ​​(considered from the perspective of the implementer), it is a comprehensive teaching material. Right to be a literacy teaching material.

  2. Yukihiro Matsumoto's new book "Design and Implementation of Programming Languages". This book is actually a collection of several articles published by Brother Hong in a Japanese magazine more than ten years ago. I thought that through this book, I could understand the implementation process of a language, but in fact I didn't learn much. Can only be said to be an eye-opener. Compared with another Japanese book "The Algorithm and Implementation of Garbage Collection", Hong Ge's book is a bit less interesting.

After reading the above two books, I found no help to the big problem of QJS. There is really no way. I said in a small circle that I would give up QJS and plan to switch to DukTape. Unexpectedly, DukTape's documentation is so detailed, and the implementation ideas are roughly the same as QJS. Based on some documents of DukTape, I am no longer afraid of QJS (this is the feeling now, will it be difficult to say in the future). I now feel that choosing QJS as the learning goal may be correct. Yesterday I restarted QJS again, dumped the bytecode, and planned to settle down and study it case by case.

The mentality of QJS is to go back and forth. Maybe I'm still old, and I don't have the courage before I was young. Perhaps, as long as you settle your mind, you may get it done as soon as you gritted your teeth-think about how the ART book was made like this, and stick to it.

Other things done during this time

I see that the children's shoes of the Shennong Class Fwk Bureau are engaged in Android 10.0, and they are also itchy to compile the code of 10.0. There are a few problems to talk about:

  • For the first time, I found that Android compilation eats memory like this. If you compile for 64-bit, at least 15GB of memory must be prepared. I think the main reason is that the ninjia.build file takes up memory. Students who use Ubuntu, please note that as long as the memory of the swap area is increased, the method is very simple. I use a virtual machine, the physical memory is only divided into 8GB, and the swap is divided into 8GB, so it is no problem to compile x86_64.

  • For AOSP compilation, if you want to run with the simulator, just compile aosp_x86-eng or aosp_x86_64-eng after lunch. I used to choose the mini-emulator, but found that the compilation on 10.0 would fail. The simulator uses the self-compiled image very fast, I feel that Google should optimize a lot.

  • After compiling, create the corresponding simulator from AVD. Then you need to set it up to load the image you compiled with the simulator. In the past, you only need to specify "--system own image file path", but it doesn't work now. My classmates in the Fwk Bureau of Shennong Class and I asked for advice. They copied the mirror file compiled by themselves to the mirror file downloaded by the SDK. This is too much trouble. I made a script and just made a few links. As follows:

640?wx_fmt=jpeg

Put this script in the root directory of the aosp source code and make it executable. In this way, the simulator can be started in one run, isn't it cool?

Some thinking

I saw an article on XYS called "Dark Effect and the Four Stages of Cognition". The article said, "A person's cognitive process generally goes through these four stages:  

  • The first stage: I don’t know I don’t know ;  

  • The second stage: know you don't know ;  

  • The third stage: know that you know ;  

  • The fourth stage: I don't know I know .

This cognitive process is exactly similar to the summary of the Dunning-Kruger Effect: the more ignorant people are, the more confident they are. When a person has more and more knowledge, self-confidence will decline, but after breaking through the critical point, self-confidence will rise, but no matter how it rises afterwards, he will not be as confident as when he knew nothing at the beginning.That is, the more knowledgeable people are, the more they can realize their own shortcomings, and the more they can discover, recognize and learn from others' advantages .

These cognitive stage also happens to be corresponding to different segments Dunning-Kruger effect curve: ignorance mountain (do not know they do not know), the valley of despair (know that they do not know), enlightenment slope (know they know) and a smooth plateau (not Know you know).

The Duck effect is a phenomenon of cognitive bias. This bias may be that those with low ability overestimate their own level, or those with high ability overestimate the level of others, but no matter where it is One is because the individual incorrectly assessed the cognitive level of a specific group of people.

In our real life, the Duck effect can be said to be ubiquitous, not only those who are disdainful, not good at learning and enterprising, always have fascinating self-confidence, even those who are in high positions or regarded as Successful social elites cannot avoid showing such cognitive biases. "

For many things, I always feel that leaders and young people have courage and courage, which makes me often ashamed. It seems that they may indeed have the courage, or they may "do not know that they do not know."

Follow-up arrangements

If there are no major changes, I still want to stick to QJS. I have already paid so much, I hope it will not become a sunk cost.

last of the last

  • The result I expect is not what my friends have learned from my books, articles, and blogs and what they have done, but rather, Shennong, I stepped on your shoulders.

  • I have finished discussing the issue of learning. The following public account will learn and share some basic technologies and new technologies. Your contributions are also welcome. However, as I said in the "Contact Information" of the public account-Zheng Yuanjie has a sentence in the fairy tale King "Wisdom Teeth" that impressed me, to the effect that "I have the right to remain silent, but every word you say is May become my source of inspiration". Therefore, the impact is not one-way, it is possible that I learned more from you.

640?wx_fmt=jpeg

Collection of essays by Shennong and his friends

Long press to identify the QR code and follow us

Guess you like

Origin blog.csdn.net/Innost/article/details/102481439