Ignore:
Timestamp:
Jul 28, 2009, 6:09:02 PM (16 years ago)
Author:
[email protected]
Message:

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=27236

  • Implement TCMalloc_SystemRelease and TCMalloc_SystemCommit for Windows.
  • Use a background thread to periodically scavenge memory to release back to the system.
  • wtf/FastMalloc.cpp: (WTF::TCMalloc_PageHeap::init): (WTF::TCMalloc_PageHeap::runScavengerThread): (WTF::TCMalloc_PageHeap::scavenge): (WTF::TCMalloc_PageHeap::shouldContinueScavenging): (WTF::TCMalloc_PageHeap::New): (WTF::TCMalloc_PageHeap::AllocLarge): (WTF::TCMalloc_PageHeap::Delete): (WTF::TCMalloc_PageHeap::GrowHeap): (WTF::sleep): (WTF::TCMalloc_PageHeap::scavengerThread):
  • wtf/TCSystemAlloc.cpp: (TCMalloc_SystemRelease): (TCMalloc_SystemCommit):
  • wtf/TCSystemAlloc.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/TCSystemAlloc.cpp

    r43988 r46511  
    3232
    3333#include "config.h"
     34#include "TCSystemAlloc.h"
     35
     36#include <algorithm>
     37#include <fcntl.h>
     38#include "Assertions.h"
     39#include "TCSpinLock.h"
     40#include "UnusedParam.h"
     41
    3442#if HAVE(STDINT_H)
    3543#include <stdint.h>
     
    3947#include <sys/types.h>
    4048#endif
     49
    4150#if PLATFORM(WIN_OS)
    4251#include "windows.h"
     
    4655#include <sys/mman.h>
    4756#endif
    48 #include <fcntl.h>
    49 #include "Assertions.h"
    50 #include "TCSystemAlloc.h"
    51 #include "TCSpinLock.h"
    52 #include "UnusedParam.h"
    5357
    5458#ifndef MAP_ANONYMOUS
    5559#define MAP_ANONYMOUS MAP_ANON
    5660#endif
     61
     62using namespace std;
    5763
    5864// Structure for discovering alignment
     
    442448}
    443449
     450#elif HAVE(VIRTUALALLOC)
     451
     452void TCMalloc_SystemRelease(void* start, size_t length)
     453{
     454    if (VirtualFree(start, length, MEM_DECOMMIT))
     455        return;
     456
     457    // The decommit may fail if the memory region consists of allocations
     458    // from more than one call to VirtualAlloc.  In this case, fall back to
     459    // using VirtualQuery to retrieve the allocation boundaries and decommit
     460    // them each individually.
     461
     462    char* ptr = static_cast<char*>(start);
     463    char* end = ptr + length;
     464    MEMORY_BASIC_INFORMATION info;
     465    while (ptr < end) {
     466        size_t resultSize = VirtualQuery(ptr, &info, sizeof(info));
     467        ASSERT_UNUSED(resultSize, resultSize == sizeof(info));
     468
     469        size_t decommitSize = min<size_t>(info.RegionSize, end - ptr);
     470        BOOL success = VirtualFree(ptr, decommitSize, MEM_DECOMMIT);
     471        ASSERT_UNUSED(success, success);
     472        ptr += decommitSize;
     473    }
     474}
     475
    444476#else
    445477
     
    458490#elif HAVE(VIRTUALALLOC)
    459491
    460 void TCMalloc_SystemCommit(void*, size_t)
     492void TCMalloc_SystemCommit(void* start, size_t length)
    461493{
     494    if (VirtualAlloc(start, length, MEM_COMMIT, PAGE_READWRITE) == start)
     495        return;
     496
     497    // The commit may fail if the memory region consists of allocations
     498    // from more than one call to VirtualAlloc.  In this case, fall back to
     499    // using VirtualQuery to retrieve the allocation boundaries and commit them
     500    // each individually.
     501
     502    char* ptr = static_cast<char*>(start);
     503    char* end = ptr + length;
     504    MEMORY_BASIC_INFORMATION info;
     505    while (ptr < end) {
     506        size_t resultSize = VirtualQuery(ptr, &info, sizeof(info));
     507        ASSERT_UNUSED(resultSize, resultSize == sizeof(info));
     508
     509        size_t commitSize = min<size_t>(info.RegionSize, end - ptr);
     510        void* newAddress = VirtualAlloc(ptr, commitSize, MEM_COMMIT, PAGE_READWRITE);
     511        ASSERT_UNUSED(newAddress, newAddress == ptr);
     512        ptr += commitSize;
     513    }
    462514}
    463515
Note: See TracChangeset for help on using the changeset viewer.