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

Side by Side Diff: src/serialize.h

Issue 8344079: Shave 39% from snapshot size. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
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
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
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
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 int RootArrayConstantFromByteCode(int byte_code) {
281 return (byte_code & 0xf) | ((byte_code & 0x40) >> 2);
282 }
285 283
286 284
287 static const int kLargeData = LAST_SPACE; 285 static const int kLargeData = LAST_SPACE;
288 static const int kLargeCode = kLargeData + 1; 286 static const int kLargeCode = kLargeData + 1;
289 static const int kLargeFixedArray = kLargeCode + 1; 287 static const int kLargeFixedArray = kLargeCode + 1;
290 static const int kNumberOfSpaces = kLargeFixedArray + 1; 288 static const int kNumberOfSpaces = kLargeFixedArray + 1;
291 static const int kAnyOldSpace = -1; 289 static const int kAnyOldSpace = -1;
292 290
293 // A bitmask for getting the space out of an instruction. 291 // A bitmask for getting the space out of an instruction.
294 static const int kSpaceMask = 15; 292 static const int kSpaceMask = 15;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 466 }
469 serialization_enabled_ = true; 467 serialization_enabled_ = true;
470 } 468 }
471 469
472 static void Disable() { serialization_enabled_ = false; } 470 static void Disable() { serialization_enabled_ = false; }
473 // Call this when you have made use of the fact that there is no serialization 471 // Call this when you have made use of the fact that there is no serialization
474 // going on. 472 // going on.
475 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; } 473 static void TooLateToEnableNow() { too_late_to_enable_now_ = true; }
476 static bool enabled() { return serialization_enabled_; } 474 static bool enabled() { return serialization_enabled_; }
477 SerializationAddressMapper* address_mapper() { return &address_mapper_; } 475 SerializationAddressMapper* address_mapper() { return &address_mapper_; }
476 void PutRoot(
477 int index, HeapObject* object, HowToCode how, WhereToPoint where);
478 #ifdef DEBUG 478 #ifdef DEBUG
479 virtual void Synchronize(const char* tag); 479 virtual void Synchronize(const char* tag);
480 #endif 480 #endif
481 481
482 protected: 482 protected:
483 static const int kInvalidRootIndex = -1; 483 static const int kInvalidRootIndex = -1;
484 virtual int RootIndex(HeapObject* heap_object) = 0; 484
485 int RootIndex(HeapObject* heap_object);
485 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0; 486 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) = 0;
487 int root_index_wave_front() { return root_index_wave_front_; }
488 void set_root_index_wave_front(int value) { root_index_wave_front_ = value; }
Lasse Reichstein 2011/10/20 10:06:54 Assert that the wave-front moves forward?
Erik Corry 2011/10/20 11:01:42 Done.
486 489
487 class ObjectSerializer : public ObjectVisitor { 490 class ObjectSerializer : public ObjectVisitor {
488 public: 491 public:
489 ObjectSerializer(Serializer* serializer, 492 ObjectSerializer(Serializer* serializer,
490 Object* o, 493 Object* o,
491 SnapshotByteSink* sink, 494 SnapshotByteSink* sink,
492 HowToCode how_to_code, 495 HowToCode how_to_code,
493 WhereToPoint where_to_point) 496 WhereToPoint where_to_point)
494 : serializer_(serializer), 497 : serializer_(serializer),
495 object_(HeapObject::cast(o)), 498 object_(HeapObject::cast(o)),
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // sense in large object space. 554 // sense in large object space.
552 int fullness_[LAST_SPACE + 1]; 555 int fullness_[LAST_SPACE + 1];
553 SnapshotByteSink* sink_; 556 SnapshotByteSink* sink_;
554 int current_root_index_; 557 int current_root_index_;
555 ExternalReferenceEncoder* external_reference_encoder_; 558 ExternalReferenceEncoder* external_reference_encoder_;
556 static bool serialization_enabled_; 559 static bool serialization_enabled_;
557 // Did we already make use of the fact that serialization was not enabled? 560 // Did we already make use of the fact that serialization was not enabled?
558 static bool too_late_to_enable_now_; 561 static bool too_late_to_enable_now_;
559 int large_object_total_; 562 int large_object_total_;
560 SerializationAddressMapper address_mapper_; 563 SerializationAddressMapper address_mapper_;
564 int root_index_wave_front_;
561 565
562 friend class ObjectSerializer; 566 friend class ObjectSerializer;
563 friend class Deserializer; 567 friend class Deserializer;
564 568
565 DISALLOW_COPY_AND_ASSIGN(Serializer); 569 DISALLOW_COPY_AND_ASSIGN(Serializer);
566 }; 570 };
567 571
568 572
569 class PartialSerializer : public Serializer { 573 class PartialSerializer : public Serializer {
570 public: 574 public:
571 PartialSerializer(Serializer* startup_snapshot_serializer, 575 PartialSerializer(Serializer* startup_snapshot_serializer,
572 SnapshotByteSink* sink) 576 SnapshotByteSink* sink)
573 : Serializer(sink), 577 : Serializer(sink),
574 startup_serializer_(startup_snapshot_serializer) { 578 startup_serializer_(startup_snapshot_serializer) {
579 set_root_index_wave_front(Heap::kStrongRootListLength);
575 } 580 }
576 581
577 // Serialize the objects reachable from a single object pointer. 582 // Serialize the objects reachable from a single object pointer.
578 virtual void Serialize(Object** o); 583 virtual void Serialize(Object** o);
579 virtual void SerializeObject(Object* o, 584 virtual void SerializeObject(Object* o,
580 HowToCode how_to_code, 585 HowToCode how_to_code,
581 WhereToPoint where_to_point); 586 WhereToPoint where_to_point);
582 587
583 protected: 588 protected:
584 virtual int RootIndex(HeapObject* o);
585 virtual int PartialSnapshotCacheIndex(HeapObject* o); 589 virtual int PartialSnapshotCacheIndex(HeapObject* o);
586 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { 590 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
587 // Scripts should be referred only through shared function infos. We can't 591 // 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 592 // allow them to be part of the partial snapshot because they contain a
589 // unique ID, and deserializing several partial snapshots containing script 593 // unique ID, and deserializing several partial snapshots containing script
590 // would cause dupes. 594 // would cause dupes.
591 ASSERT(!o->IsScript()); 595 ASSERT(!o->IsScript());
592 return o->IsString() || o->IsSharedFunctionInfo() || 596 return o->IsString() || o->IsSharedFunctionInfo() ||
593 o->IsHeapNumber() || o->IsCode() || 597 o->IsHeapNumber() || o->IsCode() ||
594 o->IsSerializedScopeInfo() || 598 o->IsSerializedScopeInfo() ||
595 o->map() == HEAP->fixed_cow_array_map(); 599 o->map() == HEAP->fixed_cow_array_map();
596 } 600 }
597 601
598 private: 602 private:
599 Serializer* startup_serializer_; 603 Serializer* startup_serializer_;
600 DISALLOW_COPY_AND_ASSIGN(PartialSerializer); 604 DISALLOW_COPY_AND_ASSIGN(PartialSerializer);
601 }; 605 };
602 606
603 607
604 class StartupSerializer : public Serializer { 608 class StartupSerializer : public Serializer {
605 public: 609 public:
606 explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) { 610 explicit StartupSerializer(SnapshotByteSink* sink) : Serializer(sink) {
607 // Clear the cache of objects used by the partial snapshot. After the 611 // Clear the cache of objects used by the partial snapshot. After the
608 // strong roots have been serialized we can create a partial snapshot 612 // strong roots have been serialized we can create a partial snapshot
609 // which will repopulate the cache with objects neede by that partial 613 // which will repopulate the cache with objects needed by that partial
610 // snapshot. 614 // snapshot.
611 Isolate::Current()->set_serialize_partial_snapshot_cache_length(0); 615 Isolate::Current()->set_serialize_partial_snapshot_cache_length(0);
612 } 616 }
613 // Serialize the current state of the heap. The order is: 617 // Serialize the current state of the heap. The order is:
614 // 1) Strong references. 618 // 1) Strong references.
615 // 2) Partial snapshot cache. 619 // 2) Partial snapshot cache.
616 // 3) Weak references (eg the symbol table). 620 // 3) Weak references (eg the symbol table).
617 virtual void SerializeStrongReferences(); 621 virtual void SerializeStrongReferences();
618 virtual void SerializeObject(Object* o, 622 virtual void SerializeObject(Object* o,
619 HowToCode how_to_code, 623 HowToCode how_to_code,
620 WhereToPoint where_to_point); 624 WhereToPoint where_to_point);
621 void SerializeWeakReferences(); 625 void SerializeWeakReferences();
622 void Serialize() { 626 void Serialize() {
623 SerializeStrongReferences(); 627 SerializeStrongReferences();
624 SerializeWeakReferences(); 628 SerializeWeakReferences();
625 } 629 }
626 630
627 private: 631 private:
628 virtual int RootIndex(HeapObject* o) { return kInvalidRootIndex; }
629 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) { 632 virtual bool ShouldBeInThePartialSnapshotCache(HeapObject* o) {
630 return false; 633 return false;
631 } 634 }
632 }; 635 };
633 636
634 637
635 } } // namespace v8::internal 638 } } // namespace v8::internal
636 639
637 #endif // V8_SERIALIZE_H_ 640 #endif // V8_SERIALIZE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698