jitcraft/Spaces-inl.h
author David Anderson <dvander@alliedmods.net>
Sun Jul 01 14:52:57 2012 -0700 (2012-07-01)
changeset 21 af5d8e985502
parent 12 75e385f68b7e
child 49 a92afa7484fd
permissions -rw-r--r--
Added initial String: support.
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     6  * JITCraft is free software: you can redistribute it and/or modify it under
     7  * the terms of the GNU General Public License as published by the Free
     8  * Software Foundation, either version 3 of the License, or (at your option)
     9  * any later version.
    10  * 
    11  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along with
    16  * JITCraft. If not, see http://www.gnu.org/licenses/.
    17  */
    18 #ifndef _include_jitcraft_spaces_inl_h_
    19 #define _include_jitcraft_spaces_inl_h_
    20 
    21 namespace jc {
    22 
    23 inline Address
    24 HeapStack::allocate(size_t nbytes)
    25 {
    26     nbytes = Align(nbytes, kObjectAlignment);
    27 
    28     if (pos_ + nbytes > end_)
    29         return NULL;
    30 
    31     Address ptr = pos_;
    32     pos_ += nbytes;
    33     return ptr;
    34 }
    35 
    36 inline void
    37 HeapStack::unwind(Address to)
    38 {
    39     assert(to <= pos_ && to >= buffer_);
    40     pos_ = to;
    41 }
    42 
    43 inline Address
    44 HeapChunk::allocate(size_t nbytes)
    45 {
    46     if (cursor_ + nbytes > end_)
    47         return NULL;
    48 
    49     Address address = cursor_;
    50     cursor_ += nbytes;
    51     return address;
    52 }
    53 
    54 inline Address
    55 OldSpace::allocate(size_t nbytes)
    56 {
    57     assert(IsAligned(nbytes, kObjectAlignment));
    58 
    59     if (Address addr = last_->allocate(nbytes))
    60         return addr;
    61 
    62     return allocateSlow(nbytes);
    63 }
    64 
    65 }
    66 
    67 #endif // _include_jitcraft_spaces_inl_h_