| 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_BaselineCompileTask_h |
| 8 |
#define jit_BaselineCompileTask_h |
| 9 |
|
| 10 |
#include "mozilla/LinkedList.h" |
| 11 |
#include "mozilla/Maybe.h" |
| 12 |
|
| 13 |
#include "jit/BaselineCodeGen.h" |
| 14 |
#include "jit/OffthreadSnapshot.h" |
| 15 |
#include "vm/HelperThreadTask.h" |
| 16 |
|
| 17 |
namespace js::jit { |
| 18 |
|
| 19 |
class BaselineSnapshot { |
| 20 |
OffthreadGCPtr<JSScript*> script_; |
| 21 |
OffthreadGCPtr<GlobalLexicalEnvironmentObject*> globalLexical_; |
| 22 |
OffthreadGCPtr<JSObject*> globalThis_; |
| 23 |
uint32_t baseWarmUpThreshold_; |
| 24 |
bool isIonCompileable_; |
| 25 |
bool compileDebugInstrumentation_; |
| 26 |
|
| 27 |
public: |
| 28 |
BaselineSnapshot(JSScript* script, |
| 29 |
GlobalLexicalEnvironmentObject* globalLexical, |
| 30 |
JSObject* globalThis, uint32_t baseWarmUpThreshold, |
| 31 |
bool isIonCompileable, bool compileDebugInstrumentation) |
| 32 |
: script_(script), |
| 33 |
globalLexical_(globalLexical), |
| 34 |
globalThis_(globalThis), |
| 35 |
baseWarmUpThreshold_(baseWarmUpThreshold), |
| 36 |
isIonCompileable_(isIonCompileable), |
| 37 |
compileDebugInstrumentation_(compileDebugInstrumentation) {} |
| 38 |
|
| 39 |
JSScript* script() const { return script_; } |
| 40 |
GlobalLexicalEnvironmentObject* globalLexical() const { |
| 41 |
return globalLexical_; |
| 42 |
} |
| 43 |
JSObject* globalThis() const { return globalThis_; } |
| 44 |
uint32_t baseWarmUpThreshold() const { return baseWarmUpThreshold_; } |
| 45 |
bool isIonCompileable() const { return isIonCompileable_; } |
| 46 |
bool compileDebugInstrumentation() const { |
| 47 |
return compileDebugInstrumentation_; |
| 48 |
} |
| 49 |
void trace(JSTracer* trc); |
| 50 |
}; |
| 51 |
|
| 52 |
class OffThreadBaselineSnapshot |
| 53 |
: public BaselineSnapshot, |
| 54 |
public mozilla::LinkedListElement<OffThreadBaselineSnapshot> { |
| 55 |
public: |
| 56 |
OffThreadBaselineSnapshot(JSScript* script, |
| 57 |
GlobalLexicalEnvironmentObject* globalLexical, |
| 58 |
JSObject* globalThis, uint32_t baseWarmUpThreshold, |
| 59 |
bool isIonCompileable, |
| 60 |
bool compileDebugInstrumentation) |
| 61 |
: BaselineSnapshot(script, globalLexical, globalThis, baseWarmUpThreshold, |
| 62 |
isIonCompileable, compileDebugInstrumentation) {} |
| 63 |
explicit OffThreadBaselineSnapshot(BaselineSnapshot other) |
| 64 |
: BaselineSnapshot(other) {} |
| 65 |
|
| 66 |
bool compileOffThread(TempAllocator& temp, CompileRealm* realm); |
| 67 |
|
| 68 |
private: |
| 69 |
mozilla::Maybe<OffThreadMacroAssembler> masm_; |
| 70 |
mozilla::Maybe<BaselineCompiler> compiler_; |
| 71 |
|
| 72 |
friend class BaselineCompileTask; |
| 73 |
}; |
| 74 |
|
| 75 |
using BaselineSnapshotList = mozilla::LinkedList<OffThreadBaselineSnapshot>; |
| 76 |
|
| 77 |
class BaselineCompileTask final : public HelperThreadTask { |
| 78 |
public: |
| 79 |
BaselineCompileTask(CompileRealm* realm, LifoAlloc* alloc, |
| 80 |
BaselineSnapshotList&& snapshots) |
| 81 |
: realm_(realm), alloc_(alloc), snapshots_(std::move(snapshots)) { |
| 82 |
#ifdef DEBUG |
| 83 |
for (auto* snapshot : snapshots_) { |
| 84 |
MOZ_ASSERT(CompileRealm::get(snapshot->script()->realm()) == realm); |
| 85 |
} |
| 86 |
#endif |
| 87 |
} |
| 88 |
|
| 89 |
ThreadType threadType() override { return THREAD_TYPE_BASELINE; } |
| 90 |
void runTask(); |
| 91 |
void runHelperThreadTask(AutoLockHelperThreadState& locked) override; |
| 92 |
|
| 93 |
void markScriptsAsCompiling(); |
| 94 |
|
| 95 |
void finishOnMainThread(JSContext* cx); |
| 96 |
|
| 97 |
JSRuntime* runtimeFromAnyThread() const { |
| 98 |
return firstScript()->runtimeFromAnyThread(); |
| 99 |
} |
| 100 |
Zone* zoneFromAnyThread() const { return firstScript()->zoneFromAnyThread(); } |
| 101 |
bool scriptMatches(JSScript* script) { |
| 102 |
for (auto* snapshot : snapshots_) { |
| 103 |
if (snapshot->script() == script) { |
| 104 |
return true; |
| 105 |
} |
| 106 |
} |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
const char* getName() override { return "BaselineCompileTask"; } |
| 111 |
|
| 112 |
void trace(JSTracer* trc); |
| 113 |
|
| 114 |
static void FinishOffThreadTask(BaselineCompileTask* task); |
| 115 |
|
| 116 |
bool failed() const { return failed_; } |
| 117 |
|
| 118 |
private: |
| 119 |
// All scripts are in the same realm, so we can use an arbitrary script |
| 120 |
// to access the realm/zone/runtime. |
| 121 |
JSScript* firstScript() const { return snapshots_.getFirst()->script(); } |
| 122 |
|
| 123 |
CompileRealm* realm_; |
| 124 |
LifoAlloc* alloc_; |
| 125 |
BaselineSnapshotList snapshots_; |
| 126 |
|
| 127 |
bool failed_ = false; |
| 128 |
}; |
| 129 |
|
| 130 |
} // namespace js::jit |
| 131 |
|
| 132 |
#endif /* jit_BaselineCompileTask_h */ |