Changeset 79126 in webkit


Ignore:
Timestamp:
Feb 19, 2011 10:05:16 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-02-19 Siddharth Mathur <siddharth.mathur@nokia.com>

Reviewed by Laszlo Gombos.

[Symbian] OSAllocator implementation for Symbian OS.
Manages both data and code region requests. V8 and Sunspider tested
OK with interpreter. Not tested with JSC JIT yet as it has unrelated
failures. Also no thread safety yet.
https://bugs.webkit.org/show_bug.cgi?id=51128

  • JavaScriptCore.pri: removed HAL linkage
  • wtf/Bitmap.h: (WTF::::findRunOfZeros): find run of zeros in a bitmap. quick n dirty
  • wtf/OSAllocator.h: (WTF::OSAllocator::decommitAndRelease): decommit explicitly
  • wtf/OSAllocatorSymbian.cpp: Impl. of OSAllocator interface (WTF::allocateCodeChunk): utility for code chunks (WTF::deallocateCodeChunk): utility for code chunks (WTF::dataAllocatorInstance): getter for data allocator instance (WTF::OSAllocator::reserveUncommitted): (WTF::OSAllocator::releaseDecommitted): (WTF::OSAllocator::commit): (WTF::OSAllocator::decommit): (WTF::OSAllocator::reserveAndCommit): (WTF::PageAllocatorSymbian::PageAllocatorSymbian): maps requests to one underlying Symbian chunk (WTF::PageAllocatorSymbian::~PageAllocatorSymbian): (WTF::PageAllocatorSymbian::reserve): (WTF::PageAllocatorSymbian::release): (WTF::PageAllocatorSymbian::commit): (WTF::PageAllocatorSymbian::decommit): (WTF::PageAllocatorSymbian::contains):
  • wtf/PageAllocatorSymbian.h: Added. (WTF::SymbianChunk::SymbianChunk): wrapper around RChunk (WTF::SymbianChunk::~SymbianChunk): (WTF::SymbianChunk::contains):
