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
|
|
|
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2014-12-09 16:19:40 +00:00
|
|
|
bool Snapshot::Initialize(Isolate* isolate) {
|
|
|
|
if (size_ > 0) {
|
|
|
|
base::ElapsedTimer timer;
|
|
|
|
if (FLAG_profile_deserialization) timer.Start();
|
|
|
|
|
|
|
|
SnapshotData snapshot_data(data_, size_);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return false;
|
2014-12-09 15:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-09 16:19:40 +00:00
|
|
|
bool Snapshot::HaveASnapshotToStartFrom() {
|
|
|
|
return size_ != 0;
|
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 16:19:40 +00:00
|
|
|
if (context_size_ == 0) return Handle<Context>();
|
2014-12-05 13:03:10 +00:00
|
|
|
|
2014-12-09 16:19:40 +00:00
|
|
|
SnapshotData snapshot_data(context_data_, context_size_);
|
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));
|
|
|
|
}
|
|
|
|
|
2014-12-09 16:19:40 +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
|