| 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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 if (obj->IsFailure()) return false; | 1180 if (obj->IsFailure()) return false; |
| 1181 set_proxy_map(Map::cast(obj)); | 1181 set_proxy_map(Map::cast(obj)); |
| 1182 | 1182 |
| 1183 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { | 1183 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { |
| 1184 const StringTypeTable& entry = string_type_table[i]; | 1184 const StringTypeTable& entry = string_type_table[i]; |
| 1185 obj = AllocateMap(entry.type, entry.size); | 1185 obj = AllocateMap(entry.type, entry.size); |
| 1186 if (obj->IsFailure()) return false; | 1186 if (obj->IsFailure()) return false; |
| 1187 roots_[entry.index] = Map::cast(obj); | 1187 roots_[entry.index] = Map::cast(obj); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 obj = AllocateMap(SHORT_STRING_TYPE, SeqTwoByteString::kAlignedSize); | 1190 obj = AllocateMap(STRING_TYPE, SeqTwoByteString::kAlignedSize); |
| 1191 if (obj->IsFailure()) return false; | 1191 if (obj->IsFailure()) return false; |
| 1192 set_undetectable_short_string_map(Map::cast(obj)); | 1192 set_undetectable_string_map(Map::cast(obj)); |
| 1193 Map::cast(obj)->set_is_undetectable(); | 1193 Map::cast(obj)->set_is_undetectable(); |
| 1194 | 1194 |
| 1195 obj = AllocateMap(MEDIUM_STRING_TYPE, SeqTwoByteString::kAlignedSize); | 1195 obj = AllocateMap(ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); |
| 1196 if (obj->IsFailure()) return false; | 1196 if (obj->IsFailure()) return false; |
| 1197 set_undetectable_medium_string_map(Map::cast(obj)); | 1197 set_undetectable_ascii_string_map(Map::cast(obj)); |
| 1198 Map::cast(obj)->set_is_undetectable(); | |
| 1199 | |
| 1200 obj = AllocateMap(LONG_STRING_TYPE, SeqTwoByteString::kAlignedSize); | |
| 1201 if (obj->IsFailure()) return false; | |
| 1202 set_undetectable_long_string_map(Map::cast(obj)); | |
| 1203 Map::cast(obj)->set_is_undetectable(); | |
| 1204 | |
| 1205 obj = AllocateMap(SHORT_ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); | |
| 1206 if (obj->IsFailure()) return false; | |
| 1207 set_undetectable_short_ascii_string_map(Map::cast(obj)); | |
| 1208 Map::cast(obj)->set_is_undetectable(); | |
| 1209 | |
| 1210 obj = AllocateMap(MEDIUM_ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); | |
| 1211 if (obj->IsFailure()) return false; | |
| 1212 set_undetectable_medium_ascii_string_map(Map::cast(obj)); | |
| 1213 Map::cast(obj)->set_is_undetectable(); | |
| 1214 | |
| 1215 obj = AllocateMap(LONG_ASCII_STRING_TYPE, SeqAsciiString::kAlignedSize); | |
| 1216 if (obj->IsFailure()) return false; | |
| 1217 set_undetectable_long_ascii_string_map(Map::cast(obj)); | |
| 1218 Map::cast(obj)->set_is_undetectable(); | 1198 Map::cast(obj)->set_is_undetectable(); |
| 1219 | 1199 |
| 1220 obj = AllocateMap(BYTE_ARRAY_TYPE, ByteArray::kAlignedSize); | 1200 obj = AllocateMap(BYTE_ARRAY_TYPE, ByteArray::kAlignedSize); |
| 1221 if (obj->IsFailure()) return false; | 1201 if (obj->IsFailure()) return false; |
| 1222 set_byte_array_map(Map::cast(obj)); | 1202 set_byte_array_map(Map::cast(obj)); |
| 1223 | 1203 |
| 1224 obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize); | 1204 obj = AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize); |
| 1225 if (obj->IsFailure()) return false; | 1205 if (obj->IsFailure()) return false; |
| 1226 set_pixel_array_map(Map::cast(obj)); | 1206 set_pixel_array_map(Map::cast(obj)); |
| 1227 | 1207 |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 Object* result = AllocateRawTwoByteString(length); | 1829 Object* result = AllocateRawTwoByteString(length); |
| 1850 if (result->IsFailure()) return result; | 1830 if (result->IsFailure()) return result; |
| 1851 // Copy the characters into the new object. | 1831 // Copy the characters into the new object. |
| 1852 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); | 1832 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); |
| 1853 String::WriteToFlat(first, dest, 0, first_length); | 1833 String::WriteToFlat(first, dest, 0, first_length); |
| 1854 String::WriteToFlat(second, dest + first_length, 0, second_length); | 1834 String::WriteToFlat(second, dest + first_length, 0, second_length); |
| 1855 return result; | 1835 return result; |
| 1856 } | 1836 } |
| 1857 } | 1837 } |
| 1858 | 1838 |
| 1859 Map* map; | 1839 Map* map = is_ascii ? cons_ascii_string_map() : cons_string_map(); |
| 1860 if (length <= String::kMaxShortSize) { | |
| 1861 map = is_ascii ? short_cons_ascii_string_map() | |
| 1862 : short_cons_string_map(); | |
| 1863 } else if (length <= String::kMaxMediumSize) { | |
| 1864 map = is_ascii ? medium_cons_ascii_string_map() | |
| 1865 : medium_cons_string_map(); | |
| 1866 } else { | |
| 1867 map = is_ascii ? long_cons_ascii_string_map() | |
| 1868 : long_cons_string_map(); | |
| 1869 } | |
| 1870 | 1840 |
| 1871 Object* result = Allocate(map, | 1841 Object* result = Allocate(map, |
| 1872 always_allocate() ? OLD_POINTER_SPACE : NEW_SPACE); | 1842 always_allocate() ? OLD_POINTER_SPACE : NEW_SPACE); |
| 1873 if (result->IsFailure()) return result; | 1843 if (result->IsFailure()) return result; |
| 1874 ConsString* cons_string = ConsString::cast(result); | 1844 ConsString* cons_string = ConsString::cast(result); |
| 1875 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(); | 1845 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(); |
| 1846 cons_string->set_length(length); |
| 1847 cons_string->set_hash_field(String::kEmptyHashField); |
| 1876 cons_string->set_first(first, mode); | 1848 cons_string->set_first(first, mode); |
| 1877 cons_string->set_second(second, mode); | 1849 cons_string->set_second(second, mode); |
| 1878 cons_string->set_length(length); | |
| 1879 return result; | 1850 return result; |
| 1880 } | 1851 } |
| 1881 | 1852 |
| 1882 | 1853 |
| 1883 Object* Heap::AllocateSubString(String* buffer, | 1854 Object* Heap::AllocateSubString(String* buffer, |
| 1884 int start, | 1855 int start, |
| 1885 int end) { | 1856 int end) { |
| 1886 int length = end - start; | 1857 int length = end - start; |
| 1887 | 1858 |
| 1888 if (length == 1) { | 1859 if (length == 1) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1918 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); | 1889 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); |
| 1919 String::WriteToFlat(buffer, dest, start, end); | 1890 String::WriteToFlat(buffer, dest, start, end); |
| 1920 } | 1891 } |
| 1921 | 1892 |
| 1922 return result; | 1893 return result; |
| 1923 } | 1894 } |
| 1924 | 1895 |
| 1925 | 1896 |
| 1926 Object* Heap::AllocateExternalStringFromAscii( | 1897 Object* Heap::AllocateExternalStringFromAscii( |
| 1927 ExternalAsciiString::Resource* resource) { | 1898 ExternalAsciiString::Resource* resource) { |
| 1928 Map* map; | |
| 1929 size_t length = resource->length(); | 1899 size_t length = resource->length(); |
| 1930 if (length <= static_cast<size_t>(String::kMaxShortSize)) { | 1900 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 1931 map = short_external_ascii_string_map(); | |
| 1932 } else if (length <= static_cast<size_t>(String::kMaxMediumSize)) { | |
| 1933 map = medium_external_ascii_string_map(); | |
| 1934 } else if (length <= static_cast<size_t>(String::kMaxLength)) { | |
| 1935 map = long_external_ascii_string_map(); | |
| 1936 } else { | |
| 1937 Top::context()->mark_out_of_memory(); | 1901 Top::context()->mark_out_of_memory(); |
| 1938 return Failure::OutOfMemoryException(); | 1902 return Failure::OutOfMemoryException(); |
| 1939 } | 1903 } |
| 1940 | 1904 |
| 1905 Map* map = external_ascii_string_map(); |
| 1941 Object* result = Allocate(map, | 1906 Object* result = Allocate(map, |
| 1942 always_allocate() ? OLD_DATA_SPACE : NEW_SPACE); | 1907 always_allocate() ? OLD_DATA_SPACE : NEW_SPACE); |
| 1943 if (result->IsFailure()) return result; | 1908 if (result->IsFailure()) return result; |
| 1944 | 1909 |
| 1945 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); | 1910 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); |
| 1946 external_string->set_length(static_cast<int>(length)); | 1911 external_string->set_length(static_cast<int>(length)); |
| 1912 external_string->set_hash_field(String::kEmptyHashField); |
| 1947 external_string->set_resource(resource); | 1913 external_string->set_resource(resource); |
| 1948 | 1914 |
| 1949 return result; | 1915 return result; |
| 1950 } | 1916 } |
| 1951 | 1917 |
| 1952 | 1918 |
| 1953 Object* Heap::AllocateExternalStringFromTwoByte( | 1919 Object* Heap::AllocateExternalStringFromTwoByte( |
| 1954 ExternalTwoByteString::Resource* resource) { | 1920 ExternalTwoByteString::Resource* resource) { |
| 1955 size_t length = resource->length(); | 1921 size_t length = resource->length(); |
| 1956 if (length > static_cast<size_t>(String::kMaxLength)) { | 1922 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 1957 Top::context()->mark_out_of_memory(); | 1923 Top::context()->mark_out_of_memory(); |
| 1958 return Failure::OutOfMemoryException(); | 1924 return Failure::OutOfMemoryException(); |
| 1959 } | 1925 } |
| 1960 Map* map = ExternalTwoByteString::StringMap(static_cast<int>(length)); | 1926 |
| 1927 Map* map = Heap::external_string_map(); |
| 1961 Object* result = Allocate(map, | 1928 Object* result = Allocate(map, |
| 1962 always_allocate() ? OLD_DATA_SPACE : NEW_SPACE); | 1929 always_allocate() ? OLD_DATA_SPACE : NEW_SPACE); |
| 1963 if (result->IsFailure()) return result; | 1930 if (result->IsFailure()) return result; |
| 1964 | 1931 |
| 1965 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); | 1932 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); |
| 1966 external_string->set_length(static_cast<int>(length)); | 1933 external_string->set_length(static_cast<int>(length)); |
| 1934 external_string->set_hash_field(String::kEmptyHashField); |
| 1967 external_string->set_resource(resource); | 1935 external_string->set_resource(resource); |
| 1968 | 1936 |
| 1969 return result; | 1937 return result; |
| 1970 } | 1938 } |
| 1971 | 1939 |
| 1972 | 1940 |
| 1973 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { | 1941 Object* Heap::LookupSingleCharacterStringFromCode(uint16_t code) { |
| 1974 if (code <= String::kMaxAsciiCharCode) { | 1942 if (code <= String::kMaxAsciiCharCode) { |
| 1975 Object* value = Heap::single_character_string_cache()->get(code); | 1943 Object* value = Heap::single_character_string_cache()->get(code); |
| 1976 if (value != Heap::undefined_value()) return value; | 1944 if (value != Heap::undefined_value()) return value; |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2597 return result; | 2565 return result; |
| 2598 } | 2566 } |
| 2599 | 2567 |
| 2600 | 2568 |
| 2601 Map* Heap::SymbolMapForString(String* string) { | 2569 Map* Heap::SymbolMapForString(String* string) { |
| 2602 // If the string is in new space it cannot be used as a symbol. | 2570 // If the string is in new space it cannot be used as a symbol. |
| 2603 if (InNewSpace(string)) return NULL; | 2571 if (InNewSpace(string)) return NULL; |
| 2604 | 2572 |
| 2605 // Find the corresponding symbol map for strings. | 2573 // Find the corresponding symbol map for strings. |
| 2606 Map* map = string->map(); | 2574 Map* map = string->map(); |
| 2607 | 2575 if (map == ascii_string_map()) return ascii_symbol_map(); |
| 2608 if (map == short_ascii_string_map()) return short_ascii_symbol_map(); | 2576 if (map == string_map()) return symbol_map(); |
| 2609 if (map == medium_ascii_string_map()) return medium_ascii_symbol_map(); | 2577 if (map == cons_string_map()) return cons_symbol_map(); |
| 2610 if (map == long_ascii_string_map()) return long_ascii_symbol_map(); | 2578 if (map == cons_ascii_string_map()) return cons_ascii_symbol_map(); |
| 2611 | 2579 if (map == external_string_map()) return external_symbol_map(); |
| 2612 if (map == short_string_map()) return short_symbol_map(); | 2580 if (map == external_ascii_string_map()) return external_ascii_symbol_map(); |
| 2613 if (map == medium_string_map()) return medium_symbol_map(); | |
| 2614 if (map == long_string_map()) return long_symbol_map(); | |
| 2615 | |
| 2616 if (map == short_cons_string_map()) return short_cons_symbol_map(); | |
| 2617 if (map == medium_cons_string_map()) return medium_cons_symbol_map(); | |
| 2618 if (map == long_cons_string_map()) return long_cons_symbol_map(); | |
| 2619 | |
| 2620 if (map == short_cons_ascii_string_map()) { | |
| 2621 return short_cons_ascii_symbol_map(); | |
| 2622 } | |
| 2623 if (map == medium_cons_ascii_string_map()) { | |
| 2624 return medium_cons_ascii_symbol_map(); | |
| 2625 } | |
| 2626 if (map == long_cons_ascii_string_map()) { | |
| 2627 return long_cons_ascii_symbol_map(); | |
| 2628 } | |
| 2629 | |
| 2630 if (map == short_external_string_map()) { | |
| 2631 return short_external_symbol_map(); | |
| 2632 } | |
| 2633 if (map == medium_external_string_map()) { | |
| 2634 return medium_external_symbol_map(); | |
| 2635 } | |
| 2636 if (map == long_external_string_map()) { | |
| 2637 return long_external_symbol_map(); | |
| 2638 } | |
| 2639 | |
| 2640 if (map == short_external_ascii_string_map()) { | |
| 2641 return short_external_ascii_symbol_map(); | |
| 2642 } | |
| 2643 if (map == medium_external_ascii_string_map()) { | |
| 2644 return medium_external_ascii_symbol_map(); | |
| 2645 } | |
| 2646 if (map == long_external_ascii_string_map()) { | |
| 2647 return long_external_ascii_symbol_map(); | |
| 2648 } | |
| 2649 | 2581 |
| 2650 // No match found. | 2582 // No match found. |
| 2651 return NULL; | 2583 return NULL; |
| 2652 } | 2584 } |
| 2653 | 2585 |
| 2654 | 2586 |
| 2655 Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, | 2587 Object* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer, |
| 2656 int chars, | 2588 int chars, |
| 2657 uint32_t length_field) { | 2589 uint32_t hash_field) { |
| 2658 // Ensure the chars matches the number of characters in the buffer. | 2590 // Ensure the chars matches the number of characters in the buffer. |
| 2659 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); | 2591 ASSERT(static_cast<unsigned>(chars) == buffer->Length()); |
| 2660 // Determine whether the string is ascii. | 2592 // Determine whether the string is ascii. |
| 2661 bool is_ascii = true; | 2593 bool is_ascii = true; |
| 2662 while (buffer->has_more() && is_ascii) { | 2594 while (buffer->has_more() && is_ascii) { |
| 2663 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; | 2595 if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) is_ascii = false; |
| 2664 } | 2596 } |
| 2665 buffer->Rewind(); | 2597 buffer->Rewind(); |
| 2666 | 2598 |
| 2667 // Compute map and object size. | 2599 // Compute map and object size. |
| 2668 int size; | 2600 int size; |
| 2669 Map* map; | 2601 Map* map; |
| 2670 | 2602 |
| 2671 if (is_ascii) { | 2603 if (is_ascii) { |
| 2672 if (chars <= String::kMaxShortSize) { | 2604 map = ascii_symbol_map(); |
| 2673 map = short_ascii_symbol_map(); | |
| 2674 } else if (chars <= String::kMaxMediumSize) { | |
| 2675 map = medium_ascii_symbol_map(); | |
| 2676 } else { | |
| 2677 map = long_ascii_symbol_map(); | |
| 2678 } | |
| 2679 size = SeqAsciiString::SizeFor(chars); | 2605 size = SeqAsciiString::SizeFor(chars); |
| 2680 } else { | 2606 } else { |
| 2681 if (chars <= String::kMaxShortSize) { | 2607 map = symbol_map(); |
| 2682 map = short_symbol_map(); | |
| 2683 } else if (chars <= String::kMaxMediumSize) { | |
| 2684 map = medium_symbol_map(); | |
| 2685 } else { | |
| 2686 map = long_symbol_map(); | |
| 2687 } | |
| 2688 size = SeqTwoByteString::SizeFor(chars); | 2608 size = SeqTwoByteString::SizeFor(chars); |
| 2689 } | 2609 } |
| 2690 | 2610 |
| 2691 // Allocate string. | 2611 // Allocate string. |
| 2692 AllocationSpace space = | 2612 AllocationSpace space = |
| 2693 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_DATA_SPACE; | 2613 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_DATA_SPACE; |
| 2694 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2614 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2695 if (result->IsFailure()) return result; | 2615 if (result->IsFailure()) return result; |
| 2696 | 2616 |
| 2697 reinterpret_cast<HeapObject*>(result)->set_map(map); | 2617 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 2698 // The hash value contains the length of the string. | 2618 // Set length and hash fields of the allocated string. |
| 2699 String* answer = String::cast(result); | 2619 String* answer = String::cast(result); |
| 2700 answer->set_length_field(length_field); | 2620 answer->set_length(chars); |
| 2621 answer->set_hash_field(hash_field); |
| 2701 | 2622 |
| 2702 ASSERT_EQ(size, answer->Size()); | 2623 ASSERT_EQ(size, answer->Size()); |
| 2703 | 2624 |
| 2704 // Fill in the characters. | 2625 // Fill in the characters. |
| 2705 for (int i = 0; i < chars; i++) { | 2626 for (int i = 0; i < chars; i++) { |
| 2706 answer->Set(i, buffer->GetNext()); | 2627 answer->Set(i, buffer->GetNext()); |
| 2707 } | 2628 } |
| 2708 return answer; | 2629 return answer; |
| 2709 } | 2630 } |
| 2710 | 2631 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2721 if (space == NEW_SPACE) { | 2642 if (space == NEW_SPACE) { |
| 2722 result = size <= kMaxObjectSizeInNewSpace | 2643 result = size <= kMaxObjectSizeInNewSpace |
| 2723 ? new_space_.AllocateRaw(size) | 2644 ? new_space_.AllocateRaw(size) |
| 2724 : lo_space_->AllocateRaw(size); | 2645 : lo_space_->AllocateRaw(size); |
| 2725 } else { | 2646 } else { |
| 2726 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 2647 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |
| 2727 result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2648 result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2728 } | 2649 } |
| 2729 if (result->IsFailure()) return result; | 2650 if (result->IsFailure()) return result; |
| 2730 | 2651 |
| 2731 // Determine the map based on the string's length. | |
| 2732 Map* map; | |
| 2733 if (length <= String::kMaxShortSize) { | |
| 2734 map = short_ascii_string_map(); | |
| 2735 } else if (length <= String::kMaxMediumSize) { | |
| 2736 map = medium_ascii_string_map(); | |
| 2737 } else { | |
| 2738 map = long_ascii_string_map(); | |
| 2739 } | |
| 2740 | |
| 2741 // Partially initialize the object. | 2652 // Partially initialize the object. |
| 2742 HeapObject::cast(result)->set_map(map); | 2653 HeapObject::cast(result)->set_map(ascii_string_map()); |
| 2743 String::cast(result)->set_length(length); | 2654 String::cast(result)->set_length(length); |
| 2655 String::cast(result)->set_hash_field(String::kEmptyHashField); |
| 2744 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 2656 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
| 2745 return result; | 2657 return result; |
| 2746 } | 2658 } |
| 2747 | 2659 |
| 2748 | 2660 |
| 2749 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { | 2661 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { |
| 2750 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 2662 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 2751 | 2663 |
| 2752 // New space can't cope with forced allocation. | 2664 // New space can't cope with forced allocation. |
| 2753 if (always_allocate()) space = OLD_DATA_SPACE; | 2665 if (always_allocate()) space = OLD_DATA_SPACE; |
| 2754 | 2666 |
| 2755 int size = SeqTwoByteString::SizeFor(length); | 2667 int size = SeqTwoByteString::SizeFor(length); |
| 2756 | 2668 |
| 2757 Object* result = Failure::OutOfMemoryException(); | 2669 Object* result = Failure::OutOfMemoryException(); |
| 2758 if (space == NEW_SPACE) { | 2670 if (space == NEW_SPACE) { |
| 2759 result = size <= kMaxObjectSizeInNewSpace | 2671 result = size <= kMaxObjectSizeInNewSpace |
| 2760 ? new_space_.AllocateRaw(size) | 2672 ? new_space_.AllocateRaw(size) |
| 2761 : lo_space_->AllocateRaw(size); | 2673 : lo_space_->AllocateRaw(size); |
| 2762 } else { | 2674 } else { |
| 2763 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 2675 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |
| 2764 result = AllocateRaw(size, space, OLD_DATA_SPACE); | 2676 result = AllocateRaw(size, space, OLD_DATA_SPACE); |
| 2765 } | 2677 } |
| 2766 if (result->IsFailure()) return result; | 2678 if (result->IsFailure()) return result; |
| 2767 | 2679 |
| 2768 // Determine the map based on the string's length. | |
| 2769 Map* map; | |
| 2770 if (length <= String::kMaxShortSize) { | |
| 2771 map = short_string_map(); | |
| 2772 } else if (length <= String::kMaxMediumSize) { | |
| 2773 map = medium_string_map(); | |
| 2774 } else { | |
| 2775 map = long_string_map(); | |
| 2776 } | |
| 2777 | |
| 2778 // Partially initialize the object. | 2680 // Partially initialize the object. |
| 2779 HeapObject::cast(result)->set_map(map); | 2681 HeapObject::cast(result)->set_map(string_map()); |
| 2780 String::cast(result)->set_length(length); | 2682 String::cast(result)->set_length(length); |
| 2683 String::cast(result)->set_hash_field(String::kEmptyHashField); |
| 2781 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 2684 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
| 2782 return result; | 2685 return result; |
| 2783 } | 2686 } |
| 2784 | 2687 |
| 2785 | 2688 |
| 2786 Object* Heap::AllocateEmptyFixedArray() { | 2689 Object* Heap::AllocateEmptyFixedArray() { |
| 2787 int size = FixedArray::SizeFor(0); | 2690 int size = FixedArray::SizeFor(0); |
| 2788 Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 2691 Object* result = AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
| 2789 if (result->IsFailure()) return result; | 2692 if (result->IsFailure()) return result; |
| 2790 // Initialize the object. | 2693 // Initialize the object. |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4048 for (int i = 0; i < kNumberOfCaches; i++) { | 3951 for (int i = 0; i < kNumberOfCaches; i++) { |
| 4049 if (caches_[i] != NULL) { | 3952 if (caches_[i] != NULL) { |
| 4050 delete caches_[i]; | 3953 delete caches_[i]; |
| 4051 caches_[i] = NULL; | 3954 caches_[i] = NULL; |
| 4052 } | 3955 } |
| 4053 } | 3956 } |
| 4054 } | 3957 } |
| 4055 | 3958 |
| 4056 | 3959 |
| 4057 } } // namespace v8::internal | 3960 } } // namespace v8::internal |
| OLD | NEW |