How does the JIT compiler Maglev in chrome v8 perform?

I write some js codes in a function named f , and call the f 4 times. That’s all I did, quite simple.

After I run it with ./d8 –trace-opt, I find the f is compiled 4 times by Maglev, 2 times by Turbofan, and then 2 times by Maglev.

In the turbofan period, it shows that “Found optimize code for f….”, which means that when it try to compile f with Turbofan again, it will directly return the code compiled at the first time, just as many blogs say.

But what about the Maglev? It compiles everytime and many times, and when I try to look at the result of it with option ‘–print-maglev-code’, it prints codes which are different with each other. Some are long, some are short.

Dose it have something to do with deoptmization becasue I see 6 times deopt from Maglev code and 3 times deopt from Turbofan code with option –trace-deopt? I am quite confused, and need some help.

What I need for help:

I’d like to know, in the source code files or any blog link, where is the reason for a function to get Magleved?

Will the deoptimization from maglev code influence the later call of f , which makes it compile again and render the different compiled codes?

Why maglev doesn’t get the code it compiled before just like Turbofan? Does it have something to do with FeedbackVector?

I am a beginner in v8 and I am very willing to refer to the source code. But I can’t find the exact code and don’t know if the code I find is the right place. Thanks.