Chrome V8 marks feature for optimization over and over until it gives up

I have a JavaScript function detectSingleScale

that V8 is trying to optimize, and as far as I can tell, it cannot optimize it.

When I start Chrome with, --trace_deopt --trace_opt --trace_opt_verbose --code_comments

I see hundreds of lines of log like below:

6087 [found optimized code for 0x1a9b67169161 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> at OSR AST id 218]
6088 [didn't find optimized code in optimized code map for 0x145b5fa71bb1 <SharedFunctionInfo detectSingleScale>]
6089 [marking 0x1a9b6721ab91 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> for recompilation, reason: hot and stable, ICs with typeinfo: 140/144 (97%), generic ICs: 0/144 (0%)]
6090 [found optimized code for 0x1a9b6721ab91 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> at OSR AST id 218]
6091 [didn't find optimized code in optimized code map for 0x145b5fa71bb1 <SharedFunctionInfo detectSingleScale>]
6092 [marking 0x1a9b672c80f1 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> for recompilation, reason: hot and stable, ICs with typeinfo: 140/144 (97%), generic ICs: 0/144 (0%)]
6093 [found optimized code for 0x1a9b672c80f1 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> at OSR AST id 218]
6094 [didn't find optimized code in optimized code map for 0x145b5fa71bb1 <SharedFunctionInfo detectSingleScale>]
6095 [marking 0x1a9b67379db1 <JS Function detectSingleScale (SharedFunctionInfo 0x145b5fa71bb1)> for recompilation, reason: hot and stable, ICs with typeinfo: 140/144 (97%), generic ICs: 0/144 (0%)]

      

  • V8 marks the function detectSingleScale

    for optimization.
  • He then says that he found an optimized version.
  • But then he says that he did not find it. And the whole process is restarted over and over again.

The addresses for the optimized code are all different. I'm wondering what might be causing the V8 to behave like this. Under what circumstances can the V8 function be set in this state?

Thanks in advance!

+3


source to share


2 answers


When looking at the traceback it seems like it detectSingleScale

is a new closure every time. It is optimized every time through OSR (when replacing the stack), so it doesn't have a cached version without OSR.

The first time you create and run a closure, it is optimized through OSR and the resulting code, which it puts in the cache.

The next time you re-create the closure, you will first get the message didn't find optimized code

- Factory::NewFunctionFromSharedFunctionInfo

[1] tries to find a non- OSR version (OSR ID is set to BailoutId::None()

) and doesn't find them, because the only optimized version is OSR.

Then V8 sees the hot loop and solves the OSR function - this time it finds the already optimized code with the corresponding OSR identifier in the cache and uses it.

Here's how to illustrate it



function foo() {
  print('! creating bar')
  var bar = function () {
    for (var i = 0; i < 100000; i++) {
      // OSR happens in this loop.
    }

    // Add a literal here to ensure we hit Runtime_NewClosure
    // instead of FastNewClosureStub - stub doesn't log anything.
    var a = [];
  }

  print('! running bar')
  bar();
  print('-- done')
}

foo();
foo();
foo();

      

When I run this file with d8

I get:

$ out/ia32.release/d8 --trace-opt test.js
! creating bar
! running bar
[marking 0x4301b705 <JS Function bar (SharedFunctionInfo 0x4c208765)> for recompilation, reason: small function, ICs with typeinfo: 2/2 (100%), generic ICs: 0/2 (0%)]
[compiling method 0x4301b705 <JS Function bar (SharedFunctionInfo 0x4c208765)> using Crankshaft]
[optimizing 0x4301b705 <JS Function bar (SharedFunctionInfo 0x4c208765)> - took 0.082, 0.119, 0.047 ms]
-- done
! creating bar
[didn't find optimized code in optimized code map for 0x4c208765 <SharedFunctionInfo bar>]
! running bar
[marking 0x4301bdb5 <JS Function bar (SharedFunctionInfo 0x4c208765)> for recompilation, reason: small function, ICs with typeinfo: 2/2 (100%), generic ICs: 0/2 (0%)]
[found optimized code for 0x4301bdb5 <JS Function bar (SharedFunctionInfo 0x4c208765)> at OSR AST id 10]
-- done
! creating bar
[didn't find optimized code in optimized code map for 0x4c208765 <SharedFunctionInfo bar>]
! running bar
[marking 0x4301be35 <JS Function bar (SharedFunctionInfo 0x4c208765)> for recompilation, reason: hot and stable, ICs with typeinfo: 2/2 (100%), generic ICs: 0/2 (0%)]
[found optimized code for 0x4301be35 <JS Function bar (SharedFunctionInfo 0x4c208765)> at OSR AST id 10]
-- done

      

[1] https://github.com/v8/v8-git-mirror/blob/master/src/factory.cc#L1396-L1397

+4


source


The V8 team is currently working on optimizing this case: Tracking Chrome Issues .

You can start --mark_shared_functions_for_tier_up

to use the current job. Then detectSingleScale

it should be optimized.



The post didn't find optimized code in optimized code map for

was not very helpful and was recently removed from the codebase.

0


source







All Articles