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 2286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 // allocation space has been set up with the top and limit of the space. If | 2297 // allocation space has been set up with the top and limit of the space. If |
2298 // the allocation fails then NULL is returned, and the caller can perform a GC | 2298 // the allocation fails then NULL is returned, and the caller can perform a GC |
2299 // or allocate a new page before retrying. | 2299 // or allocate a new page before retrying. |
2300 HeapObject* FreeList::Allocate(int size_in_bytes) { | 2300 HeapObject* FreeList::Allocate(int size_in_bytes) { |
2301 ASSERT(0 < size_in_bytes); | 2301 ASSERT(0 < size_in_bytes); |
2302 ASSERT(size_in_bytes <= kMaxBlockSize); | 2302 ASSERT(size_in_bytes <= kMaxBlockSize); |
2303 ASSERT(IsAligned(size_in_bytes, kPointerSize)); | 2303 ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
2304 // Don't free list allocate if there is linear space available. | 2304 // Don't free list allocate if there is linear space available. |
2305 ASSERT(owner_->limit() - owner_->top() < size_in_bytes); | 2305 ASSERT(owner_->limit() - owner_->top() < size_in_bytes); |
2306 | 2306 |
2307 int new_node_size = 0; | |
2308 FreeListNode* new_node = FindNodeFor(size_in_bytes, &new_node_size); | |
2309 if (new_node == NULL) return NULL; | |
2310 | |
2311 | |
2312 int bytes_left = new_node_size - size_in_bytes; | |
2313 ASSERT(bytes_left >= 0); | |
2314 | |
2315 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); | 2307 int old_linear_size = static_cast<int>(owner_->limit() - owner_->top()); |
2316 // Mark the old linear allocation area with a free space map so it can be | 2308 // Mark the old linear allocation area with a free space map so it can be |
2317 // skipped when scanning the heap. This also puts it back in the free list | 2309 // skipped when scanning the heap. This also puts it back in the free list |
2318 // if it is big enough. | 2310 // if it is big enough. |
2319 owner_->Free(owner_->top(), old_linear_size); | 2311 owner_->Free(owner_->top(), old_linear_size); |
2320 | 2312 |
2321 owner_->heap()->incremental_marking()->OldSpaceStep( | 2313 owner_->heap()->incremental_marking()->OldSpaceStep( |
2322 size_in_bytes - old_linear_size); | 2314 size_in_bytes - old_linear_size); |
2323 | 2315 |
| 2316 int new_node_size = 0; |
| 2317 FreeListNode* new_node = FindNodeFor(size_in_bytes, &new_node_size); |
| 2318 if (new_node == NULL) { |
| 2319 owner_->SetTop(NULL, NULL); |
| 2320 return NULL; |
| 2321 } |
| 2322 |
| 2323 int bytes_left = new_node_size - size_in_bytes; |
| 2324 ASSERT(bytes_left >= 0); |
| 2325 |
2324 #ifdef DEBUG | 2326 #ifdef DEBUG |
2325 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { | 2327 for (int i = 0; i < size_in_bytes / kPointerSize; i++) { |
2326 reinterpret_cast<Object**>(new_node->address())[i] = | 2328 reinterpret_cast<Object**>(new_node->address())[i] = |
2327 Smi::FromInt(kCodeZapValue); | 2329 Smi::FromInt(kCodeZapValue); |
2328 } | 2330 } |
2329 #endif | 2331 #endif |
2330 | 2332 |
2331 // The old-space-step might have finished sweeping and restarted marking. | 2333 // The old-space-step might have finished sweeping and restarted marking. |
2332 // Verify that it did not turn the page of the new node into an evacuation | 2334 // Verify that it did not turn the page of the new node into an evacuation |
2333 // candidate. | 2335 // candidate. |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 object->ShortPrint(); | 3178 object->ShortPrint(); |
3177 PrintF("\n"); | 3179 PrintF("\n"); |
3178 } | 3180 } |
3179 printf(" --------------------------------------\n"); | 3181 printf(" --------------------------------------\n"); |
3180 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); | 3182 printf(" Marked: %x, LiveCount: %x\n", mark_size, LiveBytes()); |
3181 } | 3183 } |
3182 | 3184 |
3183 #endif // DEBUG | 3185 #endif // DEBUG |
3184 | 3186 |
3185 } } // namespace v8::internal | 3187 } } // namespace v8::internal |
OLD | NEW |