LCOV - code coverage report
Current view: top level - src/snapshot - startup-deserializer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 31 34 91.2 %
Date: 2017-10-20 Functions: 3 4 75.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/snapshot/startup-deserializer.h"
       6             : 
       7             : #include "src/api.h"
       8             : #include "src/assembler-inl.h"
       9             : #include "src/heap/heap-inl.h"
      10             : #include "src/snapshot/builtin-deserializer.h"
      11             : #include "src/snapshot/snapshot.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : 
      16      219872 : void StartupDeserializer::DeserializeInto(Isolate* isolate) {
      17      109936 :   Initialize(isolate);
      18             : 
      19       54968 :   BuiltinDeserializer builtin_deserializer(isolate, builtin_data_);
      20             : 
      21       54968 :   if (!DefaultDeserializerAllocator::ReserveSpace(this,
      22       54968 :                                                   &builtin_deserializer)) {
      23           0 :     V8::FatalProcessOutOfMemory("StartupDeserializer");
      24             :   }
      25             : 
      26             :   // No active threads.
      27             :   DCHECK_NULL(isolate->thread_manager()->FirstThreadStateInUse());
      28             :   // No active handles.
      29             :   DCHECK(isolate->handle_scope_implementer()->blocks()->empty());
      30             :   // Partial snapshot cache is not yet populated.
      31             :   DCHECK(isolate->partial_snapshot_cache()->empty());
      32             :   // Builtins are not yet created.
      33             :   DCHECK(!isolate->builtins()->is_initialized());
      34             : 
      35             :   {
      36             :     DisallowHeapAllocation no_gc;
      37             : 
      38       54968 :     isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG_ROOT_LIST);
      39       54968 :     isolate->heap()->IterateSmiRoots(this);
      40       54968 :     isolate->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG);
      41       54968 :     isolate->heap()->RepairFreeListsAfterDeserialization();
      42       54968 :     isolate->heap()->IterateWeakRoots(this, VISIT_ALL);
      43       54968 :     DeserializeDeferredObjects();
      44       54968 :     RestoreExternalReferenceRedirectors(accessor_infos());
      45             : 
      46             :     // Deserialize eager builtins from the builtin snapshot. Note that deferred
      47             :     // objects must have been deserialized prior to this.
      48       54968 :     builtin_deserializer.DeserializeEagerBuiltins();
      49             : 
      50             :     // Flush the instruction cache for the entire code-space. Must happen after
      51             :     // builtins deserialization.
      52       54968 :     FlushICacheForNewIsolate();
      53             :   }
      54             : 
      55       54968 :   isolate->heap()->set_native_contexts_list(isolate->heap()->undefined_value());
      56             :   // The allocation site list is build during root iteration, but if no sites
      57             :   // were encountered then it needs to be initialized to undefined.
      58       54968 :   if (isolate->heap()->allocation_sites_list() == Smi::kZero) {
      59             :     isolate->heap()->set_allocation_sites_list(
      60             :         isolate->heap()->undefined_value());
      61             :   }
      62             : 
      63             :   // Issue code events for newly deserialized code objects.
      64       54968 :   LOG_CODE_EVENT(isolate, LogCodeObjects());
      65       54968 :   LOG_CODE_EVENT(isolate, LogBytecodeHandlers());
      66       54968 :   LOG_CODE_EVENT(isolate, LogCompiledFunctions());
      67             : 
      68             :   isolate->builtins()->MarkInitialized();
      69             : 
      70             :   // If needed, print the dissassembly of deserialized code objects.
      71             :   // Needs to be called after the builtins are marked as initialized, in order
      72             :   // to display the builtin names.
      73             :   PrintDisassembledCodeObjects();
      74             : 
      75      109936 :   if (FLAG_rehash_snapshot && can_rehash()) Rehash();
      76       54968 : }
      77             : 
      78       54968 : void StartupDeserializer::FlushICacheForNewIsolate() {
      79             :   DCHECK(!deserializing_user_code());
      80             :   // The entire isolate is newly deserialized. Simply flush all code pages.
      81      439744 :   for (Page* p : *isolate()->heap()->code_space()) {
      82             :     Assembler::FlushICache(isolate(), p->area_start(),
      83      219872 :                            p->area_end() - p->area_start());
      84             :   }
      85       54968 : }
      86             : 
      87           0 : void StartupDeserializer::PrintDisassembledCodeObjects() {
      88             : #ifdef ENABLE_DISASSEMBLER
      89             :   if (FLAG_print_builtin_code) {
      90             :     Heap* heap = isolate()->heap();
      91             :     HeapIterator iterator(heap);
      92             :     DisallowHeapAllocation no_gc;
      93             : 
      94             :     CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
      95             :     OFStream os(tracing_scope.file());
      96             : 
      97             :     for (HeapObject* obj = iterator.next(); obj != nullptr;
      98             :          obj = iterator.next()) {
      99             :       if (obj->IsCode()) {
     100             :         Code::cast(obj)->Disassemble(nullptr, os);
     101             :       }
     102             :     }
     103             :   }
     104             : #endif
     105           0 : }
     106             : 
     107       54908 : void StartupDeserializer::Rehash() {
     108             :   DCHECK(FLAG_rehash_snapshot && can_rehash());
     109      109816 :   isolate()->heap()->InitializeHashSeed();
     110       54908 :   isolate()->heap()->string_table()->Rehash();
     111       54908 :   isolate()->heap()->weak_object_to_code_table()->Rehash();
     112       54908 :   SortMapDescriptors();
     113       54908 : }
     114             : 
     115             : }  // namespace internal
     116             : }  // namespace v8

Generated by: LCOV version 1.10