Changeset 20229 in webkit for trunk/JavaScriptCore/wtf


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.
Location:
trunk/JavaScriptCore/wtf
Files:
3 edited

Legend:

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

    r20026 r20229  
    190190#include <stdio.h>
    191191#include <string.h>
    192 #include <unistd.h>
    193192
    194193#if WTF_CHANGES
     
    329328#endif
    330329
    331 static inline int SizeClass(size_t size) {
     330static inline size_t SizeClass(size_t size) {
    332331  if (size == 0) size = 1;
    333332  const int lg = LgFloor(size);
    334333  const int align = size_shift[lg];
    335   return static_cast<int>(size_base[lg]) + ((size-1) >> align);
     334  return size_base[lg] + ((size-1) >> align);
    336335}
    337336
     
    350349
    351350  size_t next_class = 1;
    352   int alignshift = kAlignShift;
     351  unsigned char alignshift = kAlignShift;
    353352  int last_lg = -1;
    354353  for (size_t size = kAlignment; size <= kMaxSize; size += (1 << alignshift)) {
     
    365364        alignshift++;
    366365      }
    367       size_base[lg] = next_class - ((size-1) >> alignshift);
     366      size_base[lg] = static_cast<unsigned char>(next_class - ((size-1) >> alignshift));
    368367      size_shift[lg] = alignshift;
    369368    }
     
    819818  Event(span, 'T', n);
    820819
    821   const int extra = span->length - n;
     820  const Length extra = span->length - n;
    822821  Span* leftover = NewSpan(span->start + n, extra);
    823822  Event(leftover, 'U', extra);
     
    909908  ASSERT(GetDescriptor(span->start+span->length-1) == span);
    910909  Event(span, 'C', sc);
    911   span->sizeclass = sc;
     910  span->sizeclass = static_cast<unsigned int>(sc);
    912911  for (Length i = 1; i < span->length-1; i++) {
    913912    pagemap_.set(span->start+i, span);
     
    11421141  // REQUIRES: lock_ is held
    11431142  // Number of free objects in cache
    1144   int length() const { return counter_; }
     1143  size_t length() const { return counter_; }
    11451144
    11461145  // Lock -- exposed because caller grabs it before touching this object
     
    15651564#endif
    15661565  for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) {
    1567     if (h->tid_ == zero) {
     1566    if (pthread_equal(h->tid_, zero)) {
    15681567      h->tid_ = pthread_self();
    15691568    }
     
    15891588    // and added to the linked list.  So we search for that first.
    15901589    for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) {
    1591       if (h->tid_ == me) {
     1590      if (pthread_equal(h->tid_, me)) {
    15921591        heap = h;
    15931592        break;
  • trunk/JavaScriptCore/wtf/TCSpinLock.h

    r19245 r20229  
    3535
    3636#include "config.h"
     37
     38#if (PLATFORM(X86) || PLATFORM(PPC)) && COMPILER(GCC)
     39
    3740#include <time.h>       /* For nanosleep() */
     41
    3842#include <sched.h>      /* For sched_yield() */
     43
    3944#if HAVE(STDINT_H)
    4045#include <stdint.h>
     
    4651#include <stdlib.h>     /* for abort() */
    4752
    48 #if (PLATFORM(X86) || PLATFORM(PPC)) && COMPILER(GCC)
    4953static void TCMalloc_SlowLock(volatile unsigned int* lockword);
    5054
  • 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.