Commit 60f8b7a8 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[snapshot][cleanup] Remove WhereToPoint flag from bytecodes

... as it's no longer needed.

Bug: v8:8794, v8:8562
Change-Id: Ifbc4f5f5d34f24ff4ba8f32309e8a032268c12c0
Reviewed-on: https://chromium-review.googlesource.com/c/1460457
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59461}
parent 9afefcbc
......@@ -97,8 +97,7 @@ ScriptData* CodeSerializer::SerializeSharedFunctionInfo(
}
bool CodeSerializer::SerializeReadOnlyObject(HeapObject obj,
HowToCode how_to_code,
WhereToPoint where_to_point) {
HowToCode how_to_code) {
PagedSpace* read_only_space = isolate()->heap()->read_only_space();
if (!read_only_space->Contains(obj)) return false;
......@@ -116,19 +115,18 @@ bool CodeSerializer::SerializeReadOnlyObject(HeapObject obj,
SerializerReference back_reference =
SerializerReference::BackReference(RO_SPACE, chunk_index, chunk_offset);
reference_map()->Add(reinterpret_cast<void*>(obj->ptr()), back_reference);
CHECK(SerializeBackReference(obj, how_to_code, where_to_point));
CHECK(SerializeBackReference(obj, how_to_code));
return true;
}
void CodeSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
if (SerializeHotObject(obj, how_to_code, where_to_point)) return;
void CodeSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code) {
if (SerializeHotObject(obj, how_to_code)) return;
if (SerializeRoot(obj, how_to_code, where_to_point)) return;
if (SerializeRoot(obj, how_to_code)) return;
if (SerializeBackReference(obj, how_to_code, where_to_point)) return;
if (SerializeBackReference(obj, how_to_code)) return;
if (SerializeReadOnlyObject(obj, how_to_code, where_to_point)) return;
if (SerializeReadOnlyObject(obj, how_to_code)) return;
if (obj->IsCode()) {
Code code_object = Code::cast(obj);
......@@ -141,15 +139,14 @@ void CodeSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
case Code::STUB:
case Code::BUILTIN:
default:
return SerializeCodeObject(code_object, how_to_code, where_to_point);
return SerializeCodeObject(code_object, how_to_code);
}
UNREACHABLE();
}
ReadOnlyRoots roots(isolate());
if (ElideObject(obj)) {
return SerializeObject(roots.undefined_value(), how_to_code,
where_to_point);
return SerializeObject(roots.undefined_value(), how_to_code);
}
if (obj->IsScript()) {
......@@ -167,7 +164,7 @@ void CodeSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
// object graph.
FixedArray host_options = script_obj->host_defined_options();
script_obj->set_host_defined_options(roots.empty_fixed_array());
SerializeGeneric(obj, how_to_code, where_to_point);
SerializeGeneric(obj, how_to_code);
script_obj->set_host_defined_options(host_options);
script_obj->set_context_data(context_data);
return;
......@@ -192,7 +189,7 @@ void CodeSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
}
DCHECK(!sfi->HasDebugInfo());
SerializeGeneric(obj, how_to_code, where_to_point);
SerializeGeneric(obj, how_to_code);
// Restore debug info
if (!debug_info.is_null()) {
......@@ -218,15 +215,13 @@ void CodeSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
// We expect no instantiated function objects or contexts.
CHECK(!obj->IsJSFunction() && !obj->IsContext());
SerializeGeneric(obj, how_to_code, where_to_point);
SerializeGeneric(obj, how_to_code);
}
void CodeSerializer::SerializeGeneric(HeapObject heap_object,
HowToCode how_to_code,
WhereToPoint where_to_point) {
HowToCode how_to_code) {
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this, heap_object, &sink_, how_to_code,
where_to_point);
ObjectSerializer serializer(this, heap_object, &sink_, how_to_code);
serializer.Serialize();
}
......
......@@ -58,21 +58,17 @@ class CodeSerializer : public Serializer {
CodeSerializer(Isolate* isolate, uint32_t source_hash);
~CodeSerializer() override { OutputStatistics("CodeSerializer"); }
virtual void SerializeCodeObject(Code code_object, HowToCode how_to_code,
WhereToPoint where_to_point) {
virtual void SerializeCodeObject(Code code_object, HowToCode how_to_code) {
UNREACHABLE();
}
virtual bool ElideObject(Object obj) { return false; }
void SerializeGeneric(HeapObject heap_object, HowToCode how_to_code,
WhereToPoint where_to_point);
void SerializeGeneric(HeapObject heap_object, HowToCode how_to_code);
private:
void SerializeObject(HeapObject o, HowToCode how_to_code,
WhereToPoint where_to_point) override;
void SerializeObject(HeapObject o, HowToCode how_to_code) override;
bool SerializeReadOnlyObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point);
bool SerializeReadOnlyObject(HeapObject obj, HowToCode how_to_code);
DISALLOW_HEAP_ALLOCATION(no_gc_);
uint32_t source_hash_;
......
......@@ -442,15 +442,14 @@ void Deserializer::VisitRuntimeEntry(Code host, RelocInfo* rinfo) {
void Deserializer::VisitExternalReference(Code host, RelocInfo* rinfo) {
byte data = source_.Get();
CHECK(data == kExternalReference + kPlain + kStartOfObject ||
data == kExternalReference + kFromCode + kStartOfObject);
CHECK(data == kExternalReference + kPlain ||
data == kExternalReference + kFromCode);
uint32_t reference_id = static_cast<uint32_t>(source_.GetInt());
Address address = external_reference_table_->address(reference_id);
DCHECK_EQ(rinfo->IsCodedSpecially(),
data == kExternalReference + kFromCode + kStartOfObject);
if (data == kExternalReference + kFromCode + kStartOfObject) {
DCHECK_EQ(rinfo->IsCodedSpecially(), data == kExternalReference + kFromCode);
if (data == kExternalReference + kFromCode) {
Address location_of_branch_data = rinfo->pc();
Assembler::deserialization_set_special_target_at(location_of_branch_data,
host, address);
......@@ -537,34 +536,33 @@ bool Deserializer::ReadData(UnalignedSlot current, UnalignedSlot limit,
while (current < limit) {
byte data = source_.Get();
switch (data) {
#define CASE_STATEMENT(where, how, within, space_number) \
case where + how + within + space_number: \
STATIC_ASSERT((where & ~kWhereMask) == 0); \
STATIC_ASSERT((how & ~kHowToCodeMask) == 0); \
STATIC_ASSERT((within & ~kWhereToPointMask) == 0); \
#define CASE_STATEMENT(where, how, space_number) \
case where + how + space_number: \
STATIC_ASSERT((where & ~kWhereMask) == 0); \
STATIC_ASSERT((how & ~kHowToCodeMask) == 0); \
STATIC_ASSERT((space_number & ~kSpaceMask) == 0);
#define CASE_BODY(where, how, within, space_number_if_any) \
current = ReadDataCase<where, how, within, space_number_if_any>( \
#define CASE_BODY(where, how, space_number_if_any) \
current = ReadDataCase<where, space_number_if_any>( \
isolate, current, current_object_address, data, write_barrier_needed); \
break;
// This generates a case and a body for the new space (which has to do extra
// write barrier handling) and handles the other spaces with fall-through cases
// and one body.
#define ALL_SPACES(where, how, within) \
CASE_STATEMENT(where, how, within, NEW_SPACE) \
CASE_BODY(where, how, within, NEW_SPACE) \
CASE_STATEMENT(where, how, within, OLD_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, within, CODE_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, within, MAP_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, within, LO_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, within, RO_SPACE) \
CASE_BODY(where, how, within, kAnyOldSpace)
#define ALL_SPACES(where, how) \
CASE_STATEMENT(where, how, NEW_SPACE) \
CASE_BODY(where, how, NEW_SPACE) \
CASE_STATEMENT(where, how, OLD_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, CODE_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, MAP_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, LO_SPACE) \
V8_FALLTHROUGH; \
CASE_STATEMENT(where, how, RO_SPACE) \
CASE_BODY(where, how, kAnyOldSpace)
#define FOUR_CASES(byte_code) \
case byte_code: \
......@@ -578,58 +576,43 @@ bool Deserializer::ReadData(UnalignedSlot current, UnalignedSlot limit,
FOUR_CASES(byte_code + 8) \
FOUR_CASES(byte_code + 12)
#define SINGLE_CASE(where, how, within, space) \
CASE_STATEMENT(where, how, within, space) \
CASE_BODY(where, how, within, space)
#define SINGLE_CASE(where, how, space) \
CASE_STATEMENT(where, how, space) \
CASE_BODY(where, how, space)
// Deserialize a new object and write a pointer to it to the current
// object.
ALL_SPACES(kNewObject, kPlain, kStartOfObject)
ALL_SPACES(kNewObject, kPlain)
// Deserialize a new code object and write a pointer to its first
// instruction to the current code object.
ALL_SPACES(kNewObject, kFromCode, kInnerPointer)
ALL_SPACES(kNewObject, kFromCode)
// Find a recently deserialized object using its offset from the current
// allocation point and write a pointer to it to the current object.
ALL_SPACES(kBackref, kPlain, kStartOfObject)
#if V8_CODE_EMBEDS_OBJECT_POINTER
// Deserialize a new object from pointer found in code and write
// a pointer to it to the current object. Required only for MIPS, PPC, ARM
// or S390 with embedded constant pool, and omitted on the other
// architectures because it is fully unrolled and would cause bloat.
ALL_SPACES(kNewObject, kFromCode, kStartOfObject)
// Find a recently deserialized code object using its offset from the
// current allocation point and write a pointer to it to the current
// object. Required only for MIPS, PPC, ARM or S390 with embedded
// constant pool.
ALL_SPACES(kBackref, kFromCode, kStartOfObject)
#endif
ALL_SPACES(kBackref, kPlain)
// Find a recently deserialized code object using its offset from the
// current allocation point and write a pointer to its first instruction
// to the current code object or the instruction pointer in a function
// object.
ALL_SPACES(kBackref, kFromCode, kInnerPointer)
ALL_SPACES(kBackref, kFromCode)
// Find an object in the roots array and write a pointer to it to the
// current object.
SINGLE_CASE(kRootArray, kPlain, kStartOfObject, 0)
SINGLE_CASE(kRootArray, kPlain, 0)
#if V8_CODE_EMBEDS_OBJECT_POINTER
// Find an object in the roots array and write a pointer to it to in code.
SINGLE_CASE(kRootArray, kFromCode, kStartOfObject, 0)
SINGLE_CASE(kRootArray, kFromCode, 0)
#endif
// Find an object in the partial snapshots cache and write a pointer to it
// to the current object.
SINGLE_CASE(kPartialSnapshotCache, kPlain, kStartOfObject, 0)
SINGLE_CASE(kPartialSnapshotCache, kFromCode, kStartOfObject, 0)
SINGLE_CASE(kPartialSnapshotCache, kFromCode, kInnerPointer, 0)
SINGLE_CASE(kPartialSnapshotCache, kPlain, 0)
SINGLE_CASE(kPartialSnapshotCache, kFromCode, 0)
// Find an object in the partial snapshots cache and write a pointer to it
// to the current object.
SINGLE_CASE(kReadOnlyObjectCache, kPlain, kStartOfObject, 0)
SINGLE_CASE(kReadOnlyObjectCache, kFromCode, kStartOfObject, 0)
SINGLE_CASE(kReadOnlyObjectCache, kFromCode, kInnerPointer, 0)
SINGLE_CASE(kReadOnlyObjectCache, kPlain, 0)
SINGLE_CASE(kReadOnlyObjectCache, kFromCode, 0)
// Find an object in the attached references and write a pointer to it to
// the current object.
SINGLE_CASE(kAttachedReference, kPlain, kStartOfObject, 0)
SINGLE_CASE(kAttachedReference, kFromCode, kStartOfObject, 0)
SINGLE_CASE(kAttachedReference, kFromCode, kInnerPointer, 0)
SINGLE_CASE(kAttachedReference, kPlain, 0)
SINGLE_CASE(kAttachedReference, kFromCode, 0)
#undef CASE_STATEMENT
#undef CASE_BODY
......@@ -637,13 +620,11 @@ bool Deserializer::ReadData(UnalignedSlot current, UnalignedSlot limit,
// Find an external reference and write a pointer to it to the current
// object.
case kExternalReference + kPlain + kStartOfObject:
case kExternalReference + kPlain:
current =
ReadExternalReferenceCase(kPlain, current, current_object_address);
break;
// Find an external reference and write a pointer to it in the current
// code object.
case kExternalReference + kFromCode + kStartOfObject:
case kExternalReference + kFromCode:
UNREACHABLE();
break;
......@@ -847,7 +828,7 @@ UnalignedSlot Deserializer::ReadExternalReferenceCase(
return current;
}
template <int where, int how, int within, int space_number_if_any>
template <SerializerDeserializer::Where where, int space_number_if_any>
UnalignedSlot Deserializer::ReadDataCase(Isolate* isolate,
UnalignedSlot current,
Address current_object_address,
......
......@@ -126,7 +126,7 @@ class Deserializer : public SerializerDeserializer {
// A helper function for ReadData, templatized on the bytecode for efficiency.
// Returns the new value of {current}.
template <int where, int how, int within, int space_number_if_any>
template <Where where, int space_number_if_any>
inline UnalignedSlot ReadDataCase(Isolate* isolate, UnalignedSlot current,
Address current_object_address, byte data,
bool write_barrier_needed);
......
......@@ -68,24 +68,23 @@ void PartialSerializer::Serialize(Context* o, bool include_global_proxy) {
Pad();
}
void PartialSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
void PartialSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code) {
DCHECK(!ObjectIsBytecodeHandler(obj)); // Only referenced in dispatch table.
if (SerializeHotObject(obj, how_to_code, where_to_point)) return;
if (SerializeHotObject(obj, how_to_code)) return;
if (SerializeRoot(obj, how_to_code, where_to_point)) return;
if (SerializeRoot(obj, how_to_code)) return;
if (SerializeBackReference(obj, how_to_code, where_to_point)) return;
if (SerializeBackReference(obj, how_to_code)) return;
if (startup_serializer_->SerializeUsingReadOnlyObjectCache(
&sink_, obj, how_to_code, where_to_point)) {
if (startup_serializer_->SerializeUsingReadOnlyObjectCache(&sink_, obj,
how_to_code)) {
return;
}
if (ShouldBeInThePartialSnapshotCache(obj)) {
startup_serializer_->SerializeUsingPartialSnapshotCache(
&sink_, obj, how_to_code, where_to_point);
startup_serializer_->SerializeUsingPartialSnapshotCache(&sink_, obj,
how_to_code);
return;
}
......@@ -104,7 +103,7 @@ void PartialSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
// Clear literal boilerplates and feedback.
if (obj->IsFeedbackVector()) FeedbackVector::cast(obj)->ClearSlots(isolate());
if (SerializeJSObjectWithEmbedderFields(obj, how_to_code, where_to_point)) {
if (SerializeJSObjectWithEmbedderFields(obj, how_to_code)) {
return;
}
......@@ -119,7 +118,7 @@ void PartialSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
CheckRehashability(obj);
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point);
ObjectSerializer serializer(this, obj, &sink_, how_to_code);
serializer.Serialize();
}
......@@ -141,7 +140,7 @@ bool DataIsEmpty(const StartupData& data) { return data.raw_size == 0; }
} // anonymous namespace
bool PartialSerializer::SerializeJSObjectWithEmbedderFields(
Object obj, HowToCode how_to_code, WhereToPoint where_to_point) {
Object obj, HowToCode how_to_code) {
if (!obj->IsJSObject()) return false;
JSObject js_obj = JSObject::cast(obj);
int embedder_fields_count = js_obj->GetEmbedderFieldCount();
......@@ -192,8 +191,7 @@ bool PartialSerializer::SerializeJSObjectWithEmbedderFields(
// 3) Serialize the object. References from embedder fields to heap objects or
// smis are serialized regularly.
ObjectSerializer(this, js_obj, &sink_, how_to_code, where_to_point)
.Serialize();
ObjectSerializer(this, js_obj, &sink_, how_to_code).Serialize();
// 4) Obtain back reference for the serialized object.
SerializerReference reference =
......
......@@ -27,13 +27,11 @@ class PartialSerializer : public Serializer {
bool can_be_rehashed() const { return can_be_rehashed_; }
private:
void SerializeObject(HeapObject o, HowToCode how_to_code,
WhereToPoint where_to_point) override;
void SerializeObject(HeapObject o, HowToCode how_to_code) override;
bool ShouldBeInThePartialSnapshotCache(HeapObject o);
bool SerializeJSObjectWithEmbedderFields(Object obj, HowToCode how_to_code,
WhereToPoint where_to_point);
bool SerializeJSObjectWithEmbedderFields(Object obj, HowToCode how_to_code);
void CheckRehashability(HeapObject obj);
......
......@@ -24,23 +24,21 @@ ReadOnlySerializer::~ReadOnlySerializer() {
OutputStatistics("ReadOnlySerializer");
}
void ReadOnlySerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
void ReadOnlySerializer::SerializeObject(HeapObject obj,
HowToCode how_to_code) {
CHECK(isolate()->heap()->read_only_space()->Contains(obj));
CHECK_IMPLIES(obj->IsString(), obj->IsInternalizedString());
if (SerializeHotObject(obj, how_to_code, where_to_point)) return;
if (IsRootAndHasBeenSerialized(obj) &&
SerializeRoot(obj, how_to_code, where_to_point)) {
if (SerializeHotObject(obj, how_to_code)) return;
if (IsRootAndHasBeenSerialized(obj) && SerializeRoot(obj, how_to_code)) {
return;
}
if (SerializeBackReference(obj, how_to_code, where_to_point)) return;
if (SerializeBackReference(obj, how_to_code)) return;
CheckRehashability(obj);
// Object has not yet been serialized. Serialize it here.
ObjectSerializer object_serializer(this, obj, &sink_, how_to_code,
where_to_point);
ObjectSerializer object_serializer(this, obj, &sink_, how_to_code);
object_serializer.Serialize();
}
......@@ -81,8 +79,7 @@ bool ReadOnlySerializer::MustBeDeferred(HeapObject object) {
}
bool ReadOnlySerializer::SerializeUsingReadOnlyObjectCache(
SnapshotByteSink* sink, HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
SnapshotByteSink* sink, HeapObject obj, HowToCode how_to_code) {
if (!isolate()->heap()->read_only_space()->Contains(obj)) return false;
// Get the cache index and serialize it into the read-only snapshot if
......@@ -90,8 +87,7 @@ bool ReadOnlySerializer::SerializeUsingReadOnlyObjectCache(
int cache_index = SerializeInObjectCache(obj);
// Writing out the cache entry into the calling serializer's sink.
sink->Put(kReadOnlyObjectCache + how_to_code + where_to_point,
"ReadOnlyObjectCache");
sink->Put(kReadOnlyObjectCache + how_to_code, "ReadOnlyObjectCache");
sink->PutInt(cache_index, "read_only_object_cache_index");
return true;
......
......@@ -29,12 +29,10 @@ class ReadOnlySerializer : public RootsSerializer {
// ReadOnlyObjectCache bytecode into |sink|. Returns whether this was
// successful.
bool SerializeUsingReadOnlyObjectCache(SnapshotByteSink* sink, HeapObject obj,
HowToCode how_to_code,
WhereToPoint where_to_point);
HowToCode how_to_code);
private:
void SerializeObject(HeapObject o, HowToCode how_to_code,
WhereToPoint where_to_point) override;
void SerializeObject(HeapObject o, HowToCode how_to_code) override;
bool MustBeDeferred(HeapObject object) override;
DISALLOW_COPY_AND_ASSIGN(ReadOnlySerializer);
......
......@@ -28,7 +28,7 @@ int RootsSerializer::SerializeInObjectCache(HeapObject heap_object) {
if (!object_cache_index_map_.LookupOrInsert(heap_object, &index)) {
// This object is not part of the object cache yet. Add it to the cache so
// we can refer to it via cache index from the delegating snapshot.
SerializeObject(heap_object, kPlain, kStartOfObject);
SerializeObject(heap_object, kPlain);
}
return index;
}
......
......@@ -147,8 +147,8 @@ class SerializerDeserializer : public RootVisitor {
V(0x7b) \
V(0x7c)
// ---------- byte code range 0x00..0x7f ----------
// Byte codes in this range represent Where, HowToCode and WhereToPoint.
// ---------- byte code range 0x00..0x3f ----------
// Byte codes in this range represent Where and HowToCode.
// Where the pointed-to object can be found:
// The static assert below will trigger when the number of preallocated spaces
// changed. If that happens, update the bytecode ranges in the comments below.
......@@ -189,16 +189,6 @@ class SerializerDeserializer : public RootVisitor {
static const int kHowToCodeMask = 0x20;
// Where to point within the object.
enum WhereToPoint {
// Points to start of object
kStartOfObject = 0,
// Points to instruction in code object or payload of cell.
kInnerPointer = 0x40
};
static const int kWhereToPointMask = 0x40;
// ---------- Misc ----------
// Do nothing, used for padding.
static const int kNop = 0x2f;
......
......@@ -91,7 +91,7 @@ void Serializer::SerializeDeferredObjects() {
while (!deferred_objects_.empty()) {
HeapObject obj = deferred_objects_.back();
deferred_objects_.pop_back();
ObjectSerializer obj_serializer(this, obj, &sink_, kPlain, kStartOfObject);
ObjectSerializer obj_serializer(this, obj, &sink_, kPlain);
obj_serializer.SerializeDeferred();
}
sink_.Put(kSynchronize, "Finished with deferred objects");
......@@ -110,7 +110,7 @@ void Serializer::SerializeRootObject(Object object) {
if (object->IsSmi()) {
PutSmi(Smi::cast(object));
} else {
SerializeObject(HeapObject::cast(object), kPlain, kStartOfObject);
SerializeObject(HeapObject::cast(object), kPlain);
}
}
......@@ -123,21 +123,19 @@ void Serializer::PrintStack() {
}
#endif // DEBUG
bool Serializer::SerializeRoot(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
bool Serializer::SerializeRoot(HeapObject obj, HowToCode how_to_code) {
RootIndex root_index;
// Derived serializers are responsible for determining if the root has
// actually been serialized before calling this.
if (root_index_map()->Lookup(obj, &root_index)) {
PutRoot(root_index, obj, how_to_code, where_to_point);
PutRoot(root_index, obj, how_to_code);
return true;
}
return false;
}
bool Serializer::SerializeHotObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
if (how_to_code != kPlain || where_to_point != kStartOfObject) return false;
bool Serializer::SerializeHotObject(HeapObject obj, HowToCode how_to_code) {
if (how_to_code != kPlain) return false;
// Encode a reference to a hot object by its index in the working set.
int index = hot_objects_.Find(obj);
if (index == HotObjectsList::kNotFound) return false;
......@@ -152,8 +150,7 @@ bool Serializer::SerializeHotObject(HeapObject obj, HowToCode how_to_code,
return true;
}
bool Serializer::SerializeBackReference(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
bool Serializer::SerializeBackReference(HeapObject obj, HowToCode how_to_code) {
SerializerReference reference =
reference_map_.LookupReference(reinterpret_cast<void*>(obj.ptr()));
if (!reference.is_valid()) return false;
......@@ -166,7 +163,7 @@ bool Serializer::SerializeBackReference(HeapObject obj, HowToCode how_to_code,
PrintF(" Encoding attached reference %d\n",
reference.attached_reference_index());
}
PutAttachedReference(reference, how_to_code, where_to_point);
PutAttachedReference(reference, how_to_code);
} else {
DCHECK(reference.is_back_reference());
if (FLAG_trace_serializer) {
......@@ -177,7 +174,7 @@ bool Serializer::SerializeBackReference(HeapObject obj, HowToCode how_to_code,
PutAlignmentPrefix(obj);
AllocationSpace space = reference.space();
sink_.Put(kBackref + how_to_code + where_to_point + space, "BackRef");
sink_.Put(kBackref + how_to_code + space, "BackRef");
PutBackReference(obj, reference);
}
return true;
......@@ -189,8 +186,7 @@ bool Serializer::ObjectIsBytecodeHandler(HeapObject obj) const {
}
void Serializer::PutRoot(RootIndex root, HeapObject object,
SerializerDeserializer::HowToCode how_to_code,
SerializerDeserializer::WhereToPoint where_to_point) {
SerializerDeserializer::HowToCode how_to_code) {
int root_index = static_cast<int>(root);
if (FLAG_trace_serializer) {
PrintF(" Encoding root %d:", root_index);
......@@ -204,12 +200,11 @@ void Serializer::PutRoot(RootIndex root, HeapObject object,
kNumberOfRootArrayConstants - 1);
// TODO(ulan): Check that it works with young large objects.
if (how_to_code == kPlain && where_to_point == kStartOfObject &&
root_index < kNumberOfRootArrayConstants &&
if (how_to_code == kPlain && root_index < kNumberOfRootArrayConstants &&
!Heap::InYoungGeneration(object)) {
sink_.Put(kRootArrayConstants + root_index, "RootConstant");
} else {
sink_.Put(kRootArray + how_to_code + where_to_point, "RootSerialization");
sink_.Put(kRootArray + how_to_code, "RootSerialization");
sink_.PutInt(root_index, "root_index");
hot_objects_.Add(object);
}
......@@ -245,13 +240,9 @@ void Serializer::PutBackReference(HeapObject object,
}
void Serializer::PutAttachedReference(SerializerReference reference,
HowToCode how_to_code,
WhereToPoint where_to_point) {
HowToCode how_to_code) {
DCHECK(reference.is_attached_reference());
DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) ||
(how_to_code == kFromCode && where_to_point == kStartOfObject) ||
(how_to_code == kFromCode && where_to_point == kInnerPointer));
sink_.Put(kAttachedReference + how_to_code + where_to_point, "AttachedRef");
sink_.Put(kAttachedReference + how_to_code, "AttachedRef");
sink_.PutInt(reference.attached_reference_index(), "AttachedRefIndex");
}
......@@ -349,7 +340,7 @@ void Serializer::ObjectSerializer::SerializePrologue(AllocationSpace space,
back_reference);
// Serialize the map (first word of the object).
serializer_->SerializeObject(map, kPlain, kStartOfObject);
serializer_->SerializeObject(map, kPlain);
}
int32_t Serializer::ObjectSerializer::SerializeBackingStore(
......@@ -708,7 +699,7 @@ void Serializer::ObjectSerializer::VisitPointers(HeapObject host,
if (reference_type == HeapObjectReferenceType::WEAK) {
sink_->Put(kWeakPrefix, "WeakReference");
}
serializer_->SerializeObject(current_contents, kPlain, kStartOfObject);
serializer_->SerializeObject(current_contents, kPlain);
}
}
}
......@@ -717,8 +708,7 @@ void Serializer::ObjectSerializer::VisitEmbeddedPointer(Code host,
RelocInfo* rinfo) {
HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
Object object = rinfo->target_object();
serializer_->SerializeObject(HeapObject::cast(object), how_to_code,
kStartOfObject);
serializer_->SerializeObject(HeapObject::cast(object), how_to_code);
bytes_processed_so_far_ += rinfo->target_address_size();
}
......@@ -729,7 +719,7 @@ void Serializer::ObjectSerializer::VisitExternalReference(Foreign host,
if (encoded_reference.is_from_api()) {
sink_->Put(kApiReference, "ApiRef");
} else {
sink_->Put(kExternalReference + kPlain + kStartOfObject, "ExternalRef");
sink_->Put(kExternalReference + kPlain, "ExternalRef");
}
sink_->PutInt(encoded_reference.index(), "reference index");
bytes_processed_so_far_ += kSystemPointerSize;
......@@ -744,8 +734,7 @@ void Serializer::ObjectSerializer::VisitExternalReference(Code host,
sink_->Put(kApiReference, "ApiRef");
} else {
HowToCode how_to_code = rinfo->IsCodedSpecially() ? kFromCode : kPlain;
sink_->Put(kExternalReference + how_to_code + kStartOfObject,
"ExternalRef");
sink_->Put(kExternalReference + how_to_code, "ExternalRef");
}
DCHECK_NE(target, kNullAddress); // Code does not reference null.
sink_->PutInt(encoded_reference.index(), "reference index");
......@@ -803,7 +792,7 @@ void Serializer::ObjectSerializer::VisitCodeTarget(Code host,
DCHECK(!RelocInfo::IsRelativeCodeTarget(rinfo->rmode()));
#endif
Code object = Code::GetCodeFromTargetAddress(rinfo->target_address());
serializer_->SerializeObject(object, kFromCode, kInnerPointer);
serializer_->SerializeObject(object, kFromCode);
bytes_processed_so_far_ += rinfo->target_address_size();
}
......
......@@ -191,8 +191,7 @@ class Serializer : public SerializerDeserializer {
};
void SerializeDeferredObjects();
virtual void SerializeObject(HeapObject o, HowToCode how_to_code,
WhereToPoint where_to_point) = 0;
virtual void SerializeObject(HeapObject o, HowToCode how_to_code) = 0;
virtual bool MustBeDeferred(HeapObject object);
......@@ -200,28 +199,24 @@ class Serializer : public SerializerDeserializer {
FullObjectSlot start, FullObjectSlot end) override;
void SerializeRootObject(Object object);
void PutRoot(RootIndex root_index, HeapObject object, HowToCode how,
WhereToPoint where);
void PutRoot(RootIndex root_index, HeapObject object, HowToCode how);
void PutSmi(Smi smi);
void PutBackReference(HeapObject object, SerializerReference reference);
void PutAttachedReference(SerializerReference reference,
HowToCode how_to_code, WhereToPoint where_to_point);
HowToCode how_to_code);
// Emit alignment prefix if necessary, return required padding space in bytes.
int PutAlignmentPrefix(HeapObject object);
void PutNextChunk(int space);
void PutRepeat(int repeat_count);
// Returns true if the object was successfully serialized as a root.
bool SerializeRoot(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point);
bool SerializeRoot(HeapObject obj, HowToCode how_to_code);
// Returns true if the object was successfully serialized as hot object.
bool SerializeHotObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point);
bool SerializeHotObject(HeapObject obj, HowToCode how_to_code);
// Returns true if the object was successfully serialized as back reference.
bool SerializeBackReference(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point);
bool SerializeBackReference(HeapObject obj, HowToCode how_to_code);
// Returns true if the given heap object is a bytecode handler code object.
bool ObjectIsBytecodeHandler(HeapObject obj) const;
......@@ -295,12 +290,11 @@ class RelocInfoIterator;
class Serializer::ObjectSerializer : public ObjectVisitor {
public:
ObjectSerializer(Serializer* serializer, HeapObject obj,
SnapshotByteSink* sink, HowToCode how_to_code,
WhereToPoint where_to_point)
SnapshotByteSink* sink, HowToCode how_to_code)
: serializer_(serializer),
object_(obj),
sink_(sink),
reference_representation_(how_to_code + where_to_point),
reference_representation_(how_to_code),
bytes_processed_so_far_(0) {
#ifdef DEBUG
serializer_->PushStack(obj);
......
......@@ -69,19 +69,15 @@ bool IsUnexpectedCodeObject(Isolate* isolate, HeapObject obj) {
} // namespace
#endif // DEBUG
void StartupSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
void StartupSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code) {
DCHECK(!obj->IsJSFunction());
DCHECK(!IsUnexpectedCodeObject(isolate(), obj));
if (SerializeHotObject(obj, how_to_code, where_to_point)) return;
if (IsRootAndHasBeenSerialized(obj) &&
SerializeRoot(obj, how_to_code, where_to_point))
if (SerializeHotObject(obj, how_to_code)) return;
if (IsRootAndHasBeenSerialized(obj) && SerializeRoot(obj, how_to_code))
return;
if (SerializeUsingReadOnlyObjectCache(&sink_, obj, how_to_code,
where_to_point))
return;
if (SerializeBackReference(obj, how_to_code, where_to_point)) return;
if (SerializeUsingReadOnlyObjectCache(&sink_, obj, how_to_code)) return;
if (SerializeBackReference(obj, how_to_code)) return;
bool use_simulator = false;
#ifdef USE_SIMULATOR
......@@ -116,8 +112,7 @@ void StartupSerializer::SerializeObject(HeapObject obj, HowToCode how_to_code,
// Object has not yet been serialized. Serialize it here.
DCHECK(!isolate()->heap()->read_only_space()->Contains(obj));
ObjectSerializer object_serializer(this, obj, &sink_, how_to_code,
where_to_point);
ObjectSerializer object_serializer(this, obj, &sink_, how_to_code);
object_serializer.Serialize();
}
......@@ -160,18 +155,15 @@ SerializedHandleChecker::SerializedHandleChecker(Isolate* isolate,
}
bool StartupSerializer::SerializeUsingReadOnlyObjectCache(
SnapshotByteSink* sink, HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
return read_only_serializer_->SerializeUsingReadOnlyObjectCache(
sink, obj, how_to_code, where_to_point);
SnapshotByteSink* sink, HeapObject obj, HowToCode how_to_code) {
return read_only_serializer_->SerializeUsingReadOnlyObjectCache(sink, obj,
how_to_code);
}
void StartupSerializer::SerializeUsingPartialSnapshotCache(
SnapshotByteSink* sink, HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point) {
SnapshotByteSink* sink, HeapObject obj, HowToCode how_to_code) {
int cache_index = SerializeInObjectCache(obj);
sink->Put(kPartialSnapshotCache + how_to_code + where_to_point,
"PartialSnapshotCache");
sink->Put(kPartialSnapshotCache + how_to_code, "PartialSnapshotCache");
sink->PutInt(cache_index, "partial_snapshot_cache_index");
}
......
......@@ -34,18 +34,16 @@ class StartupSerializer : public RootsSerializer {
// ReadOnlyObjectCache bytecode into |sink|. Returns whether this was
// successful.
bool SerializeUsingReadOnlyObjectCache(SnapshotByteSink* sink, HeapObject obj,
HowToCode how_to_code,
WhereToPoint where_to_point);
HowToCode how_to_code);
// Adds |obj| to the partial snapshot object cache if not already present and
// emits a PartialSnapshotCache bytecode into |sink|.
void SerializeUsingPartialSnapshotCache(SnapshotByteSink* sink,
HeapObject obj, HowToCode how_to_code,
WhereToPoint where_to_point);
HeapObject obj,
HowToCode how_to_code);
private:
void SerializeObject(HeapObject o, HowToCode how_to_code,
WhereToPoint where_to_point) override;
void SerializeObject(HeapObject o, HowToCode how_to_code) override;
ReadOnlySerializer* read_only_serializer_;
std::vector<AccessorInfo> accessor_infos_;
......
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