diff options
Diffstat (limited to 'deps/v8/src/heap/factory.h')
-rw-r--r-- | deps/v8/src/heap/factory.h | 216 |
1 files changed, 131 insertions, 85 deletions
diff --git a/deps/v8/src/heap/factory.h b/deps/v8/src/heap/factory.h index 94646517a0..5af2529021 100644 --- a/deps/v8/src/heap/factory.h +++ b/deps/v8/src/heap/factory.h @@ -8,14 +8,14 @@ // Clients of this interface shouldn't depend on lots of heap internals. // Do not include anything from src/heap here! #include "src/builtins/builtins.h" -#include "src/function-kind.h" -#include "src/globals.h" -#include "src/handles.h" +#include "src/common/globals.h" +#include "src/execution/messages.h" +#include "src/handles/handles.h" +#include "src/handles/maybe-handles.h" #include "src/heap/heap.h" -#include "src/maybe-handles.h" -#include "src/messages.h" #include "src/objects/code.h" #include "src/objects/dictionary.h" +#include "src/objects/function-kind.h" #include "src/objects/js-array.h" #include "src/objects/js-regexp.h" #include "src/objects/string.h" @@ -40,6 +40,7 @@ class EnumCache; class FinalizationGroupCleanupJobTask; class FreshlyAllocatedBigInt; class Isolate; +class JSArrayBufferView; class JSDataView; class JSGeneratorObject; class JSMap; @@ -65,7 +66,9 @@ class StoreHandler; class TemplateObjectDescription; class UncompiledDataWithoutPreparseData; class UncompiledDataWithPreparseData; +class WasmCapiFunctionData; class WasmExportedFunctionData; +class WasmJSFunctionData; class WeakCell; struct SourceRange; template <typename T> @@ -236,16 +239,19 @@ class V8_EXPORT_PRIVATE Factory { // Finds the internalized copy for string in the string table. // If not found, a new string is added to the table and returned. - Handle<String> InternalizeUtf8String(Vector<const char> str); + Handle<String> InternalizeUtf8String(const Vector<const char>& str); Handle<String> InternalizeUtf8String(const char* str) { return InternalizeUtf8String(CStrVector(str)); } - Handle<String> InternalizeOneByteString(Vector<const uint8_t> str); - Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>, int from, - int length); + template <typename Char> + EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) + Handle<String> InternalizeString(const Vector<const Char>& str, + bool convert_encoding = false); - Handle<String> InternalizeTwoByteString(Vector<const uc16> str); + template <typename SeqString> + Handle<String> InternalizeString(Handle<SeqString>, int from, int length, + bool convert_encoding = false); template <class StringTableKey> Handle<String> InternalizeStringWithKey(StringTableKey* key); @@ -276,14 +282,14 @@ class V8_EXPORT_PRIVATE Factory { // // One-byte strings are pretenured when used as keys in the SourceCodeCache. V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromOneByte( - Vector<const uint8_t> str, + const Vector<const uint8_t>& str, AllocationType allocation = AllocationType::kYoung); template <size_t N> inline Handle<String> NewStringFromStaticChars( const char (&str)[N], AllocationType allocation = AllocationType::kYoung) { - DCHECK(N == StrLength(str) + 1); + DCHECK_EQ(N, strlen(str) + 1); return NewStringFromOneByte(StaticCharVector(str), allocation) .ToHandleChecked(); } @@ -297,7 +303,7 @@ class V8_EXPORT_PRIVATE Factory { // UTF8 strings are pretenured when used for regexp literal patterns and // flags in the parser. V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8( - Vector<const char> str, + const Vector<const char>& str, AllocationType allocation = AllocationType::kYoung); V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromUtf8SubString( @@ -305,7 +311,7 @@ class V8_EXPORT_PRIVATE Factory { AllocationType allocation = AllocationType::kYoung); V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromTwoByte( - Vector<const uc16> str, + const Vector<const uc16>& str, AllocationType allocation = AllocationType::kYoung); V8_WARN_UNUSED_RESULT MaybeHandle<String> NewStringFromTwoByte( @@ -314,21 +320,18 @@ class V8_EXPORT_PRIVATE Factory { Handle<JSStringIterator> NewJSStringIterator(Handle<String> string); - // Allocates an internalized string in old space based on the character - // stream. - Handle<String> NewInternalizedStringFromUtf8(Vector<const char> str, - int chars, uint32_t hash_field); - - Handle<String> NewOneByteInternalizedString(Vector<const uint8_t> str, + Handle<String> NewOneByteInternalizedString(const Vector<const uint8_t>& str, uint32_t hash_field); - Handle<String> NewOneByteInternalizedSubString( - Handle<SeqOneByteString> string, int offset, int length, - uint32_t hash_field); + Handle<SeqOneByteString> AllocateRawOneByteInternalizedString( + int length, uint32_t hash_field); - Handle<String> NewTwoByteInternalizedString(Vector<const uc16> str, + Handle<String> NewTwoByteInternalizedString(const Vector<const uc16>& str, uint32_t hash_field); + Handle<SeqTwoByteString> AllocateRawTwoByteInternalizedString( + int length, uint32_t hash_field); + Handle<String> NewInternalizedStringImpl(Handle<String> string, int chars, uint32_t hash_field); @@ -352,7 +355,7 @@ class V8_EXPORT_PRIVATE Factory { // Creates a single character string where the character has given code. // A cache is used for Latin1 codes. - Handle<String> LookupSingleCharacterStringFromCode(uint32_t code); + Handle<String> LookupSingleCharacterStringFromCode(uint16_t code); // Create a new cons string object which consists of a pair of strings. V8_WARN_UNUSED_RESULT MaybeHandle<String> NewConsString(Handle<String> left, @@ -488,14 +491,6 @@ class V8_EXPORT_PRIVATE Factory { int frame_size, int parameter_count, Handle<FixedArray> constant_pool); - Handle<FixedTypedArrayBase> NewFixedTypedArrayWithExternalPointer( - int length, ExternalArrayType array_type, void* external_pointer, - AllocationType allocation = AllocationType::kYoung); - - Handle<FixedTypedArrayBase> NewFixedTypedArray( - size_t length, size_t byte_length, ExternalArrayType array_type, - bool initialize, AllocationType allocation = AllocationType::kYoung); - Handle<Cell> NewCell(Handle<Object> value); Handle<PropertyCell> NewPropertyCell( @@ -571,8 +566,6 @@ class V8_EXPORT_PRIVATE Factory { Handle<FixedDoubleArray> CopyFixedDoubleArray(Handle<FixedDoubleArray> array); - Handle<FeedbackVector> CopyFeedbackVector(Handle<FeedbackVector> array); - // Numbers (e.g. literals) are pretenured by the parser. // The return value may be a smi or a heap number. Handle<Object> NewNumber(double value, @@ -696,27 +689,15 @@ class V8_EXPORT_PRIVATE Factory { ExternalArrayType* array_type, size_t* element_size); - Handle<JSTypedArray> NewJSTypedArray( - ExternalArrayType type, - AllocationType allocation = AllocationType::kYoung); - - Handle<JSTypedArray> NewJSTypedArray( - ElementsKind elements_kind, - AllocationType allocation = AllocationType::kYoung); - // Creates a new JSTypedArray with the specified buffer. Handle<JSTypedArray> NewJSTypedArray( ExternalArrayType type, Handle<JSArrayBuffer> buffer, size_t byte_offset, size_t length, AllocationType allocation = AllocationType::kYoung); - // Creates a new on-heap JSTypedArray. - Handle<JSTypedArray> NewJSTypedArray( - ElementsKind elements_kind, size_t number_of_elements, + Handle<JSDataView> NewJSDataView( + Handle<JSArrayBuffer> buffer, size_t byte_offset, size_t byte_length, AllocationType allocation = AllocationType::kYoung); - Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer, - size_t byte_offset, size_t byte_length); - Handle<JSIteratorResult> NewJSIteratorResult(Handle<Object> value, bool done); Handle<JSAsyncFromSyncIterator> NewJSAsyncFromSyncIterator( Handle<JSReceiver> sync_iterator, Handle<Object> next); @@ -797,35 +778,8 @@ class V8_EXPORT_PRIVATE Factory { Handle<JSObject> NewExternal(void* value); // Creates a new CodeDataContainer for a Code object. - Handle<CodeDataContainer> NewCodeDataContainer(int flags); - - // Allocates a new code object (fully initialized). All header fields of the - // returned object are immutable and the code object is write protected. - // The reference to the Code object is stored in self_reference. - // This allows generated code to reference its own Code object - // by containing this handle. - Handle<Code> NewCode(const CodeDesc& desc, Code::Kind kind, - Handle<Object> self_reference, - int32_t builtin_index = Builtins::kNoBuiltinId, - MaybeHandle<ByteArray> maybe_source_position_table = - MaybeHandle<ByteArray>(), - MaybeHandle<DeoptimizationData> maybe_deopt_data = - MaybeHandle<DeoptimizationData>(), - Movability movability = kMovable, - bool is_turbofanned = false, int stack_slots = 0); - - // Like NewCode, this function allocates a new code object (fully - // initialized). It may return an empty handle if the allocation does not - // succeed. - V8_WARN_UNUSED_RESULT MaybeHandle<Code> TryNewCode( - const CodeDesc& desc, Code::Kind kind, Handle<Object> self_reference, - int32_t builtin_index = Builtins::kNoBuiltinId, - MaybeHandle<ByteArray> maybe_source_position_table = - MaybeHandle<ByteArray>(), - MaybeHandle<DeoptimizationData> maybe_deopt_data = - MaybeHandle<DeoptimizationData>(), - Movability movability = kMovable, bool is_turbofanned = false, - int stack_slots = 0); + Handle<CodeDataContainer> NewCodeDataContainer(int flags, + AllocationType allocation); // Allocates a new code object and initializes it as the trampoline to the // given off-heap entry point. @@ -880,6 +834,9 @@ class V8_EXPORT_PRIVATE Factory { MaybeHandle<String> maybe_name, Handle<FunctionTemplateInfo> function_template_info, FunctionKind kind); + Handle<SharedFunctionInfo> NewSharedFunctionInfoForWasmCapiFunction( + Handle<WasmCapiFunctionData> data); + Handle<SharedFunctionInfo> NewSharedFunctionInfoForBuiltin( MaybeHandle<String> name, int builtin_index, FunctionKind kind = kNormalFunction); @@ -914,7 +871,8 @@ class V8_EXPORT_PRIVATE Factory { // Allocates a new JSMessageObject object. Handle<JSMessageObject> NewJSMessageObject( MessageTemplate message, Handle<Object> argument, int start_position, - int end_position, Handle<Script> script, Handle<Object> stack_frames); + int end_position, Handle<SharedFunctionInfo> shared_info, + int bytecode_offset, Handle<Script> script, Handle<Object> stack_frames); Handle<ClassPositions> NewClassPositions(int start, int end); Handle<DebugInfo> NewDebugInfo(Handle<SharedFunctionInfo> shared); @@ -965,6 +923,89 @@ class V8_EXPORT_PRIVATE Factory { return New(map, allocation); } + // Allows creation of Code objects. It provides two build methods, one of + // which tries to gracefully handle allocation failure. + class V8_EXPORT_PRIVATE CodeBuilder final { + public: + CodeBuilder(Isolate* isolate, const CodeDesc& desc, Code::Kind kind); + + // Builds a new code object (fully initialized). All header fields of the + // returned object are immutable and the code object is write protected. + V8_WARN_UNUSED_RESULT Handle<Code> Build(); + // Like Build, builds a new code object. May return an empty handle if the + // allocation fails. + V8_WARN_UNUSED_RESULT MaybeHandle<Code> TryBuild(); + + // Sets the self-reference object in which a reference to the code object is + // stored. This allows generated code to reference its own Code object by + // using this handle. + CodeBuilder& set_self_reference(Handle<Object> self_reference) { + DCHECK(!self_reference.is_null()); + self_reference_ = self_reference; + return *this; + } + + CodeBuilder& set_builtin_index(int32_t builtin_index) { + builtin_index_ = builtin_index; + return *this; + } + + CodeBuilder& set_source_position_table(Handle<ByteArray> table) { + DCHECK(!table.is_null()); + source_position_table_ = table; + return *this; + } + + CodeBuilder& set_deoptimization_data( + Handle<DeoptimizationData> deopt_data) { + DCHECK(!deopt_data.is_null()); + deoptimization_data_ = deopt_data; + return *this; + } + + CodeBuilder& set_immovable() { + is_movable_ = false; + return *this; + } + + CodeBuilder& set_is_turbofanned() { + is_turbofanned_ = true; + return *this; + } + + // Indicates the CodeDataContainer should be allocated in read-only space. + // As an optimization, if the kind-specific flags match that of a canonical + // container, it will be used instead. + CodeBuilder& set_read_only_data_container(int32_t flags) { + read_only_data_container_ = true; + kind_specific_flags_ = flags; + return *this; + } + + CodeBuilder& set_stack_slots(int stack_slots) { + stack_slots_ = stack_slots; + return *this; + } + + private: + MaybeHandle<Code> BuildInternal(bool retry_allocation_or_fail); + + Isolate* const isolate_; + const CodeDesc& code_desc_; + const Code::Kind kind_; + + MaybeHandle<Object> self_reference_; + int32_t builtin_index_ = Builtins::kNoBuiltinId; + int32_t kind_specific_flags_ = 0; + Handle<ByteArray> source_position_table_; + Handle<DeoptimizationData> deoptimization_data_ = + DeoptimizationData::Empty(isolate_); + bool read_only_data_container_ = false; + bool is_movable_ = true; + bool is_turbofanned_ = false; + int stack_slots_ = 0; + }; + private: Isolate* isolate() { // Downcast to the privately inherited sub-class using c-style casts to @@ -981,6 +1022,11 @@ class V8_EXPORT_PRIVATE Factory { Handle<Map> map, AllocationType allocation, Handle<AllocationSite> allocation_site); + Handle<JSArrayBufferView> NewJSArrayBufferView( + Handle<Map> map, Handle<FixedArrayBase> elements, + Handle<JSArrayBuffer> buffer, size_t byte_offset, size_t byte_length, + AllocationType allocation); + // Allocate memory for an uninitialized array (e.g., a FixedArray or similar). HeapObject AllocateRawArray(int size, AllocationType allocation); HeapObject AllocateRawFixedArray(int length, AllocationType allocation); @@ -1014,11 +1060,8 @@ class V8_EXPORT_PRIVATE Factory { Handle<String> AllocateInternalizedStringImpl(T t, int chars, uint32_t hash_field); - Handle<SeqOneByteString> AllocateRawOneByteInternalizedString( - int length, uint32_t hash_field); - - Handle<String> AllocateTwoByteInternalizedString(Vector<const uc16> str, - uint32_t hash_field); + Handle<String> AllocateTwoByteInternalizedString( + const Vector<const uc16>& str, uint32_t hash_field); MaybeHandle<String> NewStringFromTwoByte(const uc16* string, int length, AllocationType allocation); @@ -1057,6 +1100,9 @@ class NewFunctionArgs final { static NewFunctionArgs ForWasm( Handle<String> name, Handle<WasmExportedFunctionData> exported_function_data, Handle<Map> map); + static NewFunctionArgs ForWasm(Handle<String> name, + Handle<WasmJSFunctionData> js_function_data, + Handle<Map> map); V8_EXPORT_PRIVATE static NewFunctionArgs ForBuiltin(Handle<String> name, Handle<Map> map, int builtin_id); @@ -1085,7 +1131,7 @@ class NewFunctionArgs final { Handle<String> name_; MaybeHandle<Map> maybe_map_; - MaybeHandle<WasmExportedFunctionData> maybe_exported_function_data_; + MaybeHandle<Struct> maybe_wasm_function_data_; bool should_create_and_set_initial_map_ = false; InstanceType type_; |