Changeset 161615 in webkit for trunk/Source/JavaScriptCore/heap/Heap.cpp
- Timestamp:
- Jan 9, 2014, 6:28:27 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/heap/Heap.cpp
r161557 r161615 254 254 , m_minBytesPerCycle(minHeapSize(m_heapType, m_ramSize)) 255 255 , m_sizeAfterLastCollect(0) 256 , m_bytesAllocatedLimit(m_minBytesPerCycle) 257 , m_bytesAllocated(0) 258 , m_bytesAbandoned(0) 256 , m_bytesAllocatedThisCycle(0) 257 , m_bytesAbandonedThisCycle(0) 258 , m_maxEdenSize(m_minBytesPerCycle) 259 , m_maxHeapSize(m_minBytesPerCycle) 260 , m_shouldDoFullCollection(false) 259 261 , m_totalBytesVisited(0) 260 262 , m_totalBytesCopied(0) … … 270 272 , m_handleSet(vm) 271 273 , m_isSafeToCollect(false) 272 , m_writeBarrierBuffer( 128)274 , m_writeBarrierBuffer(256) 273 275 , m_vm(vm) 274 276 , m_lastGCLength(0) … … 333 335 { 334 336 if (m_activityCallback) 335 m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);336 m_bytesAbandoned += bytes;337 m_activityCallback->didAllocate(m_bytesAllocatedThisCycle + m_bytesAbandonedThisCycle); 338 m_bytesAbandonedThisCycle += bytes; 337 339 } 338 340 … … 487 489 visitor.setup(); 488 490 HeapRootVisitor heapRootVisitor(visitor); 491 492 Vector<const JSCell*> rememberedSet(m_slotVisitor.markStack().size()); 493 m_slotVisitor.markStack().fillVector(rememberedSet); 489 494 490 495 { … … 591 596 } 592 597 598 { 599 GCPHASE(ClearRememberedSet); 600 for (unsigned i = 0; i < rememberedSet.size(); ++i) { 601 const JSCell* cell = rememberedSet[i]; 602 MarkedBlock::blockFor(cell)->clearRemembered(cell); 603 } 604 } 605 593 606 GCCOUNTER(VisitedValueCount, visitor.visitCount()); 594 607 … … 602 615 #endif 603 616 604 m_totalBytesVisited = visitor.bytesVisited(); 605 m_totalBytesCopied = visitor.bytesCopied(); 617 if (m_operationInProgress == EdenCollection) { 618 m_totalBytesVisited += visitor.bytesVisited(); 619 m_totalBytesCopied += visitor.bytesCopied(); 620 } else { 621 ASSERT(m_operationInProgress == FullCollection); 622 m_totalBytesVisited = visitor.bytesVisited(); 623 m_totalBytesCopied = visitor.bytesCopied(); 624 } 606 625 #if ENABLE(PARALLEL_GC) 607 626 m_totalBytesVisited += m_sharedData.childBytesVisited(); … … 616 635 } 617 636 637 template <HeapOperation collectionType> 618 638 void Heap::copyBackingStores() 619 639 { 640 if (collectionType == EdenCollection) 641 return; 642 620 643 m_storageSpace.startedCopying(); 621 644 if (m_storageSpace.shouldDoCopyPhase()) { … … 628 651 m_storageSpace.doneCopying(); 629 652 m_sharedData.didFinishCopying(); 630 } else 653 } else 631 654 m_storageSpace.doneCopying(); 632 655 } … … 724 747 } 725 748 749 void Heap::addToRememberedSet(const JSCell* cell) 750 { 751 ASSERT(cell); 752 ASSERT(!Options::enableConcurrentJIT() || !isCompilationThread()); 753 if (isInRememberedSet(cell)) 754 return; 755 MarkedBlock::blockFor(cell)->setRemembered(cell); 756 m_slotVisitor.unconditionallyAppend(const_cast<JSCell*>(cell)); 757 } 758 726 759 void Heap::collectAllGarbage() 727 760 { … … 729 762 return; 730 763 764 m_shouldDoFullCollection = true; 731 765 collect(); 732 766 … … 765 799 m_vm->prepareToDiscardCode(); 766 800 } 767 768 m_operationInProgress = Collection; 769 m_extraMemoryUsage = 0; 801 802 bool isFullCollection = m_shouldDoFullCollection; 803 if (isFullCollection) { 804 m_operationInProgress = FullCollection; 805 m_slotVisitor.clearMarkStack(); 806 m_shouldDoFullCollection = false; 807 if (Options::logGC()) 808 dataLog("FullCollection, "); 809 } else { 810 #if ENABLE(GGC) 811 m_operationInProgress = EdenCollection; 812 if (Options::logGC()) 813 dataLog("EdenCollection, "); 814 #else 815 m_operationInProgress = FullCollection; 816 m_slotVisitor.clearMarkStack(); 817 if (Options::logGC()) 818 dataLog("FullCollection, "); 819 #endif 820 } 821 if (m_operationInProgress == FullCollection) 822 m_extraMemoryUsage = 0; 770 823 771 824 if (m_activityCallback) … … 781 834 GCPHASE(StopAllocation); 782 835 m_objectSpace.stopAllocating(); 836 if (m_operationInProgress == FullCollection) 837 m_storageSpace.didStartFullCollection(); 838 } 839 840 { 841 GCPHASE(FlushWriteBarrierBuffer); 842 if (m_operationInProgress == EdenCollection) 843 m_writeBarrierBuffer.flush(*this); 844 else 845 m_writeBarrierBuffer.reset(); 783 846 } 784 847 … … 797 860 } 798 861 799 {862 if (m_operationInProgress == FullCollection) { 800 863 m_blockSnapshot.resize(m_objectSpace.blocks().set().size()); 801 864 MarkedBlockSnapshotFunctor functor(m_blockSnapshot); … … 803 866 } 804 867 805 copyBackingStores(); 868 if (m_operationInProgress == FullCollection) 869 copyBackingStores<FullCollection>(); 870 else 871 copyBackingStores<EdenCollection>(); 806 872 807 873 { … … 820 886 } 821 887 822 m_sweeper->startSweeping(m_blockSnapshot); 823 m_bytesAbandoned = 0; 888 if (m_operationInProgress == FullCollection) 889 m_sweeper->startSweeping(m_blockSnapshot); 890 891 { 892 GCPHASE(AddCurrentlyExecutingCodeBlocksToRememberedSet); 893 m_codeBlocks.rememberCurrentlyExecutingCodeBlocks(this); 894 } 895 896 m_bytesAbandonedThisCycle = 0; 824 897 825 898 { … … 832 905 HeapStatistics::exitWithFailure(); 833 906 907 if (m_operationInProgress == FullCollection) { 908 // To avoid pathological GC churn in very small and very large heaps, we set 909 // the new allocation limit based on the current size of the heap, with a 910 // fixed minimum. 911 m_maxHeapSize = max(minHeapSize(m_heapType, m_ramSize), proportionalHeapSize(currentHeapSize, m_ramSize)); 912 m_maxEdenSize = m_maxHeapSize - currentHeapSize; 913 } else { 914 ASSERT(currentHeapSize >= m_sizeAfterLastCollect); 915 m_maxEdenSize = m_maxHeapSize - currentHeapSize; 916 double edenToOldGenerationRatio = (double)m_maxEdenSize / (double)m_maxHeapSize; 917 double minEdenToOldGenerationRatio = 1.0 / 3.0; 918 if (edenToOldGenerationRatio < minEdenToOldGenerationRatio) 919 m_shouldDoFullCollection = true; 920 m_maxHeapSize += currentHeapSize - m_sizeAfterLastCollect; 921 m_maxEdenSize = m_maxHeapSize - currentHeapSize; 922 } 923 834 924 m_sizeAfterLastCollect = currentHeapSize; 835 925 836 // To avoid pathological GC churn in very small and very large heaps, we set 837 // the new allocation limit based on the current size of the heap, with a 838 // fixed minimum. 839 size_t maxHeapSize = max(minHeapSize(m_heapType, m_ramSize), proportionalHeapSize(currentHeapSize, m_ramSize)); 840 m_bytesAllocatedLimit = maxHeapSize - currentHeapSize; 841 842 m_bytesAllocated = 0; 926 m_bytesAllocatedThisCycle = 0; 843 927 double lastGCEndTime = WTF::monotonicallyIncreasingTime(); 844 928 m_lastGCLength = lastGCEndTime - lastGCStartTime; … … 846 930 if (Options::recordGCPauseTimes()) 847 931 HeapStatistics::recordGCPauseTime(lastGCStartTime, lastGCEndTime); 848 RELEASE_ASSERT(m_operationInProgress == Collection);932 RELEASE_ASSERT(m_operationInProgress == EdenCollection || m_operationInProgress == FullCollection); 849 933 850 934 m_operationInProgress = NoOperation; … … 864 948 dataLog(after - before, " ms, ", currentHeapSize / 1024, " kb]\n"); 865 949 } 866 867 #if ENABLE(ALLOCATION_LOGGING)868 dataLogF("JSC GC finishing collection.\n");869 #endif870 950 } 871 951 … … 917 997 { 918 998 if (m_activityCallback) 919 m_activityCallback->didAllocate(m_bytesAllocated + m_bytesAbandoned);920 m_bytesAllocated += bytes;999 m_activityCallback->didAllocate(m_bytesAllocatedThisCycle + m_bytesAbandonedThisCycle); 1000 m_bytesAllocatedThisCycle += bytes; 921 1001 } 922 1002 … … 993 1073 decrementDeferralDepth(); 994 1074 collectIfNecessaryOrDefer(); 1075 } 1076 1077 void Heap::writeBarrier(const JSCell* from) 1078 { 1079 ASSERT_GC_OBJECT_LOOKS_VALID(const_cast<JSCell*>(from)); 1080 if (!from || !isMarked(from)) 1081 return; 1082 Heap* heap = Heap::heap(from); 1083 heap->addToRememberedSet(from); 995 1084 } 996 1085
Note:
See TracChangeset
for help on using the changeset viewer.