diff --git a/common.gypi b/common.gypi index a411ad091da253..9ec799d3d98305 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.19', + 'v8_embedder_string': '-node.20', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 27bdfca7298d9f..873ba0e2609b0b 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1819,8 +1819,14 @@ class V8_EXPORT ScriptCompiler { Local arguments[], size_t context_extension_count, Local context_extensions[], CompileOptions options = kNoCompileOptions, - NoCacheReason no_cache_reason = kNoCacheNoReason, - Local* script_or_module_out = nullptr); + NoCacheReason no_cache_reason = kNoCacheNoReason); + + static V8_WARN_UNUSED_RESULT MaybeLocal CompileFunctionInContext( + Local context, Source* source, size_t arguments_count, + Local arguments[], size_t context_extension_count, + Local context_extensions[], CompileOptions options, + NoCacheReason no_cache_reason, + Local* script_or_module_out); /** * Creates and returns code cache for the specified unbound_script. @@ -3481,6 +3487,8 @@ enum class IntegrityLevel { kFrozen, kSealed }; */ class V8_EXPORT Object : public Value { public: + V8_DEPRECATED("Use maybe version", + bool Set(Local key, Local value)); /** * Set only return Just(true) or Empty(), so if it should never fail, use * result.Check(). @@ -3488,6 +3496,8 @@ class V8_EXPORT Object : public Value { V8_WARN_UNUSED_RESULT Maybe Set(Local context, Local key, Local value); + V8_DEPRECATED("Use maybe version", + bool Set(uint32_t index, Local value)); V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index, Local value); @@ -3532,9 +3542,11 @@ class V8_EXPORT Object : public Value { Local context, Local key, PropertyDescriptor& descriptor); // NOLINT(runtime/references) + V8_DEPRECATED("Use maybe version", Local Get(Local key)); V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, Local key); + V8_DEPRECATED("Use maybe version", Local Get(uint32_t index)); V8_WARN_UNUSED_RESULT MaybeLocal Get(Local context, uint32_t index); @@ -6683,26 +6695,7 @@ V8_INLINE Local False(Isolate* isolate); */ class V8_EXPORT ResourceConstraints { public: - /** - * Configures the constraints with reasonable default values based on the - * provided heap size limit. The heap size includes both the young and - * the old generation. - * - * \param initial_heap_size_in_bytes The initial heap size or zero. - * By default V8 starts with a small heap and dynamically grows it to - * match the set of live objects. This may lead to ineffective - * garbage collections at startup if the live set is large. - * Setting the initial heap size avoids such garbage collections. - * Note that this does not affect young generation garbage collections. - * - * \param maximum_heap_size_in_bytes The hard limit for the heap size. - * When the heap size approaches this limit, V8 will perform series of - * garbage collections and invoke the NearHeapLimitCallback. If the garbage - * collections do not help and the callback does not increase the limit, - * then V8 will crash with V8::FatalProcessOutOfMemory. - */ - void ConfigureDefaultsFromHeapSize(size_t initial_heap_size_in_bytes, - size_t maximum_heap_size_in_bytes); + ResourceConstraints(); /** * Configures the constraints with reasonable default values based on the @@ -6726,8 +6719,12 @@ class V8_EXPORT ResourceConstraints { * The amount of virtual memory reserved for generated code. This is relevant * for 64-bit architectures that rely on code range for calls in code. */ - size_t code_range_size_in_bytes() const { return code_range_size_; } - void set_code_range_size_in_bytes(size_t limit) { code_range_size_ = limit; } + size_t code_range_size_in_bytes() const { + return code_range_size_ * kMB; + } + void set_code_range_size_in_bytes(size_t limit) { + code_range_size_ = limit / kMB; + } /** * The maximum size of the old generation. @@ -6737,10 +6734,10 @@ class V8_EXPORT ResourceConstraints { * increase the limit, then V8 will crash with V8::FatalProcessOutOfMemory. */ size_t max_old_generation_size_in_bytes() const { - return max_old_generation_size_; + return max_old_space_size_ * kMB; } void set_max_old_generation_size_in_bytes(size_t limit) { - max_old_generation_size_ = limit; + max_old_space_size_ = limit / kMB; } /** @@ -6748,25 +6745,21 @@ class V8_EXPORT ResourceConstraints { * and a large object space. This affects frequency of Scavenge garbage * collections and should be typically much smaller that the old generation. */ - size_t max_young_generation_size_in_bytes() const { - return max_young_generation_size_; - } - void set_max_young_generation_size_in_bytes(size_t limit) { - max_young_generation_size_ = limit; - } + size_t max_young_generation_size_in_bytes() const; + void set_max_young_generation_size_in_bytes(size_t limit); size_t initial_old_generation_size_in_bytes() const { - return initial_old_generation_size_; + return 0; } void set_initial_old_generation_size_in_bytes(size_t initial_size) { - initial_old_generation_size_ = initial_size; + // Not available on Node 12. } size_t initial_young_generation_size_in_bytes() const { - return initial_young_generation_size_; + return 0; } void set_initial_young_generation_size_in_bytes(size_t initial_size) { - initial_young_generation_size_ = initial_size; + // Not available on Node 12. } /** @@ -6774,23 +6767,27 @@ class V8_EXPORT ResourceConstraints { */ V8_DEPRECATE_SOON("Use code_range_size_in_bytes.", size_t code_range_size() const) { - return code_range_size_ / kMB; + return code_range_size_; } V8_DEPRECATE_SOON("Use set_code_range_size_in_bytes.", void set_code_range_size(size_t limit_in_mb)) { - code_range_size_ = limit_in_mb * kMB; + code_range_size_ = limit_in_mb; } V8_DEPRECATE_SOON("Use max_young_generation_size_in_bytes.", - size_t max_semi_space_size_in_kb() const); + size_t max_semi_space_size_in_kb() const) { + return max_semi_space_size_in_kb_; + } V8_DEPRECATE_SOON("Use set_max_young_generation_size_in_bytes.", - void set_max_semi_space_size_in_kb(size_t limit_in_kb)); + void set_max_semi_space_size_in_kb(size_t limit_in_kb)) { + max_semi_space_size_in_kb_ = limit_in_kb; + } V8_DEPRECATE_SOON("Use max_old_generation_size_in_bytes.", size_t max_old_space_size() const) { - return max_old_generation_size_ / kMB; + return max_old_space_size_; } V8_DEPRECATE_SOON("Use set_max_old_generation_size_in_bytes.", void set_max_old_space_size(size_t limit_in_mb)) { - max_old_generation_size_ = limit_in_mb * kMB; + max_old_space_size_ = limit_in_mb; } V8_DEPRECATE_SOON("Zone does not pool memory any more.", size_t max_zone_pool_size() const) { @@ -6803,13 +6800,15 @@ class V8_EXPORT ResourceConstraints { private: static constexpr size_t kMB = 1048576u; + + // max_semi_space_size_ is in KB + size_t max_semi_space_size_in_kb_ = 0; + + // The remaining limits are in MB + size_t max_old_space_size_ = 0; + uint32_t* stack_limit_ = nullptr; size_t code_range_size_ = 0; - size_t max_old_generation_size_ = 0; - size_t max_young_generation_size_ = 0; size_t max_zone_pool_size_ = 0; - size_t initial_old_generation_size_ = 0; - size_t initial_young_generation_size_ = 0; - uint32_t* stack_limit_ = nullptr; }; diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 092db5c2d1056f..7ad21ee1e48dbc 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -238,10 +238,18 @@ namespace v8 { #define RETURN_ON_FAILED_EXECUTION_PRIMITIVE(T) \ EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, Nothing()) +#define RETURN_TO_LOCAL_UNCHECKED(maybe_local, T) \ + return maybe_local.FromMaybe(Local()); + #define RETURN_ESCAPED(value) return handle_scope.Escape(value); namespace { +Local ContextFromNeverReadOnlySpaceObject( + i::Handle obj) { + return reinterpret_cast(obj->GetIsolate())->GetCurrentContext(); +} + class InternalEscapableScope : public v8::EscapableHandleScope { public: explicit inline InternalEscapableScope(i::Isolate* isolate) @@ -964,31 +972,7 @@ Extension::Extension(const char* name, const char* source, int dep_count, CHECK(source != nullptr || source_length_ == 0); } -void ResourceConstraints::ConfigureDefaultsFromHeapSize( - size_t initial_heap_size_in_bytes, size_t maximum_heap_size_in_bytes) { - CHECK_LE(initial_heap_size_in_bytes, maximum_heap_size_in_bytes); - if (maximum_heap_size_in_bytes == 0) { - return; - } - size_t young_generation, old_generation; - i::Heap::GenerationSizesFromHeapSize(maximum_heap_size_in_bytes, - &young_generation, &old_generation); - set_max_young_generation_size_in_bytes( - i::Max(young_generation, i::Heap::MinYoungGenerationSize())); - set_max_old_generation_size_in_bytes( - i::Max(old_generation, i::Heap::MinOldGenerationSize())); - if (initial_heap_size_in_bytes > 0) { - i::Heap::GenerationSizesFromHeapSize(initial_heap_size_in_bytes, - &young_generation, &old_generation); - // We do not set lower bounds for the initial sizes. - set_initial_young_generation_size_in_bytes(young_generation); - set_initial_old_generation_size_in_bytes(old_generation); - } - if (i::kRequiresCodeRange) { - set_code_range_size_in_bytes( - i::Min(i::kMaximalCodeRangeSize, maximum_heap_size_in_bytes)); - } -} +ResourceConstraints::ResourceConstraints() {} void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, uint64_t virtual_memory_limit) { @@ -1006,15 +990,14 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory, } } -size_t ResourceConstraints::max_semi_space_size_in_kb() const { - return i::Heap::SemiSpaceSizeFromYoungGenerationSize( - max_young_generation_size_) / - i::KB; +size_t ResourceConstraints::max_young_generation_size_in_bytes() const { + return i::Heap::YoungGenerationSizeFromSemiSpaceSize( + max_semi_space_size_in_kb_ * i::KB); } -void ResourceConstraints::set_max_semi_space_size_in_kb(size_t limit_in_kb) { - set_max_young_generation_size_in_bytes( - i::Heap::YoungGenerationSizeFromSemiSpaceSize(limit_in_kb * i::KB)); +void ResourceConstraints::set_max_young_generation_size_in_bytes(size_t limit) { + max_semi_space_size_in_kb_ = + i::Heap::SemiSpaceSizeFromYoungGenerationSize(limit) / i::KB; } i::Address* V8::GlobalizeReference(i::Isolate* isolate, i::Address* obj) { @@ -2518,6 +2501,16 @@ bool IsIdentifier(i::Isolate* isolate, i::Handle string) { } } // anonymous namespace +MaybeLocal ScriptCompiler::CompileFunctionInContext( + Local v8_context, Source* source, size_t arguments_count, + Local arguments[], size_t context_extension_count, + Local context_extensions[], CompileOptions options, + NoCacheReason no_cache_reason) { + return ScriptCompiler::CompileFunctionInContext( + v8_context, source, arguments_count, arguments, context_extension_count, + context_extensions, options, no_cache_reason, nullptr); +} + MaybeLocal ScriptCompiler::CompileFunctionInContext( Local v8_context, Source* source, size_t arguments_count, Local arguments[], size_t context_extension_count, @@ -3988,6 +3981,11 @@ Maybe v8::Object::Set(v8::Local context, return Just(true); } +bool v8::Object::Set(v8::Local key, v8::Local value) { + auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this)); + return Set(context, key, value).FromMaybe(false); +} + Maybe v8::Object::Set(v8::Local context, uint32_t index, v8::Local value) { auto isolate = reinterpret_cast(context->GetIsolate()); @@ -4001,6 +3999,11 @@ Maybe v8::Object::Set(v8::Local context, uint32_t index, return Just(true); } +bool v8::Object::Set(uint32_t index, v8::Local value) { + auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this)); + return Set(context, index, value).FromMaybe(false); +} + Maybe v8::Object::CreateDataProperty(v8::Local context, v8::Local key, v8::Local value) { @@ -4218,6 +4221,11 @@ MaybeLocal v8::Object::Get(Local context, RETURN_ESCAPED(Utils::ToLocal(result)); } +Local v8::Object::Get(v8::Local key) { + auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this)); + RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value); +} + MaybeLocal v8::Object::Get(Local context, uint32_t index) { PREPARE_FOR_EXECUTION(context, Object, Get, Value); auto self = Utils::OpenHandle(this); @@ -4228,6 +4236,11 @@ MaybeLocal v8::Object::Get(Local context, uint32_t index) { RETURN_ESCAPED(Utils::ToLocal(result)); } +Local v8::Object::Get(uint32_t index) { + auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this)); + RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value); +} + MaybeLocal v8::Object::GetPrivate(Local context, Local key) { return Get(context, Local(reinterpret_cast(*key))); @@ -10651,6 +10664,7 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo& info, #undef EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE #undef RETURN_ON_FAILED_EXECUTION #undef RETURN_ON_FAILED_EXECUTION_PRIMITIVE +#undef RETURN_TO_LOCAL_UNCHECKED #undef RETURN_ESCAPED #undef SET_FIELD_WRAPPED #undef NEW_STRING diff --git a/deps/v8/test/unittests/api/resource-constraints-unittest.cc b/deps/v8/test/unittests/api/resource-constraints-unittest.cc index 4c9b7f33dd33da..42966dcf4925e6 100644 --- a/deps/v8/test/unittests/api/resource-constraints-unittest.cc +++ b/deps/v8/test/unittests/api/resource-constraints-unittest.cc @@ -10,6 +10,7 @@ namespace v8 { +/* These tests do not apply on Node 12. TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeSmall) { const size_t KB = static_cast(i::KB); const size_t MB = static_cast(i::MB); @@ -39,6 +40,7 @@ TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeLarge) { ASSERT_EQ(3 * 512 * pm * KB, constraints.initial_young_generation_size_in_bytes()); } +*/ TEST(ResourceConstraints, ConfigureDefaults) { const size_t KB = static_cast(i::KB);