src/3rdparty/webkit/JavaScriptCore/runtime/Collector.cpp
changeset 22 79de32ba3296
parent 3 41300fa6a67c
child 30 5dc02b23752f
equal deleted inserted replaced
19:fcece45ef507 22:79de32ba3296
    50 #include <mach/mach_port.h>
    50 #include <mach/mach_port.h>
    51 #include <mach/task.h>
    51 #include <mach/task.h>
    52 #include <mach/thread_act.h>
    52 #include <mach/thread_act.h>
    53 #include <mach/vm_map.h>
    53 #include <mach/vm_map.h>
    54 
    54 
    55 #elif PLATFORM(SYMBIAN)
       
    56 #include <e32std.h>
       
    57 #include <e32cmn.h>
       
    58 #include <unistd.h>
       
    59 
       
    60 #elif PLATFORM(WIN_OS)
    55 #elif PLATFORM(WIN_OS)
    61 
    56 
    62 #include <windows.h>
    57 #include <windows.h>
    63 #include <malloc.h>
    58 #include <malloc.h>
    64 
    59 
   122 const size_t ALLOCATIONS_PER_COLLECTION = 4000;
   117 const size_t ALLOCATIONS_PER_COLLECTION = 4000;
   123 // This value has to be a macro to be used in max() without introducing
   118 // This value has to be a macro to be used in max() without introducing
   124 // a PIC branch in Mach-O binaries, see <rdar://problem/5971391>.
   119 // a PIC branch in Mach-O binaries, see <rdar://problem/5971391>.
   125 #define MIN_ARRAY_SIZE (static_cast<size_t>(14))
   120 #define MIN_ARRAY_SIZE (static_cast<size_t>(14))
   126 
   121 
   127 #if PLATFORM(SYMBIAN)
       
   128 const size_t MAX_NUM_BLOCKS = 256; // Max size of collector heap set to 16 MB
       
   129 static RHeap* userChunk = 0;
       
   130 #endif
       
   131 
       
   132 #if ENABLE(JSC_MULTIPLE_THREADS)
   122 #if ENABLE(JSC_MULTIPLE_THREADS)
   133 
   123 
   134 #if PLATFORM(DARWIN)
   124 #if PLATFORM(DARWIN)
   135 typedef mach_port_t PlatformThread;
   125 typedef mach_port_t PlatformThread;
   136 #elif PLATFORM(WIN_OS)
   126 #elif PLATFORM(WIN_OS)
   163 #if ENABLE(JSC_MULTIPLE_THREADS)
   153 #if ENABLE(JSC_MULTIPLE_THREADS)
   164     , m_registeredThreads(0)
   154     , m_registeredThreads(0)
   165     , m_currentThreadRegistrar(0)
   155     , m_currentThreadRegistrar(0)
   166 #endif
   156 #endif
   167     , m_globalData(globalData)
   157     , m_globalData(globalData)
       
   158 #if PLATFORM(SYMBIAN)
       
   159     , m_blockallocator(JSCCOLLECTOR_VIRTUALMEM_RESERVATION, BLOCK_SIZE)
       
   160 #endif
   168 {
   161 {
   169     ASSERT(globalData);
   162     ASSERT(globalData);
   170 
       
   171 #if PLATFORM(SYMBIAN)
       
   172     // Symbian OpenC supports mmap but currently not the MAP_ANON flag.
       
   173     // Using fastMalloc() does not properly align blocks on 64k boundaries
       
   174     // and previous implementation was flawed/incomplete.
       
   175     // UserHeap::ChunkHeap allows allocation of continuous memory and specification
       
   176     // of alignment value for (symbian) cells within that heap.
       
   177     //
       
   178     // Clarification and mapping of terminology:
       
   179     // RHeap (created by UserHeap::ChunkHeap below) is continuos memory chunk,
       
   180     // which can dynamically grow up to 8 MB,
       
   181     // that holds all CollectorBlocks of this session (static).
       
   182     // Each symbian cell within RHeap maps to a 64kb aligned CollectorBlock.
       
   183     // JSCell objects are maintained as usual within CollectorBlocks.
       
   184     if (!userChunk) {
       
   185         userChunk = UserHeap::ChunkHeap(0, 0, MAX_NUM_BLOCKS * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE);
       
   186         if (!userChunk)
       
   187             CRASH();
       
   188     }
       
   189 #endif // PLATFORM(SYMBIAN)
       
   190     
       
   191     memset(&primaryHeap, 0, sizeof(CollectorHeap));
   163     memset(&primaryHeap, 0, sizeof(CollectorHeap));
   192     memset(&numberHeap, 0, sizeof(CollectorHeap));
   164     memset(&numberHeap, 0, sizeof(CollectorHeap));
   193 }
   165 }
   194 
   166 
   195 Heap::~Heap()
   167 Heap::~Heap()
   231         Heap::Thread* next = t->next;
   203         Heap::Thread* next = t->next;
   232         delete t;
   204         delete t;
   233         t = next;
   205         t = next;
   234     }
   206     }
   235 #endif
   207 #endif
   236 
   208 #if PLATFORM(SYMBIAN)
       
   209     m_blockallocator.destroy();
       
   210 #endif
   237     m_globalData = 0;
   211     m_globalData = 0;
   238 }
   212 }
   239 
   213 
   240 template <HeapType heapType>
   214 template <HeapType heapType>
   241 NEVER_INLINE CollectorBlock* Heap::allocateBlock()
   215 NEVER_INLINE CollectorBlock* Heap::allocateBlock()
   245 #if PLATFORM(DARWIN) && !PLATFORM(QT)
   219 #if PLATFORM(DARWIN) && !PLATFORM(QT)
   246     vm_address_t address = 0;
   220     vm_address_t address = 0;
   247     // FIXME: tag the region as a JavaScriptCore heap when we get a registered VM tag: <rdar://problem/6054788>.
   221     // FIXME: tag the region as a JavaScriptCore heap when we get a registered VM tag: <rdar://problem/6054788>.
   248     vm_map(current_task(), &address, BLOCK_SIZE, BLOCK_OFFSET_MASK, VM_FLAGS_ANYWHERE | VM_TAG_FOR_COLLECTOR_MEMORY, MEMORY_OBJECT_NULL, 0, FALSE, VM_PROT_DEFAULT, VM_PROT_DEFAULT, VM_INHERIT_DEFAULT);
   222     vm_map(current_task(), &address, BLOCK_SIZE, BLOCK_OFFSET_MASK, VM_FLAGS_ANYWHERE | VM_TAG_FOR_COLLECTOR_MEMORY, MEMORY_OBJECT_NULL, 0, FALSE, VM_PROT_DEFAULT, VM_PROT_DEFAULT, VM_INHERIT_DEFAULT);
   249 #elif PLATFORM(SYMBIAN)
   223 #elif PLATFORM(SYMBIAN)
   250     // Allocate a 64 kb aligned CollectorBlock
   224     void* address = m_blockallocator.alloc();  
   251     unsigned char* mask = reinterpret_cast<unsigned char*>(userChunk->Alloc(BLOCK_SIZE));
   225     if (!address)
   252     if (!mask)
       
   253         CRASH();
   226         CRASH();
   254     uintptr_t address = reinterpret_cast<uintptr_t>(mask);
       
   255 
       
   256     memset(reinterpret_cast<void*>(address), 0, BLOCK_SIZE);
   227     memset(reinterpret_cast<void*>(address), 0, BLOCK_SIZE);
   257 #elif PLATFORM(WINCE)
   228 #elif PLATFORM(WINCE)
   258     void* address = VirtualAlloc(NULL, BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
   229     void* address = VirtualAlloc(NULL, BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
   259 #elif PLATFORM(WIN_OS)
   230 #elif PLATFORM(WIN_OS)
   260 #if COMPILER(MINGW)
   231 #if COMPILER(MINGW)
   337     // Disable the use of vm_deallocate for the Qt build on Darwin, because when compiled on 10.4
   308     // Disable the use of vm_deallocate for the Qt build on Darwin, because when compiled on 10.4
   338     // it crashes on 10.5
   309     // it crashes on 10.5
   339 #if PLATFORM(DARWIN) && !PLATFORM(QT)
   310 #if PLATFORM(DARWIN) && !PLATFORM(QT)
   340     vm_deallocate(current_task(), reinterpret_cast<vm_address_t>(block), BLOCK_SIZE);
   311     vm_deallocate(current_task(), reinterpret_cast<vm_address_t>(block), BLOCK_SIZE);
   341 #elif PLATFORM(SYMBIAN)
   312 #elif PLATFORM(SYMBIAN)
   342     userChunk->Free(reinterpret_cast<TAny*>(block));
   313     m_blockallocator.free(reinterpret_cast<void*>(block));
   343 #elif PLATFORM(WINCE)
   314 #elif PLATFORM(WINCE)
   344     VirtualFree(block, 0, MEM_RELEASE);
   315     VirtualFree(block, 0, MEM_RELEASE);
   345 #elif PLATFORM(WIN_OS)
   316 #elif PLATFORM(WIN_OS)
   346 #if COMPILER(MINGW)
   317 #if COMPILER(MINGW)
   347     __mingw_aligned_free(block);
   318     __mingw_aligned_free(block);