2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// The common functionality when building with or without snapshots.
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/api.h"
|
2014-06-30 13:25:46 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/serialize.h"
|
|
|
|
#include "src/snapshot.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-12-04 10:31:13 +00:00
|
|
|
void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) {
|
|
|
|
deserializer->AddReservation(NEW_SPACE, new_space_used_);
|
|
|
|
deserializer->AddReservation(OLD_POINTER_SPACE, pointer_space_used_);
|
|
|
|
deserializer->AddReservation(OLD_DATA_SPACE, data_space_used_);
|
|
|
|
deserializer->AddReservation(CODE_SPACE, code_space_used_);
|
|
|
|
deserializer->AddReservation(MAP_SPACE, map_space_used_);
|
|
|
|
deserializer->AddReservation(CELL_SPACE, cell_space_used_);
|
|
|
|
deserializer->AddReservation(PROPERTY_CELL_SPACE, property_cell_space_used_);
|
|
|
|
deserializer->AddReservation(LO_SPACE, lo_space_used_);
|
|
|
|
}
|
|
|
|
|
2009-10-27 11:54:01 +00:00
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
bool Snapshot::Initialize(Isolate* isolate) {
|
2014-06-23 13:52:17 +00:00
|
|
|
if (size_ > 0) {
|
2014-06-30 13:25:46 +00:00
|
|
|
base::ElapsedTimer timer;
|
2014-12-04 10:31:13 +00:00
|
|
|
if (FLAG_profile_deserialization) {
|
|
|
|
timer.Start();
|
|
|
|
}
|
|
|
|
SnapshotByteSource source(raw_data_, raw_size_);
|
|
|
|
Deserializer deserializer(&source);
|
|
|
|
ReserveSpaceForLinkedInSnapshot(&deserializer);
|
2014-09-19 08:01:35 +00:00
|
|
|
bool success = isolate->Init(&deserializer);
|
2013-10-02 11:32:19 +00:00
|
|
|
if (FLAG_profile_deserialization) {
|
|
|
|
double ms = timer.Elapsed().InMillisecondsF();
|
|
|
|
PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
|
|
|
|
}
|
|
|
|
return success;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
2009-10-30 10:23:12 +00:00
|
|
|
return false;
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2012-06-19 18:38:03 +00:00
|
|
|
bool Snapshot::HaveASnapshotToStartFrom() {
|
|
|
|
return size_ != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
|
2014-12-04 10:31:13 +00:00
|
|
|
if (context_size_ == 0) {
|
|
|
|
return Handle<Context>();
|
|
|
|
}
|
|
|
|
SnapshotByteSource source(context_raw_data_,
|
|
|
|
context_raw_size_);
|
|
|
|
Deserializer deserializer(&source);
|
2010-03-23 11:40:38 +00:00
|
|
|
Object* root;
|
2014-12-04 10:31:13 +00:00
|
|
|
deserializer.AddReservation(NEW_SPACE, context_new_space_used_);
|
|
|
|
deserializer.AddReservation(OLD_POINTER_SPACE, context_pointer_space_used_);
|
|
|
|
deserializer.AddReservation(OLD_DATA_SPACE, context_data_space_used_);
|
|
|
|
deserializer.AddReservation(CODE_SPACE, context_code_space_used_);
|
|
|
|
deserializer.AddReservation(MAP_SPACE, context_map_space_used_);
|
|
|
|
deserializer.AddReservation(CELL_SPACE, context_cell_space_used_);
|
|
|
|
deserializer.AddReservation(PROPERTY_CELL_SPACE,
|
|
|
|
context_property_cell_space_used_);
|
|
|
|
deserializer.AddReservation(LO_SPACE, context_lo_space_used_);
|
2013-09-03 11:54:08 +00:00
|
|
|
deserializer.DeserializePartial(isolate, &root);
|
2010-03-23 11:40:38 +00:00
|
|
|
CHECK(root->IsContext());
|
|
|
|
return Handle<Context>(Context::cast(root));
|
|
|
|
}
|
|
|
|
|
2014-06-23 13:52:17 +00:00
|
|
|
|
|
|
|
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
|
|
|
|
// Dummy implementations of Set*FromFile(..) APIs.
|
|
|
|
//
|
|
|
|
// These are meant for use with snapshot-external.cc. Should this file
|
|
|
|
// be compiled with those options we just supply these dummy implementations
|
|
|
|
// below. This happens when compiling the mksnapshot utility.
|
|
|
|
void SetNativesFromFile(StartupData* data) { CHECK(false); }
|
|
|
|
void SetSnapshotFromFile(StartupData* data) { CHECK(false); }
|
|
|
|
#endif // V8_USE_EXTERNAL_STARTUP_DATA
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|