Changeset 79126 in webkit
- Timestamp:
- Feb 19, 2011 10:05:16 AM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r79124 r79126 1 2011-02-19 Siddharth Mathur <siddharth.mathur@nokia.com> 2 3 Reviewed by Laszlo Gombos. 4 5 [Symbian] OSAllocator implementation for Symbian OS. 6 Manages both data and code region requests. V8 and Sunspider tested 7 OK with interpreter. Not tested with JSC JIT yet as it has unrelated 8 failures. Also no thread safety yet. 9 https://bugs.webkit.org/show_bug.cgi?id=51128 10 11 * JavaScriptCore.pri: removed HAL linkage 12 * wtf/Bitmap.h: 13 (WTF::::findRunOfZeros): find run of zeros in a bitmap. quick n dirty 14 * wtf/OSAllocator.h: 15 (WTF::OSAllocator::decommitAndRelease): decommit explicitly 16 * wtf/OSAllocatorSymbian.cpp: Impl. of OSAllocator interface 17 (WTF::allocateCodeChunk): utility for code chunks 18 (WTF::deallocateCodeChunk): utility for code chunks 19 (WTF::dataAllocatorInstance): getter for data allocator instance 20 (WTF::OSAllocator::reserveUncommitted): 21 (WTF::OSAllocator::releaseDecommitted): 22 (WTF::OSAllocator::commit): 23 (WTF::OSAllocator::decommit): 24 (WTF::OSAllocator::reserveAndCommit): 25 (WTF::PageAllocatorSymbian::PageAllocatorSymbian): maps requests 26 to one underlying Symbian chunk 27 (WTF::PageAllocatorSymbian::~PageAllocatorSymbian): 28 (WTF::PageAllocatorSymbian::reserve): 29 (WTF::PageAllocatorSymbian::release): 30 (WTF::PageAllocatorSymbian::commit): 31 (WTF::PageAllocatorSymbian::decommit): 32 (WTF::PageAllocatorSymbian::contains): 33 * wtf/PageAllocatorSymbian.h: Added. 34 (WTF::SymbianChunk::SymbianChunk): wrapper around RChunk 35 (WTF::SymbianChunk::~SymbianChunk): 36 (WTF::SymbianChunk::contains): 37 1 38 2011-02-19 Yong Li <yoli@rim.com> 2 39 -
trunk/Source/JavaScriptCore/JavaScriptCore.pri
r78634 r79126 48 48 } else { 49 49 INCLUDEPATH = $$JAVASCRIPTCORE_INCLUDEPATH $$INCLUDEPATH 50 }51 52 symbian: {53 LIBS += -lhal54 # For hal.h55 INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE56 50 } 57 51 -
trunk/Source/JavaScriptCore/wtf/Bitmap.h
r78108 r79126 41 41 void clear(size_t); 42 42 void clearAll(); 43 int64_t findRunOfZeros(size_t) const; 43 44 size_t count(size_t = 0) const; 44 45 size_t isEmpty() const; … … 108 109 109 110 template<size_t size> 111 inline int64_t Bitmap<size>::findRunOfZeros(size_t runLength) const 112 { 113 if (!runLength) 114 runLength = 1; 115 116 for (size_t i = 0; i <= (size - runLength) ; i++) { 117 bool found = true; 118 for (size_t j = i; j <= (i + runLength - 1) ; j++) { 119 if (get(j)) { 120 found = false; 121 break; 122 } 123 } 124 if (found) 125 return i; 126 } 127 return -1; 128 } 129 130 template<size_t size> 110 131 inline size_t Bitmap<size>::count(size_t start) const 111 132 { -
trunk/Source/JavaScriptCore/wtf/OSAllocator.h
r74434 r79126 78 78 { 79 79 ASSERT(decommitBase >= releaseBase && (static_cast<char*>(decommitBase) + decommitSize) <= (static_cast<char*>(releaseBase) + releaseSize)); 80 #if OS(WINCE) 80 #if OS(WINCE) || OS(SYMBIAN) 81 81 // On most platforms we can actually skip this final decommit; releasing the VM will 82 82 // implicitly decommit any physical memory in the region. This is not true on WINCE. 83 // On Symbian, this makes implementation simpler and better aligned with the RChunk API 83 84 decommit(decommitBase, decommitSize); 84 85 #else -
trunk/Source/JavaScriptCore/wtf/OSAllocatorSymbian.cpp
r74520 r79126 1 1 /* 2 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 27 28 #include "OSAllocator.h" 28 29 29 #include <wtf/FastMalloc.h>30 #include "PageAllocatorSymbian.h" 30 31 31 32 namespace WTF { 32 33 33 void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool, bool) 34 { 35 return fastMalloc(bytes); 36 } 37 38 void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool, bool) 39 { 40 return fastMalloc(bytes); 41 } 42 43 void OSAllocator::commit(void*, size_t, bool, bool) 44 { 45 } 46 47 void OSAllocator::decommit(void*, size_t) 48 { 49 } 50 51 void OSAllocator::releaseDecommitted(void* address, size_t) 52 { 53 fastFree(address); 34 // Array to store code chunks used by JIT engine(s) 35 static RPointerArray<SymbianChunk> codeChunksContainer; 36 37 // The singleton data allocator (non code) 38 static PageAllocatorSymbian dataAllocator; 39 40 _LIT(KErrorStringInternalConsistency, "OSAllocator:ConsistencyError"); 41 _LIT(KErrorStringChunkCreation, "OSAllocator:ChunkInitError"); 42 _LIT(KErrorStringPageSize, "OSAllocator:WrongPageSize"); 43 44 // Makes a new code chunk for a JIT engine with everything in committed state 45 static void* allocateCodeChunk(size_t bytes) 46 { 47 RChunk c; 48 TInt error = c.CreateLocalCode(bytes, bytes); 49 __ASSERT_ALWAYS(error == KErrNone, User::Panic(KErrorStringChunkCreation, error)); 50 51 codeChunksContainer.Append(new SymbianChunk(c.Handle())); 52 return static_cast<void*>(c.Base()); 53 } 54 55 // Frees the _entire_ code chunk in which this address resides. 56 static bool deallocateCodeChunk(void* address) 57 { 58 bool found = false; 59 for (int i = 0; i < codeChunksContainer.Count(); i++) { 60 SymbianChunk* p = codeChunksContainer[i]; 61 if (p && p->contains(address)) { 62 codeChunksContainer.Remove(i); 63 delete p; 64 found = true; 65 } 66 } 67 return found; 68 } 69 70 // Return the (singleton) object that manages all non-code VM operations 71 static PageAllocatorSymbian* dataAllocatorInstance() 72 { 73 return &dataAllocator; 74 } 75 76 // Reserve memory and return the base address of the region 77 void* OSAllocator::reserveUncommitted(size_t reservationSize, Usage usage, bool , bool executable) 78 { 79 void* base = 0; 80 if (executable) 81 base = allocateCodeChunk(reservationSize); 82 else 83 base = dataAllocatorInstance()->reserve(reservationSize); 84 return base; 85 } 86 87 // Inverse operation of reserveUncommitted() 88 void OSAllocator::releaseDecommitted(void* parkedBase, size_t bytes) 89 { 90 if (dataAllocatorInstance()->contains(parkedBase)) 91 dataAllocatorInstance()->release(parkedBase, bytes); 92 93 // NOOP for code chunks (JIT) because we released them in decommit() 94 } 95 96 // Commit what was previously reserved via reserveUncommitted() 97 void OSAllocator::commit(void* address, size_t bytes, bool, bool executable) 98 { 99 // For code chunks, we commit (early) in reserveUncommitted(), so NOOP 100 // For data regions, do real work 101 if (!executable) 102 dataAllocatorInstance()->commit(address, bytes); 103 } 104 105 void OSAllocator::decommit(void* address, size_t bytes) 106 { 107 if (dataAllocatorInstance()->contains(address)) 108 dataAllocatorInstance()->decommit(address, bytes); 109 else 110 deallocateCodeChunk(address); // for code chunk, decommit AND release 111 } 112 113 void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable) 114 { 115 void* base = reserveUncommitted(bytes, usage, writable, executable); 116 commit(base, bytes, writable, executable); 117 return base; 118 } 119 120 121 // The PageAllocatorSymbian class helps map OSAllocator calls for reserve/commit/decommit 122 // to a single large Symbian chunk. Only works with multiples of page size, and as a corollary 123 // all addresses accepted or returned by it are also page-sized aligned. 124 // Design notes: 125 // - We initialize a chunk up-front with a large reservation size 126 // - The entire reservation reserve is logically divided into pageSized blocks (4K on Symbian) 127 // - The map maintains 1 bit for each of the 4K-sized region in our address space 128 // - OSAllocator::reserveUncommitted() requests lead to 1 or more bits being set in map 129 // to indicate internally reserved state. The VM address corresponding to the first bit is returned. 130 // - OSAllocator::commit() actually calls RChunk.commit() and commits *all or part* of the region 131 // reserved via reserveUncommitted() previously. 132 // - OSAllocator::decommit() calls RChunk.decommit() 133 // - OSAllocator::releaseDecommitted() unparks all the bits in the map, but trusts that a previously 134 // call to decommit() would have returned the memory to the OS 135 PageAllocatorSymbian::PageAllocatorSymbian() 136 { 137 __ASSERT_ALWAYS(m_pageSize == WTF::pageSize(), User::Panic(KErrorStringPageSize, m_pageSize)); 138 139 RChunk chunk; 140 TInt error = chunk.CreateDisconnectedLocal(0, 0, TInt(largeReservationSize)); 141 __ASSERT_ALWAYS(error == KErrNone, User::Panic(KErrorStringChunkCreation, error)); 142 143 m_chunk = new SymbianChunk(chunk.Handle()); // takes ownership of chunk 144 } 145 146 PageAllocatorSymbian::~PageAllocatorSymbian() 147 { 148 delete m_chunk; 149 } 150 151 // Reserves a region internally in the bitmap 152 void* PageAllocatorSymbian::reserve(size_t bytes) 153 { 154 // Find first available region 155 const size_t nPages = bytes / m_pageSize; 156 const int64_t startIdx = m_map.findRunOfZeros(nPages); 157 158 // Pseudo OOM 159 if (startIdx < 0) 160 return 0; 161 162 for (size_t i = startIdx; i < startIdx + nPages ; i++) 163 m_map.set(i); 164 165 return static_cast<void*>( m_chunk->m_base + (TUint)(m_pageSize * startIdx) ); 166 } 167 168 // Reverses the effects of a reserve() call 169 void PageAllocatorSymbian::release(void* address, size_t bytes) 170 { 171 const size_t startIdx = (static_cast<char*>(address) - m_chunk->m_base) / m_pageSize; 172 const size_t nPages = bytes / m_pageSize; 173 for (size_t i = startIdx; i < startIdx + nPages ; i++) 174 m_map.clear(i); 175 } 176 177 // Actually commit memory from the OS, after a previous call to reserve() 178 bool PageAllocatorSymbian::commit(void* address, size_t bytes) 179 { 180 // sanity check that bits were previously set 181 const size_t idx = (static_cast<char*>(address) - m_chunk->m_base) / m_pageSize; 182 const size_t nPages = bytes / m_pageSize; 183 __ASSERT_ALWAYS(m_map.get(idx), User::Panic(KErrorStringInternalConsistency, idx)); 184 __ASSERT_ALWAYS(m_map.get(idx+nPages-1), User::Panic(KErrorStringInternalConsistency, idx+nPages-1)); 185 186 TInt error = m_chunk->Commit(static_cast<char*>(address) - m_chunk->m_base, bytes); 187 return (error == KErrNone); 188 } 189 190 // Inverse operation of commit(), a release() should follow later 191 bool PageAllocatorSymbian::decommit(void* address, size_t bytes) 192 { 193 TInt error = m_chunk->Decommit(static_cast<char*>(address) - m_chunk->m_base, bytes); 194 return (error == KErrNone); 195 } 196 197 bool PageAllocatorSymbian::contains(const void* address) const 198 { 199 return m_chunk->contains(address); 54 200 } 55 201
Note: See TracChangeset
for help on using the changeset viewer.