Debian Codegraph @

js/src/jit/IonCompileTask.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_IonCompileTask_h
8 #define jit_IonCompileTask_h
9
10 #include "mozilla/LinkedList.h"
11
12 #include "jit/CompilationDependencyTracker.h"
13 #include "jit/MIRGenerator.h"
14
15 #include "js/Utility.h"
16 #include "vm/HelperThreadTask.h"
17
18 struct JS_PUBLIC_API JSContext;
19
20 namespace js {
21 namespace jit {
22
23 class CodeGenerator;
24 class WarpSnapshot;
25
26 // IonCompileTask represents a single off-thread Ion compilation task.
27 class IonCompileTask final : public HelperThreadTask,
28 public mozilla::LinkedListElement<IonCompileTask> {
29 MIRGenerator& mirGen_;
30
31 // If off thread compilation is successful, the final code generator is
32 // attached here. Code has been generated, but not linked (there is not yet
33 // an IonScript). This is heap allocated, and must be explicitly destroyed,
34 // performed by FinishOffThreadTask().
35 CodeGenerator* backgroundCodegen_ = nullptr;
36
37 WarpSnapshot* snapshot_ = nullptr;
38
39 // Alias of the JSContext field of this task, to determine the priority of
40 // compiling this script. Contexts are destroyed after the pending tasks are
41 // removed from the helper threads. Thus this should be safe.
42 const mozilla::Atomic<bool, mozilla::ReleaseAcquire>& isExecuting_;
43
44 public:
45 explicit IonCompileTask(JSContext* cx, MIRGenerator& mirGen,
46 WarpSnapshot* snapshot);
47
48 JSScript* script() { return mirGen_.outerInfo().script(); }
49 MIRGenerator& mirGen() { return mirGen_; }
50 TempAllocator& alloc() { return mirGen_.alloc(); }
51 WarpSnapshot* snapshot() { return snapshot_; }
52
53 size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf);
54 void trace(JSTracer* trc);
55
56 CodeGenerator* backgroundCodegen() const { return backgroundCodegen_; }
57 void setBackgroundCodegen(CodeGenerator* codegen) {
58 backgroundCodegen_ = codegen;
59 }
60
61 // Return whether the main thread which scheduled this task is currently
62 // executing JS code. This changes the way we prioritize tasks.
63 bool isMainThreadRunningJS() const { return isExecuting_; }
64
65 ThreadType threadType() override { return THREAD_TYPE_ION; }
66 void runTask();
67 void runHelperThreadTask(AutoLockHelperThreadState& locked) override;
68
69 const char* getName() override { return "IonCompileTask"; }
70 };
71
72 class IonFreeTask : public HelperThreadTask {
73 IonFreeCompileTasks tasks_;
74
75 public:
76 explicit IonFreeTask(IonFreeCompileTasks&& tasks) : tasks_(std::move(tasks)) {
77 MOZ_ASSERT(!tasks_.empty());
78 }
79
80 const IonFreeCompileTasks& compileTasks() const { return tasks_; }
81
82 ThreadType threadType() override { return THREAD_TYPE_ION_FREE; }
83 void runHelperThreadTask(AutoLockHelperThreadState& locked) override;
84
85 const char* getName() override { return "IonFreeTask"; }
86 };
87
88 void AttachFinishedCompilations(JSContext* cx);
89 void FinishOffThreadTask(JSRuntime* runtime, AutoStartIonFreeTask& freeTask,
90 IonCompileTask* task);
91 void FreeIonCompileTasks(const IonFreeCompileTasks& tasks);
92 UniquePtr<LifoAlloc> FreeIonCompileTaskAndReuseLifoAlloc(IonCompileTask* task);
93
94 } // namespace jit
95 } // namespace js
96
97 #endif /* jit_IonCompileTask_h */