Changeset 636
- Timestamp:
- Mar 5, 2010, 7:50:20 PM (15 years ago)
- Location:
- trunk/src/3rdparty/webkit/JavaScriptCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.cpp
r561 r636 37 37 munmap(m_buffer, ((m_max - m_start) + m_maxGlobals) * sizeof(Register)); 38 38 #elif HAVE(VIRTUALALLOC) 39 40 41 39 42 #if PLATFORM(WINCE) 40 43 VirtualFree(m_buffer, DWORD(m_commitEnd) - DWORD(m_buffer), MEM_DECOMMIT); 41 44 #endif 42 45 VirtualFree(m_buffer, 0, MEM_RELEASE); 46 43 47 #else 44 48 fastFree(m_buffer); … … 51 55 while (madvise(m_start, (m_max - m_start) * sizeof(Register), MADV_FREE) == -1 && errno == EAGAIN) { } 52 56 #elif HAVE(VIRTUALALLOC) 57 58 59 60 53 61 VirtualFree(m_start, (m_max - m_start) * sizeof(Register), MEM_DECOMMIT); 54 62 m_commitEnd = m_start; 63 55 64 #endif 56 65 m_maxUsed = m_start; -
trunk/src/3rdparty/webkit/JavaScriptCore/interpreter/RegisterFile.h
r561 r636 42 42 #endif 43 43 44 45 46 47 48 44 49 namespace JSC { 45 50 … … 130 135 bool grow(Register* newEnd); 131 136 void shrink(Register* newEnd); 132 137 133 138 void setNumGlobals(size_t numGlobals) { m_numGlobals = numGlobals; } 134 139 int numGlobals() const { return m_numGlobals; } … … 136 141 137 142 Register* lastGlobal() const { return m_start - m_numGlobals; } 138 143 139 144 void markGlobals(MarkStack& markStack, Heap* heap) { heap->markConservatively(markStack, lastGlobal(), m_start); } 140 145 void markCallFrames(MarkStack& markStack, Heap* heap) { heap->markConservatively(markStack, m_start, m_end); } … … 185 190 } 186 191 #elif HAVE(VIRTUALALLOC) 192 193 194 195 196 197 198 199 200 201 202 203 204 205 187 206 m_buffer = static_cast<Register*>(VirtualAlloc(0, roundUpAllocationSize(bufferLength, commitSize), MEM_RESERVE, PAGE_READWRITE)); 188 207 if (!m_buffer) { … … 205 224 } 206 225 m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_buffer) + committedSize); 207 #else 208 /* 226 #endif 227 #else 228 /* 209 229 * If neither MMAP nor VIRTUALALLOC are available - use fastMalloc instead. 210 230 * … … 240 260 241 261 #if !HAVE(MMAP) && HAVE(VIRTUALALLOC) 262 263 264 265 266 267 268 269 270 271 272 242 273 if (newEnd > m_commitEnd) { 243 274 size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize); … … 253 284 } 254 285 #endif 286 255 287 256 288 if (newEnd > m_maxUsed) -
trunk/src/3rdparty/webkit/JavaScriptCore/jit/JITStubs.cpp
r561 r636 64 64 namespace JSC { 65 65 66 #if PLATFORM(DARWIN) || PLATFORM(WIN_OS) 66 #if PLATFORM(DARWIN) || PLATFORM(WIN_OS) 67 67 #define SYMBOL_STRING(name) "_" #name 68 68 #else … … 143 143 "ret" "\n" 144 144 ); 145 145 146 146 asm volatile ( 147 147 ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n" … … 155 155 "ret" "\n" 156 156 ); 157 157 158 158 #elif COMPILER(GCC) && PLATFORM(X86_64) 159 159 … … 405 405 "ret" "\n" 406 406 ); 407 407 408 408 asm volatile ( 409 409 ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n" … … 417 417 "ret" "\n" 418 418 ); 419 419 420 420 #elif COMPILER(GCC) && PLATFORM(X86_64) 421 421 … … 648 648 } 649 649 } 650 650 651 651 __declspec(naked) void ctiOpThrowNotCaught() 652 652 { … … 709 709 return; 710 710 } 711 711 712 712 JSCell* baseCell = asCell(baseValue); 713 713 Structure* structure = baseCell->structure(); … … 741 741 return; 742 742 } 743 743 744 744 stubInfo->initPutByIdReplace(structure); 745 745 … … 757 757 return; 758 758 } 759 759 760 760 JSGlobalData* globalData = &callFrame->globalData(); 761 761 … … 764 764 return; 765 765 } 766 766 767 767 if (isJSString(globalData, baseValue) && propertyName == callFrame->propertyNames().length) { 768 768 // The tradeoff of compiling an patched inline string length access routine does not seem … … 810 810 if (slotBaseObject->structure()->isDictionary()) 811 811 slotBaseObject->setStructure(Structure::fromDictionaryTransition(slotBaseObject->structure())); 812 812 813 813 stubInfo->initGetByIdProto(structure, slotBaseObject->structure()); 814 814 … … 840 840 extern "C" { 841 841 842 static void jscGeneratedNativeCode() 842 static void jscGeneratedNativeCode() 843 843 { 844 844 // When executing a JIT stub function (which might do an allocation), we hack the return address … … 850 850 851 851 struct StackHack { 852 ALWAYS_INLINE StackHack(JITStackFrame& stackFrame) 852 ALWAYS_INLINE StackHack(JITStackFrame& stackFrame) 853 853 : stackFrame(stackFrame) 854 854 , savedReturnAddress(*stackFrame.returnAddressSlot()) … … 857 857 } 858 858 859 ALWAYS_INLINE ~StackHack() 860 { 859 ALWAYS_INLINE ~StackHack() 860 { 861 861 *stackFrame.returnAddressSlot() = savedReturnAddress; 862 862 } … … 996 996 if (rightIsNumber && v1.getNumber(left)) 997 997 return JSValue::encode(jsNumber(stackFrame.globalData, left + right)); 998 998 999 999 CallFrame* callFrame = stackFrame.callFrame; 1000 1000 … … 1043 1043 { 1044 1044 STUB_INIT_STACK_FRAME(stackFrame); 1045 1045 1046 1046 JSGlobalData* globalData = stackFrame.globalData; 1047 1047 TimeoutChecker& timeoutChecker = globalData->timeoutChecker; … … 1051 1051 VM_THROW_EXCEPTION_AT_END(); 1052 1052 } 1053 1053 1054 1054 return timeoutChecker.ticksUntilNextCheck(); 1055 1055 } … … 1338 1338 ASSERT_NOT_REACHED(); 1339 1339 } 1340 1340 1341 1341 ASSERT(listIndex < POLYMORPHIC_LIST_CACHE_SIZE); 1342 1342 return prototypeStructureList; … … 1458 1458 // At least one of these checks must have failed to get to the slow case. 1459 1459 ASSERT(!value.isCell() || !baseVal.isCell() || !proto.isCell() 1460 || !value.isObject() || !baseVal.isObject() || !proto.isObject() 1460 || !value.isObject() || !baseVal.isObject() || !proto.isObject() 1461 1461 || (asObject(baseVal)->structure()->typeInfo().flags() & (ImplementsHasInstance | OverridesHasInstance)) != ImplementsHasInstance); 1462 1462 … … 1495 1495 1496 1496 CallFrame* callFrame = stackFrame.callFrame; 1497 1497 1498 1498 JSObject* baseObj = stackFrame.args[0].jsValue().toObject(callFrame); 1499 1499 … … 1600 1600 ExecutableBase* executable = callee->executable(); 1601 1601 JITCode& jitCode = executable->generatedJITCode(); 1602 1602 1603 1603 CodeBlock* codeBlock = 0; 1604 1604 if (!executable->isHostFunction()) … … 1866 1866 return JSValue::encode(result); 1867 1867 } 1868 1868 1869 1869 DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_val_string) 1870 1870 { 1871 1871 STUB_INIT_STACK_FRAME(stackFrame); 1872 1872 1873 1873 CallFrame* callFrame = stackFrame.callFrame; 1874 1874 JSGlobalData* globalData = stackFrame.globalData; 1875 1875 1876 1876 JSValue baseValue = stackFrame.args[0].jsValue(); 1877 1877 JSValue subscript = stackFrame.args[1].jsValue(); 1878 1878 1879 1879 JSValue result; 1880 1880 1881 1881 if (LIKELY(subscript.isUInt32())) { 1882 1882 uint32_t i = subscript.asUInt32(); … … 1892 1892 result = baseValue.get(callFrame, property); 1893 1893 } 1894 1895 CHECK_FOR_EXCEPTION_AT_END(); 1896 return JSValue::encode(result); 1897 } 1898 1894 1895 CHECK_FOR_EXCEPTION_AT_END(); 1896 return JSValue::encode(result); 1897 } 1898 1899 1899 DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_val_byte_array) 1900 1900 { 1901 1901 STUB_INIT_STACK_FRAME(stackFrame); 1902 1902 1903 1903 CallFrame* callFrame = stackFrame.callFrame; 1904 1904 JSGlobalData* globalData = stackFrame.globalData; 1905 1905 1906 1906 JSValue baseValue = stackFrame.args[0].jsValue(); 1907 1907 JSValue subscript = stackFrame.args[1].jsValue(); 1908 1908 1909 1909 JSValue result; 1910 1910 … … 1923 1923 result = baseValue.get(callFrame, property); 1924 1924 } 1925 1925 1926 1926 CHECK_FOR_EXCEPTION_AT_END(); 1927 1927 return JSValue::encode(result); … … 1997 1997 { 1998 1998 STUB_INIT_STACK_FRAME(stackFrame); 1999 1999 2000 2000 CallFrame* callFrame = stackFrame.callFrame; 2001 2001 JSGlobalData* globalData = stackFrame.globalData; 2002 2002 2003 2003 JSValue baseValue = stackFrame.args[0].jsValue(); 2004 2004 JSValue subscript = stackFrame.args[1].jsValue(); 2005 2005 JSValue value = stackFrame.args[2].jsValue(); 2006 2006 2007 2007 if (LIKELY(subscript.isUInt32())) { 2008 2008 uint32_t i = subscript.asUInt32(); 2009 2009 if (isJSByteArray(globalData, baseValue) && asByteArray(baseValue)->canAccessIndex(i)) { 2010 2010 JSByteArray* jsByteArray = asByteArray(baseValue); 2011 2011 2012 2012 // All fast byte array accesses are safe from exceptions so return immediately to avoid exception checks. 2013 2013 if (value.isInt32()) { … … 2015 2015 return; 2016 2016 } else { 2017 double dValue = 0; 2017 double dValue = 0; 2018 2018 if (value.getNumber(dValue)) { 2019 2019 jsByteArray->setIndex(i, dValue); … … 2033 2033 } 2034 2034 } 2035 2035 2036 2036 CHECK_FOR_EXCEPTION_AT_END(); 2037 2037 } … … 2059 2059 return result; 2060 2060 } 2061 2061 2062 2062 DEFINE_STUB_FUNCTION(int, op_load_varargs) 2063 2063 { … … 2080 2080 int32_t expectedParams = callFrame->callee()->jsExecutable()->parameterCount(); 2081 2081 int32_t inplaceArgs = min(providedParams, expectedParams); 2082 2082 2083 2083 Register* inplaceArgsDst = callFrame->registers() + argsOffset; 2084 2084 … … 2088 2088 Register* inplaceArgsSrc = callFrame->registers() - RegisterFile::CallFrameHeaderSize - expectedParams; 2089 2089 Register* inplaceArgsSrc2 = inplaceArgsSrc - providedParams - 1 + inplaceArgs; 2090 2090 2091 2091 // First step is to copy the "expected" parameters from their normal location relative to the callframe 2092 2092 while (inplaceArgsDst < inplaceArgsEnd) … … 2345 2345 start: 2346 2346 if (src2.isUndefined()) { 2347 return src1.isNull() || 2347 return src1.isNull() || 2348 2348 (src1.isCell() && asCell(src1)->structure()->typeInfo().masqueradesAsUndefined()) || 2349 2349 src1.isUndefined(); 2350 2350 } 2351 2351 2352 2352 if (src2.isNull()) { 2353 return src1.isUndefined() || 2353 return src1.isUndefined() || 2354 2354 (src1.isCell() && asCell(src1)->structure()->typeInfo().masqueradesAsUndefined()) || 2355 2355 src1.isNull(); … … 2387 2387 return d == 0.0; 2388 2388 } 2389 2389 2390 2390 if (src1.isUndefined()) 2391 2391 return src2.isCell() && asCell(src2)->structure()->typeInfo().masqueradesAsUndefined(); 2392 2392 2393 2393 if (src1.isNull()) 2394 2394 return src2.isCell() && asCell(src2)->structure()->typeInfo().masqueradesAsUndefined(); … … 2399 2399 if (src2.isInt32()) 2400 2400 return static_cast<JSString*>(cell1)->value().toDouble() == src2.asInt32(); 2401 2401 2402 2402 if (src2.isDouble()) 2403 2403 return static_cast<JSString*>(cell1)->value().toDouble() == src2.asDouble(); … … 2553 2553 JSFunction* func = function->make(callFrame, callFrame->scopeChain()); 2554 2554 2555 /* 2555 /* 2556 2556 The Identifier in a FunctionExpression can be referenced from inside 2557 2557 the FunctionExpression's FunctionBody to allow the function to call … … 2663 2663 2664 2664 Interpreter* interpreter = stackFrame.globalData->interpreter; 2665 2665 2666 2666 JSValue funcVal = stackFrame.args[0].jsValue(); 2667 2667 int registerOffset = stackFrame.args[1].int32(); -
trunk/src/3rdparty/webkit/JavaScriptCore/runtime/Collector.cpp
r561 r636 144 144 class Heap::Thread { 145 145 public: 146 Thread(pthread_t pthread, const PlatformThread& platThread, void* base) 146 Thread(pthread_t pthread, const PlatformThread& platThread, void* base) 147 147 : posixThread(pthread) 148 148 , platformThread(platThread) … … 188 188 } 189 189 #endif // PLATFORM(SYMBIAN) 190 190 191 191 memset(&primaryHeap, 0, sizeof(CollectorHeap)); 192 192 memset(&numberHeap, 0, sizeof(CollectorHeap)); … … 255 255 256 256 memset(reinterpret_cast<void*>(address), 0, BLOCK_SIZE); 257 258 259 257 260 #elif PLATFORM(WINCE) 258 261 void* address = VirtualAlloc(NULL, BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); … … 328 331 329 332 if (heap.numBlocks > MIN_ARRAY_SIZE && heap.usedBlocks < heap.numBlocks / LOW_WATER_FACTOR) { 330 heap.numBlocks = heap.numBlocks / GROWTH_FACTOR; 333 heap.numBlocks = heap.numBlocks / GROWTH_FACTOR; 331 334 heap.blocks = static_cast<CollectorBlock**>(fastRealloc(heap.blocks, heap.numBlocks * sizeof(CollectorBlock*))); 332 335 } … … 341 344 #elif PLATFORM(SYMBIAN) 342 345 userChunk->Free(reinterpret_cast<TAny*>(block)); 346 347 343 348 #elif PLATFORM(WINCE) 344 349 VirtualFree(block, 0, MEM_RELEASE); … … 377 382 // if a large value survives one garbage collection, there is not much point to 378 383 // collecting more frequently as long as it stays alive. 379 // NOTE: we target the primaryHeap unconditionally as JSNumber doesn't modify cost 384 // NOTE: we target the primaryHeap unconditionally as JSNumber doesn't modify cost 380 385 381 386 primaryHeap.extraCost += cost; … … 602 607 ); 603 608 return static_cast<void*>(pTib->StackBase); 609 610 611 612 604 613 #elif PLATFORM(QNX) 605 614 return currentThreadStackBaseQNX(); … … 821 830 } 822 831 } 823 832 824 833 // Mark the primary heap 825 834 for (size_t block = 0; block < usedPrimaryBlocks; block++) { … … 926 935 unsigned user_count = x86_THREAD_STATE64_COUNT; 927 936 thread_state_flavor_t flavor = x86_THREAD_STATE64; 928 #elif PLATFORM(PPC) 937 #elif PLATFORM(PPC) 929 938 unsigned user_count = PPC_THREAD_STATE_COUNT; 930 939 thread_state_flavor_t flavor = PPC_THREAD_STATE; … … 941 950 kern_return_t result = thread_get_state(platformThread, flavor, (thread_state_t)®s, &user_count); 942 951 if (result != KERN_SUCCESS) { 943 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 952 WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 944 953 "JavaScript garbage collection failed because thread_get_state returned an error (%d). This is probably the result of running inside Rosetta, which is not supported.", result); 945 954 CRASH(); … … 1026 1035 1027 1036 #ifndef NDEBUG 1028 // Forbid malloc during the mark phase. Marking a thread suspends it, so 1029 // a malloc inside markChildren() would risk a deadlock with a thread that had been 1037 // Forbid malloc during the mark phase. Marking a thread suspends it, so 1038 // a malloc inside markChildren() would risk a deadlock with a thread that had been 1030 1039 // suspended while holding the malloc lock. 1031 1040 fastMallocForbid(); … … 1082 1091 // SWEEP: delete everything with a zero refcount (garbage) and unmark everything else 1083 1092 CollectorHeap& heap = heapType == PrimaryHeap ? primaryHeap : numberHeap; 1084 1093 1085 1094 size_t emptyBlocks = 0; 1086 1095 size_t numLiveObjects = heap.numLiveObjects; 1087 1096 1088 1097 for (size_t block = 0; block < heap.usedBlocks; block++) { 1089 1098 Block* curBlock = reinterpret_cast<Block*>(heap.blocks[block]); 1090 1099 1091 1100 size_t usedCells = curBlock->usedCells; 1092 1101 Cell* freeList = curBlock->freeList; 1093 1102 1094 1103 if (usedCells == HeapConstants<heapType>::cellsPerBlock) { 1095 1104 // special case with a block where all cells are used -- testing indicates this happens often … … 1097 1106 if (!curBlock->marked.get(i >> HeapConstants<heapType>::bitmapShift)) { 1098 1107 Cell* cell = curBlock->cells + i; 1099 1108 1100 1109 if (heapType != NumberHeap) { 1101 1110 JSCell* imp = reinterpret_cast<JSCell*>(cell); 1102 1111 // special case for allocated but uninitialized object 1103 // (We don't need this check earlier because nothing prior this point 1112 // (We don't need this check earlier because nothing prior this point 1104 1113 // assumes the object has a valid vptr.) 1105 1114 if (cell->u.freeCell.zeroIfFree == 0) 1106 1115 continue; 1107 1116 1108 1117 imp->~JSCell(); 1109 1118 } 1110 1119 1111 1120 --usedCells; 1112 1121 --numLiveObjects; 1113 1122 1114 1123 // put cell on the free list 1115 1124 cell->u.freeCell.zeroIfFree = 0; … … 1132 1141 --usedCells; 1133 1142 --numLiveObjects; 1134 1143 1135 1144 // put cell on the free list 1136 1145 cell->u.freeCell.zeroIfFree = 0; 1137 cell->u.freeCell.next = freeList - (cell + 1); 1146 cell->u.freeCell.next = freeList - (cell + 1); 1138 1147 freeList = cell; 1139 1148 } … … 1141 1150 } 1142 1151 } 1143 1152 1144 1153 curBlock->usedCells = static_cast<uint32_t>(usedCells); 1145 1154 curBlock->freeList = freeList; 1146 1155 curBlock->marked.clearAll(); 1147 1156 1148 1157 if (!usedCells) 1149 1158 ++emptyBlocks; 1150 1159 } 1151 1160 1152 1161 if (heap.numLiveObjects != numLiveObjects) 1153 1162 heap.firstBlockWithPossibleSpace = 0; 1154 1163 1155 1164 heap.numLiveObjects = numLiveObjects; 1156 1165 heap.numLiveObjectsAtLastCollect = numLiveObjects; 1157 1166 heap.extraCost = 0; 1158 1167 1159 1168 if (!emptyBlocks) 1160 1169 return numLiveObjects; … … 1224 1233 } 1225 1234 1226 size_t Heap::objectCount() 1227 { 1228 return primaryHeap.numLiveObjects + numberHeap.numLiveObjects - m_globalData->smallStrings.count(); 1229 } 1230 1231 template <HeapType heapType> 1235 size_t Heap::objectCount() 1236 { 1237 return primaryHeap.numLiveObjects + numberHeap.numLiveObjects - m_globalData->smallStrings.count(); 1238 } 1239 1240 template <HeapType heapType> 1232 1241 static void addToStatistics(Heap::Statistics& statistics, const CollectorHeap& heap) 1233 1242 { -
trunk/src/3rdparty/webkit/JavaScriptCore/runtime/Collector.h
r561 r636 111 111 JSGlobalData* globalData() const { return m_globalData; } 112 112 static bool isNumber(JSCell*); 113 113 114 114 // Iterators for the object heap. 115 115 iterator primaryHeapBegin(); … … 172 172 template<> struct CellSize<sizeof(uint64_t)> { static const size_t m_value = 64; }; 173 173 174 #if PLATFORM(WINCE) || PLATFORM(SYMBIAN) 174 #if PLATFORM(WINCE) || PLATFORM(SYMBIAN) 175 175 const size_t BLOCK_SIZE = 64 * 1024; // 64k 176 176 #else … … 191 191 const size_t BITMAP_SIZE = (CELLS_PER_BLOCK + 7) / 8; 192 192 const size_t BITMAP_WORDS = (BITMAP_SIZE + 3) / sizeof(uint32_t); 193 193 194 194 struct CollectorBitmap { 195 195 uint32_t bits[BITMAP_WORDS]; 196 bool get(size_t n) const { return !!(bits[n >> 5] & (1 << (n & 0x1F))); } 197 void set(size_t n) { bits[n >> 5] |= (1 << (n & 0x1F)); } 198 void clear(size_t n) { bits[n >> 5] &= ~(1 << (n & 0x1F)); } 196 bool get(size_t n) const { return !!(bits[n >> 5] & (1 << (n & 0x1F))); } 197 void set(size_t n) { bits[n >> 5] |= (1 << (n & 0x1F)); } 198 void clear(size_t n) { bits[n >> 5] &= ~(1 << (n & 0x1F)); } 199 199 void clearAll() { memset(bits, 0, sizeof(bits)); } 200 200 }; 201 201 202 202 struct CollectorCell { 203 203 union { … … 239 239 HeapType type; 240 240 }; 241 241 242 242 template <HeapType heapType> struct HeapConstants; 243 243 … … 285 285 inline void Heap::reportExtraMemoryCost(size_t cost) 286 286 { 287 if (cost > minExtraCostSize) 288 recordExtraCost(cost / (CELL_SIZE * 2)); 287 if (cost > minExtraCostSize) 288 recordExtraCost(cost / (CELL_SIZE * 2)); 289 289 } 290 290 -
trunk/src/3rdparty/webkit/JavaScriptCore/runtime/MarkStackPosix.cpp
r561 r636 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 … … 41 41 void* MarkStack::allocateStack(size_t size) 42 42 { 43 44 45 43 46 return mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); 47 44 48 } 45 49 void MarkStack::releaseStack(void* addr, size_t size) 46 50 { 51 52 53 47 54 munmap(addr, size); 55 48 56 } 49 57 -
trunk/src/3rdparty/webkit/JavaScriptCore/wtf/FastMalloc.cpp
r561 r636 2 2 // All rights reserved. 3 3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 4 // 4 // 5 5 // Redistribution and use in source and binary forms, with or without 6 6 // modification, are permitted provided that the following conditions are 7 7 // met: 8 // 8 // 9 9 // * Redistributions of source code must retain the above copyright 10 10 // notice, this list of conditions and the following disclaimer. … … 16 16 // contributors may be used to endorse or promote products derived from 17 17 // this software without specific prior written permission. 18 // 18 // 19 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT … … 172 172 #endif 173 173 174 void* fastZeroedMalloc(size_t n) 174 void* fastZeroedMalloc(size_t n) 175 175 { 176 176 void* result = fastMalloc(n); … … 178 178 return result; 179 179 } 180 181 TryMallocReturnValue tryFastZeroedMalloc(size_t n) 180 181 TryMallocReturnValue tryFastZeroedMalloc(size_t n) 182 182 { 183 183 void* result; … … 193 193 194 194 #include <stdlib.h> 195 #if !PLATFORM(WIN_OS) 195 #if PLATFORM(WIN_OS) 196 #include "windows.h" 197 #elif PLATFORM(OS2) 198 #define INCL_BASE 199 #include <os2.h> 200 #else 196 201 #include <pthread.h> 197 #else198 #include "windows.h"199 202 #endif 200 203 201 204 namespace WTF { 202 205 203 TryMallocReturnValue tryFastMalloc(size_t n) 206 TryMallocReturnValue tryFastMalloc(size_t n) 204 207 { 205 208 ASSERT(!isForbidden()); … … 222 225 } 223 226 224 void* fastMalloc(size_t n) 227 void* fastMalloc(size_t n) 225 228 { 226 229 ASSERT(!isForbidden()); … … 341 344 342 345 void releaseFastMallocFreeMemory() { } 343 346 344 347 FastMallocStatistics fastMallocStatistics() 345 348 { … … 417 420 } \ 418 421 using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_##name 419 422 420 423 #define DEFINE_int64(name, value, meaning) \ 421 424 DEFINE_VARIABLE(int64_t, name, value, meaning) 422 425 423 426 #define DEFINE_double(name, value, meaning) \ 424 427 DEFINE_VARIABLE(double, name, value, meaning) … … 1174 1177 #if defined(WTF_CHANGES) 1175 1178 #if PLATFORM(X86_64) 1176 // On all known X86-64 platforms, the upper 16 bits are always unused and therefore 1179 // On all known X86-64 platforms, the upper 16 bits are always unused and therefore 1177 1180 // can be excluded from the PageMap key. 1178 1181 // See http://en.wikipedia.org/wiki/X86-64#Virtual_address_space_details … … 1271 1274 return GetDescriptor(p); 1272 1275 } 1273 1276 1274 1277 size_t ReturnedBytes() const; 1275 1278 #endif … … 1356 1359 } 1357 1360 } 1358 1361 1359 1362 // Allocate a large span of length == n. If successful, returns a 1360 1363 // span of exactly the specified length. Else, returns NULL. … … 1372 1375 // Index of last free list we scavenged 1373 1376 size_t scavenge_index_; 1374 1377 1375 1378 #if defined(WTF_CHANGES) && PLATFORM(DARWIN) 1376 1379 friend class FastMallocZone; … … 1438 1441 } 1439 1442 1440 void TCMalloc_PageHeap::scavenge() 1443 void TCMalloc_PageHeap::scavenge() 1441 1444 { 1442 1445 // If we have to commit memory in the last 5 seconds, it means we don't have enough free committed pages … … 1451 1454 if (!DLL_IsEmpty(&slist->normal)) { 1452 1455 // Release the last span on the normal portion of this list 1453 Span* s = slist->normal.prev; 1456 Span* s = slist->normal.prev; 1454 1457 // Only decommit up to a fraction of the free committed pages if pages_allocated_since_last_scavenge_ > 0. 1455 1458 if ((pagesDecommitted + s->length) * kMaxScavengeAmountFactor > free_committed_pages_) … … 1473 1476 } 1474 1477 1475 inline bool TCMalloc_PageHeap::shouldContinueScavenging() const 1476 { 1477 return free_committed_pages_ > kMinimumFreeCommittedPageCount; 1478 inline bool TCMalloc_PageHeap::shouldContinueScavenging() const 1479 { 1480 return free_committed_pages_ > kMinimumFreeCommittedPageCount; 1478 1481 } 1479 1482 … … 1795 1798 } 1796 1799 } 1797 1800 1798 1801 #ifdef WTF_CHANGES 1799 1802 size_t TCMalloc_PageHeap::ReturnedBytes() const { … … 1804 1807 result += r_pages << kPageShift; 1805 1808 } 1806 1809 1807 1810 for (Span* s = large_.returned.next; s != &large_.returned; s = s->next) 1808 1811 result += s->length << kPageShift; … … 2284 2287 ::Sleep(seconds * 1000); 2285 2288 } 2289 2290 2291 2292 2293 2286 2294 #endif 2287 2295 … … 2875 2883 #endif 2876 2884 tsd_inited = true; 2877 2885 2878 2886 #if !COMPILER(MSVC) 2879 2887 // We may have used a fake pthread_t for the main thread. Fix it. … … 3579 3587 3580 3588 #ifndef WTF_CHANGES 3581 extern "C" 3589 extern "C" 3582 3590 #else 3583 3591 #define do_malloc do_malloc<crashOnFailure> … … 3621 3629 3622 3630 #ifndef WTF_CHANGES 3623 extern "C" 3631 extern "C" 3624 3632 #endif 3625 3633 void free(void* ptr) { … … 3642 3650 3643 3651 #ifndef WTF_CHANGES 3644 extern "C" 3652 extern "C" 3645 3653 #else 3646 3654 template <bool crashOnFailure> … … 3662 3670 void* calloc(size_t n, size_t elem_size) { 3663 3671 size_t totalBytes = n * elem_size; 3664 3672 3665 3673 // Protect against overflow 3666 3674 if (n > 1 && elem_size && (totalBytes / elem_size) != n) … … 3695 3703 #ifndef WTF_CHANGES 3696 3704 #ifndef WTF_CHANGES 3697 extern "C" 3705 extern "C" 3698 3706 #endif 3699 3707 void cfree(void* ptr) { … … 3706 3714 3707 3715 #ifndef WTF_CHANGES 3708 extern "C" 3716 extern "C" 3709 3717 #else 3710 3718 template <bool crashOnFailure> … … 4348 4356 pageheap->ReleaseFreePages(); 4349 4357 } 4350 4358 4351 4359 FastMallocStatistics fastMallocStatistics() 4352 4360 { -
trunk/src/3rdparty/webkit/JavaScriptCore/wtf/Platform.h
r561 r636 58 58 #endif 59 59 60 61 62 63 64 65 66 60 67 /* PLATFORM(WINCE) */ 61 68 /* Operating system level dependencies for Windows CE that should be used */ … … 201 208 /* Makes PLATFORM(WIN) default to PLATFORM(CAIRO) */ 202 209 /* FIXME: This should be changed from a blacklist to a whitelist */ 203 #if !PLATFORM(MAC) && !PLATFORM(QT) && !PLATFORM(WX) && !PLATFORM(CHROMIUM) && !PLATFORM(WINCE) && !PLATFORM(HAIKU) 210 #if !PLATFORM(MAC) && !PLATFORM(QT) && !PLATFORM(WX) && !PLATFORM(CHROMIUM) && !PLATFORM(WINCE) && !PLATFORM(HAIKU) 204 211 #define WTF_PLATFORM_CAIRO 1 205 212 #endif … … 565 572 566 573 #if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS) && !PLATFORM(QNX) \ 567 && !PLATFORM(SYMBIAN) && !PLATFORM(HAIKU) && !COMPILER(RVCT) 574 && !PLATFORM(SYMBIAN) && !PLATFORM(HAIKU) && !COMPILER(RVCT) \ 575 && !PLATFORM(OS2) 568 576 #define HAVE_TM_GMTOFF 1 569 577 #define HAVE_TM_ZONE 1 570 578 #define HAVE_TIMEGM 1 571 #endif 579 #endif 572 580 573 581 #if PLATFORM(DARWIN) … … 602 610 #endif 603 611 #define HAVE_VIRTUALALLOC 1 612 613 614 615 616 617 618 619 620 604 621 605 622 #elif PLATFORM(SYMBIAN) -
trunk/src/3rdparty/webkit/JavaScriptCore/wtf/TCSystemAlloc.cpp
r561 r636 1 1 // Copyright (c) 2005, 2007, Google Inc. 2 2 // All rights reserved. 3 // 3 // 4 4 // Redistribution and use in source and binary forms, with or without 5 5 // modification, are permitted provided that the following conditions are 6 6 // met: 7 // 7 // 8 8 // * Redistributions of source code must retain the above copyright 9 9 // notice, this list of conditions and the following disclaimer. … … 15 15 // contributors may be used to endorse or promote products derived from 16 16 // this software without specific prior written permission. 17 // 17 // 18 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT … … 50 50 #if PLATFORM(WIN_OS) 51 51 #include "windows.h" 52 53 54 52 55 #else 53 56 #include <errno.h> … … 90 93 #if HAVE(MMAP) 91 94 static bool use_mmap = true; 92 #endif 95 #endif 93 96 94 97 #if HAVE(VIRTUALALLOC) … … 118 121 static void* TrySbrk(size_t size, size_t *actual_size, size_t alignment) { 119 122 size = ((size + alignment - 1) / alignment) * alignment; 120 123 121 124 // could theoretically return the "extra" bytes here, but this 122 125 // is simple and correct. 123 if (actual_size) 126 if (actual_size) 124 127 *actual_size = size; 125 128 126 129 void* result = sbrk(size); 127 130 if (result == reinterpret_cast<void*>(-1)) { … … 165 168 if (alignment < pagesize) alignment = pagesize; 166 169 size = ((size + alignment - 1) / alignment) * alignment; 167 170 168 171 // could theoretically return the "extra" bytes here, but this 169 172 // is simple and correct. 170 if (actual_size) 173 if (actual_size) 171 174 *actual_size = size; 172 175 173 176 // Ask for extra memory if alignment > pagesize 174 177 size_t extra = 0; … … 211 214 // Enforce page alignment 212 215 if (pagesize == 0) { 216 217 218 213 219 SYSTEM_INFO system_info; 214 220 GetSystemInfo(&system_info); 215 221 pagesize = system_info.dwPageSize; 222 216 223 } 217 224 … … 221 228 // could theoretically return the "extra" bytes here, but this 222 229 // is simple and correct. 223 if (actual_size) 230 if (actual_size) 224 231 *actual_size = size; 225 232 226 233 // Ask for extra memory if alignment > pagesize 227 234 size_t extra = 0; … … 229 236 extra = alignment - pagesize; 230 237 } 238 239 240 241 231 242 void* result = VirtualAlloc(NULL, size + extra, 232 MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, 243 MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, 233 244 PAGE_READWRITE); 245 234 246 235 247 if (result == NULL) { … … 248 260 // is decommit, since Windows only lets you free the whole allocation. 249 261 if (adjust > 0) { 262 263 264 250 265 VirtualFree(reinterpret_cast<void*>(ptr), adjust, MEM_DECOMMIT); 266 251 267 } 252 268 if (adjust < extra) { 269 270 271 253 272 VirtualFree(reinterpret_cast<void*>(ptr + adjust + size), extra-adjust, MEM_DECOMMIT); 273 254 274 } 255 275 … … 258 278 } 259 279 260 #endif /* HAVE( MMAP) */280 #endif /* HAVE() */ 261 281 262 282 #ifndef WTF_CHANGES … … 266 286 static off_t physmem_limit; // maximum physical address allowed 267 287 static int physmem_fd; // file descriptor for /dev/mem 268 288 269 289 // Check if we should use /dev/mem allocation. Note that it may take 270 290 // a while to get this flag initialized, so meanwhile we fall back to … … 276 296 return NULL; 277 297 } 278 298 279 299 if (!initialized) { 280 300 physmem_fd = open("/dev/mem", O_RDWR); … … 287 307 initialized = true; 288 308 } 289 309 290 310 // Enforce page alignment 291 311 if (pagesize == 0) pagesize = getpagesize(); 292 312 if (alignment < pagesize) alignment = pagesize; 293 313 size = ((size + alignment - 1) / alignment) * alignment; 294 314 295 315 // could theoretically return the "extra" bytes here, but this 296 316 // is simple and correct. 297 317 if (actual_size) 298 318 *actual_size = size; 299 319 300 320 // Ask for extra memory if alignment > pagesize 301 321 size_t extra = 0; … … 303 323 extra = alignment - pagesize; 304 324 } 305 325 306 326 // check to see if we have any memory left 307 327 if (physmem_limit != 0 && physmem_base + size + extra > physmem_limit) { … … 357 377 } 358 378 #endif 359 379 360 380 #if HAVE(SBRK) 361 381 if (use_sbrk && !sbrk_failure) { … … 365 385 #endif 366 386 367 #if HAVE(MMAP) 387 #if HAVE(MMAP) 368 388 if (use_mmap && !mmap_failure) { 369 389 void* result = TryMmap(size, actual_size, alignment); … … 452 472 void TCMalloc_SystemRelease(void* start, size_t length) 453 473 { 474 475 476 477 454 478 if (VirtualFree(start, length, MEM_DECOMMIT)) 455 479 return; 480 456 481 457 482 // The decommit may fail if the memory region consists of allocations … … 492 517 void TCMalloc_SystemCommit(void* start, size_t length) 493 518 { 519 520 521 522 494 523 if (VirtualAlloc(start, length, MEM_COMMIT, PAGE_READWRITE) == start) 495 524 return; 525 496 526 497 527 // The commit may fail if the memory region consists of allocations
Note:
See TracChangeset
for help on using the changeset viewer.