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
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/isolate.h"
|
2015-02-20 09:34:00 +00:00
|
|
|
#include "src/serialize.h"
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#ifndef V8_SNAPSHOT_H_
|
|
|
|
#define V8_SNAPSHOT_H_
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-12-10 14:20:12 +00:00
|
|
|
class Snapshot : public AllStatic {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2015-01-14 11:06:38 +00:00
|
|
|
class Metadata {
|
|
|
|
public:
|
|
|
|
explicit Metadata(uint32_t data = 0) : data_(data) {}
|
|
|
|
bool embeds_script() { return EmbedsScriptBits::decode(data_); }
|
|
|
|
void set_embeds_script(bool v) {
|
|
|
|
data_ = EmbedsScriptBits::update(data_, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t& RawValue() { return data_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
class EmbedsScriptBits : public BitField<bool, 0, 1> {};
|
|
|
|
uint32_t data_;
|
|
|
|
};
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
// Initialize the Isolate from the internal snapshot. Returns false if no
|
|
|
|
// snapshot could be found.
|
|
|
|
static bool Initialize(Isolate* isolate);
|
2014-12-10 11:46:27 +00:00
|
|
|
// Create a new context using the internal partial snapshot.
|
2015-01-13 08:48:00 +00:00
|
|
|
static MaybeHandle<Context> NewContextFromSnapshot(
|
2015-01-14 16:42:15 +00:00
|
|
|
Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
|
|
|
|
Handle<FixedArray>* outdated_contexts_out);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-06-19 18:38:03 +00:00
|
|
|
static bool HaveASnapshotToStartFrom();
|
|
|
|
|
2015-01-14 11:06:38 +00:00
|
|
|
static bool EmbedsScript();
|
|
|
|
|
2015-02-20 09:34:00 +00:00
|
|
|
static uint32_t SizeOfFirstPage(AllocationSpace space);
|
|
|
|
|
2014-12-10 14:20:12 +00:00
|
|
|
// To be implemented by the snapshot source.
|
2014-12-10 11:46:27 +00:00
|
|
|
static const v8::StartupData SnapshotBlob();
|
2010-03-23 11:40:38 +00:00
|
|
|
|
2014-12-10 14:20:12 +00:00
|
|
|
static v8::StartupData CreateSnapshotBlob(
|
2015-02-20 09:34:00 +00:00
|
|
|
const StartupSerializer& startup_ser,
|
|
|
|
const PartialSerializer& context_ser, Snapshot::Metadata metadata);
|
2015-01-14 11:06:38 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static bool SnapshotIsValid(v8::StartupData* snapshot_blob);
|
|
|
|
#endif // DEBUG
|
2014-12-10 14:20:12 +00:00
|
|
|
|
2015-01-14 11:06:38 +00:00
|
|
|
private:
|
2014-12-10 14:20:12 +00:00
|
|
|
static Vector<const byte> ExtractStartupData(const v8::StartupData* data);
|
|
|
|
static Vector<const byte> ExtractContextData(const v8::StartupData* data);
|
2015-01-14 11:06:38 +00:00
|
|
|
static Metadata ExtractMetadata(const v8::StartupData* data);
|
|
|
|
|
2015-02-20 09:34:00 +00:00
|
|
|
// Snapshot blob layout:
|
|
|
|
// [0] metadata
|
|
|
|
// [1 - 6] pre-calculated first page sizes for paged spaces
|
|
|
|
// [7] serialized start up data length
|
|
|
|
// ... serialized start up data
|
|
|
|
// ... serialized context data
|
|
|
|
|
|
|
|
static const int kNumPagedSpaces = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1;
|
|
|
|
|
2015-01-14 11:06:38 +00:00
|
|
|
static const int kMetadataOffset = 0;
|
2015-02-20 09:34:00 +00:00
|
|
|
static const int kFirstPageSizesOffset = kMetadataOffset + kInt32Size;
|
|
|
|
static const int kStartupLengthOffset =
|
|
|
|
kFirstPageSizesOffset + kNumPagedSpaces * kInt32Size;
|
2015-01-14 11:06:38 +00:00
|
|
|
static const int kStartupDataOffset = kStartupLengthOffset + kInt32Size;
|
|
|
|
|
|
|
|
static int ContextOffset(int startup_length) {
|
|
|
|
return kStartupDataOffset + startup_length;
|
|
|
|
}
|
2014-12-10 14:20:12 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
|
|
|
|
};
|
|
|
|
|
2014-06-23 13:52:17 +00:00
|
|
|
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
|
|
|
|
void SetSnapshotFromFile(StartupData* snapshot_blob);
|
|
|
|
#endif
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_SNAPSHOT_H_
|