diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-06-06 10:28:14 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2017-06-07 10:33:31 +0200 |
commit | 3dc8c3bed4cf3a77607edbb0b015e33f8b60fc09 (patch) | |
tree | 9dee56e142638b34f1eccbd0ad88c3bce5377c29 /deps/v8/test/cctest/test-serialize.cc | |
parent | 91a1bbe3055a660194ca4d403795aa0c03e9d056 (diff) | |
download | android-node-v8-3dc8c3bed4cf3a77607edbb0b015e33f8b60fc09.tar.gz android-node-v8-3dc8c3bed4cf3a77607edbb0b015e33f8b60fc09.tar.bz2 android-node-v8-3dc8c3bed4cf3a77607edbb0b015e33f8b60fc09.zip |
deps: update V8 to 5.9.211.32
PR-URL: https://github.com/nodejs/node/pull/13263
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/test/cctest/test-serialize.cc')
-rw-r--r-- | deps/v8/test/cctest/test-serialize.cc | 181 |
1 files changed, 134 insertions, 47 deletions
diff --git a/deps/v8/test/cctest/test-serialize.cc b/deps/v8/test/cctest/test-serialize.cc index 20085a23c0..c0776bc4bb 100644 --- a/deps/v8/test/cctest/test-serialize.cc +++ b/deps/v8/test/cctest/test-serialize.cc @@ -38,7 +38,7 @@ #include "src/compiler.h" #include "src/debug/debug.h" #include "src/heap/spaces.h" -#include "src/macro-assembler.h" +#include "src/macro-assembler-inl.h" #include "src/objects-inl.h" #include "src/runtime/runtime.h" #include "src/snapshot/code-serializer.h" @@ -49,6 +49,7 @@ #include "src/snapshot/startup-serializer.h" #include "test/cctest/cctest.h" #include "test/cctest/heap/heap-utils.h" +#include "test/cctest/setup-isolate-for-tests.h" using namespace v8::internal; @@ -64,14 +65,26 @@ class TestIsolate : public Isolate { public: static v8::Isolate* NewInitialized(bool enable_serializer) { i::Isolate* isolate = new TestIsolate(enable_serializer); + isolate->setup_delegate_ = new SetupIsolateDelegateForTests(); v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate::Scope isolate_scope(v8_isolate); isolate->Init(NULL); return v8_isolate; } + // Wraps v8::Isolate::New, but with a TestIsolate under the hood. + // 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); + isolate->setup_delegate_ = new SetupIsolateDelegateForTests(); + return v8::IsolateNewImpl(isolate, params); + } explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) { set_array_buffer_allocator(CcTest::array_buffer_allocator()); } + void CreateSetupDelegateForTests() { + setup_delegate_ = new SetupIsolateDelegateForTests(); + } }; static Vector<const byte> WritePayload(const Vector<const byte>& payload) { @@ -125,9 +138,10 @@ v8::Isolate* InitializeFromBlob(Vector<const byte> blob) { { SnapshotData snapshot_data(blob); Deserializer deserializer(&snapshot_data); - Isolate* isolate = new TestIsolate(false); + TestIsolate* isolate = new TestIsolate(false); v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate::Scope isolate_scope(v8_isolate); + isolate->CreateSetupDelegateForTests(); isolate->Init(&deserializer); } return v8_isolate; @@ -257,13 +271,6 @@ static void PartiallySerializeObject(Vector<const byte>* startup_blob_out, v8::HandleScope handle_scope(v8_isolate); v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); } - // Make sure all builtin scripts are cached. - { - HandleScope scope(isolate); - for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { - isolate->bootstrapper()->SourceLookup<Natives>(i); - } - } heap->CollectAllAvailableGarbage(i::GarbageCollectionReason::kTesting); heap->CollectAllAvailableGarbage(i::GarbageCollectionReason::kTesting); @@ -364,13 +371,6 @@ static void PartiallySerializeContext(Vector<const byte>* startup_blob_out, v8::HandleScope handle_scope(v8_isolate); v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); } - // Make sure all builtin scripts are cached. - { - HandleScope scope(isolate); - for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { - isolate->bootstrapper()->SourceLookup<Natives>(i); - } - } // If we don't do this then we end up with a stray root pointing at the // context even after we have disposed of env. @@ -422,7 +422,7 @@ UNINITIALIZED_TEST(PartialSerializerContext) { Handle<Object> root; Handle<JSGlobalProxy> global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy( - JSGlobalProxy::SizeWithInternalFields(0)); + JSGlobalProxy::SizeWithEmbedderFields(0)); { SnapshotData snapshot_data(partial_blob); Deserializer deserializer(&snapshot_data); @@ -489,13 +489,6 @@ static void PartiallySerializeCustomContext( CompileRun(source_str.ToLocalChecked()); source.Dispose(); } - // Make sure all builtin scripts are cached. - { - HandleScope scope(isolate); - for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { - isolate->bootstrapper()->SourceLookup<Natives>(i); - } - } // If we don't do this then we end up with a stray root pointing at the // context even after we have disposed of env. isolate->heap()->CollectAllAvailableGarbage( @@ -547,7 +540,7 @@ UNINITIALIZED_TEST(PartialSerializerCustomContext) { Handle<Object> root; Handle<JSGlobalProxy> global_proxy = isolate->factory()->NewUninitializedJSGlobalProxy( - JSGlobalProxy::SizeWithInternalFields(0)); + JSGlobalProxy::SizeWithEmbedderFields(0)); { SnapshotData snapshot_data(partial_blob); Deserializer deserializer(&snapshot_data); @@ -633,7 +626,8 @@ TEST(CustomSnapshotDataBlob1) { params1.snapshot_blob = &data1; params1.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate1 = v8::Isolate::New(params1); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate1 = TestIsolate::New(params1); { v8::Isolate::Scope i_scope(isolate1); v8::HandleScope h_scope(isolate1); @@ -660,7 +654,8 @@ TEST(CustomSnapshotDataBlob2) { v8::Isolate::CreateParams params2; params2.snapshot_blob = &data2; params2.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate2 = v8::Isolate::New(params2); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate2 = TestIsolate::New(params2); { v8::Isolate::Scope i_scope(isolate2); v8::HandleScope h_scope(isolate2); @@ -703,7 +698,8 @@ TEST(CustomSnapshotDataBlobOutdatedContextWithOverflow) { params.snapshot_blob = &data; params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope i_scope(isolate); v8::HandleScope h_scope(isolate); @@ -750,7 +746,8 @@ TEST(CustomSnapshotDataBlobWithLocker) { v8::Isolate::CreateParams params1; params1.snapshot_blob = &data1; params1.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate1 = v8::Isolate::New(params1); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate1 = TestIsolate::New(params1); { v8::Locker locker(isolate1); v8::Isolate::Scope i_scope(isolate1); @@ -782,7 +779,8 @@ TEST(CustomSnapshotDataBlobStackOverflow) { params.snapshot_blob = &data; params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope i_scope(isolate); v8::HandleScope h_scope(isolate); @@ -822,7 +820,8 @@ TEST(SnapshotDataBlobWithWarmup) { params.snapshot_blob = &warm; params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope i_scope(isolate); v8::HandleScope h_scope(isolate); @@ -855,7 +854,8 @@ TEST(CustomSnapshotDataBlobWithWarmup) { params.snapshot_blob = &warm; params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope i_scope(isolate); v8::HandleScope h_scope(isolate); @@ -868,7 +868,7 @@ TEST(CustomSnapshotDataBlobWithWarmup) { CHECK(IsCompiled("Math.abs")); CHECK(!IsCompiled("g")); CHECK(!IsCompiled("String.raw")); - CHECK(!IsCompiled("Object.valueOf")); + CHECK(!IsCompiled("Array.prototype.sort")); CHECK_EQ(5, CompileRun("a")->Int32Value(context).FromJust()); } isolate->Dispose(); @@ -891,7 +891,8 @@ TEST(CustomSnapshotDataBlobImmortalImmovableRoots) { params.snapshot_blob = &data; params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope i_scope(isolate); v8::HandleScope h_scope(isolate); @@ -1125,6 +1126,87 @@ TEST(CodeSerializerLargeCodeObject) { source.Dispose(); } +TEST(CodeSerializerLargeCodeObjectWithIncrementalMarking) { + FLAG_serialize_toplevel = true; + FLAG_always_opt = false; + // This test relies on (full-codegen) code objects going to large object + // space. Once FCG goes away, it must either be redesigned (to put some + // other large deserialized object into LO space), or it can be deleted. + FLAG_ignition = false; + const char* filter_flag = "--turbo-filter=NOTHING"; + FlagList::SetFlagsFromString(filter_flag, StrLength(filter_flag)); + FLAG_black_allocation = true; + FLAG_manual_evacuation_candidates_selection = true; + + LocalContext context; + Isolate* isolate = CcTest::i_isolate(); + Heap* heap = isolate->heap(); + isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. + + v8::HandleScope scope(CcTest::isolate()); + + Vector<const uint8_t> source = ConstructSource( + STATIC_CHAR_VECTOR("var j=1; if (j == 0) {"), + STATIC_CHAR_VECTOR("for (var i = 0; i < Object.prototype; i++);"), + STATIC_CHAR_VECTOR("} j=7; var s = 'happy_hippo'; j"), 2100); + Handle<String> source_str = + isolate->factory()->NewStringFromOneByte(source).ToHandleChecked(); + + // Create a string on an evacuation candidate in old space. + Handle<String> moving_object; + Page* ec_page; + { + AlwaysAllocateScope always_allocate(isolate); + heap::SimulateFullSpace(heap->old_space()); + moving_object = isolate->factory()->InternalizeString( + isolate->factory()->NewStringFromAsciiChecked("happy_hippo")); + ec_page = Page::FromAddress(moving_object->address()); + } + + Handle<JSObject> global(isolate->context()->global_object()); + ScriptData* cache = NULL; + + Handle<SharedFunctionInfo> orig = + CompileScript(isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kProduceCodeCache); + + CHECK(heap->InSpace(orig->abstract_code(), LO_SPACE)); + + // Pretend that incremental marking is on when deserialization begins. + heap::ForceEvacuationCandidate(ec_page); + heap::SimulateIncrementalMarking(heap, false); + IncrementalMarking* marking = heap->incremental_marking(); + marking->StartBlackAllocationForTesting(); + CHECK(marking->IsCompacting()); + CHECK(MarkCompactCollector::IsOnEvacuationCandidate(*moving_object)); + + Handle<SharedFunctionInfo> copy; + { + DisallowCompilation no_compile_expected(isolate); + copy = CompileScript(isolate, source_str, Handle<String>(), &cache, + v8::ScriptCompiler::kConsumeCodeCache); + } + CHECK_NE(*orig, *copy); + + // We should have missed a write barrier. Complete incremental marking + // to flush out the bug. + heap::SimulateIncrementalMarking(heap, true); + CcTest::CollectAllGarbage(Heap::kFinalizeIncrementalMarkingMask); + + Handle<JSFunction> copy_fun = + isolate->factory()->NewFunctionFromSharedFunctionInfo( + copy, isolate->native_context()); + + Handle<Object> copy_result = + Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); + + int result_int; + CHECK(copy_result->ToInt32(&result_int)); + CHECK_EQ(7, result_int); + + delete cache; + source.Dispose(); +} TEST(CodeSerializerLargeStrings) { FLAG_serialize_toplevel = true; LocalContext context; @@ -1906,7 +1988,8 @@ TEST(SnapshotCreatorMultipleContexts) { v8::Isolate::CreateParams params; params.snapshot_blob = &blob; params.array_buffer_allocator = CcTest::array_buffer_allocator(); - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope isolate_scope(isolate); { @@ -2028,7 +2111,8 @@ TEST(SnapshotCreatorExternalReferences) { params.snapshot_blob = &blob; params.array_buffer_allocator = CcTest::array_buffer_allocator(); params.external_references = original_external_references; - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); @@ -2045,7 +2129,8 @@ TEST(SnapshotCreatorExternalReferences) { params.snapshot_blob = &blob; params.array_buffer_allocator = CcTest::array_buffer_allocator(); params.external_references = replaced_external_references; - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); @@ -2089,12 +2174,12 @@ struct InternalFieldData { v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index, void* data) { CHECK_EQ(reinterpret_cast<void*>(2016), data); - InternalFieldData* internal_field = static_cast<InternalFieldData*>( + InternalFieldData* embedder_field = static_cast<InternalFieldData*>( holder->GetAlignedPointerFromInternalField(index)); - int size = sizeof(*internal_field); + int size = sizeof(*embedder_field); char* payload = new char[size]; // We simply use memcpy to serialize the content. - memcpy(payload, internal_field, size); + memcpy(payload, embedder_field, size); return {payload, size}; } @@ -2103,10 +2188,10 @@ std::vector<InternalFieldData*> deserialized_data; void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, v8::StartupData payload, void* data) { CHECK_EQ(reinterpret_cast<void*>(2017), data); - InternalFieldData* internal_field = new InternalFieldData{0}; - memcpy(internal_field, payload.data, payload.raw_size); - holder->SetAlignedPointerInInternalField(index, internal_field); - deserialized_data.push_back(internal_field); + 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) { @@ -2178,7 +2263,8 @@ TEST(SnapshotCreatorTemplates) { params.snapshot_blob = &blob; params.array_buffer_allocator = CcTest::array_buffer_allocator(); params.external_references = original_external_references; - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope isolate_scope(isolate); { @@ -2215,7 +2301,7 @@ TEST(SnapshotCreatorTemplates) { // Check that it instantiates to the same prototype. ExpectTrue("g.prototype === f.prototype"); - // Retrieve internal fields. + // Retrieve embedder fields. v8::Local<v8::Object> a = context->Global() ->Get(context, v8_str("a")) .ToLocalChecked() @@ -2355,7 +2441,8 @@ TEST(SnapshotCreatorIncludeGlobalProxy) { params.snapshot_blob = &blob; params.array_buffer_allocator = CcTest::array_buffer_allocator(); params.external_references = original_external_references; - v8::Isolate* isolate = v8::Isolate::New(params); + // Test-appropriate equivalent of v8::Isolate::New. + v8::Isolate* isolate = TestIsolate::New(params); { v8::Isolate::Scope isolate_scope(isolate); // We can introduce new extensions, which could override the already |