LCOV - code coverage report
Current view: top level - src/snapshot - partial-deserializer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 28 29 96.6 %
Date: 2019-04-17 Functions: 4 4 100.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/partial-deserializer.h"
       6             : 
       7             : #include "src/api-inl.h"
       8             : #include "src/heap/heap-inl.h"
       9             : #include "src/objects/slots.h"
      10             : #include "src/snapshot/snapshot.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15       91654 : MaybeHandle<Context> PartialDeserializer::DeserializeContext(
      16             :     Isolate* isolate, const SnapshotData* data, bool can_rehash,
      17             :     Handle<JSGlobalProxy> global_proxy,
      18             :     v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
      19             :   PartialDeserializer d(data);
      20             :   d.SetRehashability(can_rehash);
      21             : 
      22             :   MaybeHandle<Object> maybe_result =
      23       91655 :       d.Deserialize(isolate, global_proxy, embedder_fields_deserializer);
      24             : 
      25             :   Handle<Object> result;
      26             :   return maybe_result.ToHandle(&result) ? Handle<Context>::cast(result)
      27      183310 :                                         : MaybeHandle<Context>();
      28             : }
      29             : 
      30       91654 : MaybeHandle<Object> PartialDeserializer::Deserialize(
      31             :     Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
      32             :     v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
      33       91654 :   Initialize(isolate);
      34       91654 :   if (!allocator()->ReserveSpace()) {
      35           0 :     V8::FatalProcessOutOfMemory(isolate, "PartialDeserializer");
      36             :   }
      37             : 
      38             :   AddAttachedObject(global_proxy);
      39             : 
      40             :   DisallowHeapAllocation no_gc;
      41             :   // Keep track of the code space start and end pointers in case new
      42             :   // code objects were unserialized
      43             :   CodeSpace* code_space = isolate->heap()->code_space();
      44             :   Address start_address = code_space->top();
      45       91655 :   Object root;
      46       91655 :   VisitRootPointer(Root::kPartialSnapshotCache, nullptr, FullObjectSlot(&root));
      47       91655 :   DeserializeDeferredObjects();
      48       91655 :   DeserializeEmbedderFields(embedder_fields_deserializer);
      49             : 
      50       91655 :   allocator()->RegisterDeserializedObjectsForBlackAllocation();
      51             : 
      52             :   // There's no code deserialized here. If this assert fires then that's
      53             :   // changed and logging should be added to notify the profiler et al of the
      54             :   // new code, which also has to be flushed from instruction cache.
      55       91655 :   CHECK_EQ(start_address, code_space->top());
      56             : 
      57       91655 :   if (FLAG_rehash_snapshot && can_rehash()) Rehash();
      58       91655 :   LogNewMapEvents();
      59             : 
      60       91655 :   return Handle<Object>(root, isolate);
      61             : }
      62             : 
      63       91655 : void PartialDeserializer::DeserializeEmbedderFields(
      64             :     v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer) {
      65      274960 :   if (!source()->HasMore() || source()->Get() != kEmbedderFieldsData) return;
      66             :   DisallowHeapAllocation no_gc;
      67          10 :   DisallowJavascriptExecution no_js(isolate());
      68             :   DisallowCompilation no_compile(isolate());
      69             :   DCHECK_NOT_NULL(embedder_fields_deserializer.callback);
      70          20 :   for (int code = source()->Get(); code != kSynchronize;
      71             :        code = source()->Get()) {
      72             :     HandleScope scope(isolate());
      73          15 :     int space = code & kSpaceMask;
      74             :     DCHECK_LE(space, kNumberOfSpaces);
      75             :     DCHECK_EQ(code - space, kNewObject);
      76          30 :     Handle<JSObject> obj(JSObject::cast(GetBackReferencedObject(space)),
      77             :                          isolate());
      78          15 :     int index = source()->GetInt();
      79          15 :     int size = source()->GetInt();
      80             :     // TODO(yangguo,jgruber): Turn this into a reusable shared buffer.
      81          15 :     byte* data = new byte[size];
      82             :     source()->CopyRaw(data, size);
      83          15 :     embedder_fields_deserializer.callback(v8::Utils::ToLocal(obj), index,
      84             :                                           {reinterpret_cast<char*>(data), size},
      85          15 :                                           embedder_fields_deserializer.data);
      86          15 :     delete[] data;
      87             :   }
      88             : }
      89             : }  // namespace internal
      90      121996 : }  // namespace v8

Generated by: LCOV version 1.10