Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: src/heap.cc

Issue 518007: Simplify checking during allocation when Heap::always_allocate() is... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/heap-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 return true; 1347 return true;
1348 } 1348 }
1349 1349
1350 1350
1351 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 1351 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
1352 // Statically ensure that it is safe to allocate heap numbers in paged 1352 // Statically ensure that it is safe to allocate heap numbers in paged
1353 // spaces. 1353 // spaces.
1354 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1354 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1355 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1355 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1356 1356
1357 // New space can't cope with forced allocation.
1358 if (always_allocate()) space = OLD_DATA_SPACE;
1359
1360 Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE); 1357 Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
1361 if (result->IsFailure()) return result; 1358 if (result->IsFailure()) return result;
1362 1359
1363 HeapObject::cast(result)->set_map(heap_number_map()); 1360 HeapObject::cast(result)->set_map(heap_number_map());
1364 HeapNumber::cast(result)->set_value(value); 1361 HeapNumber::cast(result)->set_value(value);
1365 return result; 1362 return result;
1366 } 1363 }
1367 1364
1368 1365
1369 Object* Heap::AllocateHeapNumber(double value) { 1366 Object* Heap::AllocateHeapNumber(double value) {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 return SmiOrNumberFromDouble(value, 1752 return SmiOrNumberFromDouble(value,
1756 false /* use preallocated NaN, -0.0 */, 1753 false /* use preallocated NaN, -0.0 */,
1757 pretenure); 1754 pretenure);
1758 } 1755 }
1759 1756
1760 1757
1761 Object* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) { 1758 Object* Heap::AllocateProxy(Address proxy, PretenureFlag pretenure) {
1762 // Statically ensure that it is safe to allocate proxies in paged spaces. 1759 // Statically ensure that it is safe to allocate proxies in paged spaces.
1763 STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize); 1760 STATIC_ASSERT(Proxy::kSize <= Page::kMaxHeapObjectSize);
1764 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1761 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1765 if (always_allocate()) space = OLD_DATA_SPACE;
1766 Object* result = Allocate(proxy_map(), space); 1762 Object* result = Allocate(proxy_map(), space);
1767 if (result->IsFailure()) return result; 1763 if (result->IsFailure()) return result;
1768 1764
1769 Proxy::cast(result)->set_proxy(proxy); 1765 Proxy::cast(result)->set_proxy(proxy);
1770 return result; 1766 return result;
1771 } 1767 }
1772 1768
1773 1769
1774 Object* Heap::AllocateSharedFunctionInfo(Object* name) { 1770 Object* Heap::AllocateSharedFunctionInfo(Object* name) {
1775 Object* result = Allocate(shared_function_info_map(), OLD_POINTER_SPACE); 1771 Object* result = Allocate(shared_function_info_map(), OLD_POINTER_SPACE);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 // Copy the characters into the new object. 1891 // Copy the characters into the new object.
1896 uc16* dest = SeqTwoByteString::cast(result)->GetChars(); 1892 uc16* dest = SeqTwoByteString::cast(result)->GetChars();
1897 String::WriteToFlat(first, dest, 0, first_length); 1893 String::WriteToFlat(first, dest, 0, first_length);
1898 String::WriteToFlat(second, dest + first_length, 0, second_length); 1894 String::WriteToFlat(second, dest + first_length, 0, second_length);
1899 return result; 1895 return result;
1900 } 1896 }
1901 } 1897 }
1902 1898
1903 Map* map = is_ascii ? cons_ascii_string_map() : cons_string_map(); 1899 Map* map = is_ascii ? cons_ascii_string_map() : cons_string_map();
1904 1900
1905 Object* result = Allocate(map, 1901 Object* result = Allocate(map, NEW_SPACE);
1906 always_allocate() ? OLD_POINTER_SPACE : NEW_SPACE);
1907 if (result->IsFailure()) return result; 1902 if (result->IsFailure()) return result;
1908 ConsString* cons_string = ConsString::cast(result); 1903 ConsString* cons_string = ConsString::cast(result);
1909 WriteBarrierMode mode = cons_string->GetWriteBarrierMode(); 1904 WriteBarrierMode mode = cons_string->GetWriteBarrierMode();
1910 cons_string->set_length(length); 1905 cons_string->set_length(length);
1911 cons_string->set_hash_field(String::kEmptyHashField); 1906 cons_string->set_hash_field(String::kEmptyHashField);
1912 cons_string->set_first(first, mode); 1907 cons_string->set_first(first, mode);
1913 cons_string->set_second(second, mode); 1908 cons_string->set_second(second, mode);
1914 return result; 1909 return result;
1915 } 1910 }
1916 1911
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 1955
1961 Object* Heap::AllocateExternalStringFromAscii( 1956 Object* Heap::AllocateExternalStringFromAscii(
1962 ExternalAsciiString::Resource* resource) { 1957 ExternalAsciiString::Resource* resource) {
1963 size_t length = resource->length(); 1958 size_t length = resource->length();
1964 if (length > static_cast<size_t>(String::kMaxLength)) { 1959 if (length > static_cast<size_t>(String::kMaxLength)) {
1965 Top::context()->mark_out_of_memory(); 1960 Top::context()->mark_out_of_memory();
1966 return Failure::OutOfMemoryException(); 1961 return Failure::OutOfMemoryException();
1967 } 1962 }
1968 1963
1969 Map* map = external_ascii_string_map(); 1964 Map* map = external_ascii_string_map();
1970 Object* result = Allocate(map, 1965 Object* result = Allocate(map, NEW_SPACE);
1971 always_allocate() ? OLD_DATA_SPACE : NEW_SPACE);
1972 if (result->IsFailure()) return result; 1966 if (result->IsFailure()) return result;
1973 1967
1974 ExternalAsciiString* external_string = ExternalAsciiString::cast(result); 1968 ExternalAsciiString* external_string = ExternalAsciiString::cast(result);
1975 external_string->set_length(static_cast<int>(length)); 1969 external_string->set_length(static_cast<int>(length));
1976 external_string->set_hash_field(String::kEmptyHashField); 1970 external_string->set_hash_field(String::kEmptyHashField);
1977 external_string->set_resource(resource); 1971 external_string->set_resource(resource);
1978 1972
1979 return result; 1973 return result;
1980 } 1974 }
1981 1975
1982 1976
1983 Object* Heap::AllocateExternalStringFromTwoByte( 1977 Object* Heap::AllocateExternalStringFromTwoByte(
1984 ExternalTwoByteString::Resource* resource) { 1978 ExternalTwoByteString::Resource* resource) {
1985 size_t length = resource->length(); 1979 size_t length = resource->length();
1986 if (length > static_cast<size_t>(String::kMaxLength)) { 1980 if (length > static_cast<size_t>(String::kMaxLength)) {
1987 Top::context()->mark_out_of_memory(); 1981 Top::context()->mark_out_of_memory();
1988 return Failure::OutOfMemoryException(); 1982 return Failure::OutOfMemoryException();
1989 } 1983 }
1990 1984
1991 Map* map = Heap::external_string_map(); 1985 Map* map = Heap::external_string_map();
1992 Object* result = Allocate(map, 1986 Object* result = Allocate(map, NEW_SPACE);
1993 always_allocate() ? OLD_DATA_SPACE : NEW_SPACE);
1994 if (result->IsFailure()) return result; 1987 if (result->IsFailure()) return result;
1995 1988
1996 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result); 1989 ExternalTwoByteString* external_string = ExternalTwoByteString::cast(result);
1997 external_string->set_length(static_cast<int>(length)); 1990 external_string->set_length(static_cast<int>(length));
1998 external_string->set_hash_field(String::kEmptyHashField); 1991 external_string->set_hash_field(String::kEmptyHashField);
1999 external_string->set_resource(resource); 1992 external_string->set_resource(resource);
2000 1993
2001 return result; 1994 return result;
2002 } 1995 }
2003 1996
(...skipping 18 matching lines...) Expand all
2022 answer->Set(0, code); 2015 answer->Set(0, code);
2023 return answer; 2016 return answer;
2024 } 2017 }
2025 2018
2026 2019
2027 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 2020 Object* Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
2028 if (pretenure == NOT_TENURED) { 2021 if (pretenure == NOT_TENURED) {
2029 return AllocateByteArray(length); 2022 return AllocateByteArray(length);
2030 } 2023 }
2031 int size = ByteArray::SizeFor(length); 2024 int size = ByteArray::SizeFor(length);
2032 AllocationSpace space = 2025 Object* result = (size <= MaxObjectSizeInPagedSpace())
2033 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : OLD_DATA_SPACE; 2026 ? old_data_space_->AllocateRaw(size)
2034 2027 : lo_space_->AllocateRaw(size);
2035 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);
2036
2037 if (result->IsFailure()) return result; 2028 if (result->IsFailure()) return result;
2038 2029
2039 reinterpret_cast<Array*>(result)->set_map(byte_array_map()); 2030 reinterpret_cast<Array*>(result)->set_map(byte_array_map());
2040 reinterpret_cast<Array*>(result)->set_length(length); 2031 reinterpret_cast<Array*>(result)->set_length(length);
2041 return result; 2032 return result;
2042 } 2033 }
2043 2034
2044 2035
2045 Object* Heap::AllocateByteArray(int length) { 2036 Object* Heap::AllocateByteArray(int length) {
2046 int size = ByteArray::SizeFor(length); 2037 int size = ByteArray::SizeFor(length);
2047 AllocationSpace space = 2038 AllocationSpace space =
2048 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : NEW_SPACE; 2039 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE;
2049
2050 // New space can't cope with forced allocation.
2051 if (always_allocate()) space = LO_SPACE;
2052
2053 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); 2040 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);
2054
2055 if (result->IsFailure()) return result; 2041 if (result->IsFailure()) return result;
2056 2042
2057 reinterpret_cast<Array*>(result)->set_map(byte_array_map()); 2043 reinterpret_cast<Array*>(result)->set_map(byte_array_map());
2058 reinterpret_cast<Array*>(result)->set_length(length); 2044 reinterpret_cast<Array*>(result)->set_length(length);
2059 return result; 2045 return result;
2060 } 2046 }
2061 2047
2062 2048
2063 void Heap::CreateFillerObjectAt(Address addr, int size) { 2049 void Heap::CreateFillerObjectAt(Address addr, int size) {
2064 if (size == 0) return; 2050 if (size == 0) return;
2065 HeapObject* filler = HeapObject::FromAddress(addr); 2051 HeapObject* filler = HeapObject::FromAddress(addr);
2066 if (size == kPointerSize) { 2052 if (size == kPointerSize) {
2067 filler->set_map(Heap::one_pointer_filler_map()); 2053 filler->set_map(Heap::one_pointer_filler_map());
2068 } else { 2054 } else {
2069 filler->set_map(Heap::byte_array_map()); 2055 filler->set_map(Heap::byte_array_map());
2070 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size)); 2056 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size));
2071 } 2057 }
2072 } 2058 }
2073 2059
2074 2060
2075 Object* Heap::AllocatePixelArray(int length, 2061 Object* Heap::AllocatePixelArray(int length,
2076 uint8_t* external_pointer, 2062 uint8_t* external_pointer,
2077 PretenureFlag pretenure) { 2063 PretenureFlag pretenure) {
2078 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2064 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2079
2080 // New space can't cope with forced allocation.
2081 if (always_allocate()) space = OLD_DATA_SPACE;
2082
2083 Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE); 2065 Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
2084
2085 if (result->IsFailure()) return result; 2066 if (result->IsFailure()) return result;
2086 2067
2087 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); 2068 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map());
2088 reinterpret_cast<PixelArray*>(result)->set_length(length); 2069 reinterpret_cast<PixelArray*>(result)->set_length(length);
2089 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); 2070 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer);
2090 2071
2091 return result; 2072 return result;
2092 } 2073 }
2093 2074
2094 2075
2095 Object* Heap::AllocateExternalArray(int length, 2076 Object* Heap::AllocateExternalArray(int length,
2096 ExternalArrayType array_type, 2077 ExternalArrayType array_type,
2097 void* external_pointer, 2078 void* external_pointer,
2098 PretenureFlag pretenure) { 2079 PretenureFlag pretenure) {
2099 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2080 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2100
2101 // New space can't cope with forced allocation.
2102 if (always_allocate()) space = OLD_DATA_SPACE;
2103
2104 Object* result = AllocateRaw(ExternalArray::kAlignedSize, 2081 Object* result = AllocateRaw(ExternalArray::kAlignedSize,
2105 space, 2082 space,
2106 OLD_DATA_SPACE); 2083 OLD_DATA_SPACE);
2107
2108 if (result->IsFailure()) return result; 2084 if (result->IsFailure()) return result;
2109 2085
2110 reinterpret_cast<ExternalArray*>(result)->set_map( 2086 reinterpret_cast<ExternalArray*>(result)->set_map(
2111 MapForExternalArrayType(array_type)); 2087 MapForExternalArrayType(array_type));
2112 reinterpret_cast<ExternalArray*>(result)->set_length(length); 2088 reinterpret_cast<ExternalArray*>(result)->set_length(length);
2113 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( 2089 reinterpret_cast<ExternalArray*>(result)->set_external_pointer(
2114 external_pointer); 2090 external_pointer);
2115 2091
2116 return result; 2092 return result;
2117 } 2093 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 map->unused_property_fields() - 2355 map->unused_property_fields() -
2380 map->inobject_properties(); 2356 map->inobject_properties();
2381 ASSERT(prop_size >= 0); 2357 ASSERT(prop_size >= 0);
2382 Object* properties = AllocateFixedArray(prop_size, pretenure); 2358 Object* properties = AllocateFixedArray(prop_size, pretenure);
2383 if (properties->IsFailure()) return properties; 2359 if (properties->IsFailure()) return properties;
2384 2360
2385 // Allocate the JSObject. 2361 // Allocate the JSObject.
2386 AllocationSpace space = 2362 AllocationSpace space =
2387 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; 2363 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2388 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2364 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
2389 if (always_allocate()) space = OLD_POINTER_SPACE;
2390 Object* obj = Allocate(map, space); 2365 Object* obj = Allocate(map, space);
2391 if (obj->IsFailure()) return obj; 2366 if (obj->IsFailure()) return obj;
2392 2367
2393 // Initialize the JSObject. 2368 // Initialize the JSObject.
2394 InitializeJSObjectFromMap(JSObject::cast(obj), 2369 InitializeJSObjectFromMap(JSObject::cast(obj),
2395 FixedArray::cast(properties), 2370 FixedArray::cast(properties),
2396 map); 2371 map);
2397 return obj; 2372 return obj;
2398 } 2373 }
2399 2374
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2676 2651
2677 if (is_ascii) { 2652 if (is_ascii) {
2678 map = ascii_symbol_map(); 2653 map = ascii_symbol_map();
2679 size = SeqAsciiString::SizeFor(chars); 2654 size = SeqAsciiString::SizeFor(chars);
2680 } else { 2655 } else {
2681 map = symbol_map(); 2656 map = symbol_map();
2682 size = SeqTwoByteString::SizeFor(chars); 2657 size = SeqTwoByteString::SizeFor(chars);
2683 } 2658 }
2684 2659
2685 // Allocate string. 2660 // Allocate string.
2686 AllocationSpace space = 2661 Object* result = (size > MaxObjectSizeInPagedSpace())
2687 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : OLD_DATA_SPACE; 2662 ? lo_space_->AllocateRaw(size)
2688 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); 2663 : old_data_space_->AllocateRaw(size);
2689 if (result->IsFailure()) return result; 2664 if (result->IsFailure()) return result;
2690 2665
2691 reinterpret_cast<HeapObject*>(result)->set_map(map); 2666 reinterpret_cast<HeapObject*>(result)->set_map(map);
2692 // Set length and hash fields of the allocated string. 2667 // Set length and hash fields of the allocated string.
2693 String* answer = String::cast(result); 2668 String* answer = String::cast(result);
2694 answer->set_length(chars); 2669 answer->set_length(chars);
2695 answer->set_hash_field(hash_field); 2670 answer->set_hash_field(hash_field);
2696 2671
2697 ASSERT_EQ(size, answer->Size()); 2672 ASSERT_EQ(size, answer->Size());
2698 2673
2699 // Fill in the characters. 2674 // Fill in the characters.
2700 for (int i = 0; i < chars; i++) { 2675 for (int i = 0; i < chars; i++) {
2701 answer->Set(i, buffer->GetNext()); 2676 answer->Set(i, buffer->GetNext());
2702 } 2677 }
2703 return answer; 2678 return answer;
2704 } 2679 }
2705 2680
2706 2681
2707 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { 2682 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) {
2683 int size = SeqAsciiString::SizeFor(length);
2708 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2684 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2685 AllocationSpace retry_space = OLD_DATA_SPACE;
2709 2686
2710 // New space can't cope with forced allocation.
2711 if (always_allocate()) space = OLD_DATA_SPACE;
2712
2713 int size = SeqAsciiString::SizeFor(length);
2714
2715 Object* result = Failure::OutOfMemoryException();
2716 if (space == NEW_SPACE) { 2687 if (space == NEW_SPACE) {
2717 result = size <= kMaxObjectSizeInNewSpace 2688 if (size > kMaxObjectSizeInNewSpace) {
2718 ? new_space_.AllocateRaw(size) 2689 // Allocate in large object space, retry space will be ignored.
2719 : lo_space_->AllocateRaw(size); 2690 space = LO_SPACE;
2720 } else { 2691 } else if (size > MaxObjectSizeInPagedSpace()) {
2721 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2692 // Allocate in new space, retry in large object space.
2722 result = AllocateRaw(size, space, OLD_DATA_SPACE); 2693 retry_space = LO_SPACE;
2694 }
2695 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
2696 space = LO_SPACE;
2723 } 2697 }
2698 Object* result = AllocateRaw(size, space, retry_space);
2724 if (result->IsFailure()) return result; 2699 if (result->IsFailure()) return result;
2725 2700
2726 // Partially initialize the object. 2701 // Partially initialize the object.
2727 HeapObject::cast(result)->set_map(ascii_string_map()); 2702 HeapObject::cast(result)->set_map(ascii_string_map());
2728 String::cast(result)->set_length(length); 2703 String::cast(result)->set_length(length);
2729 String::cast(result)->set_hash_field(String::kEmptyHashField); 2704 String::cast(result)->set_hash_field(String::kEmptyHashField);
2730 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 2705 ASSERT_EQ(size, HeapObject::cast(result)->Size());
2731 return result; 2706 return result;
2732 } 2707 }
2733 2708
2734 2709
2735 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { 2710 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) {
2711 int size = SeqTwoByteString::SizeFor(length);
2736 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2712 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2713 AllocationSpace retry_space = OLD_DATA_SPACE;
2737 2714
2738 // New space can't cope with forced allocation.
2739 if (always_allocate()) space = OLD_DATA_SPACE;
2740
2741 int size = SeqTwoByteString::SizeFor(length);
2742
2743 Object* result = Failure::OutOfMemoryException();
2744 if (space == NEW_SPACE) { 2715 if (space == NEW_SPACE) {
2745 result = size <= kMaxObjectSizeInNewSpace 2716 if (size > kMaxObjectSizeInNewSpace) {
2746 ? new_space_.AllocateRaw(size) 2717 // Allocate in large object space, retry space will be ignored.
2747 : lo_space_->AllocateRaw(size); 2718 space = LO_SPACE;
2748 } else { 2719 } else if (size > MaxObjectSizeInPagedSpace()) {
2749 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2720 // Allocate in new space, retry in large object space.
2750 result = AllocateRaw(size, space, OLD_DATA_SPACE); 2721 retry_space = LO_SPACE;
2722 }
2723 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) {
2724 space = LO_SPACE;
2751 } 2725 }
2726 Object* result = AllocateRaw(size, space, retry_space);
2752 if (result->IsFailure()) return result; 2727 if (result->IsFailure()) return result;
2753 2728
2754 // Partially initialize the object. 2729 // Partially initialize the object.
2755 HeapObject::cast(result)->set_map(string_map()); 2730 HeapObject::cast(result)->set_map(string_map());
2756 String::cast(result)->set_length(length); 2731 String::cast(result)->set_length(length);
2757 String::cast(result)->set_hash_field(String::kEmptyHashField); 2732 String::cast(result)->set_hash_field(String::kEmptyHashField);
2758 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 2733 ASSERT_EQ(size, HeapObject::cast(result)->Size());
2759 return result; 2734 return result;
2760 } 2735 }
2761 2736
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2819 } 2794 }
2820 } 2795 }
2821 return result; 2796 return result;
2822 } 2797 }
2823 2798
2824 2799
2825 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 2800 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
2826 ASSERT(empty_fixed_array()->IsFixedArray()); 2801 ASSERT(empty_fixed_array()->IsFixedArray());
2827 if (length == 0) return empty_fixed_array(); 2802 if (length == 0) return empty_fixed_array();
2828 2803
2829 // New space can't cope with forced allocation. 2804 AllocationSpace space =
2830 if (always_allocate()) pretenure = TENURED; 2805 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2806 int size = FixedArray::SizeFor(length);
2807 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) {
2808 // Too big for new space.
2809 space = LO_SPACE;
2810 } else if (space == OLD_POINTER_SPACE &&
2811 size > MaxObjectSizeInPagedSpace()) {
2812 // Too big for old pointer space.
2813 space = LO_SPACE;
2814 }
2831 2815
2832 int size = FixedArray::SizeFor(length); 2816 // Specialize allocation for the space.
2833 Object* result = Failure::OutOfMemoryException(); 2817 Object* result = Failure::OutOfMemoryException();
2834 if (pretenure != TENURED) { 2818 if (space == NEW_SPACE) {
2835 result = size <= kMaxObjectSizeInNewSpace 2819 // We cannot use Heap::AllocateRaw() because it will not properly
2836 ? new_space_.AllocateRaw(size) 2820 // allocate extra remembered set bits if always_allocate() is true and
2837 : lo_space_->AllocateRawFixedArray(size); 2821 // new space allocation fails.
2822 result = new_space_.AllocateRaw(size);
2823 if (result->IsFailure() && always_allocate()) {
2824 if (size <= MaxObjectSizeInPagedSpace()) {
2825 result = old_pointer_space_->AllocateRaw(size);
2826 } else {
2827 result = lo_space_->AllocateRawFixedArray(size);
2828 }
2829 }
2830 } else if (space == OLD_POINTER_SPACE) {
2831 result = old_pointer_space_->AllocateRaw(size);
2832 } else {
2833 ASSERT(space == LO_SPACE);
2834 result = lo_space_->AllocateRawFixedArray(size);
2838 } 2835 }
2839 if (result->IsFailure()) { 2836 if (result->IsFailure()) return result;
2840 if (size > MaxObjectSizeInPagedSpace()) { 2837
2841 result = lo_space_->AllocateRawFixedArray(size);
2842 } else {
2843 AllocationSpace space =
2844 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
2845 result = AllocateRaw(size, space, OLD_POINTER_SPACE);
2846 }
2847 if (result->IsFailure()) return result;
2848 }
2849 // Initialize the object. 2838 // Initialize the object.
2850 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2839 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2851 FixedArray* array = FixedArray::cast(result); 2840 FixedArray* array = FixedArray::cast(result);
2852 array->set_length(length); 2841 array->set_length(length);
2853 Object* value = undefined_value(); 2842 Object* value = undefined_value();
2854 for (int index = 0; index < length; index++) { 2843 for (int index = 0; index < length; index++) {
2855 array->set(index, value, SKIP_WRITE_BARRIER); 2844 array->set(index, value, SKIP_WRITE_BARRIER);
2856 } 2845 }
2857 return array; 2846 return array;
2858 } 2847 }
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
4092 void ExternalStringTable::TearDown() { 4081 void ExternalStringTable::TearDown() {
4093 new_space_strings_.Free(); 4082 new_space_strings_.Free();
4094 old_space_strings_.Free(); 4083 old_space_strings_.Free();
4095 } 4084 }
4096 4085
4097 4086
4098 List<Object*> ExternalStringTable::new_space_strings_; 4087 List<Object*> ExternalStringTable::new_space_strings_;
4099 List<Object*> ExternalStringTable::old_space_strings_; 4088 List<Object*> ExternalStringTable::old_space_strings_;
4100 4089
4101 } } // namespace v8::internal 4090 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698