Ignore:
Timestamp:
Jul 6, 2007, 5:09:08 AM (18 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Antti.

  • <rdar://problem/5311093> JavaScriptCore fails to build with strict-aliasing warnings


  • Configurations/Base.xcconfig: Re-enable -Wstrict-aliasing
  • bindings/jni/jni_utility.cpp: (KJS::Bindings::getJNIEnv): Type-pun via a union instead of a pointer cast.
  • wtf/HashMap.h: (WTF::): Instead of doing type-punned assignments via pointer cast, do one of three things: (1) assign directly w/o cast if storage type matches real type; (2) assign using cast via union if type does not need reffing; (3) copy with memcpy and ref/deref manually if type needs reffing. This is ok peref-wise because memcpy of a constant length gets optomized. HashTraits are now expected to make ref()/deref() take the storage type, not the true type.
  • wtf/HashSet.h: (WTF::): Same basic idea.
  • wtf/HashTable.h: (WTF::): Added Assigner template for use by HashMap/HashSet. Change RefCounter to call ref() and deref() via storage type, avoiding the need to type-pun. (WTF::RefCounter::ref): ditto (WTF::RefCounter::deref): ditto
  • wtf/HashTraits.h: (WTF::): Change ref() and deref() for RefPtr HashTraits to take the storage type; cast via union to pointer type.
  • wtf/FastMalloc.cpp: (WTF::TCMalloc_PageHeap::init): Changed from constructor to init function so this can go in a union. (WTF::): redefine pageheap macro in terms of getPageHeap(). (WTF::getPageHeap): new inline function, helper for pageheap macro. This hides the cast in a union. (WTF::TCMalloc_ThreadCache::InitModule): Call init() instead of using placement new to initialize page heap.
  • wtf/TCPageMap.h: (TCMalloc_PageMap1::init): Changed from constructor to init function. (TCMalloc_PageMap2::init): ditto (TCMalloc_PageMap3::init): ditto

WebCore:

Reviewed by Antti.

  • <rdar://problem/5311093> JavaScriptCore fails to build with strict-aliasing warnings
  • platform/StringHash.h: (WTF::): Adapt to newer way to do storage types.
File:
1 edited

Legend:

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

    r23515 r24059  
    677677class TCMalloc_PageHeap {
    678678 public:
    679   TCMalloc_PageHeap();
     679  void init();
    680680
    681681  // Allocate a run of "n" pages.  Returns zero if out of memory.
     
    758758};
    759759
    760 TCMalloc_PageHeap::TCMalloc_PageHeap() : pagemap_(MetaDataAlloc),
    761                                          free_pages_(0),
    762                                          system_bytes_(0) {
     760void TCMalloc_PageHeap::init()
     761{
     762  pagemap_.init(MetaDataAlloc);
     763  free_pages_ = 0;
     764  system_bytes_ = 0;
     765 
    763766  DLL_Init(&large_);
    764767  for (size_t i = 0; i < kMaxPages; i++) {
     
    11741177// Avoid extra level of indirection by making "pageheap" be just an alias
    11751178// of pageheap_memory.
    1176 #define pageheap ((TCMalloc_PageHeap*) pageheap_memory)
     1179
     1180typedef union {
     1181    void* m_memory;
     1182    TCMalloc_PageHeap m_pageHeap;
     1183} PageHeapUnion;
     1184
     1185static inline TCMalloc_PageHeap* getPageHeap()
     1186{
     1187    return &reinterpret_cast<PageHeapUnion*>(&pageheap_memory[0])->m_pageHeap;
     1188}
     1189
     1190#define pageheap getPageHeap()
    11771191
    11781192// Thread-specific key.  Initialization here is somewhat tricky
     
    15441558      central_cache[i].Init(i);
    15451559    }
    1546     new ((void*)pageheap_memory) TCMalloc_PageHeap;
     1560    pageheap->init();
    15471561    phinited = 1;
    15481562  }
Note: See TracChangeset for help on using the changeset viewer.