LCOV - code coverage report
Current view: top level - src/snapshot - object-deserializer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 38 44 86.4 %
Date: 2019-02-19 Functions: 7 8 87.5 %

          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/object-deserializer.h"
       6             : 
       7             : #include "src/assembler-inl.h"
       8             : #include "src/heap/heap-inl.h"
       9             : #include "src/isolate.h"
      10             : #include "src/objects.h"
      11             : #include "src/objects/allocation-site-inl.h"
      12             : #include "src/objects/slots.h"
      13             : #include "src/snapshot/code-serializer.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : 
      18           0 : ObjectDeserializer::ObjectDeserializer(const SerializedCodeData* data)
      19         209 :     : Deserializer(data, true) {}
      20             : 
      21             : MaybeHandle<SharedFunctionInfo>
      22         209 : ObjectDeserializer::DeserializeSharedFunctionInfo(
      23             :     Isolate* isolate, const SerializedCodeData* data, Handle<String> source) {
      24             :   ObjectDeserializer d(data);
      25             : 
      26             :   d.AddAttachedObject(source);
      27             : 
      28             :   Handle<HeapObject> result;
      29         418 :   return d.Deserialize(isolate).ToHandle(&result)
      30             :              ? Handle<SharedFunctionInfo>::cast(result)
      31         418 :              : MaybeHandle<SharedFunctionInfo>();
      32             : }
      33             : 
      34         209 : MaybeHandle<HeapObject> ObjectDeserializer::Deserialize(Isolate* isolate) {
      35         209 :   Initialize(isolate);
      36             : 
      37         209 :   if (!allocator()->ReserveSpace()) return MaybeHandle<HeapObject>();
      38             : 
      39             :   DCHECK(deserializing_user_code());
      40             :   HandleScope scope(isolate);
      41             :   Handle<HeapObject> result;
      42             :   {
      43             :     DisallowHeapAllocation no_gc;
      44         209 :     Object root;
      45             :     VisitRootPointer(Root::kPartialSnapshotCache, nullptr,
      46         418 :                      FullObjectSlot(&root));
      47         209 :     DeserializeDeferredObjects();
      48         209 :     FlushICache();
      49         209 :     LinkAllocationSites();
      50         209 :     LogNewMapEvents();
      51         209 :     result = handle(HeapObject::cast(root), isolate);
      52         209 :     Rehash();
      53         209 :     allocator()->RegisterDeserializedObjectsForBlackAllocation();
      54             :   }
      55         209 :   CommitPostProcessedObjects();
      56         209 :   return scope.CloseAndEscape(result);
      57             : }
      58             : 
      59         209 : void ObjectDeserializer::FlushICache() {
      60             :   DCHECK(deserializing_user_code());
      61         418 :   for (Code code : new_code_objects()) {
      62             :     // Record all references to embedded objects in the new code object.
      63             :     WriteBarrierForCode(code);
      64             :     FlushInstructionCache(code->raw_instruction_start(),
      65           0 :                           code->raw_instruction_size());
      66             :   }
      67         209 : }
      68             : 
      69         209 : void ObjectDeserializer::CommitPostProcessedObjects() {
      70        5936 :   CHECK_LE(new_internalized_strings().size(), kMaxInt);
      71             :   StringTable::EnsureCapacityForDeserialization(
      72         418 :       isolate(), static_cast<int>(new_internalized_strings().size()));
      73        5100 :   for (Handle<String> string : new_internalized_strings()) {
      74             :     DisallowHeapAllocation no_gc;
      75        4682 :     StringTableInsertionKey key(*string);
      76             :     DCHECK(
      77             :         StringTable::ForwardStringIfExists(isolate(), &key, *string).is_null());
      78        4682 :     StringTable::AddKeyNoResize(isolate(), &key);
      79             :   }
      80             : 
      81         209 :   Heap* heap = isolate()->heap();
      82             :   Factory* factory = isolate()->factory();
      83         627 :   for (Handle<Script> script : new_scripts()) {
      84             :     // Assign a new script id to avoid collision.
      85         209 :     script->set_id(isolate()->heap()->NextScriptId());
      86         209 :     LogScriptEvents(*script);
      87             :     // Add script to list.
      88             :     Handle<WeakArrayList> list = factory->script_list();
      89             :     list = WeakArrayList::AddToEnd(isolate(), list,
      90         418 :                                    MaybeObjectHandle::Weak(script));
      91             :     heap->SetRootScriptList(*list);
      92             :   }
      93         209 : }
      94             : 
      95         209 : void ObjectDeserializer::LinkAllocationSites() {
      96             :   DisallowHeapAllocation no_gc;
      97         209 :   Heap* heap = isolate()->heap();
      98             :   // Allocation sites are present in the snapshot, and must be linked into
      99             :   // a list at deserialization time.
     100         418 :   for (AllocationSite site : new_allocation_sites()) {
     101           0 :     if (!site->HasWeakNext()) continue;
     102             :     // TODO(mvstanton): consider treating the heap()->allocation_sites_list()
     103             :     // as a (weak) root. If this root is relocated correctly, this becomes
     104             :     // unnecessary.
     105           0 :     if (heap->allocation_sites_list() == Smi::kZero) {
     106           0 :       site->set_weak_next(ReadOnlyRoots(heap).undefined_value());
     107             :     } else {
     108           0 :       site->set_weak_next(heap->allocation_sites_list());
     109             :     }
     110             :     heap->set_allocation_sites_list(site);
     111             :   }
     112         209 : }
     113             : 
     114             : }  // namespace internal
     115      178779 : }  // namespace v8

Generated by: LCOV version 1.10