Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/heap.cc

Issue 1165004: New GCCallbacks with additional parameters. (Closed)
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 3182 matching lines...) Expand 10 before | Expand all | Expand 10 after
3780 if (HasBeenSetup()) { 3802 if (HasBeenSetup()) {
3781 AllSpaces spaces; 3803 AllSpaces spaces;
3782 for (Space* space = spaces.next(); space != NULL; space = spaces.next()) 3804 for (Space* space = spaces.next(); space != NULL; space = spaces.next())
3783 space->Unprotect(); 3805 space->Unprotect();
3784 } 3806 }
3785 } 3807 }
3786 3808
3787 #endif 3809 #endif
3788 3810
3789 3811
3812 void Heap::AddGCPrologueCallback(GCPrologueCallback callback, GCType gc_type) {
3813 ASSERT(callback != NULL);
3814 GCPrologueCallbackPair pair(callback, gc_type);
3815 ASSERT(!gc_prologue_callbacks_.Contains(pair));
3816 return gc_prologue_callbacks_.Add(pair);
3817 }
3818
3819
3820 void Heap::RemoveGCPrologueCallback(GCPrologueCallback callback) {
3821 ASSERT(callback != NULL);
3822 for (int i = 0; i < gc_prologue_callbacks_.length(); ++i) {
3823 if (gc_prologue_callbacks_[i].callback == callback) {
3824 gc_prologue_callbacks_.Remove(i);
3825 return;
3826 }
3827 }
3828 UNREACHABLE();
3829 }
3830
3831
3832 void Heap::AddGCEpilogueCallback(GCEpilogueCallback callback, GCType gc_type) {
3833 ASSERT(callback != NULL);
3834 GCEpilogueCallbackPair pair(callback, gc_type);
3835 ASSERT(!gc_epilogue_callbacks_.Contains(pair));
3836 return gc_epilogue_callbacks_.Add(pair);
3837 }
3838
3839
3840 void Heap::RemoveGCEpilogueCallback(GCEpilogueCallback callback) {
3841 ASSERT(callback != NULL);
3842 for (int i = 0; i < gc_epilogue_callbacks_.length(); ++i) {
3843 if (gc_epilogue_callbacks_[i].callback == callback) {
3844 gc_epilogue_callbacks_.Remove(i);
3845 return;
3846 }
3847 }
3848 UNREACHABLE();
3849 }
3850
3851
3790 #ifdef DEBUG 3852 #ifdef DEBUG
3791 3853
3792 class PrintHandleVisitor: public ObjectVisitor { 3854 class PrintHandleVisitor: public ObjectVisitor {
3793 public: 3855 public:
3794 void VisitPointers(Object** start, Object** end) { 3856 void VisitPointers(Object** start, Object** end) {
3795 for (Object** p = start; p < end; p++) 3857 for (Object** p = start; p < end; p++)
3796 PrintF(" handle %p to %p\n", p, *p); 3858 PrintF(" handle %p to %p\n", p, *p);
3797 } 3859 }
3798 }; 3860 };
3799 3861
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
4304 void ExternalStringTable::TearDown() { 4366 void ExternalStringTable::TearDown() {
4305 new_space_strings_.Free(); 4367 new_space_strings_.Free();
4306 old_space_strings_.Free(); 4368 old_space_strings_.Free();
4307 } 4369 }
4308 4370
4309 4371
4310 List<Object*> ExternalStringTable::new_space_strings_; 4372 List<Object*> ExternalStringTable::new_space_strings_;
4311 List<Object*> ExternalStringTable::old_space_strings_; 4373 List<Object*> ExternalStringTable::old_space_strings_;
4312 4374
4313 } } // namespace v8::internal 4375 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698