Changeset 20004 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- Mar 6, 2007, 8:25:49 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r19994 r20004 109 109 static CollectorHeap heap = {NULL, 0, 0, 0, NULL, 0, 0, 0, 0}; 110 110 111 size_t Collector::mainThreadOnlyObjectCount = 0; 111 112 bool Collector::memoryFull = false; 112 113 … … 474 475 } 475 476 477 void Collector::collectOnMainThreadOnly(JSValue* value) 478 { 479 ASSERT(value); 480 ASSERT(JSLock::lockCount() > 0); 481 482 if (JSImmediate::isImmediate(value)) 483 return; 484 485 JSCell* cell = value->downcast(); 486 cell->m_collectOnMainThreadOnly = true; 487 ++mainThreadOnlyObjectCount; 488 } 489 476 490 void Collector::markProtectedObjects() 477 491 { … … 485 499 } 486 500 501 void Collector::markMainThreadOnlyObjects() 502 { 503 ASSERT(!pthread_main_np()); 504 505 // Optimization for clients that never register "main thread only" objects. 506 if (!mainThreadOnlyObjectCount) 507 return; 508 509 // FIXME: We can optimize this marking algorithm by keeping an exact set of 510 // "main thread only" objects when the "main thread only" object count is 511 // small. We don't want to keep an exact set all the time, because WebCore 512 // tends to create lots of "main thread only" objects, and all that set 513 // thrashing can be expensive. 514 515 size_t count = 0; 516 517 for (size_t block = 0; block < heap.usedBlocks; block++) { 518 ASSERT(count < mainThreadOnlyObjectCount); 519 520 CollectorBlock* curBlock = heap.blocks[block]; 521 size_t minimumCellsToProcess = curBlock->usedCells; 522 for (size_t i = 0; (i < minimumCellsToProcess) & (i < CELLS_PER_BLOCK); i++) { 523 CollectorCell* cell = curBlock->cells + i; 524 if (cell->u.freeCell.zeroIfFree == 0) 525 ++minimumCellsToProcess; 526 else { 527 JSCell* imp = reinterpret_cast<JSCell*>(cell); 528 if (imp->m_collectOnMainThreadOnly) { 529 if(!imp->marked()) 530 imp->mark(); 531 if (++count == mainThreadOnlyObjectCount) 532 return; 533 } 534 } 535 } 536 } 537 538 for (size_t cell = 0; cell < heap.usedOversizeCells; cell++) { 539 ASSERT(count < mainThreadOnlyObjectCount); 540 541 JSCell* imp = reinterpret_cast<JSCell*>(heap.oversizeCells[cell]); 542 if (imp->m_collectOnMainThreadOnly) { 543 if (!imp->marked()) 544 imp->mark(); 545 if (++count == mainThreadOnlyObjectCount) 546 return; 547 } 548 } 549 } 550 487 551 bool Collector::collect() 488 552 { … … 502 566 Interpreter* scr = Interpreter::s_hook; 503 567 do { 504 scr->mark( currentThreadIsMainThread);568 scr->mark(); 505 569 scr = scr->next; 506 570 } while (scr != Interpreter::s_hook); … … 512 576 markProtectedObjects(); 513 577 List::markProtectedLists(); 578 if (!currentThreadIsMainThread) 579 markMainThreadOnlyObjects(); 514 580 515 581 // SWEEP: delete everything with a zero refcount (garbage) and unmark everything else … … 531 597 if (imp->m_marked) { 532 598 imp->m_marked = false; 533 } else if (currentThreadIsMainThread || imp->m_destructorIsThreadSafe){599 } else { 534 600 // special case for allocated but uninitialized object 535 // (We don't need this check earlier because nothing prior this point assumes the object has a valid vptr.) 601 // (We don't need this check earlier because nothing prior this point 602 // assumes the object has a valid vptr.) 536 603 if (cell->u.freeCell.zeroIfFree == 0) 537 604 continue; 538 605 606 ASSERT(currentThreadIsMainThread || !imp->m_collectOnMainThreadOnly); 607 if (imp->m_collectOnMainThreadOnly) 608 --mainThreadOnlyObjectCount; 539 609 imp->~JSCell(); 540 610 --usedCells; … … 557 627 if (imp->m_marked) { 558 628 imp->m_marked = false; 559 } else if (currentThreadIsMainThread || imp->m_destructorIsThreadSafe) { 629 } else { 630 ASSERT(currentThreadIsMainThread || !imp->m_collectOnMainThreadOnly); 631 if (imp->m_collectOnMainThreadOnly) 632 --mainThreadOnlyObjectCount; 560 633 imp->~JSCell(); 561 634 --usedCells; … … 600 673 JSCell *imp = (JSCell *)heap.oversizeCells[cell]; 601 674 602 if (!imp->m_marked && (currentThreadIsMainThread || imp->m_destructorIsThreadSafe)) { 675 if (imp->m_marked) { 676 imp->m_marked = false; 677 cell++; 678 } else { 679 ASSERT(currentThreadIsMainThread || !imp->m_collectOnMainThreadOnly); 680 if (imp->m_collectOnMainThreadOnly) 681 --mainThreadOnlyObjectCount; 603 682 imp->~JSCell(); 604 683 #if DEBUG_COLLECTOR … … 618 697 heap.oversizeCells = (CollectorCell **)fastRealloc(heap.oversizeCells, heap.numOversizeCells * sizeof(CollectorCell *)); 619 698 } 620 } else {621 imp->m_marked = false;622 cell++;623 699 } 624 700 }
Note:
See TracChangeset
for help on using the changeset viewer.