#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<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(base));
+ addToCommittedByteCount(-(reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(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<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(m_start));
+ addToCommittedByteCount(-(reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(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<long>(committedBytesCount) + byteCount > -1);
+ committedBytesCount += byteCount;
}
} // namespace JSC