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/snapshot/serialize.h" | 5 #include "src/snapshot/serialize.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 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 "BackRefWithSkip"); | 1673 "BackRefWithSkip"); |
1674 sink_->PutInt(skip, "BackRefSkipDistance"); | 1674 sink_->PutInt(skip, "BackRefSkipDistance"); |
1675 } | 1675 } |
1676 PutBackReference(obj, back_reference); | 1676 PutBackReference(obj, back_reference); |
1677 } | 1677 } |
1678 return true; | 1678 return true; |
1679 } | 1679 } |
1680 return false; | 1680 return false; |
1681 } | 1681 } |
1682 | 1682 |
1683 | |
1684 StartupSerializer::StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) | 1683 StartupSerializer::StartupSerializer(Isolate* isolate, SnapshotByteSink* sink) |
1685 : Serializer(isolate, sink), root_index_wave_front_(0) { | 1684 : Serializer(isolate, sink), |
| 1685 root_index_wave_front_(0), |
| 1686 serializing_builtins_(false) { |
1686 // Clear the cache of objects used by the partial snapshot. After the | 1687 // Clear the cache of objects used by the partial snapshot. After the |
1687 // strong roots have been serialized we can create a partial snapshot | 1688 // strong roots have been serialized we can create a partial snapshot |
1688 // which will repopulate the cache with objects needed by that partial | 1689 // which will repopulate the cache with objects needed by that partial |
1689 // snapshot. | 1690 // snapshot. |
1690 isolate->partial_snapshot_cache()->Clear(); | 1691 isolate->partial_snapshot_cache()->Clear(); |
1691 InitializeCodeAddressMap(); | 1692 InitializeCodeAddressMap(); |
1692 } | 1693 } |
1693 | 1694 |
1694 | 1695 |
1695 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, | 1696 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, |
1696 WhereToPoint where_to_point, int skip) { | 1697 WhereToPoint where_to_point, int skip) { |
1697 DCHECK(!obj->IsJSFunction()); | 1698 DCHECK(!obj->IsJSFunction()); |
1698 | 1699 |
| 1700 if (obj->IsCode()) { |
| 1701 Code* code = Code::cast(obj); |
| 1702 // If the function code is compiled (either as native code or bytecode), |
| 1703 // replace it with lazy-compile builtin. Only exception is when we are |
| 1704 // serializing the canonical interpreter-entry-trampoline builtin. |
| 1705 if (code->kind() == Code::FUNCTION || |
| 1706 (!serializing_builtins_ && code->is_interpreter_entry_trampoline())) { |
| 1707 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); |
| 1708 } |
| 1709 } else if (obj->IsBytecodeArray()) { |
| 1710 obj = isolate()->heap()->undefined_value(); |
| 1711 } |
| 1712 |
1699 int root_index = root_index_map_.Lookup(obj); | 1713 int root_index = root_index_map_.Lookup(obj); |
1700 // We can only encode roots as such if it has already been serialized. | 1714 // We can only encode roots as such if it has already been serialized. |
1701 // That applies to root indices below the wave front. | 1715 // That applies to root indices below the wave front. |
1702 if (root_index != RootIndexMap::kInvalidRootIndex && | 1716 if (root_index != RootIndexMap::kInvalidRootIndex && |
1703 root_index < root_index_wave_front_) { | 1717 root_index < root_index_wave_front_) { |
1704 PutRoot(root_index, obj, how_to_code, where_to_point, skip); | 1718 PutRoot(root_index, obj, how_to_code, where_to_point, skip); |
1705 return; | 1719 return; |
1706 } | 1720 } |
1707 | 1721 |
1708 if (obj->IsCode() && Code::cast(obj)->kind() == Code::FUNCTION) { | |
1709 obj = isolate()->builtins()->builtin(Builtins::kCompileLazy); | |
1710 } | |
1711 | |
1712 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return; | 1722 if (SerializeKnownObject(obj, how_to_code, where_to_point, skip)) return; |
1713 | 1723 |
1714 FlushSkip(skip); | 1724 FlushSkip(skip); |
1715 | 1725 |
1716 // Object has not yet been serialized. Serialize it here. | 1726 // Object has not yet been serialized. Serialize it here. |
1717 ObjectSerializer object_serializer(this, obj, sink_, how_to_code, | 1727 ObjectSerializer object_serializer(this, obj, sink_, how_to_code, |
1718 where_to_point); | 1728 where_to_point); |
1719 object_serializer.Serialize(); | 1729 object_serializer.Serialize(); |
1720 } | 1730 } |
1721 | 1731 |
1722 | 1732 |
1723 void StartupSerializer::SerializeWeakReferencesAndDeferred() { | 1733 void StartupSerializer::SerializeWeakReferencesAndDeferred() { |
1724 // This phase comes right after the serialization (of the snapshot). | 1734 // This phase comes right after the serialization (of the snapshot). |
1725 // After we have done the partial serialization the partial snapshot cache | 1735 // After we have done the partial serialization the partial snapshot cache |
1726 // will contain some references needed to decode the partial snapshot. We | 1736 // will contain some references needed to decode the partial snapshot. We |
1727 // add one entry with 'undefined' which is the sentinel that the deserializer | 1737 // add one entry with 'undefined' which is the sentinel that the deserializer |
1728 // uses to know it is done deserializing the array. | 1738 // uses to know it is done deserializing the array. |
1729 Object* undefined = isolate()->heap()->undefined_value(); | 1739 Object* undefined = isolate()->heap()->undefined_value(); |
1730 VisitPointer(&undefined); | 1740 VisitPointer(&undefined); |
1731 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL); | 1741 isolate()->heap()->IterateWeakRoots(this, VISIT_ALL); |
1732 SerializeDeferredObjects(); | 1742 SerializeDeferredObjects(); |
1733 Pad(); | 1743 Pad(); |
1734 } | 1744 } |
1735 | 1745 |
| 1746 void StartupSerializer::Synchronize(VisitorSynchronization::SyncTag tag) { |
| 1747 // We expect the builtins tag after builtins have been serialized. |
| 1748 DCHECK(!serializing_builtins_ || tag == VisitorSynchronization::kBuiltins); |
| 1749 serializing_builtins_ = (tag == VisitorSynchronization::kHandleScope); |
| 1750 } |
1736 | 1751 |
1737 void Serializer::PutRoot(int root_index, | 1752 void Serializer::PutRoot(int root_index, |
1738 HeapObject* object, | 1753 HeapObject* object, |
1739 SerializerDeserializer::HowToCode how_to_code, | 1754 SerializerDeserializer::HowToCode how_to_code, |
1740 SerializerDeserializer::WhereToPoint where_to_point, | 1755 SerializerDeserializer::WhereToPoint where_to_point, |
1741 int skip) { | 1756 int skip) { |
1742 if (FLAG_trace_serializer) { | 1757 if (FLAG_trace_serializer) { |
1743 PrintF(" Encoding root %d:", root_index); | 1758 PrintF(" Encoding root %d:", root_index); |
1744 object->ShortPrint(); | 1759 object->ShortPrint(); |
1745 PrintF("\n"); | 1760 PrintF("\n"); |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2820 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2835 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2821 SanityCheckResult r = scd->SanityCheck(isolate, source); | 2836 SanityCheckResult r = scd->SanityCheck(isolate, source); |
2822 if (r == CHECK_SUCCESS) return scd; | 2837 if (r == CHECK_SUCCESS) return scd; |
2823 cached_data->Reject(); | 2838 cached_data->Reject(); |
2824 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2839 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2825 delete scd; | 2840 delete scd; |
2826 return NULL; | 2841 return NULL; |
2827 } | 2842 } |
2828 } // namespace internal | 2843 } // namespace internal |
2829 } // namespace v8 | 2844 } // namespace v8 |
OLD | NEW |