v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
shared-function-info.h
Go to the documentation of this file.
1// Copyright 2017 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#ifndef V8_OBJECTS_SHARED_FUNCTION_INFO_H_
6#define V8_OBJECTS_SHARED_FUNCTION_INFO_H_
7
8#include <memory>
9#include <optional>
10
11#include "src/base/bit-field.h"
14#include "src/common/globals.h"
18#include "src/objects/name.h"
19#include "src/objects/objects.h"
20#include "src/objects/script.h"
21#include "src/objects/slots.h"
22#include "src/objects/smi.h"
23#include "src/objects/struct.h"
24#include "src/roots/roots.h"
25#include "testing/gtest/include/gtest/gtest_prod.h" // nogncheck
26#include "torque-generated/bit-fields.h"
27
28// Has to be the last include (doesn't have include guards):
30
31namespace v8::internal {
32
33class AsmWasmData;
34class BytecodeArray;
35class CoverageInfo;
36class DebugInfo;
37class IsCompiledScope;
38template <typename>
44class WasmResumeData;
45
46#if V8_ENABLE_WEBASSEMBLY
47namespace wasm {
48class CanonicalValueType;
49struct WasmModule;
50class ValueType;
51} // namespace wasm
52#endif
53
54#include "torque-generated/src/objects/shared-function-info-tq.inc"
55
56// Defines whether the source positions should be created during function
57// compilation.
59
60// Data collected by the pre-parser storing information about scopes and inner
61// functions.
62//
63// PreparseData Layout:
64// +-------------------------------+
65// | data_length | children_length |
66// +-------------------------------+
67// | Scope Byte Data ... |
68// | ... |
69// +-------------------------------+
70// | [Padding] |
71// +-------------------------------+
72// | Inner PreparseData 1 |
73// +-------------------------------+
74// | ... |
75// +-------------------------------+
76// | Inner PreparseData N |
77// +-------------------------------+
79 : public TorqueGeneratedPreparseData<PreparseData, HeapObject> {
80 public:
81 inline int inner_start_offset() const;
82 inline ObjectSlot inner_data_start() const;
83
84 inline uint8_t get(int index) const;
85 inline void set(int index, uint8_t value);
86 inline void copy_in(int index, const uint8_t* buffer, int length);
87
88 inline Tagged<PreparseData> get_child(int index) const;
89 inline void set_child(int index, Tagged<PreparseData> value,
91
92 // Clear uninitialized padding space.
93 inline void clear_padding();
94
97
98 static const int kDataStartOffset = kSize;
99
100 class BodyDescriptor;
101
102 static int InnerOffset(int data_length) {
103 return RoundUp(kDataStartOffset + data_length * kByteSize, kTaggedSize);
104 }
105
106 static int SizeFor(int data_length, int children_length) {
107 return InnerOffset(data_length) + children_length * kTaggedSize;
108 }
109
111
112 private:
113 inline Tagged<Object> get_child_raw(int index) const;
114};
115
116// Abstract class representing extra data for an uncompiled function, which is
117// not stored in the SharedFunctionInfo.
119 : public TorqueGeneratedUncompiledData<UncompiledData,
120 ExposedTrustedObject> {
121 public:
122 inline void InitAfterBytecodeFlush(
123 Isolate* isolate, Tagged<String> inferred_name, int start_position,
124 int end_position,
125 std::function<void(Tagged<HeapObject> object, ObjectSlot slot,
126 Tagged<HeapObject> target)>
127 gc_notify_updated_slot);
128
130};
131
132// Class representing data for an uncompiled function that does not have any
133// data from the pre-parser, either because it's a leaf function or because the
134// pre-parser bailed out.
136 : public TorqueGeneratedUncompiledDataWithoutPreparseData<
137 UncompiledDataWithoutPreparseData, UncompiledData> {
138 public:
139 class BodyDescriptor;
140
142};
143
144// Class representing data for an uncompiled function that has pre-parsed scope
145// data.
147 : public TorqueGeneratedUncompiledDataWithPreparseData<
148 UncompiledDataWithPreparseData, UncompiledData> {
149 public:
150 class BodyDescriptor;
151
153};
154
155// Class representing data for an uncompiled function that does not have any
156// data from the pre-parser, either because it's a leaf function or because the
157// pre-parser bailed out, but has a job pointer.
159 : public TorqueGeneratedUncompiledDataWithoutPreparseDataWithJob<
160 UncompiledDataWithoutPreparseDataWithJob,
161 UncompiledDataWithoutPreparseData> {
162 public:
163 class BodyDescriptor;
164
166};
167
168// Class representing data for an uncompiled function that has pre-parsed scope
169// data and a job pointer.
171 : public TorqueGeneratedUncompiledDataWithPreparseDataAndJob<
172 UncompiledDataWithPreparseDataAndJob,
173 UncompiledDataWithPreparseData> {
174 public:
175 class BodyDescriptor;
176
178};
179
181 : public TorqueGeneratedInterpreterData<InterpreterData,
182 ExposedTrustedObject> {
183 public:
186
187 class BodyDescriptor;
188
189 private:
191};
192
194
195// SharedFunctionInfo describes the JSFunction information that can be
196// shared by multiple instances of the function.
198 : public TorqueGeneratedSharedFunctionInfo<SharedFunctionInfo, HeapObject> {
199 public:
200 DEFINE_TORQUE_GENERATED_SHARED_FUNCTION_INFO_FLAGS()
201 DEFINE_TORQUE_GENERATED_SHARED_FUNCTION_INFO_FLAGS2()
202
203 // This initializes the SharedFunctionInfo after allocation. It must
204 // initialize all fields, and leave the SharedFunctionInfo in a state where
205 // it is safe for the GC to visit it.
206 //
207 // Important: This function MUST not allocate.
208 void Init(ReadOnlyRoots roots, int unique_id);
209
211 Smi::zero();
212
213 // [name]: Returns shared name if it exists or an empty string otherwise.
214 inline Tagged<String> Name() const;
215 inline void SetName(Tagged<String> name);
216
217 // Get the code object which represents the execution of this function.
219
220 // Get the abstract code associated with the function, which will either be
221 // a Code object or a BytecodeArray.
223
224 // Set up the link between shared function info and the script. The shared
225 // function info is added to the list on the script.
227 ReadOnlyRoots roots,
228 Tagged<HeapObject> script_object,
229 int function_literal_id,
230 bool reset_preparsed_scope_data = true);
231
232 // Copy the data from another SharedFunctionInfo. Used for copying data into
233 // and out of a placeholder SharedFunctionInfo, for off-thread compilation
234 // which is not allowed to touch a main-thread-visible SharedFunctionInfo.
236
237 // Layout description of the optimized code map.
238 static const int kEntriesStart = 0;
239 static const int kContextOffset = 0;
240 static const int kCachedCodeOffset = 1;
241 static const int kEntryLength = 2;
243
244 static const int kNotFound = -1;
245
246 static constexpr int kAgeSize = kAgeOffsetEnd - kAgeOffset + 1;
247 static constexpr uint16_t kMaxAge = UINT16_MAX;
248
250 // Deprecated, use the ACQUIRE version instead.
251 DECL_GETTER(scope_info, Tagged<ScopeInfo>)
252 // Slow but safe:
254
255 // Set scope_info without moving the existing name onto the ScopeInfo.
256 inline void set_raw_scope_info(Tagged<ScopeInfo> scope_info,
258
259 inline void SetScopeInfo(Tagged<ScopeInfo> scope_info,
261
262 inline bool is_script() const;
263 inline bool needs_script_context() const;
264
265 // End position of this function in the script source.
266 V8_EXPORT_PRIVATE int EndPosition() const;
267
268 // Start position of this function in the script source.
270
272 IsolateForSandbox isolate, FunctionLiteral* lit);
273
274 // [outer scope info | feedback metadata] Shared storage for outer scope info
275 // (on uncompiled functions) and feedback metadata (on compiled functions).
279 private:
280 using TorqueGeneratedSharedFunctionInfo::
281 outer_scope_info_or_feedback_metadata;
282 using TorqueGeneratedSharedFunctionInfo::
283 set_outer_scope_info_or_feedback_metadata;
284
285 public:
286 // Get the outer scope info whether this function is compiled or not.
287 inline bool HasOuterScopeInfo() const;
289
290 // [feedback metadata] Metadata template for feedback vectors of instances of
291 // this function.
292 inline bool HasFeedbackMetadata() const;
293 inline bool HasFeedbackMetadata(AcquireLoadTag tag) const;
294 DECL_GETTER(feedback_metadata, Tagged<FeedbackMetadata>)
296
297 // Returns if this function has been compiled yet. Note: with bytecode
298 // flushing, any GC after this call is made could cause the function
299 // to become uncompiled. If you need to ensure the function remains compiled
300 // for some period of time, use IsCompiledScope instead.
301 inline bool is_compiled() const;
302
303 // Returns an IsCompiledScope which reports whether the function is compiled,
304 // and if compiled, will avoid the function becoming uncompiled while it is
305 // held.
306 template <typename IsolateT>
307 inline IsCompiledScope is_compiled_scope(IsolateT* isolate) const;
308
309 // [internal formal parameter count]: The declared number of parameters.
310 // For subclass constructors, also includes new.target.
311 // The size of function's frame is
312 // internal_formal_parameter_count_with_receiver.
313 //
314 // NOTE: this API should be considered DEPRECATED. Please obtain the
315 // parameter count from the Code/BytecodeArray or another trusted source
316 // instead. See also crbug.com/40931165.
317 // TODO(saelo): mark as V8_DEPRECATE_SOON once the remaining users are fixed.
318 inline void set_internal_formal_parameter_count(int value);
319 inline uint16_t internal_formal_parameter_count_with_receiver() const;
321
322 private:
323 using TorqueGeneratedSharedFunctionInfo::formal_parameter_count;
324 using TorqueGeneratedSharedFunctionInfo::set_formal_parameter_count;
325
326 public:
327 // Set the formal parameter count so the function code will be
328 // called without using argument adaptor frames.
329 inline void DontAdaptArguments();
330 inline bool IsDontAdaptArguments() const;
331
332 // Accessors for the data associated with this SFI.
333 //
334 // Currently it can be one of:
335 // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()].
336 // - a BytecodeArray for the interpreter [HasBytecodeArray()].
337 // - a InterpreterData with the BytecodeArray and a copy of the
338 // interpreter trampoline [HasInterpreterData()]
339 // - an AsmWasmData with Asm->Wasm conversion [HasAsmWasmData()].
340 // - a Smi containing the builtin id [HasBuiltinId()]
341 // - a UncompiledDataWithoutPreparseData for lazy compilation
342 // [HasUncompiledDataWithoutPreparseData()]
343 // - a UncompiledDataWithPreparseData for lazy compilation
344 // [HasUncompiledDataWithPreparseData()]
345 // - a WasmExportedFunctionData for Wasm [HasWasmExportedFunctionData()]
346 // - a WasmJSFunctionData for functions created with WebAssembly.Function
347 // - a WasmCapiFunctionData for Wasm C-API functions
348 // - a WasmResumeData for JSPI Wasm functions
349 //
350 // If the (expected) type of data is known, prefer to use the specialized
351 // accessors (e.g. bytecode_array(), uncompiled_data(), etc.).
352 inline Tagged<Object> GetTrustedData(IsolateForSandbox isolate) const;
353 inline Tagged<Object> GetUntrustedData() const;
354
355 // Helper function for use when a specific data type is expected.
356 template <typename T, IndirectPointerTag tag>
357 inline Tagged<T> GetTrustedData(IsolateForSandbox isolate) const;
358
359 // Helper function when no Isolate is available. Prefer to use the variant
360 // with an isolate parameter if possible.
361 inline Tagged<Object> GetTrustedData() const;
362
363 private:
364 // For the sandbox, the function's data is split across two fields, with the
365 // "trusted" part containing a trusted pointer and the regular/untrusted part
366 // containing a tagged pointer. In that case, code accessing the data field
367 // will first load the trusted data field. If that is empty (i.e.
368 // kNullIndirectPointerHandle), it will then load the regular field. With
369 // that, the only racy transition would be a tagged -> trusted transition
370 // (one thread may first read the empty trusted pointer, then another thread
371 // transitions to the trusted field, clearing the tagged field, and then the
372 // first thread continues to load the tagged field). As such, this transition
373 // is only allowed on the main thread. From a GC perspective, both fields
374 // always contain a valid value and so can be processed unconditionally.
375 // Only one of these two fields should be in use at any time and the other
376 // field should be cleared. As such, when setting these fields use
377 // SetTrustedData() and SetUntrustedData() which automatically clear the
378 // inactive field.
379 // TODO(chromium:1490564): try to merge these two fields back together, for
380 // example by moving all data objects into trusted space.
383 inline void SetUntrustedData(Tagged<Object> value,
385
386 inline bool HasTrustedData() const;
387 inline bool HasUntrustedData() const;
388
389 public:
390 inline bool IsApiFunction() const;
391 inline bool is_class_constructor() const;
393 DECL_GETTER(HasBytecodeArray, bool)
394 template <typename IsolateT>
395 inline Tagged<BytecodeArray> GetBytecodeArray(IsolateT* isolate) const;
396
397 // Sets the bytecode for this SFI. This is only allowed when this SFI has not
398 // yet been compiled or if it has been "uncompiled", or in other words when
399 // there is no existing bytecode yet.
400 inline void set_bytecode_array(Tagged<BytecodeArray> bytecode);
401 // Like set_bytecode_array but allows overwriting existing bytecode.
402 inline void overwrite_bytecode_array(Tagged<BytecodeArray> bytecode);
403
404 inline Tagged<Code> InterpreterTrampoline(IsolateForSandbox isolate) const;
405 inline bool HasInterpreterData(IsolateForSandbox isolate) const;
407 IsolateForSandbox isolate) const;
408 inline void set_interpreter_data(
411 DECL_GETTER(HasBaselineCode, bool)
413 inline void FlushBaselineCode();
415 IsolateForSandbox isolate) const;
416 inline void SetActiveBytecodeArray(Tagged<BytecodeArray> bytecode,
417 IsolateForSandbox isolate);
418
419#if V8_ENABLE_WEBASSEMBLY
420 inline bool HasAsmWasmData() const;
421 inline bool HasWasmFunctionData() const;
422 inline bool HasWasmExportedFunctionData() const;
423 inline bool HasWasmJSFunctionData() const;
424 inline bool HasWasmCapiFunctionData() const;
425 inline bool HasWasmResumeData() const;
426 DECL_ACCESSORS(asm_wasm_data, Tagged<AsmWasmData>)
427
428 // Note: The accessors below will read a trusted pointer; when accessing it
429 // again, you must assume that it might have been swapped out e.g. by a
430 // concurrently running worker.
431 DECL_GETTER(wasm_function_data, Tagged<WasmFunctionData>)
432 DECL_GETTER(wasm_exported_function_data, Tagged<WasmExportedFunctionData>)
433 DECL_GETTER(wasm_js_function_data, Tagged<WasmJSFunctionData>)
434 DECL_GETTER(wasm_capi_function_data, Tagged<WasmCapiFunctionData>)
435
436 DECL_GETTER(wasm_resume_data, Tagged<WasmResumeData>)
437#endif // V8_ENABLE_WEBASSEMBLY
438
439 // builtin corresponds to the auto-generated Builtin enum.
440 inline bool HasBuiltinId() const;
442
443 inline bool HasUncompiledData() const;
445 IsolateForSandbox isolate) const;
448 inline bool HasUncompiledDataWithPreparseData() const;
454 inline bool HasUncompiledDataWithoutPreparseData() const;
456
457 // Clear out pre-parsed scope data from UncompiledDataWithPreparseData,
458 // turning it into UncompiledDataWithoutPreparseData.
459 inline void ClearPreparseData(IsolateForSandbox isolate);
460
461 // The inferred_name is inferred from variable or property assignment of this
462 // function. It is used to facilitate debugging and profiling of JavaScript
463 // code written in OO style, where almost all functions are anonymous but are
464 // assigned to object properties.
465 inline bool HasInferredName();
466 DECL_GETTER(inferred_name, Tagged<String>)
467
468 // All DebugInfo accessors forward to the Debug object which stores DebugInfo
469 // objects in a sidetable.
470 bool HasDebugInfo(Isolate* isolate) const;
472 V8_EXPORT_PRIVATE std::optional<Tagged<DebugInfo>> TryGetDebugInfo(
473 Isolate* isolate) const;
474 V8_EXPORT_PRIVATE bool HasBreakInfo(Isolate* isolate) const;
475 bool BreakAtEntry(Isolate* isolate) const;
476 bool HasCoverageInfo(Isolate* isolate) const;
478
479 // The function's name if it is non-empty, otherwise the inferred name.
480 std::unique_ptr<char[]> DebugNameCStr() const;
481 static Handle<String> DebugName(Isolate* isolate,
483
484 // Used for flags such as --turbo-filter.
485 bool PassesFilter(const char* raw_filter);
486
487 // [script]: the Script from which the function originates, or undefined.
489 // Use `raw_script` if deserialization of this SharedFunctionInfo may still
490 // be in progress and thus the `script` field still equal to
491 // Smi::uninitialized_deserialization_value.
493 // TODO(jgruber): Remove these overloads and pass the kAcquireLoad tag
494 // explicitly.
495 inline Tagged<HeapObject> script() const;
496 inline Tagged<HeapObject> script(PtrComprCageBase cage_base) const;
497 inline bool has_script(AcquireLoadTag tag) const;
498
499 // True if the underlying script was parsed and compiled in REPL mode.
500 inline bool is_repl_mode() const;
501
502 // The offset of the 'function' token in the script source relative to the
503 // start position. Can return kFunctionTokenOutOfRange if offset doesn't
504 // fit in 16 bits.
505 DECL_UINT16_ACCESSORS(raw_function_token_offset)
506 private:
507 using TorqueGeneratedSharedFunctionInfo::function_token_offset;
508 using TorqueGeneratedSharedFunctionInfo::set_function_token_offset;
509
510 public:
511 // The position of the 'function' token in the script source. Can return
512 // kNoSourcePosition if raw_function_token_offset() returns
513 // kFunctionTokenOutOfRange.
514 inline int function_token_position() const;
515
516 // Returns true if the function has shared name.
517 inline bool HasSharedName() const;
518
519 // [flags] Bit field containing various flags about the function.
522
524
525 // True if the outer class scope contains a private brand for
526 // private instance methods.
527 DECL_BOOLEAN_ACCESSORS(class_scope_has_private_brand)
529
530 DECL_BOOLEAN_ACCESSORS(is_sparkplug_compiling)
532
535
536 DECL_BOOLEAN_ACCESSORS(function_context_independent_compiled)
537
538 // Is this function a top-level function (scripts, evals).
539 DECL_BOOLEAN_ACCESSORS(is_toplevel)
540
541 // Indicates if this function can be lazy compiled.
542 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
543
544 // Indicates the language mode.
545 inline LanguageMode language_mode() const;
547
548 // How the function appears in source text.
550
551 // Indicates whether the source is implicitly wrapped in a function.
552 inline bool is_wrapped() const;
553
554 // True if the function has any duplicated parameter names.
556
557 // Indicates whether the function is a native function.
558 // These needs special treatment in .call and .apply since
559 // null passed as the receiver should not be translated to the
560 // global object.
562
563#if V8_ENABLE_WEBASSEMBLY
564 // Indicates that asm->wasm conversion failed and should not be re-attempted.
565 DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken)
566#endif // V8_ENABLE_WEBASSEMBLY
567
568 // Indicates that the function was created by the Function function.
569 // Though it's anonymous, toString should treat it as if it had the name
570 // "anonymous". We don't set the name itself so that the system does not
571 // see a binding for it.
572 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
573
574 // Whether or not the number of expected properties may change.
575 DECL_BOOLEAN_ACCESSORS(are_properties_final)
576
577 // Indicates that the function has been reported for binary code coverage.
579
580 // Indicates that the private name lookups inside the function skips the
581 // closest outer class scope.
582 DECL_BOOLEAN_ACCESSORS(private_name_lookup_skips_outer_class)
583
584 // Indicates that the shared function info was live-edited.
586
587 inline FunctionKind kind() const;
588
589 int UniqueIdInScript() const;
590
591 // Defines the index in a native context of closure's map instantiated using
592 // this shared function info.
593 DECL_INT_ACCESSORS(function_map_index)
594
595 // Clear uninitialized padding space. This ensures that the snapshot content
596 // is deterministic.
597 inline void clear_padding();
598
599 // Recalculates the |map_index| value after modifications of this shared info.
600 inline void UpdateFunctionMapIndex();
601
602 // Indicates whether optimizations have been disabled for this shared function
603 // info. If we cannot optimize the function we disable optimization to avoid
604 // spending time attempting to optimize it again.
605 inline bool optimization_disabled() const;
606
607 // The reason why optimization was disabled.
609
610 // Disable (further) attempted optimization of all functions sharing this
611 // shared function info.
612 void DisableOptimization(Isolate* isolate, BailoutReason reason);
613
614 // This class constructor needs to call out to an instance fields
615 // initializer. This flag is set when creating the
616 // SharedFunctionInfo as a reminder to emit the initializer call
617 // when generating code later.
619
620 // [source code]: Source code for the function.
621 bool HasSourceCode() const;
626
627 // Tells whether this function should be subject to debugging, e.g. for
628 // - scope inspection
629 // - internal break points
630 // - coverage and type profile
631 // - error stack trace
632 inline bool IsSubjectToDebugging() const;
633
634 // Whether this function is defined in user-provided JavaScript code.
635 inline bool IsUserJavaScript() const;
636
637 // True if one can flush compiled code from this function, in such a way that
638 // it can later be re-compiled.
639 inline bool CanDiscardCompiled() const;
640
641 // Flush compiled data from this function, setting it back to CompileLazy and
642 // clearing any compiled metadata.
644 Isolate* isolate, DirectHandle<SharedFunctionInfo> shared_info);
645
646 // Discard the compiled metadata. If called during GC then
647 // |gc_notify_updated_slot| should be used to record any slot updates.
649 Isolate* isolate,
650 std::function<void(Tagged<HeapObject> object, ObjectSlot slot,
651 Tagged<HeapObject> target)>
652 gc_notify_updated_slot = [](Tagged<HeapObject> object,
653 ObjectSlot slot,
654 Tagged<HeapObject> target) {});
655
656 // Returns true if the function has old bytecode that could be flushed. This
657 // function shouldn't access any flags as it is used by concurrent marker.
658 // Hence it takes the mode as an argument.
659 inline bool ShouldFlushCode(base::EnumSet<CodeFlushMode> code_flush_mode);
660
674 // Returns the first value that applies (see enum definition for the order).
675 template <typename IsolateT>
676 Inlineability GetInlineability(IsolateT* isolate) const;
677
678 // Source size of this function.
679 int SourceSize();
680
681 // Returns `false` if formal parameters include rest parameters, optional
682 // parameters, or destructuring parameters.
683 // TODO(caitp): make this a flag set during parsing
684 inline bool has_simple_parameters();
685
686 // Initialize a SharedFunctionInfo from a parsed or preparsed function
687 // literal.
688 template <typename IsolateT>
689 static void InitFromFunctionLiteral(IsolateT* isolate,
690 FunctionLiteral* lit, bool is_toplevel);
691
692 template <typename IsolateT>
693 static void CreateAndSetUncompiledData(IsolateT* isolate,
694 FunctionLiteral* lit);
695
696 // Updates the expected number of properties based on estimate from parser.
700
701 // Sets the FunctionTokenOffset field based on the given token position and
702 // start position.
704 int start_position);
705
707 Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
710
711 inline bool CanCollectSourcePosition(Isolate* isolate);
713 Isolate* isolate, DirectHandle<SharedFunctionInfo> shared_info);
714
715 template <typename IsolateT>
716 bool AreSourcePositionsAvailable(IsolateT* isolate) const;
717
718 // Hash based on function literal id and script id.
719 V8_EXPORT_PRIVATE uint32_t Hash();
720
721 inline bool construct_as_builtin() const;
722
723 // Determines and sets the ConstructAsBuiltinBit in |flags|, based on the
724 // |function_data|. Must be called when creating the SFI after other fields
725 // are initialized. The ConstructAsBuiltinBit determines whether
726 // JSBuiltinsConstructStub or JSConstructStubGeneric should be called to
727 // construct this function.
728 inline void CalculateConstructAsBuiltin();
729
730 // Replaces the current age with a new value if the current value matches the
731 // one expected. Returns the value before this operation.
732 inline uint16_t CompareExchangeAge(uint16_t expected_age, uint16_t new_age);
733
734 // Bytecode aging
737
738 // Dispatched behavior.
741#ifdef VERIFY_HEAP
742 void SharedFunctionInfoVerify(LocalIsolate* isolate);
743#endif
744#ifdef OBJECT_PRINT
745 void PrintSourceCode(std::ostream& os);
746#endif
747
748 // Iterate over all shared function infos in a given script.
750 public:
756 int CurrentIndex() const { return index_ - 1; }
757
758 // Reset the iterator to run on |script|.
759 void Reset(Isolate* isolate, Tagged<Script> script);
760
761 private:
764 };
765
766 // Constants.
768 static const uint16_t kFunctionTokenOutOfRange = static_cast<uint16_t>(-1);
770
771 static_assert(kSize % kTaggedSize == 0);
772
773 class BodyDescriptor;
774
775 // Bailout reasons must fit in the DisabledOptimizationReason bitfield.
776 static_assert(DisabledOptimizationReasonBits::is_valid(
777 BailoutReason::kLastErrorMessage));
778
779 static_assert(FunctionKindBits::is_valid(FunctionKind::kLastFunctionKind));
780 static_assert(FunctionSyntaxKindBits::is_valid(
782
783 // Sets the bytecode in {shared}'s DebugInfo as the bytecode to
784 // be returned by following calls to GetActiveBytecodeArray. Stores a
785 // reference to the original bytecode in the DebugInfo.
787 Isolate* isolate);
788 // Removes the debug bytecode and restores the original bytecode to be
789 // returned by following calls to GetActiveBytecodeArray.
791 Isolate* isolate);
792
793#ifdef DEBUG
794 // Verifies that all SFI::unique_id values on the heap are unique, including
795 // Isolate::new_unique_sfi_id_.
796 static bool UniqueIdsAreUnique(Isolate* isolate);
797#endif // DEBUG
798
799 private:
800#ifdef VERIFY_HEAP
801 void SharedFunctionInfoVerify(ReadOnlyRoots roots);
802#endif
803
804 // [name_or_scope_info]: Function name string, kNoSharedNameSentinel or
805 // ScopeInfo.
807
808 // [outer scope info] The outer scope info, needed to lazily parse this
809 // function.
810 DECL_ACCESSORS(outer_scope_info, Tagged<HeapObject>)
811
812 // [properties_are_final]: This bit is used to track if we have finished
813 // parsing its properties. The properties final bit is only used by
814 // class constructors to handle lazily parsed properties.
816
817 inline void set_kind(FunctionKind kind);
818
820
821 // For ease of use of the BITFIELD macro.
822 inline int32_t relaxed_flags() const;
823 inline void set_relaxed_flags(int32_t flags);
824
825 template <typename Impl>
826 friend class FactoryBase;
827 friend class V8HeapExplorer;
828 FRIEND_TEST(PreParserTest, LazyFunctionLength);
829
831};
832
833std::ostream& operator<<(std::ostream& os, SharedFunctionInfo::Inlineability i);
834
835// A SharedFunctionInfoWrapper wraps a SharedFunctionInfo from trusted space.
836// It can be useful when a protected pointer reference to a SharedFunctionInfo
837// is needed, for example for a ProtectedFixedArray.
839 public:
841
844
845#define FIELD_LIST(V) \
846 V(kSharedInfoOffset, kTaggedSize) \
847 V(kHeaderSize, 0) \
848 V(kSize, 0)
849
851#undef FIELD_LIST
852
853 class BodyDescriptor;
854
856};
857
858static constexpr int kStaticRootsSFISize = 48;
859#ifdef V8_STATIC_ROOTS
860static_assert(SharedFunctionInfo::kSize == kStaticRootsSFISize);
861#endif // V8_STATIC_ROOTS
862
863// Printing support.
865 explicit SourceCodeOf(Tagged<SharedFunctionInfo> v, int max = -1)
866 : value(v), max_length(max) {}
869};
870
871// IsCompiledScope enables a caller to check if a function is compiled, and
872// ensure it remains compiled (i.e., doesn't have it's bytecode flushed) while
873// the scope is retained.
875 public:
877 Isolate* isolate);
879 LocalIsolate* isolate);
880 inline IsCompiledScope() : retain_code_(), is_compiled_(false) {}
881
882 inline bool is_compiled() const { return is_compiled_; }
883
884 private:
887};
888
889std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v);
890
891} // namespace v8::internal
892
894
895#endif // V8_OBJECTS_SHARED_FUNCTION_INFO_H_
MaybeHandle< HeapObject > retain_code_
IsCompiledScope(const Tagged< SharedFunctionInfo > shared, Isolate *isolate)
void copy_in(int index, const uint8_t *buffer, int length)
static int InnerOffset(int data_length)
void set_child(int index, Tagged< PreparseData > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
Tagged< Object > get_child_raw(int index) const
Tagged< PreparseData > get_child(int index) const
void set(int index, uint8_t value)
static int SizeFor(int data_length, int children_length)
OBJECT_CONSTRUCTORS(SharedFunctionInfoWrapper, TrustedObject)
void Reset(Isolate *isolate, Tagged< Script > script)
ScriptIterator(const ScriptIterator &)=delete
V8_EXPORT_PRIVATE ScriptIterator(Isolate *isolate, Tagged< Script > script)
ScriptIterator & operator=(const ScriptIterator &)=delete
V8_EXPORT_PRIVATE Tagged< SharedFunctionInfo > Next()
uint16_t internal_formal_parameter_count_with_receiver() const
void set_bytecode_array(Tagged< BytecodeArray > bytecode)
static void UninstallDebugBytecode(Tagged< SharedFunctionInfo > shared, Isolate *isolate)
void Init(ReadOnlyRoots roots, int unique_id)
Tagged< CoverageInfo > GetCoverageInfo(Isolate *isolate) const
Tagged< BytecodeArray > GetActiveBytecodeArray(IsolateForSandbox isolate) const
bool ShouldFlushCode(base::EnumSet< CodeFlushMode > code_flush_mode)
bool HasCoverageInfo(Isolate *isolate) const
void SetFunctionTokenPosition(int function_token_position, int start_position)
Tagged< UncompiledDataWithPreparseData > uncompiled_data_with_preparse_data(IsolateForSandbox isolate) const
Tagged< BytecodeArray > GetBytecodeArray(IsolateT *isolate) const
static DirectHandle< Object > GetSourceCode(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
static void InstallDebugBytecode(DirectHandle< SharedFunctionInfo > shared, Isolate *isolate)
static const uint16_t kFunctionTokenOutOfRange
void set_cached_tiering_decision(CachedTieringDecision decision)
void DisableOptimization(Isolate *isolate, BailoutReason reason)
void UpdateAndFinalizeExpectedNofPropertiesFromEstimate(FunctionLiteral *literal)
void set_uncompiled_data(Tagged< UncompiledData > data, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static void EnsureSourcePositionsAvailable(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared_info)
static void EnsureBytecodeArrayAvailable(Isolate *isolate, Handle< SharedFunctionInfo > shared_info, IsCompiledScope *is_compiled_scope, CreateSourcePositions flag=CreateSourcePositions::kNo)
uint16_t get_property_estimate_from_literal(FunctionLiteral *literal)
void set_raw_scope_info(Tagged< ScopeInfo > scope_info, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
Tagged< ScopeInfo > EarlyScopeInfo(AcquireLoadTag tag)
bool PassesFilter(const char *raw_filter)
V8_EXPORT_PRIVATE uint32_t Hash()
Tagged< AbstractCode > abstract_code(Isolate *isolate)
Tagged< Code > InterpreterTrampoline(IsolateForSandbox isolate) const
static Handle< Object > GetSourceCodeHarmony(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
static V8_EXPORT_PRIVATE constexpr Tagged< Smi > const kNoSharedNameSentinel
void SetTrustedData(Tagged< ExposedTrustedObject > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
void ClearPreparseData(IsolateForSandbox isolate)
void ClearUncompiledDataJobPointer(IsolateForSandbox isolate)
uint16_t CompareExchangeAge(uint16_t expected_age, uint16_t new_age)
Tagged< ScopeInfo > GetOuterScopeInfo() const
CachedTieringDecision cached_tiering_decision()
V8_EXPORT_PRIVATE std::optional< Tagged< DebugInfo > > TryGetDebugInfo(Isolate *isolate) const
V8_EXPORT_PRIVATE Tagged< DebugInfo > GetDebugInfo(Isolate *isolate) const
void SetUntrustedData(Tagged< Object > value, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
void CopyFrom(Tagged< SharedFunctionInfo > other, IsolateForSandbox isolate)
V8_EXPORT_PRIVATE int StartPosition() const
Tagged< InterpreterData > interpreter_data(IsolateForSandbox isolate) const
Tagged< UncompiledData > uncompiled_data(IsolateForSandbox isolate) const
V8_EXPORT_PRIVATE void UpdateFromFunctionLiteralForLiveEdit(IsolateForSandbox isolate, FunctionLiteral *lit)
uint16_t internal_formal_parameter_count_without_receiver() const
bool BreakAtEntry(Isolate *isolate) const
static void CreateAndSetUncompiledData(IsolateT *isolate, FunctionLiteral *lit)
static Handle< String > DebugName(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared)
void SetActiveBytecodeArray(Tagged< BytecodeArray > bytecode, IsolateForSandbox isolate)
void set_interpreter_data(Isolate *isolate, Tagged< InterpreterData > interpreter_data, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
static V8_EXPORT_PRIVATE void DiscardCompiled(Isolate *isolate, DirectHandle< SharedFunctionInfo > shared_info)
std::unique_ptr< char[]> DebugNameCStr() const
void UpdateExpectedNofPropertiesFromEstimate(FunctionLiteral *literal)
V8_EXPORT_PRIVATE int EndPosition() const
bool has_script(AcquireLoadTag tag) const
void SetScopeInfo(Tagged< ScopeInfo > scope_info, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
V8_EXPORT_PRIVATE Tagged< Code > GetCode(Isolate *isolate) const
V8_EXPORT_PRIVATE void SetScript(IsolateForSandbox isolate, ReadOnlyRoots roots, Tagged< HeapObject > script_object, int function_literal_id, bool reset_preparsed_scope_data=true)
static V8_EXPORT_PRIVATE void EnsureOldForTesting(Tagged< SharedFunctionInfo > sfu)
IsCompiledScope is_compiled_scope(IsolateT *isolate) const
void DiscardCompiledMetadata(Isolate *isolate, std::function< void(Tagged< HeapObject > object, ObjectSlot slot, Tagged< HeapObject > target)> gc_notify_updated_slot=[](Tagged< HeapObject > object, ObjectSlot slot, Tagged< HeapObject > target) {})
Inlineability GetInlineability(IsolateT *isolate) const
bool AreSourcePositionsAvailable(IsolateT *isolate) const
void overwrite_bytecode_array(Tagged< BytecodeArray > bytecode)
void set_relaxed_flags(int32_t flags)
V8_EXPORT_PRIVATE bool HasBreakInfo(Isolate *isolate) const
void set_language_mode(LanguageMode language_mode)
bool HasInterpreterData(IsolateForSandbox isolate) const
void set_uncompiled_data_with_preparse_data(Tagged< UncompiledDataWithPreparseData > data, WriteBarrierMode mode=UPDATE_WRITE_BARRIER)
FRIEND_TEST(PreParserTest, LazyFunctionLength)
static void InitFromFunctionLiteral(IsolateT *isolate, FunctionLiteral *lit, bool is_toplevel)
bool HasDebugInfo(Isolate *isolate) const
static constexpr Tagged< Smi > zero()
Definition smi.h:99
static constexpr int kHeaderSize
void InitAfterBytecodeFlush(Isolate *isolate, Tagged< String > inferred_name, int start_position, int end_position, std::function< void(Tagged< HeapObject > object, ObjectSlot slot, Tagged< HeapObject > target)> gc_notify_updated_slot)
FunctionLiteral * literal
Definition liveedit.cc:294
#define FIELD_LIST(V)
constexpr int kByteSize
Definition globals.h:395
static constexpr int kStaticRootsSFISize
constexpr int kTaggedSize
Definition globals.h:542
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit SharedFunctionInfo::FunctionSyntaxKindBits SharedFunctionInfo::HasDuplicateParametersBit SharedFunctionInfo::RequiresInstanceMembersInitializerBit has_reported_binary_coverage
@ UPDATE_WRITE_BARRIER
Definition objects.h:55
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit SharedFunctionInfo::FunctionSyntaxKindBits SharedFunctionInfo::HasDuplicateParametersBit SharedFunctionInfo::RequiresInstanceMembersInitializerBit SharedFunctionInfo::HasReportedBinaryCoverageBit SharedFunctionInfo::PropertiesAreFinalBit live_edited
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit syntax_kind
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit maglev_compilation_failed
constexpr int kMaxUInt16
Definition globals.h:382
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit SharedFunctionInfo::FunctionSyntaxKindBits SharedFunctionInfo::HasDuplicateParametersBit SharedFunctionInfo::RequiresInstanceMembersInitializerBit SharedFunctionInfo::HasReportedBinaryCoverageBit properties_are_final
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit SharedFunctionInfo::FunctionSyntaxKindBits has_duplicate_parameters
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
UnionOf< Smi, String, ScopeInfo > NameOrScopeInfoT
SharedFunctionInfo::HasStaticPrivateMethodsOrAccessorsBit SharedFunctionInfo::MaglevCompilationFailedBit SharedFunctionInfo::FunctionSyntaxKindBits SharedFunctionInfo::HasDuplicateParametersBit requires_instance_members_initializer
Definition c-api.cc:87
#define DECL_UINT16_ACCESSORS(name)
#define DECL_ACCESSORS(name,...)
#define DECL_GETTER(name,...)
#define DECL_ACQUIRE_GETTER(name,...)
#define DECL_VERIFIER(Name)
#define DECL_BOOLEAN_ACCESSORS(name)
#define DECL_UINT8_ACCESSORS(name)
#define DECL_PRIMITIVE_ACCESSORS(name, type)
#define DECL_PROTECTED_POINTER_ACCESSORS(name, type)
#define DECL_PRINTER(Name)
#define DECL_RELEASE_ACQUIRE_ACCESSORS(name,...)
#define DECL_RELAXED_INT32_ACCESSORS(name)
#define DECL_INT_ACCESSORS(name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
constexpr T RoundUp(T x, intptr_t m)
Definition macros.h:387
#define V8_EXPORT_PRIVATE
Definition macros.h:460
SourceCodeOf(Tagged< SharedFunctionInfo > v, int max=-1)
const Tagged< SharedFunctionInfo > value
#define DEFINE_FIELD_OFFSET_CONSTANTS(StartOffset, LIST_MACRO)
Definition utils.h:242
#define V8_NODISCARD
Definition v8config.h:693