V8 Project
snapshot-common.cc
Go to the documentation of this file.
1 // Copyright 2006-2008 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 // The common functionality when building with or without snapshots.
6 
7 #include "src/v8.h"
8 
9 #include "src/api.h"
11 #include "src/serialize.h"
12 #include "src/snapshot.h"
13 
14 namespace v8 {
15 namespace internal {
16 
25  deserializer->set_reservation(LO_SPACE, lo_space_used_);
26 }
27 
28 
29 bool Snapshot::Initialize(Isolate* isolate) {
30  if (size_ > 0) {
31  base::ElapsedTimer timer;
32  if (FLAG_profile_deserialization) {
33  timer.Start();
34  }
35  SnapshotByteSource source(raw_data_, raw_size_);
36  Deserializer deserializer(&source);
37  ReserveSpaceForLinkedInSnapshot(&deserializer);
38  bool success = isolate->Init(&deserializer);
39  if (FLAG_profile_deserialization) {
40  double ms = timer.Elapsed().InMillisecondsF();
41  PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
42  }
43  return success;
44  }
45  return false;
46 }
47 
48 
50  return size_ != 0;
51 }
52 
53 
55  if (context_size_ == 0) {
56  return Handle<Context>();
57  }
58  SnapshotByteSource source(context_raw_data_,
60  Deserializer deserializer(&source);
61  Object* root;
71  deserializer.DeserializePartial(isolate, &root);
72  CHECK(root->IsContext());
73  return Handle<Context>(Context::cast(root));
74 }
75 
76 
77 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
78 // Dummy implementations of Set*FromFile(..) APIs.
79 //
80 // These are meant for use with snapshot-external.cc. Should this file
81 // be compiled with those options we just supply these dummy implementations
82 // below. This happens when compiling the mksnapshot utility.
83 void SetNativesFromFile(StartupData* data) { CHECK(false); }
84 void SetSnapshotFromFile(StartupData* data) { CHECK(false); }
85 #endif // V8_USE_EXTERNAL_STARTUP_DATA
86 
87 } } // namespace v8::internal
static Context * cast(Object *context)
Definition: contexts.h:255
void DeserializePartial(Isolate *isolate, Object **root)
Definition: serialize.cc:661
void set_reservation(int space_number, int reservation)
Definition: serialize.h:254
bool Init(Deserializer *des)
Definition: isolate.cc:1828
static const int context_map_space_used_
Definition: snapshot.h:56
static Handle< Context > NewContextFromSnapshot(Isolate *isolate)
static const int context_data_space_used_
Definition: snapshot.h:54
static const int context_size_
Definition: snapshot.h:62
static const int raw_size_
Definition: snapshot.h:61
static void ReserveSpaceForLinkedInSnapshot(Deserializer *deserializer)
static const int pointer_space_used_
Definition: snapshot.h:45
static const int context_property_cell_space_used_
Definition: snapshot.h:58
static const int cell_space_used_
Definition: snapshot.h:49
static bool Initialize(Isolate *isolate)
static const int data_space_used_
Definition: snapshot.h:46
static const byte * context_raw_data_
Definition: snapshot.h:43
static const int context_new_space_used_
Definition: snapshot.h:52
static bool HaveASnapshotToStartFrom()
static const int lo_space_used_
Definition: snapshot.h:51
static const int context_lo_space_used_
Definition: snapshot.h:59
static const int context_raw_size_
Definition: snapshot.h:63
static const int map_space_used_
Definition: snapshot.h:48
static const int context_code_space_used_
Definition: snapshot.h:55
static const byte * raw_data_
Definition: snapshot.h:41
static const int code_space_used_
Definition: snapshot.h:47
static const int new_space_used_
Definition: snapshot.h:44
static const int context_cell_space_used_
Definition: snapshot.h:57
static const int property_cell_space_used_
Definition: snapshot.h:50
static const int context_pointer_space_used_
Definition: snapshot.h:53
static const int size_
Definition: snapshot.h:60
#define CHECK(condition)
Definition: logging.h:36
void SetNativesFromFile(StartupData *natives_blob)
Read the Natives (library sources) blob, as generated by js2c + the build system.
void PrintF(const char *format,...)
Definition: utils.cc:80
@ OLD_DATA_SPACE
Definition: globals.h:361
@ PROPERTY_CELL_SPACE
Definition: globals.h:365
@ OLD_POINTER_SPACE
Definition: globals.h:360
void SetSnapshotFromFile(StartupData *snapshot_blob)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20