| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 if (obj->IsFailure()) return false; | 924 if (obj->IsFailure()) return false; |
| 925 proxy_map_ = Map::cast(obj); | 925 proxy_map_ = Map::cast(obj); |
| 926 | 926 |
| 927 #define ALLOCATE_STRING_MAP(type, size, name) \ | 927 #define ALLOCATE_STRING_MAP(type, size, name) \ |
| 928 obj = AllocateMap(type, size); \ | 928 obj = AllocateMap(type, size); \ |
| 929 if (obj->IsFailure()) return false; \ | 929 if (obj->IsFailure()) return false; \ |
| 930 name##_map_ = Map::cast(obj); | 930 name##_map_ = Map::cast(obj); |
| 931 STRING_TYPE_LIST(ALLOCATE_STRING_MAP); | 931 STRING_TYPE_LIST(ALLOCATE_STRING_MAP); |
| 932 #undef ALLOCATE_STRING_MAP | 932 #undef ALLOCATE_STRING_MAP |
| 933 | 933 |
| 934 obj = AllocateMap(SHORT_STRING_TYPE, TwoByteString::kHeaderSize); | 934 obj = AllocateMap(SHORT_STRING_TYPE, SeqTwoByteString::kHeaderSize); |
| 935 if (obj->IsFailure()) return false; | 935 if (obj->IsFailure()) return false; |
| 936 undetectable_short_string_map_ = Map::cast(obj); | 936 undetectable_short_string_map_ = Map::cast(obj); |
| 937 undetectable_short_string_map_->set_is_undetectable(); | 937 undetectable_short_string_map_->set_is_undetectable(); |
| 938 | 938 |
| 939 obj = AllocateMap(MEDIUM_STRING_TYPE, TwoByteString::kHeaderSize); | 939 obj = AllocateMap(MEDIUM_STRING_TYPE, SeqTwoByteString::kHeaderSize); |
| 940 if (obj->IsFailure()) return false; | 940 if (obj->IsFailure()) return false; |
| 941 undetectable_medium_string_map_ = Map::cast(obj); | 941 undetectable_medium_string_map_ = Map::cast(obj); |
| 942 undetectable_medium_string_map_->set_is_undetectable(); | 942 undetectable_medium_string_map_->set_is_undetectable(); |
| 943 | 943 |
| 944 obj = AllocateMap(LONG_STRING_TYPE, TwoByteString::kHeaderSize); | 944 obj = AllocateMap(LONG_STRING_TYPE, SeqTwoByteString::kHeaderSize); |
| 945 if (obj->IsFailure()) return false; | 945 if (obj->IsFailure()) return false; |
| 946 undetectable_long_string_map_ = Map::cast(obj); | 946 undetectable_long_string_map_ = Map::cast(obj); |
| 947 undetectable_long_string_map_->set_is_undetectable(); | 947 undetectable_long_string_map_->set_is_undetectable(); |
| 948 | 948 |
| 949 obj = AllocateMap(SHORT_ASCII_STRING_TYPE, AsciiString::kHeaderSize); | 949 obj = AllocateMap(SHORT_ASCII_STRING_TYPE, SeqAsciiString::kHeaderSize); |
| 950 if (obj->IsFailure()) return false; | 950 if (obj->IsFailure()) return false; |
| 951 undetectable_short_ascii_string_map_ = Map::cast(obj); | 951 undetectable_short_ascii_string_map_ = Map::cast(obj); |
| 952 undetectable_short_ascii_string_map_->set_is_undetectable(); | 952 undetectable_short_ascii_string_map_->set_is_undetectable(); |
| 953 | 953 |
| 954 obj = AllocateMap(MEDIUM_ASCII_STRING_TYPE, AsciiString::kHeaderSize); | 954 obj = AllocateMap(MEDIUM_ASCII_STRING_TYPE, SeqAsciiString::kHeaderSize); |
| 955 if (obj->IsFailure()) return false; | 955 if (obj->IsFailure()) return false; |
| 956 undetectable_medium_ascii_string_map_ = Map::cast(obj); | 956 undetectable_medium_ascii_string_map_ = Map::cast(obj); |
| 957 undetectable_medium_ascii_string_map_->set_is_undetectable(); | 957 undetectable_medium_ascii_string_map_->set_is_undetectable(); |
| 958 | 958 |
| 959 obj = AllocateMap(LONG_ASCII_STRING_TYPE, AsciiString::kHeaderSize); | 959 obj = AllocateMap(LONG_ASCII_STRING_TYPE, SeqAsciiString::kHeaderSize); |
| 960 if (obj->IsFailure()) return false; | 960 if (obj->IsFailure()) return false; |
| 961 undetectable_long_ascii_string_map_ = Map::cast(obj); | 961 undetectable_long_ascii_string_map_ = Map::cast(obj); |
| 962 undetectable_long_ascii_string_map_->set_is_undetectable(); | 962 undetectable_long_ascii_string_map_->set_is_undetectable(); |
| 963 | 963 |
| 964 obj = AllocateMap(BYTE_ARRAY_TYPE, Array::kHeaderSize); | 964 obj = AllocateMap(BYTE_ARRAY_TYPE, Array::kHeaderSize); |
| 965 if (obj->IsFailure()) return false; | 965 if (obj->IsFailure()) return false; |
| 966 byte_array_map_ = Map::cast(obj); | 966 byte_array_map_ = Map::cast(obj); |
| 967 | 967 |
| 968 obj = AllocateMap(CODE_TYPE, Code::kHeaderSize); | 968 obj = AllocateMap(CODE_TYPE, Code::kHeaderSize); |
| 969 if (obj->IsFailure()) return false; | 969 if (obj->IsFailure()) return false; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 share->set_lazy_load_data(undefined_value()); | 1321 share->set_lazy_load_data(undefined_value()); |
| 1322 share->set_script(undefined_value()); | 1322 share->set_script(undefined_value()); |
| 1323 share->set_start_position_and_type(0); | 1323 share->set_start_position_and_type(0); |
| 1324 share->set_debug_info(undefined_value()); | 1324 share->set_debug_info(undefined_value()); |
| 1325 return result; | 1325 return result; |
| 1326 } | 1326 } |
| 1327 | 1327 |
| 1328 | 1328 |
| 1329 Object* Heap::AllocateConsString(String* first, String* second) { | 1329 Object* Heap::AllocateConsString(String* first, String* second) { |
| 1330 int length = first->length() + second->length(); | 1330 int length = first->length() + second->length(); |
| 1331 bool is_ascii = first->is_ascii() && second->is_ascii(); | 1331 bool is_ascii = first->is_ascii_representation() |
| 1332 && second->is_ascii_representation(); |
| 1332 | 1333 |
| 1333 // If the resulting string is small make a flat string. | 1334 // If the resulting string is small make a flat string. |
| 1334 if (length < ConsString::kMinLength) { | 1335 if (length < ConsString::kMinLength) { |
| 1335 Object* result = is_ascii | 1336 Object* result = is_ascii |
| 1336 ? AllocateRawAsciiString(length) | 1337 ? AllocateRawAsciiString(length) |
| 1337 : AllocateRawTwoByteString(length); | 1338 : AllocateRawTwoByteString(length); |
| 1338 if (result->IsFailure()) return result; | 1339 if (result->IsFailure()) return result; |
| 1339 // Copy the characters into the new object. | 1340 // Copy the characters into the new object. |
| 1340 String* string_result = String::cast(result); | 1341 String* string_result = String::cast(result); |
| 1341 int first_length = first->length(); | 1342 int first_length = first->length(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 Object* Heap::AllocateSlicedString(String* buffer, int start, int end) { | 1379 Object* Heap::AllocateSlicedString(String* buffer, int start, int end) { |
| 1379 int length = end - start; | 1380 int length = end - start; |
| 1380 | 1381 |
| 1381 // If the resulting string is small make a sub string. | 1382 // If the resulting string is small make a sub string. |
| 1382 if (end - start <= SlicedString::kMinLength) { | 1383 if (end - start <= SlicedString::kMinLength) { |
| 1383 return Heap::AllocateSubString(buffer, start, end); | 1384 return Heap::AllocateSubString(buffer, start, end); |
| 1384 } | 1385 } |
| 1385 | 1386 |
| 1386 Map* map; | 1387 Map* map; |
| 1387 if (length <= String::kMaxShortStringSize) { | 1388 if (length <= String::kMaxShortStringSize) { |
| 1388 map = buffer->is_ascii() ? short_sliced_ascii_string_map() | 1389 map = buffer->is_ascii_representation() ? short_sliced_ascii_string_map() |
| 1389 : short_sliced_string_map(); | 1390 : short_sliced_string_map(); |
| 1390 } else if (length <= String::kMaxMediumStringSize) { | 1391 } else if (length <= String::kMaxMediumStringSize) { |
| 1391 map = buffer->is_ascii() ? medium_sliced_ascii_string_map() | 1392 map = buffer->is_ascii_representation() ? medium_sliced_ascii_string_map() |
| 1392 : medium_sliced_string_map(); | 1393 : medium_sliced_string_map(); |
| 1393 } else { | 1394 } else { |
| 1394 map = buffer->is_ascii() ? long_sliced_ascii_string_map() | 1395 map = buffer->is_ascii_representation() ? long_sliced_ascii_string_map() |
| 1395 : long_sliced_string_map(); | 1396 : long_sliced_string_map(); |
| 1396 } | 1397 } |
| 1397 | 1398 |
| 1398 Object* result = Allocate(map, NEW_SPACE); | 1399 Object* result = Allocate(map, NEW_SPACE); |
| 1399 if (result->IsFailure()) return result; | 1400 if (result->IsFailure()) return result; |
| 1400 | 1401 |
| 1401 SlicedString* sliced_string = SlicedString::cast(result); | 1402 SlicedString* sliced_string = SlicedString::cast(result); |
| 1402 sliced_string->set_buffer(buffer); | 1403 sliced_string->set_buffer(buffer); |
| 1403 sliced_string->set_start(start); | 1404 sliced_string->set_start(start); |
| 1404 sliced_string->set_length(length); | 1405 sliced_string->set_length(length); |
| 1405 | 1406 |
| 1406 return result; | 1407 return result; |
| 1407 } | 1408 } |
| 1408 | 1409 |
| 1409 | 1410 |
| 1410 Object* Heap::AllocateSubString(String* buffer, int start, int end) { | 1411 Object* Heap::AllocateSubString(String* buffer, int start, int end) { |
| 1411 int length = end - start; | 1412 int length = end - start; |
| 1412 | 1413 |
| 1413 if (length == 1) { | 1414 if (length == 1) { |
| 1414 return Heap::LookupSingleCharacterStringFromCode(buffer->Get(start)); | 1415 return Heap::LookupSingleCharacterStringFromCode(buffer->Get(start)); |
| 1415 } | 1416 } |
| 1416 | 1417 |
| 1417 // Make an attempt to flatten the buffer to reduce access time. | 1418 // Make an attempt to flatten the buffer to reduce access time. |
| 1418 buffer->TryFlatten(); | 1419 buffer->TryFlatten(); |
| 1419 | 1420 |
| 1420 Object* result = buffer->is_ascii() | 1421 Object* result = buffer->is_ascii_representation() |
| 1421 ? AllocateRawAsciiString(length) | 1422 ? AllocateRawAsciiString(length) |
| 1422 : AllocateRawTwoByteString(length); | 1423 : AllocateRawTwoByteString(length); |
| 1423 if (result->IsFailure()) return result; | 1424 if (result->IsFailure()) return result; |
| 1424 | 1425 |
| 1425 // Copy the characters into the new object. | 1426 // Copy the characters into the new object. |
| 1426 String* string_result = String::cast(result); | 1427 String* string_result = String::cast(result); |
| 1427 StringHasher hasher(length); | 1428 StringHasher hasher(length); |
| 1428 int i = 0; | 1429 int i = 0; |
| 1429 for (; i < length && hasher.is_array_index(); i++) { | 1430 for (; i < length && hasher.is_array_index(); i++) { |
| 1430 uc32 c = buffer->Get(start + i); | 1431 uc32 c = buffer->Get(start + i); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 return object; | 1762 return object; |
| 1762 } | 1763 } |
| 1763 | 1764 |
| 1764 | 1765 |
| 1765 Object* Heap::AllocateStringFromAscii(Vector<const char> string, | 1766 Object* Heap::AllocateStringFromAscii(Vector<const char> string, |
| 1766 PretenureFlag pretenure) { | 1767 PretenureFlag pretenure) { |
| 1767 Object* result = AllocateRawAsciiString(string.length(), pretenure); | 1768 Object* result = AllocateRawAsciiString(string.length(), pretenure); |
| 1768 if (result->IsFailure()) return result; | 1769 if (result->IsFailure()) return result; |
| 1769 | 1770 |
| 1770 // Copy the characters into the new object. | 1771 // Copy the characters into the new object. |
| 1771 AsciiString* string_result = AsciiString::cast(result); | 1772 SeqAsciiString* string_result = SeqAsciiString::cast(result); |
| 1772 for (int i = 0; i < string.length(); i++) { | 1773 for (int i = 0; i < string.length(); i++) { |
| 1773 string_result->AsciiStringSet(i, string[i]); | 1774 string_result->AsciiStringSet(i, string[i]); |
| 1774 } | 1775 } |
| 1775 return result; | 1776 return result; |
| 1776 } | 1777 } |
| 1777 | 1778 |
| 1778 | 1779 |
| 1779 Object* Heap::AllocateStringFromUtf8(Vector<const char> string, | 1780 Object* Heap::AllocateStringFromUtf8(Vector<const char> string, |
| 1780 PretenureFlag pretenure) { | 1781 PretenureFlag pretenure) { |
| 1781 // Count the number of characters in the UTF-8 string and check if | 1782 // Count the number of characters in the UTF-8 string and check if |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 Map* map; | 1912 Map* map; |
| 1912 | 1913 |
| 1913 if (is_ascii) { | 1914 if (is_ascii) { |
| 1914 if (chars <= String::kMaxShortStringSize) { | 1915 if (chars <= String::kMaxShortStringSize) { |
| 1915 map = short_ascii_symbol_map(); | 1916 map = short_ascii_symbol_map(); |
| 1916 } else if (chars <= String::kMaxMediumStringSize) { | 1917 } else if (chars <= String::kMaxMediumStringSize) { |
| 1917 map = medium_ascii_symbol_map(); | 1918 map = medium_ascii_symbol_map(); |
| 1918 } else { | 1919 } else { |
| 1919 map = long_ascii_symbol_map(); | 1920 map = long_ascii_symbol_map(); |
| 1920 } | 1921 } |
| 1921 size = AsciiString::SizeFor(chars); | 1922 size = SeqAsciiString::SizeFor(chars); |
| 1922 } else { | 1923 } else { |
| 1923 if (chars <= String::kMaxShortStringSize) { | 1924 if (chars <= String::kMaxShortStringSize) { |
| 1924 map = short_symbol_map(); | 1925 map = short_symbol_map(); |
| 1925 } else if (chars <= String::kMaxMediumStringSize) { | 1926 } else if (chars <= String::kMaxMediumStringSize) { |
| 1926 map = medium_symbol_map(); | 1927 map = medium_symbol_map(); |
| 1927 } else { | 1928 } else { |
| 1928 map = long_symbol_map(); | 1929 map = long_symbol_map(); |
| 1929 } | 1930 } |
| 1930 size = TwoByteString::SizeFor(chars); | 1931 size = SeqTwoByteString::SizeFor(chars); |
| 1931 } | 1932 } |
| 1932 | 1933 |
| 1933 // Allocate string. | 1934 // Allocate string. |
| 1934 AllocationSpace space = | 1935 AllocationSpace space = |
| 1935 (size > MaxHeapObjectSize()) ? LO_SPACE : OLD_DATA_SPACE; | 1936 (size > MaxHeapObjectSize()) ? LO_SPACE : OLD_DATA_SPACE; |
| 1936 Object* result = AllocateRaw(size, space); | 1937 Object* result = AllocateRaw(size, space); |
| 1937 if (result->IsFailure()) return result; | 1938 if (result->IsFailure()) return result; |
| 1938 | 1939 |
| 1939 reinterpret_cast<HeapObject*>(result)->set_map(map); | 1940 reinterpret_cast<HeapObject*>(result)->set_map(map); |
| 1940 // The hash value contains the length of the string. | 1941 // The hash value contains the length of the string. |
| 1941 String::cast(result)->set_length_field(length_field); | 1942 String::cast(result)->set_length_field(length_field); |
| 1942 | 1943 |
| 1943 ASSERT_EQ(size, String::cast(result)->Size()); | 1944 ASSERT_EQ(size, String::cast(result)->Size()); |
| 1944 | 1945 |
| 1945 // Fill in the characters. | 1946 // Fill in the characters. |
| 1946 for (int i = 0; i < chars; i++) { | 1947 for (int i = 0; i < chars; i++) { |
| 1947 String::cast(result)->Set(i, buffer->GetNext()); | 1948 String::cast(result)->Set(i, buffer->GetNext()); |
| 1948 } | 1949 } |
| 1949 return result; | 1950 return result; |
| 1950 } | 1951 } |
| 1951 | 1952 |
| 1952 | 1953 |
| 1953 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { | 1954 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { |
| 1954 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 1955 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 1955 int size = AsciiString::SizeFor(length); | 1956 int size = SeqAsciiString::SizeFor(length); |
| 1956 if (size > MaxHeapObjectSize()) { | 1957 if (size > MaxHeapObjectSize()) { |
| 1957 space = LO_SPACE; | 1958 space = LO_SPACE; |
| 1958 } | 1959 } |
| 1959 | 1960 |
| 1960 // Use AllocateRaw rather than Allocate because the object's size cannot be | 1961 // Use AllocateRaw rather than Allocate because the object's size cannot be |
| 1961 // determined from the map. | 1962 // determined from the map. |
| 1962 Object* result = AllocateRaw(size, space); | 1963 Object* result = AllocateRaw(size, space); |
| 1963 if (result->IsFailure()) return result; | 1964 if (result->IsFailure()) return result; |
| 1964 | 1965 |
| 1965 // Determine the map based on the string's length. | 1966 // Determine the map based on the string's length. |
| 1966 Map* map; | 1967 Map* map; |
| 1967 if (length <= String::kMaxShortStringSize) { | 1968 if (length <= String::kMaxShortStringSize) { |
| 1968 map = short_ascii_string_map(); | 1969 map = short_ascii_string_map(); |
| 1969 } else if (length <= String::kMaxMediumStringSize) { | 1970 } else if (length <= String::kMaxMediumStringSize) { |
| 1970 map = medium_ascii_string_map(); | 1971 map = medium_ascii_string_map(); |
| 1971 } else { | 1972 } else { |
| 1972 map = long_ascii_string_map(); | 1973 map = long_ascii_string_map(); |
| 1973 } | 1974 } |
| 1974 | 1975 |
| 1975 // Partially initialize the object. | 1976 // Partially initialize the object. |
| 1976 HeapObject::cast(result)->set_map(map); | 1977 HeapObject::cast(result)->set_map(map); |
| 1977 String::cast(result)->set_length(length); | 1978 String::cast(result)->set_length(length); |
| 1978 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 1979 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
| 1979 return result; | 1980 return result; |
| 1980 } | 1981 } |
| 1981 | 1982 |
| 1982 | 1983 |
| 1983 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { | 1984 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { |
| 1984 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 1985 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 1985 int size = TwoByteString::SizeFor(length); | 1986 int size = SeqTwoByteString::SizeFor(length); |
| 1986 if (size > MaxHeapObjectSize()) { | 1987 if (size > MaxHeapObjectSize()) { |
| 1987 space = LO_SPACE; | 1988 space = LO_SPACE; |
| 1988 } | 1989 } |
| 1989 | 1990 |
| 1990 // Use AllocateRaw rather than Allocate because the object's size cannot be | 1991 // Use AllocateRaw rather than Allocate because the object's size cannot be |
| 1991 // determined from the map. | 1992 // determined from the map. |
| 1992 Object* result = AllocateRaw(size, space); | 1993 Object* result = AllocateRaw(size, space); |
| 1993 if (result->IsFailure()) return result; | 1994 if (result->IsFailure()) return result; |
| 1994 | 1995 |
| 1995 // Determine the map based on the string's length. | 1996 // Determine the map based on the string's length. |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3069 return "Scavenge"; | 3070 return "Scavenge"; |
| 3070 case MARK_COMPACTOR: | 3071 case MARK_COMPACTOR: |
| 3071 return MarkCompactCollector::HasCompacted() ? "Mark-compact" | 3072 return MarkCompactCollector::HasCompacted() ? "Mark-compact" |
| 3072 : "Mark-sweep"; | 3073 : "Mark-sweep"; |
| 3073 } | 3074 } |
| 3074 return "Unknown GC"; | 3075 return "Unknown GC"; |
| 3075 } | 3076 } |
| 3076 | 3077 |
| 3077 | 3078 |
| 3078 } } // namespace v8::internal | 3079 } } // namespace v8::internal |
| OLD | NEW |