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/serializer-common.h" | 5 #include "src/snapshot/serializer-common.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/counters.h" | 9 #include "src/counters.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 383 } |
384 | 384 |
385 void SerializedData::AllocateData(int size) { | 385 void SerializedData::AllocateData(int size) { |
386 DCHECK(!owns_data_); | 386 DCHECK(!owns_data_); |
387 data_ = NewArray<byte>(size); | 387 data_ = NewArray<byte>(size); |
388 size_ = size; | 388 size_ = size; |
389 owns_data_ = true; | 389 owns_data_ = true; |
390 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data_), kPointerAlignment)); | 390 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data_), kPointerAlignment)); |
391 } | 391 } |
392 | 392 |
393 // This ensures that the partial snapshot cache keeps things alive during GC and | 393 // The partial snapshot cache is terminated by undefined. We visit the |
394 // tracks their movement. When it is called during serialization of the startup | 394 // partial snapshot... |
395 // snapshot nothing happens. When the partial (context) snapshot is created, | 395 // - during deserialization to populate it. |
396 // this array is populated with the pointers that the partial snapshot will | 396 // - during normal GC to keep its content alive. |
397 // need. As that happens we emit serialized objects to the startup snapshot | 397 // - not during serialization. The partial serializer adds to it explicitly. |
398 // that correspond to the elements of this cache array. On deserialization we | |
399 // therefore need to visit the cache array. This fills it up with pointers to | |
400 // deserialized objects. | |
401 void SerializerDeserializer::Iterate(Isolate* isolate, ObjectVisitor* visitor) { | 398 void SerializerDeserializer::Iterate(Isolate* isolate, ObjectVisitor* visitor) { |
402 if (isolate->serializer_enabled()) return; | |
403 List<Object*>* cache = isolate->partial_snapshot_cache(); | 399 List<Object*>* cache = isolate->partial_snapshot_cache(); |
404 for (int i = 0;; ++i) { | 400 for (int i = 0;; ++i) { |
405 // Extend the array ready to get a value when deserializing. | 401 // Extend the array ready to get a value when deserializing. |
406 if (cache->length() <= i) cache->Add(Smi::FromInt(0)); | 402 if (cache->length() <= i) cache->Add(Smi::FromInt(0)); |
| 403 // During deserialization, the visitor populates the partial snapshot cache |
| 404 // and eventually terminates the cache with undefined. |
407 visitor->VisitPointer(&cache->at(i)); | 405 visitor->VisitPointer(&cache->at(i)); |
408 // Sentinel is the undefined object, which is a root so it will not normally | |
409 // be found in the cache. | |
410 if (cache->at(i)->IsUndefined()) break; | 406 if (cache->at(i)->IsUndefined()) break; |
411 } | 407 } |
412 } | 408 } |
413 | 409 |
414 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { | 410 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { |
415 return !o->IsString() && !o->IsScript(); | 411 return !o->IsString() && !o->IsScript(); |
416 } | 412 } |
417 | 413 |
418 } // namespace internal | 414 } // namespace internal |
419 } // namespace v8 | 415 } // namespace v8 |
OLD | NEW |