Skip to content

Commit

Permalink
deps: patch V8 to be API/ABI compatible with 7.4 (from 7.7)
Browse files Browse the repository at this point in the history
Co-authored-by: Anna Henningsen <[email protected]>
PR-URL: nodejs#29241
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
2 people authored and MylesBorins committed Jan 7, 2020
1 parent 7305a2d commit dbb2088
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 80 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####

Expand Down
93 changes: 46 additions & 47 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,14 @@ class V8_EXPORT ScriptCompiler {
Local<String> arguments[], size_t context_extension_count,
Local<Object> context_extensions[],
CompileOptions options = kNoCompileOptions,
NoCacheReason no_cache_reason = kNoCacheNoReason,
Local<ScriptOrModule>* script_or_module_out = nullptr);
NoCacheReason no_cache_reason = kNoCacheNoReason);

static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
Local<Context> context, Source* source, size_t arguments_count,
Local<String> arguments[], size_t context_extension_count,
Local<Object> context_extensions[], CompileOptions options,
NoCacheReason no_cache_reason,
Local<ScriptOrModule>* script_or_module_out);

/**
* Creates and returns code cache for the specified unbound_script.
Expand Down Expand Up @@ -3481,13 +3487,17 @@ enum class IntegrityLevel { kFrozen, kSealed };
*/
class V8_EXPORT Object : public Value {
public:
V8_DEPRECATED("Use maybe version",
bool Set(Local<Value> key, Local<Value> value));
/**
* Set only return Just(true) or Empty(), so if it should never fail, use
* result.Check().
*/
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
Local<Value> key, Local<Value> value);

V8_DEPRECATED("Use maybe version",
bool Set(uint32_t index, Local<Value> value));
V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
Local<Value> value);

Expand Down Expand Up @@ -3532,9 +3542,11 @@ class V8_EXPORT Object : public Value {
Local<Context> context, Local<Name> key,
PropertyDescriptor& descriptor); // NOLINT(runtime/references)

V8_DEPRECATED("Use maybe version", Local<Value> Get(Local<Value> key));
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
Local<Value> key);

V8_DEPRECATED("Use maybe version", Local<Value> Get(uint32_t index));
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
uint32_t index);

Expand Down Expand Up @@ -6683,26 +6695,7 @@ V8_INLINE Local<Boolean> 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
Expand All @@ -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.
Expand All @@ -6737,60 +6734,60 @@ 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;
}

/**
* The maximum size of the young generation, which consists of two semi-spaces
* 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.
}

/**
* Deprecated functions. Do not use in new code.
*/
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) {
Expand All @@ -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;
};


Expand Down
78 changes: 46 additions & 32 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,18 @@ namespace v8 {
#define RETURN_ON_FAILED_EXECUTION_PRIMITIVE(T) \
EXCEPTION_BAILOUT_CHECK_SCOPED_DO_NOT_USE(isolate, Nothing<T>())

#define RETURN_TO_LOCAL_UNCHECKED(maybe_local, T) \
return maybe_local.FromMaybe(Local<T>());

#define RETURN_ESCAPED(value) return handle_scope.Escape(value);

namespace {

Local<Context> ContextFromNeverReadOnlySpaceObject(
i::Handle<i::JSReceiver> obj) {
return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
}

class InternalEscapableScope : public v8::EscapableHandleScope {
public:
explicit inline InternalEscapableScope(i::Isolate* isolate)
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -2518,6 +2501,16 @@ bool IsIdentifier(i::Isolate* isolate, i::Handle<i::String> string) {
}
} // anonymous namespace

MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
Local<Context> v8_context, Source* source, size_t arguments_count,
Local<String> arguments[], size_t context_extension_count,
Local<Object> 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<Function> ScriptCompiler::CompileFunctionInContext(
Local<Context> v8_context, Source* source, size_t arguments_count,
Local<String> arguments[], size_t context_extension_count,
Expand Down Expand Up @@ -3988,6 +3981,11 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context,
return Just(true);
}

bool v8::Object::Set(v8::Local<Value> key, v8::Local<Value> value) {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return Set(context, key, value).FromMaybe(false);
}

Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
v8::Local<Value> value) {
auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
Expand All @@ -4001,6 +3999,11 @@ Maybe<bool> v8::Object::Set(v8::Local<v8::Context> context, uint32_t index,
return Just(true);
}

bool v8::Object::Set(uint32_t index, v8::Local<Value> value) {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return Set(context, index, value).FromMaybe(false);
}

Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
v8::Local<Name> key,
v8::Local<Value> value) {
Expand Down Expand Up @@ -4218,6 +4221,11 @@ MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
RETURN_ESCAPED(Utils::ToLocal(result));
}

Local<Value> v8::Object::Get(v8::Local<Value> key) {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(Get(context, key), Value);
}

MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
PREPARE_FOR_EXECUTION(context, Object, Get, Value);
auto self = Utils::OpenHandle(this);
Expand All @@ -4228,6 +4236,11 @@ MaybeLocal<Value> v8::Object::Get(Local<Context> context, uint32_t index) {
RETURN_ESCAPED(Utils::ToLocal(result));
}

Local<Value> v8::Object::Get(uint32_t index) {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(Get(context, index), Value);
}

MaybeLocal<Value> v8::Object::GetPrivate(Local<Context> context,
Local<Private> key) {
return Get(context, Local<Value>(reinterpret_cast<Value*>(*key)));
Expand Down Expand Up @@ -10651,6 +10664,7 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& 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
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/test/unittests/api/resource-constraints-unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace v8 {

/* These tests do not apply on Node 12.
TEST(ResourceConstraints, ConfigureDefaultsFromHeapSizeSmall) {
const size_t KB = static_cast<size_t>(i::KB);
const size_t MB = static_cast<size_t>(i::MB);
Expand Down Expand Up @@ -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<size_t>(i::KB);
Expand Down

0 comments on commit dbb2088

Please sign in to comment.