| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 int position() { return position_; } | 181 int position() { return position_; } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 const byte* data_; | 184 const byte* data_; |
| 185 int length_; | 185 int length_; |
| 186 int position_; | 186 int position_; |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 | 189 |
| 190 // It is very common to have a reference to objects at certain offsets in the | |
| 191 // heap. These offsets have been determined experimentally. We code | |
| 192 // references to such objects in a single byte that encodes the way the pointer | |
| 193 // is written (only plain pointers allowed), the space number and the offset. | |
| 194 // This only works for objects in the first page of a space. Don't use this for | |
| 195 // things in newspace since it bypasses the write barrier. | |
| 196 | |
| 197 static const int k64 = (sizeof(uintptr_t) - 4) / 4; | |
| 198 | |
| 199 #define COMMON_REFERENCE_PATTERNS(f) \ | |
| 200 f(kNumberOfSpaces, 2, (11 - k64)) \ | |
| 201 f((kNumberOfSpaces + 1), 2, 0) \ | |
| 202 f((kNumberOfSpaces + 2), 2, (142 - 16 * k64)) \ | |
| 203 f((kNumberOfSpaces + 3), 2, (74 - 15 * k64)) \ | |
| 204 f((kNumberOfSpaces + 4), 2, 5) \ | |
| 205 f((kNumberOfSpaces + 5), 1, 135) \ | |
| 206 f((kNumberOfSpaces + 6), 2, (228 - 39 * k64)) | |
| 207 | |
| 208 #define COMMON_RAW_LENGTHS(f) \ | 190 #define COMMON_RAW_LENGTHS(f) \ |
| 209 f(1, 1) \ | 191 f(1, 1) \ |
| 210 f(2, 2) \ | 192 f(2, 2) \ |
| 211 f(3, 3) \ | 193 f(3, 3) \ |
| 212 f(4, 4) \ | 194 f(4, 4) \ |
| 213 f(5, 5) \ | 195 f(5, 5) \ |
| 214 f(6, 6) \ | 196 f(6, 6) \ |
| 215 f(7, 7) \ | 197 f(7, 7) \ |
| 216 f(8, 8) \ | 198 f(8, 8) \ |
| 217 f(9, 12) \ | 199 f(9, 12) \ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 235 enum Where { | 217 enum Where { |
| 236 kNewObject = 0, // Object is next in snapshot. | 218 kNewObject = 0, // Object is next in snapshot. |
| 237 // 1-8 One per space. | 219 // 1-8 One per space. |
| 238 kRootArray = 0x9, // Object is found in root array. | 220 kRootArray = 0x9, // Object is found in root array. |
| 239 kPartialSnapshotCache = 0xa, // Object is in the cache. | 221 kPartialSnapshotCache = 0xa, // Object is in the cache. |
| 240 kExternalReference = 0xb, // Pointer to an external reference. | 222 kExternalReference = 0xb, // Pointer to an external reference. |
| 241 kSkip = 0xc, // Skip a pointer sized cell. | 223 kSkip = 0xc, // Skip a pointer sized cell. |
| 242 // 0xd-0xf Free. | 224 // 0xd-0xf Free. |
| 243 kBackref = 0x10, // Object is described relative to end. | 225 kBackref = 0x10, // Object is described relative to end. |
| 244 // 0x11-0x18 One per space. | 226 // 0x11-0x18 One per space. |
| 245 // 0x19-0x1f Common backref offsets. | 227 // 0x19-0x1f Free. |
| 246 kFromStart = 0x20, // Object is described relative to start. | 228 kFromStart = 0x20, // Object is described relative to start. |
| 247 // 0x21-0x28 One per space. | 229 // 0x21-0x28 One per space. |
| 248 // 0x29-0x2f Free. | 230 // 0x29-0x2f Free. |
| 249 // 0x30-0x3f Used by misc tags below. | 231 // 0x30-0x3f Used by misc tags below. |
| 250 kPointedToMask = 0x3f | 232 kPointedToMask = 0x3f |
| 251 }; | 233 }; |
| 252 | 234 |
| 253 // How to code the pointer to the object. | 235 // How to code the pointer to the object. |
| 254 enum HowToCode { | 236 enum HowToCode { |
| 255 kPlain = 0, // Straight pointer. | 237 kPlain = 0, // Straight pointer. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 272 // A tag emitted at strategic points in the snapshot to delineate sections. | 254 // A tag emitted at strategic points in the snapshot to delineate sections. |
| 273 // If the deserializer does not find these at the expected moments then it | 255 // If the deserializer does not find these at the expected moments then it |
| 274 // is an indication that the snapshot and the VM do not fit together. | 256 // is an indication that the snapshot and the VM do not fit together. |
| 275 // Examine the build process for architecture, version or configuration | 257 // Examine the build process for architecture, version or configuration |
| 276 // mismatches. | 258 // mismatches. |
| 277 static const int kSynchronize = 0x70; | 259 static const int kSynchronize = 0x70; |
| 278 // Used for the source code of the natives, which is in the executable, but | 260 // Used for the source code of the natives, which is in the executable, but |
| 279 // is referred to from external strings in the snapshot. | 261 // is referred to from external strings in the snapshot. |
| 280 static const int kNativesStringResource = 0x71; | 262 static const int kNativesStringResource = 0x71; |
| 281 static const int kNewPage = 0x72; | 263 static const int kNewPage = 0x72; |
| 282 // 0x73-0x7f Free. | 264 static const int kRepeat = 0x73; |
| 283 // 0xb0-0xbf Free. | 265 static const int kConstantRepeat = 0x74; |
| 284 // 0xf0-0xff Free. | 266 // 0x74-0x7f Repeat last word (subtract 0x73 to get the count). |
| 267 static const int kMaxRepeats = 0x7f - 0x73; |
| 268 static int CodeForRepeats(int repeats) { |
| 269 ASSERT(repeats >= 1 && repeats <= kMaxRepeats); |
| 270 return 0x73 + repeats; |
| 271 } |
| 272 static int RepeatsForCode(int byte_code) { |
| 273 ASSERT(byte_code >= kConstantRepeat && byte_code <= 0x7f); |
| 274 return byte_code - 0x73; |
| 275 } |
| 276 static const int kRootArrayLowConstants = 0xb0; |
| 277 // 0xb0-0xbf Things from the first 16 elements of the root array. |
| 278 static const int kRootArrayHighConstants = 0xf0; |
| 279 // 0xf0-0xff Things from the next 16 elements of the root array. |
| 280 static const int kRootArrayNumberOfConstantEncodings = 0x20; |
| 281 static const int kRootArrayNumberOfLowConstantEncodings = 0x10; |
| 282 static int RootArrayConstantFromByteCode(int byte_code) { |
| 283 int constant = (byte_code & 0xf) | ((byte_code & 0x40) >> 2); |
| 284 ASSERT(constant >= 0 && constant < kRootArrayNumberOfConstantEncodings); |
| 285 return constant; |
| 286 } |
| 285 | 287 |
| 286 | 288 |
| 287 static const int kLargeData = LAST_SPACE; | 289 static const int kLargeData = LAST_SPACE; |
| 288 static const int kLargeCode = kLargeData + 1; | 290 static const int kLargeCode = kLargeData + 1; |
| 289 static const int kLargeFixedArray = kLargeCode + 1; | 291 static const int kLargeFixedArray = kLargeCode + 1; |
| 290 static const int kNumberOfSpaces = kLargeFixedArray + 1; | 292 static const int kNumberOfSpaces = kLargeFixedArray + 1; |
| 291 static const int kAnyOldSpace = -1; | 293 static const int kAnyOldSpace = -1; |
| 292 | 294 |
| 293 // A bitmask for getting the space out of an instruction. | 295 // A bitmask for getting the space out of an instruction. |
| 294 static const int kSpaceMask = 15; | 296 static const int kSpaceMask = 15; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 virtual void VisitPointers(Object** start, Object** end); | 349 virtual void VisitPointers(Object** start, Object** end); |
| 348 | 350 |
| 349 virtual void VisitExternalReferences(Address* start, Address* end) { | 351 virtual void VisitExternalReferences(Address* start, Address* end) { |
| 350 UNREACHABLE(); | 352 UNREACHABLE(); |
| 351 } | 353 } |
| 352 | 354 |
| 353 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { | 355 virtual void VisitRuntimeEntry(RelocInfo* rinfo) { |
| 354 UNREACHABLE(); | 356 UNREACHABLE(); |
| 355 } | 357 } |
| 356 | 358 |
| 357 void ReadChunk(Object** start, Object** end, int space, Address address); | 359 // Fills in some heap data in an area from start to end (non-inclusive). The |
| 360 // space id is used for the write barrier. The object_address is the address |
| 361 // of the object we are writing into, or NULL if we are not writing into an |
| 362 // object, ie if we are writing a series of tagged values that are not on the |
| 363 // heap. |
| 364 void ReadChunk( |
| 365 Object** start, Object** end, int space, Address object_address); |
| 358 HeapObject* GetAddressFromStart(int space); | 366 HeapObject* GetAddressFromStart(int space); |
| 359 inline HeapObject* GetAddressFromEnd(int space); | 367 inline HeapObject* GetAddressFromEnd(int space); |
| 360 Address Allocate(int space_number, Space* space, int size); | 368 Address Allocate(int space_number, Space* space, int size); |
| 361 void ReadObject(int space_number, Space* space, Object** write_back); | 369 void ReadObject(int space_number, Space* space, Object** write_back); |
| 362 | 370 |
| 363 // Cached current isolate. | 371 // Cached current isolate. |
| 364 Isolate* isolate_; | 372 Isolate* isolate_; |
| 365 | 373 |
| 366 // Keep track of the pages in the paged spaces. | 374 // Keep track of the pages in the paged spaces. |
| 367 // (In large object space we are keeping track of individual objects | 375 // (In large object space we are keeping track of individual objects |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 476 } |
| 469 serialization_enabled_ = true; | 477 serialization_enabled_ = true; |
| 470 } | 478 } |
| 471 | 479 |
| 472 static void Disable() { serialization_enabled_ = false; } | 480 static void Disable() { serialization_enabled_ = false; } |
| 473 // Call this when you have made use of the fact that there is no serialization | 481 // Call this when you have made use of the fact that there is no serialization |
| 474 // going on. | 482 // going on. |
| 475 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } | 483 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } |
| 476 static bool enabled() { return serialization_enabled_; } | 484 static bool enabled() { return serialization_enabled_; } |
| 477 SerializationAddressMapper* address_mapper() { return &address_mapper_; } | 485 SerializationAddressMapper* address_mapper() { return &address_mapper_; } |
| 486 void PutRoot( |
| 487 int index, HeapObject* object, HowToCode how, WhereToPoint where); |
| 478 #ifdef DEBUG | 488 #ifdef DEBUG |
| 479 virtual void Synchronize(const char* tag); | 489 virtual void Synchronize(const char* tag); |
| 480 #endif | 490 #endif |
| 481 | 491 |
| 482 protected: | 492 protected: |
| 483 static const int kInvalidRootIndex = -1; | 493 static const int kInvalidRootIndex = -1; |
| 484 virtual int RootIndex(HeapObject* heap_object) = 0; | 494 |
| 495 int RootIndex(HeapObject* heap_object); |
| 485 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0; | 496 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0; |
| 497 intptr_t root_index_wave_front() { return root_index_wave_front_; } |
| 498 void set_root_index_wave_front(intptr_t value) { |
| 499 ASSERT(value >= root_index_wave_front_); |
| 500 root_index_wave_front_ = value; |
| 501 } |
| 486 | 502 |
| 487 class ObjectSerializer : public ObjectVisitor { | 503 class ObjectSerializer : public ObjectVisitor { |
| 488 public: | 504 public: |
| 489 ObjectSerializer(Serializer* serializer, | 505 ObjectSerializer(Serializer* serializer, |
| 490 Object* o, | 506 Object* o, |
| 491 SnapshotByteSink* sink, | 507 SnapshotByteSink* sink, |
| 492 HowToCode how_to_code, | 508 HowToCode how_to_code, |
| 493 WhereToPoint where_to_point) | 509 WhereToPoint where_to_point) |
| 494 : serializer_(serializer), | 510 : serializer_(serializer), |
| 495 object_(HeapObject::cast(o)), | 511 object_(HeapObject::cast(o)), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 // sense in large object space. | 567 // sense in large object space. |
| 552 int fullness_[LAST_SPACE + 1]; | 568 int fullness_[LAST_SPACE + 1]; |
| 553 SnapshotByteSink* sink_; | 569 SnapshotByteSink* sink_; |
| 554 int current_root_index_; | 570 int current_root_index_; |
| 555 ExternalReferenceEncoder* external_reference_encoder_; | 571 ExternalReferenceEncoder* external_reference_encoder_; |
| 556 static bool serialization_enabled_; | 572 static bool serialization_enabled_; |
| 557 // Did we already make use of the fact that serialization was not enabled? | 573 // Did we already make use of the fact that serialization was not enabled? |
| 558 static bool too_late_to_enable_now_; | 574 static bool too_late_to_enable_now_; |
| 559 int large_object_total_; | 575 int large_object_total_; |
| 560 SerializationAddressMapper address_mapper_; | 576 SerializationAddressMapper address_mapper_; |
| 577 intptr_t root_index_wave_front_; |
| 561 | 578 |
| 562 friend class ObjectSerializer; | 579 friend class ObjectSerializer; |
| 563 friend class Deserializer; | 580 friend class Deserializer; |
| 564 | 581 |
| 565 DISALLOW_COPY_AND_ASSIGN(Serializer); | 582 DISALLOW_COPY_AND_ASSIGN(Serializer); |
| 566 }; | 583 }; |
| 567 | 584 |
| 568 | 585 |
| 569 class PartialSerializer : public Serializer { | 586 class PartialSerializer : public Serializer { |
| 570 public: | 587 public: |
| 571 PartialSerializer(Serializer* startup_snapshot_serializer, | 588 PartialSerializer(Serializer* startup_snapshot_serializer, |
| 572 SnapshotByteSink* sink) | 589 SnapshotByteSink* sink) |
| 573 : Serializer(sink), | 590 : Serializer(sink), |
| 574 startup_serializer_(startup_snapshot_serializer) { | 591 startup_serializer_(startup_snapshot_serializer) { |
| 592 set_root_index_wave_front(Heap::kStrongRootListLength); |
| 575 } | 593 } |
| 576 | 594 |
| 577 // Serialize the objects reachable from a single object pointer. | 595 // Serialize the objects reachable from a single object pointer. |
| 578 virtual void Serialize(Object** o); | 596 virtual void Serialize(Object** o); |
| 579 virtual void SerializeObject(Object* o, | 597 virtual void SerializeObject(Object* o, |
| 580 HowToCode how_to_code, | 598 HowToCode how_to_code, |
| 581 WhereToPoint where_to_point); | 599 WhereToPoint where_to_point); |
| 582 | 600 |
| 583 protected: | 601 protected: |
| 584 virtual int RootIndex(HeapObject* o); | |
| 585 virtual int PartialSnapshotCacheIndex(HeapObject* o); | 602 virtual int PartialSnapshotCacheIndex(HeapObject* o); |
| 586 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 603 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
| 587 // Scripts should be referred only through shared function infos. We can't | 604 // Scripts should be referred only through shared function infos. We can't |
| 588 // allow them to be part of the partial snapshot because they contain a | 605 // allow them to be part of the partial snapshot because they contain a |
| 589 // unique ID, and deserializing several partial snapshots containing script | 606 // unique ID, and deserializing several partial snapshots containing script |
| 590 // would cause dupes. | 607 // would cause dupes. |
| 591 ASSERT(!o->IsScript()); | 608 ASSERT(!o->IsScript()); |
| 592 return o->IsString() || o->IsSharedFunctionInfo() || | 609 return o->IsString() || o->IsSharedFunctionInfo() || |
| 593 o->IsHeapNumber() || o->IsCode() || | 610 o->IsHeapNumber() || o->IsCode() || |
| 594 o->IsSerializedScopeInfo() || | 611 o->IsSerializedScopeInfo() || |
| 595 o->map() == HEAP->fixed_cow_array_map(); | 612 o->map() == HEAP->fixed_cow_array_map(); |
| 596 } | 613 } |
| 597 | 614 |
| 598 private: | 615 private: |
| 599 Serializer* startup_serializer_; | 616 Serializer* startup_serializer_; |
| 600 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); | 617 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); |
| 601 }; | 618 }; |
| 602 | 619 |
| 603 | 620 |
| 604 class StartupSerializer : public Serializer { | 621 class StartupSerializer : public Serializer { |
| 605 public: | 622 public: |
| 606 explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { | 623 explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { |
| 607 // Clear the cache of objects used by the partial snapshot. After the | 624 // Clear the cache of objects used by the partial snapshot. After the |
| 608 // strong roots have been serialized we can create a partial snapshot | 625 // strong roots have been serialized we can create a partial snapshot |
| 609 // which will repopulate the cache with objects neede by that partial | 626 // which will repopulate the cache with objects needed by that partial |
| 610 // snapshot. | 627 // snapshot. |
| 611 Isolate::Current()->set_serialize_partial_snapshot_cache_length(0); | 628 Isolate::Current()->set_serialize_partial_snapshot_cache_length(0); |
| 612 } | 629 } |
| 613 // Serialize the current state of the heap. The order is: | 630 // Serialize the current state of the heap. The order is: |
| 614 // 1) Strong references. | 631 // 1) Strong references. |
| 615 // 2) Partial snapshot cache. | 632 // 2) Partial snapshot cache. |
| 616 // 3) Weak references (eg the symbol table). | 633 // 3) Weak references (eg the symbol table). |
| 617 virtual void SerializeStrongReferences(); | 634 virtual void SerializeStrongReferences(); |
| 618 virtual void SerializeObject(Object* o, | 635 virtual void SerializeObject(Object* o, |
| 619 HowToCode how_to_code, | 636 HowToCode how_to_code, |
| 620 WhereToPoint where_to_point); | 637 WhereToPoint where_to_point); |
| 621 void SerializeWeakReferences(); | 638 void SerializeWeakReferences(); |
| 622 void Serialize() { | 639 void Serialize() { |
| 623 SerializeStrongReferences(); | 640 SerializeStrongReferences(); |
| 624 SerializeWeakReferences(); | 641 SerializeWeakReferences(); |
| 625 } | 642 } |
| 626 | 643 |
| 627 private: | 644 private: |
| 628 virtual int RootIndex(HeapObject* o) { return kInvalidRootIndex; } | |
| 629 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { | 645 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { |
| 630 return false; | 646 return false; |
| 631 } | 647 } |
| 632 }; | 648 }; |
| 633 | 649 |
| 634 | 650 |
| 635 } } // namespace v8::internal | 651 } } // namespace v8::internal |
| 636 | 652 |
| 637 #endif // V8_SERIALIZE_H_ | 653 #endif // V8_SERIALIZE_H_ |
| OLD | NEW |