Debian Codegraph @

js/src/jit/OffthreadSnapshot.h

raw
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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_OffthreadSnapshot_h
8 #define jit_OffthreadSnapshot_h
9
10 #include "gc/Policy.h"
11 #include "gc/Tracer.h"
12
13 // Wrapper for GC things stored in snapshots for offthread compilation.
14 // Asserts the GC pointer is not nursery-allocated.
15 // These pointers must be traced using TraceOffthreadGCPtr.
16 template <typename T>
17 class OffthreadGCPtr {
18 // Note: no pre-barrier is needed because this is a constant. No post-barrier
19 // is needed because the value is always tenured.
20 const T ptr_;
21
22 public:
23 explicit OffthreadGCPtr(const T& ptr) : ptr_(ptr) {
24 MOZ_ASSERT(JS::GCPolicy<T>::isTenured(ptr),
25 "OffthreadSnapshot pointers must be tenured");
26 }
27 OffthreadGCPtr(const OffthreadGCPtr<T>& other) = default;
28
29 operator T() const { return ptr_; }
30 T operator->() const { return ptr_; }
31
32 private:
33 OffthreadGCPtr() = delete;
34 void operator=(OffthreadGCPtr<T>& other) = delete;
35 };
36
37 template <typename T>
38 inline void TraceOffthreadGCPtr(JSTracer* trc, const OffthreadGCPtr<T>& thing,
39 const char* name) {
40 T thingRaw = thing;
41 js::TraceManuallyBarrieredEdge(trc, &thingRaw, name);
42 MOZ_ASSERT(static_cast<T>(thing) == thingRaw, "Unexpected moving GC!");
43 }
44
45 #endif /* jit_OffthreadSnapshot_h */