Chromium Code Reviews| Index: src/snapshot-external.cc |
| diff --git a/src/snapshot-external.cc b/src/snapshot-external.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2b77bd2fc45c0515204729201d0af33a948e6140 |
| --- /dev/null |
| +++ b/src/snapshot-external.cc |
| @@ -0,0 +1,152 @@ |
| +// Copyright 2006-2008 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Used for building with external snapshots. |
| + |
| +#include "v8.h" |
|
Benedikt Meurer
2014/05/27 04:09:59
Nit: No new v8.h includes if possible.
vogelheim
2014/05/27 15:20:23
Well, I tried, but this uses V8::Initialize(Deseri
Benedikt Meurer
2014/05/29 03:19:59
I see, in that case we'll have to keep that v8.h i
|
| + |
| +#include "serialize.h" |
| +#include "snapshot.h" |
| +#include "snapshot-source-sink.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| + |
| +class SnapshotImpl { |
|
jochen (gone - plz use gerrit)
2014/05/26 14:34:49
should be a struct (and use e.g. data_ instead of
vogelheim
2014/05/27 15:20:23
Done.
|
| + public: |
| + const byte* data_; |
| + int size_; |
| + int new_space_used_; |
| + int pointer_space_used_; |
| + int data_space_used_; |
| + int code_space_used_; |
| + int map_space_used_; |
| + int cell_space_used_; |
| + int property_cell_space_used_; |
| + |
| + const byte* context_data_; |
| + int context_size_; |
| + int context_new_space_used_; |
| + int context_pointer_space_used_; |
| + int context_data_space_used_; |
| + int context_code_space_used_; |
| + int context_map_space_used_; |
| + int context_cell_space_used_; |
| + int context_property_cell_space_used_; |
| + |
| + static SnapshotImpl* impl_; |
|
jochen (gone - plz use gerrit)
2014/05/26 14:34:49
and this should be moved out of SnapshotImpl
vogelheim
2014/05/27 15:20:23
Done.
|
| +}; |
| + |
| + |
| +SnapshotImpl* SnapshotImpl::impl_ = NULL; |
| + |
| + |
| +bool Snapshot::HaveASnapshotToStartFrom() { |
| + return SnapshotImpl::impl_ != NULL; |
| +} |
| + |
| + |
| +bool Snapshot::IsEnabled() { |
| + return HaveASnapshotToStartFrom(); |
| +} |
| + |
| + |
| +bool Snapshot::Initialize() { |
| + if (!HaveASnapshotToStartFrom()) |
| + return false; |
| + |
| + ElapsedTimer timer; |
| + if (FLAG_profile_deserialization) { |
| + timer.Start(); |
| + } |
| + SnapshotByteSource source(SnapshotImpl::impl_->data_, |
| + SnapshotImpl::impl_->size_); |
| + Deserializer deserializer(&source); |
| + deserializer.set_reservation(NEW_SPACE, |
| + SnapshotImpl::impl_->new_space_used_); |
| + deserializer.set_reservation(OLD_POINTER_SPACE, |
| + SnapshotImpl::impl_->pointer_space_used_); |
| + deserializer.set_reservation(OLD_DATA_SPACE, |
| + SnapshotImpl::impl_->data_space_used_); |
| + deserializer.set_reservation(CODE_SPACE, |
| + SnapshotImpl::impl_->code_space_used_); |
| + deserializer.set_reservation(MAP_SPACE, |
| + SnapshotImpl::impl_->map_space_used_); |
| + deserializer.set_reservation(CELL_SPACE, |
| + SnapshotImpl::impl_->cell_space_used_); |
| + deserializer.set_reservation(PROPERTY_CELL_SPACE, |
| + SnapshotImpl::impl_->property_cell_space_used_); |
| + bool success = V8::Initialize(&deserializer); |
| + if (FLAG_profile_deserialization) { |
| + double ms = timer.Elapsed().InMillisecondsF(); |
| + PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); |
| + } |
| + return success; |
| +} |
| + |
| + |
| +Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { |
| + if (!HaveASnapshotToStartFrom()) |
| + return Handle<Context>(); |
| + |
| + SnapshotByteSource source(SnapshotImpl::impl_->context_data_, |
| + SnapshotImpl::impl_->context_size_); |
| + Deserializer deserializer(&source); |
| + deserializer.set_reservation(NEW_SPACE, |
| + SnapshotImpl::impl_->context_new_space_used_); |
| + deserializer.set_reservation(OLD_POINTER_SPACE, |
| + SnapshotImpl::impl_-> |
| + context_pointer_space_used_); |
| + deserializer.set_reservation(OLD_DATA_SPACE, |
| + SnapshotImpl::impl_->context_data_space_used_); |
| + deserializer.set_reservation(CODE_SPACE, |
| + SnapshotImpl::impl_->context_code_space_used_); |
| + deserializer.set_reservation(MAP_SPACE, |
| + SnapshotImpl::impl_->context_map_space_used_); |
| + deserializer.set_reservation(CELL_SPACE, |
| + SnapshotImpl::impl_->context_cell_space_used_); |
| + deserializer.set_reservation(PROPERTY_CELL_SPACE, |
| + SnapshotImpl::impl_-> |
| + context_property_cell_space_used_); |
| + Object* root; |
| + deserializer.DeserializePartial(isolate, &root); |
| + CHECK(root->IsContext()); |
| + return Handle<Context>(Context::cast(root)); |
| +} |
| + |
| + |
| +void SetSnapshotFromFile(StartupData* snapshot_blob) { |
| + ASSERT(snapshot_blob); |
| + ASSERT(snapshot_blob->data); |
| + ASSERT(snapshot_blob->raw_size > 0); |
| + |
| + SnapshotImpl::impl_ = new SnapshotImpl; |
| + SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), |
| + snapshot_blob->raw_size); |
| + |
| + bool success = source.GetBlob(&SnapshotImpl::impl_->data_, |
| + &SnapshotImpl::impl_->size_); |
| + SnapshotImpl::impl_->new_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->pointer_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->data_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->code_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->map_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->cell_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->property_cell_space_used_ = source.GetInt(); |
| + |
| + success &= source.GetBlob(&SnapshotImpl::impl_->context_data_, |
| + &SnapshotImpl::impl_->context_size_); |
| + SnapshotImpl::impl_->context_new_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->context_pointer_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->context_data_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->context_code_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->context_map_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->context_cell_space_used_ = source.GetInt(); |
| + SnapshotImpl::impl_->context_property_cell_space_used_ = source.GetInt(); |
| + |
| + ASSERT(success); |
| +} |
| + |
| +} } // namespace v8::internal |