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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 { | 568 { |
569 DisallowHeapAllocation no_gc; | 569 DisallowHeapAllocation no_gc; |
570 isolate_->heap()->IterateSmiRoots(this); | 570 isolate_->heap()->IterateSmiRoots(this); |
571 isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); | 571 isolate_->heap()->IterateStrongRoots(this, VISIT_ONLY_STRONG); |
572 isolate_->heap()->RepairFreeListsAfterDeserialization(); | 572 isolate_->heap()->RepairFreeListsAfterDeserialization(); |
573 isolate_->heap()->IterateWeakRoots(this, VISIT_ALL); | 573 isolate_->heap()->IterateWeakRoots(this, VISIT_ALL); |
574 DeserializeDeferredObjects(); | 574 DeserializeDeferredObjects(); |
575 } | 575 } |
576 | 576 |
577 isolate_->heap()->set_native_contexts_list( | 577 isolate_->heap()->set_native_contexts_list( |
578 isolate_->heap()->undefined_value()); | 578 isolate_->heap()->code_stub_context()); |
579 | 579 |
580 // The allocation site list is build during root iteration, but if no sites | 580 // The allocation site list is build during root iteration, but if no sites |
581 // were encountered then it needs to be initialized to undefined. | 581 // were encountered then it needs to be initialized to undefined. |
582 if (isolate_->heap()->allocation_sites_list() == Smi::FromInt(0)) { | 582 if (isolate_->heap()->allocation_sites_list() == Smi::FromInt(0)) { |
583 isolate_->heap()->set_allocation_sites_list( | 583 isolate_->heap()->set_allocation_sites_list( |
584 isolate_->heap()->undefined_value()); | 584 isolate_->heap()->undefined_value()); |
585 } | 585 } |
586 | 586 |
587 // Update data pointers to the external strings containing natives sources. | 587 // Update data pointers to the external strings containing natives sources. |
588 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { | 588 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
589 Object* source = isolate_->heap()->natives_source_cache()->get(i); | 589 Object* source = isolate_->heap()->natives_source_cache()->get(i); |
590 if (!source->IsUndefined()) { | 590 if (!source->IsUndefined()) { |
591 ExternalOneByteString::cast(source)->update_data_cache(); | 591 ExternalOneByteString::cast(source)->update_data_cache(); |
592 } | 592 } |
593 } | 593 } |
594 | 594 |
595 for (int i = 0; i < CodeStubNatives::GetBuiltinsCount(); i++) { | |
596 Object* source = isolate_->heap()->code_stub_natives_source_cache()->get(i); | |
597 if (!source->IsUndefined()) { | |
598 ExternalOneByteString::cast(source)->update_data_cache(); | |
599 } | |
600 } | |
601 | |
595 FlushICacheForNewCodeObjects(); | 602 FlushICacheForNewCodeObjects(); |
596 | 603 |
597 // Issue code events for newly deserialized code objects. | 604 // Issue code events for newly deserialized code objects. |
598 LOG_CODE_EVENT(isolate_, LogCodeObjects()); | 605 LOG_CODE_EVENT(isolate_, LogCodeObjects()); |
599 LOG_CODE_EVENT(isolate_, LogCompiledFunctions()); | 606 LOG_CODE_EVENT(isolate_, LogCompiledFunctions()); |
600 } | 607 } |
601 | 608 |
602 | 609 |
603 MaybeHandle<Object> Deserializer::DeserializePartial( | 610 MaybeHandle<Object> Deserializer::DeserializePartial( |
604 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, | 611 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 int index = source_.Get(); | 1185 int index = source_.Get(); |
1179 Vector<const char> source_vector = Natives::GetScriptSource(index); | 1186 Vector<const char> source_vector = Natives::GetScriptSource(index); |
1180 NativesExternalStringResource* resource = | 1187 NativesExternalStringResource* resource = |
1181 new NativesExternalStringResource(source_vector.start(), | 1188 new NativesExternalStringResource(source_vector.start(), |
1182 source_vector.length()); | 1189 source_vector.length()); |
1183 Object* resource_obj = reinterpret_cast<Object*>(resource); | 1190 Object* resource_obj = reinterpret_cast<Object*>(resource); |
1184 UnalignedCopy(current++, &resource_obj); | 1191 UnalignedCopy(current++, &resource_obj); |
1185 break; | 1192 break; |
1186 } | 1193 } |
1187 | 1194 |
1195 case kCodeStubNativesStringResource: { | |
1196 DCHECK(!isolate_->heap()->deserialization_complete()); | |
1197 int index = source_.Get(); | |
Yang
2015/07/08 08:32:54
This duplicate code could be refactored into a hel
danno
2015/07/08 20:25:59
Done.
| |
1198 Vector<const char> source_vector = | |
1199 CodeStubNatives::GetScriptSource(index); | |
1200 NativesExternalStringResource* resource = | |
1201 new NativesExternalStringResource(source_vector.start(), | |
1202 source_vector.length()); | |
1203 Object* resource_obj = reinterpret_cast<Object*>(resource); | |
1204 UnalignedCopy(current++, &resource_obj); | |
1205 break; | |
1206 } | |
1207 | |
1188 // Deserialize raw data of variable length. | 1208 // Deserialize raw data of variable length. |
1189 case kVariableRawData: { | 1209 case kVariableRawData: { |
1190 int size_in_bytes = source_.GetInt(); | 1210 int size_in_bytes = source_.GetInt(); |
1191 byte* raw_data_out = reinterpret_cast<byte*>(current); | 1211 byte* raw_data_out = reinterpret_cast<byte*>(current); |
1192 source_.CopyRaw(raw_data_out, size_in_bytes); | 1212 source_.CopyRaw(raw_data_out, size_in_bytes); |
1193 break; | 1213 break; |
1194 } | 1214 } |
1195 | 1215 |
1196 case kVariableRepeat: { | 1216 case kVariableRepeat: { |
1197 int repeats = source_.GetInt(); | 1217 int repeats = source_.GetInt(); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1412 } | 1432 } |
1413 } | 1433 } |
1414 } | 1434 } |
1415 | 1435 |
1416 | 1436 |
1417 void PartialSerializer::Serialize(Object** o) { | 1437 void PartialSerializer::Serialize(Object** o) { |
1418 if ((*o)->IsContext()) { | 1438 if ((*o)->IsContext()) { |
1419 Context* context = Context::cast(*o); | 1439 Context* context = Context::cast(*o); |
1420 global_object_ = context->global_object(); | 1440 global_object_ = context->global_object(); |
1421 back_reference_map()->AddGlobalProxy(context->global_proxy()); | 1441 back_reference_map()->AddGlobalProxy(context->global_proxy()); |
1442 if (context->IsNativeContext()) { | |
1443 context->set(Context::NEXT_CONTEXT_LINK, | |
Yang
2015/07/08 08:32:54
Some comment here would be great.
danno
2015/07/08 20:25:59
Done.
| |
1444 isolate_->heap()->undefined_value()); | |
1445 DCHECK(!context->global_object()->IsUndefined()); | |
1446 DCHECK(!context->builtins()->IsUndefined()); | |
1447 } | |
1422 } | 1448 } |
1423 VisitPointer(o); | 1449 VisitPointer(o); |
1424 SerializeDeferredObjects(); | 1450 SerializeDeferredObjects(); |
1425 SerializeOutdatedContextsAsFixedArray(); | 1451 SerializeOutdatedContextsAsFixedArray(); |
1426 Pad(); | 1452 Pad(); |
1427 } | 1453 } |
1428 | 1454 |
1429 | 1455 |
1430 void PartialSerializer::SerializeOutdatedContextsAsFixedArray() { | 1456 void PartialSerializer::SerializeOutdatedContextsAsFixedArray() { |
1431 int length = outdated_contexts_.length(); | 1457 int length = outdated_contexts_.length(); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1616 PutBackReference(obj, back_reference); | 1642 PutBackReference(obj, back_reference); |
1617 } | 1643 } |
1618 return true; | 1644 return true; |
1619 } | 1645 } |
1620 return false; | 1646 return false; |
1621 } | 1647 } |
1622 | 1648 |
1623 | 1649 |
1624 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, | 1650 void StartupSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code, |
1625 WhereToPoint where_to_point, int skip) { | 1651 WhereToPoint where_to_point, int skip) { |
1626 DCHECK(!obj->IsJSFunction()); | 1652 #if DEBUG |
1653 // Make sure that all contexts are derived from the code-stub context | |
Yang
2015/07/08 08:32:54
... all *functions* are derived ...
danno
2015/07/08 20:25:59
Done.
| |
1654 if (obj->IsJSFunction()) { | |
1655 Context* current = JSFunction::cast(obj)->context(); | |
Yang
2015/07/08 08:32:54
Can you replace this with
DCHECK(!obj->IsJSFuncti
danno
2015/07/08 20:25:59
Done.
| |
1656 while (current != isolate()->heap()->code_stub_context()) { | |
1657 current = current->previous(); | |
1658 } | |
1659 DCHECK_EQ(isolate()->heap()->code_stub_context(), current); | |
1660 } | |
1661 #endif | |
1627 | 1662 |
1628 int root_index = root_index_map_.Lookup(obj); | 1663 int root_index = root_index_map_.Lookup(obj); |
1629 // We can only encode roots as such if it has already been serialized. | 1664 // We can only encode roots as such if it has already been serialized. |
1630 // That applies to root indices below the wave front. | 1665 // That applies to root indices below the wave front. |
1631 if (root_index != RootIndexMap::kInvalidRootIndex && | 1666 if (root_index != RootIndexMap::kInvalidRootIndex && |
1632 root_index < root_index_wave_front_) { | 1667 root_index < root_index_wave_front_) { |
1633 PutRoot(root_index, obj, how_to_code, where_to_point, skip); | 1668 PutRoot(root_index, obj, how_to_code, where_to_point, skip); |
1634 return; | 1669 return; |
1635 } | 1670 } |
1636 | 1671 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2139 typedef v8::String::ExternalOneByteStringResource Resource; | 2174 typedef v8::String::ExternalOneByteStringResource Resource; |
2140 const Resource* resource = string->resource(); | 2175 const Resource* resource = string->resource(); |
2141 if (resource == *resource_pointer) { | 2176 if (resource == *resource_pointer) { |
2142 sink_->Put(kNativesStringResource, "NativesStringResource"); | 2177 sink_->Put(kNativesStringResource, "NativesStringResource"); |
2143 sink_->PutSection(i, "NativesStringResourceEnd"); | 2178 sink_->PutSection(i, "NativesStringResourceEnd"); |
2144 bytes_processed_so_far_ += sizeof(resource); | 2179 bytes_processed_so_far_ += sizeof(resource); |
2145 return; | 2180 return; |
2146 } | 2181 } |
2147 } | 2182 } |
2148 } | 2183 } |
2184 for (int i = 0; i < CodeStubNatives::GetBuiltinsCount(); i++) { | |
Yang
2015/07/08 08:32:54
Could you refactor this duplicate code into a help
danno
2015/07/08 20:25:59
Done.
| |
2185 Object* source = | |
2186 serializer_->isolate()->heap()->code_stub_natives_source_cache()->get( | |
2187 i); | |
2188 if (!source->IsUndefined()) { | |
2189 ExternalOneByteString* string = ExternalOneByteString::cast(source); | |
2190 typedef v8::String::ExternalOneByteStringResource Resource; | |
2191 const Resource* resource = string->resource(); | |
2192 if (resource == *resource_pointer) { | |
2193 sink_->Put(kCodeStubNativesStringResource, | |
2194 "CodeStubNativesStringResource"); | |
2195 sink_->PutSection(i, "CodeStubNativesStringResourceEnd"); | |
2196 bytes_processed_so_far_ += sizeof(resource); | |
2197 return; | |
2198 } | |
2199 } | |
2200 } | |
2149 // One of the strings in the natives cache should match the resource. We | 2201 // One of the strings in the natives cache should match the resource. We |
2150 // don't expect any other kinds of external strings here. | 2202 // don't expect any other kinds of external strings here. |
2151 UNREACHABLE(); | 2203 UNREACHABLE(); |
2152 } | 2204 } |
2153 | 2205 |
2154 | 2206 |
2155 Address Serializer::ObjectSerializer::PrepareCode() { | 2207 Address Serializer::ObjectSerializer::PrepareCode() { |
2156 // To make snapshots reproducible, we make a copy of the code object | 2208 // To make snapshots reproducible, we make a copy of the code object |
2157 // and wipe all pointers in the copy, which we then serialize. | 2209 // and wipe all pointers in the copy, which we then serialize. |
2158 Code* original = Code::cast(object_); | 2210 Code* original = Code::cast(object_); |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2749 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2801 SerializedCodeData* scd = new SerializedCodeData(cached_data); |
2750 SanityCheckResult r = scd->SanityCheck(isolate, source); | 2802 SanityCheckResult r = scd->SanityCheck(isolate, source); |
2751 if (r == CHECK_SUCCESS) return scd; | 2803 if (r == CHECK_SUCCESS) return scd; |
2752 cached_data->Reject(); | 2804 cached_data->Reject(); |
2753 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | 2805 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); |
2754 delete scd; | 2806 delete scd; |
2755 return NULL; | 2807 return NULL; |
2756 } | 2808 } |
2757 } // namespace internal | 2809 } // namespace internal |
2758 } // namespace v8 | 2810 } // namespace v8 |
OLD | NEW |