Changeset 24874 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- Aug 5, 2007, 3:16:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r24843 r24874 2 2 /* 3 3 * This file is part of the KDE libraries 4 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.4 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 23 23 #include "collector.h" 24 24 25 #include "internal.h" 26 #include "list.h" 27 #include "value.h" 28 #include <algorithm> 29 #include <setjmp.h> 30 #include <stdlib.h> 25 31 #include <wtf/FastMalloc.h> 26 32 #include <wtf/FastMallocInternal.h> 27 33 #include <wtf/HashCountedSet.h> 28 34 #include <wtf/UnusedParam.h> 29 #include "internal.h"30 #include "list.h"31 #include "value.h"32 33 #include <setjmp.h>34 #include <algorithm>35 35 36 36 #if USE(MULTIPLE_THREADS) … … 69 69 namespace KJS { 70 70 71 72 71 // tunable parameters 73 72 … … 78 77 const size_t ALLOCATIONS_PER_COLLECTION = 4000; 79 78 79 enum OperationInProgress { NoOperation, Allocation, Collection }; 80 80 81 struct CollectorHeap { 81 CollectorBlock **blocks;82 CollectorBlock** blocks; 82 83 size_t numBlocks; 83 84 size_t usedBlocks; … … 87 88 size_t numLiveObjectsAtLastCollect; 88 89 size_t extraCost; 90 91 OperationInProgress operationInProgress; 89 92 }; 90 93 91 static CollectorHeap heap = {NULL, 0, 0, 0, 0, 0, 0}; 92 94 static CollectorHeap heap = { 0, 0, 0, 0, 0, 0, 0, NoOperation }; 95 96 // FIXME: I don't think this needs to be a static data member of the Collector class. 97 // Just a private global like "heap" above would be fine. 93 98 size_t Collector::mainThreadOnlyObjectCount = 0; 99 94 100 bool Collector::memoryFull = false; 95 96 #ifndef NDEBUG97 98 class GCLock {99 static bool isLocked;100 101 public:102 GCLock()103 {104 ASSERT(!isLocked);105 isLocked = true;106 }107 108 ~GCLock()109 {110 ASSERT(isLocked);111 isLocked = false;112 }113 };114 115 bool GCLock::isLocked = false;116 #endif117 101 118 102 static CollectorBlock* allocateBlock() … … 191 175 UNUSED_PARAM(s); // s is now only used for the above assert 192 176 177 ASSERT(heap.operationInProgress == NoOperation); 178 // FIXME: If another global variable access here doesn't hurt performance 179 // too much, we could abort() in NDEBUG builds, which could help ensure we 180 // don't spend any time debugging cases where we allocate inside an object's 181 // deallocation code. 182 193 183 // collect if needed 194 184 size_t numLiveObjects = heap.numLiveObjects; … … 202 192 } 203 193 194 ASSERT(heap.operationInProgress == NoOperation); 204 195 #ifndef NDEBUG 205 GCLock lock; 196 // FIXME: Consider doing this in NDEBUG builds too (see comment above). 197 heap.operationInProgress = Allocation; 206 198 #endif 207 199 … … 252 244 targetBlock->usedCells = static_cast<uint32_t>(targetBlockUsedCells + 1); 253 245 heap.numLiveObjects = numLiveObjects + 1; 246 247 #ifndef NDEBUG 248 // FIXME: Consider doing this in NDEBUG builds too (see comment above). 249 heap.operationInProgress = NoOperation; 250 #endif 254 251 255 252 return newCell; … … 760 757 ASSERT(JSLock::currentThreadIsHoldingLock()); 761 758 762 763 #ifndef NDEBUG 764 GCLock lock; 765 #endif 766 767 #if USE(MULTIPLE_THREADS) 768 bool currentThreadIsMainThread = onMainThread(); 769 #else 770 bool currentThreadIsMainThread = true; 771 #endif 772 759 ASSERT(heap.operationInProgress == NoOperation); 760 if (heap.operationInProgress != NoOperation) 761 abort(); 762 763 heap.operationInProgress = Collection; 764 765 bool currentThreadIsMainThread = onMainThread(); 766 773 767 // MARK: first mark all referenced objects recursively starting out from the set of root objects 774 768 … … 901 895 memoryFull = (numLiveObjects >= KJS_MEM_LIMIT); 902 896 897 heap.operationInProgress = NoOperation; 898 903 899 return deleted; 904 900 } … … 908 904 return heap.numLiveObjects; 909 905 } 910 911 #ifdef KJS_DEBUG_MEM912 void Collector::finalCheck()913 {914 }915 #endif916 906 917 907 size_t Collector::numInterpreters() … … 978 968 } 979 969 970 bool Collector::isBusy() 971 { 972 return heap.operationInProgress != NoOperation; 973 } 974 980 975 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.