From 758b730139c50f47de7f975af02e735cbf3f27cd Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 13 Oct 2017 07:28:06 +0200 Subject: [PATCH] deps: revert ABI breaking changes in V8 6.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Below is the list of changes: [ABI] deps: move new PARSER value to end of enum [ABI] deps: revert 749b9c062ea from upstream V8 Original commit message: Remove deprecated allow code-gen callback BUG=chromium:732736 R=marja@chromium.org Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I2c0a96b76ae977e53a418d22175bcc487f548786 Reviewed-on: https://chromium-review.googlesource.com/543238 Reviewed-by: Marja Hölttä Commit-Queue: Jochen Eisinger Cr-Commit-Position: refs/heads/master@{#47509} [ABI] deps: reorder InstanceType enum for ABI compat [ABI] deps: restore HeapProfiler::GetProfilerMemorySize() Reimplemented as a method returning 0. [ABI] deps: partially revert a5f321cd9bf Remove default arguments from `Context::SetDefaultContext()` and `Context::New()`. Refs: https://github.com/v8/v8/commit/a5f321cd9bf [ABI] deps: revert change to ComputeMaxSemiSpaceSize Refs: https://github.com/v8/v8/commit/2178bbaf3f2b71093ceb3885e524c076f9d827cd PR-URL: https://github.com/nodejs/node/pull/16413 --- deps/v8/include/v8-profiler.h | 3 + deps/v8/include/v8.h | 42 ++-- deps/v8/src/api.cc | 22 +- deps/v8/src/heap/heap.h | 2 +- deps/v8/src/objects.h | 8 +- deps/v8/test/cctest/test-serialize.cc | 293 +++----------------------- deps/v8/tools/tickprocessor.js | 12 +- 7 files changed, 86 insertions(+), 296 deletions(-) diff --git a/deps/v8/include/v8-profiler.h b/deps/v8/include/v8-profiler.h index 621ca8b215762d..2363f0514778f0 100644 --- a/deps/v8/include/v8-profiler.h +++ b/deps/v8/include/v8-profiler.h @@ -809,6 +809,9 @@ class V8_EXPORT HeapProfiler { */ static const uint16_t kPersistentHandleNoClassId = 0; + /** Returns memory used for profiler internal data and snapshots. */ + size_t GetProfilerMemorySize(); + private: HeapProfiler(); ~HeapProfiler(); diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index b183d4342fcbcf..a7c1f088ddaae0 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1729,12 +1729,12 @@ class V8_EXPORT StackFrame { enum StateTag { JS, GC, - PARSER, - BYTECODE_COMPILER, COMPILER, OTHER, EXTERNAL, - IDLE + IDLE, + PARSER, + BYTECODE_COMPILER }; // A RegisterState represents the current state of registers used @@ -6348,6 +6348,8 @@ typedef void (*FailedAccessCheckCallback)(Local target, * Callback to check if code generation from strings is allowed. See * Context::AllowCodeGenerationFromStrings. */ +typedef bool (*DeprecatedAllowCodeGenerationFromStringsCallback)( + Local context); typedef bool (*AllowCodeGenerationFromStringsCallback)(Local context, Local source); @@ -7636,6 +7638,9 @@ class V8_EXPORT Isolate { */ void SetAllowCodeGenerationFromStringsCallback( AllowCodeGenerationFromStringsCallback callback); + V8_DEPRECATED("Use callback with source parameter.", + void SetAllowCodeGenerationFromStringsCallback( + DeprecatedAllowCodeGenerationFromStringsCallback callback)); /** * Embedder over{ride|load} injection points for wasm APIs. The expectation @@ -7796,6 +7801,15 @@ class V8_EXPORT V8 { "Use isolate version", void SetFatalErrorHandler(FatalErrorCallback that)); + /** + * Set the callback to invoke to check if code generation from + * strings should be allowed. + */ + V8_INLINE static V8_DEPRECATED( + "Use isolate version", + void SetAllowCodeGenerationFromStringsCallback( + DeprecatedAllowCodeGenerationFromStringsCallback that)); + /** * Check if V8 is dead and therefore unusable. This is the case after * fatal errors such as out-of-memory situations. @@ -8205,12 +8219,8 @@ class V8_EXPORT SnapshotCreator { * Set the default context to be included in the snapshot blob. * The snapshot will not contain the global proxy, and we expect one or a * global object template to create one, to be provided upon deserialization. - * - * \param callback optional callback to serialize internal fields. */ - void SetDefaultContext(Local context, - SerializeInternalFieldsCallback callback = - SerializeInternalFieldsCallback()); + void SetDefaultContext(Local context); /** * Add additional context to be included in the snapshot blob. @@ -8562,9 +8572,7 @@ class V8_EXPORT Context { static Local New( Isolate* isolate, ExtensionConfiguration* extensions = NULL, MaybeLocal global_template = MaybeLocal(), - MaybeLocal global_object = MaybeLocal(), - DeserializeInternalFieldsCallback internal_fields_deserializer = - DeserializeInternalFieldsCallback()); + MaybeLocal global_object = MaybeLocal()); /** * Create a new context from a (non-default) context snapshot. There @@ -9021,8 +9029,8 @@ class Internals { static const int kNodeIsIndependentShift = 3; static const int kNodeIsActiveShift = 4; - static const int kJSApiObjectType = 0xbd; - static const int kJSObjectType = 0xbe; + static const int kJSApiObjectType = 0xbb; + static const int kJSObjectType = 0xbc; static const int kFirstNonstringType = 0x80; static const int kOddballType = 0x82; static const int kForeignType = 0x86; @@ -10275,6 +10283,14 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) { #endif } +void V8::SetAllowCodeGenerationFromStringsCallback( + DeprecatedAllowCodeGenerationFromStringsCallback callback) { + Isolate* isolate = Isolate::GetCurrent(); + isolate->SetAllowCodeGenerationFromStringsCallback( + reinterpret_cast(callback)); +} + + bool V8::IsDead() { Isolate* isolate = Isolate::GetCurrent(); return isolate->IsDead(); diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 7f819872fa90c2..4ed46ebe431e3b 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -597,8 +597,7 @@ Isolate* SnapshotCreator::GetIsolate() { return SnapshotCreatorData::cast(data_)->isolate_; } -void SnapshotCreator::SetDefaultContext( - Local context, SerializeInternalFieldsCallback callback) { +void SnapshotCreator::SetDefaultContext(Local context) { DCHECK(!context.IsEmpty()); SnapshotCreatorData* data = SnapshotCreatorData::cast(data_); DCHECK(!data->created_); @@ -606,7 +605,8 @@ void SnapshotCreator::SetDefaultContext( Isolate* isolate = data->isolate_; CHECK_EQ(isolate, context->GetIsolate()); data->default_context_.Reset(isolate, context); - data->default_embedder_fields_serializer_ = callback; + data->default_embedder_fields_serializer_ = + v8::SerializeInternalFieldsCallback(); } size_t SnapshotCreator::AddContext(Local context, @@ -6559,10 +6559,9 @@ Local NewContext( Local v8::Context::New( v8::Isolate* external_isolate, v8::ExtensionConfiguration* extensions, v8::MaybeLocal global_template, - v8::MaybeLocal global_object, - DeserializeInternalFieldsCallback internal_fields_deserializer) { + v8::MaybeLocal global_object) { return NewContext(external_isolate, extensions, global_template, - global_object, 0, internal_fields_deserializer); + global_object, 0, v8::DeserializeInternalFieldsCallback()); } MaybeLocal v8::Context::FromSnapshot( @@ -9052,6 +9051,13 @@ void Isolate::SetAllowCodeGenerationFromStringsCallback( isolate->set_allow_code_gen_callback(callback); } +void Isolate::SetAllowCodeGenerationFromStringsCallback( + DeprecatedAllowCodeGenerationFromStringsCallback callback) { + i::Isolate* isolate = reinterpret_cast(this); + isolate->set_allow_code_gen_callback( + reinterpret_cast(callback)); +} + #define CALLBACK_SETTER(ExternalName, Type, InternalName) \ void Isolate::Set##ExternalName(Type callback) { \ i::Isolate* isolate = reinterpret_cast(this); \ @@ -10509,6 +10515,10 @@ void HeapProfiler::SetGetRetainerInfosCallback( callback); } +size_t HeapProfiler::GetProfilerMemorySize() { + return 0; +} + v8::Testing::StressType internal::Testing::stress_type_ = v8::Testing::kStressTypeOpt; diff --git a/deps/v8/src/heap/heap.h b/deps/v8/src/heap/heap.h index 7b877703855c88..c79a4b01238313 100644 --- a/deps/v8/src/heap/heap.h +++ b/deps/v8/src/heap/heap.h @@ -1303,7 +1303,7 @@ class Heap { static size_t ComputeMaxSemiSpaceSize(uint64_t physical_memory) { const uint64_t min_physical_memory = 512 * MB; - const uint64_t max_physical_memory = 3 * static_cast(GB); + const uint64_t max_physical_memory = 2 * static_cast(GB); uint64_t capped_physical_memory = Max(Min(physical_memory, max_physical_memory), min_physical_memory); diff --git a/deps/v8/src/objects.h b/deps/v8/src/objects.h index a5acf7c6c4f3d4..f9987c2837c466 100644 --- a/deps/v8/src/objects.h +++ b/deps/v8/src/objects.h @@ -384,10 +384,10 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1; V(JS_MODULE_NAMESPACE_TYPE) \ V(JS_SPECIAL_API_OBJECT_TYPE) \ V(JS_VALUE_TYPE) \ - V(JS_MESSAGE_OBJECT_TYPE) \ - V(JS_DATE_TYPE) \ V(JS_API_OBJECT_TYPE) \ V(JS_OBJECT_TYPE) \ + V(JS_MESSAGE_OBJECT_TYPE) \ + V(JS_DATE_TYPE) \ V(JS_ARGUMENTS_TYPE) \ V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ V(JS_GENERATOR_OBJECT_TYPE) \ @@ -741,11 +741,11 @@ enum InstanceType : uint8_t { // interceptors. JS_SPECIAL_API_OBJECT_TYPE, // LAST_SPECIAL_RECEIVER_TYPE JS_VALUE_TYPE, // LAST_CUSTOM_ELEMENTS_RECEIVER - JS_MESSAGE_OBJECT_TYPE, - JS_DATE_TYPE, // Like JS_OBJECT_TYPE, but created from API function. JS_API_OBJECT_TYPE, JS_OBJECT_TYPE, + JS_MESSAGE_OBJECT_TYPE, + JS_DATE_TYPE, JS_ARGUMENTS_TYPE, JS_CONTEXT_EXTENSION_OBJECT_TYPE, JS_GENERATOR_OBJECT_TYPE, diff --git a/deps/v8/test/cctest/test-serialize.cc b/deps/v8/test/cctest/test-serialize.cc index 7c83f9ad497ad3..d3bb7a099cd701 100644 --- a/deps/v8/test/cctest/test-serialize.cc +++ b/deps/v8/test/cctest/test-serialize.cc @@ -588,272 +588,6 @@ TEST(CustomSnapshotDataBlob1) { isolate1->Dispose(); } -struct InternalFieldData { - uint32_t data; -}; - -v8::StartupData SerializeInternalFields(v8::Local holder, int index, - void* data) { - CHECK_EQ(reinterpret_cast(2016), data); - InternalFieldData* embedder_field = static_cast( - holder->GetAlignedPointerFromInternalField(index)); - if (embedder_field == nullptr) return {nullptr, 0}; - int size = sizeof(*embedder_field); - char* payload = new char[size]; - // We simply use memcpy to serialize the content. - memcpy(payload, embedder_field, size); - return {payload, size}; -} - -std::vector deserialized_data; - -void DeserializeInternalFields(v8::Local holder, int index, - v8::StartupData payload, void* data) { - if (payload.raw_size == 0) { - holder->SetAlignedPointerInInternalField(index, nullptr); - return; - } - CHECK_EQ(reinterpret_cast(2017), data); - InternalFieldData* embedder_field = new InternalFieldData{0}; - memcpy(embedder_field, payload.data, payload.raw_size); - holder->SetAlignedPointerInInternalField(index, embedder_field); - deserialized_data.push_back(embedder_field); -} - -typedef std::vector> Int32Expectations; - -void TestInt32Expectations(const Int32Expectations& expectations) { - for (const auto& e : expectations) { - ExpectInt32(std::get<0>(e), std::get<1>(e)); - } -} - -void TypedArrayTestHelper(const char* code, - const Int32Expectations& expectations) { - DisableAlwaysOpt(); - i::FLAG_allow_natives_syntax = true; - v8::StartupData blob; - { - v8::SnapshotCreator creator; - v8::Isolate* isolate = creator.GetIsolate(); - { - v8::HandleScope handle_scope(isolate); - v8::Local context = v8::Context::New(isolate); - v8::Context::Scope context_scope(context); - - CompileRun(code); - TestInt32Expectations(expectations); - creator.SetDefaultContext( - context, v8::SerializeInternalFieldsCallback( - SerializeInternalFields, reinterpret_cast(2016))); - } - blob = - creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); - } - - v8::Isolate::CreateParams create_params; - create_params.snapshot_blob = &blob; - create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = TestIsolate::New(create_params); - { - v8::Isolate::Scope i_scope(isolate); - v8::HandleScope h_scope(isolate); - v8::Local context = v8::Context::New( - isolate, NULL, v8::MaybeLocal(), - v8::MaybeLocal(), - v8::DeserializeInternalFieldsCallback(DeserializeInternalFields, - reinterpret_cast(2017))); - delete[] blob.data; // We can dispose of the snapshot blob now. - CHECK(deserialized_data.empty()); // We do not expect any embedder data. - v8::Context::Scope c_scope(context); - TestInt32Expectations(expectations); - } - isolate->Dispose(); -} - -TEST(CustomSnapshotDataBlobWithOffHeapTypedArray) { - const char* code = - "var x = new Uint8Array(128);" - "x[0] = 12;" - "var arr = new Array(17);" - "arr[1] = 24;" - "var y = new Uint32Array(arr);" - "var buffer = new ArrayBuffer(128);" - "var z = new Int16Array(buffer);" - "z[0] = 48;"; - Int32Expectations expectations = {std::make_tuple("x[0]", 12), - std::make_tuple("y[1]", 24), - std::make_tuple("z[0]", 48)}; - - TypedArrayTestHelper(code, expectations); -} - -TEST(CustomSnapshotDataBlobSharedArrayBuffer) { - const char* code = - "var x = new Int32Array([12, 24, 48, 96]);" - "var y = new Uint8Array(x.buffer)"; - Int32Expectations expectations = { - std::make_tuple("x[0]", 12), - std::make_tuple("x[1]", 24), -#if !V8_TARGET_BIG_ENDIAN - std::make_tuple("y[0]", 12), - std::make_tuple("y[1]", 0), - std::make_tuple("y[2]", 0), - std::make_tuple("y[3]", 0), - std::make_tuple("y[4]", 24) -#else - std::make_tuple("y[3]", 12), - std::make_tuple("y[2]", 0), - std::make_tuple("y[1]", 0), - std::make_tuple("y[0]", 0), - std::make_tuple("y[7]", 24) -#endif - }; - - TypedArrayTestHelper(code, expectations); -} - -TEST(CustomSnapshotDataBlobDataView) { - const char* code = - "var x = new Int8Array([1, 2, 3, 4]);" - "var v = new DataView(x.buffer)"; - Int32Expectations expectations = {std::make_tuple("v.getInt8(0)", 1), - std::make_tuple("v.getInt8(1)", 2), - std::make_tuple("v.getInt16(0)", 258), - std::make_tuple("v.getInt16(1)", 515)}; - - TypedArrayTestHelper(code, expectations); -} - -TEST(CustomSnapshotDataBlobNeuteredArrayBuffer) { - const char* code = - "var x = new Int16Array([12, 24, 48]);" - "%ArrayBufferNeuter(x.buffer);"; - Int32Expectations expectations = {std::make_tuple("x.buffer.byteLength", 0), - std::make_tuple("x.length", 0)}; - - DisableAlwaysOpt(); - i::FLAG_allow_natives_syntax = true; - v8::StartupData blob; - { - v8::SnapshotCreator creator; - v8::Isolate* isolate = creator.GetIsolate(); - { - v8::HandleScope handle_scope(isolate); - v8::Local context = v8::Context::New(isolate); - v8::Context::Scope context_scope(context); - - CompileRun(code); - TestInt32Expectations(expectations); - creator.SetDefaultContext( - context, v8::SerializeInternalFieldsCallback( - SerializeInternalFields, reinterpret_cast(2016))); - } - blob = - creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); - } - - v8::Isolate::CreateParams create_params; - create_params.snapshot_blob = &blob; - create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = TestIsolate::New(create_params); - { - v8::Isolate::Scope i_scope(isolate); - v8::HandleScope h_scope(isolate); - v8::Local context = v8::Context::New( - isolate, NULL, v8::MaybeLocal(), - v8::MaybeLocal(), - v8::DeserializeInternalFieldsCallback(DeserializeInternalFields, - reinterpret_cast(2017))); - delete[] blob.data; // We can dispose of the snapshot blob now. - v8::Context::Scope c_scope(context); - TestInt32Expectations(expectations); - - v8::Local x = CompileRun("x"); - CHECK(x->IsTypedArray()); - i::Handle array = - i::Handle::cast(v8::Utils::OpenHandle(*x)); - CHECK(array->WasNeutered()); - CHECK_NULL( - FixedTypedArrayBase::cast(array->elements())->external_pointer()); - } - isolate->Dispose(); -} - -i::Handle GetBufferFromTypedArray( - v8::Local typed_array) { - CHECK(typed_array->IsTypedArray()); - - i::Handle view = i::Handle::cast( - v8::Utils::OpenHandle(*typed_array)); - - return i::handle(i::JSArrayBuffer::cast(view->buffer())); -} - -TEST(CustomSnapshotDataBlobOnOrOffHeapTypedArray) { - const char* code = - "var x = new Uint8Array(8);" - "x[0] = 12;" - "x[7] = 24;" - "var y = new Int16Array([12, 24, 48]);" - "var z = new Int32Array(64);" - "z[0] = 96;"; - Int32Expectations expectations = { - std::make_tuple("x[0]", 12), std::make_tuple("x[7]", 24), - std::make_tuple("y[2]", 48), std::make_tuple("z[0]", 96)}; - - DisableAlwaysOpt(); - i::FLAG_allow_natives_syntax = true; - v8::StartupData blob; - { - v8::SnapshotCreator creator; - v8::Isolate* isolate = creator.GetIsolate(); - { - v8::HandleScope handle_scope(isolate); - v8::Local context = v8::Context::New(isolate); - v8::Context::Scope context_scope(context); - - CompileRun(code); - TestInt32Expectations(expectations); - creator.SetDefaultContext( - context, v8::SerializeInternalFieldsCallback( - SerializeInternalFields, reinterpret_cast(2016))); - } - blob = - creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); - } - - v8::Isolate::CreateParams create_params; - create_params.snapshot_blob = &blob; - create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = TestIsolate::New(create_params); - { - v8::Isolate::Scope i_scope(isolate); - v8::HandleScope h_scope(isolate); - v8::Local context = v8::Context::New( - isolate, NULL, v8::MaybeLocal(), - v8::MaybeLocal(), - v8::DeserializeInternalFieldsCallback(DeserializeInternalFields, - reinterpret_cast(2017))); - delete[] blob.data; // We can dispose of the snapshot blob now. - v8::Context::Scope c_scope(context); - TestInt32Expectations(expectations); - - i::Handle buffer = - GetBufferFromTypedArray(CompileRun("x")); - // The resulting buffer should be on-heap. - CHECK_NULL(buffer->backing_store()); - - buffer = GetBufferFromTypedArray(CompileRun("y")); - CHECK_NULL(buffer->backing_store()); - - buffer = GetBufferFromTypedArray(CompileRun("z")); - // The resulting buffer should be off-heap. - CHECK_NOT_NULL(buffer->backing_store()); - } - isolate->Dispose(); -} - TEST(CustomSnapshotDataBlob2) { DisableAlwaysOpt(); const char* source2 = @@ -2313,6 +2047,33 @@ TEST(SnapshotCreatorUnknownExternalReferences) { delete[] blob.data; } +struct InternalFieldData { + uint32_t data; +}; + +v8::StartupData SerializeInternalFields(v8::Local holder, int index, + void* data) { + CHECK_EQ(reinterpret_cast(2016), data); + InternalFieldData* embedder_field = static_cast( + holder->GetAlignedPointerFromInternalField(index)); + int size = sizeof(*embedder_field); + char* payload = new char[size]; + // We simply use memcpy to serialize the content. + memcpy(payload, embedder_field, size); + return {payload, size}; +} + +std::vector deserialized_data; + +void DeserializeInternalFields(v8::Local holder, int index, + v8::StartupData payload, void* data) { + CHECK_EQ(reinterpret_cast(2017), data); + InternalFieldData* embedder_field = new InternalFieldData{0}; + memcpy(embedder_field, payload.data, payload.raw_size); + holder->SetAlignedPointerInInternalField(index, embedder_field); + deserialized_data.push_back(embedder_field); +} + TEST(SnapshotCreatorTemplates) { DisableAlwaysOpt(); v8::StartupData blob; diff --git a/deps/v8/tools/tickprocessor.js b/deps/v8/tools/tickprocessor.js index 51e6dabf493c96..1d517f6d4423e9 100644 --- a/deps/v8/tools/tickprocessor.js +++ b/deps/v8/tools/tickprocessor.js @@ -216,12 +216,12 @@ inherits(TickProcessor, LogReader); TickProcessor.VmStates = { JS: 0, GC: 1, - PARSER: 2, - BYTECODE_COMPILER: 3, - COMPILER: 4, - OTHER: 5, - EXTERNAL: 6, - IDLE: 7, + COMPILER: 2, + OTHER: 3, + EXTERNAL: 4, + IDLE: 5, + PARSER: 6, + BYTECODE_COMPILER: 7, };