summaryrefslogtreecommitdiff
path: root/chromium/v8/src/builtins/internal-coverage.tq
blob: 07bfc40d8f277c9f02cf56aa63f337a7f6d0f2d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include 'src/builtins/builtins-regexp-gen.h'

namespace internal_coverage {

macro GetCoverageInfo(implicit context: Context)(function: JSFunction):
    CoverageInfo labels IfNoCoverageInfo {
  const shared: SharedFunctionInfo = function.shared_function_info;
  const debugInfo = Cast<DebugInfo>(shared.script_or_debug_info)
      otherwise goto IfNoCoverageInfo;

  if (!debugInfo.flags.has_coverage_info) goto IfNoCoverageInfo;
  return UnsafeCast<CoverageInfo>(debugInfo.coverage_info);
}

macro IncrementBlockCount(implicit context: Context)(
    coverageInfo: CoverageInfo, slot: Smi) {
  assert(Convert<int32>(slot) < coverageInfo.slot_count);
  ++coverageInfo.slots[slot].block_count;
}

builtin IncBlockCounter(
    implicit context:
        Context)(function: JSFunction, coverageArraySlotIndex: Smi): Undefined {
  // It's quite possible that a function contains IncBlockCounter bytecodes,
  // but no coverage info exists. This happens e.g. by selecting the
  // best-effort coverage collection mode, which triggers deletion of all
  // coverage infos in order to avoid memory leaks.

  const coverageInfo: CoverageInfo =
      GetCoverageInfo(function) otherwise return Undefined;
  IncrementBlockCount(coverageInfo, coverageArraySlotIndex);
  return Undefined;
}

}  // namespace internal_coverage