Commit 748b7177 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[snapshot] Replace deserializer Lists with std::vector.

Bug: v8:6333
Change-Id: I189aa2938287e634bb4fec3b0e7c16acb6d66a11
Reviewed-on: https://chromium-review.googlesource.com/623249
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47496}
parent 1b5df683
......@@ -1324,7 +1324,7 @@ static void VerifyStringTable(Heap* heap) {
}
#endif // VERIFY_HEAP
bool Heap::ReserveSpace(Reservation* reservations, List<Address>* maps) {
bool Heap::ReserveSpace(Reservation* reservations, std::vector<Address>* maps) {
bool gc_performed = true;
int counter = 0;
static const int kThreshold = 20;
......@@ -1338,7 +1338,7 @@ bool Heap::ReserveSpace(Reservation* reservations, List<Address>* maps) {
bool perform_gc = false;
if (space == MAP_SPACE) {
// We allocate each map individually to avoid fragmentation.
maps->Clear();
maps->clear();
DCHECK_EQ(1, reservation->size());
int num_maps = reservation->at(0).size / Map::kSize;
for (int i = 0; i < num_maps; i++) {
......@@ -1352,7 +1352,7 @@ bool Heap::ReserveSpace(Reservation* reservations, List<Address>* maps) {
Address free_space_address = free_space->address();
CreateFillerObjectAt(free_space_address, Map::kSize,
ClearRecordedSlots::kNo);
maps->Add(free_space_address);
maps->push_back(free_space_address);
} else {
perform_gc = true;
break;
......@@ -4537,8 +4537,8 @@ void Heap::FinalizeIncrementalMarkingIfComplete(
}
void Heap::RegisterDeserializedObjectsForBlackAllocation(
Reservation* reservations, List<HeapObject*>* large_objects,
List<Address>* maps) {
Reservation* reservations, const std::vector<HeapObject*>& large_objects,
const std::vector<Address>& maps) {
// TODO(ulan): pause black allocation during deserialization to avoid
// iterating all these objects in one go.
......@@ -4568,12 +4568,12 @@ void Heap::RegisterDeserializedObjectsForBlackAllocation(
local_embedder_heap_tracer()->RegisterWrappersWithRemoteTracer();
// Large object space doesn't use reservations, so it needs custom handling.
for (HeapObject* object : *large_objects) {
for (HeapObject* object : large_objects) {
incremental_marking()->ProcessBlackAllocatedObject(object);
}
// Map space doesn't use reservations, so it needs custom handling.
for (Address addr : *maps) {
for (Address addr : maps) {
incremental_marking()->ProcessBlackAllocatedObject(
HeapObject::FromAddress(addr));
}
......
......@@ -776,7 +776,7 @@ class Heap {
inline AllocationMemento* FindAllocationMemento(Map* map, HeapObject* object);
// Returns false if not able to reserve.
bool ReserveSpace(Reservation* reservations, List<Address>* maps);
bool ReserveSpace(Reservation* reservations, std::vector<Address>* maps);
//
// Support for the API.
......@@ -1177,8 +1177,8 @@ class Heap {
void FinalizeIncrementalMarkingIfComplete(GarbageCollectionReason gc_reason);
void RegisterDeserializedObjectsForBlackAllocation(
Reservation* reservations, List<HeapObject*>* large_objects,
List<Address>* maps);
Reservation* reservations, const std::vector<HeapObject*>& large_objects,
const std::vector<Address>& maps);
IncrementalMarking* incremental_marking() { return incremental_marking_; }
......
......@@ -35,7 +35,7 @@ void Deserializer::DecodeReservation(
void Deserializer::RegisterDeserializedObjectsForBlackAllocation() {
isolate_->heap()->RegisterDeserializedObjectsForBlackAllocation(
reservations_, &deserialized_large_objects_, &allocated_maps_);
reservations_, deserialized_large_objects_, allocated_maps_);
}
bool Deserializer::ReserveSpace() {
......@@ -44,7 +44,7 @@ bool Deserializer::ReserveSpace() {
CHECK(reservations_[i].size() > 0);
}
#endif // DEBUG
DCHECK(allocated_maps_.is_empty());
DCHECK(allocated_maps_.empty());
if (!isolate_->heap()->ReserveSpace(reservations_, &allocated_maps_))
return false;
for (int i = 0; i < kNumberOfPreallocatedSpaces; i++) {
......@@ -87,7 +87,7 @@ Deserializer::~Deserializer() {
CHECK_EQ(reservations_[space].size(), chunk_index + 1);
CHECK_EQ(reservations_[space][chunk_index].end, high_water_[space]);
}
CHECK_EQ(allocated_maps_.length(), next_map_index_);
CHECK_EQ(allocated_maps_.size(), next_map_index_);
#endif // DEBUG
}
......@@ -165,7 +165,7 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
StringTableInsertionKey key(string);
String* canonical = StringTable::LookupKeyIfExists(isolate_, &key);
if (canonical == NULL) {
new_internalized_strings_.Add(handle(string));
new_internalized_strings_.push_back(handle(string));
return string;
} else {
string->SetForwardedInternalizedString(canonical);
......@@ -173,7 +173,7 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
}
}
} else if (obj->IsScript()) {
new_scripts_.Add(handle(Script::cast(obj)));
new_scripts_.push_back(handle(Script::cast(obj)));
} else {
DCHECK(CanBeDeferred(obj));
}
......@@ -196,11 +196,11 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
// case, we only need to remember code objects in the large object space.
// When deserializing user code, remember each individual code object.
if (deserializing_user_code() || space == LO_SPACE) {
new_code_objects_.Add(Code::cast(obj));
new_code_objects_.push_back(Code::cast(obj));
}
} else if (obj->IsAccessorInfo()) {
if (isolate_->external_reference_redirector()) {
accessor_infos_.Add(AccessorInfo::cast(obj));
accessor_infos_.push_back(AccessorInfo::cast(obj));
}
} else if (obj->IsExternalOneByteString()) {
DCHECK(obj->map() == isolate_->heap()->native_source_string_map());
......@@ -238,7 +238,7 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
string->set_hash_field(String::kEmptyHashField);
} else if (obj->IsTransitionArray() &&
TransitionArray::cast(obj)->number_of_entries() > 1) {
transition_arrays_.Add(TransitionArray::cast(obj));
transition_arrays_.push_back(TransitionArray::cast(obj));
}
}
// Check alignment.
......@@ -345,7 +345,7 @@ Address Deserializer::Allocate(int space_index, int size) {
Executability exec = static_cast<Executability>(source_.Get());
AllocationResult result = lo_space->AllocateRaw(size, exec);
HeapObject* obj = result.ToObjectChecked();
deserialized_large_objects_.Add(obj);
deserialized_large_objects_.push_back(obj);
return obj->address();
} else if (space_index == MAP_SPACE) {
DCHECK_EQ(Map::kSize, size);
......
......@@ -35,7 +35,7 @@ class Deserializer : public SerializerDeserializer {
// Add an object to back an attached reference. The order to add objects must
// mirror the order they are added in the serializer.
void AddAttachedObject(Handle<HeapObject> attached_object) {
attached_objects_.Add(attached_object);
attached_objects_.push_back(attached_object);
}
void SetRehashability(bool v) { can_rehash_ = v; }
......@@ -74,13 +74,21 @@ class Deserializer : public SerializerDeserializer {
Isolate* isolate() const { return isolate_; }
SnapshotByteSource* source() { return &source_; }
List<Code*>& new_code_objects() { return new_code_objects_; }
List<AccessorInfo*>* accessor_infos() { return &accessor_infos_; }
List<Handle<String>>& new_internalized_strings() {
const std::vector<Code*>& new_code_objects() const {
return new_code_objects_;
}
const std::vector<AccessorInfo*>& accessor_infos() const {
return accessor_infos_;
}
const std::vector<Handle<String>>& new_internalized_strings() const {
return new_internalized_strings_;
}
List<Handle<Script>>& new_scripts() { return new_scripts_; }
List<TransitionArray*>& transition_arrays() { return transition_arrays_; }
const std::vector<Handle<Script>>& new_scripts() const {
return new_scripts_;
}
const std::vector<TransitionArray*>& transition_arrays() const {
return transition_arrays_;
}
bool deserializing_user_code() const { return deserializing_user_code_; }
bool can_rehash() const { return can_rehash_; }
......@@ -128,7 +136,7 @@ class Deserializer : public SerializerDeserializer {
Isolate* isolate_;
// Objects from the attached object descriptions in the serialized user code.
List<Handle<HeapObject>> attached_objects_;
std::vector<Handle<HeapObject>> attached_objects_;
SnapshotByteSource source_;
uint32_t magic_number_;
......@@ -142,16 +150,16 @@ class Deserializer : public SerializerDeserializer {
uint32_t current_chunk_[kNumberOfPreallocatedSpaces];
Address high_water_[kNumberOfPreallocatedSpaces];
int next_map_index_;
List<Address> allocated_maps_;
std::vector<Address> allocated_maps_;
ExternalReferenceTable* external_reference_table_;
List<HeapObject*> deserialized_large_objects_;
List<Code*> new_code_objects_;
List<AccessorInfo*> accessor_infos_;
List<Handle<String>> new_internalized_strings_;
List<Handle<Script>> new_scripts_;
List<TransitionArray*> transition_arrays_;
std::vector<HeapObject*> deserialized_large_objects_;
std::vector<Code*> new_code_objects_;
std::vector<AccessorInfo*> accessor_infos_;
std::vector<Handle<String>> new_internalized_strings_;
std::vector<Handle<Script>> new_scripts_;
std::vector<TransitionArray*> transition_arrays_;
std::vector<byte*> off_heap_backing_stores_;
const bool deserializing_user_code_;
......
......@@ -99,8 +99,9 @@ void ObjectDeserializer::
}
void ObjectDeserializer::CommitPostProcessedObjects() {
CHECK(new_internalized_strings().size() <= kMaxInt);
StringTable::EnsureCapacityForDeserialization(
isolate(), new_internalized_strings().length());
isolate(), static_cast<int>(new_internalized_strings().size()));
for (Handle<String> string : new_internalized_strings()) {
StringTableInsertionKey key(*string);
DCHECK_NULL(StringTable::LookupKeyIfExists(isolate(), &key));
......
......@@ -88,9 +88,9 @@ bool SerializerDeserializer::CanBeDeferred(HeapObject* o) {
}
void SerializerDeserializer::RestoreExternalReferenceRedirectors(
List<AccessorInfo*>* accessor_infos) {
const std::vector<AccessorInfo*>& accessor_infos) {
// Restore wiped accessor infos.
for (AccessorInfo* info : *accessor_infos) {
for (AccessorInfo* info : accessor_infos) {
Foreign::cast(info->js_getter())
->set_foreign_address(info->redirected_getter());
}
......
......@@ -88,7 +88,8 @@ class SerializerDeserializer : public RootVisitor {
protected:
static bool CanBeDeferred(HeapObject* o);
void RestoreExternalReferenceRedirectors(List<AccessorInfo*>* accessor_infos);
void RestoreExternalReferenceRedirectors(
const std::vector<AccessorInfo*>& accessor_infos);
// ---------- byte code range 0x00..0x7f ----------
// Byte codes in this range represent Where, HowToCode and WhereToPoint.
......
......@@ -22,7 +22,7 @@ StartupSerializer::StartupSerializer(
}
StartupSerializer::~StartupSerializer() {
RestoreExternalReferenceRedirectors(&accessor_infos_);
RestoreExternalReferenceRedirectors(accessor_infos_);
OutputStatistics("StartupSerializer");
}
......@@ -72,7 +72,7 @@ void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
AccessorInfo* info = AccessorInfo::cast(obj);
Address original_address = Foreign::cast(info->getter())->foreign_address();
Foreign::cast(info->js_getter())->set_foreign_address(original_address);
accessor_infos_.Add(info);
accessor_infos_.push_back(info);
} else if (obj->IsScript() && Script::cast(obj)->IsUserJavaScript()) {
Script::cast(obj)->set_context_data(
isolate_->heap()->uninitialized_symbol());
......
......@@ -78,7 +78,7 @@ class StartupSerializer : public Serializer {
bool serializing_immortal_immovables_roots_;
std::bitset<Heap::kStrongRootListLength> root_has_been_serialized_;
PartialCacheIndexMap partial_cache_index_map_;
List<AccessorInfo*> accessor_infos_;
std::vector<AccessorInfo*> accessor_infos_;
// Indicates whether we only serialized hash tables that we can rehash.
// TODO(yangguo): generalize rehashing, and remove this flag.
bool can_be_rehashed_;
......
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