Commit 8a8867d3 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

Make snapshot.h usable without objects-inl.h header.

This CL us a pure refactoring that makes an empty compilation unit
including just "snapshot.h" but not "objects-inl.h" compile without
warnings or errors. This is needed to further reduce the header
dependency tangle.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/1287113010

Cr-Commit-Position: refs/heads/master@{#30270}
parent 8533d4b5
......@@ -1372,6 +1372,66 @@ void Serializer::OutputStatistics(const char* name) {
}
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();
......@@ -1533,6 +1593,11 @@ void SerializerDeserializer::Iterate(Isolate* isolate,
}
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();
......@@ -1553,6 +1618,19 @@ int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) {
}
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());
......@@ -1636,6 +1714,17 @@ bool Serializer::SerializeKnownObject(HeapObject* obj, HowToCode how_to_code,
}
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
......@@ -2730,6 +2819,11 @@ SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck(
}
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_);
......
......@@ -6,12 +6,14 @@
#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;
......@@ -308,9 +310,7 @@ class SerializerDeserializer: public ObjectVisitor {
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.
......@@ -653,65 +653,7 @@ class Serializer : public SerializerDeserializer {
#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) {
......@@ -850,17 +792,7 @@ class PartialSerializer : public 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();
......@@ -874,16 +806,7 @@ class PartialSerializer : public Serializer {
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
......@@ -1030,7 +953,7 @@ class SerializedCodeData : public SerializedData {
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
......
......@@ -21,6 +21,13 @@ bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) {
#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();
......
......@@ -6,8 +6,6 @@
#include "src/snapshot/snapshot.h"
#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
namespace v8 {
namespace internal {
......
......@@ -7,7 +7,6 @@
#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
......
......@@ -5,7 +5,6 @@
#ifndef V8_SNAPSHOT_SNAPSHOT_H_
#define V8_SNAPSHOT_SNAPSHOT_H_
#include "src/isolate.h"
#include "src/snapshot/serialize.h"
namespace v8 {
......@@ -41,11 +40,7 @@ class Snapshot : public AllStatic {
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment