V8 Project
v8::internal::Deserializer Class Reference

#include <serialize.h>

+ Inheritance diagram for v8::internal::Deserializer:
+ Collaboration diagram for v8::internal::Deserializer:

Public Member Functions

 Deserializer (SnapshotByteSource *source)
 
virtual ~Deserializer ()
 
void Deserialize (Isolate *isolate)
 
void DeserializePartial (Isolate *isolate, Object **root)
 
void set_reservation (int space_number, int reservation)
 
void FlushICacheForNewCodeObjects ()
 
void SetAttachedObjects (Vector< Handle< Object > > *attached_objects)
 
bool deserializing_user_code ()
 

Private Member Functions

virtual void VisitPointers (Object **start, Object **end)
 
virtual void VisitRuntimeEntry (RelocInfo *rinfo)
 
void RelinkAllocationSite (AllocationSite *site)
 
void ReadChunk (Object **start, Object **end, int space, Address object_address)
 
void ReadObject (int space_number, Object **write_back)
 
Address Allocate (int space_index, int size)
 
HeapObjectProcessNewObjectFromSerializedCode (HeapObject *obj)
 
ObjectProcessBackRefInSerializedCode (Object *obj)
 
HeapObjectGetAddressFromEnd (int space)
 
 DISALLOW_COPY_AND_ASSIGN (Deserializer)
 

Private Attributes

Isolateisolate_
 
Vector< Handle< Object > > * attached_objects_
 
SnapshotByteSource * source_
 
Address high_water_ [kNumberOfPreallocatedSpaces]
 
int reservations_ [kNumberOfSpaces]
 
ExternalReferenceDecoderexternal_reference_decoder_
 
List< HeapObject * > deserialized_large_objects_
 

Static Private Attributes

static const intptr_t kUninitializedReservation = -1
 

Additional Inherited Members

- Static Public Member Functions inherited from v8::internal::SerializerDeserializer
static void Iterate (Isolate *isolate, ObjectVisitor *visitor)
 
static int nop ()
 
- Static Public Attributes inherited from v8::internal::SerializerDeserializer
static const int kNumberOfPreallocatedSpaces = LO_SPACE
 
static const int kNumberOfSpaces = INVALID_SPACE
 
- Protected Types inherited from v8::internal::SerializerDeserializer
enum  Where {
  kNewObject = 0 , kRootArray = 0x9 , kPartialSnapshotCache = 0xa , kExternalReference = 0xb ,
  kSkip = 0xc , kBuiltin = 0xd , kAttachedReference = 0xe , kNop = 0xf ,
  kBackref = 0x10 , kBackrefWithSkip = 0x18 , kPointedToMask = 0x3f
}
 
enum  HowToCode { kPlain = 0 , kFromCode = 0x40 , kHowToCodeMask = 0x40 }
 
enum  WithSkip { kNoSkipDistance = 0 , kHasSkipDistance = 0x40 , kWithSkipMask = 0x40 }
 
enum  WhereToPoint { kStartOfObject = 0 , kInnerPointer = 0x80 , kWhereToPointMask = 0x80 }
 
- Protected Member Functions inherited from v8::internal::SerializerDeserializer
 STATIC_ASSERT (kNumberOfSpaces<=kSpaceMask+1)
 
- Static Protected Member Functions inherited from v8::internal::SerializerDeserializer
static int CodeForRepeats (int repeats)
 
static int RepeatsForCode (int byte_code)
 
static int RootArrayConstantFromByteCode (int byte_code)
 
- Static Protected Attributes inherited from v8::internal::SerializerDeserializer
static const int kRawData = 0x20
 
static const int kSynchronize = 0x70
 
static const int kNativesStringResource = 0x71
 
static const int kRepeat = 0x72
 
static const int kConstantRepeat = 0x73
 
static const int kMaxRepeats = 0x7f - 0x72
 
static const int kRootArrayConstants = 0xa0
 
static const int kRootArrayNumberOfConstantEncodings = 0x20
 
static const int kAnyOldSpace = -1
 
static const int kSpaceMask = 7
 

Detailed Description

Definition at line 241 of file serialize.h.

Constructor & Destructor Documentation

◆ Deserializer()

v8::internal::Deserializer::Deserializer ( SnapshotByteSource *  source)
explicit

Definition at line 595 of file serialize.cc.

596  : isolate_(NULL),
598  source_(source),
601  for (int i = 0; i < kNumberOfSpaces; i++) {
603  }
604 }
ExternalReferenceDecoder * external_reference_decoder_
Definition: serialize.h:319
int reservations_[kNumberOfSpaces]
Definition: serialize.h:316
Vector< Handle< Object > > * attached_objects_
Definition: serialize.h:309
List< HeapObject * > deserialized_large_objects_
Definition: serialize.h:321
static const intptr_t kUninitializedReservation
Definition: serialize.h:317
SnapshotByteSource * source_
Definition: serialize.h:311
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References v8::internal::SerializerDeserializer::kNumberOfSpaces, kUninitializedReservation, and reservations_.

◆ ~Deserializer()

v8::internal::Deserializer::~Deserializer ( )
virtual

Definition at line 687 of file serialize.cc.

687  {
688  // TODO(svenpanne) Re-enable this assertion when v8 initialization is fixed.
689  // DCHECK(source_->AtEOF());
693  }
694  if (attached_objects_) attached_objects_->Dispose();
695 }

References attached_objects_, external_reference_decoder_, and NULL.

Member Function Documentation

◆ Allocate()

Address v8::internal::Deserializer::Allocate ( int  space_index,
int  size 
)
private

Definition at line 820 of file serialize.cc.

820  {
821  if (space_index == LO_SPACE) {
822  AlwaysAllocateScope scope(isolate_);
823  LargeObjectSpace* lo_space = isolate_->heap()->lo_space();
824  Executability exec = static_cast<Executability>(source_->GetInt());
825  AllocationResult result = lo_space->AllocateRaw(size, exec);
826  HeapObject* obj = HeapObject::cast(result.ToObjectChecked());
828  return obj->address();
829  } else {
830  DCHECK(space_index < kNumberOfPreallocatedSpaces);
831  Address address = high_water_[space_index];
832  high_water_[space_index] = address + size;
833  return address;
834  }
835 }
Address high_water_[kNumberOfPreallocatedSpaces]
Definition: serialize.h:314
LargeObjectSpace * lo_space()
Definition: heap.h:600
static const int kNumberOfPreallocatedSpaces
Definition: serialize.h:152
enable harmony numeric enable harmony object literal extensions Optimize object size
#define DCHECK(condition)
Definition: logging.h:205
byte * Address
Definition: globals.h:101

References v8::internal::HeapObject::address(), v8::internal::LargeObjectSpace::AllocateRaw(), DCHECK, deserialized_large_objects_, v8::internal::Isolate::heap(), high_water_, isolate_, v8::internal::SerializerDeserializer::kNumberOfPreallocatedSpaces, v8::internal::LO_SPACE, v8::internal::Heap::lo_space(), size, source_, and v8::internal::AllocationResult::ToObjectChecked().

Referenced by ReadObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Deserialize()

void v8::internal::Deserializer::Deserialize ( Isolate isolate)

Definition at line 616 of file serialize.cc.

616  {
617  isolate_ = isolate;
618  DCHECK(isolate_ != NULL);
620  // No active threads.
622  // No active handles.
623  DCHECK(isolate_->handle_scope_implementer()->blocks()->is_empty());
625  external_reference_decoder_ = new ExternalReferenceDecoder(isolate);
626  isolate_->heap()->IterateSmiRoots(this);
630 
632  isolate_->heap()->undefined_value());
634  isolate_->heap()->undefined_value());
635 
636  // The allocation site list is build during root iteration, but if no sites
637  // were encountered then it needs to be initialized to undefined.
640  isolate_->heap()->undefined_value());
641  }
642 
644 
645  // Update data pointers to the external strings containing natives sources.
646  for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
647  Object* source = isolate_->heap()->natives_source_cache()->get(i);
648  if (!source->IsUndefined()) {
649  ExternalOneByteString::cast(source)->update_data_cache();
650  }
651  }
652 
654 
655  // Issue code events for newly deserialized code objects.
656  LOG_CODE_EVENT(isolate_, LogCodeObjects());
657  LOG_CODE_EVENT(isolate_, LogCompiledFunctions());
658 }
List< internal::Object ** > * blocks()
Definition: api.h:537
void set_array_buffers_list(Object *object)
Definition: heap.h:795
void ReserveSpace(int *sizes, Address *addresses)
Definition: heap.cc:920
Object * allocation_sites_list()
Definition: heap.h:801
void InitializeWeakObjectToCodeTable()
Definition: heap.h:1348
void IterateSmiRoots(ObjectVisitor *v)
Definition: heap.cc:4739
void set_allocation_sites_list(Object *object)
Definition: heap.h:798
void IterateWeakRoots(ObjectVisitor *v, VisitMode mode)
Definition: heap.cc:4728
void IterateStrongRoots(ObjectVisitor *v, VisitMode mode)
Definition: heap.cc:4747
void RepairFreeListsAfterBoot()
Definition: heap.cc:484
void set_native_contexts_list(Object *object)
Definition: heap.h:790
HandleScopeImplementer * handle_scope_implementer()
Definition: isolate.h:901
ThreadManager * thread_manager()
Definition: isolate.h:921
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
ThreadState * FirstThreadStateInUse()
Definition: v8threads.cc:231
#define LOG_CODE_EVENT(isolate, Call)
Definition: log.h:77
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
@ VISIT_ONLY_STRONG
Definition: globals.h:397
kSerializedDataOffset Object
Definition: objects-inl.h:5322

References v8::internal::Heap::allocation_sites_list(), v8::internal::HandleScopeImplementer::blocks(), DCHECK, DCHECK_EQ, external_reference_decoder_, v8::internal::ThreadManager::FirstThreadStateInUse(), FlushICacheForNewCodeObjects(), v8::internal::Smi::FromInt(), v8::internal::NativesCollection< type >::GetBuiltinsCount(), v8::internal::Isolate::handle_scope_implementer(), v8::internal::Isolate::heap(), high_water_, v8::internal::Heap::InitializeWeakObjectToCodeTable(), isolate_, v8::internal::Heap::IterateSmiRoots(), v8::internal::Heap::IterateStrongRoots(), v8::internal::Heap::IterateWeakRoots(), LOG_CODE_EVENT, NULL, v8::internal::Heap::RepairFreeListsAfterBoot(), reservations_, v8::internal::Heap::ReserveSpace(), v8::internal::Heap::set_allocation_sites_list(), v8::internal::Heap::set_array_buffers_list(), v8::internal::Heap::set_native_contexts_list(), v8::internal::Isolate::thread_manager(), v8::internal::VISIT_ALL, and v8::internal::VISIT_ONLY_STRONG.

Referenced by v8::internal::Isolate::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DeserializePartial()

void v8::internal::Deserializer::DeserializePartial ( Isolate isolate,
Object **  root 
)

Definition at line 661 of file serialize.cc.

661  {
662  isolate_ = isolate;
663  for (int i = NEW_SPACE; i < kNumberOfSpaces; i++) {
665  }
666  Heap* heap = isolate->heap();
667  heap->ReserveSpace(reservations_, high_water_);
669  external_reference_decoder_ = new ExternalReferenceDecoder(isolate);
670  }
671 
673 
674  // Keep track of the code space start and end pointers in case new
675  // code objects were unserialized
676  OldSpace* code_space = isolate_->heap()->code_space();
677  Address start_address = code_space->top();
678  VisitPointer(root);
679 
680  // There's no code deserialized here. If this assert fires
681  // then that's changed and logging should be added to notify
682  // the profiler et al of the new code.
683  CHECK_EQ(start_address, code_space->top());
684 }
OldSpace * code_space()
Definition: heap.h:596
#define CHECK_EQ(expected, value)
Definition: logging.h:169
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110

References CHECK_EQ, v8::internal::Heap::code_space(), DCHECK, external_reference_decoder_, v8::internal::Isolate::heap(), high_water_, isolate_, v8::internal::SerializerDeserializer::kNumberOfSpaces, kUninitializedReservation, v8::internal::NEW_SPACE, NULL, reservations_, v8::internal::Heap::ReserveSpace(), and v8::internal::PagedSpace::top().

Referenced by v8::internal::CodeSerializer::Deserialize(), and v8::internal::Snapshot::NewContextFromSnapshot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deserializing_user_code()

bool v8::internal::Deserializer::deserializing_user_code ( )
inline

Definition at line 268 of file serialize.h.

268 { return attached_objects_ != NULL; }

References attached_objects_, and NULL.

Referenced by ReadObject().

+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::Deserializer::DISALLOW_COPY_AND_ASSIGN ( Deserializer  )
private

◆ FlushICacheForNewCodeObjects()

void v8::internal::Deserializer::FlushICacheForNewCodeObjects ( )

Definition at line 607 of file serialize.cc.

607  {
608  PageIterator it(isolate_->heap()->code_space());
609  while (it.has_next()) {
610  Page* p = it.next();
611  CpuFeatures::FlushICache(p->area_start(), p->area_end() - p->area_start());
612  }
613 }
static void FlushICache(void *start, size_t size)

References v8::internal::MemoryChunk::area_end(), v8::internal::MemoryChunk::area_start(), v8::internal::Heap::code_space(), v8::internal::CpuFeatures::FlushICache(), v8::internal::Isolate::heap(), and isolate_.

Referenced by Deserialize(), and v8::internal::CodeSerializer::Deserialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAddressFromEnd()

HeapObject* v8::internal::Deserializer::GetAddressFromEnd ( int  space)
inlineprivate

Definition at line 297 of file serialize.h.

297  {
298  int offset = source_->GetInt();
299  if (space == LO_SPACE) return deserialized_large_objects_[offset];
301  offset <<= kObjectAlignmentBits;
302  return HeapObject::FromAddress(high_water_[space] - offset);
303  }
static HeapObject * FromAddress(Address address)
Definition: objects-inl.h:1464
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi space(in MBytes)
const int kObjectAlignmentBits
Definition: globals.h:225

References DCHECK, deserialized_large_objects_, v8::internal::HeapObject::FromAddress(), high_water_, v8::internal::SerializerDeserializer::kNumberOfPreallocatedSpaces, v8::internal::kObjectAlignmentBits, v8::internal::LO_SPACE, source_, and space().

+ Here is the call graph for this function:

◆ ProcessBackRefInSerializedCode()

Object * v8::internal::Deserializer::ProcessBackRefInSerializedCode ( Object obj)
private

Definition at line 767 of file serialize.cc.

767  {
768  if (obj->IsInternalizedString()) {
769  return String::cast(obj)->GetForwardedInternalizedString();
770  }
771  return obj;
772 }

◆ ProcessNewObjectFromSerializedCode()

HeapObject * v8::internal::Deserializer::ProcessNewObjectFromSerializedCode ( HeapObject obj)
private

Definition at line 749 of file serialize.cc.

749  {
750  if (obj->IsString()) {
751  String* string = String::cast(obj);
752  // Uninitialize hash field as the hash seed may have changed.
753  string->set_hash_field(String::kEmptyHashField);
754  if (string->IsInternalizedString()) {
756  HandleScope scope(isolate_);
757  StringTableInsertionKey key(string);
758  String* canonical = *StringTable::LookupKey(isolate_, &key);
759  string->SetForwardedInternalizedString(canonical);
760  return canonical;
761  }
762  }
763  return obj;
764 }
static const int kEmptyHashField
Definition: objects.h:8534
static Handle< String > LookupKey(Isolate *isolate, HashTableKey *key)
Definition: objects.cc:14713

References isolate_, v8::internal::Name::kEmptyHashField, and v8::internal::StringTable::LookupKey().

Referenced by ReadObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadChunk()

void v8::internal::Deserializer::ReadChunk ( Object **  start,
Object **  end,
int  space,
Address  object_address 
)
private

Definition at line 837 of file serialize.cc.

840  {
841  Isolate* const isolate = isolate_;
842  // Write barrier support costs around 1% in startup time. In fact there
843  // are no new space objects in current boot snapshots, so it's not needed,
844  // but that may change.
845  bool write_barrier_needed = (current_object_address != NULL &&
846  source_space != NEW_SPACE &&
847  source_space != CELL_SPACE &&
848  source_space != PROPERTY_CELL_SPACE &&
849  source_space != CODE_SPACE &&
850  source_space != OLD_DATA_SPACE);
851  while (current < limit) {
852  int data = source_->Get();
853  switch (data) {
854 #define CASE_STATEMENT(where, how, within, space_number) \
855  case where + how + within + space_number: \
856  STATIC_ASSERT((where & ~kPointedToMask) == 0); \
857  STATIC_ASSERT((how & ~kHowToCodeMask) == 0); \
858  STATIC_ASSERT((within & ~kWhereToPointMask) == 0); \
859  STATIC_ASSERT((space_number & ~kSpaceMask) == 0);
860 
861 #define CASE_BODY(where, how, within, space_number_if_any) \
862  { \
863  bool emit_write_barrier = false; \
864  bool current_was_incremented = false; \
865  int space_number = space_number_if_any == kAnyOldSpace \
866  ? (data & kSpaceMask) \
867  : space_number_if_any; \
868  if (where == kNewObject && how == kPlain && within == kStartOfObject) { \
869  ReadObject(space_number, current); \
870  emit_write_barrier = (space_number == NEW_SPACE); \
871  } else { \
872  Object* new_object = NULL; /* May not be a real Object pointer. */ \
873  if (where == kNewObject) { \
874  ReadObject(space_number, &new_object); \
875  } else if (where == kRootArray) { \
876  int root_id = source_->GetInt(); \
877  new_object = isolate->heap()->roots_array_start()[root_id]; \
878  emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
879  } else if (where == kPartialSnapshotCache) { \
880  int cache_index = source_->GetInt(); \
881  new_object = isolate->serialize_partial_snapshot_cache()[cache_index]; \
882  emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
883  } else if (where == kExternalReference) { \
884  int skip = source_->GetInt(); \
885  current = reinterpret_cast<Object**>( \
886  reinterpret_cast<Address>(current) + skip); \
887  int reference_id = source_->GetInt(); \
888  Address address = external_reference_decoder_->Decode(reference_id); \
889  new_object = reinterpret_cast<Object*>(address); \
890  } else if (where == kBackref) { \
891  emit_write_barrier = (space_number == NEW_SPACE); \
892  new_object = GetAddressFromEnd(data & kSpaceMask); \
893  if (deserializing_user_code()) { \
894  new_object = ProcessBackRefInSerializedCode(new_object); \
895  } \
896  } else if (where == kBuiltin) { \
897  DCHECK(deserializing_user_code()); \
898  int builtin_id = source_->GetInt(); \
899  DCHECK_LE(0, builtin_id); \
900  DCHECK_LT(builtin_id, Builtins::builtin_count); \
901  Builtins::Name name = static_cast<Builtins::Name>(builtin_id); \
902  new_object = isolate->builtins()->builtin(name); \
903  emit_write_barrier = false; \
904  } else if (where == kAttachedReference) { \
905  DCHECK(deserializing_user_code()); \
906  int index = source_->GetInt(); \
907  new_object = *attached_objects_->at(index); \
908  emit_write_barrier = isolate->heap()->InNewSpace(new_object); \
909  } else { \
910  DCHECK(where == kBackrefWithSkip); \
911  int skip = source_->GetInt(); \
912  current = reinterpret_cast<Object**>( \
913  reinterpret_cast<Address>(current) + skip); \
914  emit_write_barrier = (space_number == NEW_SPACE); \
915  new_object = GetAddressFromEnd(data & kSpaceMask); \
916  if (deserializing_user_code()) { \
917  new_object = ProcessBackRefInSerializedCode(new_object); \
918  } \
919  } \
920  if (within == kInnerPointer) { \
921  if (space_number != CODE_SPACE || new_object->IsCode()) { \
922  Code* new_code_object = reinterpret_cast<Code*>(new_object); \
923  new_object = \
924  reinterpret_cast<Object*>(new_code_object->instruction_start()); \
925  } else { \
926  DCHECK(space_number == CODE_SPACE); \
927  Cell* cell = Cell::cast(new_object); \
928  new_object = reinterpret_cast<Object*>(cell->ValueAddress()); \
929  } \
930  } \
931  if (how == kFromCode) { \
932  Address location_of_branch_data = reinterpret_cast<Address>(current); \
933  Assembler::deserialization_set_special_target_at( \
934  location_of_branch_data, \
935  Code::cast(HeapObject::FromAddress(current_object_address)), \
936  reinterpret_cast<Address>(new_object)); \
937  location_of_branch_data += Assembler::kSpecialTargetSize; \
938  current = reinterpret_cast<Object**>(location_of_branch_data); \
939  current_was_incremented = true; \
940  } else { \
941  *current = new_object; \
942  } \
943  } \
944  if (emit_write_barrier && write_barrier_needed) { \
945  Address current_address = reinterpret_cast<Address>(current); \
946  isolate->heap()->RecordWrite( \
947  current_object_address, \
948  static_cast<int>(current_address - current_object_address)); \
949  } \
950  if (!current_was_incremented) { \
951  current++; \
952  } \
953  break; \
954  }
955 
956 // This generates a case and a body for the new space (which has to do extra
957 // write barrier handling) and handles the other spaces with 8 fall-through
958 // cases and one body.
959 #define ALL_SPACES(where, how, within) \
960  CASE_STATEMENT(where, how, within, NEW_SPACE) \
961  CASE_BODY(where, how, within, NEW_SPACE) \
962  CASE_STATEMENT(where, how, within, OLD_DATA_SPACE) \
963  CASE_STATEMENT(where, how, within, OLD_POINTER_SPACE) \
964  CASE_STATEMENT(where, how, within, CODE_SPACE) \
965  CASE_STATEMENT(where, how, within, MAP_SPACE) \
966  CASE_STATEMENT(where, how, within, CELL_SPACE) \
967  CASE_STATEMENT(where, how, within, PROPERTY_CELL_SPACE) \
968  CASE_STATEMENT(where, how, within, LO_SPACE) \
969  CASE_BODY(where, how, within, kAnyOldSpace)
970 
971 #define FOUR_CASES(byte_code) \
972  case byte_code: \
973  case byte_code + 1: \
974  case byte_code + 2: \
975  case byte_code + 3:
976 
977 #define SIXTEEN_CASES(byte_code) \
978  FOUR_CASES(byte_code) \
979  FOUR_CASES(byte_code + 4) \
980  FOUR_CASES(byte_code + 8) \
981  FOUR_CASES(byte_code + 12)
982 
983 #define COMMON_RAW_LENGTHS(f) \
984  f(1) \
985  f(2) \
986  f(3) \
987  f(4) \
988  f(5) \
989  f(6) \
990  f(7) \
991  f(8) \
992  f(9) \
993  f(10) \
994  f(11) \
995  f(12) \
996  f(13) \
997  f(14) \
998  f(15) \
999  f(16) \
1000  f(17) \
1001  f(18) \
1002  f(19) \
1003  f(20) \
1004  f(21) \
1005  f(22) \
1006  f(23) \
1007  f(24) \
1008  f(25) \
1009  f(26) \
1010  f(27) \
1011  f(28) \
1012  f(29) \
1013  f(30) \
1014  f(31)
1015 
1016  // We generate 15 cases and bodies that process special tags that combine
1017  // the raw data tag and the length into one byte.
1018 #define RAW_CASE(index) \
1019  case kRawData + index: { \
1020  byte* raw_data_out = reinterpret_cast<byte*>(current); \
1021  source_->CopyRaw(raw_data_out, index * kPointerSize); \
1022  current = \
1023  reinterpret_cast<Object**>(raw_data_out + index * kPointerSize); \
1024  break; \
1025  }
1027 #undef RAW_CASE
1028 
1029  // Deserialize a chunk of raw data that doesn't have one of the popular
1030  // lengths.
1031  case kRawData: {
1032  int size = source_->GetInt();
1033  byte* raw_data_out = reinterpret_cast<byte*>(current);
1034  source_->CopyRaw(raw_data_out, size);
1035  break;
1036  }
1037 
1040  int root_id = RootArrayConstantFromByteCode(data);
1041  Object* object = isolate->heap()->roots_array_start()[root_id];
1042  DCHECK(!isolate->heap()->InNewSpace(object));
1043  *current++ = object;
1044  break;
1045  }
1046 
1049  int root_id = RootArrayConstantFromByteCode(data);
1050  int skip = source_->GetInt();
1051  current = reinterpret_cast<Object**>(
1052  reinterpret_cast<intptr_t>(current) + skip);
1053  Object* object = isolate->heap()->roots_array_start()[root_id];
1054  DCHECK(!isolate->heap()->InNewSpace(object));
1055  *current++ = object;
1056  break;
1057  }
1058 
1059  case kRepeat: {
1060  int repeats = source_->GetInt();
1061  Object* object = current[-1];
1062  DCHECK(!isolate->heap()->InNewSpace(object));
1063  for (int i = 0; i < repeats; i++) current[i] = object;
1064  current += repeats;
1065  break;
1066  }
1067 
1070  STATIC_ASSERT(kMaxRepeats == 13);
1071  case kConstantRepeat:
1075  int repeats = RepeatsForCode(data);
1076  Object* object = current[-1];
1077  DCHECK(!isolate->heap()->InNewSpace(object));
1078  for (int i = 0; i < repeats; i++) current[i] = object;
1079  current += repeats;
1080  break;
1081  }
1082 
1083  // Deserialize a new object and write a pointer to it to the current
1084  // object.
1086  // Support for direct instruction pointers in functions. It's an inner
1087  // pointer because it points at the entry point, not at the start of the
1088  // code object.
1091  // Deserialize a new code object and write a pointer to its first
1092  // instruction to the current code object.
1094  // Find a recently deserialized object using its offset from the current
1095  // allocation point and write a pointer to it to the current object.
1098 #if defined(V8_TARGET_ARCH_MIPS) || V8_OOL_CONSTANT_POOL || \
1099  defined(V8_TARGET_ARCH_MIPS64)
1100  // Deserialize a new object from pointer found in code and write
1101  // a pointer to it to the current object. Required only for MIPS or ARM
1102  // with ool constant pool, and omitted on the other architectures because
1103  // it is fully unrolled and would cause bloat.
1105  // Find a recently deserialized code object using its offset from the
1106  // current allocation point and write a pointer to it to the current
1107  // object. Required only for MIPS or ARM with ool constant pool.
1110 #endif
1111  // Find a recently deserialized code object using its offset from the
1112  // current allocation point and write a pointer to its first instruction
1113  // to the current code object or the instruction pointer in a function
1114  // object.
1119  // Find an object in the roots array and write a pointer to it to the
1120  // current object.
1123 #if defined(V8_TARGET_ARCH_MIPS) || V8_OOL_CONSTANT_POOL || \
1124  defined(V8_TARGET_ARCH_MIPS64)
1125  // Find an object in the roots array and write a pointer to it to in code.
1128 #endif
1129  // Find an object in the partial snapshots cache and write a pointer to it
1130  // to the current object.
1133  kPlain,
1135  0)
1136  // Find an code entry in the partial snapshots cache and
1137  // write a pointer to it to the current object.
1140  kPlain,
1141  kInnerPointer,
1142  0)
1143  // Find an external reference and write a pointer to it to the current
1144  // object.
1147  kPlain,
1149  0)
1150  // Find an external reference and write a pointer to it in the current
1151  // code object.
1154  kFromCode,
1156  0)
1157  // Find a builtin and write a pointer to it to the current object.
1160 #if V8_OOL_CONSTANT_POOL
1161  // Find a builtin code entry and write a pointer to it to the current
1162  // object.
1165 #endif
1166  // Find a builtin and write a pointer to it in the current code object.
1169  // Find an object in the attached references and write a pointer to it to
1170  // the current object.
1177 
1178 #undef CASE_STATEMENT
1179 #undef CASE_BODY
1180 #undef ALL_SPACES
1181 
1182  case kSkip: {
1183  int size = source_->GetInt();
1184  current = reinterpret_cast<Object**>(
1185  reinterpret_cast<intptr_t>(current) + size);
1186  break;
1187  }
1188 
1189  case kNativesStringResource: {
1190  int index = source_->Get();
1191  Vector<const char> source_vector = Natives::GetRawScriptSource(index);
1192  NativesExternalStringResource* resource =
1193  new NativesExternalStringResource(isolate->bootstrapper(),
1194  source_vector.start(),
1195  source_vector.length());
1196  *current++ = reinterpret_cast<Object*>(resource);
1197  break;
1198  }
1199 
1200  case kSynchronize: {
1201  // If we get here then that indicates that you have a mismatch between
1202  // the number of GC roots when serializing and deserializing.
1203  UNREACHABLE();
1204  }
1205 
1206  default:
1207  UNREACHABLE();
1208  }
1209  }
1210  DCHECK_EQ(limit, current);
1211 }
static const int kOldSpaceRoots
Definition: heap.h:1235
static Vector< const char > GetRawScriptSource(int index)
STATIC_ASSERT(kNumberOfSpaces<=kSpaceMask+1)
static int RootArrayConstantFromByteCode(int byte_code)
Definition: serialize.h:228
static int RepeatsForCode(int byte_code)
Definition: serialize.h:221
static const int kNativesStringResource
Definition: serialize.h:212
static const int kRootArrayNumberOfConstantEncodings
Definition: serialize.h:227
static const int kRootArrayConstants
Definition: serialize.h:225
#define UNREACHABLE()
Definition: logging.h:30
@ OLD_DATA_SPACE
Definition: globals.h:361
@ PROPERTY_CELL_SPACE
Definition: globals.h:365
#define ALL_SPACES(where, how, within)
#define CASE_STATEMENT(where, how, within, space_number)
#define COMMON_RAW_LENGTHS(f)
#define CASE_BODY(where, how, within, space_number_if_any)
#define FOUR_CASES(byte_code)
#define RAW_CASE(index)
#define SIXTEEN_CASES(byte_code)

References ALL_SPACES, v8::internal::Isolate::bootstrapper(), CASE_BODY, CASE_STATEMENT, v8::internal::CELL_SPACE, v8::internal::CODE_SPACE, COMMON_RAW_LENGTHS, DCHECK, DCHECK_EQ, FOUR_CASES, v8::internal::NativesCollection< type >::GetRawScriptSource(), v8::internal::Isolate::heap(), v8::internal::Heap::InNewSpace(), isolate_, v8::internal::SerializerDeserializer::kAttachedReference, v8::internal::SerializerDeserializer::kBackref, v8::internal::SerializerDeserializer::kBackrefWithSkip, v8::internal::SerializerDeserializer::kBuiltin, v8::internal::SerializerDeserializer::kConstantRepeat, v8::internal::SerializerDeserializer::kExternalReference, v8::internal::SerializerDeserializer::kFromCode, v8::internal::SerializerDeserializer::kHasSkipDistance, v8::internal::SerializerDeserializer::kInnerPointer, v8::internal::SerializerDeserializer::kMaxRepeats, v8::internal::SerializerDeserializer::kNativesStringResource, v8::internal::SerializerDeserializer::kNewObject, v8::internal::SerializerDeserializer::kNoSkipDistance, v8::internal::Heap::kOldSpaceRoots, v8::internal::SerializerDeserializer::kPartialSnapshotCache, v8::internal::SerializerDeserializer::kPlain, v8::internal::SerializerDeserializer::kRawData, v8::internal::SerializerDeserializer::kRepeat, v8::internal::SerializerDeserializer::kRootArray, v8::internal::SerializerDeserializer::kRootArrayConstants, v8::internal::SerializerDeserializer::kRootArrayNumberOfConstantEncodings, v8::internal::SerializerDeserializer::kSkip, v8::internal::SerializerDeserializer::kStartOfObject, v8::internal::SerializerDeserializer::kSynchronize, v8::internal::Vector< T >::length(), v8::internal::NEW_SPACE, NULL, v8::internal::OLD_DATA_SPACE, v8::internal::PROPERTY_CELL_SPACE, RAW_CASE, v8::internal::SerializerDeserializer::RepeatsForCode(), v8::internal::SerializerDeserializer::RootArrayConstantFromByteCode(), v8::internal::Heap::roots_array_start(), SIXTEEN_CASES, size, source_, v8::internal::Vector< T >::start(), v8::internal::SerializerDeserializer::STATIC_ASSERT(), and UNREACHABLE.

Referenced by ReadObject(), and VisitPointers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReadObject()

void v8::internal::Deserializer::ReadObject ( int  space_number,
Object **  write_back 
)
private

Definition at line 780 of file serialize.cc.

781  {
782  int size = source_->GetInt() << kObjectAlignmentBits;
783  Address address = Allocate(space_number, size);
784  HeapObject* obj = HeapObject::FromAddress(address);
786  Object** current = reinterpret_cast<Object**>(address);
787  Object** limit = current + (size >> kPointerSizeLog2);
788  if (FLAG_log_snapshot_positions) {
789  LOG(isolate_, SnapshotPositionEvent(address, source_->position()));
790  }
791  ReadChunk(current, limit, space_number, address);
792 
793  // TODO(mvstanton): consider treating the heap()->allocation_sites_list()
794  // as a (weak) root. If this root is relocated correctly,
795  // RelinkAllocationSite() isn't necessary.
796  if (obj->IsAllocationSite()) RelinkAllocationSite(AllocationSite::cast(obj));
797 
798  // Fix up strings from serialized user code.
800 
801  *write_back = obj;
802 #ifdef DEBUG
803  if (obj->IsCode()) {
804  DCHECK(space_number == CODE_SPACE || space_number == LO_SPACE);
805  } else {
806  DCHECK(space_number != CODE_SPACE);
807  }
808 #endif
809 }
void ReadChunk(Object **start, Object **end, int space, Address object_address)
Definition: serialize.cc:837
Address Allocate(int space_index, int size)
Definition: serialize.cc:820
void RelinkAllocationSite(AllocationSite *site)
Definition: serialize.cc:707
HeapObject * ProcessNewObjectFromSerializedCode(HeapObject *obj)
Definition: serialize.cc:749
void OnAllocationEvent(HeapObject *object, int size_in_bytes)
Definition: heap-inl.h:224
#define LOG(isolate, Call)
Definition: log.h:69
const int kPointerSizeLog2
Definition: globals.h:147

References Allocate(), v8::internal::CODE_SPACE, DCHECK, deserializing_user_code(), v8::internal::HeapObject::FromAddress(), v8::internal::Isolate::heap(), isolate_, v8::internal::kObjectAlignmentBits, v8::internal::kPointerSizeLog2, v8::internal::LO_SPACE, LOG, v8::internal::Heap::OnAllocationEvent(), ProcessNewObjectFromSerializedCode(), ReadChunk(), RelinkAllocationSite(), size, and source_.

+ Here is the call graph for this function:

◆ RelinkAllocationSite()

void v8::internal::Deserializer::RelinkAllocationSite ( AllocationSite site)
private

Definition at line 707 of file serialize.cc.

707  {
709  site->set_weak_next(isolate_->heap()->undefined_value());
710  } else {
711  site->set_weak_next(isolate_->heap()->allocation_sites_list());
712  }
714 }

References v8::internal::Heap::allocation_sites_list(), v8::internal::Smi::FromInt(), v8::internal::Isolate::heap(), isolate_, and v8::internal::Heap::set_allocation_sites_list().

Referenced by ReadObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_reservation()

void v8::internal::Deserializer::set_reservation ( int  space_number,
int  reservation 
)
inline

Definition at line 254 of file serialize.h.

254  {
255  DCHECK(space_number >= 0);
256  DCHECK(space_number < kNumberOfSpaces);
257  reservations_[space_number] = reservation;
258  }

