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-09 15:12:13 +00:00
|
|
|
bool Snapshot::HaveASnapshotToStartFrom() {
|
|
|
|
return SnapshotBlob().data != NULL;
|
|
|
|
}
|
2009-10-27 11:54:01 +00:00
|
|
|
|
2014-12-09 15:12:13 +00:00
|
|
|
|
|
|
|
const Vector<const byte> Snapshot::StartupSnapshot() {
|
|
|
|
DCHECK(HaveASnapshotToStartFrom());
|
|
|
|
const v8::StartupData blob = SnapshotBlob();
|
|
|
|
SnapshotByteSource source(blob.data, blob.raw_size);
|
|
|
|
const byte* data;
|
|
|
|
int length;
|
|
|
|
bool success = source.GetBlob(&data, &length);
|
|
|
|
CHECK(success);
|
|
|
|
return Vector<const byte>(data, length);
|
2009-10-27 11:54:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2014-12-09 15:12:13 +00:00
|
|
|
const Vector<const byte> Snapshot::ContextSnapshot() {
|
|
|
|
DCHECK(HaveASnapshotToStartFrom());
|
|
|
|
const v8::StartupData blob = SnapshotBlob();
|
|
|
|
SnapshotByteSource source(blob.data, blob.raw_size);
|
|
|
|
const byte* data;
|
|
|
|
int length;
|
|
|
|
bool success = source.GetBlob(&data, &length);
|
|
|
|
success &= source.GetBlob(&data, &length);
|
|
|
|
CHECK(success);
|
|
|
|
return Vector<const byte>(data, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Snapshot::Initialize(Isolate* isolate) {
|
|
|
|
if (!HaveASnapshotToStartFrom()) return false;
|
|
|
|
base::ElapsedTimer timer;
|
|
|
|
if (FLAG_profile_deserialization) timer.Start();
|
|
|
|
|
|
|
|
SnapshotData snapshot_data(StartupSnapshot());
|
|
|
|
Deserializer deserializer(&snapshot_data);
|
|
|
|
bool success = isolate->Init(&deserializer);
|
|
|
|
if (FLAG_profile_deserialization) {
|
|
|
|
double ms = timer.Elapsed().InMillisecondsF();
|
|
|
|
PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
|
|
|
|
}
|
|
|
|
return success;
|
2012-06-19 18:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-03 11:54:08 +00:00
|
|
|
Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
|
2014-12-09 15:12:13 +00:00
|
|
|
if (!HaveASnapshotToStartFrom()) return Handle<Context>();
|
2014-12-05 13:03:10 +00:00
|
|
|
|
2014-12-09 15:12:13 +00:00
|
|
|
SnapshotData snapshot_data(ContextSnapshot());
|
2014-12-05 13:03:10 +00:00
|
|
|
Deserializer deserializer(&snapshot_data);
|
2010-03-23 11:40:38 +00:00
|
|
|
Object* root;
|
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));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|