Handle-ize Code.
authorDavid Anderson <dvander@alliedmods.net>
Tue Jul 03 00:43:29 2012 -0700 (2012-07-03)
changeset 349aafaf3797e6
parent 33 95baf120f7d4
child 35 75bdaf9fcb25
Handle-ize Code.
jitcraft/Code.h
jitcraft/Handles.h
jitcraft/Opcodes.cpp
jitcraft/Zone.h
     1.1 --- a/jitcraft/Code.h	Tue Jul 03 00:36:48 2012 -0700
     1.2 +++ b/jitcraft/Code.h	Tue Jul 03 00:43:29 2012 -0700
     1.3 @@ -34,16 +34,15 @@
     1.4  // the bytecode.
     1.5  class Code : public Object
     1.6  {
     1.7 -    Module *module_;
     1.8 -    Unbarriered<ByteArray> bytecode_;
     1.9 -    Unbarriered<FixedArray> locals_;
    1.10 -    Unbarriered<FixedArray> objects_;
    1.11 +    Barriered<Module> module_;
    1.12 +    Barriered<ByteArray> bytecode_;
    1.13 +    Barriered<FixedArray> locals_;
    1.14 +    Barriered<FixedArray> objects_;
    1.15      unsigned maxStackDepth_;
    1.16  
    1.17    public:
    1.18 -    // :TODO: use handles
    1.19 -    static Code *New(Zone *zone, ByteArray *bytecode, FixedArray *locals,
    1.20 -                     FixedArray *objects, unsigned maxStackDepth, Module *module);
    1.21 +    static Code *New(Zone *zone, Handle<ByteArray> bytecode, Handle<FixedArray> locals,
    1.22 +                     Handle<FixedArray> objects, unsigned maxStackDepth, Handle<Module> module);
    1.23  
    1.24      Module *module() {
    1.25          return module_;
     2.1 --- a/jitcraft/Handles.h	Tue Jul 03 00:36:48 2012 -0700
     2.2 +++ b/jitcraft/Handles.h	Tue Jul 03 00:43:29 2012 -0700
     2.3 @@ -135,10 +135,7 @@
     2.4      inline T **make(T *other);
     2.5  
     2.6      void assign(T *other) {
     2.7 -        if (!thingp_)
     2.8 -            thingp_ = make(other);
     2.9 -        else
    2.10 -            *thingp_ = other;
    2.11 +        *thingp_ = other;
    2.12      }
    2.13  
    2.14    public:
    2.15 @@ -163,10 +160,13 @@
    2.16          return *thingp_;
    2.17      }
    2.18      operator T *() const {
    2.19 -        return thingp_ ? *thingp_ : NULL;
    2.20 +        return *thingp_;
    2.21      }
    2.22      operator bool () const {
    2.23 -        return thingp_ && *thingp_;
    2.24 +        return *thingp_;
    2.25 +    }
    2.26 +    T **address() const {
    2.27 +        return thingp_;
    2.28      }
    2.29  };
    2.30  
    2.31 @@ -174,7 +174,14 @@
    2.32  Handle<T>::Handle(const Local<S> &local)
    2.33  {
    2.34      typeCheck<S>();
    2.35 -    thingp_ = reinterpret_cast<T * const*>(local.address());
    2.36 +    thingp_ = reinterpret_cast<T * const *>(local.address());
    2.37 +}
    2.38 +
    2.39 +template <typename T> template <typename S> inline
    2.40 +Handle<T>::Handle(const ScopedRoot<S> &root)
    2.41 +{
    2.42 +    typeCheck<S>();
    2.43 +    thingp_ = reinterpret_cast<T * const *>(root.address());
    2.44  }
    2.45  
    2.46  }
     3.1 --- a/jitcraft/Opcodes.cpp	Tue Jul 03 00:36:48 2012 -0700
     3.2 +++ b/jitcraft/Opcodes.cpp	Tue Jul 03 00:43:29 2012 -0700
     3.3 @@ -33,14 +33,13 @@
     3.4  };
     3.5  
     3.6  Code *
     3.7 -Code::New(Zone *zone, ByteArray *bytecode, FixedArray *locals,
     3.8 -          FixedArray *objects, unsigned maxStackDepth, Module *module)
     3.9 +Code::New(Zone *zone, Handle<ByteArray> bytecode, Handle<FixedArray> locals,
    3.10 +          Handle<FixedArray> objects, unsigned maxStackDepth, Handle<Module> module)
    3.11  {
    3.12 -    Object *obj = zone->allocate(MapKind_Code, sizeof(Code), Heap::Tenure_Old);
    3.13 -    if (!obj)
    3.14 +    Local<Code> code(zone, Code::cast(zone->allocate(MapKind_Code, sizeof(Code), Heap::Tenure_Old)));
    3.15 +    if (!code)
    3.16          return NULL;
    3.17  
    3.18 -    Code *code = Code::cast(obj);
    3.19      code->bytecode_ = bytecode;
    3.20      code->locals_ = locals;
    3.21      code->objects_ = objects;
     4.1 --- a/jitcraft/Zone.h	Tue Jul 03 00:36:48 2012 -0700
     4.2 +++ b/jitcraft/Zone.h	Tue Jul 03 00:43:29 2012 -0700
     4.3 @@ -128,13 +128,10 @@
     4.4  
     4.5  template <typename T>
     4.6  ScopedRoot<T>::ScopedRoot(T *thing)
     4.7 -  : thingp_(NULL)
     4.8 +  : thingp_(make(thing))
     4.9  {
    4.10      // Type check that T is an Object.
    4.11      (void)static_cast<Object *>(thing);
    4.12 -
    4.13 -    if (thing)
    4.14 -        assign(thing);
    4.15  }
    4.16  
    4.17  template <typename T> T **