| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 return initial_chunk_->address(); | 391 return initial_chunk_->address(); |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 static int PagesInChunk(Address start, size_t size) { | 395 static int PagesInChunk(Address start, size_t size) { |
| 396 // The first page starts on the first page-aligned address from start onward | 396 // The first page starts on the first page-aligned address from start onward |
| 397 // and the last page ends on the last page-aligned address before | 397 // and the last page ends on the last page-aligned address before |
| 398 // start+size. Page::kPageSize is a power of two so we can divide by | 398 // start+size. Page::kPageSize is a power of two so we can divide by |
| 399 // shifting. | 399 // shifting. |
| 400 return static_cast<int>((RoundDown(start + size, Page::kPageSize) | 400 return static_cast<int>((RoundDown(start + size, Page::kPageSize) |
| 401 - RoundUp(start, Page::kPageSize)) >> Page::kPageSizeBits); | 401 - RoundUp(start, Page::kPageSize)) >> kPageSizeBits); |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 Page* MemoryAllocator::AllocatePages(int requested_pages, int* allocated_pages, | 405 Page* MemoryAllocator::AllocatePages(int requested_pages, int* allocated_pages, |
| 406 PagedSpace* owner) { | 406 PagedSpace* owner) { |
| 407 if (requested_pages <= 0) return Page::FromAddress(NULL); | 407 if (requested_pages <= 0) return Page::FromAddress(NULL); |
| 408 size_t chunk_size = requested_pages * Page::kPageSize; | 408 size_t chunk_size = requested_pages * Page::kPageSize; |
| 409 | 409 |
| 410 // There is not enough space to guarantee the desired number pages can be | 410 // There is not enough space to guarantee the desired number pages can be |
| 411 // allocated. | 411 // allocated. |
| 412 if (size_ + static_cast<int>(chunk_size) > capacity_) { | 412 if (size_ + static_cast<int>(chunk_size) > capacity_) { |
| 413 // Request as many pages as we can. | 413 // Request as many pages as we can. |
| 414 chunk_size = capacity_ - size_; | 414 chunk_size = capacity_ - size_; |
| 415 requested_pages = static_cast<int>(chunk_size >> Page::kPageSizeBits); | 415 requested_pages = static_cast<int>(chunk_size >> kPageSizeBits); |
| 416 | 416 |
| 417 if (requested_pages <= 0) return Page::FromAddress(NULL); | 417 if (requested_pages <= 0) return Page::FromAddress(NULL); |
| 418 } | 418 } |
| 419 void* chunk = AllocateRawMemory(chunk_size, &chunk_size, owner->executable()); | 419 void* chunk = AllocateRawMemory(chunk_size, &chunk_size, owner->executable()); |
| 420 if (chunk == NULL) return Page::FromAddress(NULL); | 420 if (chunk == NULL) return Page::FromAddress(NULL); |
| 421 LOG(NewEvent("PagedChunk", chunk, chunk_size)); | 421 LOG(NewEvent("PagedChunk", chunk, chunk_size)); |
| 422 | 422 |
| 423 *allocated_pages = PagesInChunk(static_cast<Address>(chunk), chunk_size); | 423 *allocated_pages = PagesInChunk(static_cast<Address>(chunk), chunk_size); |
| 424 if (*allocated_pages == 0) { | 424 if (*allocated_pages == 0) { |
| 425 FreeRawMemory(chunk, chunk_size); | 425 FreeRawMemory(chunk, chunk_size); |
| (...skipping 2365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2791 reinterpret_cast<Object**>(object->address() | 2791 reinterpret_cast<Object**>(object->address() |
| 2792 + Page::kObjectAreaSize), | 2792 + Page::kObjectAreaSize), |
| 2793 allocation_top); | 2793 allocation_top); |
| 2794 PrintF("\n"); | 2794 PrintF("\n"); |
| 2795 } | 2795 } |
| 2796 } | 2796 } |
| 2797 } | 2797 } |
| 2798 #endif // DEBUG | 2798 #endif // DEBUG |
| 2799 | 2799 |
| 2800 } } // namespace v8::internal | 2800 } } // namespace v8::internal |
| OLD | NEW |