| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // can be loaded from v8natives.js and their addresses can be processed. This | 83 // can be loaded from v8natives.js and their addresses can be processed. This |
| 84 // will clear the pending fixups array, which would otherwise contain GC roots | 84 // will clear the pending fixups array, which would otherwise contain GC roots |
| 85 // that would confuse the serialization/deserialization process. | 85 // that would confuse the serialization/deserialization process. |
| 86 v8::Isolate::Scope isolate_scope(isolate); | 86 v8::Isolate::Scope isolate_scope(isolate); |
| 87 { | 87 { |
| 88 v8::HandleScope scope(isolate); | 88 v8::HandleScope scope(isolate); |
| 89 v8::Context::New(isolate); | 89 v8::Context::New(isolate); |
| 90 } | 90 } |
| 91 | 91 |
| 92 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); | 92 Isolate* internal_isolate = reinterpret_cast<Isolate*>(isolate); |
| 93 internal_isolate->heap()->CollectAllAvailableGarbage("serialize"); | 93 internal_isolate->heap()->CollectAllAvailableGarbage( |
| 94 i::GarbageCollectionReason::kTesting); |
| 94 StartupSerializer ser(internal_isolate, | 95 StartupSerializer ser(internal_isolate, |
| 95 v8::SnapshotCreator::FunctionCodeHandling::kClear); | 96 v8::SnapshotCreator::FunctionCodeHandling::kClear); |
| 96 ser.SerializeStrongReferences(); | 97 ser.SerializeStrongReferences(); |
| 97 ser.SerializeWeakReferencesAndDeferred(); | 98 ser.SerializeWeakReferencesAndDeferred(); |
| 98 SnapshotData snapshot_data(&ser); | 99 SnapshotData snapshot_data(&ser); |
| 99 return WritePayload(snapshot_data.RawData()); | 100 return WritePayload(snapshot_data.RawData()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 | 103 |
| 103 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, | 104 Vector<const uint8_t> ConstructSource(Vector<const uint8_t> head, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 v8::HandleScope handle_scope(v8_isolate); | 257 v8::HandleScope handle_scope(v8_isolate); |
| 257 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); | 258 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
| 258 } | 259 } |
| 259 // Make sure all builtin scripts are cached. | 260 // Make sure all builtin scripts are cached. |
| 260 { | 261 { |
| 261 HandleScope scope(isolate); | 262 HandleScope scope(isolate); |
| 262 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 263 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 263 isolate->bootstrapper()->SourceLookup<Natives>(i); | 264 isolate->bootstrapper()->SourceLookup<Natives>(i); |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 heap->CollectAllGarbage(); | 267 heap->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, |
| 267 heap->CollectAllGarbage(); | 268 i::GarbageCollectionReason::kTesting); |
| 269 heap->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, |
| 270 i::GarbageCollectionReason::kTesting); |
| 268 | 271 |
| 269 Object* raw_foo; | 272 Object* raw_foo; |
| 270 { | 273 { |
| 271 v8::HandleScope handle_scope(v8_isolate); | 274 v8::HandleScope handle_scope(v8_isolate); |
| 272 v8::Local<v8::String> foo = v8_str("foo"); | 275 v8::Local<v8::String> foo = v8_str("foo"); |
| 273 CHECK(!foo.IsEmpty()); | 276 CHECK(!foo.IsEmpty()); |
| 274 raw_foo = *(v8::Utils::OpenHandle(*foo)); | 277 raw_foo = *(v8::Utils::OpenHandle(*foo)); |
| 275 } | 278 } |
| 276 | 279 |
| 277 { | 280 { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 362 } |
| 360 // Make sure all builtin scripts are cached. | 363 // Make sure all builtin scripts are cached. |
| 361 { | 364 { |
| 362 HandleScope scope(isolate); | 365 HandleScope scope(isolate); |
| 363 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 366 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 364 isolate->bootstrapper()->SourceLookup<Natives>(i); | 367 isolate->bootstrapper()->SourceLookup<Natives>(i); |
| 365 } | 368 } |
| 366 } | 369 } |
| 367 // If we don't do this then we end up with a stray root pointing at the | 370 // If we don't do this then we end up with a stray root pointing at the |
| 368 // context even after we have disposed of env. | 371 // context even after we have disposed of env. |
| 369 heap->CollectAllGarbage(); | 372 heap->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, |
| 373 i::GarbageCollectionReason::kTesting); |
| 370 | 374 |
| 371 { | 375 { |
| 372 v8::HandleScope handle_scope(v8_isolate); | 376 v8::HandleScope handle_scope(v8_isolate); |
| 373 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 377 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 374 } | 378 } |
| 375 | 379 |
| 376 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 380 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
| 377 | 381 |
| 378 env.Reset(); | 382 env.Reset(); |
| 379 | 383 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 } | 481 } |
| 478 // Make sure all builtin scripts are cached. | 482 // Make sure all builtin scripts are cached. |
| 479 { | 483 { |
| 480 HandleScope scope(isolate); | 484 HandleScope scope(isolate); |
| 481 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 485 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 482 isolate->bootstrapper()->SourceLookup<Natives>(i); | 486 isolate->bootstrapper()->SourceLookup<Natives>(i); |
| 483 } | 487 } |
| 484 } | 488 } |
| 485 // If we don't do this then we end up with a stray root pointing at the | 489 // If we don't do this then we end up with a stray root pointing at the |
| 486 // context even after we have disposed of env. | 490 // context even after we have disposed of env. |
| 487 isolate->heap()->CollectAllAvailableGarbage("snapshotting"); | 491 isolate->heap()->CollectAllAvailableGarbage( |
| 492 i::GarbageCollectionReason::kTesting); |
| 488 | 493 |
| 489 { | 494 { |
| 490 v8::HandleScope handle_scope(v8_isolate); | 495 v8::HandleScope handle_scope(v8_isolate); |
| 491 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 496 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 492 } | 497 } |
| 493 | 498 |
| 494 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 499 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
| 495 | 500 |
| 496 env.Reset(); | 501 env.Reset(); |
| 497 | 502 |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 | 1892 |
| 1888 delete script_data; | 1893 delete script_data; |
| 1889 } | 1894 } |
| 1890 #endif // V8_TARGET_ARCH_X64 | 1895 #endif // V8_TARGET_ARCH_X64 |
| 1891 | 1896 |
| 1892 TEST(CodeSerializerEmbeddedObject) { | 1897 TEST(CodeSerializerEmbeddedObject) { |
| 1893 FLAG_serialize_toplevel = true; | 1898 FLAG_serialize_toplevel = true; |
| 1894 LocalContext context; | 1899 LocalContext context; |
| 1895 Isolate* isolate = CcTest::i_isolate(); | 1900 Isolate* isolate = CcTest::i_isolate(); |
| 1896 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. | 1901 isolate->compilation_cache()->Disable(); // Disable same-isolate code cache. |
| 1897 Heap* heap = isolate->heap(); | |
| 1898 v8::HandleScope scope(CcTest::isolate()); | 1902 v8::HandleScope scope(CcTest::isolate()); |
| 1899 | 1903 |
| 1900 size_t actual_size; | 1904 size_t actual_size; |
| 1901 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( | 1905 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 1902 Assembler::kMinimalBufferSize, &actual_size, true)); | 1906 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 1903 CHECK(buffer); | 1907 CHECK(buffer); |
| 1904 HandleScope handles(isolate); | 1908 HandleScope handles(isolate); |
| 1905 | 1909 |
| 1906 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), | 1910 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 1907 v8::internal::CodeObjectRequired::kYes); | 1911 v8::internal::CodeObjectRequired::kYes); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1927 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); | 1931 ScriptData* script_data = CodeSerializer::Serialize(isolate, sfi, source); |
| 1928 | 1932 |
| 1929 Handle<SharedFunctionInfo> copy = | 1933 Handle<SharedFunctionInfo> copy = |
| 1930 CodeSerializer::Deserialize(isolate, script_data, source) | 1934 CodeSerializer::Deserialize(isolate, script_data, source) |
| 1931 .ToHandleChecked(); | 1935 .ToHandleChecked(); |
| 1932 RelocIterator rit2(copy->code(), | 1936 RelocIterator rit2(copy->code(), |
| 1933 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT)); | 1937 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT)); |
| 1934 CHECK(rit2.rinfo()->target_object()->IsHeapNumber()); | 1938 CHECK(rit2.rinfo()->target_object()->IsHeapNumber()); |
| 1935 CHECK_EQ(0.3, HeapNumber::cast(rit2.rinfo()->target_object())->value()); | 1939 CHECK_EQ(0.3, HeapNumber::cast(rit2.rinfo()->target_object())->value()); |
| 1936 | 1940 |
| 1937 heap->CollectAllAvailableGarbage(); | 1941 CcTest::CollectAllAvailableGarbage(); |
| 1938 | 1942 |
| 1939 RelocIterator rit3(copy->code(), | 1943 RelocIterator rit3(copy->code(), |
| 1940 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT)); | 1944 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT)); |
| 1941 CHECK(rit3.rinfo()->target_object()->IsHeapNumber()); | 1945 CHECK(rit3.rinfo()->target_object()->IsHeapNumber()); |
| 1942 CHECK_EQ(0.3, HeapNumber::cast(rit3.rinfo()->target_object())->value()); | 1946 CHECK_EQ(0.3, HeapNumber::cast(rit3.rinfo()->target_object())->value()); |
| 1943 | 1947 |
| 1944 delete script_data; | 1948 delete script_data; |
| 1945 } | 1949 } |
| 1946 | 1950 |
| 1947 TEST(SnapshotCreatorMultipleContexts) { | 1951 TEST(SnapshotCreatorMultipleContexts) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 } | 2178 } |
| 2175 delete[] blob.data; | 2179 delete[] blob.data; |
| 2176 } | 2180 } |
| 2177 | 2181 |
| 2178 TEST(SerializationMemoryStats) { | 2182 TEST(SerializationMemoryStats) { |
| 2179 FLAG_profile_deserialization = true; | 2183 FLAG_profile_deserialization = true; |
| 2180 FLAG_always_opt = false; | 2184 FLAG_always_opt = false; |
| 2181 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 2185 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
| 2182 delete[] blob.data; | 2186 delete[] blob.data; |
| 2183 } | 2187 } |
| OLD | NEW |