Location:
trunk/Source/JavaScriptCore
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r79124 r79126  
     12011-02-19  Siddharth Mathur  <siddharth.mathur@nokia.com>
     2
     3        Reviewed by Laszlo Gombos.
     4
     5        [Symbian] OSAllocator implementation for Symbian OS.
     6        Manages both data and code region requests. V8 and Sunspider tested
     7        OK with interpreter. Not tested with JSC JIT yet as it has unrelated
     8        failures. Also no thread safety yet.
     9        https://bugs.webkit.org/show_bug.cgi?id=51128
     10
     11        * JavaScriptCore.pri: removed HAL linkage
     12        * wtf/Bitmap.h:
     13        (WTF::::findRunOfZeros): find run of zeros in a bitmap. quick n dirty
     14        * wtf/OSAllocator.h:
     15        (WTF::OSAllocator::decommitAndRelease): decommit explicitly
     16        * wtf/OSAllocatorSymbian.cpp: Impl. of OSAllocator interface
     17        (WTF::allocateCodeChunk): utility for code chunks
     18        (WTF::deallocateCodeChunk): utility for code chunks
     19        (WTF::dataAllocatorInstance): getter for data allocator instance
     20        (WTF::OSAllocator::reserveUncommitted):
     21        (WTF::OSAllocator::releaseDecommitted):
     22        (WTF::OSAllocator::commit):
     23        (WTF::OSAllocator::decommit):
     24        (WTF::OSAllocator::reserveAndCommit):
     25        (WTF::PageAllocatorSymbian::PageAllocatorSymbian): maps requests
     26        to one underlying Symbian chunk
     27        (WTF::PageAllocatorSymbian::~PageAllocatorSymbian):
     28        (WTF::PageAllocatorSymbian::reserve):
     29        (WTF::PageAllocatorSymbian::release):
     30        (WTF::PageAllocatorSymbian::commit):
     31        (WTF::PageAllocatorSymbian::decommit):
     32        (WTF::PageAllocatorSymbian::contains):
     33        * wtf/PageAllocatorSymbian.h: Added.
     34        (WTF::SymbianChunk::SymbianChunk): wrapper around RChunk 
     35        (WTF::SymbianChunk::~SymbianChunk):
     36        (WTF::SymbianChunk::contains):
     37       
    1382011-02-19  Yong Li  <yoli@rim.com>
    239
  • trunk/Source/JavaScriptCore/JavaScriptCore.pri

    r78634 r79126  
    4848} else {
    4949    INCLUDEPATH = $$JAVASCRIPTCORE_INCLUDEPATH $$INCLUDEPATH
    50 }
    51 
    52 symbian: {
    53     LIBS += -lhal
    54     # For hal.h
    55     INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE
    5650}
    5751
  • trunk/Source/JavaScriptCore/wtf/Bitmap.h

    r78108 r79126  
    4141    void clear(size_t);
    4242    void clearAll();
     43    int64_t findRunOfZeros(size_t) const;
    4344    size_t count(size_t = 0) const;
    4445    size_t isEmpty() const;
     
    108109
    109110template<size_t size>
     111inline int64_t Bitmap<size>::findRunOfZeros(size_t runLength) const
     112{
     113    if (!runLength)
     114        runLength = 1;
     115     
     116    for (size_t i = 0; i <= (size - runLength) ; i++) {
     117        bool found = true;
     118        for (size_t j = i; j <= (i + runLength - 1) ; j++) {
     119            if (get(j)) {
     120                found = false;
     121                break;
     122            }
     123        }
     124        if (found) 
     125            return i;
     126    }
     127    return -1;
     128}
     129
     130template<size_t size>
    110131inline size_t Bitmap<size>::count(size_t start) const
    111132{
  • trunk/Source/JavaScriptCore/wtf/OSAllocator.h

    r74434 r79126  
    7878{
    7979    ASSERT(decommitBase >= releaseBase && (static_cast<char*>(decommitBase) + decommitSize) <= (static_cast<char*>(releaseBase) + releaseSize));
    80 #if OS(WINCE)
     80#if OS(WINCE) || OS(SYMBIAN)
    8181    // On most platforms we can actually skip this final decommit; releasing the VM will
    8282    // implicitly decommit any physical memory in the region. This is not true on WINCE.
     83    // On Symbian, this makes implementation simpler and better aligned with the RChunk API
    8384    decommit(decommitBase, decommitSize);
    8485#else
  • trunk/Source/JavaScriptCore/wtf/OSAllocatorSymbian.cpp

    r74520 r79126  
    11/*
    22 * Copyright (C) 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#include "OSAllocator.h"
    2829
    29 #include <wtf/FastMalloc.h>
     30#include "PageAllocatorSymbian.h"
    3031
    3132namespace WTF {
    3233
    33 void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool, bool)
    34 {
    35     return fastMalloc(bytes);
    36 }
    37 
    38 void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool, bool)
    39 {
    40     return fastMalloc(bytes);
    41 }
    42 
    43 void OSAllocator::commit(void*, size_t, bool, bool)
    44 {
    45 }
    46 
    47 void OSAllocator::decommit(void*, size_t)
    48 {
    49 }
    50 
    51 void OSAllocator::releaseDecommitted(void* address, size_t)
    52 {
    53     fastFree(address);
     34// Array to store code chunks used by JIT engine(s)
     35static RPointerArray<SymbianChunk> codeChunksContainer;
     36
     37// The singleton data allocator (non code)
     38static PageAllocatorSymbian dataAllocator;
     39
     40_LIT(KErrorStringInternalConsistency, "OSAllocator:ConsistencyError");
     41_LIT(KErrorStringChunkCreation, "OSAllocator:ChunkInitError");
     42_LIT(KErrorStringPageSize, "OSAllocator:WrongPageSize");
     43
     44// Makes a new code chunk for a JIT engine with everything in committed state
     45static void* allocateCodeChunk(size_t bytes)
     46{
     47    RChunk c;
     48    TInt error = c.CreateLocalCode(bytes, bytes);
     49    __ASSERT_ALWAYS(error == KErrNone, User::Panic(KErrorStringChunkCreation, error));
     50   
     51    codeChunksContainer.Append(new SymbianChunk(c.Handle()));
     52    return static_cast<void*>(c.Base());
     53}
     54   
     55// Frees the _entire_ code chunk in which this address resides.
     56static bool deallocateCodeChunk(void* address)
     57{     
     58    bool found = false;
     59    for (int i = 0; i < codeChunksContainer.Count(); i++) {
     60        SymbianChunk* p = codeChunksContainer[i];
     61        if (p && p->contains(address)) {
     62            codeChunksContainer.Remove(i);
     63            delete p;
     64            found = true;
     65        }
     66    }
     67    return found;
     68}
     69
     70// Return the (singleton) object that manages all non-code VM operations
     71static PageAllocatorSymbian* dataAllocatorInstance()
     72{
     73    return &dataAllocator;
     74}
     75
     76// Reserve memory and return the base address of the region
     77void* OSAllocator::reserveUncommitted(size_t reservationSize, Usage usage, bool , bool executable)
     78{
     79    void* base = 0;
     80    if (executable)
     81        base = allocateCodeChunk(reservationSize);
     82    else
     83        base = dataAllocatorInstance()->reserve(reservationSize);
     84    return base;
     85}
     86
     87// Inverse operation of reserveUncommitted()
     88void OSAllocator::releaseDecommitted(void* parkedBase, size_t bytes)
     89{
     90    if (dataAllocatorInstance()->contains(parkedBase))
     91        dataAllocatorInstance()->release(parkedBase, bytes);
     92
     93    // NOOP for code chunks (JIT) because we released them in decommit()
     94}
     95
     96// Commit what was previously reserved via reserveUncommitted()
     97void OSAllocator::commit(void* address, size_t bytes, bool, bool executable)
     98{
     99    // For code chunks, we commit (early) in reserveUncommitted(), so NOOP
     100    // For data regions, do real work
     101    if (!executable)
     102        dataAllocatorInstance()->commit(address, bytes);
     103}
     104
     105void OSAllocator::decommit(void* address, size_t bytes)
     106{
     107    if (dataAllocatorInstance()->contains(address))
     108        dataAllocatorInstance()->decommit(address, bytes);
     109    else
     110        deallocateCodeChunk(address); // for code chunk, decommit AND release   
     111}
     112   
     113void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable)
     114{
     115    void* base = reserveUncommitted(bytes, usage, writable, executable);
     116    commit(base, bytes, writable, executable);
     117    return base;
     118}
     119
     120
     121// The PageAllocatorSymbian class helps map OSAllocator calls for reserve/commit/decommit
     122// to a single large Symbian chunk. Only works with multiples of page size, and as a corollary
     123// all addresses accepted or returned by it are also page-sized aligned.
     124// Design notes:
     125// - We initialize a chunk up-front with a large reservation size
     126// - The entire reservation reserve is logically divided into pageSized blocks (4K on Symbian)
     127// - The map maintains 1 bit for each of the 4K-sized region in our address space
     128// - OSAllocator::reserveUncommitted() requests lead to 1 or more bits being set in map
     129//   to indicate internally reserved state. The VM address corresponding to the first bit is returned.
     130// - OSAllocator::commit() actually calls RChunk.commit() and commits *all or part* of the region
     131//   reserved via reserveUncommitted() previously.
     132// - OSAllocator::decommit() calls RChunk.decommit()
     133// - OSAllocator::releaseDecommitted() unparks all the bits in the map, but trusts that a previously
     134//   call to decommit() would have returned the memory to the OS
     135PageAllocatorSymbian::PageAllocatorSymbian()
     136{       
     137    __ASSERT_ALWAYS(m_pageSize == WTF::pageSize(), User::Panic(KErrorStringPageSize, m_pageSize));
     138   
     139    RChunk chunk;
     140    TInt error = chunk.CreateDisconnectedLocal(0, 0, TInt(largeReservationSize));
     141    __ASSERT_ALWAYS(error == KErrNone, User::Panic(KErrorStringChunkCreation, error));
     142   
     143    m_chunk = new SymbianChunk(chunk.Handle()); // takes ownership of chunk
     144}
     145
     146PageAllocatorSymbian::~PageAllocatorSymbian()
     147{
     148    delete m_chunk;
     149}
     150
     151// Reserves a region internally in the bitmap
     152void* PageAllocatorSymbian::reserve(size_t bytes)
     153{
     154    // Find first available region
     155    const size_t nPages = bytes / m_pageSize;
     156    const int64_t startIdx = m_map.findRunOfZeros(nPages);
     157
     158    // Pseudo OOM
     159    if (startIdx < 0)
     160        return 0;
     161   
     162    for (size_t i = startIdx; i < startIdx + nPages ; i++)
     163        m_map.set(i);
     164   
     165    return static_cast<void*>( m_chunk->m_base + (TUint)(m_pageSize * startIdx) );
     166}
     167
     168// Reverses the effects of a reserve() call
     169void PageAllocatorSymbian::release(void* address, size_t bytes)
     170{
     171    const size_t startIdx = (static_cast<char*>(address) - m_chunk->m_base) / m_pageSize;
     172    const size_t nPages = bytes / m_pageSize;
     173    for (size_t i = startIdx; i < startIdx + nPages ; i++)
     174        m_map.clear(i);
     175}
     176
     177// Actually commit memory from the OS, after a previous call to reserve()
     178bool PageAllocatorSymbian::commit(void* address, size_t bytes)
     179{
     180    // sanity check that bits were previously set
     181    const size_t idx = (static_cast<char*>(address) - m_chunk->m_base) / m_pageSize;
     182    const size_t nPages = bytes / m_pageSize;
     183    __ASSERT_ALWAYS(m_map.get(idx), User::Panic(KErrorStringInternalConsistency, idx));
     184    __ASSERT_ALWAYS(m_map.get(idx+nPages-1), User::Panic(KErrorStringInternalConsistency, idx+nPages-1));
     185   
     186    TInt error = m_chunk->Commit(static_cast<char*>(address) - m_chunk->m_base, bytes);
     187    return (error == KErrNone);
     188}
     189
     190// Inverse operation of commit(), a release() should follow later
     191bool PageAllocatorSymbian::decommit(void* address, size_t bytes)
     192{
     193    TInt error = m_chunk->Decommit(static_cast<char*>(address) - m_chunk->m_base, bytes);
     194    return (error == KErrNone);
     195}
     196
     197bool PageAllocatorSymbian::contains(const void* address) const
     198{
     199    return m_chunk->contains(address);     
    54200}
    55201
Note: See TracChangeset for help on using the changeset viewer.