1/* 2 * Copyright (c) 2011 Apple Inc. All rights reserved. 3 * 4 * @APPLE_APACHE_LICENSE_HEADER_START@ 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * @APPLE_APACHE_LICENSE_HEADER_END@ 19 */ 20/* 21 WriteBarrierIterator.h 22 Write Barrier Iteration of Subzones and Large blocks 23 Copyright (c) 2004-2011 Apple Inc. All rights reserved. 24 */ 25 26#pragma once 27#ifndef __AUTO_WRITE_BARRIER_ITERATOR__ 28#define __AUTO_WRITE_BARRIER_ITERATOR__ 29 30 31#include "Admin.h" 32#include "Definitions.h" 33#include "Large.h" 34#include "RangeIterator.h" 35#include "Region.h" 36#include "Subzone.h" 37#include "WriteBarrier.h" 38#include "Zone.h" 39 40 41namespace Auto { 42 43 //----- WriteBarrierIterator -----// 44 45 // 46 // Visit all the write barriers. 47 // 48 49 template <class Visitor> bool visitWriteBarriers(Zone *zone, Visitor &visitor) { 50 // iterate through the regions first 51 for (Region *region = zone->region_list(); region != NULL; region = region->next()) { 52 // iterate through the subzones 53 SubzoneRangeIterator iterator(region->subzone_range()); 54 while (Subzone *subzone = iterator.next()) { 55 // extract the write barrier information 56 WriteBarrier& wb = subzone->write_barrier(); 57 58 // let the visitor visit the write barrier 59 if (!visitor.visit(zone, wb)) return false; 60 } 61 } 62 63 // iterate through the large blocks list. we assume that either the large_lock() is held, 64 // or that the collector has made large block deallocation lazy. 65 for (Large *large = zone->large_list(); large != NULL; large = large->next()) { 66 // skip unscanned large blocks, which have no write-barrier cards. 67 if (!large->is_scanned()) continue; 68 69 // extract the write barrier information 70 WriteBarrier& wb = large->write_barrier(); 71 72 // let the visitor visit the write barrier 73 if (!visitor.visit(zone, wb)) return false; 74 } 75 76 return true; 77 } 78 79}; 80 81#endif // __AUTO_WRITE_BARRIER_ITERATOR__ 82 83