| OLD | NEW | 
|     1 // Copyright 2009 the V8 project authors. All rights reserved. |     1 // Copyright 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 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1803       if (result->IsFailure()) return result; |  1803       if (result->IsFailure()) return result; | 
|  1804       // Copy the characters into the new object. |  1804       // Copy the characters into the new object. | 
|  1805       uc16* dest = SeqTwoByteString::cast(result)->GetChars(); |  1805       uc16* dest = SeqTwoByteString::cast(result)->GetChars(); | 
|  1806       String::WriteToFlat(first, dest, 0, first_length); |  1806       String::WriteToFlat(first, dest, 0, first_length); | 
|  1807       String::WriteToFlat(second, dest + first_length, 0, second_length); |  1807       String::WriteToFlat(second, dest + first_length, 0, second_length); | 
|  1808       return result; |  1808       return result; | 
|  1809     } |  1809     } | 
|  1810   } |  1810   } | 
|  1811  |  1811  | 
|  1812   Map* map; |  1812   Map* map; | 
|  1813   if (length <= String::kMaxShortStringSize) { |  1813   if (length <= String::kMaxShortSize) { | 
|  1814     map = is_ascii ? short_cons_ascii_string_map() |  1814     map = is_ascii ? short_cons_ascii_string_map() | 
|  1815       : short_cons_string_map(); |  1815       : short_cons_string_map(); | 
|  1816   } else if (length <= String::kMaxMediumStringSize) { |  1816   } else if (length <= String::kMaxMediumSize) { | 
|  1817     map = is_ascii ? medium_cons_ascii_string_map() |  1817     map = is_ascii ? medium_cons_ascii_string_map() | 
|  1818       : medium_cons_string_map(); |  1818       : medium_cons_string_map(); | 
|  1819   } else { |  1819   } else { | 
|  1820     map = is_ascii ? long_cons_ascii_string_map() |  1820     map = is_ascii ? long_cons_ascii_string_map() | 
|  1821       : long_cons_string_map(); |  1821       : long_cons_string_map(); | 
|  1822   } |  1822   } | 
|  1823  |  1823  | 
|  1824   Object* result = Allocate(map, NEW_SPACE); |  1824   Object* result = Allocate(map, NEW_SPACE); | 
|  1825   if (result->IsFailure()) return result; |  1825   if (result->IsFailure()) return result; | 
|  1826   ASSERT(InNewSpace(result)); |  1826   ASSERT(InNewSpace(result)); | 
|  1827   ConsString* cons_string = ConsString::cast(result); |  1827   ConsString* cons_string = ConsString::cast(result); | 
|  1828   cons_string->set_first(first, SKIP_WRITE_BARRIER); |  1828   cons_string->set_first(first, SKIP_WRITE_BARRIER); | 
|  1829   cons_string->set_second(second, SKIP_WRITE_BARRIER); |  1829   cons_string->set_second(second, SKIP_WRITE_BARRIER); | 
|  1830   cons_string->set_length(length); |  1830   cons_string->set_length(length); | 
|  1831   return result; |  1831   return result; | 
|  1832 } |  1832 } | 
|  1833  |  1833  | 
|  1834  |  1834  | 
|  1835 Object* Heap::AllocateSlicedString(String* buffer, |  1835 Object* Heap::AllocateSlicedString(String* buffer, | 
|  1836                                    int start, |  1836                                    int start, | 
|  1837                                    int end) { |  1837                                    int end) { | 
|  1838   int length = end - start; |  1838   int length = end - start; | 
|  1839  |  1839  | 
|  1840   // If the resulting string is small make a sub string. |  1840   // If the resulting string is small make a sub string. | 
|  1841   if (length <= String::kMinNonFlatLength) { |  1841   if (length <= String::kMinNonFlatLength) { | 
|  1842     return Heap::AllocateSubString(buffer, start, end); |  1842     return Heap::AllocateSubString(buffer, start, end); | 
|  1843   } |  1843   } | 
|  1844  |  1844  | 
|  1845   Map* map; |  1845   Map* map; | 
|  1846   if (length <= String::kMaxShortStringSize) { |  1846   if (length <= String::kMaxShortSize) { | 
|  1847     map = buffer->IsAsciiRepresentation() ? |  1847     map = buffer->IsAsciiRepresentation() ? | 
|  1848       short_sliced_ascii_string_map() : |  1848       short_sliced_ascii_string_map() : | 
|  1849       short_sliced_string_map(); |  1849       short_sliced_string_map(); | 
|  1850   } else if (length <= String::kMaxMediumStringSize) { |  1850   } else if (length <= String::kMaxMediumSize) { | 
|  1851     map = buffer->IsAsciiRepresentation() ? |  1851     map = buffer->IsAsciiRepresentation() ? | 
|  1852       medium_sliced_ascii_string_map() : |  1852       medium_sliced_ascii_string_map() : | 
|  1853       medium_sliced_string_map(); |  1853       medium_sliced_string_map(); | 
|  1854   } else { |  1854   } else { | 
|  1855     map = buffer->IsAsciiRepresentation() ? |  1855     map = buffer->IsAsciiRepresentation() ? | 
|  1856       long_sliced_ascii_string_map() : |  1856       long_sliced_ascii_string_map() : | 
|  1857       long_sliced_string_map(); |  1857       long_sliced_string_map(); | 
|  1858   } |  1858   } | 
|  1859  |  1859  | 
|  1860   Object* result = Allocate(map, NEW_SPACE); |  1860   Object* result = Allocate(map, NEW_SPACE); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1905   } |  1905   } | 
|  1906   string_result->set_length_field(hasher.GetHashField()); |  1906   string_result->set_length_field(hasher.GetHashField()); | 
|  1907   return result; |  1907   return result; | 
|  1908 } |  1908 } | 
|  1909  |  1909  | 
|  1910  |  1910  | 
|  1911 Object* Heap::AllocateExternalStringFromAscii( |  1911 Object* Heap::AllocateExternalStringFromAscii( | 
|  1912     ExternalAsciiString::Resource* resource) { |  1912     ExternalAsciiString::Resource* resource) { | 
|  1913   Map* map; |  1913   Map* map; | 
|  1914   int length = resource->length(); |  1914   int length = resource->length(); | 
|  1915   if (length <= String::kMaxShortStringSize) { |  1915   if (length <= String::kMaxShortSize) { | 
|  1916     map = short_external_ascii_string_map(); |  1916     map = short_external_ascii_string_map(); | 
|  1917   } else if (length <= String::kMaxMediumStringSize) { |  1917   } else if (length <= String::kMaxMediumSize) { | 
|  1918     map = medium_external_ascii_string_map(); |  1918     map = medium_external_ascii_string_map(); | 
|  1919   } else { |  1919   } else { | 
|  1920     map = long_external_ascii_string_map(); |  1920     map = long_external_ascii_string_map(); | 
|  1921   } |  1921   } | 
|  1922  |  1922  | 
|  1923   Object* result = Allocate(map, NEW_SPACE); |  1923   Object* result = Allocate(map, NEW_SPACE); | 
|  1924   if (result->IsFailure()) return result; |  1924   if (result->IsFailure()) return result; | 
|  1925  |  1925  | 
|  1926   ExternalAsciiString* external_string = ExternalAsciiString::cast(result); |  1926   ExternalAsciiString* external_string = ExternalAsciiString::cast(result); | 
|  1927   external_string->set_length(length); |  1927   external_string->set_length(length); | 
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2652   while (buffer->has_more() && is_ascii) { |  2652   while (buffer->has_more() && is_ascii) { | 
|  2653     if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; |  2653     if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; | 
|  2654   } |  2654   } | 
|  2655   buffer->Rewind(); |  2655   buffer->Rewind(); | 
|  2656  |  2656  | 
|  2657   // Compute map and object size. |  2657   // Compute map and object size. | 
|  2658   int size; |  2658   int size; | 
|  2659   Map* map; |  2659   Map* map; | 
|  2660  |  2660  | 
|  2661   if (is_ascii) { |  2661   if (is_ascii) { | 
|  2662     if (chars <= String::kMaxShortStringSize) { |  2662     if (chars <= String::kMaxShortSize) { | 
|  2663       map = short_ascii_symbol_map(); |  2663       map = short_ascii_symbol_map(); | 
|  2664     } else if (chars <= String::kMaxMediumStringSize) { |  2664     } else if (chars <= String::kMaxMediumSize) { | 
|  2665       map = medium_ascii_symbol_map(); |  2665       map = medium_ascii_symbol_map(); | 
|  2666     } else { |  2666     } else { | 
|  2667       map = long_ascii_symbol_map(); |  2667       map = long_ascii_symbol_map(); | 
|  2668     } |  2668     } | 
|  2669     size = SeqAsciiString::SizeFor(chars); |  2669     size = SeqAsciiString::SizeFor(chars); | 
|  2670   } else { |  2670   } else { | 
|  2671     if (chars <= String::kMaxShortStringSize) { |  2671     if (chars <= String::kMaxShortSize) { | 
|  2672       map = short_symbol_map(); |  2672       map = short_symbol_map(); | 
|  2673     } else if (chars <= String::kMaxMediumStringSize) { |  2673     } else if (chars <= String::kMaxMediumSize) { | 
|  2674       map = medium_symbol_map(); |  2674       map = medium_symbol_map(); | 
|  2675     } else { |  2675     } else { | 
|  2676       map = long_symbol_map(); |  2676       map = long_symbol_map(); | 
|  2677     } |  2677     } | 
|  2678     size = SeqTwoByteString::SizeFor(chars); |  2678     size = SeqTwoByteString::SizeFor(chars); | 
|  2679   } |  2679   } | 
|  2680  |  2680  | 
|  2681   // Allocate string. |  2681   // Allocate string. | 
|  2682   AllocationSpace space = |  2682   AllocationSpace space = | 
|  2683       (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_DATA_SPACE; |  2683       (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_DATA_SPACE; | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  2713         ? new_space_.AllocateRaw(size) |  2713         ? new_space_.AllocateRaw(size) | 
|  2714         : lo_space_->AllocateRaw(size); |  2714         : lo_space_->AllocateRaw(size); | 
|  2715   } else { |  2715   } else { | 
|  2716     if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |  2716     if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 
|  2717     result = AllocateRaw(size, space, OLD_DATA_SPACE); |  2717     result = AllocateRaw(size, space, OLD_DATA_SPACE); | 
|  2718   } |  2718   } | 
|  2719   if (result->IsFailure()) return result; |  2719   if (result->IsFailure()) return result; | 
|  2720  |  2720  | 
|  2721   // Determine the map based on the string's length. |  2721   // Determine the map based on the string's length. | 
|  2722   Map* map; |  2722   Map* map; | 
|  2723   if (length <= String::kMaxShortStringSize) { |  2723   if (length <= String::kMaxShortSize) { | 
|  2724     map = short_ascii_string_map(); |  2724     map = short_ascii_string_map(); | 
|  2725   } else if (length <= String::kMaxMediumStringSize) { |  2725   } else if (length <= String::kMaxMediumSize) { | 
|  2726     map = medium_ascii_string_map(); |  2726     map = medium_ascii_string_map(); | 
|  2727   } else { |  2727   } else { | 
|  2728     map = long_ascii_string_map(); |  2728     map = long_ascii_string_map(); | 
|  2729   } |  2729   } | 
|  2730  |  2730  | 
|  2731   // Partially initialize the object. |  2731   // Partially initialize the object. | 
|  2732   HeapObject::cast(result)->set_map(map); |  2732   HeapObject::cast(result)->set_map(map); | 
|  2733   String::cast(result)->set_length(length); |  2733   String::cast(result)->set_length(length); | 
|  2734   ASSERT_EQ(size, HeapObject::cast(result)->Size()); |  2734   ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 
|  2735   return result; |  2735   return result; | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  2750         ? new_space_.AllocateRaw(size) |  2750         ? new_space_.AllocateRaw(size) | 
|  2751         : lo_space_->AllocateRaw(size); |  2751         : lo_space_->AllocateRaw(size); | 
|  2752   } else { |  2752   } else { | 
|  2753     if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |  2753     if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 
|  2754     result = AllocateRaw(size, space, OLD_DATA_SPACE); |  2754     result = AllocateRaw(size, space, OLD_DATA_SPACE); | 
|  2755   } |  2755   } | 
|  2756   if (result->IsFailure()) return result; |  2756   if (result->IsFailure()) return result; | 
|  2757  |  2757  | 
|  2758   // Determine the map based on the string's length. |  2758   // Determine the map based on the string's length. | 
|  2759   Map* map; |  2759   Map* map; | 
|  2760   if (length <= String::kMaxShortStringSize) { |  2760   if (length <= String::kMaxShortSize) { | 
|  2761     map = short_string_map(); |  2761     map = short_string_map(); | 
|  2762   } else if (length <= String::kMaxMediumStringSize) { |  2762   } else if (length <= String::kMaxMediumSize) { | 
|  2763     map = medium_string_map(); |  2763     map = medium_string_map(); | 
|  2764   } else { |  2764   } else { | 
|  2765     map = long_string_map(); |  2765     map = long_string_map(); | 
|  2766   } |  2766   } | 
|  2767  |  2767  | 
|  2768   // Partially initialize the object. |  2768   // Partially initialize the object. | 
|  2769   HeapObject::cast(result)->set_map(map); |  2769   HeapObject::cast(result)->set_map(map); | 
|  2770   String::cast(result)->set_length(length); |  2770   String::cast(result)->set_length(length); | 
|  2771   ASSERT_EQ(size, HeapObject::cast(result)->Size()); |  2771   ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 
|  2772   return result; |  2772   return result; | 
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  4030   for (int i = 0; i < kNumberOfCaches; i++) { |  4030   for (int i = 0; i < kNumberOfCaches; i++) { | 
|  4031     if (caches_[i] != NULL) { |  4031     if (caches_[i] != NULL) { | 
|  4032       delete caches_[i]; |  4032       delete caches_[i]; | 
|  4033       caches_[i] = NULL; |  4033       caches_[i] = NULL; | 
|  4034     } |  4034     } | 
|  4035   } |  4035   } | 
|  4036 } |  4036 } | 
|  4037  |  4037  | 
|  4038  |  4038  | 
|  4039 } }  // namespace v8::internal |  4039 } }  // namespace v8::internal | 
| OLD | NEW |