v8/test/cctest/compiler
Seth Brenith 18c73676c1 [diagnostics] Support --turbo-profiling for builtins
Currently, if d8 is run with the --turbo-profiling flag, it prints info
about every TurboFan-compiled function. This info includes the number of
times that each basic block in the function was run. It also includes
text representations of the function's schedule and code, so that the
person reading the output can associate counters with blocks of code.

The data about each function is currently stored in a
BasicBlockProfiler::Data instance, which is attached to a list owned by
the singleton BasicBlockProfiler. Each Data contains an
std::vector<uint32_t> which represents how many times each block in the
function has executed. The generated code for each block uses a raw
pointer into the storage of that vector to implement incrementing the
counter.

With this change, if you compile with v8_enable_builtins_profiling and
then run with --turbo-profiling, d8 will print that same info about
builtins too.

In order to generate code that can survive being serialized to a
snapshot and reloaded, this change uses counters in the JS heap instead
of a std::vector outside the JS heap. The steps for instrumentation are
as follows:

1. Between scheduling and instruction selection, add code to increment
   the counter for each block. The counters array doesn't yet exist at
   this point, and allocation is disallowed, so at this point the code
   refers to a special marker value.
2. During finalization of the code, allocate a BasicBlockProfilingData
   object on the JS heap containing data equivalent to what is stored in
   BasicBlockProfiler::Data. This includes a ByteArray that is big
   enough to store the counters for each block.
3. Patch the reference in the BuiltinsConstantsTableBuilder so that
   instead of referring to the marker object, it now refers to this
   ByteArray. Also add the BasicBlockProfilingData object to a list that
   is attached to the heap roots so it can be easily accessed for
   printing.

Because these steps include modifying the BuiltinsConstantsTableBuilder,
this procedure is only applicable to builtins. Runtime-generated code
still uses raw pointers into std::vector instances. In order to keep
divergence between these code paths to a minimum, most work is done
referring to instances of BasicBlockProfiler::Data (the C++ class), and
functions are provided to copy back and forth between that type and
BasicBlockProfilingData (the JS heap object).

This change is intended only to make --turbo-profiling work consistently
on more kinds of functions, but with some further work, this data could
form the basis for:
- code coverage info for fuzzers, and/or
- hot-path info for profile-guided optimization.

Bug: v8:10470, v8:9119
Change-Id: Ib556a5bc3abe67cdaa2e3ee62702a2a08b11cb61
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2159738
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67944}
2020-05-21 16:31:52 +00:00
..
c-signature.h [cleanup] Replace simple typedefs by using 2019-05-27 12:39:49 +00:00
call-tester.h Move handles-related files to src/handles 2019-05-23 06:00:15 +00:00
code-assembler-tester.h Move handles-related files to src/handles 2019-05-23 06:00:15 +00:00
codegen-tester.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
codegen-tester.h [turbofan] Simplify handling of calls with saved registers. 2019-08-01 08:59:15 +00:00
function-tester.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
function-tester.h Move handles-related files to src/handles 2019-05-23 06:00:15 +00:00
graph-and-builders.h [cleanup] Removing GraphBuilderTester class 2019-05-07 09:54:51 +00:00
serializer-tester.cc [turbofan] Remove unused --inline-accessors flag 2019-11-26 12:51:16 +00:00
serializer-tester.h [iwyu] Add missing includes of <memory> for std::unique_ptr 2019-09-13 17:13:36 +00:00
test-basic-block-profiler.cc [diagnostics] Support --turbo-profiling for builtins 2020-05-21 16:31:52 +00:00
test-branch-combine.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
test-code-assembler.cc [compiler] Remove error-prone GotoIfException 2020-02-18 11:45:08 +00:00
test-code-generator.cc [arm64] Use BTI instructions for forward CFI 2020-03-17 17:52:28 +00:00
test-gap-resolver.cc [turbofan][cleanup] Remove dead ExplicitOperand class. 2019-09-10 08:23:40 +00:00
test-graph-visualizer.cc Reland "Introduce StdoutStream which prints to Android log or stdout" 2018-06-14 13:29:01 +00:00
test-instruction-scheduler.cc Reland "[turbofan] Further brokerize BytecodeGraphBuilder" 2019-08-26 08:58:44 +00:00
test-instruction.cc [cleanup] Replace simple typedefs by using 2019-05-27 12:39:49 +00:00
test-js-constant-cache.cc [turbofan] Disable concurrent inlining for OSR 2020-01-09 18:24:12 +00:00
test-js-context-specialization.cc [torque][cleanup] Simplify some Torque-defined classes 2020-05-11 17:18:59 +00:00
test-js-typed-lowering.cc [turbofan] Disable concurrent inlining for OSR 2020-01-09 18:24:12 +00:00
test-jump-threading.cc [compiler] Replace remaining mutable reference arguments 2019-09-12 08:56:15 +00:00
test-linkage.cc [wasm] Remove test line from TestFPLinkageStubCall 2020-04-22 19:32:13 +00:00
test-loop-analysis.cc [cleanup] Eliminate non-const reference parameters 2019-09-10 09:31:07 +00:00
test-machine-operator-reducer.cc [turbofan] introduce a deterministic tick measurement and assert optimization doesn't take too long 2019-07-17 07:00:00 +00:00
test-multiple-return.cc [wasm] Turn ValueType from an enum to a class 2020-03-12 17:03:16 +00:00
test-node.cc [node] OwnedBy fix for only one owner check 2020-01-20 16:36:02 +00:00
test-operator.cc Normalize casing of hexadecimal digits 2017-12-02 01:24:40 +00:00
test-representation-change.cc [turbofan] Disable concurrent inlining for OSR 2020-01-09 18:24:12 +00:00
test-run-bytecode-graph-builder.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
test-run-calls-to-external-references.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
test-run-deopt.cc Move relevant files to src/execution 2019-05-22 08:36:33 +00:00
test-run-intrinsics.cc Move code generation related files to src/codegen 2019-05-21 10:33:39 +00:00
test-run-jsbranches.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
test-run-jscalls.cc Move remaining files in src/ 2019-05-24 18:24:36 +00:00
test-run-jsexceptions.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
test-run-jsobjects.cc [keys] Handle RangeError in GetKeysWithPrototypeInfoCache 2020-03-04 13:38:10 +00:00
test-run-jsops.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
test-run-load-store.cc [ptr-compr] Enable pointer compression on s390x 2020-03-31 17:06:17 +00:00
test-run-machops.cc [ptr-compr] Remove Compressed mentions from in the pipeline 2019-11-11 12:23:41 +00:00
test-run-native-calls.cc [roheap] Add Isolate parameter to Code::Disassemble 2019-09-25 10:46:45 +00:00
test-run-retpoline.cc [turbofan] Remove unsafe {CodeAssembler::ReturnRaw}. 2019-11-28 09:39:52 +00:00
test-run-stackcheck.cc Move relevant files to src/execution 2019-05-22 08:36:33 +00:00
test-run-tail-calls.cc [turbofan] Remove unsafe {CodeAssembler::ReturnRaw}. 2019-11-28 09:39:52 +00:00
test-run-unwinding-info.cc Remove --perf-prof flag on non-linux 2020-01-10 13:58:50 +00:00
test-run-variables.cc Move more relevant files to src/objects 2019-05-23 08:52:30 +00:00
value-helper.cc Reland "[test] Avoid unnecessary std::vector allocations" 2017-10-19 08:47:31 +00:00
value-helper.h [base] Fix {StaticCharVector} and add {StaticOneByteVector} 2020-04-17 18:45:32 +00:00