Ignore:
Timestamp:
Mar 15, 2007, 10:12:59 PM (18 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Geoff and Steve.


  • fix some portability issues with TCMalloc.
  • JavaScriptCore.vcproj/WTF/WTF.vcproj:
  • kjs/config.h:
  • wtf/FastMalloc.cpp: (WTF::SizeClass): (WTF::InitSizeClasses): (WTF::TCMalloc_PageHeap::Split): (WTF::TCMalloc_PageHeap::RegisterSizeClass): (WTF::TCMalloc_Central_FreeList::length): (WTF::TCMalloc_ThreadCache::InitTSD): (WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
  • wtf/TCSpinLock.h:
  • wtf/TCSystemAlloc.cpp: (TryVirtualAlloc): (TCMalloc_SystemAlloc):

WebCore:

Reviewed by Geoff and Steve.

  • config.h: Remove unneeded hack.
File:
1 edited

Legend:

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

    r14256 r20229  
    3939#include <sys/types.h>
    4040#endif
    41 #if !PLATFORM(WIN_OS)
     41#if PLATFORM(WIN_OS)
     42#include "windows.h"
     43#else
    4244#include <unistd.h>
    4345#include <sys/mman.h>
     
    7476static bool use_sbrk = false;
    7577static bool use_mmap = true;
     78static bool use_VirtualAlloc = true;
    7679
    7780// Flags to keep us from retrying allocators that failed.
     
    7982static bool sbrk_failure = false;
    8083static bool mmap_failure = false;
     84static bool VirtualAlloc_failure = false;
    8185
    8286#ifndef WTF_CHANGES
     
    173177#endif /* HAVE(MMAP) */
    174178
     179#if HAVE(VIRTUALALLOC)
     180
     181static void* TryVirtualAlloc(size_t size, size_t alignment) {
     182  // Enforce page alignment
     183  if (pagesize == 0) {
     184    SYSTEM_INFO system_info;
     185    GetSystemInfo(&system_info);
     186    pagesize = system_info.dwPageSize;
     187  }
     188  if (alignment < pagesize) alignment = pagesize;
     189  size = ((size + alignment - 1) / alignment) * alignment;
     190
     191  // Ask for extra memory if alignment > pagesize
     192  size_t extra = 0;
     193  if (alignment > pagesize) {
     194    extra = alignment - pagesize;
     195  }
     196  void* result = VirtualAlloc(NULL, size + extra,
     197                              MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN,
     198                              PAGE_READWRITE);
     199
     200  if (result == NULL) {
     201    VirtualAlloc_failure = true;
     202    return NULL;
     203  }
     204
     205  // Adjust the return memory so it is aligned
     206  uintptr_t ptr = reinterpret_cast<uintptr_t>(result);
     207  size_t adjust = 0;
     208  if ((ptr & (alignment - 1)) != 0) {
     209    adjust = alignment - (ptr & (alignment - 1));
     210  }
     211
     212  // Return the unused memory to the system - we'd like to release but the best we can do
     213  // is decommit, since Windows only lets you free the whole allocation.
     214  if (adjust > 0) {
     215    VirtualFree(reinterpret_cast<void*>(ptr), adjust, MEM_DECOMMIT);
     216  }
     217  if (adjust < extra) {
     218    VirtualFree(reinterpret_cast<void*>(ptr + adjust + size), extra-adjust, MEM_DECOMMIT);
     219  }
     220
     221  ptr += adjust;
     222  return reinterpret_cast<void*>(ptr);
     223}
     224
     225#endif /* HAVE(MMAP) */
     226
    175227#ifndef WTF_CHANGES
    176228static void* TryDevMem(size_t size, size_t alignment) {
     
    283335#endif
    284336
     337#if HAVE(VIRTUALALLOC)
     338    if (use_VirtualAlloc && !VirtualAlloc_failure) {
     339      void* result = TryVirtualAlloc(size, alignment);
     340      if (result != NULL) return result;
     341    }
     342#endif
     343
    285344    // nothing worked - reset failure flags and try again
    286345    devmem_failure = false;
    287346    sbrk_failure = false;
    288347    mmap_failure = false;
     348    VirtualAlloc_failure = false;
    289349  }
    290350  return NULL;
Note: See TracChangeset for help on using the changeset viewer.