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

Side by Side Diff: src/heap.cc

Issue 251072: When allocation is forced because we already did two GCs we need to force GCs... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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
« src/api.cc ('K') | « src/api.cc ('k') | src/log-utils.cc » ('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 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); 1243 ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array()));
1244 return true; 1244 return true;
1245 } 1245 }
1246 1246
1247 1247
1248 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 1248 Object* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) {
1249 // Statically ensure that it is safe to allocate heap numbers in paged 1249 // Statically ensure that it is safe to allocate heap numbers in paged
1250 // spaces. 1250 // spaces.
1251 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1251 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1252 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1252 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1253
1254 // New space can't cope with forced allocation.
1255 if (always_allocate()) space = OLD_DATA_SPACE;
1256
1253 Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE); 1257 Object* result = AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE);
1254 if (result->IsFailure()) return result; 1258 if (result->IsFailure()) return result;
1255 1259
1256 HeapObject::cast(result)->set_map(heap_number_map()); 1260 HeapObject::cast(result)->set_map(heap_number_map());
1257 HeapNumber::cast(result)->set_value(value); 1261 HeapNumber::cast(result)->set_value(value);
1258 return result; 1262 return result;
1259 } 1263 }
1260 1264
1261 1265
1262 Object* Heap::AllocateHeapNumber(double value) { 1266 Object* Heap::AllocateHeapNumber(double value) {
1263 // Use general version, if we're forced to always allocate. 1267 // Use general version, if we're forced to always allocate.
1264 if (always_allocate()) return AllocateHeapNumber(value, NOT_TENURED); 1268 if (always_allocate()) return AllocateHeapNumber(value, TENURED);
1269
1265 // This version of AllocateHeapNumber is optimized for 1270 // This version of AllocateHeapNumber is optimized for
1266 // allocation in new space. 1271 // allocation in new space.
1267 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); 1272 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize);
1268 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); 1273 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC);
1269 Object* result = new_space_.AllocateRaw(HeapNumber::kSize); 1274 Object* result = new_space_.AllocateRaw(HeapNumber::kSize);
1270 if (result->IsFailure()) return result; 1275 if (result->IsFailure()) return result;
1271 HeapObject::cast(result)->set_map(heap_number_map()); 1276 HeapObject::cast(result)->set_map(heap_number_map());
1272 HeapNumber::cast(result)->set_value(value); 1277 HeapNumber::cast(result)->set_value(value);
1273 return result; 1278 return result;
1274 } 1279 }
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 reinterpret_cast<Array*>(result)->set_length(length); 1860 reinterpret_cast<Array*>(result)->set_length(length);
1856 return result; 1861 return result;
1857 } 1862 }
1858 1863
1859 1864
1860 Object* Heap::AllocateByteArray(int length) { 1865 Object* Heap::AllocateByteArray(int length) {
1861 int size = ByteArray::SizeFor(length); 1866 int size = ByteArray::SizeFor(length);
1862 AllocationSpace space = 1867 AllocationSpace space =
1863 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : NEW_SPACE; 1868 size > MaxObjectSizeInPagedSpace() ? LO_SPACE : NEW_SPACE;
1864 1869
1870 // New space can't cope with forced allocation.
1871 if (always_allocate()) space = LO_SPACE;
1872
1865 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE); 1873 Object* result = AllocateRaw(size, space, OLD_DATA_SPACE);
1866 1874
1867 if (result->IsFailure()) return result; 1875 if (result->IsFailure()) return result;
1868 1876
1869 reinterpret_cast<Array*>(result)->set_map(byte_array_map()); 1877 reinterpret_cast<Array*>(result)->set_map(byte_array_map());
1870 reinterpret_cast<Array*>(result)->set_length(length); 1878 reinterpret_cast<Array*>(result)->set_length(length);
1871 return result; 1879 return result;
1872 } 1880 }
1873 1881
1874 1882
1875 void Heap::CreateFillerObjectAt(Address addr, int size) { 1883 void Heap::CreateFillerObjectAt(Address addr, int size) {
1876 if (size == 0) return; 1884 if (size == 0) return;
1877 HeapObject* filler = HeapObject::FromAddress(addr); 1885 HeapObject* filler = HeapObject::FromAddress(addr);
1878 if (size == kPointerSize) { 1886 if (size == kPointerSize) {
1879 filler->set_map(Heap::one_pointer_filler_map()); 1887 filler->set_map(Heap::one_pointer_filler_map());
1880 } else { 1888 } else {
1881 filler->set_map(Heap::byte_array_map()); 1889 filler->set_map(Heap::byte_array_map());
1882 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size)); 1890 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size));
1883 } 1891 }
1884 } 1892 }
1885 1893
1886 1894
1887 Object* Heap::AllocatePixelArray(int length, 1895 Object* Heap::AllocatePixelArray(int length,
1888 uint8_t* external_pointer, 1896 uint8_t* external_pointer,
1889 PretenureFlag pretenure) { 1897 PretenureFlag pretenure) {
1890 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 1898 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
1891 1899
1900 // New space can't cope with forced allocation.
1901 if (always_allocate()) space = OLD_DATA_SPACE;
1902
1892 Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE); 1903 Object* result = AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE);
1893 1904
1894 if (result->IsFailure()) return result; 1905 if (result->IsFailure()) return result;
1895 1906
1896 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); 1907 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map());
1897 reinterpret_cast<PixelArray*>(result)->set_length(length); 1908 reinterpret_cast<PixelArray*>(result)->set_length(length);
1898 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); 1909 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer);
1899 1910
1900 return result; 1911 return result;
1901 } 1912 }
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
2525 // Fill in the characters. 2536 // Fill in the characters.
2526 for (int i = 0; i < chars; i++) { 2537 for (int i = 0; i < chars; i++) {
2527 answer->Set(i, buffer->GetNext()); 2538 answer->Set(i, buffer->GetNext());
2528 } 2539 }
2529 return answer; 2540 return answer;
2530 } 2541 }
2531 2542
2532 2543
2533 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) { 2544 Object* Heap::AllocateRawAsciiString(int length, PretenureFlag pretenure) {
2534 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2545 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2546
2547 // New space can't cope with forced allocation.
2548 if (always_allocate()) space = OLD_DATA_SPACE;
2549
2535 int size = SeqAsciiString::SizeFor(length); 2550 int size = SeqAsciiString::SizeFor(length);
2536 2551
2537 Object* result = Failure::OutOfMemoryException(); 2552 Object* result = Failure::OutOfMemoryException();
2538 if (space == NEW_SPACE) { 2553 if (space == NEW_SPACE) {
2539 result = size <= kMaxObjectSizeInNewSpace 2554 result = size <= kMaxObjectSizeInNewSpace
2540 ? new_space_.AllocateRaw(size) 2555 ? new_space_.AllocateRaw(size)
2541 : lo_space_->AllocateRawFixedArray(size); 2556 : lo_space_->AllocateRaw(size);
2542 } else { 2557 } else {
2543 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2558 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
2544 result = AllocateRaw(size, space, OLD_DATA_SPACE); 2559 result = AllocateRaw(size, space, OLD_DATA_SPACE);
2545 } 2560 }
2546 if (result->IsFailure()) return result; 2561 if (result->IsFailure()) return result;
2547 2562
2548 // Determine the map based on the string's length. 2563 // Determine the map based on the string's length.
2549 Map* map; 2564 Map* map;
2550 if (length <= String::kMaxShortStringSize) { 2565 if (length <= String::kMaxShortStringSize) {
2551 map = short_ascii_string_map(); 2566 map = short_ascii_string_map();
2552 } else if (length <= String::kMaxMediumStringSize) { 2567 } else if (length <= String::kMaxMediumStringSize) {
2553 map = medium_ascii_string_map(); 2568 map = medium_ascii_string_map();
2554 } else { 2569 } else {
2555 map = long_ascii_string_map(); 2570 map = long_ascii_string_map();
2556 } 2571 }
2557 2572
2558 // Partially initialize the object. 2573 // Partially initialize the object.
2559 HeapObject::cast(result)->set_map(map); 2574 HeapObject::cast(result)->set_map(map);
2560 String::cast(result)->set_length(length); 2575 String::cast(result)->set_length(length);
2561 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 2576 ASSERT_EQ(size, HeapObject::cast(result)->Size());
2562 return result; 2577 return result;
2563 } 2578 }
2564 2579
2565 2580
2566 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) { 2581 Object* Heap::AllocateRawTwoByteString(int length, PretenureFlag pretenure) {
2567 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 2582 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
2583
2584 // New space can't cope with forced allocation.
2585 if (always_allocate()) space = OLD_DATA_SPACE;
2586
2568 int size = SeqTwoByteString::SizeFor(length); 2587 int size = SeqTwoByteString::SizeFor(length);
2569 2588
2570 Object* result = Failure::OutOfMemoryException(); 2589 Object* result = Failure::OutOfMemoryException();
2571 if (space == NEW_SPACE) { 2590 if (space == NEW_SPACE) {
2572 result = size <= kMaxObjectSizeInNewSpace 2591 result = size <= kMaxObjectSizeInNewSpace
2573 ? new_space_.AllocateRaw(size) 2592 ? new_space_.AllocateRaw(size)
2574 : lo_space_->AllocateRawFixedArray(size); 2593 : lo_space_->AllocateRaw(size);
2575 } else { 2594 } else {
2576 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE; 2595 if (size > MaxObjectSizeInPagedSpace()) space = LO_SPACE;
2577 result = AllocateRaw(size, space, OLD_DATA_SPACE); 2596 result = AllocateRaw(size, space, OLD_DATA_SPACE);
2578 } 2597 }
2579 if (result->IsFailure()) return result; 2598 if (result->IsFailure()) return result;
2580 2599
2581 // Determine the map based on the string's length. 2600 // Determine the map based on the string's length.
2582 Map* map; 2601 Map* map;
2583 if (length <= String::kMaxShortStringSize) { 2602 if (length <= String::kMaxShortStringSize) {
2584 map = short_string_map(); 2603 map = short_string_map();
(...skipping 17 matching lines...) Expand all
2602 if (result->IsFailure()) return result; 2621 if (result->IsFailure()) return result;
2603 // Initialize the object. 2622 // Initialize the object.
2604 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); 2623 reinterpret_cast<Array*>(result)->set_map(fixed_array_map());
2605 reinterpret_cast<Array*>(result)->set_length(0); 2624 reinterpret_cast<Array*>(result)->set_length(0);
2606 return result; 2625 return result;
2607 } 2626 }
2608 2627
2609 2628
2610 Object* Heap::AllocateRawFixedArray(int length) { 2629 Object* Heap::AllocateRawFixedArray(int length) {
2611 // Use the general function if we're forced to always allocate. 2630 // Use the general function if we're forced to always allocate.
2612 if (always_allocate()) return AllocateFixedArray(length, NOT_TENURED); 2631 if (always_allocate()) return AllocateFixedArray(length, TENURED);
2613 // Allocate the raw data for a fixed array. 2632 // Allocate the raw data for a fixed array.
2614 int size = FixedArray::SizeFor(length); 2633 int size = FixedArray::SizeFor(length);
2615 return size <= kMaxObjectSizeInNewSpace 2634 return size <= kMaxObjectSizeInNewSpace
2616 ? new_space_.AllocateRaw(size) 2635 ? new_space_.AllocateRaw(size)
2617 : lo_space_->AllocateRawFixedArray(size); 2636 : lo_space_->AllocateRawFixedArray(size);
2618 } 2637 }
2619 2638
2620 2639
2621 Object* Heap::CopyFixedArray(FixedArray* src) { 2640 Object* Heap::CopyFixedArray(FixedArray* src) {
2622 int len = src->length(); 2641 int len = src->length();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 } 2674 }
2656 } 2675 }
2657 return result; 2676 return result;
2658 } 2677 }
2659 2678
2660 2679
2661 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { 2680 Object* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
2662 ASSERT(empty_fixed_array()->IsFixedArray()); 2681 ASSERT(empty_fixed_array()->IsFixedArray());
2663 if (length == 0) return empty_fixed_array(); 2682 if (length == 0) return empty_fixed_array();
2664 2683
2684 // New space can't cope with forced allocation.
2685 if (always_allocate()) pretenure = TENURED;
2686
2665 int size = FixedArray::SizeFor(length); 2687 int size = FixedArray::SizeFor(length);
2666 Object* result = Failure::OutOfMemoryException(); 2688 Object* result = Failure::OutOfMemoryException();
2667 if (pretenure != TENURED) { 2689 if (pretenure != TENURED) {
2668 result = size <= kMaxObjectSizeInNewSpace 2690 result = size <= kMaxObjectSizeInNewSpace
2669 ? new_space_.AllocateRaw(size) 2691 ? new_space_.AllocateRaw(size)
2670 : lo_space_->AllocateRawFixedArray(size); 2692 : lo_space_->AllocateRawFixedArray(size);
2671 } 2693 }
2672 if (result->IsFailure()) { 2694 if (result->IsFailure()) {
2673 if (size > MaxObjectSizeInPagedSpace()) { 2695 if (size > MaxObjectSizeInPagedSpace()) {
2674 result = lo_space_->AllocateRawFixedArray(size); 2696 result = lo_space_->AllocateRawFixedArray(size);
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3827 for (int i = 0; i < kNumberOfCaches; i++) { 3849 for (int i = 0; i < kNumberOfCaches; i++) {
3828 if (caches_[i] != NULL) { 3850 if (caches_[i] != NULL) {
3829 delete caches_[i]; 3851 delete caches_[i];
3830 caches_[i] = NULL; 3852 caches_[i] = NULL;
3831 } 3853 }
3832 } 3854 }
3833 } 3855 }
3834 3856
3835 3857
3836 } } // namespace v8::internal 3858 } } // namespace v8::internal
OLDNEW
« src/api.cc ('K') | « src/api.cc ('k') | src/log-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698