V8 Project
snapshot-external.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 // Used for building with external snapshots.
6 
7 #include "src/snapshot.h"
8 
9 #include "src/serialize.h"
11 #include "src/v8.h" // for V8::Initialize
12 
13 namespace v8 {
14 namespace internal {
15 
16 
17 struct SnapshotImpl {
18  public:
19  const byte* data;
20  int size;
29 
30  const byte* context_data;
40 };
41 
42 
44 
45 
47  return snapshot_impl_ != NULL;
48 }
49 
50 
51 bool Snapshot::Initialize(Isolate* isolate) {
53  return false;
54 
55  base::ElapsedTimer timer;
56  if (FLAG_profile_deserialization) {
57  timer.Start();
58  }
59  SnapshotByteSource source(snapshot_impl_->data, snapshot_impl_->size);
60  Deserializer deserializer(&source);
61  deserializer.set_reservation(NEW_SPACE, snapshot_impl_->new_space_used);
62  deserializer.set_reservation(OLD_POINTER_SPACE,
64  deserializer.set_reservation(OLD_DATA_SPACE,
66  deserializer.set_reservation(CODE_SPACE, snapshot_impl_->code_space_used);
67  deserializer.set_reservation(MAP_SPACE, snapshot_impl_->map_space_used);
68  deserializer.set_reservation(CELL_SPACE, snapshot_impl_->cell_space_used);
69  deserializer.set_reservation(PROPERTY_CELL_SPACE,
71  deserializer.set_reservation(LO_SPACE, snapshot_impl_->lo_space_used);
72  bool success = isolate->Init(&deserializer);
73  if (FLAG_profile_deserialization) {
74  double ms = timer.Elapsed().InMillisecondsF();
75  PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
76  }
77  return success;
78 }
79 
80 
81 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
83  return Handle<Context>();
84 
85  SnapshotByteSource source(snapshot_impl_->context_data,
87  Deserializer deserializer(&source);
88  deserializer.set_reservation(NEW_SPACE,
90  deserializer.set_reservation(OLD_POINTER_SPACE,
92  deserializer.set_reservation(OLD_DATA_SPACE,
94  deserializer.set_reservation(CODE_SPACE,
96  deserializer.set_reservation(MAP_SPACE,
98  deserializer.set_reservation(CELL_SPACE,
100  deserializer.set_reservation(PROPERTY_CELL_SPACE,
102  context_property_cell_space_used);
103  deserializer.set_reservation(LO_SPACE, snapshot_impl_->context_lo_space_used);
104  Object* root;
105  deserializer.DeserializePartial(isolate, &root);
106  CHECK(root->IsContext());
107  return Handle<Context>(Context::cast(root));
108 }
109 
110 
111 void SetSnapshotFromFile(StartupData* snapshot_blob) {
112  DCHECK(snapshot_blob);
113  DCHECK(snapshot_blob->data);
114  DCHECK(snapshot_blob->raw_size > 0);
116 
118  SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data),
119  snapshot_blob->raw_size);
120 
121  bool success = source.GetBlob(&snapshot_impl_->data,
122  &snapshot_impl_->size);
123  snapshot_impl_->new_space_used = source.GetInt();
124  snapshot_impl_->pointer_space_used = source.GetInt();
125  snapshot_impl_->data_space_used = source.GetInt();
126  snapshot_impl_->code_space_used = source.GetInt();
127  snapshot_impl_->map_space_used = source.GetInt();
128  snapshot_impl_->cell_space_used = source.GetInt();
129  snapshot_impl_->property_cell_space_used = source.GetInt();
130  snapshot_impl_->lo_space_used = source.GetInt();
131 
132  success &= source.GetBlob(&snapshot_impl_->context_data,
134  snapshot_impl_->context_new_space_used = source.GetInt();
135  snapshot_impl_->context_pointer_space_used = source.GetInt();
136  snapshot_impl_->context_data_space_used = source.GetInt();
137  snapshot_impl_->context_code_space_used = source.GetInt();
138  snapshot_impl_->context_map_space_used = source.GetInt();
139  snapshot_impl_->context_cell_space_used = source.GetInt();
141 
142  DCHECK(success);
143 }
144 
145 } } // namespace v8::internal
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
int raw_size
Definition: v8.h:4887
const char * data
Definition: v8.h:4885
static Context * cast(Object *context)
Definition: contexts.h:255
static Handle< Context > NewContextFromSnapshot(Isolate *isolate)
static bool Initialize(Isolate *isolate)
static bool HaveASnapshotToStartFrom()
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define CHECK(condition)
Definition: logging.h:36
#define DCHECK(condition)
Definition: logging.h:205
kSerializedDataOffset Object
Definition: objects-inl.h:5322
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
static SnapshotImpl * snapshot_impl_
void SetSnapshotFromFile(StartupData *snapshot_blob)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20