michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef jit_CompilerRoot_h michael@0: #define jit_CompilerRoot_h michael@0: michael@0: #ifdef JS_ION michael@0: michael@0: #include "jscntxt.h" michael@0: michael@0: #include "jit/Ion.h" michael@0: #include "jit/IonAllocPolicy.h" michael@0: #include "js/RootingAPI.h" michael@0: michael@0: namespace js { michael@0: namespace jit { michael@0: michael@0: // Roots a read-only GCThing for the lifetime of a single compilation. michael@0: // Each root is maintained in a linked list that is walked over during tracing. michael@0: // The CompilerRoot must be heap-allocated and may not go out of scope. michael@0: template michael@0: class CompilerRoot : public CompilerRootNode michael@0: { michael@0: public: michael@0: CompilerRoot(T ptr) michael@0: : CompilerRootNode(nullptr) michael@0: { michael@0: if (ptr) { michael@0: JS_ASSERT(!GetIonContext()->runtime->isInsideNursery(ptr)); michael@0: setRoot(ptr); michael@0: } michael@0: } michael@0: michael@0: public: michael@0: // Sets the pointer and inserts into root list. The pointer becomes read-only. michael@0: void setRoot(T root) { michael@0: CompilerRootNode *&rootList = GetIonContext()->temp->rootList(); michael@0: michael@0: JS_ASSERT(!ptr_); michael@0: ptr_ = root; michael@0: next = rootList; michael@0: rootList = this; michael@0: } michael@0: michael@0: public: michael@0: operator T () const { return static_cast(ptr_); } michael@0: T operator ->() const { return static_cast(ptr_); } michael@0: michael@0: private: michael@0: CompilerRoot() MOZ_DELETE; michael@0: CompilerRoot(const CompilerRoot &) MOZ_DELETE; michael@0: CompilerRoot &operator =(const CompilerRoot &) MOZ_DELETE; michael@0: }; michael@0: michael@0: typedef CompilerRoot CompilerRootObject; michael@0: typedef CompilerRoot CompilerRootFunction; michael@0: typedef CompilerRoot CompilerRootScript; michael@0: typedef CompilerRoot CompilerRootPropertyName; michael@0: typedef CompilerRoot CompilerRootShape; michael@0: typedef CompilerRoot CompilerRootValue; michael@0: michael@0: } // namespace jit michael@0: } // namespace js michael@0: michael@0: #endif // JS_ION michael@0: michael@0: #endif /* jit_CompilerRoot_h */