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/deserializer.h" | 5 #include "src/snapshot/deserializer.h" |
6 | 6 |
7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
8 #include "src/external-reference-table.h" | 8 #include "src/external-reference-table.h" |
9 #include "src/heap/heap.h" | 9 #include "src/heap/heap.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 MaybeHandle<Object> Deserializer::DeserializePartial( | 114 MaybeHandle<Object> Deserializer::DeserializePartial( |
115 Isolate* isolate, Handle<JSGlobalProxy> global_proxy) { | 115 Isolate* isolate, Handle<JSGlobalProxy> global_proxy) { |
116 Initialize(isolate); | 116 Initialize(isolate); |
117 if (!ReserveSpace()) { | 117 if (!ReserveSpace()) { |
118 V8::FatalProcessOutOfMemory("deserialize context"); | 118 V8::FatalProcessOutOfMemory("deserialize context"); |
119 return MaybeHandle<Object>(); | 119 return MaybeHandle<Object>(); |
120 } | 120 } |
121 | 121 |
122 Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New(1); | 122 AddAttachedObject(global_proxy); |
123 attached_objects[kGlobalProxyReference] = global_proxy; | |
124 SetAttachedObjects(attached_objects); | |
125 | 123 |
126 DisallowHeapAllocation no_gc; | 124 DisallowHeapAllocation no_gc; |
127 // Keep track of the code space start and end pointers in case new | 125 // Keep track of the code space start and end pointers in case new |
128 // code objects were unserialized | 126 // code objects were unserialized |
129 OldSpace* code_space = isolate_->heap()->code_space(); | 127 OldSpace* code_space = isolate_->heap()->code_space(); |
130 Address start_address = code_space->top(); | 128 Address start_address = code_space->top(); |
131 Object* root; | 129 Object* root; |
132 VisitPointer(&root); | 130 VisitPointer(&root); |
133 DeserializeDeferredObjects(); | 131 DeserializeDeferredObjects(); |
134 | 132 |
(...skipping 25 matching lines...) Expand all Loading... |
160 isolate->heap()->RegisterReservationsForBlackAllocation(reservations_); | 158 isolate->heap()->RegisterReservationsForBlackAllocation(reservations_); |
161 } | 159 } |
162 CommitPostProcessedObjects(isolate); | 160 CommitPostProcessedObjects(isolate); |
163 return scope.CloseAndEscape(result); | 161 return scope.CloseAndEscape(result); |
164 } | 162 } |
165 } | 163 } |
166 | 164 |
167 Deserializer::~Deserializer() { | 165 Deserializer::~Deserializer() { |
168 // TODO(svenpanne) Re-enable this assertion when v8 initialization is fixed. | 166 // TODO(svenpanne) Re-enable this assertion when v8 initialization is fixed. |
169 // DCHECK(source_.AtEOF()); | 167 // DCHECK(source_.AtEOF()); |
170 attached_objects_.Dispose(); | |
171 } | 168 } |
172 | 169 |
173 // This is called on the roots. It is the driver of the deserialization | 170 // This is called on the roots. It is the driver of the deserialization |
174 // process. It is also called on the body of each function. | 171 // process. It is also called on the body of each function. |
175 void Deserializer::VisitPointers(Object** start, Object** end) { | 172 void Deserializer::VisitPointers(Object** start, Object** end) { |
176 // The space must be new space. Any other space would cause ReadChunk to try | 173 // The space must be new space. Any other space would cause ReadChunk to try |
177 // to update the remembered using NULL as the address. | 174 // to update the remembered using NULL as the address. |
178 ReadData(start, end, NEW_SPACE, NULL); | 175 ReadData(start, end, NEW_SPACE, NULL); |
179 } | 176 } |
180 | 177 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // Assign a new script id to avoid collision. | 305 // Assign a new script id to avoid collision. |
309 script->set_id(isolate_->heap()->NextScriptId()); | 306 script->set_id(isolate_->heap()->NextScriptId()); |
310 // Add script to list. | 307 // Add script to list. |
311 Handle<Object> list = WeakFixedArray::Add(factory->script_list(), script); | 308 Handle<Object> list = WeakFixedArray::Add(factory->script_list(), script); |
312 heap->SetRootScriptList(*list); | 309 heap->SetRootScriptList(*list); |
313 } | 310 } |
314 } | 311 } |
315 | 312 |
316 HeapObject* Deserializer::GetBackReferencedObject(int space) { | 313 HeapObject* Deserializer::GetBackReferencedObject(int space) { |
317 HeapObject* obj; | 314 HeapObject* obj; |
318 BackReference back_reference(source_.GetInt()); | 315 SerializerReference back_reference = |
| 316 SerializerReference::FromBitfield(source_.GetInt()); |
319 if (space == LO_SPACE) { | 317 if (space == LO_SPACE) { |
320 CHECK(back_reference.chunk_index() == 0); | 318 CHECK(back_reference.chunk_index() == 0); |
321 uint32_t index = back_reference.large_object_index(); | 319 uint32_t index = back_reference.large_object_index(); |
322 obj = deserialized_large_objects_[index]; | 320 obj = deserialized_large_objects_[index]; |
323 } else { | 321 } else { |
324 DCHECK(space < kNumberOfPreallocatedSpaces); | 322 DCHECK(space < kNumberOfPreallocatedSpaces); |
325 uint32_t chunk_index = back_reference.chunk_index(); | 323 uint32_t chunk_index = back_reference.chunk_index(); |
326 DCHECK_LE(chunk_index, current_chunk_[space]); | 324 DCHECK_LE(chunk_index, current_chunk_[space]); |
327 uint32_t chunk_offset = back_reference.chunk_offset(); | 325 uint32_t chunk_offset = back_reference.chunk_offset(); |
328 Address address = reservations_[space][chunk_index].start + chunk_offset; | 326 Address address = reservations_[space][chunk_index].start + chunk_offset; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ | 487 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ |
490 } else if (where == kExternalReference) { \ | 488 } else if (where == kExternalReference) { \ |
491 int skip = source_.GetInt(); \ | 489 int skip = source_.GetInt(); \ |
492 current = reinterpret_cast<Object**>( \ | 490 current = reinterpret_cast<Object**>( \ |
493 reinterpret_cast<Address>(current) + skip); \ | 491 reinterpret_cast<Address>(current) + skip); \ |
494 int reference_id = source_.GetInt(); \ | 492 int reference_id = source_.GetInt(); \ |
495 Address address = external_reference_table_->address(reference_id); \ | 493 Address address = external_reference_table_->address(reference_id); \ |
496 new_object = reinterpret_cast<Object*>(address); \ | 494 new_object = reinterpret_cast<Object*>(address); \ |
497 } else if (where == kAttachedReference) { \ | 495 } else if (where == kAttachedReference) { \ |
498 int index = source_.GetInt(); \ | 496 int index = source_.GetInt(); \ |
499 DCHECK(deserializing_user_code() || index == kGlobalProxyReference); \ | |
500 new_object = *attached_objects_[index]; \ | 497 new_object = *attached_objects_[index]; \ |
501 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ | 498 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ |
502 } else { \ | 499 } else { \ |
503 DCHECK(where == kBuiltin); \ | 500 DCHECK(where == kBuiltin); \ |
504 DCHECK(deserializing_user_code()); \ | 501 DCHECK(deserializing_user_code()); \ |
505 int builtin_id = source_.GetInt(); \ | 502 int builtin_id = source_.GetInt(); \ |
506 DCHECK_LE(0, builtin_id); \ | 503 DCHECK_LE(0, builtin_id); \ |
507 DCHECK_LT(builtin_id, Builtins::builtin_count); \ | 504 DCHECK_LT(builtin_id, Builtins::builtin_count); \ |
508 Builtins::Name name = static_cast<Builtins::Name>(builtin_id); \ | 505 Builtins::Name name = static_cast<Builtins::Name>(builtin_id); \ |
509 new_object = isolate->builtins()->builtin(name); \ | 506 new_object = isolate->builtins()->builtin(name); \ |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 | 806 |
810 default: | 807 default: |
811 CHECK(false); | 808 CHECK(false); |
812 } | 809 } |
813 } | 810 } |
814 CHECK_EQ(limit, current); | 811 CHECK_EQ(limit, current); |
815 return true; | 812 return true; |
816 } | 813 } |
817 } // namespace internal | 814 } // namespace internal |
818 } // namespace v8 | 815 } // namespace v8 |
OLD | NEW |