References DCHECK, v8::internal::SerializerDeserializer::kNumberOfSpaces, and reservations_.

Referenced by v8::internal::CodeSerializer::Deserialize(), v8::internal::Snapshot::NewContextFromSnapshot(), and v8::internal::Snapshot::ReserveSpaceForLinkedInSnapshot().

+ Here is the caller graph for this function:

◆ SetAttachedObjects()

void v8::internal::Deserializer::SetAttachedObjects ( Vector< Handle< Object > > *  attached_objects)
inline

Definition at line 264 of file serialize.h.

264  {
265  attached_objects_ = attached_objects;
266  }

References attached_objects_.

Referenced by v8::internal::CodeSerializer::Deserialize().

+ Here is the caller graph for this function:

◆ VisitPointers()

void v8::internal::Deserializer::VisitPointers ( Object **  start,
Object **  end 
)
privatevirtual

Definition at line 700 of file serialize.cc.

700  {
701  // The space must be new space. Any other space would cause ReadChunk to try
702  // to update the remembered using NULL as the address.
703  ReadChunk(start, end, NEW_SPACE, NULL);
704 }

References v8::internal::NEW_SPACE, NULL, and ReadChunk().

+ Here is the call graph for this function:

◆ VisitRuntimeEntry()

virtual void v8::internal::Deserializer::VisitRuntimeEntry ( RelocInfo rinfo)
inlineprivatevirtual

Definition at line 273 of file serialize.h.

273  {
274  UNREACHABLE();
275  }

References UNREACHABLE.

Member Data Documentation

◆ attached_objects_

Vector<Handle<Object> >* v8::internal::Deserializer::attached_objects_
private

Definition at line 309 of file serialize.h.

Referenced by deserializing_user_code(), SetAttachedObjects(), and ~Deserializer().

◆ deserialized_large_objects_

List<HeapObject*> v8::internal::Deserializer::deserialized_large_objects_
private

Definition at line 321 of file serialize.h.

Referenced by Allocate(), and GetAddressFromEnd().

◆ external_reference_decoder_

ExternalReferenceDecoder* v8::internal::Deserializer::external_reference_decoder_
private

Definition at line 319 of file serialize.h.

Referenced by Deserialize(), DeserializePartial(), and ~Deserializer().

◆ high_water_

Address v8::internal::Deserializer::high_water_[kNumberOfPreallocatedSpaces]
private

Definition at line 314 of file serialize.h.

Referenced by Allocate(), Deserialize(), DeserializePartial(), and GetAddressFromEnd().

◆ isolate_

◆ kUninitializedReservation

const intptr_t v8::internal::Deserializer::kUninitializedReservation = -1
staticprivate

Definition at line 317 of file serialize.h.

Referenced by DeserializePartial(), and Deserializer().

◆ reservations_

int v8::internal::Deserializer::reservations_[kNumberOfSpaces]
private

Definition at line 316 of file serialize.h.

Referenced by Deserialize(), DeserializePartial(), Deserializer(), and set_reservation().

◆ source_

SnapshotByteSource* v8::internal::Deserializer::source_
private

Definition at line 311 of file serialize.h.

Referenced by Allocate(), GetAddressFromEnd(), ReadChunk(), and ReadObject().


The documentation for this class was generated from the following files: