| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 mark_compact_collector_.SetFlags(flags); | 433 mark_compact_collector_.SetFlags(flags); |
| 434 CollectGarbage(OLD_POINTER_SPACE); | 434 CollectGarbage(OLD_POINTER_SPACE); |
| 435 mark_compact_collector_.SetFlags(kNoGCFlags); | 435 mark_compact_collector_.SetFlags(kNoGCFlags); |
| 436 } | 436 } |
| 437 | 437 |
| 438 | 438 |
| 439 void Heap::CollectAllAvailableGarbage() { | 439 void Heap::CollectAllAvailableGarbage() { |
| 440 // Since we are ignoring the return value, the exact choice of space does | 440 // Since we are ignoring the return value, the exact choice of space does |
| 441 // not matter, so long as we do not specify NEW_SPACE, which would not | 441 // not matter, so long as we do not specify NEW_SPACE, which would not |
| 442 // cause a full GC. | 442 // cause a full GC. |
| 443 mark_compact_collector()->SetFlags( | |
| 444 kMakeHeapIterableMask | kForceCompactionMask); | |
| 445 | |
| 446 // Major GC would invoke weak handle callbacks on weakly reachable | 443 // Major GC would invoke weak handle callbacks on weakly reachable |
| 447 // handles, but won't collect weakly reachable objects until next | 444 // handles, but won't collect weakly reachable objects until next |
| 448 // major GC. Therefore if we collect aggressively and weak handle callback | 445 // major GC. Therefore if we collect aggressively and weak handle callback |
| 449 // has been invoked, we rerun major GC to release objects which become | 446 // has been invoked, we rerun major GC to release objects which become |
| 450 // garbage. | 447 // garbage. |
| 451 // Note: as weak callbacks can execute arbitrary code, we cannot | 448 // Note: as weak callbacks can execute arbitrary code, we cannot |
| 452 // hope that eventually there will be no weak callbacks invocations. | 449 // hope that eventually there will be no weak callbacks invocations. |
| 453 // Therefore stop recollecting after several attempts. | 450 // Therefore stop recollecting after several attempts. |
| 451 mark_compact_collector()->SetFlags(kMakeHeapIterableMask); |
| 454 const int kMaxNumberOfAttempts = 7; | 452 const int kMaxNumberOfAttempts = 7; |
| 455 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { | 453 for (int attempt = 0; attempt < kMaxNumberOfAttempts; attempt++) { |
| 456 if (!CollectGarbage(OLD_POINTER_SPACE, MARK_COMPACTOR)) { | 454 if (!CollectGarbage(OLD_POINTER_SPACE, MARK_COMPACTOR)) { |
| 457 break; | 455 break; |
| 458 } | 456 } |
| 459 } | 457 } |
| 460 mark_compact_collector()->SetFlags(kNoGCFlags); | 458 mark_compact_collector()->SetFlags(kNoGCFlags); |
| 461 } | 459 } |
| 462 | 460 |
| 463 | 461 |
| (...skipping 3710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4174 // Before doing the mark-sweep collections we clear the | 4172 // Before doing the mark-sweep collections we clear the |
| 4175 // compilation cache to avoid hanging on to source code and | 4173 // compilation cache to avoid hanging on to source code and |
| 4176 // generated code for cached functions. | 4174 // generated code for cached functions. |
| 4177 isolate_->compilation_cache()->Clear(); | 4175 isolate_->compilation_cache()->Clear(); |
| 4178 | 4176 |
| 4179 CollectAllGarbage(kNoGCFlags); | 4177 CollectAllGarbage(kNoGCFlags); |
| 4180 new_space_.Shrink(); | 4178 new_space_.Shrink(); |
| 4181 last_idle_notification_gc_count_ = gc_count_; | 4179 last_idle_notification_gc_count_ = gc_count_; |
| 4182 | 4180 |
| 4183 } else if (number_idle_notifications_ == kIdlesBeforeMarkCompact) { | 4181 } else if (number_idle_notifications_ == kIdlesBeforeMarkCompact) { |
| 4184 CollectAllGarbage(kForceCompactionMask); | 4182 CollectAllGarbage(kNoGCFlags); |
| 4185 new_space_.Shrink(); | 4183 new_space_.Shrink(); |
| 4186 last_idle_notification_gc_count_ = gc_count_; | 4184 last_idle_notification_gc_count_ = gc_count_; |
| 4187 number_idle_notifications_ = 0; | 4185 number_idle_notifications_ = 0; |
| 4188 finished = true; | 4186 finished = true; |
| 4189 } else if (contexts_disposed_ > 0) { | 4187 } else if (contexts_disposed_ > 0) { |
| 4190 if (FLAG_expose_gc) { | 4188 if (FLAG_expose_gc) { |
| 4191 contexts_disposed_ = 0; | 4189 contexts_disposed_ = 0; |
| 4192 } else { | 4190 } else { |
| 4193 HistogramTimerScope scope(isolate_->counters()->gc_context()); | 4191 HistogramTimerScope scope(isolate_->counters()->gc_context()); |
| 4194 CollectAllGarbage(kNoGCFlags); | 4192 CollectAllGarbage(kNoGCFlags); |
| (...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6076 } | 6074 } |
| 6077 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6075 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
| 6078 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6076 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
| 6079 next = chunk->next_chunk(); | 6077 next = chunk->next_chunk(); |
| 6080 isolate_->memory_allocator()->Free(chunk); | 6078 isolate_->memory_allocator()->Free(chunk); |
| 6081 } | 6079 } |
| 6082 chunks_queued_for_free_ = NULL; | 6080 chunks_queued_for_free_ = NULL; |
| 6083 } | 6081 } |
| 6084 | 6082 |
| 6085 } } // namespace v8::internal | 6083 } } // namespace v8::internal |
| OLD | NEW |