|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef jit_CompilerRoot_h |
|
8 #define jit_CompilerRoot_h |
|
9 |
|
10 #ifdef JS_ION |
|
11 |
|
12 #include "jscntxt.h" |
|
13 |
|
14 #include "jit/Ion.h" |
|
15 #include "jit/IonAllocPolicy.h" |
|
16 #include "js/RootingAPI.h" |
|
17 |
|
18 namespace js { |
|
19 namespace jit { |
|
20 |
|
21 // Roots a read-only GCThing for the lifetime of a single compilation. |
|
22 // Each root is maintained in a linked list that is walked over during tracing. |
|
23 // The CompilerRoot must be heap-allocated and may not go out of scope. |
|
24 template <typename T> |
|
25 class CompilerRoot : public CompilerRootNode |
|
26 { |
|
27 public: |
|
28 CompilerRoot(T ptr) |
|
29 : CompilerRootNode(nullptr) |
|
30 { |
|
31 if (ptr) { |
|
32 JS_ASSERT(!GetIonContext()->runtime->isInsideNursery(ptr)); |
|
33 setRoot(ptr); |
|
34 } |
|
35 } |
|
36 |
|
37 public: |
|
38 // Sets the pointer and inserts into root list. The pointer becomes read-only. |
|
39 void setRoot(T root) { |
|
40 CompilerRootNode *&rootList = GetIonContext()->temp->rootList(); |
|
41 |
|
42 JS_ASSERT(!ptr_); |
|
43 ptr_ = root; |
|
44 next = rootList; |
|
45 rootList = this; |
|
46 } |
|
47 |
|
48 public: |
|
49 operator T () const { return static_cast<T>(ptr_); } |
|
50 T operator ->() const { return static_cast<T>(ptr_); } |
|
51 |
|
52 private: |
|
53 CompilerRoot() MOZ_DELETE; |
|
54 CompilerRoot(const CompilerRoot<T> &) MOZ_DELETE; |
|
55 CompilerRoot<T> &operator =(const CompilerRoot<T> &) MOZ_DELETE; |
|
56 }; |
|
57 |
|
58 typedef CompilerRoot<JSObject*> CompilerRootObject; |
|
59 typedef CompilerRoot<JSFunction*> CompilerRootFunction; |
|
60 typedef CompilerRoot<JSScript*> CompilerRootScript; |
|
61 typedef CompilerRoot<PropertyName*> CompilerRootPropertyName; |
|
62 typedef CompilerRoot<Shape*> CompilerRootShape; |
|
63 typedef CompilerRoot<Value> CompilerRootValue; |
|
64 |
|
65 } // namespace jit |
|
66 } // namespace js |
|
67 |
|
68 #endif // JS_ION |
|
69 |
|
70 #endif /* jit_CompilerRoot_h */ |