shared-function-info.tq 5.85 KB
Newer Older
Tobias Tebbi's avatar
Tobias Tebbi committed
1 2 3 4 5 6 7 8 9 10 11 12
// 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.

extern class PreparseData extends HeapObject {
  // TODO(v8:8983): Add declaration for variable-sized region.
  data_length: int32;
  children_length: int32;
}

extern class InterpreterData extends Struct {
  bytecode_array: BytecodeArray;
13 14
  @if(V8_EXTERNAL_CODE_SPACE) interpreter_trampoline: CodeDataContainer;
  @ifnot(V8_EXTERNAL_CODE_SPACE) interpreter_trampoline: Code;
Tobias Tebbi's avatar
Tobias Tebbi committed
15 16
}

17 18 19
type FunctionKind extends uint8 constexpr 'FunctionKind';
type FunctionSyntaxKind extends uint8 constexpr 'FunctionSyntaxKind';
type BailoutReason extends uint8 constexpr 'BailoutReason';
20 21 22 23 24 25 26 27

bitfield struct SharedFunctionInfoFlags extends uint32 {
  // Have FunctionKind first to make it cheaper to access.
  function_kind: FunctionKind: 5 bit;
  is_native: bool: 1 bit;
  is_strict: bool: 1 bit;
  function_syntax_kind: FunctionSyntaxKind: 3 bit;
  is_class_constructor: bool: 1 bit;
28
  has_duplicate_parameters: bool: 1 bit;
29
  allow_lazy_compilation: bool: 1 bit;
30
  is_asm_wasm_broken: bool: 1 bit;
31
  function_map_index: uint32: 5 bit;
32
  disabled_optimization_reason: BailoutReason: 4 bit;
33 34
  requires_instance_members_initializer: bool: 1 bit;
  construct_as_builtin: bool: 1 bit;
35
  name_should_print_as_anonymous: bool: 1 bit;
36 37
  has_reported_binary_coverage: bool: 1 bit;
  is_top_level: bool: 1 bit;
38
  properties_are_final: bool: 1 bit;
39 40 41
  private_name_lookup_skips_outer_class: bool: 1 bit;
}

42
bitfield struct SharedFunctionInfoFlags2 extends uint8 {
43 44
  class_scope_has_private_brand: bool: 1 bit;
  has_static_private_methods_or_accessors: bool: 1 bit;
45
  is_sparkplug_compiling: bool: 1 bit;
46
  maglev_compilation_failed: bool: 1 bit;
47
  sparkplug_compiled: bool: 1 bit;
48 49
}

50 51
@generateBodyDescriptor
extern class SharedFunctionInfo extends HeapObject {
52 53 54 55
  // function_data field is treated as a custom weak pointer. We visit this
  // field as a weak pointer if there is aged bytecode. If there is no bytecode
  // or if the bytecode is young then we treat it as a strong pointer. This is
  // done to support flushing of bytecode.
56
  @customWeakMarking function_data: Object;
Tobias Tebbi's avatar
Tobias Tebbi committed
57 58 59
  name_or_scope_info: String|NoSharedNameSentinel|ScopeInfo;
  outer_scope_info_or_feedback_metadata: HeapObject;
  script_or_debug_info: Script|DebugInfo|Undefined;
60 61
  // [length]: The function length - usually the number of declared parameters
  // (always without the receiver).
62 63 64
  // Use up to 2^16-2 parameters (16 bits of values, where one is reserved for
  // kDontAdaptArgumentsSentinel). The value is only reliable when the function
  // has been compiled.
Tobias Tebbi's avatar
Tobias Tebbi committed
65
  length: int16;
66 67 68
  // [formal_parameter_count]: The number of declared parameters (or the special
  // value kDontAdaptArgumentsSentinel to indicate that arguments are passed
  // unaltered).
69
  // In contrast to [length], formal_parameter_count includes the receiver.
Tobias Tebbi's avatar
Tobias Tebbi committed
70
  formal_parameter_count: uint16;
71 72 73
  function_token_offset: uint16;
  // [expected_nof_properties]: Expected number of properties for the
  // function. The value is only reliable when the function has been compiled.
74 75
  expected_nof_properties: uint8;
  flags2: SharedFunctionInfoFlags2;
76
  flags: SharedFunctionInfoFlags;
77 78 79
  // [function_literal_id] - uniquely identifies the FunctionLiteral this
  // SharedFunctionInfo represents within its script, or -1 if this
  // SharedFunctionInfo object doesn't correspond to a parsed FunctionLiteral.
Tobias Tebbi's avatar
Tobias Tebbi committed
80
  function_literal_id: int32;
81
  // [unique_id] - For --log-maps purposes, an identifier that's persistent
82
  // even if the GC moves this SharedFunctionInfo.
Tobias Tebbi's avatar
Tobias Tebbi committed
83 84 85
  @if(V8_SFI_HAS_UNIQUE_ID) unique_id: int32;
}

