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

Generated by: LCOV version 1.10