Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/snapshot/serializer.cc

Issue 2807023003: [snapshot] encode resource before serializing. (Closed)
Patch Set: fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot/serializer.h ('k') | src/snapshot/serializer-common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "src/snapshot/serializer.h"
6 6
7 #include "src/assembler-inl.h" 7 #include "src/assembler-inl.h"
8 #include "src/deoptimizer.h" 8 #include "src/deoptimizer.h"
9 #include "src/heap/heap-inl.h" 9 #include "src/heap/heap-inl.h"
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 void Serializer::ObjectSerializer::SerializeExternalString() { 403 void Serializer::ObjectSerializer::SerializeExternalString() {
404 Heap* heap = serializer_->isolate()->heap(); 404 Heap* heap = serializer_->isolate()->heap();
405 if (object_->map() != heap->native_source_string_map()) { 405 if (object_->map() != heap->native_source_string_map()) {
406 // Usually we cannot recreate resources for external strings. To work 406 // Usually we cannot recreate resources for external strings. To work
407 // around this, external strings are serialized to look like ordinary 407 // around this, external strings are serialized to look like ordinary
408 // sequential strings. 408 // sequential strings.
409 // The exception are native source code strings, since we can recreate 409 // The exception are native source code strings, since we can recreate
410 // their resources. 410 // their resources.
411 SerializeExternalStringAsSequentialString(); 411 SerializeExternalStringAsSequentialString();
412 } else { 412 } else {
413 DCHECK(object_->IsExternalOneByteString()); 413 ExternalOneByteString* string = ExternalOneByteString::cast(object_);
414 DCHECK(ExternalOneByteString::cast(object_)->is_short()); 414 DCHECK(string->is_short());
415 int size = object_->Size(); 415 const NativesExternalStringResource* resource =
416 Map* map = object_->map(); 416 reinterpret_cast<const NativesExternalStringResource*>(
417 AllocationSpace space = 417 string->resource());
418 MemoryChunk::FromAddress(object_->address())->owner()->identity(); 418 // Replace the resource field with the type and index of the native source.
419 SerializePrologue(space, size, map); 419 string->set_resource(resource->EncodeForSerialization());
420 // Serialize the rest of the object. 420 SerializeContent();
421 CHECK_EQ(0, bytes_processed_so_far_); 421 // Restore the resource field.
422 bytes_processed_so_far_ = kPointerSize; 422 string->set_resource(resource);
423 typedef v8::String::ExternalOneByteStringResource Resource;
424 Resource** resource_pointer = reinterpret_cast<Resource**>(
425 HeapObject::RawField(object_, ExternalString::kResourceOffset));
426
427 Address references_start = reinterpret_cast<Address>(resource_pointer);
428 OutputRawData(references_start);
429 if (!SerializeExternalNativeSourceString(
430 Natives::GetBuiltinsCount(), resource_pointer,
431 Natives::GetSourceCache(heap), kNativesStringResource)) {
432 bool result = SerializeExternalNativeSourceString(
433 ExtraNatives::GetBuiltinsCount(), resource_pointer,
434 ExtraNatives::GetSourceCache(heap), kExtraNativesStringResource);
435 // One of the strings in the natives cache should match the resource. We
436 // don't expect any other kinds of external strings here.
437 USE(result);
438 DCHECK(result);
439 }
440 OutputRawData(object_->address() + size);
441 } 423 }
442 } 424 }
443 425
444 bool Serializer::ObjectSerializer::SerializeExternalNativeSourceString(
445 int builtin_count,
446 v8::String::ExternalOneByteStringResource** resource_pointer,
447 FixedArray* source_cache, int resource_index) {
448 Isolate* isolate = serializer_->isolate();
449 for (int i = 0; i < builtin_count; i++) {
450 Object* source = source_cache->get(i);
451 if (!source->IsUndefined(isolate)) {
452 ExternalOneByteString* string = ExternalOneByteString::cast(source);
453 typedef v8::String::ExternalOneByteStringResource Resource;
454 const Resource* resource = string->resource();
455 if (resource == *resource_pointer) {
456 sink_->Put(resource_index, "NativesStringResource");
457 sink_->PutSection(i, "NativesStringResourceEnd");
458 bytes_processed_so_far_ += sizeof(resource);
459 return true;
460 }
461 }
462 }
463 return false;
464 }
465
466 void Serializer::ObjectSerializer::SerializeExternalStringAsSequentialString() { 426 void Serializer::ObjectSerializer::SerializeExternalStringAsSequentialString() {
467 // Instead of serializing this as an external string, we serialize 427 // Instead of serializing this as an external string, we serialize
468 // an imaginary sequential string with the same content. 428 // an imaginary sequential string with the same content.
469 Isolate* isolate = serializer_->isolate(); 429 Isolate* isolate = serializer_->isolate();
470 DCHECK(object_->IsExternalString()); 430 DCHECK(object_->IsExternalString());
471 DCHECK(object_->map() != isolate->heap()->native_source_string_map()); 431 DCHECK(object_->map() != isolate->heap()->native_source_string_map());
472 ExternalString* string = ExternalString::cast(object_); 432 ExternalString* string = ExternalString::cast(object_);
473 int length = string->length(); 433 int length = string->length();
474 Map* map; 434 Map* map;
475 int content_size; 435 int content_size;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 519
560 void Serializer::ObjectSerializer::Serialize() { 520 void Serializer::ObjectSerializer::Serialize() {
561 if (FLAG_trace_serializer) { 521 if (FLAG_trace_serializer) {
562 PrintF(" Encoding heap object: "); 522 PrintF(" Encoding heap object: ");
563 object_->ShortPrint(); 523 object_->ShortPrint();
564 PrintF("\n"); 524 PrintF("\n");
565 } 525 }
566 526
567 if (object_->IsExternalString()) { 527 if (object_->IsExternalString()) {
568 SerializeExternalString(); 528 SerializeExternalString();
569 } else { 529 return;
570 // We cannot serialize typed array objects correctly. 530 }
571 DCHECK(!object_->IsJSTypedArray());
572 531
573 // We don't expect fillers. 532 // We cannot serialize typed array objects correctly.
574 DCHECK(!object_->IsFiller()); 533 DCHECK(!object_->IsJSTypedArray());
575 534
576 if (object_->IsScript()) { 535 // We don't expect fillers.
577 // Clear cached line ends. 536 DCHECK(!object_->IsFiller());
578 Object* undefined = serializer_->isolate()->heap()->undefined_value();
579 Script::cast(object_)->set_line_ends(undefined);
580 }
581 537
582 int size = object_->Size(); 538 if (object_->IsScript()) {
583 Map* map = object_->map(); 539 // Clear cached line ends.
584 AllocationSpace space = 540 Object* undefined = serializer_->isolate()->heap()->undefined_value();
585 MemoryChunk::FromAddress(object_->address())->owner()->identity(); 541 Script::cast(object_)->set_line_ends(undefined);
586 SerializePrologue(space, size, map); 542 }
587 543
588 // Serialize the rest of the object. 544 SerializeContent();
589 CHECK_EQ(0, bytes_processed_so_far_); 545 }
590 bytes_processed_so_far_ = kPointerSize;
591 546
592 RecursionScope recursion(serializer_); 547 void Serializer::ObjectSerializer::SerializeContent() {
593 // Objects that are immediately post processed during deserialization 548 int size = object_->Size();
594 // cannot be deferred, since post processing requires the object content. 549 Map* map = object_->map();
595 if (recursion.ExceedsMaximum() && CanBeDeferred(object_)) { 550 AllocationSpace space =
596 serializer_->QueueDeferredObject(object_); 551 MemoryChunk::FromAddress(object_->address())->owner()->identity();
597 sink_->Put(kDeferred, "Deferring object content"); 552 SerializePrologue(space, size, map);
598 return;
599 }
600 553
601 UnlinkWeakNextScope unlink_weak_next(object_); 554 // Serialize the rest of the object.
555 CHECK_EQ(0, bytes_processed_so_far_);
556 bytes_processed_so_far_ = kPointerSize;
602 557
603 object_->IterateBody(map->instance_type(), size, this); 558 RecursionScope recursion(serializer_);
604 OutputRawData(object_->address() + size); 559 // Objects that are immediately post processed during deserialization
560 // cannot be deferred, since post processing requires the object content.
561 if (recursion.ExceedsMaximum() && CanBeDeferred(object_)) {
562 serializer_->QueueDeferredObject(object_);
563 sink_->Put(kDeferred, "Deferring object content");
564 return;
605 } 565 }
566
567 UnlinkWeakNextScope unlink_weak_next(object_);
568
569 object_->IterateBody(map->instance_type(), size, this);
570 OutputRawData(object_->address() + size);
606 } 571 }
607 572
608 void Serializer::ObjectSerializer::SerializeDeferred() { 573 void Serializer::ObjectSerializer::SerializeDeferred() {
609 if (FLAG_trace_serializer) { 574 if (FLAG_trace_serializer) {
610 PrintF(" Encoding deferred heap object: "); 575 PrintF(" Encoding deferred heap object: ");
611 object_->ShortPrint(); 576 object_->ShortPrint();
612 PrintF("\n"); 577 PrintF("\n");
613 } 578 }
614 579
615 int size = object_->Size(); 580 int size = object_->Size();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 if (to_skip != 0 && return_skip == kIgnoringReturn) { 798 if (to_skip != 0 && return_skip == kIgnoringReturn) {
834 sink_->Put(kSkip, "Skip"); 799 sink_->Put(kSkip, "Skip");
835 sink_->PutInt(to_skip, "SkipDistance"); 800 sink_->PutInt(to_skip, "SkipDistance");
836 to_skip = 0; 801 to_skip = 0;
837 } 802 }
838 return to_skip; 803 return to_skip;
839 } 804 }
840 805
841 } // namespace internal 806 } // namespace internal
842 } // namespace v8 807 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/serializer.h ('k') | src/snapshot/serializer-common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698