src/Barriers.h
author David Anderson <dvander@alliedmods.net>
Sun Sep 02 13:06:09 2012 -0700 (2012-09-02)
changeset 177 56f7e5b0243c
parent 86 32ad0523b309
permissions -rw-r--r--
Fix bug in bytecode resizing.
     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_barriers_h_
    19 #define _include_jitcraft_barriers_h_
    20 
    21 namespace ke {
    22 
    23 class Object;
    24 
    25 // Used to store unbarriered heap locations.
    26 template <typename T>
    27 class Unbarriered
    28 {
    29     T *obj_;
    30 
    31   public:
    32     Unbarriered()
    33       : obj_(NULL)
    34     {
    35     }
    36 
    37     T *operator ->() const {
    38         return operator *();
    39     }
    40     T *operator *() const {
    41         return static_cast<T *>(obj_);
    42     }
    43     Unbarriered &operator =(T *obj) {
    44         obj_ = obj;
    45         return *this;
    46     }
    47     Object **address() {
    48         return reinterpret_cast<Object **>(&obj_);
    49     }
    50     operator bool () const {
    51         return !!obj_;
    52     }
    53     operator T*() const {
    54         return static_cast<T *>(obj_);
    55     }
    56 };
    57 
    58 // Used to store unbarriered heap locations.
    59 template <typename T>
    60 class Barriered
    61 {
    62     T *obj_;
    63 
    64   public:
    65     Barriered()
    66       : obj_(NULL)
    67     {
    68     }
    69 
    70     T *operator ->() const {
    71         return operator *();
    72     }
    73     T *operator *() const {
    74         return static_cast<T *>(obj_);
    75     }
    76     Barriered &operator =(T *obj) {
    77         obj_ = obj;
    78         return *this;
    79     }
    80     Object **addr() {
    81         return reinterpret_cast<Object **>(&obj_);
    82     }
    83     operator bool () const {
    84         return !!obj_;
    85     }
    86     operator T*() const {
    87         return static_cast<T *>(obj_);
    88     }
    89 };
    90 
    91 }
    92 
    93 #endif // _include_jitcraft_barriers_h_