| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 enum GCReason { | 198 enum GCReason { |
| 199 IdleGC, | 199 IdleGC, |
| 200 PreciseGC, | 200 PreciseGC, |
| 201 ConservativeGC, | 201 ConservativeGC, |
| 202 ForcedGC, | 202 ForcedGC, |
| 203 MemoryPressureGC, | 203 MemoryPressureGC, |
| 204 PageNavigationGC, | 204 PageNavigationGC, |
| 205 NumberOfGCReason, | 205 NumberOfGCReason, |
| 206 }; | 206 }; |
| 207 static const char* gcReasonString(GCReason); | 207 static const char* gcReasonString(GCReason); |
| 208 static void collectGarbage(ThreadState::StackState, ThreadState::GCType, GCR
eason); | 208 static void collectGarbage(BlinkGC::StackState, BlinkGC::GCType, GCReason); |
| 209 static void collectGarbageForTerminatingThread(ThreadState*); | 209 static void collectGarbageForTerminatingThread(ThreadState*); |
| 210 static void collectAllGarbage(); | 210 static void collectAllGarbage(); |
| 211 | 211 |
| 212 static void processMarkingStack(Visitor*); | 212 static void processMarkingStack(Visitor*); |
| 213 static void postMarkingProcessing(Visitor*); | 213 static void postMarkingProcessing(Visitor*); |
| 214 static void globalWeakProcessing(Visitor*); | 214 static void globalWeakProcessing(Visitor*); |
| 215 static void setForcePreciseGCForTesting(); | 215 static void setForcePreciseGCForTesting(); |
| 216 | 216 |
| 217 static void preGC(); | 217 static void preGC(); |
| 218 static void postGC(ThreadState::GCType); | 218 static void postGC(BlinkGC::GCType); |
| 219 | 219 |
| 220 // Conservatively checks whether an address is a pointer in any of the | 220 // Conservatively checks whether an address is a pointer in any of the |
| 221 // thread heaps. If so marks the object pointed to as live. | 221 // thread heaps. If so marks the object pointed to as live. |
| 222 static Address checkAndMarkPointer(Visitor*, Address); | 222 static Address checkAndMarkPointer(Visitor*, Address); |
| 223 | 223 |
| 224 #if ENABLE(GC_PROFILING) | 224 #if ENABLE(GC_PROFILING) |
| 225 // Dump the path to specified object on the next GC. This method is to be | 225 // Dump the path to specified object on the next GC. This method is to be |
| 226 // invoked from GDB. | 226 // invoked from GDB. |
| 227 static void dumpPathToObjectOnNextGC(void* p); | 227 static void dumpPathToObjectOnNextGC(void* p); |
| 228 | 228 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 // sweeping kicks in for their heap and page. The EAGERLY_FINALIZE() | 404 // sweeping kicks in for their heap and page. The EAGERLY_FINALIZE() |
| 405 // macro is used to declare a class (and its derived classes) as being | 405 // macro is used to declare a class (and its derived classes) as being |
| 406 // in need of eager finalization. Must be defined with 'public' visibility | 406 // in need of eager finalization. Must be defined with 'public' visibility |
| 407 // for a class. | 407 // for a class. |
| 408 // | 408 // |
| 409 | 409 |
| 410 inline int Heap::heapIndexForObjectSize(size_t size) | 410 inline int Heap::heapIndexForObjectSize(size_t size) |
| 411 { | 411 { |
| 412 if (size < 64) { | 412 if (size < 64) { |
| 413 if (size < 32) | 413 if (size < 32) |
| 414 return ThreadState::NormalPage1HeapIndex; | 414 return BlinkGC::NormalPage1HeapIndex; |
| 415 return ThreadState::NormalPage2HeapIndex; | 415 return BlinkGC::NormalPage2HeapIndex; |
| 416 } | 416 } |
| 417 if (size < 128) | 417 if (size < 128) |
| 418 return ThreadState::NormalPage3HeapIndex; | 418 return BlinkGC::NormalPage3HeapIndex; |
| 419 return ThreadState::NormalPage4HeapIndex; | 419 return BlinkGC::NormalPage4HeapIndex; |
| 420 } | 420 } |
| 421 | 421 |
| 422 inline bool Heap::isNormalHeapIndex(int index) | 422 inline bool Heap::isNormalHeapIndex(int index) |
| 423 { | 423 { |
| 424 return index >= ThreadState::NormalPage1HeapIndex && index <= ThreadState::N
ormalPage4HeapIndex; | 424 return index >= BlinkGC::NormalPage1HeapIndex && index <= BlinkGC::NormalPag
e4HeapIndex; |
| 425 } | 425 } |
| 426 | 426 |
| 427 #define DECLARE_EAGER_FINALIZATION_OPERATOR_NEW() \ | 427 #define DECLARE_EAGER_FINALIZATION_OPERATOR_NEW() \ |
| 428 public: \ | 428 public: \ |
| 429 GC_PLUGIN_IGNORE("491488") \ | 429 GC_PLUGIN_IGNORE("491488") \ |
| 430 void* operator new(size_t size) \ | 430 void* operator new(size_t size) \ |
| 431 { \ | 431 { \ |
| 432 return allocateObject(size, true); \ | 432 return allocateObject(size, true); \ |
| 433 } | 433 } |
| 434 | 434 |
| 435 #define IS_EAGERLY_FINALIZED() (pageFromObject(this)->heap()->heapIndex() == Thr
eadState::EagerSweepHeapIndex) | 435 #define IS_EAGERLY_FINALIZED() (pageFromObject(this)->heap()->heapIndex() == Bli
nkGC::EagerSweepHeapIndex) |
| 436 #if ENABLE(ASSERT) && ENABLE(OILPAN) | 436 #if ENABLE(ASSERT) && ENABLE(OILPAN) |
| 437 class VerifyEagerFinalization { | 437 class VerifyEagerFinalization { |
| 438 public: | 438 public: |
| 439 ~VerifyEagerFinalization() | 439 ~VerifyEagerFinalization() |
| 440 { | 440 { |
| 441 // If this assert triggers, the class annotated as eagerly | 441 // If this assert triggers, the class annotated as eagerly |
| 442 // finalized ended up not being allocated on the heap | 442 // finalized ended up not being allocated on the heap |
| 443 // set aside for eager finalization. The reason is most | 443 // set aside for eager finalization. The reason is most |
| 444 // likely that the effective 'operator new' overload for | 444 // likely that the effective 'operator new' overload for |
| 445 // this class' leftmost base is for a class that is not | 445 // this class' leftmost base is for a class that is not |
| (...skipping 14 matching lines...) Expand all Loading... |
| 460 | 460 |
| 461 #if !ENABLE(OILPAN) | 461 #if !ENABLE(OILPAN) |
| 462 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() EAGERLY_FINALIZE() | 462 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() EAGERLY_FINALIZE() |
| 463 #else | 463 #else |
| 464 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() | 464 #define EAGERLY_FINALIZE_WILL_BE_REMOVED() |
| 465 #endif | 465 #endif |
| 466 | 466 |
| 467 inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he
apIndex, size_t gcInfoIndex) | 467 inline Address Heap::allocateOnHeapIndex(ThreadState* state, size_t size, int he
apIndex, size_t gcInfoIndex) |
| 468 { | 468 { |
| 469 ASSERT(state->isAllocationAllowed()); | 469 ASSERT(state->isAllocationAllowed()); |
| 470 ASSERT(heapIndex != ThreadState::LargeObjectHeapIndex); | 470 ASSERT(heapIndex != BlinkGC::LargeObjectHeapIndex); |
| 471 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex)); | 471 NormalPageHeap* heap = static_cast<NormalPageHeap*>(state->heap(heapIndex)); |
| 472 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex); | 472 return heap->allocateObject(allocationSizeFromSize(size), gcInfoIndex); |
| 473 } | 473 } |
| 474 | 474 |
| 475 template<typename T> | 475 template<typename T> |
| 476 Address Heap::allocate(size_t size, bool eagerlySweep) | 476 Address Heap::allocate(size_t size, bool eagerlySweep) |
| 477 { | 477 { |
| 478 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 478 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
| 479 return Heap::allocateOnHeapIndex(state, size, eagerlySweep ? ThreadState::Ea
gerSweepHeapIndex : Heap::heapIndexForObjectSize(size), GCInfoTrait<T>::index())
; | 479 return Heap::allocateOnHeapIndex(state, size, eagerlySweep ? BlinkGC::EagerS
weepHeapIndex : Heap::heapIndexForObjectSize(size), GCInfoTrait<T>::index()); |
| 480 } | 480 } |
| 481 | 481 |
| 482 template<typename T> | 482 template<typename T> |
| 483 Address Heap::reallocate(void* previous, size_t size) | 483 Address Heap::reallocate(void* previous, size_t size) |
| 484 { | 484 { |
| 485 // Not intended to be a full C realloc() substitute; | 485 // Not intended to be a full C realloc() substitute; |
| 486 // realloc(nullptr, size) is not a supported alias for malloc(size). | 486 // realloc(nullptr, size) is not a supported alias for malloc(size). |
| 487 | 487 |
| 488 // TODO(sof): promptly free the previous object. | 488 // TODO(sof): promptly free the previous object. |
| 489 if (!size) { | 489 if (!size) { |
| 490 // If the new size is 0 this is considered equivalent to free(previous). | 490 // If the new size is 0 this is considered equivalent to free(previous). |
| 491 return nullptr; | 491 return nullptr; |
| 492 } | 492 } |
| 493 | 493 |
| 494 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 494 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
| 495 HeapObjectHeader* previousHeader = HeapObjectHeader::fromPayload(previous); | 495 HeapObjectHeader* previousHeader = HeapObjectHeader::fromPayload(previous); |
| 496 BasePage* page = pageFromObject(previousHeader); | 496 BasePage* page = pageFromObject(previousHeader); |
| 497 ASSERT(page); | 497 ASSERT(page); |
| 498 int heapIndex = page->heap()->heapIndex(); | 498 int heapIndex = page->heap()->heapIndex(); |
| 499 // Recompute the effective heap index if previous allocation | 499 // Recompute the effective heap index if previous allocation |
| 500 // was on the normal heaps or a large object. | 500 // was on the normal heaps or a large object. |
| 501 if (isNormalHeapIndex(heapIndex) || heapIndex == ThreadState::LargeObjectHea
pIndex) | 501 if (isNormalHeapIndex(heapIndex) || heapIndex == BlinkGC::LargeObjectHeapInd
ex) |
| 502 heapIndex = heapIndexForObjectSize(size); | 502 heapIndex = heapIndexForObjectSize(size); |
| 503 | 503 |
| 504 // TODO(haraken): We don't support reallocate() for finalizable objects. | 504 // TODO(haraken): We don't support reallocate() for finalizable objects. |
| 505 ASSERT(!Heap::gcInfo(previousHeader->gcInfoIndex())->hasFinalizer()); | 505 ASSERT(!Heap::gcInfo(previousHeader->gcInfoIndex())->hasFinalizer()); |
| 506 ASSERT(previousHeader->gcInfoIndex() == GCInfoTrait<T>::index()); | 506 ASSERT(previousHeader->gcInfoIndex() == GCInfoTrait<T>::index()); |
| 507 Address address = Heap::allocateOnHeapIndex(state, size, heapIndex, GCInfoTr
ait<T>::index()); | 507 Address address = Heap::allocateOnHeapIndex(state, size, heapIndex, GCInfoTr
ait<T>::index()); |
| 508 size_t copySize = previousHeader->payloadSize(); | 508 size_t copySize = previousHeader->payloadSize(); |
| 509 if (copySize > size) | 509 if (copySize > size) |
| 510 copySize = size; | 510 copySize = size; |
| 511 memcpy(address, previous, copySize); | 511 memcpy(address, previous, copySize); |
| 512 return address; | 512 return address; |
| 513 } | 513 } |
| 514 | 514 |
| 515 template<typename Derived> | 515 template<typename Derived> |
| 516 template<typename T> | 516 template<typename T> |
| 517 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) | 517 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) |
| 518 { | 518 { |
| 519 T** cell = reinterpret_cast<T**>(object); | 519 T** cell = reinterpret_cast<T**>(object); |
| 520 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) | 520 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) |
| 521 *cell = nullptr; | 521 *cell = nullptr; |
| 522 } | 522 } |
| 523 | 523 |
| 524 } // namespace blink | 524 } // namespace blink |
| 525 | 525 |
| 526 #endif // Heap_h | 526 #endif // Heap_h |
| OLD | NEW |