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
|
|
|
|
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 09:50:27 +00:00
|
|
|
if (FLAG_profile_deserialization) timer.Start();
|
|
|
|
|
|
|
|
SnapshotData snapshot_data(data_, size_);
|
|
|
|
Deserializer deserializer(&snapshot_data);
|
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 09:50:27 +00:00
|
|
|
if (context_size_ == 0) return Handle<Context>();
|
|
|
|
|
|
|
|
SnapshotData snapshot_data(context_data_, context_size_);
|
|
|
|
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-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
|