Changeset 34838 in webkit for trunk/JavaScriptCore/VM/RegisterFile.cpp
- Timestamp:
- Jun 27, 2008, 3:35:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/RegisterFile.cpp
r34372 r34838 30 30 #include "RegisterFile.h" 31 31 32 #include "RegisterFileStack.h"33 #include "Register.h"34 35 using namespace std;36 37 32 namespace KJS { 38 33 39 size_t RegisterFile::newBuffer(size_t size, size_t capacity, size_t minCapacity, size_t maxSize, size_t offset)34 RegisterFile::~RegisterFile() 40 35 { 41 capacity = (max(minCapacity, min(maxSize, max<size_t>(16, capacity + capacity / 4 + 1)))); 42 Register* newBuffer = static_cast<Register*>(fastCalloc(capacity, sizeof(Register))); // zero-filled memory 43 44 if (m_buffer) 45 memcpy(newBuffer + offset, m_buffer, size * sizeof(Register)); 46 47 setBuffer(newBuffer); 48 return capacity; 49 } 50 51 bool RegisterFile::growBuffer(size_t minCapacity, size_t maxSize) 52 { 53 if (minCapacity > m_maxSize) 54 return false; 55 56 size_t numGlobalSlots = this->numGlobalSlots(); 57 size_t size = m_size + numGlobalSlots; 58 size_t capacity = m_capacity + numGlobalSlots; 59 minCapacity += numGlobalSlots; 60 61 capacity = newBuffer(size, capacity, minCapacity, maxSize, 0); 62 63 setBase(m_buffer + numGlobalSlots); 64 m_capacity = capacity - numGlobalSlots; 65 return true; 66 } 67 68 void RegisterFile::addGlobalSlots(size_t count) 69 { 70 if (!count) 71 return; 72 ASSERT(safeForReentry()); 73 size_t numGlobalSlots = this->numGlobalSlots(); 74 size_t size = m_size + numGlobalSlots; 75 size_t capacity = m_capacity + numGlobalSlots; 76 size_t minCapacity = size + count; 77 78 if (minCapacity < capacity) 79 memmove(m_buffer + count, m_buffer, size * sizeof(Register)); 80 else 81 capacity = newBuffer(size, capacity, minCapacity, m_maxSize, count); 82 83 numGlobalSlots += count; 84 85 setBase(m_buffer + numGlobalSlots); 86 m_capacity = capacity - numGlobalSlots; 87 } 88 89 void RegisterFile::copyGlobals(RegisterFile* src) 90 { 91 ASSERT(src->numGlobalSlots() > 0); // Global code should always allocate at least a "this" slot. 92 size_t numSlotsToCopy = src->numGlobalSlots() - 1; // Don't propogate the nested "this" value back to the parent register file. 93 if (!numSlotsToCopy) 94 return; 95 memcpy(m_buffer, src->m_buffer, numSlotsToCopy * sizeof(Register)); 96 } 97 98 void RegisterFile::setBase(Register* base) 99 { 100 m_base = base; 101 if (m_baseObserver) 102 m_baseObserver->baseChanged(this); 103 } 104 105 void RegisterFile::clear() 106 { 107 setBase(m_buffer); 108 m_size = 0; 36 #if HAVE(MMAP) 37 munmap(m_buffer, m_capacity + m_maxGlobals); 38 #elif HAVE(VIRTUALALLOC) 39 // FIXME: Use VirtualFree. 40 fastFree(m_buffer); 41 #else 42 #error "Don't know how to release virtual memory on this platform." 43 #endif 109 44 } 110 45
Note:
See TracChangeset
for help on using the changeset viewer.