diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index aeaa7131cd6992..f3fbdc696294e4 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1732,8 +1732,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. @@ -3393,6 +3399,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(). @@ -3400,6 +3408,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); @@ -3444,9 +3454,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); @@ -6560,19 +6572,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 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 @@ -6596,8 +6596,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. @@ -6607,10 +6611,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; } /** @@ -6618,25 +6622,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. } /** @@ -6644,23 +6644,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) { @@ -6673,13 +6677,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 1de05cd9f7a30c..a18aeeda8711f2 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -237,10 +237,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) @@ -953,31 +961,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) { @@ -995,15 +979,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) { @@ -2499,6 +2482,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, @@ -3969,6 +3962,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()); @@ -3982,6 +3980,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) { @@ -4199,6 +4202,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); @@ -4209,6 +4217,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))); @@ -10545,6 +10558,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);