LCOV - code coverage report
Current view: top level - src/snapshot - roots-serializer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 22 23 95.7 %
Date: 2019-04-17 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright 2018 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/roots-serializer.h"
       6             : 
       7             : #include "src/heap/heap.h"
       8             : #include "src/isolate.h"
       9             : #include "src/objects-inl.h"
      10             : #include "src/objects/slots.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15         522 : RootsSerializer::RootsSerializer(Isolate* isolate,
      16             :                                  RootIndex first_root_to_be_serialized)
      17             :     : Serializer(isolate),
      18             :       first_root_to_be_serialized_(first_root_to_be_serialized),
      19        1044 :       can_be_rehashed_(true) {
      20      280314 :   for (size_t i = 0; i < static_cast<size_t>(first_root_to_be_serialized);
      21             :        ++i) {
      22             :     root_has_been_serialized_[i] = true;
      23             :   }
      24         522 : }
      25             : 
      26      621700 : int RootsSerializer::SerializeInObjectCache(HeapObject heap_object) {
      27             :   int index;
      28      621700 :   if (!object_cache_index_map_.LookupOrInsert(heap_object, &index)) {
      29             :     // This object is not part of the object cache yet. Add it to the cache so
      30             :     // we can refer to it via cache index from the delegating snapshot.
      31      418735 :     SerializeObject(heap_object);
      32             :   }
      33      621700 :   return index;
      34             : }
      35             : 
      36        4437 : void RootsSerializer::Synchronize(VisitorSynchronization::SyncTag tag) {
      37             :   sink_.Put(kSynchronize, "Synchronize");
      38        4437 : }
      39             : 
      40      401940 : void RootsSerializer::VisitRootPointers(Root root, const char* description,
      41             :                                         FullObjectSlot start,
      42             :                                         FullObjectSlot end) {
      43             :   RootsTable& roots_table = isolate()->roots_table();
      44      401940 :   if (start ==
      45      401940 :       roots_table.begin() + static_cast<int>(first_root_to_be_serialized_)) {
      46             :     // Serializing the root list needs special handling:
      47             :     // - Only root list elements that have been fully serialized can be
      48             :     //   referenced using kRootArray bytecodes.
      49      154773 :     for (FullObjectSlot current = start; current < end; ++current) {
      50      154251 :       SerializeRootObject(*current);
      51             :       size_t root_index = current - roots_table.begin();
      52             :       root_has_been_serialized_.set(root_index);
      53             :     }
      54             :   } else {
      55      401418 :     Serializer::VisitRootPointers(root, description, start, end);
      56             :   }
      57      401940 : }
      58             : 
      59     1347096 : void RootsSerializer::CheckRehashability(HeapObject obj) {
      60     1347096 :   if (!can_be_rehashed_) return;
      61     1347096 :   if (!obj->NeedsRehashing()) return;
      62         803 :   if (obj->CanBeRehashed()) return;
      63           0 :   can_be_rehashed_ = false;
      64             : }
      65             : 
      66             : }  // namespace internal
      67      121996 : }  // namespace v8

Generated by: LCOV version 1.10