js/src/jit/CompilerRoot.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/CompilerRoot.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,70 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef jit_CompilerRoot_h
    1.11 +#define jit_CompilerRoot_h
    1.12 +
    1.13 +#ifdef JS_ION
    1.14 +
    1.15 +#include "jscntxt.h"
    1.16 +
    1.17 +#include "jit/Ion.h"
    1.18 +#include "jit/IonAllocPolicy.h"
    1.19 +#include "js/RootingAPI.h"
    1.20 +
    1.21 +namespace js {
    1.22 +namespace jit {
    1.23 +
    1.24 +// Roots a read-only GCThing for the lifetime of a single compilation.
    1.25 +// Each root is maintained in a linked list that is walked over during tracing.
    1.26 +// The CompilerRoot must be heap-allocated and may not go out of scope.
    1.27 +template <typename T>
    1.28 +class CompilerRoot : public CompilerRootNode
    1.29 +{
    1.30 +  public:
    1.31 +    CompilerRoot(T ptr)
    1.32 +      : CompilerRootNode(nullptr)
    1.33 +    {
    1.34 +        if (ptr) {
    1.35 +            JS_ASSERT(!GetIonContext()->runtime->isInsideNursery(ptr));
    1.36 +            setRoot(ptr);
    1.37 +        }
    1.38 +    }
    1.39 +
    1.40 +  public:
    1.41 +    // Sets the pointer and inserts into root list. The pointer becomes read-only.
    1.42 +    void setRoot(T root) {
    1.43 +        CompilerRootNode *&rootList = GetIonContext()->temp->rootList();
    1.44 +
    1.45 +        JS_ASSERT(!ptr_);
    1.46 +        ptr_ = root;
    1.47 +        next = rootList;
    1.48 +        rootList = this;
    1.49 +    }
    1.50 +
    1.51 +  public:
    1.52 +    operator T () const { return static_cast<T>(ptr_); }
    1.53 +    T operator ->() const { return static_cast<T>(ptr_); }
    1.54 +
    1.55 +  private:
    1.56 +    CompilerRoot() MOZ_DELETE;
    1.57 +    CompilerRoot(const CompilerRoot<T> &) MOZ_DELETE;
    1.58 +    CompilerRoot<T> &operator =(const CompilerRoot<T> &) MOZ_DELETE;
    1.59 +};
    1.60 +
    1.61 +typedef CompilerRoot<JSObject*> CompilerRootObject;
    1.62 +typedef CompilerRoot<JSFunction*> CompilerRootFunction;
    1.63 +typedef CompilerRoot<JSScript*> CompilerRootScript;
    1.64 +typedef CompilerRoot<PropertyName*> CompilerRootPropertyName;
    1.65 +typedef CompilerRoot<Shape*> CompilerRootShape;
    1.66 +typedef CompilerRoot<Value> CompilerRootValue;
    1.67 +
    1.68 +} // namespace jit
    1.69 +} // namespace js
    1.70 +
    1.71 +#endif // JS_ION
    1.72 +
    1.73 +#endif /* jit_CompilerRoot_h */

mercurial