| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 } else { \ | 991 } else { \ |
| 992 Object* new_object = NULL; /* May not be a real Object pointer. */ \ | 992 Object* new_object = NULL; /* May not be a real Object pointer. */ \ |
| 993 if (where == kNewObject) { \ | 993 if (where == kNewObject) { \ |
| 994 ReadObject(space_number, &new_object); \ | 994 ReadObject(space_number, &new_object); \ |
| 995 } else if (where == kRootArray) { \ | 995 } else if (where == kRootArray) { \ |
| 996 int root_id = source_.GetInt(); \ | 996 int root_id = source_.GetInt(); \ |
| 997 new_object = isolate->heap()->roots_array_start()[root_id]; \ | 997 new_object = isolate->heap()->roots_array_start()[root_id]; \ |
| 998 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ | 998 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ |
| 999 } else if (where == kPartialSnapshotCache) { \ | 999 } else if (where == kPartialSnapshotCache) { \ |
| 1000 int cache_index = source_.GetInt(); \ | 1000 int cache_index = source_.GetInt(); \ |
| 1001 new_object = isolate->serialize_partial_snapshot_cache()[cache_index]; \ | 1001 new_object = isolate->partial_snapshot_cache()->at(cache_index); \ |
| 1002 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ | 1002 emit_write_barrier = isolate->heap()->InNewSpace(new_object); \ |
| 1003 } else if (where == kExternalReference) { \ | 1003 } else if (where == kExternalReference) { \ |
| 1004 int skip = source_.GetInt(); \ | 1004 int skip = source_.GetInt(); \ |
| 1005 current = reinterpret_cast<Object**>( \ | 1005 current = reinterpret_cast<Object**>( \ |
| 1006 reinterpret_cast<Address>(current) + skip); \ | 1006 reinterpret_cast<Address>(current) + skip); \ |
| 1007 int reference_id = source_.GetInt(); \ | 1007 int reference_id = source_.GetInt(); \ |
| 1008 Address address = external_reference_decoder_->Decode(reference_id); \ | 1008 Address address = external_reference_decoder_->Decode(reference_id); \ |
| 1009 new_object = reinterpret_cast<Object*>(address); \ | 1009 new_object = reinterpret_cast<Object*>(address); \ |
| 1010 } else if (where == kBackref) { \ | 1010 } else if (where == kBackref) { \ |
| 1011 emit_write_barrier = (space_number == NEW_SPACE); \ | 1011 emit_write_barrier = (space_number == NEW_SPACE); \ |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 // tracks their movement. When it is called during serialization of the startup | 1501 // tracks their movement. When it is called during serialization of the startup |
| 1502 // snapshot nothing happens. When the partial (context) snapshot is created, | 1502 // snapshot nothing happens. When the partial (context) snapshot is created, |
| 1503 // this array is populated with the pointers that the partial snapshot will | 1503 // this array is populated with the pointers that the partial snapshot will |
| 1504 // need. As that happens we emit serialized objects to the startup snapshot | 1504 // need. As that happens we emit serialized objects to the startup snapshot |
| 1505 // that correspond to the elements of this cache array. On deserialization we | 1505 // that correspond to the elements of this cache array. On deserialization we |
| 1506 // therefore need to visit the cache array. This fills it up with pointers to | 1506 // therefore need to visit the cache array. This fills it up with pointers to |
| 1507 // deserialized objects. | 1507 // deserialized objects. |
| 1508 void SerializerDeserializer::Iterate(Isolate* isolate, | 1508 void SerializerDeserializer::Iterate(Isolate* isolate, |
| 1509 ObjectVisitor* visitor) { | 1509 ObjectVisitor* visitor) { |
| 1510 if (isolate->serializer_enabled()) return; | 1510 if (isolate->serializer_enabled()) return; |
| 1511 for (int i = 0; ; i++) { | 1511 List<Object*>* cache = isolate->partial_snapshot_cache(); |
| 1512 if (isolate->serialize_partial_snapshot_cache_length() <= i) { | 1512 for (int i = 0;; ++i) { |
| 1513 // Extend the array ready to get a value from the visitor when | 1513 // Extend the array ready to get a value when deserializing. |
| 1514 // deserializing. | 1514 if (cache->length() <= i) cache->Add(Smi::FromInt(0)); |
| 1515 isolate->PushToPartialSnapshotCache(Smi::FromInt(0)); | 1515 visitor->VisitPointer(&cache->at(i)); |
| 1516 } | |
| 1517 Object** cache = isolate->serialize_partial_snapshot_cache(); | |
| 1518 visitor->VisitPointers(&cache[i], &cache[i + 1]); | |
| 1519 // Sentinel is the undefined object, which is a root so it will not normally | 1516 // Sentinel is the undefined object, which is a root so it will not normally |
| 1520 // be found in the cache. | 1517 // be found in the cache. |
| 1521 if (cache[i] == isolate->heap()->undefined_value()) { | 1518 if (cache->at(i)->IsUndefined()) break; |
| 1522 break; | |
| 1523 } | |
| 1524 } | 1519 } |
| 1525 } | 1520 } |
| 1526 | 1521 |
| 1527 | 1522 |
| 1528 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { | 1523 int PartialSerializer::PartialSnapshotCacheIndex(HeapObject* heap_object) { |
| 1529 Isolate* isolate = this->isolate(); | 1524 Isolate* isolate = this->isolate(); |
| 1530 | 1525 List<Object*>* cache = isolate->partial_snapshot_cache(); |
| 1531 for (int i = 0; | 1526 for (int i = 0; i < cache->length(); ++i) { |
| 1532 i < isolate->serialize_partial_snapshot_cache_length(); | 1527 Object* entry = cache->at(i); |
| 1533 i++) { | |
| 1534 Object* entry = isolate->serialize_partial_snapshot_cache()[i]; | |
| 1535 if (entry == heap_object) return i; | 1528 if (entry == heap_object) return i; |
| 1536 } | 1529 } |
| 1537 | 1530 |
| 1538 // We didn't find the object in the cache. So we add it to the cache and | 1531 // We didn't find the object in the cache. So we add it to the cache and |
| 1539 // then visit the pointer so that it becomes part of the startup snapshot | 1532 // then visit the pointer so that it becomes part of the startup snapshot |
| 1540 // and we can refer to it from the partial snapshot. | 1533 // and we can refer to it from the partial snapshot. |
| 1541 int length = isolate->serialize_partial_snapshot_cache_length(); | 1534 cache->Add(heap_object); |
| 1542 isolate->PushToPartialSnapshotCache(heap_object); | |
| 1543 startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object)); | 1535 startup_serializer_->VisitPointer(reinterpret_cast<Object**>(&heap_object)); |
| 1544 // We don't recurse from the startup snapshot generator into the partial | 1536 // We don't recurse from the startup snapshot generator into the partial |
| 1545 // snapshot generator. | 1537 // snapshot generator. |
| 1546 DCHECK(length == isolate->serialize_partial_snapshot_cache_length() - 1); | 1538 return cache->length() - 1; |
| 1547 return length; | |
| 1548 } | 1539 } |
| 1549 | 1540 |
| 1550 | 1541 |
| 1551 #ifdef DEBUG | 1542 #ifdef DEBUG |
| 1552 bool Serializer::BackReferenceIsAlreadyAllocated(BackReference reference) { | 1543 bool Serializer::BackReferenceIsAlreadyAllocated(BackReference reference) { |
| 1553 DCHECK(reference.is_valid()); | 1544 DCHECK(reference.is_valid()); |
| 1554 DCHECK(!reference.is_source()); | 1545 DCHECK(!reference.is_source()); |
| 1555 DCHECK(!reference.is_global_proxy()); | 1546 DCHECK(!reference.is_global_proxy()); |
| 1556 AllocationSpace space = reference.space(); | 1547 AllocationSpace space = reference.space(); |
| 1557 int chunk_index = reference.chunk_index(); | 1548 int chunk_index = reference.chunk_index(); |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2672 DisallowHeapAllocation no_gc; | 2663 DisallowHeapAllocation no_gc; |
| 2673 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2664 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
| 2674 SanityCheckResult r = scd->SanityCheck(source); | 2665 SanityCheckResult r = scd->SanityCheck(source); |
| 2675 if (r == CHECK_SUCCESS) return scd; | 2666 if (r == CHECK_SUCCESS) return scd; |
| 2676 cached_data->Reject(); | 2667 cached_data->Reject(); |
| 2677 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2668 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
| 2678 delete scd; | 2669 delete scd; |
| 2679 return NULL; | 2670 return NULL; |
| 2680 } | 2671 } |
| 2681 } } // namespace v8::internal | 2672 } } // namespace v8::internal |
| OLD | NEW |