void Heap::destroy() { JSLock lock(SilenceAssertionsOnly); if (!m_globalData) return; ASSERT(!m_globalData->dynamicGlobalObject); ASSERT(m_operationInProgress == NoOperation); // The global object is not GC protected at this point, so sweeping may delete it // (and thus the global data) before other objects that may use the global data. RefPtr<JSGlobalData> protect(m_globalData); #if ENABLE(JIT) m_globalData->jitStubs->clearHostFunctionStubs(); #endif delete m_markListSet; m_markListSet = 0; clearMarks(); m_handleHeap.finalizeWeakHandles(); m_globalData->smallStrings.finalizeSmallStrings(); #if !ENABLE(JSC_ZOMBIES) shrink(); ASSERT(!size()); #endif m_globalData = 0; }
void Heap::markRoots() { ASSERT(isValidThreadState(m_globalData)); if (m_operationInProgress != NoOperation) CRASH(); m_operationInProgress = Collection; void* dummy; // We gather conservative roots before clearing mark bits because conservative // gathering uses the mark bits to determine whether a reference is valid. ConservativeRoots machineThreadRoots(&m_blocks); m_machineThreads.gatherConservativeRoots(machineThreadRoots, &dummy); ConservativeRoots registerFileRoots(&m_blocks); registerFile().gatherConservativeRoots(registerFileRoots); clearMarks(); SlotVisitor& visitor = m_slotVisitor; HeapRootVisitor heapRootVisitor(visitor); visitor.append(machineThreadRoots); visitor.drain(); visitor.append(registerFileRoots); visitor.drain(); markProtectedObjects(heapRootVisitor); visitor.drain(); markTempSortVectors(heapRootVisitor); visitor.drain(); if (m_markListSet && m_markListSet->size()) MarkedArgumentBuffer::markLists(heapRootVisitor, *m_markListSet); if (m_globalData->exception) heapRootVisitor.visit(&m_globalData->exception); visitor.drain(); m_handleHeap.visitStrongHandles(heapRootVisitor); visitor.drain(); m_handleStack.visit(heapRootVisitor); visitor.drain(); // Weak handles must be marked last, because their owners use the set of // opaque roots to determine reachability. int lastOpaqueRootCount; do { lastOpaqueRootCount = visitor.opaqueRootCount(); m_handleHeap.visitWeakHandles(heapRootVisitor); visitor.drain(); // If the set of opaque roots has grown, more weak handles may have become reachable. } while (lastOpaqueRootCount != visitor.opaqueRootCount()); visitor.reset(); m_operationInProgress = NoOperation; }
void Marks::modelChanged() { // parse model to display errors in the editor auto documents = KTextEditor::Editor::instance()->documents(); foreach (auto document, documents) { auto iface = qobject_cast<KTextEditor::MarkInterface*>(document); if (iface) iface->clearMarks(); }
PathNode::PathNode ( Vector const & position ) : m_graph(NULL), m_index(-1), m_id(-1), m_key(-1), m_type(PNT_Invalid), m_partId(-1), m_position( position ), m_radius(0.0f), m_userId(-1) { clearMarks(); }
void QXsldbgDoc::selectBreakPoint(uint lineNumber, bool reachedBreakPoint) { if (locked) return; clearMarks(false); KTextEditor::MarkInterface *markIf = KTextEditor::markInterface(kDoc); if (markIf){ if (reachedBreakPoint){ //markIf->setMark(lineNumber, KTextEditor::MarkInterface::BreakpointReached); }else{ markIf->setMark(lineNumber, KTextEditor::MarkInterface::Execution); } } }
// The JSGlobalData is being destroyed and the collector will never run again. // Run all pending finalizers now because we won't get another chance. void Heap::lastChanceToFinalize() { ASSERT(!m_globalData->dynamicGlobalObject); ASSERT(m_operationInProgress == NoOperation); // FIXME: Make this a release-mode crash once we're sure no one's doing this. if (size_t size = m_protectedValues.size()) WTFLogAlways("ERROR: JavaScriptCore heap deallocated while %ld values were still protected", static_cast<unsigned long>(size)); m_weakSet.finalizeAll(); canonicalizeCellLivenessData(); clearMarks(); sweep(); m_globalData->smallStrings.finalizeSmallStrings(); #if ENABLE(SIMPLE_HEAP_PROFILING) m_slotVisitor.m_visitedTypeCounts.dump(WTF::dataFile(), "Visited Type Counts"); m_destroyedTypeCounts.dump(WTF::dataFile(), "Destroyed Type Counts"); #endif }
void Heap::destroy() { JSLock lock(SilenceAssertionsOnly); if (!m_globalData) return; ASSERT(!m_globalData->dynamicGlobalObject); ASSERT(m_operationInProgress == NoOperation); // The global object is not GC protected at this point, so sweeping may delete it // (and thus the global data) before other objects that may use the global data. RefPtr<JSGlobalData> protect(m_globalData); #if ENABLE(JIT) m_globalData->jitStubs->clearHostFunctionStubs(); #endif delete m_markListSet; m_markListSet = 0; canonicalizeCellLivenessData(); clearMarks(); m_handleHeap.finalizeWeakHandles(); m_globalData->smallStrings.finalizeSmallStrings(); shrink(); ASSERT(!size()); #if ENABLE(SIMPLE_HEAP_PROFILING) m_slotVisitor.m_visitedTypeCounts.dump(stderr, "Visited Type Counts"); m_destroyedTypeCounts.dump(stderr, "Destroyed Type Counts"); #endif releaseFreeBlocks(); m_globalData = 0; }
Boolean Btree<T>::getFirstNode(T& x) // // Purpose: visits the root of the B-tree. The function // returns TRUE if the B-tree object has a root. // // Parameters: // // input: x - the index to the data associated with the root of // the B-tree. { Bstruct<T> *buf; if (root != BTREE_NIL) { seekNode = TRUE; clearMarks(root); visitTree(root, nodePtr); buf = new Bstruct<T>; readNode(buf, nodePtr); x = buf->data[visitIndex]; delete buf; } return (root != BTREE_NIL) ? TRUE : FALSE; }
void Heap::markRoots(bool fullGC) { COND_GCPHASE(fullGC, MarkFullRoots, MarkYoungRoots); UNUSED_PARAM(fullGC); ASSERT(isValidThreadState(m_globalData)); if (m_operationInProgress != NoOperation) CRASH(); m_operationInProgress = Collection; void* dummy; // We gather conservative roots before clearing mark bits because conservative // gathering uses the mark bits to determine whether a reference is valid. ConservativeRoots machineThreadRoots(&m_objectSpace.blocks()); { GCPHASE(GatherConservativeRoots); m_machineThreads.gatherConservativeRoots(machineThreadRoots, &dummy); } ConservativeRoots registerFileRoots(&m_objectSpace.blocks()); m_jettisonedCodeBlocks.clearMarks(); { GCPHASE(GatherRegisterFileRoots); registerFile().gatherConservativeRoots(registerFileRoots, m_jettisonedCodeBlocks); } m_jettisonedCodeBlocks.deleteUnmarkedCodeBlocks(); #if ENABLE(GGC) MarkedBlock::DirtyCellVector dirtyCells; if (!fullGC) { GCPHASE(GatheringDirtyCells); m_objectSpace.gatherDirtyCells(dirtyCells); } else #endif { GCPHASE(clearMarks); clearMarks(); } SlotVisitor& visitor = m_slotVisitor; HeapRootVisitor heapRootVisitor(visitor); #if ENABLE(GGC) { size_t dirtyCellCount = dirtyCells.size(); GCPHASE(VisitDirtyCells); GCCOUNTER(DirtyCellCount, dirtyCellCount); for (size_t i = 0; i < dirtyCellCount; i++) { heapRootVisitor.visitChildren(dirtyCells[i]); visitor.drain(); } } #endif if (m_globalData->codeBlocksBeingCompiled.size()) { GCPHASE(VisitActiveCodeBlock); for (size_t i = 0; i < m_globalData->codeBlocksBeingCompiled.size(); i++) m_globalData->codeBlocksBeingCompiled[i]->visitAggregate(visitor); } { GCPHASE(VisitMachineRoots); visitor.append(machineThreadRoots); visitor.drain(); } { GCPHASE(VisitRegisterFileRoots); visitor.append(registerFileRoots); visitor.drain(); } { GCPHASE(VisitProtectedObjects); markProtectedObjects(heapRootVisitor); visitor.drain(); } { GCPHASE(VisitTempSortVectors); markTempSortVectors(heapRootVisitor); visitor.drain(); } { GCPHASE(MarkingArgumentBuffers); if (m_markListSet && m_markListSet->size()) { MarkedArgumentBuffer::markLists(heapRootVisitor, *m_markListSet); visitor.drain(); } } if (m_globalData->exception) { GCPHASE(MarkingException); heapRootVisitor.visit(&m_globalData->exception); visitor.drain(); } { GCPHASE(VisitStrongHandles); m_handleHeap.visitStrongHandles(heapRootVisitor); visitor.drain(); } { GCPHASE(HandleStack); m_handleStack.visit(heapRootVisitor); visitor.drain(); } { GCPHASE(TraceCodeBlocks); m_jettisonedCodeBlocks.traceCodeBlocks(visitor); visitor.drain(); } // Weak handles must be marked last, because their owners use the set of // opaque roots to determine reachability. { GCPHASE(VisitingWeakHandles); int lastOpaqueRootCount; do { lastOpaqueRootCount = visitor.opaqueRootCount(); m_handleHeap.visitWeakHandles(heapRootVisitor); visitor.drain(); // If the set of opaque roots has grown, more weak handles may have become reachable. } while (lastOpaqueRootCount != visitor.opaqueRootCount()); } GCCOUNTER(VisitedValueCount, visitor.visitCount()); visitor.reset(); m_operationInProgress = NoOperation; }
void MarkedSpace::destroy() { clearMarks(); shrink(); ASSERT(!size()); }
void Heap::markRoots(bool fullGC) { SamplingRegion samplingRegion("Garbage Collection: Tracing"); COND_GCPHASE(fullGC, MarkFullRoots, MarkYoungRoots); UNUSED_PARAM(fullGC); ASSERT(isValidThreadState(m_globalData)); if (m_operationInProgress != NoOperation) CRASH(); m_operationInProgress = Collection; void* dummy; // We gather conservative roots before clearing mark bits because conservative // gathering uses the mark bits to determine whether a reference is valid. ConservativeRoots machineThreadRoots(&m_objectSpace.blocks(), &m_storageSpace); { GCPHASE(GatherConservativeRoots); m_machineThreads.gatherConservativeRoots(machineThreadRoots, &dummy); } ConservativeRoots registerFileRoots(&m_objectSpace.blocks(), &m_storageSpace); m_dfgCodeBlocks.clearMarks(); { GCPHASE(GatherRegisterFileRoots); registerFile().gatherConservativeRoots(registerFileRoots, m_dfgCodeBlocks); } #if ENABLE(GGC) MarkedBlock::DirtyCellVector dirtyCells; if (!fullGC) { GCPHASE(GatheringDirtyCells); m_objectSpace.gatherDirtyCells(dirtyCells); } else #endif { GCPHASE(clearMarks); clearMarks(); } m_storageSpace.startedCopying(); SlotVisitor& visitor = m_slotVisitor; HeapRootVisitor heapRootVisitor(visitor); { ParallelModeEnabler enabler(visitor); #if ENABLE(GGC) { size_t dirtyCellCount = dirtyCells.size(); GCPHASE(VisitDirtyCells); GCCOUNTER(DirtyCellCount, dirtyCellCount); for (size_t i = 0; i < dirtyCellCount; i++) { heapRootVisitor.visitChildren(dirtyCells[i]); visitor.donateAndDrain(); } } #endif if (m_globalData->codeBlocksBeingCompiled.size()) { GCPHASE(VisitActiveCodeBlock); for (size_t i = 0; i < m_globalData->codeBlocksBeingCompiled.size(); i++) m_globalData->codeBlocksBeingCompiled[i]->visitAggregate(visitor); } { GCPHASE(VisitMachineRoots); visitor.append(machineThreadRoots); visitor.donateAndDrain(); } { GCPHASE(VisitRegisterFileRoots); visitor.append(registerFileRoots); visitor.donateAndDrain(); } { GCPHASE(VisitProtectedObjects); markProtectedObjects(heapRootVisitor); visitor.donateAndDrain(); } { GCPHASE(VisitTempSortVectors); markTempSortVectors(heapRootVisitor); visitor.donateAndDrain(); } { GCPHASE(MarkingArgumentBuffers); if (m_markListSet && m_markListSet->size()) { MarkedArgumentBuffer::markLists(heapRootVisitor, *m_markListSet); visitor.donateAndDrain(); } } if (m_globalData->exception) { GCPHASE(MarkingException); heapRootVisitor.visit(&m_globalData->exception); visitor.donateAndDrain(); } { GCPHASE(VisitStrongHandles); m_handleSet.visitStrongHandles(heapRootVisitor); visitor.donateAndDrain(); } { GCPHASE(HandleStack); m_handleStack.visit(heapRootVisitor); visitor.donateAndDrain(); } { GCPHASE(TraceCodeBlocks); m_dfgCodeBlocks.traceMarkedCodeBlocks(visitor); visitor.donateAndDrain(); } #if ENABLE(PARALLEL_GC) { GCPHASE(Convergence); visitor.drainFromShared(SlotVisitor::MasterDrain); } #endif } // Weak references must be marked last because their liveness depends on // the liveness of the rest of the object graph. { GCPHASE(VisitingLiveWeakHandles); while (true) { m_weakSet.visitLiveWeakImpls(heapRootVisitor); harvestWeakReferences(); if (visitor.isEmpty()) break; { ParallelModeEnabler enabler(visitor); visitor.donateAndDrain(); #if ENABLE(PARALLEL_GC) visitor.drainFromShared(SlotVisitor::MasterDrain); #endif } } } { GCPHASE(VisitingDeadWeakHandles); m_weakSet.visitDeadWeakImpls(heapRootVisitor); } GCCOUNTER(VisitedValueCount, visitor.visitCount()); visitor.doneCopying(); visitor.reset(); m_sharedData.reset(); m_storageSpace.doneCopying(); m_operationInProgress = NoOperation; }
/* core function, drives all action on the board each turn param player: the player whose turn needs to be executed param x,y: coordinates of the stone to be placed (note, should be validated with isValidMove() before step is called. return int: a signal to show the turn has completed succesfully */ int GoBoard::step( Player player, int x, int y ) { Player currPlayer = player; Player Enemy; Stone *currStone; bool KOflag1 = false; Group playerGroup; std::string playerName; //establish the opposing player for reference if( currPlayer == BLACK ) { Enemy = WHITE; } else { Enemy = BLACK; } //get the stone at x, y currStone = grid[x][y]; //set the piece to its new player currStone->setPlayer( currPlayer ); //test and possibly kill enemies KOflag1 = effectEnemies( Enemy, x, y ); //set the Ko flag to the output //initialize the attributes of the group for the current player playerGroup.size = 0; playerGroup.liberties = 0; playerGroup.player = currPlayer; playerGroup.owner = (Player)EMPTY; //call to determine the attributes playerGroup = getGroup( x, y, playerGroup ); //Debug message to see if the liberties, size, and owner are counted correctly //std::cout<<"Size: "<<playerGroup.size<<" Liberties: "<<playerGroup.liberties<<" Player: "<<playerGroup.player<<" Owner: "<<playerGroup.owner<<std::endl; //test if player killed themselves if( playerGroup.liberties == 0 ) { clearGroup( currPlayer, x, y ); } //Determine if there is not a KO if( playerGroup.liberties != 1 || playerGroup.size != 1 || !KOflag1 ) { //The KO positions are set when an enemy is killed, //if a KO is not possible then the positions need to be reset //to an unreachable position -1,-1 before the step finishes koPosX = -1; koPosY = -1; } //clear all our Counted marks clearMarks(); //return to signal that the player made a move return 1; }
/* Scores the board according to Japanese/Korean Territory scoring rules -each stone captured during the course of the game is added to the capturing players score -each empty group that is completely surrounded by just 1 player's stones and board edges has its size scored for that player. return the player who has the higher score */ Player GoBoard::scoreTerritory() { Group currGroup; //reset the player scores scoreBlack = 0; scoreWhite = 0; //print out the number of prisoners on each side std::cout<<"Black's captured stones "<<blackPrisoners<<std::endl; std::cout<<"White's captured stones "<<whitePrisoners<<std::endl; //add each players captured prisoners to their score scoreBlack = blackPrisoners; scoreWhite = whitePrisoners; //iterate through the board piece by piece for( int x = 0; x < width; x++ ) { for( int y = 0; y < height; y++ ) { //reset the group attributes currGroup.size = 0; currGroup.liberties = 0; currGroup.owner = (Player)EMPTY; currGroup.player = (Player)EMPTY; if( grid[x][y]->isPlayer( EMPTY ) && !grid[x][y]->isCounted()) { //get attributes of the empty territory currGroup = getGroup( x, y, currGroup ); //DEBUG msg to print the size and owner of all empty groups //std::cout<<"Size: "<<currGroup.size<<" owner: "<<currGroup.owner<<std::endl; //determine 'Ownership' of the empty territory and add the size to that player score switch( currGroup.owner ) { case(BLACK): { scoreBlack += currGroup.size; break; } case(WHITE): { scoreWhite += currGroup.size; break; } default: { break; } } } } } //console messages to display the score //std::cout<<"Black's Score "<<scoreBlack<<std::endl; //std::cout<<"White's Score "<<scoreWhite<<std::endl; clearMarks(); //Determine winner and return that player if( scoreBlack > scoreWhite ) { return BLACK; } else if ( scoreWhite > scoreBlack ) { return WHITE; } else { return EMPTY; } }
/* Scores the board according to chinese Area scoring rules -each stone on the board is a point for it's owning player -each empty group that is completely surrounded by just 1 player's stones and board edges has its size scored for that player. returns the player who has the higher score */ Player GoBoard::scoreArea() { Group currGroup; //reset the scores scoreBlack = 0; scoreWhite = 0; //iterate through the board for( int x = 0; x < width; x++ ) { for( int y = 0; y < height; y++ ) { //reset the attributes of the group currGroup.size = 0; currGroup.liberties = 0; currGroup.owner = EMPTY; //don't double count... never double count! if( !grid[x][y]->isCounted() ) { switch( grid[x][y]->getPlayer() ) { //determine the player, set the player of the group //and determine it's size, if one of the players //add it to their score case( BLACK ): currGroup.player = (Player)BLACK; currGroup = getGroup( x, y, currGroup ); scoreBlack += currGroup.size; break; case( WHITE ): currGroup.player = (Player)WHITE; currGroup = getGroup( x, y, currGroup ); scoreWhite += currGroup.size; break; case( EMPTY ): //if it's empty we have to figure out who owns the group currGroup.player = (Player)EMPTY; currGroup.owner = (Player)EMPTY; currGroup = getGroup( x, y, currGroup); //figure out the owner of the controlled territory //add it to their score switch( currGroup.owner ) { case( BLACK ): scoreBlack += currGroup.size; break; case( WHITE ): scoreWhite += currGroup.size; break; default: break; } break; default: break; } } } } //std::cout<<"Black's Score "<<scoreBlack<<std::endl; //std::cout<<"White's Score "<<scoreWhite<<std::endl; clearMarks(); //find the bigger number //return the winner if( scoreWhite > scoreBlack ) { return WHITE; } else if( scoreBlack > scoreWhite ) { return BLACK; } else { return EMPTY; } }