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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 DisallowHeapAllocation no_gc; | 533 DisallowHeapAllocation no_gc; |
534 isolate_->heap()->IterateSmiRoots(this); | 534 isolate_->heap()->IterateSmiRoots(this); |
535 isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); | 535 isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); |
536 isolate_->heap()->RepairFreeListsAfterDeserialization(); | 536 isolate_->heap()->RepairFreeListsAfterDeserialization(); |
537 isolate_->heap()->IterateWeakRoots(this, VISIT_ALL); | 537 isolate_->heap()->IterateWeakRoots(this, VISIT_ALL); |
538 DeserializeDeferredObjects(); | 538 DeserializeDeferredObjects(); |
539 FlushICacheForNewIsolate(); | 539 FlushICacheForNewIsolate(); |
540 } | 540 } |
541 | 541 |
542 isolate_->heap()->set_native_contexts_list( | 542 isolate_->heap()->set_native_contexts_list( |
543 isolate_->heap()->code_stub_context()); | 543 isolate_->heap()->undefined_value()); |
544 | |
545 // The allocation site list is build during root iteration, but if no sites | 544 // The allocation site list is build during root iteration, but if no sites |
546 // were encountered then it needs to be initialized to undefined. | 545 // were encountered then it needs to be initialized to undefined. |
547 if (isolate_->heap()->allocation_sites_list() == Smi::FromInt(0)) { | 546 if (isolate_->heap()->allocation_sites_list() == Smi::FromInt(0)) { |
548 isolate_->heap()->set_allocation_sites_list( | 547 isolate_->heap()->set_allocation_sites_list( |
549 isolate_->heap()->undefined_value()); | 548 isolate_->heap()->undefined_value()); |
550 } | 549 } |
551 | 550 |
552 // Update data pointers to the external strings containing natives sources. | 551 // Update data pointers to the external strings containing natives sources. |
553 Natives::UpdateSourceCache(isolate_->heap()); | 552 Natives::UpdateSourceCache(isolate_->heap()); |
554 ExtraNatives::UpdateSourceCache(isolate_->heap()); | 553 ExtraNatives::UpdateSourceCache(isolate_->heap()); |
555 CodeStubNatives::UpdateSourceCache(isolate_->heap()); | |
556 | 554 |
557 // Issue code events for newly deserialized code objects. | 555 // Issue code events for newly deserialized code objects. |
558 LOG_CODE_EVENT(isolate_, LogCodeObjects()); | 556 LOG_CODE_EVENT(isolate_, LogCodeObjects()); |
559 LOG_CODE_EVENT(isolate_, LogCompiledFunctions()); | 557 LOG_CODE_EVENT(isolate_, LogCompiledFunctions()); |
560 } | 558 } |
561 | 559 |
562 | 560 |
563 MaybeHandle<Object> Deserializer::DeserializePartial( | 561 MaybeHandle<Object> Deserializer::DeserializePartial( |
564 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, | 562 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, |
565 Handle<FixedArray>* outdated_contexts_out) { | 563 Handle<FixedArray>* outdated_contexts_out) { |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 case kNativesStringResource: | 1165 case kNativesStringResource: |
1168 current = CopyInNativesSource(Natives::GetScriptSource(source_.Get()), | 1166 current = CopyInNativesSource(Natives::GetScriptSource(source_.Get()), |
1169 current); | 1167 current); |
1170 break; | 1168 break; |
1171 | 1169 |
1172 case kExtraNativesStringResource: | 1170 case kExtraNativesStringResource: |
1173 current = CopyInNativesSource( | 1171 current = CopyInNativesSource( |
1174 ExtraNatives::GetScriptSource(source_.Get()), current); | 1172 ExtraNatives::GetScriptSource(source_.Get()), current); |
1175 break; | 1173 break; |
1176 | 1174 |
1177 case kCodeStubNativesStringResource: | |
1178 current = CopyInNativesSource( | |
1179 CodeStubNatives::GetScriptSource(source_.Get()), current); | |
1180 break; | |
1181 | |
1182 // Deserialize raw data of variable length. | 1175 // Deserialize raw data of variable length. |
1183 case kVariableRawData: { | 1176 case kVariableRawData: { |
1184 int size_in_bytes = source_.GetInt(); | 1177 int size_in_bytes = source_.GetInt(); |
1185 byte* raw_data_out = reinterpret_cast<byte*>(current); | 1178 byte* raw_data_out = reinterpret_cast<byte*>(current); |
1186 source_.CopyRaw(raw_data_out, size_in_bytes); | 1179 source_.CopyRaw(raw_data_out, size_in_bytes); |
1187 break; | 1180 break; |
1188 } | 1181 } |
1189 | 1182 |
1190 case kVariableRepeat: { | 1183 case kVariableRepeat: { |
1191 int repeats = source_.GetInt(); | 1184 int repeats = source_.GetInt(); |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 // strong roots have been serialized we can create a partial snapshot | 1700 // strong roots have been serialized we can create a partial snapshot |
1708 // which will repopulate the cache with objects needed by that partial | 1701 // which will repopulate the cache with objects needed by that partial |
1709 // snapshot. | 1702 // snapshot. |
1710 isolate->partial_snapshot_cache()->Clear(); | 1703 isolate->partial_snapshot_cache()->Clear(); |
1711 InitializeCodeAddressMap(); | 1704 InitializeCodeAddressMap(); |
1712 } | 1705 } |
1713 | 1706 |
1714 | 1707 |
1715 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, | 1708 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, |
1716 WhereToPoint where_to_point, int skip) { | 1709 WhereToPoint where_to_point, int skip) { |
1717 // Make sure that all functions are derived from the code-stub context | 1710 DCHECK(!obj->IsJSFunction()); |
1718 DCHECK(!obj->IsJSFunction() || | |
1719 JSFunction::cast(obj)->GetCreationContext() == | |
1720 isolate()->heap()->code_stub_context()); | |
1721 | 1711 |
1722 int root_index = root_index_map_.Lookup(obj); | 1712 int root_index = root_index_map_.Lookup(obj); |
1723 // We can only encode roots as such if it has already been serialized. | 1713 // We can only encode roots as such if it has already been serialized. |
1724 // That applies to root indices below the wave front. | 1714 // That applies to root indices below the wave front. |
1725 if (root_index != RootIndexMap::kInvalidRootIndex && | 1715 if (root_index != RootIndexMap::kInvalidRootIndex && |
1726 root_index < root_index_wave_front_) { | 1716 root_index < root_index_wave_front_) { |
1727 PutRoot(root_index, obj, how_to_code, where_to_point, skip); | 1717 PutRoot(root_index, obj, how_to_code, where_to_point, skip); |
1728 return; | 1718 return; |
1729 } | 1719 } |
1730 | 1720 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2244 Natives::GetSourceCache(serializer_->isolate()->heap()), | 2234 Natives::GetSourceCache(serializer_->isolate()->heap()), |
2245 kNativesStringResource)) { | 2235 kNativesStringResource)) { |
2246 return; | 2236 return; |
2247 } | 2237 } |
2248 if (SerializeExternalNativeSourceString( | 2238 if (SerializeExternalNativeSourceString( |
2249 ExtraNatives::GetBuiltinsCount(), resource_pointer, | 2239 ExtraNatives::GetBuiltinsCount(), resource_pointer, |
2250 ExtraNatives::GetSourceCache(serializer_->isolate()->heap()), | 2240 ExtraNatives::GetSourceCache(serializer_->isolate()->heap()), |
2251 kExtraNativesStringResource)) { | 2241 kExtraNativesStringResource)) { |
2252 return; | 2242 return; |
2253 } | 2243 } |
2254 if (SerializeExternalNativeSourceString( | |
2255 CodeStubNatives::GetBuiltinsCount(), resource_pointer, | |
2256 CodeStubNatives::GetSourceCache(serializer_->isolate()->heap()), | |
2257 kCodeStubNativesStringResource)) { | |
2258 return; | |
2259 } | |
2260 // One of the strings in the natives cache should match the resource. We | 2244 // One of the strings in the natives cache should match the resource. We |
2261 // don't expect any other kinds of external strings here. | 2245 // don't expect any other kinds of external strings here. |
2262 UNREACHABLE(); | 2246 UNREACHABLE(); |
2263 } | 2247 } |
2264 | 2248 |
2265 | 2249 |
2266 Address Serializer::ObjectSerializer::PrepareCode() { | 2250 Address Serializer::ObjectSerializer::PrepareCode() { |
2267 // To make snapshots reproducible, we make a copy of the code object | 2251 // To make snapshots reproducible, we make a copy of the code object |
2268 // and wipe all pointers in the copy, which we then serialize. | 2252 // and wipe all pointers in the copy, which we then serialize. |
2269 Code* original = Code::cast(object_); | 2253 Code* original = Code::cast(object_); |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2858 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2842 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2859 SanityCheckResult r = scd->SanityCheck(isolate, source); | 2843 SanityCheckResult r = scd->SanityCheck(isolate, source); |
2860 if (r == CHECK_SUCCESS) return scd; | 2844 if (r == CHECK_SUCCESS) return scd; |
2861 cached_data->Reject(); | 2845 cached_data->Reject(); |
2862 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2846 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2863 delete scd; | 2847 delete scd; |
2864 return NULL; | 2848 return NULL; |
2865 } | 2849 } |
2866 } // namespace internal | 2850 } // namespace internal |
2867 } // namespace v8 | 2851 } // namespace v8 |
OLD | NEW |