Revision: 24824
Author:   [email protected]
Date:     Thu Oct 23 08:25:42 2014 UTC
Log:      Small fixes for the code serializer.
- assertions regarding max heap object size.
- ensure string table capacity upfront.

[email protected]

Review URL: https://codereview.chromium.org/671843003
https://code.google.com/p/v8/source/detail?r=24824

Modified:
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/serialize.cc
 /branches/bleeding_edge/src/serialize.h

=======================================
--- /branches/bleeding_edge/src/objects.cc      Thu Oct 23 05:57:01 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Thu Oct 23 08:25:42 2014 UTC
@@ -14767,6 +14767,16 @@
     return result;
   }
 }
+
+
+void StringTable::EnsureCapacityForDeserialization(Isolate* isolate,
+                                                   int expected) {
+  Handle<StringTable> table = isolate->factory()->string_table();
+  // We need a key instance for the virtual hash function.
+  InternalizedStringKey dummy_key(Handle<String>::null());
+  table = StringTable::EnsureCapacity(table, expected, &dummy_key);
+  isolate->factory()->set_string_table(table);
+}


 Handle<String> StringTable::LookupString(Isolate* isolate,
=======================================
--- /branches/bleeding_edge/src/objects.h       Thu Oct 23 05:57:01 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Thu Oct 23 08:25:42 2014 UTC
@@ -3446,6 +3446,8 @@
       uint16_t c1,
       uint16_t c2);

+ static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
+
   DECLARE_CAST(StringTable)

  private:
=======================================
--- /branches/bleeding_edge/src/serialize.cc    Mon Oct 20 08:46:11 2014 UTC
+++ /branches/bleeding_edge/src/serialize.cc    Thu Oct 23 08:25:42 2014 UTC
@@ -1594,12 +1594,15 @@
   int size;
   const char* resource;
   // Find the map and size for the imaginary sequential string.
+  bool internalized = object_->IsInternalizedString();
   if (object_->IsExternalOneByteString()) {
-    map = isolate->heap()->one_byte_internalized_string_map();
+ map = internalized ? isolate->heap()->one_byte_internalized_string_map()
+                       : isolate->heap()->one_byte_string_map();
     size = SeqOneByteString::SizeFor(length);
     resource = ExternalOneByteString::cast(string)->resource()->data();
   } else {
-    map = isolate->heap()->internalized_string_map();
+    map = internalized ? isolate->heap()->internalized_string_map()
+                       : isolate->heap()->string_map();
     size = SeqTwoByteString::SizeFor(length);
     resource = reinterpret_cast<const char*>(
         ExternalTwoByteString::cast(string)->resource()->data());
@@ -1910,7 +1913,7 @@

 uint32_t Serializer::Allocate(int space, int size) {
   CHECK(space >= 0 && space < kNumberOfPreallocatedSpaces);
-  DCHECK(size > 0 && size < Page::kMaxRegularHeapObjectSize);
+  DCHECK(size > 0 && size <= Page::kMaxRegularHeapObjectSize);
   uint32_t new_chunk_size = pending_chunk_[space] + size;
   uint32_t allocation;
if (new_chunk_size > static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize)) {
@@ -2080,6 +2083,8 @@
     heap_object->ShortPrint();
     PrintF("\n");
   }
+
+  if (heap_object->IsInternalizedString()) num_internalized_strings_++;

   // Object has not yet been serialized.  Serialize it here.
   ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
@@ -2201,6 +2206,11 @@
     SnapshotByteSource payload(scd.Payload(), scd.PayloadLength());
     Deserializer deserializer(&payload);

+ // Eagerly expand string table to avoid allocations during deserialization.
+    StringTable::EnsureCapacityForDeserialization(isolate,
+ scd.NumInternalizedStrings());
+
+    // Set reservations.
     STATIC_ASSERT(NEW_SPACE == 0);
     int current_space = NEW_SPACE;
     Vector<const SerializedCodeData::Reservation> res = scd.Reservations();
@@ -2254,7 +2264,7 @@
     Vector<const uint32_t> chunks = cs->FinalAllocationChunks(i);
     for (int j = 0; j < chunks.length(); j++) {
       DCHECK(i == LO_SPACE ||
-             chunks[j] <
+             chunks[j] <=
                  static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
       uint32_t chunk = ChunkSizeBits::encode(chunks[j]) |
                        IsLastChunkBits::encode(j == chunks.length() - 1);
@@ -2277,6 +2287,7 @@

   // Set header values.
   SetHeaderValue(kCheckSumOffset, CheckSum(cs->source()));
+ SetHeaderValue(kNumInternalizedStringsOffset, cs->num_internalized_strings());
   SetHeaderValue(kReservationsOffset, reservations.length());
   SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
   SetHeaderValue(kPayloadLengthOffset, payload->length());
=======================================
--- /branches/bleeding_edge/src/serialize.h     Mon Oct 20 08:46:11 2014 UTC
+++ /branches/bleeding_edge/src/serialize.h     Thu Oct 23 08:25:42 2014 UTC
@@ -264,7 +264,7 @@
     DCHECK(space >= 0);
     DCHECK(space < kNumberOfSpaces);
     DCHECK(space == LO_SPACE ||
-           chunk < static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
+ chunk <= static_cast<uint32_t>(Page::kMaxRegularHeapObjectSize));
     reservations_[space].Add({chunk, NULL, NULL});
   }

@@ -619,17 +619,21 @@
   static const int kSourceObjectIndex = 0;
   static const int kCodeStubsBaseIndex = 1;

-  String* source() {
+  String* source() const {
     DCHECK(!AllowHeapAllocation::IsAllowed());
     return source_;
   }

   List<uint32_t>* stub_keys() { return &stub_keys_; }
+ int num_internalized_strings() const { return num_internalized_strings_; }

  private:
   CodeSerializer(Isolate* isolate, SnapshotByteSink* sink, String* source,
                  Code* main_code)
-      : Serializer(isolate, sink), source_(source), main_code_(main_code) {
+      : Serializer(isolate, sink),
+        source_(source),
+        main_code_(main_code),
+        num_internalized_strings_(0) {
     set_root_index_wave_front(Heap::kStrongRootListLength);
     InitializeCodeAddressMap();
   }
@@ -652,6 +656,7 @@
   DisallowHeapAllocation no_gc_;
   String* source_;
   Code* main_code_;
+  int num_internalized_strings_;
   List<uint32_t> stub_keys_;
   DISALLOW_COPY_AND_ASSIGN(CodeSerializer);
 };
@@ -694,6 +699,10 @@
     DISALLOW_COPY_AND_ASSIGN(Reservation);
   };

+  int NumInternalizedStrings() const {
+    return GetHeaderValue(kNumInternalizedStringsOffset);
+  }
+
   Vector<const Reservation> Reservations() const {
     return Vector<const Reservation>(reinterpret_cast<const Reservation*>(
script_data_->data() + kHeaderSize),
@@ -737,13 +746,15 @@

   // The data header consists of int-sized entries:
   // [0] version hash
-  // [1] number of code stub keys
-  // [2] payload length
- // [3..9] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
+  // [1] number of internalized strings
+  // [2] number of code stub keys
+  // [3] payload length
+ // [4..10] reservation sizes for spaces from NEW_SPACE to PROPERTY_CELL_SPACE.
   static const int kCheckSumOffset = 0;
-  static const int kReservationsOffset = 1;
-  static const int kNumCodeStubKeysOffset = 2;
-  static const int kPayloadLengthOffset = 3;
+  static const int kNumInternalizedStringsOffset = 1;
+  static const int kReservationsOffset = 2;
+  static const int kNumCodeStubKeysOffset = 3;
+  static const int kPayloadLengthOffset = 4;
   static const int kHeaderSize = (kPayloadLengthOffset + 1) * kIntSize;

   class ChunkSizeBits : public BitField<uint32_t, 0, 31> {};

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to