| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/snapshot/partial-serializer.h" | 5 #include "src/snapshot/partial-serializer.h" |
| 6 | 6 |
| 7 #include "src/objects-inl.h" | 7 #include "src/objects-inl.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 | 11 |
| 12 PartialSerializer::PartialSerializer(Isolate* isolate, | 12 PartialSerializer::PartialSerializer(Isolate* isolate, |
| 13 Serializer* startup_snapshot_serializer, | 13 Serializer* startup_snapshot_serializer) |
| 14 SnapshotByteSink* sink) | 14 : Serializer(isolate), |
| 15 : Serializer(isolate, sink), | |
| 16 startup_serializer_(startup_snapshot_serializer), | 15 startup_serializer_(startup_snapshot_serializer), |
| 17 next_partial_cache_index_(0) { | 16 next_partial_cache_index_(0) { |
| 18 InitializeCodeAddressMap(); | 17 InitializeCodeAddressMap(); |
| 19 } | 18 } |
| 20 | 19 |
| 21 PartialSerializer::~PartialSerializer() { | 20 PartialSerializer::~PartialSerializer() { |
| 22 OutputStatistics("PartialSerializer"); | 21 OutputStatistics("PartialSerializer"); |
| 23 } | 22 } |
| 24 | 23 |
| 25 void PartialSerializer::Serialize(Object** o) { | 24 void PartialSerializer::Serialize(Object** o) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 56 int root_index = root_index_map_.Lookup(obj); | 55 int root_index = root_index_map_.Lookup(obj); |
| 57 if (root_index != RootIndexMap::kInvalidRootIndex) { | 56 if (root_index != RootIndexMap::kInvalidRootIndex) { |
| 58 PutRoot(root_index, obj, how_to_code, where_to_point, skip); | 57 PutRoot(root_index, obj, how_to_code, where_to_point, skip); |
| 59 return; | 58 return; |
| 60 } | 59 } |
| 61 | 60 |
| 62 if (ShouldBeInThePartialSnapshotCache(obj)) { | 61 if (ShouldBeInThePartialSnapshotCache(obj)) { |
| 63 FlushSkip(skip); | 62 FlushSkip(skip); |
| 64 | 63 |
| 65 int cache_index = PartialSnapshotCacheIndex(obj); | 64 int cache_index = PartialSnapshotCacheIndex(obj); |
| 66 sink_->Put(kPartialSnapshotCache + how_to_code + where_to_point, | 65 sink_.Put(kPartialSnapshotCache + how_to_code + where_to_point, |
| 67 "PartialSnapshotCache"); | 66 "PartialSnapshotCache"); |
| 68 sink_->PutInt(cache_index, "partial_snapshot_cache_index"); | 67 sink_.PutInt(cache_index, "partial_snapshot_cache_index"); |
| 69 return; | 68 return; |
| 70 } | 69 } |
| 71 | 70 |
| 72 // Pointers from the partial snapshot to the objects in the startup snapshot | 71 // Pointers from the partial snapshot to the objects in the startup snapshot |
| 73 // should go through the root array or through the partial snapshot cache. | 72 // should go through the root array or through the partial snapshot cache. |
| 74 // If this is not the case you may have to add something to the root array. | 73 // If this is not the case you may have to add something to the root array. |
| 75 DCHECK(!startup_serializer_->reference_map()->Lookup(obj).is_valid()); | 74 DCHECK(!startup_serializer_->reference_map()->Lookup(obj).is_valid()); |
| 76 // All the internalized strings that the partial snapshot needs should be | 75 // All the internalized strings that the partial snapshot needs should be |
| 77 // either in the root table or in the partial snapshot cache. | 76 // either in the root table or in the partial snapshot cache. |
| 78 DCHECK(!obj->IsInternalizedString()); | 77 DCHECK(!obj->IsInternalizedString()); |
| 79 | 78 |
| 80 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return; | 79 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return; |
| 81 | 80 |
| 82 FlushSkip(skip); | 81 FlushSkip(skip); |
| 83 | 82 |
| 84 // Clear literal boilerplates. | 83 // Clear literal boilerplates. |
| 85 if (obj->IsJSFunction()) { | 84 if (obj->IsJSFunction()) { |
| 86 LiteralsArray* literals = JSFunction::cast(obj)->literals(); | 85 LiteralsArray* literals = JSFunction::cast(obj)->literals(); |
| 87 for (int i = 0; i < literals->literals_count(); i++) { | 86 for (int i = 0; i < literals->literals_count(); i++) { |
| 88 literals->set_literal_undefined(i); | 87 literals->set_literal_undefined(i); |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 // Object has not yet been serialized. Serialize it here. | 91 // Object has not yet been serialized. Serialize it here. |
| 93 ObjectSerializer serializer(this, obj, sink_, how_to_code, where_to_point); | 92 ObjectSerializer serializer(this, obj, &sink_, how_to_code, where_to_point); |
| 94 serializer.Serialize(); | 93 serializer.Serialize(); |
| 95 } | 94 } |
| 96 | 95 |
| 97 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { | 96 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { |
| 98 int index = partial_cache_index_map_.LookupOrInsert( | 97 int index = partial_cache_index_map_.LookupOrInsert( |
| 99 heap_object, next_partial_cache_index_); | 98 heap_object, next_partial_cache_index_); |
| 100 if (index == PartialCacheIndexMap::kInvalidIndex) { | 99 if (index == PartialCacheIndexMap::kInvalidIndex) { |
| 101 // This object is not part of the partial snapshot cache yet. Add it to the | 100 // This object is not part of the partial snapshot cache yet. Add it to the |
| 102 // startup snapshot so we can refer to it via partial snapshot index from | 101 // startup snapshot so we can refer to it via partial snapshot index from |
| 103 // the partial snapshot. | 102 // the partial snapshot. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 // would cause dupes. | 113 // would cause dupes. |
| 115 DCHECK(!o->IsScript()); | 114 DCHECK(!o->IsScript()); |
| 116 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || | 115 return o->IsName() || o->IsSharedFunctionInfo() || o->IsHeapNumber() || |
| 117 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || | 116 o->IsCode() || o->IsScopeInfo() || o->IsAccessorInfo() || |
| 118 o->map() == | 117 o->map() == |
| 119 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); | 118 startup_serializer_->isolate()->heap()->fixed_cow_array_map(); |
| 120 } | 119 } |
| 121 | 120 |
| 122 } // namespace internal | 121 } // namespace internal |
| 123 } // namespace v8 | 122 } // namespace v8 |
| OLD | NEW |