OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 int Heap::max_old_generation_size_ = 512*MB; | 91 int Heap::max_old_generation_size_ = 512*MB; |
92 int Heap::initial_semispace_size_ = 512*KB; | 92 int Heap::initial_semispace_size_ = 512*KB; |
93 size_t Heap::code_range_size_ = 0; | 93 size_t Heap::code_range_size_ = 0; |
94 #endif | 94 #endif |
95 | 95 |
96 // The snapshot semispace size will be the default semispace size if | 96 // The snapshot semispace size will be the default semispace size if |
97 // snapshotting is used and will be the requested semispace size as | 97 // snapshotting is used and will be the requested semispace size as |
98 // set up by ConfigureHeap otherwise. | 98 // set up by ConfigureHeap otherwise. |
99 int Heap::reserved_semispace_size_ = Heap::max_semispace_size_; | 99 int Heap::reserved_semispace_size_ = Heap::max_semispace_size_; |
100 | 100 |
| 101 List<Heap::GCPrologueCallbackPair> Heap::gc_prologue_callbacks_; |
| 102 List<Heap::GCEpilogueCallbackPair> Heap::gc_epilogue_callbacks_; |
| 103 |
101 GCCallback Heap::global_gc_prologue_callback_ = NULL; | 104 GCCallback Heap::global_gc_prologue_callback_ = NULL; |
102 GCCallback Heap::global_gc_epilogue_callback_ = NULL; | 105 GCCallback Heap::global_gc_epilogue_callback_ = NULL; |
103 | 106 |
104 // Variables set based on semispace_size_ and old_generation_size_ in | 107 // Variables set based on semispace_size_ and old_generation_size_ in |
105 // ConfigureHeap. | 108 // ConfigureHeap. |
106 | 109 |
107 // Will be 4 * reserved_semispace_size_ to ensure that young | 110 // Will be 4 * reserved_semispace_size_ to ensure that young |
108 // generation can be aligned to its size. | 111 // generation can be aligned to its size. |
109 int Heap::survived_since_last_expansion_ = 0; | 112 int Heap::survived_since_last_expansion_ = 0; |
110 int Heap::external_allocation_limit_ = 0; | 113 int Heap::external_allocation_limit_ = 0; |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 543 |
541 void Heap::PerformGarbageCollection(AllocationSpace space, | 544 void Heap::PerformGarbageCollection(AllocationSpace space, |
542 GarbageCollector collector, | 545 GarbageCollector collector, |
543 GCTracer* tracer) { | 546 GCTracer* tracer) { |
544 VerifySymbolTable(); | 547 VerifySymbolTable(); |
545 if (collector == MARK_COMPACTOR && global_gc_prologue_callback_) { | 548 if (collector == MARK_COMPACTOR && global_gc_prologue_callback_) { |
546 ASSERT(!allocation_allowed_); | 549 ASSERT(!allocation_allowed_); |
547 GCTracer::ExternalScope scope(tracer); | 550 GCTracer::ExternalScope scope(tracer); |
548 global_gc_prologue_callback_(); | 551 global_gc_prologue_callback_(); |
549 } | 552 } |
| 553 |
| 554 GCType gc_type = |
| 555 collector == MARK_COMPACTOR ? kGCTypeMarkSweepCompact : kGCTypeScavenge; |
| 556 |
| 557 for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { |
| 558 if (gc_type & gc_prologue_callbacks_[i].gc_type) { |
| 559 gc_prologue_callbacks_[i].callback(gc_type, kNoGCCallbackFlags); |
| 560 } |
| 561 } |
| 562 |
550 EnsureFromSpaceIsCommitted(); | 563 EnsureFromSpaceIsCommitted(); |
551 | 564 |
552 // Perform mark-sweep with optional compaction. | 565 // Perform mark-sweep with optional compaction. |
553 if (collector == MARK_COMPACTOR) { | 566 if (collector == MARK_COMPACTOR) { |
554 MarkCompact(tracer); | 567 MarkCompact(tracer); |
555 } | 568 } |
556 | 569 |
557 // Always perform a scavenge to make room in new space. | 570 // Always perform a scavenge to make room in new space. |
558 Scavenge(); | 571 Scavenge(); |
559 | 572 |
(...skipping 18 matching lines...) Expand all Loading... |
578 | 591 |
579 // Update relocatables. | 592 // Update relocatables. |
580 Relocatable::PostGarbageCollectionProcessing(); | 593 Relocatable::PostGarbageCollectionProcessing(); |
581 | 594 |
582 if (collector == MARK_COMPACTOR) { | 595 if (collector == MARK_COMPACTOR) { |
583 // Register the amount of external allocated memory. | 596 // Register the amount of external allocated memory. |
584 amount_of_external_allocated_memory_at_last_global_gc_ = | 597 amount_of_external_allocated_memory_at_last_global_gc_ = |
585 amount_of_external_allocated_memory_; | 598 amount_of_external_allocated_memory_; |
586 } | 599 } |
587 | 600 |
| 601 GCCallbackFlags callback_flags = tracer->is_compacting() |
| 602 ? kGCCallbackFlagCompacted |
| 603 : kNoGCCallbackFlags; |
| 604 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { |
| 605 if (gc_type & gc_epilogue_callbacks_[i].gc_type) { |
| 606 gc_epilogue_callbacks_[i].callback(gc_type, callback_flags); |
| 607 } |
| 608 } |
| 609 |
588 if (collector == MARK_COMPACTOR && global_gc_epilogue_callback_) { | 610 if (collector == MARK_COMPACTOR && global_gc_epilogue_callback_) { |
589 ASSERT(!allocation_allowed_); | 611 ASSERT(!allocation_allowed_); |
590 GCTracer::ExternalScope scope(tracer); | 612 GCTracer::ExternalScope scope(tracer); |
591 global_gc_epilogue_callback_(); | 613 global_gc_epilogue_callback_(); |
592 } | 614 } |
593 VerifySymbolTable(); | 615 VerifySymbolTable(); |
594 } | 616 } |
595 | 617 |
596 | 618 |
597 void Heap::MarkCompact(GCTracer* tracer) { | 619 void Heap::MarkCompact(GCTracer* tracer) { |
(...skipping 3181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3779 if (HasBeenSetup()) { | 3801 if (HasBeenSetup()) { |
3780 AllSpaces spaces; | 3802 AllSpaces spaces; |
3781 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) | 3803 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) |
3782 space->Unprotect(); | 3804 space->Unprotect(); |
3783 } | 3805 } |
3784 } | 3806 } |
3785 | 3807 |
3786 #endif | 3808 #endif |
3787 | 3809 |
3788 | 3810 |
| 3811 void Heap::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) { |
| 3812 ASSERT(callback != NULL); |
| 3813 GCPrologueCallbackPair pair(callback, gc_type); |
| 3814 ASSERT(!gc_prologue_callbacks_.Contains(pair)); |
| 3815 return gc_prologue_callbacks_.Add(pair); |
| 3816 } |
| 3817 |
| 3818 |
| 3819 void Heap::RemoveGCPrologueCallback(GCPrologueCallback callback) { |
| 3820 ASSERT(callback != NULL); |
| 3821 for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) { |
| 3822 if (gc_prologue_callbacks_[i].callback == callback) { |
| 3823 gc_prologue_callbacks_.Remove(i); |
| 3824 return; |
| 3825 } |
| 3826 } |
| 3827 UNREACHABLE(); |
| 3828 } |
| 3829 |
| 3830 |
| 3831 void Heap::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) { |
| 3832 ASSERT(callback != NULL); |
| 3833 GCEpilogueCallbackPair pair(callback, gc_type); |
| 3834 ASSERT(!gc_epilogue_callbacks_.Contains(pair)); |
| 3835 return gc_epilogue_callbacks_.Add(pair); |
| 3836 } |
| 3837 |
| 3838 |
| 3839 void Heap::RemoveGCEpilogueCallback(GCEpilogueCallback callback) { |
| 3840 ASSERT(callback != NULL); |
| 3841 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) { |
| 3842 if (gc_epilogue_callbacks_[i].callback == callback) { |
| 3843 gc_epilogue_callbacks_.Remove(i); |
| 3844 return; |
| 3845 } |
| 3846 } |
| 3847 UNREACHABLE(); |
| 3848 } |
| 3849 |
| 3850 |
3789 #ifdef DEBUG | 3851 #ifdef DEBUG |
3790 | 3852 |
3791 class PrintHandleVisitor: public ObjectVisitor { | 3853 class PrintHandleVisitor: public ObjectVisitor { |
3792 public: | 3854 public: |
3793 void VisitPointers(Object** start, Object** end) { | 3855 void VisitPointers(Object** start, Object** end) { |
3794 for (Object** p = start; p < end; p++) | 3856 for (Object** p = start; p < end; p++) |
3795 PrintF(" handle %p to %p\n", p, *p); | 3857 PrintF(" handle %p to %p\n", p, *p); |
3796 } | 3858 } |
3797 }; | 3859 }; |
3798 | 3860 |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4303 void ExternalStringTable::TearDown() { | 4365 void ExternalStringTable::TearDown() { |
4304 new_space_strings_.Free(); | 4366 new_space_strings_.Free(); |
4305 old_space_strings_.Free(); | 4367 old_space_strings_.Free(); |
4306 } | 4368 } |
4307 | 4369 |
4308 | 4370 |
4309 List<Object*> ExternalStringTable::new_space_strings_; | 4371 List<Object*> ExternalStringTable::new_space_strings_; |
4310 List<Object*> ExternalStringTable::old_space_strings_; | 4372 List<Object*> ExternalStringTable::old_space_strings_; |
4311 | 4373 |
4312 } } // namespace v8::internal | 4374 } } // namespace v8::internal |
OLD | NEW |