diff options
author | Michaël Zasso <targos@protonmail.com> | 2018-09-07 17:07:13 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-09-07 20:59:13 +0200 |
commit | 586db2414a338e1bf6eaf6e672a3adc7ce309f6a (patch) | |
tree | 139fa972aef648481ddee22a3a85b99707d28df5 /deps/v8/test/cctest/test-serialize.cc | |
parent | 12ed7c94e5160aa6d38e3d2cb2a73dae0a6f9342 (diff) | |
download | android-node-v8-586db2414a338e1bf6eaf6e672a3adc7ce309f6a.tar.gz android-node-v8-586db2414a338e1bf6eaf6e672a3adc7ce309f6a.tar.bz2 android-node-v8-586db2414a338e1bf6eaf6e672a3adc7ce309f6a.zip |
deps: update V8 to 6.9.427.22
PR-URL: https://github.com/nodejs/node/pull/21983
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'deps/v8/test/cctest/test-serialize.cc')
-rw-r--r-- | deps/v8/test/cctest/test-serialize.cc | 273 |
1 files changed, 191 insertions, 82 deletions
diff --git a/deps/v8/test/cctest/test-serialize.cc b/deps/v8/test/cctest/test-serialize.cc index c26a7e7348..8a2fe60b11 100644 --- a/deps/v8/test/cctest/test-serialize.cc +++ b/deps/v8/test/cctest/test-serialize.cc @@ -75,9 +75,10 @@ void DisableAlwaysOpt() { // TestIsolate is used for testing isolate serialization. class TestIsolate : public Isolate { public: - static v8::Isolate* NewInitialized(bool enable_serializer) { - i::Isolate* isolate = new TestIsolate(enable_serializer); - isolate->setup_delegate_ = new SetupIsolateDelegateForTests(true); + static v8::Isolate* NewInitialized() { + const bool kEnableSerializer = true; + const bool kGenerateHeap = true; + i::Isolate* isolate = new TestIsolate(kEnableSerializer, kGenerateHeap); v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate::Scope isolate_scope(v8_isolate); isolate->Init(nullptr); @@ -88,23 +89,37 @@ class TestIsolate : public Isolate { // Allows flexibility to bootstrap with or without snapshot even when // the production Isolate class has one or the other behavior baked in. static v8::Isolate* New(const v8::Isolate::CreateParams& params) { - i::Isolate* isolate = new TestIsolate(false); - bool create_heap_objects = params.snapshot_blob == nullptr; - isolate->setup_delegate_ = - new SetupIsolateDelegateForTests(create_heap_objects); + const bool kEnableSerializer = false; + const bool kGenerateHeap = params.snapshot_blob == nullptr; + i::Isolate* isolate = new TestIsolate(kEnableSerializer, kGenerateHeap); v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate::Initialize(v8_isolate, params); return v8_isolate; } - explicit TestIsolate(bool with_serializer) : Isolate() { + explicit TestIsolate(bool with_serializer, bool generate_heap) : Isolate() { if (with_serializer) enable_serializer(); set_array_buffer_allocator(CcTest::array_buffer_allocator()); + setup_delegate_ = new SetupIsolateDelegateForTests(generate_heap); + + if (FLAG_embedded_builtins) { + if (generate_heap || clear_embedded_blob_) { + // We're generating the heap, including new builtins. Act as if we don't + // have an embedded blob. + clear_embedded_blob_ = true; + SetEmbeddedBlob(nullptr, 0); + } + } } - void SetDeserializeFromSnapshot() { - setup_delegate_ = new SetupIsolateDelegateForTests(false); - } + + private: + // A sticky flag that ensures the embedded blob is remains cleared after it + // has been cleared once. E.g.: after creating & serializing a complete heap + // snapshot, future isolates also expect the embedded blob to be cleared. + static bool clear_embedded_blob_; }; +bool TestIsolate::clear_embedded_blob_ = false; + static Vector<const byte> WritePayload(const Vector<const byte>& payload) { int length = payload.length(); byte* blob = NewArray<byte>(length); @@ -256,10 +271,11 @@ v8::Isolate* InitializeFromBlob(StartupBlobs& blobs) { SnapshotData startup_snapshot(blobs.startup); BuiltinSnapshotData builtin_snapshot(blobs.builtin); StartupDeserializer deserializer(&startup_snapshot, &builtin_snapshot); - TestIsolate* isolate = new TestIsolate(false); + const bool kEnableSerializer = false; + const bool kGenerateHeap = false; + TestIsolate* isolate = new TestIsolate(kEnableSerializer, kGenerateHeap); v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate::Scope isolate_scope(v8_isolate); - isolate->SetDeserializeFromSnapshot(); isolate->Init(&deserializer); } return v8_isolate; @@ -283,10 +299,8 @@ static void SanityCheck(v8::Isolate* v8_isolate) { isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); } -UNINITIALIZED_TEST(StartupSerializerOnce) { - DisableLazyDeserialization(); - DisableAlwaysOpt(); - v8::Isolate* isolate = TestIsolate::NewInitialized(true); +void TestStartupSerializerOnceImpl() { + v8::Isolate* isolate = TestIsolate::NewInitialized(); StartupBlobs blobs = Serialize(isolate); isolate->Dispose(); isolate = Deserialize(blobs); @@ -303,6 +317,47 @@ UNINITIALIZED_TEST(StartupSerializerOnce) { blobs.Dispose(); } +UNINITIALIZED_TEST(StartupSerializerOnce) { + DisableLazyDeserialization(); + DisableAlwaysOpt(); + TestStartupSerializerOnceImpl(); +} + +UNINITIALIZED_TEST(StartupSerializerOnce1) { + DisableLazyDeserialization(); + DisableAlwaysOpt(); + FLAG_serialization_chunk_size = 1; + TestStartupSerializerOnceImpl(); +} + +UNINITIALIZED_TEST(StartupSerializerOnce32) { + DisableLazyDeserialization(); + DisableAlwaysOpt(); + FLAG_serialization_chunk_size = 32; + TestStartupSerializerOnceImpl(); +} + +UNINITIALIZED_TEST(StartupSerializerOnce1K) { + DisableLazyDeserialization(); + DisableAlwaysOpt(); + FLAG_serialization_chunk_size = 1 * KB; + TestStartupSerializerOnceImpl(); +} + +UNINITIALIZED_TEST(StartupSerializerOnce4K) { + DisableLazyDeserialization(); + DisableAlwaysOpt(); + FLAG_serialization_chunk_size = 4 * KB; + TestStartupSerializerOnceImpl(); +} + +UNINITIALIZED_TEST(StartupSerializerOnce32K) { + DisableLazyDeserialization(); + DisableAlwaysOpt(); + FLAG_serialization_chunk_size = 32 * KB; + TestStartupSerializerOnceImpl(); +} + UNINITIALIZED_TEST(StartupSerializerRootMapDependencies) { DisableAlwaysOpt(); v8::SnapshotCreator snapshot_creator; @@ -324,8 +379,9 @@ UNINITIALIZED_TEST(StartupSerializerRootMapDependencies) { // platforms. So, without special measures we're risking to serialize // object, requiring alignment before FreeSpaceMap is fully serialized. v8::internal::Handle<Map> map( - internal_isolate->heap()->one_byte_internalized_string_map()); - Map::WeakCellForMap(map); + ReadOnlyRoots(internal_isolate).one_byte_internalized_string_map(), + internal_isolate); + Map::WeakCellForMap(internal_isolate, map); // Need to avoid DCHECKs inside SnapshotCreator. snapshot_creator.SetDefaultContext(v8::Context::New(isolate)); } @@ -354,7 +410,7 @@ UNINITIALIZED_TEST(StartupSerializerRootMapDependencies) { UNINITIALIZED_TEST(StartupSerializerTwice) { DisableLazyDeserialization(); DisableAlwaysOpt(); - v8::Isolate* isolate = TestIsolate::NewInitialized(true); + v8::Isolate* isolate = TestIsolate::NewInitialized(); StartupBlobs blobs1 = Serialize(isolate); StartupBlobs blobs2 = Serialize(isolate); isolate->Dispose(); @@ -376,7 +432,7 @@ UNINITIALIZED_TEST(StartupSerializerTwice) { UNINITIALIZED_TEST(StartupSerializerOnceRunScript) { DisableLazyDeserialization(); DisableAlwaysOpt(); - v8::Isolate* isolate = TestIsolate::NewInitialized(true); + v8::Isolate* isolate = TestIsolate::NewInitialized(); StartupBlobs blobs = Serialize(isolate); isolate->Dispose(); isolate = Deserialize(blobs); @@ -402,7 +458,7 @@ UNINITIALIZED_TEST(StartupSerializerOnceRunScript) { UNINITIALIZED_TEST(StartupSerializerTwiceRunScript) { DisableLazyDeserialization(); DisableAlwaysOpt(); - v8::Isolate* isolate = TestIsolate::NewInitialized(true); + v8::Isolate* isolate = TestIsolate::NewInitialized(); StartupBlobs blobs1 = Serialize(isolate); StartupBlobs blobs2 = Serialize(isolate); isolate->Dispose(); @@ -429,7 +485,7 @@ UNINITIALIZED_TEST(StartupSerializerTwiceRunScript) { static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, Vector<const byte>* builtin_blob_out, Vector<const byte>* partial_blob_out) { - v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); + v8::Isolate* v8_isolate = TestIsolate::NewInitialized(); Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); Heap* heap = isolate->heap(); { @@ -533,7 +589,7 @@ UNINITIALIZED_TEST(PartialSerializerContext) { static void PartiallySerializeCustomContext( Vector<const byte>* startup_blob_out, Vector<const byte>* builtin_blob_out, Vector<const byte>* partial_blob_out) { - v8::Isolate* v8_isolate = TestIsolate::NewInitialized(true); + v8::Isolate* v8_isolate = TestIsolate::NewInitialized(); Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); { v8::Isolate::Scope isolate_scope(v8_isolate); @@ -953,7 +1009,7 @@ i::Handle<i::JSArrayBuffer> GetBufferFromTypedArray( i::Handle<i::JSArrayBufferView> view = i::Handle<i::JSArrayBufferView>::cast( v8::Utils::OpenHandle(*typed_array)); - return i::handle(i::JSArrayBuffer::cast(view->buffer())); + return i::handle(i::JSArrayBuffer::cast(view->buffer()), view->GetIsolate()); } TEST(CustomSnapshotDataBlobOnOrOffHeapTypedArray) { @@ -1245,7 +1301,7 @@ TEST(CustomSnapshotDataBlobWithWarmup) { CHECK(IsCompiled("Math.abs")); CHECK(!IsCompiled("g")); CHECK(IsCompiled("String.raw")); - CHECK(!IsCompiled("Array.prototype.sort")); + CHECK(!IsCompiled("Array.prototype.lastIndexOf")); CHECK_EQ(5, CompileRun("a")->Int32Value(context).FromJust()); } isolate->Dispose(); @@ -1333,7 +1389,7 @@ static Handle<SharedFunctionInfo> CompileScriptAndProduceCache( return sfi; } -TEST(CodeSerializerOnePlusOne) { +void TestCodeSerializerOnePlusOneImpl() { LocalContext context; Isolate* isolate = CcTest::i_isolate(); isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. @@ -1372,7 +1428,7 @@ TEST(CodeSerializerOnePlusOne) { Handle<JSFunction> copy_fun = isolate->factory()->NewFunctionFromSharedFunctionInfo( copy, isolate->native_context()); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); Handle<Object> copy_result = Execution::Call(isolate, copy_fun, global, 0, nullptr).ToHandleChecked(); CHECK_EQ(2, Handle<Smi>::cast(copy_result)->value()); @@ -1382,6 +1438,23 @@ TEST(CodeSerializerOnePlusOne) { delete cache; } +TEST(CodeSerializerOnePlusOne) { TestCodeSerializerOnePlusOneImpl(); } + +TEST(CodeSerializerOnePlusOne1) { + FLAG_serialization_chunk_size = 1; + TestCodeSerializerOnePlusOneImpl(); +} + +TEST(CodeSerializerOnePlusOne32) { + FLAG_serialization_chunk_size = 32; + TestCodeSerializerOnePlusOneImpl(); +} + +TEST(CodeSerializerOnePlusOne4K) { + FLAG_serialization_chunk_size = 4 * KB; + TestCodeSerializerOnePlusOneImpl(); +} + TEST(CodeSerializerPromotedToCompilationCache) { LocalContext context; Isolate* isolate = CcTest::i_isolate(); @@ -1430,7 +1503,7 @@ TEST(CodeSerializerInternalizedString) { CHECK(!orig_source.is_identical_to(copy_source)); CHECK(orig_source->Equals(*copy_source)); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); i::ScriptData* script_data = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1489,7 +1562,7 @@ TEST(CodeSerializerLargeCodeObject) { Handle<String> source_str = isolate->factory()->NewStringFromOneByte(source).ToHandleChecked(); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1555,7 +1628,7 @@ TEST(CodeSerializerLargeCodeObjectWithIncrementalMarking) { ec_page = Page::FromAddress(moving_object->address()); } - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1618,7 +1691,7 @@ TEST(CodeSerializerLargeStrings) { f->NewStringFromOneByte(source_t).ToHandleChecked()) .ToHandleChecked(); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1686,7 +1759,7 @@ TEST(CodeSerializerThreeBigStrings) { f->NewConsString(source_a_str, source_b_str).ToHandleChecked(), source_c_str).ToHandleChecked(); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1804,7 +1877,7 @@ TEST(CodeSerializerExternalString) { ->NewStringFromUtf8(CStrVector(source)) .ToHandleChecked(); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1828,6 +1901,11 @@ TEST(CodeSerializerExternalString) { CHECK_EQ(15.0, copy_result->Number()); + // This avoids the GC from trying to free stack allocated resources. + i::Handle<i::ExternalOneByteString>::cast(one_byte_string) + ->set_resource(nullptr); + i::Handle<i::ExternalTwoByteString>::cast(two_byte_string) + ->set_resource(nullptr); delete cache; } @@ -1861,7 +1939,7 @@ TEST(CodeSerializerLargeExternalString) { f->NewConsString(f->NewStringFromAsciiChecked(" = 42; "), name) .ToHandleChecked()).ToHandleChecked(); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = CompileScriptAndProduceCache( @@ -1884,6 +1962,8 @@ TEST(CodeSerializerLargeExternalString) { CHECK_EQ(42.0, copy_result->Number()); + // This avoids the GC from trying to free stack allocated resources. + i::Handle<i::ExternalOneByteString>::cast(name)->set_resource(nullptr); delete cache; string.Dispose(); } @@ -1910,7 +1990,7 @@ TEST(CodeSerializerExternalScriptName) { CHECK(name->IsExternalOneByteString()); CHECK(!name->IsInternalizedString()); - Handle<JSObject> global(isolate->context()->global_object()); + Handle<JSObject> global(isolate->context()->global_object(), isolate); ScriptData* cache = nullptr; Handle<SharedFunctionInfo> orig = @@ -1933,6 +2013,8 @@ TEST(CodeSerializerExternalScriptName) { CHECK_EQ(10.0, copy_result->Number()); + // This avoids the GC from trying to free stack allocated resources. + i::Handle<i::ExternalOneByteString>::cast(name)->set_resource(nullptr); delete cache; } @@ -2001,8 +2083,8 @@ v8::ScriptCompiler::CachedData* CompileRunAndProduceCache( void CheckDeserializedFlag(v8::Local<v8::UnboundScript> script) { i::Handle<i::SharedFunctionInfo> sfi = v8::Utils::OpenHandle(*script); - i::Handle<i::Script> i_script(Script::cast(sfi->script())); - i::SharedFunctionInfo::ScriptIterator iterator(i_script); + i::SharedFunctionInfo::ScriptIterator iterator(sfi->GetIsolate(), + Script::cast(sfi->script())); while (SharedFunctionInfo* next = iterator.Next()) { CHECK_EQ(next->is_compiled(), next->deserialized()); } @@ -2401,26 +2483,6 @@ static void AccessorForSerialization( info.GetReturnValue().Set(v8_num(2017)); } -class SerializedExtension : public v8::Extension { - public: - SerializedExtension() - : v8::Extension("serialized extension", - "native function g();" - "function h() { return 13; };" - "function i() { return 14; };" - "var o = { p: 7 };") {} - - virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( - v8::Isolate* isolate, v8::Local<v8::String> name) { - CHECK(name->Equals(isolate->GetCurrentContext(), v8_str("g")).FromJust()); - return v8::FunctionTemplate::New(isolate, FunctionCallback); - } - - static void FunctionCallback( - const v8::FunctionCallbackInfo<v8::Value>& args) { - args.GetReturnValue().Set(v8_num(12)); - } -}; static SerializerOneByteResource serializable_one_byte_resource("one_byte", 8); static SerializerTwoByteResource serializable_two_byte_resource("two_byte", 8); @@ -2430,7 +2492,6 @@ intptr_t original_external_references[] = { reinterpret_cast<intptr_t>(&serialized_static_field), reinterpret_cast<intptr_t>(&NamedPropertyGetterForSerialization), reinterpret_cast<intptr_t>(&AccessorForSerialization), - reinterpret_cast<intptr_t>(&SerializedExtension::FunctionCallback), reinterpret_cast<intptr_t>(&serialized_static_field), // duplicate entry reinterpret_cast<intptr_t>(&serializable_one_byte_resource), reinterpret_cast<intptr_t>(&serializable_two_byte_resource), @@ -2441,7 +2502,6 @@ intptr_t replaced_external_references[] = { reinterpret_cast<intptr_t>(&serialized_static_field), reinterpret_cast<intptr_t>(&NamedPropertyGetterForSerialization), reinterpret_cast<intptr_t>(&AccessorForSerialization), - reinterpret_cast<intptr_t>(&SerializedExtension::FunctionCallback), reinterpret_cast<intptr_t>(&serialized_static_field), reinterpret_cast<intptr_t>(&serializable_one_byte_resource), reinterpret_cast<intptr_t>(&serializable_two_byte_resource), @@ -2640,6 +2700,51 @@ TEST(SnapshotCreatorNoExternalReferencesDefault) { delete[] blob.data; } +v8::StartupData CreateCustomSnapshotWithPreparseDataAndNoOuterScope() { + v8::SnapshotCreator creator; + v8::Isolate* isolate = creator.GetIsolate(); + { + v8::HandleScope handle_scope(isolate); + { + v8::Local<v8::Context> context = v8::Context::New(isolate); + v8::Context::Scope context_scope(context); + CompileRun( + "var foo = {\n" + " // This function is not top-level, but also has no outer scope.\n" + " bar: function(){\n" + " // Add an inner function so that the outer one has preparse\n" + " // scope data.\n" + " return function(){}\n" + " }\n" + "};\n"); + creator.SetDefaultContext(context); + } + } + return creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); +} + +TEST(SnapshotCreatorPreparseDataAndNoOuterScope) { + DisableAlwaysOpt(); + v8::StartupData blob = CreateCustomSnapshotWithPreparseDataAndNoOuterScope(); + + // Deserialize with an incomplete list of external references. + { + v8::Isolate::CreateParams params; + params.snapshot_blob = &blob; + params.array_buffer_allocator = CcTest::array_buffer_allocator(); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); + { + v8::Isolate::Scope isolate_scope(isolate); + v8::HandleScope handle_scope(isolate); + v8::Local<v8::Context> context = v8::Context::New(isolate); + v8::Context::Scope context_scope(context); + } + isolate->Dispose(); + } + delete[] blob.data; +} + v8::StartupData CreateCustomSnapshotArrayJoinWithKeep() { v8::SnapshotCreator creator; v8::Isolate* isolate = creator.GetIsolate(); @@ -3146,9 +3251,6 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { { v8::SnapshotCreator creator(original_external_references); v8::Isolate* isolate = creator.GetIsolate(); - v8::RegisterExtension(new SerializedExtension); - const char* extension_names[] = {"serialized extension"}; - v8::ExtensionConfiguration extensions(1, extension_names); { // Set default context. This context implicitly does *not* serialize // the global proxy, and upon deserialization one has to be created @@ -3163,10 +3265,13 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { global_template->SetHandler(v8::NamedPropertyHandlerConfiguration( NamedPropertyGetterForSerialization)); v8::Local<v8::Context> context = - v8::Context::New(isolate, &extensions, global_template); + v8::Context::New(isolate, nullptr, global_template); v8::Context::Scope context_scope(context); + CompileRun( + "function h() { return 13; };" + "function i() { return 14; };" + "var o = { p: 7 };"); ExpectInt32("f()", 42); - ExpectInt32("g()", 12); ExpectInt32("h()", 13); ExpectInt32("o.p", 7); ExpectInt32("x", 2016); @@ -3194,7 +3299,7 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { v8::FunctionTemplate::NewWithCache(isolate, SerializedCallback, priv, v8::Local<v8::Value>())); v8::Local<v8::Context> context = - v8::Context::New(isolate, &extensions, global_template); + v8::Context::New(isolate, nullptr, global_template); v8::Context::Scope context_scope(context); CHECK(context->Global() @@ -3207,9 +3312,6 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { .FromJust()); ExpectInt32("f()", 42); - ExpectInt32("g()", 12); - ExpectInt32("h()", 13); - ExpectInt32("o.p", 7); ExpectInt32("x", 2016); ExpectInt32("y", 2017); CHECK(v8_str("hidden string") @@ -3236,12 +3338,14 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope isolate_scope(isolate); - // We can introduce new extensions, which could override the already - // snapshotted extension. + // We can introduce new extensions, which could override functions already + // in the snapshot. v8::Extension* extension = new v8::Extension("new extension", "function i() { return 24; }" "function j() { return 25; }" - "if (o.p == 7) o.p++;"); + "try {" + " if (o.p == 7) o.p++;" + "} catch {}"); extension->set_auto_enable(true); v8::RegisterExtension(extension); { @@ -3252,7 +3356,6 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Context::Scope context_scope(context); ExpectInt32("f()", 42); - ExpectInt32("g()", 12); ExpectInt32("h()", 13); ExpectInt32("i()", 24); ExpectInt32("j()", 25); @@ -3275,11 +3378,8 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { { v8::Context::Scope context_scope(context); ExpectInt32("f()", 42); - ExpectInt32("g()", 12); - ExpectInt32("h()", 13); ExpectInt32("i()", 24); ExpectInt32("j()", 25); - ExpectInt32("o.p", 8); ExpectInt32("x", 2016); v8::Local<v8::Private> hidden = v8::Private::ForApi(isolate, v8_str("hidden")); @@ -3307,11 +3407,8 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { { v8::Context::Scope context_scope(context2); ExpectInt32("f()", 42); - ExpectInt32("g()", 12); - ExpectInt32("h()", 13); ExpectInt32("i()", 24); ExpectInt32("j()", 25); - ExpectInt32("o.p", 8); ExpectInt32("x", 2016); v8::Local<v8::Private> hidden = v8::Private::ForApi(isolate, v8_str("hidden")); @@ -3370,7 +3467,8 @@ UNINITIALIZED_TEST(ReinitializeHashSeedNotRehashable) { v8::Isolate* isolate = v8::Isolate::New(create_params); { // Check that no rehashing has been performed. - CHECK_EQ(42, reinterpret_cast<i::Isolate*>(isolate)->heap()->HashSeed()); + CHECK_EQ(static_cast<uint64_t>(42), + reinterpret_cast<i::Isolate*>(isolate)->heap()->HashSeed()); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate); @@ -3432,7 +3530,8 @@ UNINITIALIZED_TEST(ReinitializeHashSeedRehashable) { v8::Isolate* isolate = v8::Isolate::New(create_params); { // Check that rehashing has been performed. - CHECK_EQ(1337, reinterpret_cast<i::Isolate*>(isolate)->heap()->HashSeed()); + CHECK_EQ(static_cast<uint64_t>(1337), + reinterpret_cast<i::Isolate*>(isolate)->heap()->HashSeed()); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate); @@ -3451,11 +3550,21 @@ UNINITIALIZED_TEST(ReinitializeHashSeedRehashable) { delete[] blob.data; } -TEST(SerializationMemoryStats) { +TEST(SerializationStats) { FLAG_profile_deserialization = true; FLAG_always_opt = false; v8::StartupData blob = CreateSnapshotDataBlob(); delete[] blob.data; + + // Track the embedded blob size as well. + { + int embedded_blob_size = 0; + if (FLAG_embedded_builtins) { + i::EmbeddedData d = i::EmbeddedData::FromBlob(); + embedded_blob_size = static_cast<int>(d.size()); + } + PrintF("Embedded blob is %d bytes\n", embedded_blob_size); + } } void CheckSFIsAreWeak(WeakFixedArray* sfis, Isolate* isolate) { |