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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 delete code_range_; // Frees all memory in the virtual memory range. | 263 delete code_range_; // Frees all memory in the virtual memory range. |
264 code_range_ = NULL; | 264 code_range_ = NULL; |
265 free_list_.Free(); | 265 free_list_.Free(); |
266 allocation_list_.Free(); | 266 allocation_list_.Free(); |
267 } | 267 } |
268 | 268 |
269 | 269 |
270 // ----------------------------------------------------------------------------- | 270 // ----------------------------------------------------------------------------- |
271 // MemoryAllocator | 271 // MemoryAllocator |
272 // | 272 // |
273 intptr_t MemoryAllocator::capacity_ = 0; | 273 int MemoryAllocator::capacity_ = 0; |
274 intptr_t MemoryAllocator::size_ = 0; | 274 int MemoryAllocator::size_ = 0; |
275 intptr_t MemoryAllocator::size_executable_ = 0; | 275 int MemoryAllocator::size_executable_ = 0; |
276 | 276 |
277 List<MemoryAllocator::MemoryAllocationCallbackRegistration> | 277 List<MemoryAllocator::MemoryAllocationCallbackRegistration> |
278 MemoryAllocator::memory_allocation_callbacks_; | 278 MemoryAllocator::memory_allocation_callbacks_; |
279 | 279 |
280 VirtualMemory* MemoryAllocator::initial_chunk_ = NULL; | 280 VirtualMemory* MemoryAllocator::initial_chunk_ = NULL; |
281 | 281 |
282 // 270 is an estimate based on the static default heap size of a pair of 256K | 282 // 270 is an estimate based on the static default heap size of a pair of 256K |
283 // semispaces and a 64M old generation. | 283 // semispaces and a 64M old generation. |
284 const int kEstimatedNumberOfChunks = 270; | 284 const int kEstimatedNumberOfChunks = 270; |
285 List<MemoryAllocator::ChunkInfo> MemoryAllocator::chunks_( | 285 List<MemoryAllocator::ChunkInfo> MemoryAllocator::chunks_( |
286 kEstimatedNumberOfChunks); | 286 kEstimatedNumberOfChunks); |
287 List<int> MemoryAllocator::free_chunk_ids_(kEstimatedNumberOfChunks); | 287 List<int> MemoryAllocator::free_chunk_ids_(kEstimatedNumberOfChunks); |
288 int MemoryAllocator::max_nof_chunks_ = 0; | 288 int MemoryAllocator::max_nof_chunks_ = 0; |
289 int MemoryAllocator::top_ = 0; | 289 int MemoryAllocator::top_ = 0; |
290 | 290 |
291 | 291 |
292 void MemoryAllocator::Push(int free_chunk_id) { | 292 void MemoryAllocator::Push(int free_chunk_id) { |
293 ASSERT(max_nof_chunks_ > 0); | 293 ASSERT(max_nof_chunks_ > 0); |
294 ASSERT(top_ < max_nof_chunks_); | 294 ASSERT(top_ < max_nof_chunks_); |
295 free_chunk_ids_[top_++] = free_chunk_id; | 295 free_chunk_ids_[top_++] = free_chunk_id; |
296 } | 296 } |
297 | 297 |
298 | 298 |
299 int MemoryAllocator::Pop() { | 299 int MemoryAllocator::Pop() { |
300 ASSERT(top_ > 0); | 300 ASSERT(top_ > 0); |
301 return free_chunk_ids_[--top_]; | 301 return free_chunk_ids_[--top_]; |
302 } | 302 } |
303 | 303 |
304 | 304 |
305 bool MemoryAllocator::Setup(intptr_t capacity) { | 305 bool MemoryAllocator::Setup(int capacity) { |
306 capacity_ = RoundUp(capacity, Page::kPageSize); | 306 capacity_ = RoundUp(capacity, Page::kPageSize); |
307 | 307 |
308 // Over-estimate the size of chunks_ array. It assumes the expansion of old | 308 // Over-estimate the size of chunks_ array. It assumes the expansion of old |
309 // space is always in the unit of a chunk (kChunkSize) except the last | 309 // space is always in the unit of a chunk (kChunkSize) except the last |
310 // expansion. | 310 // expansion. |
311 // | 311 // |
312 // Due to alignment, allocated space might be one page less than required | 312 // Due to alignment, allocated space might be one page less than required |
313 // number (kPagesPerChunk) of pages for old spaces. | 313 // number (kPagesPerChunk) of pages for old spaces. |
314 // | 314 // |
315 // Reserve two chunk ids for semispaces, one for map space, one for old | 315 // Reserve two chunk ids for semispaces, one for map space, one for old |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 Address high = RoundDown(chunk_start + chunk_size, Page::kPageSize); | 684 Address high = RoundDown(chunk_start + chunk_size, Page::kPageSize); |
685 ASSERT(chunk_start <= p->address() && p->address() < high); | 685 ASSERT(chunk_start <= p->address() && p->address() < high); |
686 | 686 |
687 return Page::FromAddress(high - Page::kPageSize); | 687 return Page::FromAddress(high - Page::kPageSize); |
688 } | 688 } |
689 | 689 |
690 | 690 |
691 #ifdef DEBUG | 691 #ifdef DEBUG |
692 void MemoryAllocator::ReportStatistics() { | 692 void MemoryAllocator::ReportStatistics() { |
693 float pct = static_cast<float>(capacity_ - size_) / capacity_; | 693 float pct = static_cast<float>(capacity_ - size_) / capacity_; |
694 PrintF(" capacity: %" V8_PTR_PREFIX "d" | 694 PrintF(" capacity: %d, used: %d, available: %%%d\n\n", |
695 ", used: %" V8_PTR_PREFIX "d" | |
696 ", available: %%%d\n\n", | |
697 capacity_, size_, static_cast<int>(pct*100)); | 695 capacity_, size_, static_cast<int>(pct*100)); |
698 } | 696 } |
699 #endif | 697 #endif |
700 | 698 |
701 | 699 |
702 void MemoryAllocator::RelinkPageListInChunkOrder(PagedSpace* space, | 700 void MemoryAllocator::RelinkPageListInChunkOrder(PagedSpace* space, |
703 Page** first_page, | 701 Page** first_page, |
704 Page** last_page, | 702 Page** last_page, |
705 Page** last_page_in_use) { | 703 Page** last_page_in_use) { |
706 Page* first = NULL; | 704 Page* first = NULL; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 762 } |
765 | 763 |
766 return last_page; | 764 return last_page; |
767 } | 765 } |
768 | 766 |
769 | 767 |
770 | 768 |
771 // ----------------------------------------------------------------------------- | 769 // ----------------------------------------------------------------------------- |
772 // PagedSpace implementation | 770 // PagedSpace implementation |
773 | 771 |
774 PagedSpace::PagedSpace(intptr_t max_capacity, | 772 PagedSpace::PagedSpace(int max_capacity, |
775 AllocationSpace id, | 773 AllocationSpace id, |
776 Executability executable) | 774 Executability executable) |
777 : Space(id, executable) { | 775 : Space(id, executable) { |
778 max_capacity_ = (RoundDown(max_capacity, Page::kPageSize) / Page::kPageSize) | 776 max_capacity_ = (RoundDown(max_capacity, Page::kPageSize) / Page::kPageSize) |
779 * Page::kObjectAreaSize; | 777 * Page::kObjectAreaSize; |
780 accounting_stats_.Clear(); | 778 accounting_stats_.Clear(); |
781 | 779 |
782 allocation_info_.top = NULL; | 780 allocation_info_.top = NULL; |
783 allocation_info_.limit = NULL; | 781 allocation_info_.limit = NULL; |
784 | 782 |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 } | 1636 } |
1639 LOG(HeapSampleEndEvent("NewSpace", description)); | 1637 LOG(HeapSampleEndEvent("NewSpace", description)); |
1640 } | 1638 } |
1641 #endif // ENABLE_LOGGING_AND_PROFILING | 1639 #endif // ENABLE_LOGGING_AND_PROFILING |
1642 | 1640 |
1643 | 1641 |
1644 void NewSpace::ReportStatistics() { | 1642 void NewSpace::ReportStatistics() { |
1645 #ifdef DEBUG | 1643 #ifdef DEBUG |
1646 if (FLAG_heap_stats) { | 1644 if (FLAG_heap_stats) { |
1647 float pct = static_cast<float>(Available()) / Capacity(); | 1645 float pct = static_cast<float>(Available()) / Capacity(); |
1648 PrintF(" capacity: %" V8_PTR_PREFIX "d" | 1646 PrintF(" capacity: %d, available: %d, %%%d\n", |
1649 ", available: %" V8_PTR_PREFIX "d, %%%d\n", | |
1650 Capacity(), Available(), static_cast<int>(pct*100)); | 1647 Capacity(), Available(), static_cast<int>(pct*100)); |
1651 PrintF("\n Object Histogram:\n"); | 1648 PrintF("\n Object Histogram:\n"); |
1652 for (int i = 0; i <= LAST_TYPE; i++) { | 1649 for (int i = 0; i <= LAST_TYPE; i++) { |
1653 if (allocated_histogram_[i].number() > 0) { | 1650 if (allocated_histogram_[i].number() > 0) { |
1654 PrintF(" %-34s%10d (%10d bytes)\n", | 1651 PrintF(" %-34s%10d (%10d bytes)\n", |
1655 allocated_histogram_[i].name(), | 1652 allocated_histogram_[i].name(), |
1656 allocated_histogram_[i].number(), | 1653 allocated_histogram_[i].number(), |
1657 allocated_histogram_[i].bytes()); | 1654 allocated_histogram_[i].bytes()); |
1658 } | 1655 } |
1659 } | 1656 } |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2398 prev_pc <= code->instruction_end()); | 2395 prev_pc <= code->instruction_end()); |
2399 delta += static_cast<int>(code->instruction_end() - prev_pc); | 2396 delta += static_cast<int>(code->instruction_end() - prev_pc); |
2400 EnterComment("NoComment", delta); | 2397 EnterComment("NoComment", delta); |
2401 } | 2398 } |
2402 } | 2399 } |
2403 } | 2400 } |
2404 | 2401 |
2405 | 2402 |
2406 void OldSpace::ReportStatistics() { | 2403 void OldSpace::ReportStatistics() { |
2407 int pct = Available() * 100 / Capacity(); | 2404 int pct = Available() * 100 / Capacity(); |
2408 PrintF(" capacity: %" V8_PTR_PREFIX "d" | 2405 PrintF(" capacity: %d, waste: %d, available: %d, %%%d\n", |
2409 ", waste: %" V8_PTR_PREFIX "d" | |
2410 ", available: %" V8_PTR_PREFIX "d, %%%d\n", | |
2411 Capacity(), Waste(), Available(), pct); | 2406 Capacity(), Waste(), Available(), pct); |
2412 | 2407 |
2413 ClearHistograms(); | 2408 ClearHistograms(); |
2414 HeapObjectIterator obj_it(this); | 2409 HeapObjectIterator obj_it(this); |
2415 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) | 2410 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) |
2416 CollectHistogramInfo(obj); | 2411 CollectHistogramInfo(obj); |
2417 ReportHistogram(true); | 2412 ReportHistogram(true); |
2418 } | 2413 } |
2419 #endif | 2414 #endif |
2420 | 2415 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2557 Address end = start + size_in_bytes; | 2552 Address end = start + size_in_bytes; |
2558 for (Address a = start; a < end; a += size) { | 2553 for (Address a = start; a < end; a += size) { |
2559 Free(a, add_to_freelist); | 2554 Free(a, add_to_freelist); |
2560 } | 2555 } |
2561 } | 2556 } |
2562 | 2557 |
2563 | 2558 |
2564 #ifdef DEBUG | 2559 #ifdef DEBUG |
2565 void FixedSpace::ReportStatistics() { | 2560 void FixedSpace::ReportStatistics() { |
2566 int pct = Available() * 100 / Capacity(); | 2561 int pct = Available() * 100 / Capacity(); |
2567 PrintF(" capacity: %" V8_PTR_PREFIX "d" | 2562 PrintF(" capacity: %d, waste: %d, available: %d, %%%d\n", |
2568 ", waste: %" V8_PTR_PREFIX "d" | |
2569 ", available: %" V8_PTR_PREFIX "d, %%%d\n", | |
2570 Capacity(), Waste(), Available(), pct); | 2563 Capacity(), Waste(), Available(), pct); |
2571 | 2564 |
2572 ClearHistograms(); | 2565 ClearHistograms(); |
2573 HeapObjectIterator obj_it(this); | 2566 HeapObjectIterator obj_it(this); |
2574 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) | 2567 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) |
2575 CollectHistogramInfo(obj); | 2568 CollectHistogramInfo(obj); |
2576 ReportHistogram(false); | 2569 ReportHistogram(false); |
2577 } | 2570 } |
2578 #endif | 2571 #endif |
2579 | 2572 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3011 | 3004 |
3012 void LargeObjectSpace::Print() { | 3005 void LargeObjectSpace::Print() { |
3013 LargeObjectIterator it(this); | 3006 LargeObjectIterator it(this); |
3014 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) { | 3007 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) { |
3015 obj->Print(); | 3008 obj->Print(); |
3016 } | 3009 } |
3017 } | 3010 } |
3018 | 3011 |
3019 | 3012 |
3020 void LargeObjectSpace::ReportStatistics() { | 3013 void LargeObjectSpace::ReportStatistics() { |
3021 PrintF(" size: %" V8_PTR_PREFIX "d\n", size_); | 3014 PrintF(" size: %d\n", size_); |
3022 int num_objects = 0; | 3015 int num_objects = 0; |
3023 ClearHistograms(); | 3016 ClearHistograms(); |
3024 LargeObjectIterator it(this); | 3017 LargeObjectIterator it(this); |
3025 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) { | 3018 for (HeapObject* obj = it.next(); obj != NULL; obj = it.next()) { |
3026 num_objects++; | 3019 num_objects++; |
3027 CollectHistogramInfo(obj); | 3020 CollectHistogramInfo(obj); |
3028 } | 3021 } |
3029 | 3022 |
3030 PrintF(" number of objects %d\n", num_objects); | 3023 PrintF(" number of objects %d\n", num_objects); |
3031 if (num_objects > 0) ReportHistogram(false); | 3024 if (num_objects > 0) ReportHistogram(false); |
3032 } | 3025 } |
3033 | 3026 |
3034 | 3027 |
3035 void LargeObjectSpace::CollectCodeStatistics() { | 3028 void LargeObjectSpace::CollectCodeStatistics() { |
3036 LargeObjectIterator obj_it(this); | 3029 LargeObjectIterator obj_it(this); |
3037 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { | 3030 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { |
3038 if (obj->IsCode()) { | 3031 if (obj->IsCode()) { |
3039 Code* code = Code::cast(obj); | 3032 Code* code = Code::cast(obj); |
3040 code_kind_statistics[code->kind()] += code->Size(); | 3033 code_kind_statistics[code->kind()] += code->Size(); |
3041 } | 3034 } |
3042 } | 3035 } |
3043 } | 3036 } |
3044 #endif // DEBUG | 3037 #endif // DEBUG |
3045 | 3038 |
3046 } } // namespace v8::internal | 3039 } } // namespace v8::internal |
OLD | NEW |