OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 // We should only get here if someone asks to allocate more | 1005 // We should only get here if someone asks to allocate more |
1006 // than what can be stored in a single page. | 1006 // than what can be stored in a single page. |
1007 // TODO(gc): Change the limit on new-space allocation to prevent this | 1007 // TODO(gc): Change the limit on new-space allocation to prevent this |
1008 // from happening (all such allocations should go directly to LOSpace). | 1008 // from happening (all such allocations should go directly to LOSpace). |
1009 return false; | 1009 return false; |
1010 } | 1010 } |
1011 if (!to_space_.AdvancePage()) { | 1011 if (!to_space_.AdvancePage()) { |
1012 // Failed to get a new page in to-space. | 1012 // Failed to get a new page in to-space. |
1013 return false; | 1013 return false; |
1014 } | 1014 } |
| 1015 |
1015 // Clear remainder of current page. | 1016 // Clear remainder of current page. |
1016 int remaining_in_page = | 1017 Address limit = NewSpacePage::FromLimit(top)->body_limit(); |
1017 static_cast<int>(NewSpacePage::FromLimit(top)->body_limit() - top); | 1018 if (heap()->gc_state() == Heap::SCAVENGE) { |
| 1019 heap()->promotion_queue()->SetNewLimit(limit); |
| 1020 } |
| 1021 |
| 1022 int remaining_in_page = static_cast<int>(limit - top); |
1018 heap()->CreateFillerObjectAt(top, remaining_in_page); | 1023 heap()->CreateFillerObjectAt(top, remaining_in_page); |
1019 pages_used_++; | 1024 pages_used_++; |
1020 UpdateAllocationInfo(); | 1025 UpdateAllocationInfo(); |
| 1026 |
1021 return true; | 1027 return true; |
1022 } | 1028 } |
1023 | 1029 |
1024 | 1030 |
| 1031 MaybeObject* NewSpace::SlowAllocateRaw(int size_in_bytes) { |
| 1032 Address old_top = allocation_info_.top; |
| 1033 Address new_top = old_top + size_in_bytes; |
| 1034 Address high = to_space_.page_high(); |
| 1035 if (allocation_info_.limit < high) { |
| 1036 // Incremental marking has lowered the limit to get a |
| 1037 // chance to do a step. |
| 1038 allocation_info_.limit = Min( |
| 1039 allocation_info_.limit + inline_allocation_limit_step_, |
| 1040 high); |
| 1041 int bytes_allocated = static_cast<int>(new_top - top_on_previous_step_); |
| 1042 heap()->incremental_marking()->Step(bytes_allocated); |
| 1043 top_on_previous_step_ = new_top; |
| 1044 return AllocateRaw(size_in_bytes); |
| 1045 } else if (AddFreshPage()) { |
| 1046 // Switched to new page. Try allocating again. |
| 1047 int bytes_allocated = static_cast<int>(old_top - top_on_previous_step_); |
| 1048 heap()->incremental_marking()->Step(bytes_allocated); |
| 1049 top_on_previous_step_ = to_space_.page_low(); |
| 1050 return AllocateRaw(size_in_bytes); |
| 1051 } else { |
| 1052 return Failure::RetryAfterGC(); |
| 1053 } |
| 1054 } |
| 1055 |
| 1056 |
1025 #ifdef DEBUG | 1057 #ifdef DEBUG |
1026 // We do not use the SemiSpaceIterator because verification doesn't assume | 1058 // We do not use the SemiSpaceIterator because verification doesn't assume |
1027 // that it works (it depends on the invariants we are checking). | 1059 // that it works (it depends on the invariants we are checking). |
1028 void NewSpace::Verify() { | 1060 void NewSpace::Verify() { |
1029 // The allocation pointer should be in the space or at the very end. | 1061 // The allocation pointer should be in the space or at the very end. |
1030 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); | 1062 ASSERT_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); |
1031 | 1063 |
1032 // There should be objects packed in from the low address up to the | 1064 // There should be objects packed in from the low address up to the |
1033 // allocation pointer. | 1065 // allocation pointer. |
1034 Address current = to_space_.first_page()->body(); | 1066 Address current = to_space_.first_page()->body(); |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 // OldSpace implementation | 1929 // OldSpace implementation |
1898 | 1930 |
1899 bool NewSpace::ReserveSpace(int bytes) { | 1931 bool NewSpace::ReserveSpace(int bytes) { |
1900 // We can't reliably unpack a partial snapshot that needs more new space | 1932 // We can't reliably unpack a partial snapshot that needs more new space |
1901 // space than the minimum NewSpace size. The limit can be set lower than | 1933 // space than the minimum NewSpace size. The limit can be set lower than |
1902 // the end of new space either because there is more space on the next page | 1934 // the end of new space either because there is more space on the next page |
1903 // or because we have lowered the limit in order to get periodic incremental | 1935 // or because we have lowered the limit in order to get periodic incremental |
1904 // marking. The most reliable way to ensure that there is linear space is | 1936 // marking. The most reliable way to ensure that there is linear space is |
1905 // to do the allocation, then rewind the limit. | 1937 // to do the allocation, then rewind the limit. |
1906 ASSERT(bytes <= InitialCapacity()); | 1938 ASSERT(bytes <= InitialCapacity()); |
1907 MaybeObject* maybe = AllocateRawInternal(bytes); | 1939 MaybeObject* maybe = AllocateRaw(bytes); |
1908 Object* object = NULL; | 1940 Object* object = NULL; |
1909 if (!maybe->ToObject(&object)) return false; | 1941 if (!maybe->ToObject(&object)) return false; |
1910 HeapObject* allocation = HeapObject::cast(object); | 1942 HeapObject* allocation = HeapObject::cast(object); |
1911 Address top = allocation_info_.top; | 1943 Address top = allocation_info_.top; |
1912 if ((top - bytes) == allocation->address()) { | 1944 if ((top - bytes) == allocation->address()) { |
1913 allocation_info_.top = allocation->address(); | 1945 allocation_info_.top = allocation->address(); |
1914 return true; | 1946 return true; |
1915 } | 1947 } |
1916 // There may be a borderline case here where the allocation succeeded, but | 1948 // There may be a borderline case here where the allocation succeeded, but |
1917 // the limit and top have moved on to a new page. In that case we try again. | 1949 // the limit and top have moved on to a new page. In that case we try again. |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2532 object->ShortPrint(); | 2564 object->ShortPrint(); |
2533 PrintF("\n"); | 2565 PrintF("\n"); |
2534 } | 2566 } |
2535 printf(" --------------------------------------\n"); | 2567 printf(" --------------------------------------\n"); |
2536 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 2568 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
2537 } | 2569 } |
2538 | 2570 |
2539 #endif // DEBUG | 2571 #endif // DEBUG |
2540 | 2572 |
2541 } } // namespace v8::internal | 2573 } } // namespace v8::internal |
OLD | NEW |