86 87
const kDontAdaptArgumentsSentinel: constexpr int32
    generates 'kDontAdaptArgumentsSentinel';
88

89 90 91
@export
macro LoadSharedFunctionInfoFormalParameterCountWithoutReceiver(
    sfi: SharedFunctionInfo): uint16 {
92
  let formalParameterCount = sfi.formal_parameter_count;
93 94 95
  if (Convert<int32>(formalParameterCount) != kDontAdaptArgumentsSentinel) {
    formalParameterCount =
        Convert<uint16>(formalParameterCount - kJSArgcReceiverSlots);
96 97
  }
  return formalParameterCount;
98 99 100 101 102
}

@export
macro LoadSharedFunctionInfoFormalParameterCountWithReceiver(
    sfi: SharedFunctionInfo): uint16 {
103
  return sfi.formal_parameter_count;
104 105 106 107 108 109 110 111
}

@export
macro IsSharedFunctionInfoDontAdaptArguments(sfi: SharedFunctionInfo): bool {
  const formalParameterCount = sfi.formal_parameter_count;
  return Convert<int32>(formalParameterCount) == kDontAdaptArgumentsSentinel;
}

Tobias Tebbi's avatar
Tobias Tebbi committed
112
@abstract
113
extern class UncompiledData extends HeapObject {
Tobias Tebbi's avatar
Tobias Tebbi committed
114 115 116 117 118
  inferred_name: String;
  start_position: int32;
  end_position: int32;
}

119 120 121 122
@generateBodyDescriptor
@generateUniqueMap
@generateFactoryFunction
extern class UncompiledDataWithoutPreparseData extends UncompiledData {
Tobias Tebbi's avatar
Tobias Tebbi committed
123 124
}

125 126 127 128
@generateBodyDescriptor
@generateUniqueMap
@generateFactoryFunction
extern class UncompiledDataWithPreparseData extends UncompiledData {
Tobias Tebbi's avatar
Tobias Tebbi committed
129 130
  preparse_data: PreparseData;
}
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
@generateBodyDescriptor
@generateUniqueMap
@generateFactoryFunction
extern class UncompiledDataWithoutPreparseDataWithJob extends
    UncompiledDataWithoutPreparseData {
  // TODO(v8:10391): Define the field as ExternalPointer or move jobs into cage.
  job: RawPtr;
}

@generateBodyDescriptor
@generateUniqueMap
@generateFactoryFunction
extern class UncompiledDataWithPreparseDataAndJob extends
    UncompiledDataWithPreparseData {
  // TODO(v8:10391): Define the field as ExternalPointer or move jobs into cage.
  job: RawPtr;
}

150 151 152 153
@useParentTypeChecker
type PodArrayOfIntegerPairs extends ByteArray
    constexpr 'PodArray<std::pair<int32_t, int32_t>>';

154 155
@export
class OnHeapBasicBlockProfilerData extends HeapObject {
156 157 158
  block_ids: ByteArray;              // Stored as 4-byte ints
  counts: ByteArray;                 // Stored as 4-byte unsigned ints
  branches: PodArrayOfIntegerPairs;  // Stored as pairs of 4-byte ints
159 160 161
  name: String;
  schedule: String;
  code: String;
162
  hash: Smi;
163
}