Revision: 20099
Author:   [email protected]
Date:     Thu Mar 20 08:33:06 2014 UTC
Log:      Make max size and max length of strings consistent.

[email protected]

Review URL: https://codereview.chromium.org/196133030
http://code.google.com/p/v8/source/detail?r=20099

Modified:
 /branches/bleeding_edge/src/heap-inl.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/runtime.cc

=======================================
--- /branches/bleeding_edge/src/heap-inl.h      Wed Mar 19 11:31:43 2014 UTC
+++ /branches/bleeding_edge/src/heap-inl.h      Thu Mar 20 08:33:06 2014 UTC
@@ -137,7 +137,7 @@

MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str,
                                                      uint32_t hash_field) {
-  if (str.length() > SeqOneByteString::kMaxLength) {
+  if (str.length() > String::kMaxLength) {
     return Failure::OutOfMemoryException(0x2);
   }
   // Compute map and object size.
@@ -170,7 +170,7 @@

MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
                                                      uint32_t hash_field) {
-  if (str.length() > SeqTwoByteString::kMaxLength) {
+  if (str.length() > String::kMaxLength) {
     return Failure::OutOfMemoryException(0x3);
   }
   // Compute map and object size.
=======================================
--- /branches/bleeding_edge/src/heap.cc Wed Mar 19 11:31:43 2014 UTC
+++ /branches/bleeding_edge/src/heap.cc Thu Mar 20 08:33:06 2014 UTC
@@ -4972,16 +4972,13 @@
   int size;
   Map* map;

+  if (chars > String::kMaxLength) {
+    return Failure::OutOfMemoryException(0x9);
+  }
   if (is_one_byte) {
-    if (chars > SeqOneByteString::kMaxLength) {
-      return Failure::OutOfMemoryException(0x9);
-    }
     map = ascii_internalized_string_map();
     size = SeqOneByteString::SizeFor(chars);
   } else {
-    if (chars > SeqTwoByteString::kMaxLength) {
-      return Failure::OutOfMemoryException(0xa);
-    }
     map = internalized_string_map();
     size = SeqTwoByteString::SizeFor(chars);
   }
@@ -5023,7 +5020,7 @@

 MaybeObject* Heap::AllocateRawOneByteString(int length,
                                             PretenureFlag pretenure) {
-  if (length < 0 || length > SeqOneByteString::kMaxLength) {
+  if (length < 0 || length > String::kMaxLength) {
     return Failure::OutOfMemoryException(0xb);
   }
   int size = SeqOneByteString::SizeFor(length);
@@ -5047,7 +5044,7 @@

 MaybeObject* Heap::AllocateRawTwoByteString(int length,
                                             PretenureFlag pretenure) {
-  if (length < 0 || length > SeqTwoByteString::kMaxLength) {
+  if (length < 0 || length > String::kMaxLength) {
     return Failure::OutOfMemoryException(0xc);
   }
   int size = SeqTwoByteString::SizeFor(length);
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Wed Mar 19 13:39:09 2014 UTC
+++ /branches/bleeding_edge/src/hydrogen.cc     Thu Mar 20 08:33:06 2014 UTC
@@ -1791,19 +1791,13 @@

 HValue* HGraphBuilder::BuildAddStringLengths(HValue* left_length,
                                              HValue* right_length) {
- // Compute the combined string length. If the result is larger than the max - // supported string length, we bailout to the runtime. This is done implicitly
-  // when converting the result back to a smi in case the max string length
- // equals the max smi value. Otherwise, for platforms with 32-bit smis, we do + // Compute the combined string length and check against max string length.
   HValue* length = AddUncasted<HAdd>(left_length, right_length);
-  STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
-  if (String::kMaxLength != Smi::kMaxValue) {
-    IfBuilder if_nooverflow(this);
-    if_nooverflow.If<HCompareNumericAndBranch>(
-        length, Add<HConstant>(String::kMaxLength), Token::LTE);
-    if_nooverflow.Then();
-    if_nooverflow.ElseDeopt("String length exceeds limit");
-  }
+  IfBuilder if_nooverflow(this);
+  if_nooverflow.If<HCompareNumericAndBranch>(
+      length, Add<HConstant>(String::kMaxLength), Token::LTE);
+  if_nooverflow.Then();
+  if_nooverflow.ElseDeopt("String length exceeds limit");
   return length;
 }

=======================================
--- /branches/bleeding_edge/src/objects.h       Wed Mar 19 16:29:19 2014 UTC
+++ /branches/bleeding_edge/src/objects.h       Thu Mar 20 08:33:06 2014 UTC
@@ -8904,7 +8904,7 @@
   static const int kEmptyStringHash = kIsNotArrayIndexMask;

   // Maximal string length.
-  static const int kMaxLength = (1 << (32 - 2)) - 1;
+  static const int kMaxLength = (1 << 28) - 16;

   // Max length for computing hash. For strings longer than this limit the
   // string length is used as the hash value.
@@ -9066,9 +9066,7 @@

   // Maximal memory usage for a single sequential ASCII string.
   static const int kMaxSize = 512 * MB - 1;
-  // Maximal length of a single sequential ASCII string.
- // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
-  static const int kMaxLength = (kMaxSize - kHeaderSize);
+  STATIC_CHECK((kMaxSize - kHeaderSize) >= String::kMaxLength);

  private:
   DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString);
@@ -9108,9 +9106,8 @@

   // Maximal memory usage for a single sequential two-byte string.
   static const int kMaxSize = 512 * MB - 1;
-  // Maximal length of a single sequential two-byte string.
- // Q.v. String::kMaxLength which is the maximal size of concatenated strings. - static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); + STATIC_CHECK(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t))
=
+               String::kMaxLength);

  private:
   DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Wed Mar 19 13:39:09 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Thu Mar 20 08:33:06 2014 UTC
@@ -7315,12 +7315,6 @@
   // Find total length of join result.
   int string_length = 0;
   bool is_ascii = separator->IsOneByteRepresentation();
-  int max_string_length;
-  if (is_ascii) {
-    max_string_length = SeqOneByteString::kMaxLength;
-  } else {
-    max_string_length = SeqTwoByteString::kMaxLength;
-  }
   bool overflow = false;
   CONVERT_NUMBER_CHECKED(int, elements_length,
                          Int32, elements_array->length());
@@ -7333,10 +7327,9 @@
     int length = string->length();
     if (is_ascii && !string->IsOneByteRepresentation()) {
       is_ascii = false;
-      max_string_length = SeqTwoByteString::kMaxLength;
     }
-    if (length > max_string_length ||
-        max_string_length - length < string_length) {
+    if (length > String::kMaxLength ||
+        String::kMaxLength - length < string_length) {
       overflow = true;
       break;
     }
@@ -7346,7 +7339,7 @@
   if (!overflow && separator_length > 0) {
     if (array_length <= 0x7fffffffu) {
       int separator_count = static_cast<int>(array_length) - 1;
-      int remaining_length = max_string_length - string_length;
+      int remaining_length = String::kMaxLength - string_length;
       if ((remaining_length / separator_length) >= separator_count) {
         string_length += separator_length * (array_length - 1);
       } else {

--
--
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