OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/base/platform/platform.h" | 7 #include "src/base/platform/platform.h" |
8 #include "src/full-codegen.h" | 8 #include "src/full-codegen.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/mark-compact.h" | 10 #include "src/mark-compact.h" |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->WasSwept()) { | 922 if (!chunk->InNewSpace() && !static_cast<Page*>(chunk)->WasSwept()) { |
923 static_cast<PagedSpace*>(chunk->owner())->IncrementUnsweptFreeBytes(-by); | 923 static_cast<PagedSpace*>(chunk->owner())->IncrementUnsweptFreeBytes(-by); |
924 } | 924 } |
925 chunk->IncrementLiveBytes(by); | 925 chunk->IncrementLiveBytes(by); |
926 } | 926 } |
927 | 927 |
928 | 928 |
929 // ----------------------------------------------------------------------------- | 929 // ----------------------------------------------------------------------------- |
930 // PagedSpace implementation | 930 // PagedSpace implementation |
931 | 931 |
932 PagedSpace::PagedSpace(Heap* heap, | 932 PagedSpace::PagedSpace(Heap* heap, intptr_t max_capacity, AllocationSpace id, |
933 intptr_t max_capacity, | |
934 AllocationSpace id, | |
935 Executability executable) | 933 Executability executable) |
936 : Space(heap, id, executable), | 934 : Space(heap, id, executable), |
937 free_list_(this), | 935 free_list_(this), |
938 swept_precisely_(true), | 936 swept_precisely_(true), |
939 unswept_free_bytes_(0), | 937 unswept_free_bytes_(0), |
940 end_of_unswept_pages_(NULL) { | 938 end_of_unswept_pages_(NULL), |
| 939 emergency_memory_(NULL) { |
941 if (id == CODE_SPACE) { | 940 if (id == CODE_SPACE) { |
942 area_size_ = heap->isolate()->memory_allocator()-> | 941 area_size_ = heap->isolate()->memory_allocator()-> |
943 CodePageAreaSize(); | 942 CodePageAreaSize(); |
944 } else { | 943 } else { |
945 area_size_ = Page::kPageSize - Page::kObjectStartOffset; | 944 area_size_ = Page::kPageSize - Page::kObjectStartOffset; |
946 } | 945 } |
947 max_capacity_ = (RoundDown(max_capacity, Page::kPageSize) / Page::kPageSize) | 946 max_capacity_ = (RoundDown(max_capacity, Page::kPageSize) / Page::kPageSize) |
948 * AreaSize(); | 947 * AreaSize(); |
949 accounting_stats_.Clear(); | 948 accounting_stats_.Clear(); |
950 | 949 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 heap()->isolate()->memory_allocator()->Free(page); | 1142 heap()->isolate()->memory_allocator()->Free(page); |
1144 } else { | 1143 } else { |
1145 heap()->QueueMemoryChunkForFree(page); | 1144 heap()->QueueMemoryChunkForFree(page); |
1146 } | 1145 } |
1147 | 1146 |
1148 ASSERT(Capacity() > 0); | 1147 ASSERT(Capacity() > 0); |
1149 accounting_stats_.ShrinkSpace(AreaSize()); | 1148 accounting_stats_.ShrinkSpace(AreaSize()); |
1150 } | 1149 } |
1151 | 1150 |
1152 | 1151 |
| 1152 void PagedSpace::CreateEmergencyMemory() { |
| 1153 emergency_memory_ = heap()->isolate()->memory_allocator()->AllocateChunk( |
| 1154 AreaSize(), AreaSize(), executable(), this); |
| 1155 } |
| 1156 |
| 1157 |
| 1158 void PagedSpace::FreeEmergencyMemory() { |
| 1159 Page* page = static_cast<Page*>(emergency_memory_); |
| 1160 ASSERT(page->LiveBytes() == 0); |
| 1161 ASSERT(AreaSize() == page->area_size()); |
| 1162 ASSERT(!free_list_.ContainsPageFreeListItems(page)); |
| 1163 heap()->isolate()->memory_allocator()->Free(page); |
| 1164 emergency_memory_ = NULL; |
| 1165 } |
| 1166 |
| 1167 |
| 1168 void PagedSpace::UseEmergencyMemory() { |
| 1169 Page* page = Page::Initialize(heap(), emergency_memory_, executable(), this); |
| 1170 page->InsertAfter(anchor_.prev_page()); |
| 1171 emergency_memory_ = NULL; |
| 1172 } |
| 1173 |
| 1174 |
1153 #ifdef DEBUG | 1175 #ifdef DEBUG |
1154 void PagedSpace::Print() { } | 1176 void PagedSpace::Print() { } |
1155 #endif | 1177 #endif |
1156 | 1178 |
1157 #ifdef VERIFY_HEAP | 1179 #ifdef VERIFY_HEAP |
1158 void PagedSpace::Verify(ObjectVisitor* visitor) { | 1180 void PagedSpace::Verify(ObjectVisitor* visitor) { |
1159 // We can only iterate over the pages if they were swept precisely. | 1181 // We can only iterate over the pages if they were swept precisely. |
1160 if (!swept_precisely_) return; | 1182 if (!swept_precisely_) return; |
1161 | 1183 |
1162 bool allocation_pointer_found_in_space = | 1184 bool allocation_pointer_found_in_space = |
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3152 object->ShortPrint(); | 3174 object->ShortPrint(); |
3153 PrintF("\n"); | 3175 PrintF("\n"); |
3154 } | 3176 } |
3155 printf(" --------------------------------------\n"); | 3177 printf(" --------------------------------------\n"); |
3156 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3178 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3157 } | 3179 } |
3158 | 3180 |
3159 #endif // DEBUG | 3181 #endif // DEBUG |
3160 | 3182 |
3161 } } // namespace v8::internal | 3183 } } // namespace v8::internal |
OLD | NEW |