| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 // Double the new space after this many scavenge collections. | 91 // Double the new space after this many scavenge collections. |
| 92 int Heap::new_space_growth_limit_ = 8; | 92 int Heap::new_space_growth_limit_ = 8; |
| 93 int Heap::scavenge_count_ = 0; | 93 int Heap::scavenge_count_ = 0; |
| 94 Heap::HeapState Heap::gc_state_ = NOT_IN_GC; | 94 Heap::HeapState Heap::gc_state_ = NOT_IN_GC; |
| 95 | 95 |
| 96 int Heap::mc_count_ = 0; | 96 int Heap::mc_count_ = 0; |
| 97 int Heap::gc_count_ = 0; | 97 int Heap::gc_count_ = 0; |
| 98 | 98 |
| 99 int Heap::always_allocate_scope_depth_ = 0; | 99 int Heap::always_allocate_scope_depth_ = 0; |
| 100 bool Heap::context_disposed_pending_ = false; |
| 100 | 101 |
| 101 #ifdef DEBUG | 102 #ifdef DEBUG |
| 102 bool Heap::allocation_allowed_ = true; | 103 bool Heap::allocation_allowed_ = true; |
| 103 | 104 |
| 104 int Heap::allocation_timeout_ = 0; | 105 int Heap::allocation_timeout_ = 0; |
| 105 bool Heap::disallow_allocation_failure_ = false; | 106 bool Heap::disallow_allocation_failure_ = false; |
| 106 #endif // DEBUG | 107 #endif // DEBUG |
| 107 | 108 |
| 108 | 109 |
| 109 int Heap::Capacity() { | 110 int Heap::Capacity() { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 287 |
| 287 | 288 |
| 288 void Heap::CollectAllGarbage() { | 289 void Heap::CollectAllGarbage() { |
| 289 // Since we are ignoring the return value, the exact choice of space does | 290 // Since we are ignoring the return value, the exact choice of space does |
| 290 // not matter, so long as we do not specify NEW_SPACE, which would not | 291 // not matter, so long as we do not specify NEW_SPACE, which would not |
| 291 // cause a full GC. | 292 // cause a full GC. |
| 292 CollectGarbage(0, OLD_POINTER_SPACE); | 293 CollectGarbage(0, OLD_POINTER_SPACE); |
| 293 } | 294 } |
| 294 | 295 |
| 295 | 296 |
| 297 void Heap::CollectAllGarbageIfContextDisposed() { |
| 298 if (context_disposed_pending_) { |
| 299 StatsRateScope scope(&Counters::gc_context); |
| 300 CollectAllGarbage(); |
| 301 context_disposed_pending_ = false; |
| 302 } |
| 303 } |
| 304 |
| 305 |
| 306 void Heap::NotifyContextDisposed() { |
| 307 context_disposed_pending_ = true; |
| 308 } |
| 309 |
| 310 |
| 296 bool Heap::CollectGarbage(int requested_size, AllocationSpace space) { | 311 bool Heap::CollectGarbage(int requested_size, AllocationSpace space) { |
| 297 // The VM is in the GC state until exiting this function. | 312 // The VM is in the GC state until exiting this function. |
| 298 VMState state(GC); | 313 VMState state(GC); |
| 299 | 314 |
| 300 #ifdef DEBUG | 315 #ifdef DEBUG |
| 301 // Reset the allocation timeout to the GC interval, but make sure to | 316 // Reset the allocation timeout to the GC interval, but make sure to |
| 302 // allow at least a few allocations after a collection. The reason | 317 // allow at least a few allocations after a collection. The reason |
| 303 // for this is that we have a lot of allocation sequences and we | 318 // for this is that we have a lot of allocation sequences and we |
| 304 // assume that a garbage collection will allow the subsequent | 319 // assume that a garbage collection will allow the subsequent |
| 305 // allocation attempts to go through. | 320 // allocation attempts to go through. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 440 |
| 426 MarkCompactEpilogue(); | 441 MarkCompactEpilogue(); |
| 427 | 442 |
| 428 LOG(ResourceEvent("markcompact", "end")); | 443 LOG(ResourceEvent("markcompact", "end")); |
| 429 | 444 |
| 430 gc_state_ = NOT_IN_GC; | 445 gc_state_ = NOT_IN_GC; |
| 431 | 446 |
| 432 Shrink(); | 447 Shrink(); |
| 433 | 448 |
| 434 Counters::objs_since_last_full.Set(0); | 449 Counters::objs_since_last_full.Set(0); |
| 450 context_disposed_pending_ = false; |
| 435 } | 451 } |
| 436 | 452 |
| 437 | 453 |
| 438 void Heap::MarkCompactPrologue() { | 454 void Heap::MarkCompactPrologue() { |
| 439 ClearKeyedLookupCache(); | 455 ClearKeyedLookupCache(); |
| 440 CompilationCache::MarkCompactPrologue(); | 456 CompilationCache::MarkCompactPrologue(); |
| 441 RegExpImpl::OldSpaceCollectionPrologue(); | 457 RegExpImpl::OldSpaceCollectionPrologue(); |
| 442 Top::MarkCompactPrologue(); | 458 Top::MarkCompactPrologue(); |
| 443 ThreadManager::MarkCompactPrologue(); | 459 ThreadManager::MarkCompactPrologue(); |
| 444 } | 460 } |
| (...skipping 2855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3300 #ifdef DEBUG | 3316 #ifdef DEBUG |
| 3301 bool Heap::GarbageCollectionGreedyCheck() { | 3317 bool Heap::GarbageCollectionGreedyCheck() { |
| 3302 ASSERT(FLAG_gc_greedy); | 3318 ASSERT(FLAG_gc_greedy); |
| 3303 if (Bootstrapper::IsActive()) return true; | 3319 if (Bootstrapper::IsActive()) return true; |
| 3304 if (disallow_allocation_failure()) return true; | 3320 if (disallow_allocation_failure()) return true; |
| 3305 return CollectGarbage(0, NEW_SPACE); | 3321 return CollectGarbage(0, NEW_SPACE); |
| 3306 } | 3322 } |
| 3307 #endif | 3323 #endif |
| 3308 | 3324 |
| 3309 } } // namespace v8::internal | 3325 } } // namespace v8::internal |
| OLD | NEW |