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