X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..1df5f87f1309a8daa30dabdee855f48ae40d14ab:/interpreter/RegisterFile.cpp diff --git a/interpreter/RegisterFile.cpp b/interpreter/RegisterFile.cpp index 50698f5..e3b34bb 100644 --- a/interpreter/RegisterFile.cpp +++ b/interpreter/RegisterFile.cpp @@ -29,17 +29,73 @@ #include "config.h" #include "RegisterFile.h" +#include "ConservativeRoots.h" +#include "Interpreter.h" +#include "JSGlobalData.h" +#include "JSGlobalObject.h" + namespace JSC { +static size_t committedBytesCount = 0; + +static Mutex& registerFileStatisticsMutex() +{ + DEFINE_STATIC_LOCAL(Mutex, staticMutex, ()); + return staticMutex; +} + RegisterFile::~RegisterFile() { -#if HAVE(MMAP) - munmap(m_buffer, ((m_max - m_start) + m_maxGlobals) * sizeof(Register)); -#elif HAVE(VIRTUALALLOC) - VirtualFree(m_buffer, 0, MEM_RELEASE); -#else - #error "Don't know how to release virtual memory on this platform." -#endif + void* base = m_reservation.base(); + m_reservation.decommit(base, reinterpret_cast(m_commitEnd) - reinterpret_cast(base)); + addToCommittedByteCount(-(reinterpret_cast(m_commitEnd) - reinterpret_cast(base))); + m_reservation.deallocate(); +} + +void RegisterFile::gatherConservativeRoots(ConservativeRoots& conservativeRoots) +{ + for (Register* it = start(); it != end(); ++it) { + JSValue v = it->jsValue(); + if (!v.isCell()) + continue; + conservativeRoots.add(v.asCell()); + } +} + +void RegisterFile::releaseExcessCapacity() +{ + m_reservation.decommit(m_start, reinterpret_cast(m_commitEnd) - reinterpret_cast(m_start)); + addToCommittedByteCount(-(reinterpret_cast(m_commitEnd) - reinterpret_cast(m_start))); + m_commitEnd = m_start; + m_maxUsed = m_start; +} + +void RegisterFile::setGlobalObject(JSGlobalObject* globalObject) +{ + m_globalObject.set(globalObject->globalData(), globalObject, &m_globalObjectOwner, this); +} + +JSGlobalObject* RegisterFile::globalObject() +{ + return m_globalObject.get(); +} + +void RegisterFile::initializeThreading() +{ + registerFileStatisticsMutex(); +} + +size_t RegisterFile::committedByteCount() +{ + MutexLocker locker(registerFileStatisticsMutex()); + return committedBytesCount; +} + +void RegisterFile::addToCommittedByteCount(long byteCount) +{ + MutexLocker locker(registerFileStatisticsMutex()); + ASSERT(static_cast(committedBytesCount) + byteCount > -1); + committedBytesCount += byteCount; } } // namespace JSC