• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include 'src/builtins/builtins-regexp-gen.h'
6
7namespace internal_coverage {
8
9macro GetCoverageInfo(implicit context: Context)(function: JSFunction):
10    CoverageInfo labels IfNoCoverageInfo {
11  const shared: SharedFunctionInfo = function.shared_function_info;
12  const debugInfo = Cast<DebugInfo>(shared.script_or_debug_info)
13      otherwise goto IfNoCoverageInfo;
14
15  if (!debugInfo.flags.has_coverage_info) goto IfNoCoverageInfo;
16  return UnsafeCast<CoverageInfo>(debugInfo.coverage_info);
17}
18
19macro IncrementBlockCount(implicit context: Context)(
20    coverageInfo: CoverageInfo, slot: Smi): void {
21  dcheck(Convert<int32>(slot) < coverageInfo.slot_count);
22  ++coverageInfo.slots[slot].block_count;
23}
24
25builtin IncBlockCounter(
26    implicit context:
27        Context)(function: JSFunction, coverageArraySlotIndex: Smi): Undefined {
28  // It's quite possible that a function contains IncBlockCounter bytecodes,
29  // but no coverage info exists. This happens e.g. by selecting the
30  // best-effort coverage collection mode, which triggers deletion of all
31  // coverage infos in order to avoid memory leaks.
32
33  const coverageInfo: CoverageInfo =
34      GetCoverageInfo(function) otherwise return Undefined;
35  IncrementBlockCount(coverageInfo, coverageArraySlotIndex);
36  return Undefined;
37}
38
39}  // namespace internal_coverage
40