src/Spaces-inl.h
changeset 86 32ad0523b309
parent 59 b7d61ddb3c8d
child 91 5f4402180204
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Spaces-inl.h	Tue Jul 24 23:53:34 2012 -0700
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* vim: set ts=4 sw=4 tw=99 et:
     1.5 + *
     1.6 + * Copyright (C) 2012 David Anderson
     1.7 + *
     1.8 + * This file is part of JITCraft.
     1.9 + *
    1.10 + * JITCraft is free software: you can redistribute it and/or modify it under
    1.11 + * the terms of the GNU General Public License as published by the Free
    1.12 + * Software Foundation, either version 3 of the License, or (at your option)
    1.13 + * any later version.
    1.14 + * 
    1.15 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    1.16 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License along with
    1.20 + * JITCraft. If not, see http://www.gnu.org/licenses/.
    1.21 + */
    1.22 +#ifndef _include_jitcraft_spaces_inl_h_
    1.23 +#define _include_jitcraft_spaces_inl_h_
    1.24 +
    1.25 +namespace ke {
    1.26 +
    1.27 +inline Address
    1.28 +HeapStack::allocate(size_t nbytes)
    1.29 +{
    1.30 +    nbytes = Align(nbytes, kObjectAlignment);
    1.31 +
    1.32 +    if (cursor_ + nbytes > chunk_->end())
    1.33 +        return NULL;
    1.34 +
    1.35 +    Address ptr = cursor_;
    1.36 +    cursor_ += nbytes;
    1.37 +    return ptr;
    1.38 +}
    1.39 +
    1.40 +inline void
    1.41 +HeapStack::unwind(Address to)
    1.42 +{
    1.43 +    assert(to <= cursor_ && to >= chunk_->first());
    1.44 +    cursor_ = to;
    1.45 +}
    1.46 +
    1.47 +inline Address
    1.48 +OldSpace::allocate(size_t nbytes)
    1.49 +{
    1.50 +    assert(IsAligned(nbytes, kObjectAlignment));
    1.51 +
    1.52 +    if (cursor_ + nbytes > last_->end())
    1.53 +        return allocateSlow(nbytes);
    1.54 +
    1.55 +    Address addr = cursor_;
    1.56 +    cursor_ += nbytes;
    1.57 +    return addr;
    1.58 +}
    1.59 +
    1.60 +}
    1.61 +
    1.62 +#endif // _include_jitcraft_spaces_inl_h_