}
+class Serializer::ObjectSerializer : public ObjectVisitor {
+ public:
+ ObjectSerializer(Serializer* serializer, Object* o, SnapshotByteSink* sink,
+ HowToCode how_to_code, WhereToPoint where_to_point)
+ : serializer_(serializer),
+ object_(HeapObject::cast(o)),
+ sink_(sink),
+ reference_representation_(how_to_code + where_to_point),
+ bytes_processed_so_far_(0),
+ is_code_object_(o->IsCode()),
+ code_has_been_output_(false) {}
+ void Serialize();
+ void SerializeDeferred();
+ void VisitPointers(Object** start, Object** end);
+ void VisitEmbeddedPointer(RelocInfo* target);
+ void VisitExternalReference(Address* p);
+ void VisitExternalReference(RelocInfo* rinfo);
+ void VisitInternalReference(RelocInfo* rinfo);
+ void VisitCodeTarget(RelocInfo* target);
+ void VisitCodeEntry(Address entry_address);
+ void VisitCell(RelocInfo* rinfo);
+ void VisitRuntimeEntry(RelocInfo* reloc);
+ // Used for seralizing the external strings that hold the natives source.
+ void VisitExternalOneByteString(
+ v8::String::ExternalOneByteStringResource** resource);
+ // We can't serialize a heap with external two byte strings.
+ void VisitExternalTwoByteString(
+ v8::String::ExternalStringResource** resource) {
+ UNREACHABLE();
+ }
+
+ private:
+ void SerializePrologue(AllocationSpace space, int size, Map* map);
+
+ bool SerializeExternalNativeSourceString(
+ int builtin_count,
+ v8::String::ExternalOneByteStringResource** resource_pointer,
+ FixedArray* source_cache, int resource_index);
+
+ enum ReturnSkip { kCanReturnSkipInsteadOfSkipping, kIgnoringReturn };
+ // This function outputs or skips the raw data between the last pointer and
+ // up to the current position. It optionally can just return the number of
+ // bytes to skip instead of performing a skip instruction, in case the skip
+ // can be merged into the next instruction.
+ int OutputRawData(Address up_to, ReturnSkip return_skip = kIgnoringReturn);
+ // External strings are serialized in a way to resemble sequential strings.
+ void SerializeExternalString();
+
+ Address PrepareCode();
+
+ Serializer* serializer_;
+ HeapObject* object_;
+ SnapshotByteSink* sink_;
+ int reference_representation_;
+ int bytes_processed_so_far_;
+ bool is_code_object_;
+ bool code_has_been_output_;
+};
+
+
void Serializer::SerializeDeferredObjects() {
while (deferred_objects_.length() > 0) {
HeapObject* obj = deferred_objects_.RemoveLast();
}
+bool SerializerDeserializer::CanBeDeferred(HeapObject* o) {
+ return !o->IsString() && !o->IsScript();
+}
+
+
int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
Isolate* isolate = this->isolate();
List<Object*>* cache = isolate->partial_snapshot_cache();
}
+bool PartialSerializer::ShouldBeInThePartialSnapshotCache(HeapObject* o) {
+ // Scripts should be referred only through shared function infos. We can't
+ // allow them to be part of the partial snapshot because they contain a
+ // unique ID, and deserializing several partial snapshots containing script
+ // would cause dupes.
+ DCHECK(!o->IsScript());
+ return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() ||
+ o->IsCode() || o->IsScopeInfo() || o->IsExecutableAccessorInfo() ||
+ o->map() ==
+ startup_serializer_->isolate()->heap()->fixed_cow_array_map();
+}
+
+
#ifdef DEBUG
bool Serializer::BackReferenceIsAlreadyAllocated(BackReference reference) {
DCHECK(reference.is_valid());
}
+StartupSerializer::StartupSerializer(Isolate* isolate, SnapshotByteSink* sink)
+ : Serializer(isolate, sink), root_index_wave_front_(0) {
+ // Clear the cache of objects used by the partial snapshot. After the
+ // strong roots have been serialized we can create a partial snapshot
+ // which will repopulate the cache with objects needed by that partial
+ // snapshot.
+ isolate->partial_snapshot_cache()->Clear();
+ InitializeCodeAddressMap();
+}
+
+
void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
WhereToPoint where_to_point, int skip) {
// Make sure that all functions are derived from the code-stub context
}
+uint32_t SerializedCodeData::SourceHash(String* source) const {
+ return source->length();
+}
+
+
// Return ScriptData object and relinquish ownership over it to the caller.
ScriptData* SerializedCodeData::GetScriptData() {
DCHECK(owns_data_);
#define V8_SNAPSHOT_SERIALIZE_H_
#include "src/hashmap.h"
-#include "src/isolate.h"
+#include "src/heap/heap.h"
+#include "src/objects.h"
#include "src/snapshot/snapshot-source-sink.h"
namespace v8 {
namespace internal {
+class Isolate;
class ScriptData;
static const int kDeoptTableSerializeEntryCount = 64;
static const int kNumberOfSpaces = LAST_SPACE + 1;
protected:
- static bool CanBeDeferred(HeapObject* o) {
- return !o->IsString() && !o->IsScript();
- }
+ static bool CanBeDeferred(HeapObject* o);
// ---------- byte code range 0x00..0x7f ----------
// Byte codes in this range represent Where, HowToCode and WhereToPoint.
#endif // OBJECT_PRINT
protected:
- class ObjectSerializer : public ObjectVisitor {
- public:
- ObjectSerializer(Serializer* serializer, Object* o, SnapshotByteSink* sink,
- HowToCode how_to_code, WhereToPoint where_to_point)
- : serializer_(serializer),
- object_(HeapObject::cast(o)),
- sink_(sink),
- reference_representation_(how_to_code + where_to_point),
- bytes_processed_so_far_(0),
- is_code_object_(o->IsCode()),
- code_has_been_output_(false) {}
- void Serialize();
- void SerializeDeferred();
- void VisitPointers(Object** start, Object** end);
- void VisitEmbeddedPointer(RelocInfo* target);
- void VisitExternalReference(Address* p);
- void VisitExternalReference(RelocInfo* rinfo);
- void VisitInternalReference(RelocInfo* rinfo);
- void VisitCodeTarget(RelocInfo* target);
- void VisitCodeEntry(Address entry_address);
- void VisitCell(RelocInfo* rinfo);
- void VisitRuntimeEntry(RelocInfo* reloc);
- // Used for seralizing the external strings that hold the natives source.
- void VisitExternalOneByteString(
- v8::String::ExternalOneByteStringResource** resource);
- // We can't serialize a heap with external two byte strings.
- void VisitExternalTwoByteString(
- v8::String::ExternalStringResource** resource) {
- UNREACHABLE();
- }
-
- private:
- void SerializePrologue(AllocationSpace space, int size, Map* map);
-
- bool SerializeExternalNativeSourceString(
- int builtin_count,
- v8::String::ExternalOneByteStringResource** resource_pointer,
- FixedArray* source_cache, int resource_index);
-
- enum ReturnSkip { kCanReturnSkipInsteadOfSkipping, kIgnoringReturn };
- // This function outputs or skips the raw data between the last pointer and
- // up to the current position. It optionally can just return the number of
- // bytes to skip instead of performing a skip instruction, in case the skip
- // can be merged into the next instruction.
- int OutputRawData(Address up_to, ReturnSkip return_skip = kIgnoringReturn);
- // External strings are serialized in a way to resemble sequential strings.
- void SerializeExternalString();
-
- Address PrepareCode();
-
- Serializer* serializer_;
- HeapObject* object_;
- SnapshotByteSink* sink_;
- int reference_representation_;
- int bytes_processed_so_far_;
- bool is_code_object_;
- bool code_has_been_output_;
- };
-
+ class ObjectSerializer;
class RecursionScope {
public:
explicit RecursionScope(Serializer* serializer) : serializer_(serializer) {
private:
int PartialSnapshotCacheIndex(HeapObject* o);
- bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
- // Scripts should be referred only through shared function infos. We can't
- // allow them to be part of the partial snapshot because they contain a
- // unique ID, and deserializing several partial snapshots containing script
- // would cause dupes.
- DCHECK(!o->IsScript());
- return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() ||
- o->IsCode() || o->IsScopeInfo() || o->IsExecutableAccessorInfo() ||
- o->map() ==
- startup_serializer_->isolate()->heap()->fixed_cow_array_map();
- }
+ bool ShouldBeInThePartialSnapshotCache(HeapObject* o);
void SerializeOutdatedContextsAsFixedArray();
class StartupSerializer : public Serializer {
public:
- StartupSerializer(Isolate* isolate, SnapshotByteSink* sink)
- : Serializer(isolate, sink), root_index_wave_front_(0) {
- // Clear the cache of objects used by the partial snapshot. After the
- // strong roots have been serialized we can create a partial snapshot
- // which will repopulate the cache with objects needed by that partial
- // snapshot.
- isolate->partial_snapshot_cache()->Clear();
- InitializeCodeAddressMap();
- }
-
+ StartupSerializer(Isolate* isolate, SnapshotByteSink* sink);
~StartupSerializer() { OutputStatistics("StartupSerializer"); }
// The StartupSerializer has to serialize the root array, which is slightly
SanityCheckResult SanityCheck(Isolate* isolate, String* source) const;
- uint32_t SourceHash(String* source) const { return source->length(); }
+ uint32_t SourceHash(String* source) const;
// The data header consists of uint32_t-sized entries:
// [0] magic number and external reference count
#endif // DEBUG
+bool Snapshot::HaveASnapshotToStartFrom(Isolate* isolate) {
+ // Do not use snapshots if the isolate is used to create snapshots.
+ return isolate->snapshot_blob() != NULL &&
+ isolate->snapshot_blob()->data != NULL;
+}
+
+
bool Snapshot::EmbedsScript(Isolate* isolate) {
if (!isolate->snapshot_available()) return false;
return ExtractMetadata(isolate->snapshot_blob()).embeds_script();
#include "src/snapshot/snapshot.h"
-#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
-
namespace v8 {
namespace internal {
#include "src/snapshot/snapshot.h"
#include "src/base/platform/mutex.h"
-#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
#include "src/snapshot/serialize.h"
#include "src/snapshot/snapshot-source-sink.h"
#include "src/v8.h" // for V8::Initialize
#ifndef V8_SNAPSHOT_SNAPSHOT_H_
#define V8_SNAPSHOT_SNAPSHOT_H_
-#include "src/isolate.h"
#include "src/snapshot/serialize.h"
namespace v8 {
Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
Handle<FixedArray>* outdated_contexts_out);
- static bool HaveASnapshotToStartFrom(Isolate* isolate) {
- // Do not use snapshots if the isolate is used to create snapshots.
- return isolate->snapshot_blob() != NULL &&
- isolate->snapshot_blob()->data != NULL;
- }
+ static bool HaveASnapshotToStartFrom(Isolate* isolate);
static bool EmbedsScript(Isolate* isolate);