| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 449 } |
| 450 void leaveGCForbiddenScopeIfNeeded(GarbageCollectedMixinConstructorMarker* g
cMixinMarker) | 450 void leaveGCForbiddenScopeIfNeeded(GarbageCollectedMixinConstructorMarker* g
cMixinMarker) |
| 451 { | 451 { |
| 452 ASSERT(checkThread()); | 452 ASSERT(checkThread()); |
| 453 if (m_gcMixinMarker == gcMixinMarker) { | 453 if (m_gcMixinMarker == gcMixinMarker) { |
| 454 leaveGCForbiddenScope(); | 454 leaveGCForbiddenScope(); |
| 455 m_gcMixinMarker = nullptr; | 455 m_gcMixinMarker = nullptr; |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 // vectorBackingArena() returns a heap that the vector allocation should use
. | 459 // vectorBackingArena() returns an arena that the vector allocation should u
se. |
| 460 // We have four vector arenas and want to choose the best heap here. | 460 // We have four vector arenas and want to choose the best arena here. |
| 461 // | 461 // |
| 462 // The goal is to improve the succession rate where expand and | 462 // The goal is to improve the succession rate where expand and |
| 463 // promptlyFree happen at an allocation point. This is a key for reusing | 463 // promptlyFree happen at an allocation point. This is a key for reusing |
| 464 // the same memory as much as possible and thus improves performance. | 464 // the same memory as much as possible and thus improves performance. |
| 465 // To achieve the goal, we use the following heuristics: | 465 // To achieve the goal, we use the following heuristics: |
| 466 // | 466 // |
| 467 // - A vector that has been expanded recently is likely to be expanded | 467 // - A vector that has been expanded recently is likely to be expanded |
| 468 // again soon. | 468 // again soon. |
| 469 // - A vector is likely to be promptly freed if the same type of vector | 469 // - A vector is likely to be promptly freed if the same type of vector |
| 470 // has been frequently promptly freed in the past. | 470 // has been frequently promptly freed in the past. |
| 471 // - Given the above, when allocating a new vector, look at the four vectors | 471 // - Given the above, when allocating a new vector, look at the four vectors |
| 472 // that are placed immediately prior to the allocation point of each heap. | 472 // that are placed immediately prior to the allocation point of each arena
. |
| 473 // Choose the heap where the vector is least likely to be expanded | 473 // Choose the arena where the vector is least likely to be expanded |
| 474 // nor promptly freed. | 474 // nor promptly freed. |
| 475 // | 475 // |
| 476 // To implement the heuristics, we add a arenaAge to each heap. The arenaAge | 476 // To implement the heuristics, we add an arenaAge to each arena. The arenaA
ge |
| 477 // is updated if: | 477 // is updated if: |
| 478 // | 478 // |
| 479 // - a vector on the heap is expanded; or | 479 // - a vector on the arena is expanded; or |
| 480 // - a vector that meets the condition (*) is allocated on the heap | 480 // - a vector that meets the condition (*) is allocated on the arena |
| 481 // | 481 // |
| 482 // (*) More than 33% of the same type of vectors have been promptly | 482 // (*) More than 33% of the same type of vectors have been promptly |
| 483 // freed since the last GC. | 483 // freed since the last GC. |
| 484 // | 484 // |
| 485 BaseArena* vectorBackingArena(size_t gcInfoIndex) | 485 BaseArena* vectorBackingArena(size_t gcInfoIndex) |
| 486 { | 486 { |
| 487 ASSERT(checkThread()); | 487 ASSERT(checkThread()); |
| 488 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; | 488 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; |
| 489 --m_likelyToBePromptlyFreed[entryIndex]; | 489 --m_likelyToBePromptlyFreed[entryIndex]; |
| 490 int arenaIndex = m_vectorBackingArenaIndex; | 490 int arenaIndex = m_vectorBackingArenaIndex; |
| 491 // If m_likelyToBePromptlyFreed[entryIndex] > 0, that means that | 491 // If m_likelyToBePromptlyFreed[entryIndex] > 0, that means that |
| 492 // more than 33% of vectors of the type have been promptly freed | 492 // more than 33% of vectors of the type have been promptly freed |
| 493 // since the last GC. | 493 // since the last GC. |
| 494 if (m_likelyToBePromptlyFreed[entryIndex] > 0) { | 494 if (m_likelyToBePromptlyFreed[entryIndex] > 0) { |
| 495 m_arenaAges[arenaIndex] = ++m_currentArenaAges; | 495 m_arenaAges[arenaIndex] = ++m_currentArenaAges; |
| 496 m_vectorBackingArenaIndex = arenaIndexOfVectorArenaLeastRecentlyExpa
nded(BlinkGC::Vector1ArenaIndex, BlinkGC::Vector4ArenaIndex); | 496 m_vectorBackingArenaIndex = arenaIndexOfVectorArenaLeastRecentlyExpa
nded(BlinkGC::Vector1ArenaIndex, BlinkGC::Vector4ArenaIndex); |
| 497 } | 497 } |
| 498 ASSERT(isVectorArenaIndex(arenaIndex)); | 498 ASSERT(isVectorArenaIndex(arenaIndex)); |
| 499 return m_arenas[arenaIndex]; | 499 return m_arenas[arenaIndex]; |
| 500 } | 500 } |
| 501 BaseArena* expandedVectorBackingHeap(size_t gcInfoIndex); | 501 BaseArena* expandedVectorBackingArena(size_t gcInfoIndex); |
| 502 static bool isVectorArenaIndex(int arenaIndex) | 502 static bool isVectorArenaIndex(int arenaIndex) |
| 503 { | 503 { |
| 504 return BlinkGC::Vector1ArenaIndex <= arenaIndex && arenaIndex <= BlinkGC
::Vector4ArenaIndex; | 504 return BlinkGC::Vector1ArenaIndex <= arenaIndex && arenaIndex <= BlinkGC
::Vector4ArenaIndex; |
| 505 } | 505 } |
| 506 void allocationPointAdjusted(int arenaIndex); | 506 void allocationPointAdjusted(int arenaIndex); |
| 507 void promptlyFreed(size_t gcInfoIndex); | 507 void promptlyFreed(size_t gcInfoIndex); |
| 508 | 508 |
| 509 void accumulateSweepingTime(double time) { m_accumulatedSweepingTime += time
; } | 509 void accumulateSweepingTime(double time) { m_accumulatedSweepingTime += time
; } |
| 510 | 510 |
| 511 #if OS(WIN) && COMPILER(MSVC) | 511 #if OS(WIN) && COMPILER(MSVC) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 | 707 |
| 708 template<> class ThreadStateFor<AnyThread> { | 708 template<> class ThreadStateFor<AnyThread> { |
| 709 STATIC_ONLY(ThreadStateFor); | 709 STATIC_ONLY(ThreadStateFor); |
| 710 public: | 710 public: |
| 711 static ThreadState* state() { return ThreadState::current(); } | 711 static ThreadState* state() { return ThreadState::current(); } |
| 712 }; | 712 }; |
| 713 | 713 |
| 714 } // namespace blink | 714 } // namespace blink |
| 715 | 715 |
| 716 #endif // ThreadState_h | 716 #endif // ThreadState_h |
| OLD | NEW |