| 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_JitScript_h |
| 8 |
#define jit_JitScript_h |
| 9 |
|
| 10 |
#include "mozilla/Assertions.h" |
| 11 |
#include "mozilla/Atomics.h" |
| 12 |
#include "mozilla/Attributes.h" |
| 13 |
#include "mozilla/HashFunctions.h" |
| 14 |
#include "mozilla/LinkedList.h" |
| 15 |
#include "mozilla/Maybe.h" |
| 16 |
#include "mozilla/MemoryReporting.h" |
| 17 |
|
| 18 |
#include <stddef.h> |
| 19 |
#include <stdint.h> |
| 20 |
|
| 21 |
#include "jstypes.h" |
| 22 |
#include "NamespaceImports.h" |
| 23 |
|
| 24 |
#include "ds/LifoAlloc.h" |
| 25 |
#include "gc/Barrier.h" |
| 26 |
#include "jit/BaselineIC.h" |
| 27 |
#include "js/TypeDecls.h" |
| 28 |
#include "js/UniquePtr.h" |
| 29 |
#include "js/Vector.h" |
| 30 |
#include "util/TrailingArray.h" |
| 31 |
#include "vm/EnvironmentObject.h" |
| 32 |
|
| 33 |
class JS_PUBLIC_API JSScript; |
| 34 |
class JS_PUBLIC_API JSTracer; |
| 35 |
struct JS_PUBLIC_API JSContext; |
| 36 |
|
| 37 |
namespace JS { |
| 38 |
class Zone; |
| 39 |
} |
| 40 |
|
| 41 |
namespace js { |
| 42 |
|
| 43 |
class SystemAllocPolicy; |
| 44 |
|
| 45 |
namespace gc { |
| 46 |
class AllocSite; |
| 47 |
} |
| 48 |
|
| 49 |
namespace jit { |
| 50 |
|
| 51 |
class BaselineScript; |
| 52 |
class ICStubSpace; |
| 53 |
class InliningRoot; |
| 54 |
class IonScript; |
| 55 |
class JitScript; |
| 56 |
class JitZone; |
| 57 |
|
| 58 |
// Magic values indicating compilation has been disabled or the script |
| 59 |
// is already scheduled for background compilation. |
| 60 |
static constexpr uintptr_t DisabledScript = 0x1; |
| 61 |
static constexpr uintptr_t QueuedScript = 0x3; |
| 62 |
static constexpr uintptr_t CompilingScript = 0x5; |
| 63 |
|
| 64 |
static constexpr uint32_t SpecialScriptBit = 0x1; |
| 65 |
static_assert((DisabledScript & SpecialScriptBit) != 0); |
| 66 |
static_assert((QueuedScript & SpecialScriptBit) != 0); |
| 67 |
static_assert((CompilingScript & SpecialScriptBit) != 0); |
| 68 |
|
| 69 |
static BaselineScript* const BaselineDisabledScriptPtr = |
| 70 |
reinterpret_cast<BaselineScript*>(DisabledScript); |
| 71 |
static BaselineScript* const BaselineQueuedScriptPtr = |
| 72 |
reinterpret_cast<BaselineScript*>(DisabledScript); |
| 73 |
static BaselineScript* const BaselineCompilingScriptPtr = |
| 74 |
reinterpret_cast<BaselineScript*>(CompilingScript); |
| 75 |
|
| 76 |
static IonScript* const IonDisabledScriptPtr = |
| 77 |
reinterpret_cast<IonScript*>(DisabledScript); |
| 78 |
static IonScript* const IonCompilingScriptPtr = |
| 79 |
reinterpret_cast<IonScript*>(CompilingScript); |
| 80 |
|
| 81 |
/* [SMDOC] ICScript Lifetimes |
| 82 |
* |
| 83 |
* An ICScript owns an array of ICEntries, each of which owns a linked |
| 84 |
* list of ICStubs. |
| 85 |
* |
| 86 |
* A JitScript contains an embedded ICScript. If it has done any trial |
| 87 |
* inlining, it also owns an InliningRoot. The InliningRoot owns all |
| 88 |
* of the ICScripts that have been created for inlining into the |
| 89 |
* corresponding JitScript. This ties the lifetime of the inlined |
| 90 |
* ICScripts to the lifetime of the JitScript itself. |
| 91 |
* |
| 92 |
* We store pointers to ICScripts in two other places: on the stack in |
| 93 |
* BaselineFrame, and in IC stubs for CallInlinedFunction. |
| 94 |
* |
| 95 |
* The ICScript pointer in a BaselineFrame either points to the |
| 96 |
* ICScript embedded in the JitScript for that frame, or to an inlined |
| 97 |
* ICScript owned by a caller. In each case, there must be a frame on |
| 98 |
* the stack corresponding to the JitScript that owns the current |
| 99 |
* ICScript, which will keep the ICScript alive. |
| 100 |
* |
| 101 |
* Each ICStub is owned by an ICScript and, indirectly, a |
| 102 |
* JitScript. An ICStub that uses CallInlinedFunction contains an |
| 103 |
* ICScript for use by the callee. The ICStub and the callee ICScript |
| 104 |
* are always owned by the same JitScript, so the callee ICScript will |
| 105 |
* not be freed while the ICStub is alive. |
| 106 |
* |
| 107 |
* The lifetime of an ICScript is independent of the lifetimes of the |
| 108 |
* BaselineScript and IonScript/WarpScript to which it |
| 109 |
* corresponds. They can be destroyed and recreated, and the ICScript |
| 110 |
* will remain valid. |
| 111 |
* |
| 112 |
* When we discard JIT code, we mark ICScripts that are active on the stack as |
| 113 |
* active and then purge all of the inactive ICScripts. We also purge ICStubs, |
| 114 |
* including the CallInlinedFunction stub at the trial inining call site, and |
| 115 |
* reset the ICStates to allow trial inlining again later. |
| 116 |
* |
| 117 |
* If there's a BaselineFrame for an inlined ICScript, we'll preserve both this |
| 118 |
* ICScript and the IC chain for the call site in the caller's ICScript. |
| 119 |
* See ICScript::purgeStubs and ICScript::purgeInactiveICScripts. |
| 120 |
*/ |
| 121 |
|
| 122 |
class alignas(uintptr_t) ICScript final : public TrailingArray<ICScript> { |
| 123 |
public: |
| 124 |
ICScript(uint32_t warmUpCount, Offset fallbackStubsOffset, Offset endOffset, |
| 125 |
uint32_t depth, uint32_t bytecodeSize, |
| 126 |
InliningRoot* inliningRoot = nullptr) |
| 127 |
: inliningRoot_(inliningRoot), |
| 128 |
warmUpCount_(warmUpCount), |
| 129 |
fallbackStubsOffset_(fallbackStubsOffset), |
| 130 |
endOffset_(endOffset), |
| 131 |
depth_(depth), |
| 132 |
bytecodeSize_(bytecodeSize) {} |
| 133 |
|
| 134 |
~ICScript(); |
| 135 |
|
| 136 |
bool isInlined() const { return depth_ > 0; } |
| 137 |
|
| 138 |
void initICEntries(JSContext* cx, JSScript* script); |
| 139 |
|
| 140 |
ICEntry& icEntry(size_t index) { |
| 141 |
MOZ_ASSERT(index < numICEntries()); |
| 142 |
return icEntries()[index]; |
| 143 |
} |
| 144 |
|
| 145 |
ICFallbackStub* fallbackStub(size_t index) { |
| 146 |
MOZ_ASSERT(index < numICEntries()); |
| 147 |
return fallbackStubs() + index; |
| 148 |
} |
| 149 |
|
| 150 |
ICEntry* icEntryForStub(const ICFallbackStub* stub) { |
| 151 |
size_t index = stub - fallbackStubs(); |
| 152 |
MOZ_ASSERT(index < numICEntries()); |
| 153 |
return &icEntry(index); |
| 154 |
} |
| 155 |
ICFallbackStub* fallbackStubForICEntry(const ICEntry* entry) { |
| 156 |
size_t index = entry - icEntries(); |
| 157 |
MOZ_ASSERT(index < numICEntries()); |
| 158 |
return fallbackStub(index); |
| 159 |
} |
| 160 |
|
| 161 |
InliningRoot* inliningRoot() const { return inliningRoot_; } |
| 162 |
uint32_t depth() const { return depth_; } |
| 163 |
|
| 164 |
uint32_t bytecodeSize() const { return bytecodeSize_; } |
| 165 |
|
| 166 |
void resetWarmUpCount(uint32_t count) { warmUpCount_ = count; } |
| 167 |
|
| 168 |
static constexpr size_t offsetOfFirstStub(uint32_t entryIndex) { |
| 169 |
return sizeof(ICScript) + entryIndex * sizeof(ICEntry) + |
| 170 |
ICEntry::offsetOfFirstStub(); |
| 171 |
} |
| 172 |
|
| 173 |
static constexpr Offset offsetOfWarmUpCount() { |
| 174 |
return offsetof(ICScript, warmUpCount_); |
| 175 |
} |
| 176 |
static constexpr Offset offsetOfDepth() { return offsetof(ICScript, depth_); } |
| 177 |
|
| 178 |
static constexpr Offset offsetOfICEntries() { return sizeof(ICScript); } |
| 179 |
uint32_t numICEntries() const { |
| 180 |
return numElements<ICEntry>(icEntriesOffset(), fallbackStubsOffset()); |
| 181 |
} |
| 182 |
|
| 183 |
static constexpr Offset offsetOfEnvAllocSite() { |
| 184 |
return offsetof(ICScript, envAllocSite_); |
| 185 |
} |
| 186 |
|
| 187 |
ICEntry* interpreterICEntryFromPCOffset(uint32_t pcOffset); |
| 188 |
|
| 189 |
ICEntry& icEntryFromPCOffset(uint32_t pcOffset); |
| 190 |
|
| 191 |
[[nodiscard]] bool addInlinedChild(JSContext* cx, |
| 192 |
js::UniquePtr<ICScript> child, |
| 193 |
uint32_t pcOffset); |
| 194 |
ICScript* findInlinedChild(uint32_t pcOffset); |
| 195 |
void removeInlinedChild(uint32_t pcOffset); |
| 196 |
bool hasInlinedChild(uint32_t pcOffset); |
| 197 |
|
| 198 |
void purgeStubs(Zone* zone, ICStubSpace& newStubSpace); |
| 199 |
|
| 200 |
void purgeInactiveICScripts(); |
| 201 |
|
| 202 |
bool active() const { return active_; } |
| 203 |
void setActive() { active_ = true; } |
| 204 |
void resetActive() { active_ = false; } |
| 205 |
|
| 206 |
gc::AllocSite* getOrCreateAllocSite(JSScript* outerScript, uint32_t pcOffset); |
| 207 |
|
| 208 |
void ensureEnvAllocSite(JSScript* outerScript); |
| 209 |
gc::AllocSite* maybeEnvAllocSite() const { return envAllocSite_; } |
| 210 |
|
| 211 |
void prepareForDestruction(Zone* zone); |
| 212 |
|
| 213 |
void trace(JSTracer* trc); |
| 214 |
bool traceWeak(JSTracer* trc); |
| 215 |
|
| 216 |
#ifdef DEBUG |
| 217 |
mozilla::HashNumber hash(); |
| 218 |
#endif |
| 219 |
|
| 220 |
private: |
| 221 |
class CallSite { |
| 222 |
public: |
| 223 |
CallSite(ICScript* callee, uint32_t pcOffset) |
| 224 |
: callee_(callee), pcOffset_(pcOffset) {} |
| 225 |
ICScript* callee_; |
| 226 |
uint32_t pcOffset_; |
| 227 |
}; |
| 228 |
|
| 229 |
// If this ICScript was created for trial inlining or has another |
| 230 |
// ICScript inlined into it, a pointer to the root of the inlining |
| 231 |
// tree. Otherwise, nullptr. |
| 232 |
InliningRoot* inliningRoot_ = nullptr; |
| 233 |
|
| 234 |
// ICScripts that have been inlined into this ICScript. |
| 235 |
js::UniquePtr<Vector<CallSite>> inlinedChildren_; |
| 236 |
|
| 237 |
// List of allocation sites referred to by ICs in this script. |
| 238 |
static constexpr size_t AllocSiteChunkSize = 256; |
| 239 |
LifoAlloc allocSitesSpace_{AllocSiteChunkSize, js::BackgroundMallocArena}; |
| 240 |
Vector<gc::AllocSite*, 0, SystemAllocPolicy> allocSites_; |
| 241 |
|
| 242 |
// Optional alloc site to use when allocating environment chain objects. |
| 243 |
gc::AllocSite* envAllocSite_ = nullptr; |
| 244 |
|
| 245 |
// Number of times this copy of the script has been called or has had |
| 246 |
// backedges taken. Reset if the script's JIT code is forcibly discarded. |
| 247 |
// See also the ScriptWarmUpData class. |
| 248 |
mozilla::Atomic<uint32_t, mozilla::Relaxed> warmUpCount_ = {}; |
| 249 |
|
| 250 |
// The offset of the ICFallbackStub array. |
| 251 |
Offset fallbackStubsOffset_; |
| 252 |
|
| 253 |
// The size of this allocation. |
| 254 |
Offset endOffset_; |
| 255 |
|
| 256 |
// The inlining depth of this ICScript. 0 for the inlining root. |
| 257 |
uint32_t depth_; |
| 258 |
|
| 259 |
// Bytecode size of the JSScript corresponding to this ICScript. |
| 260 |
uint32_t bytecodeSize_; |
| 261 |
|
| 262 |
// Flag set when discarding JIT code to indicate this script is on the stack |
| 263 |
// and should not be discarded. |
| 264 |
bool active_ = false; |
| 265 |
|
| 266 |
Offset icEntriesOffset() const { return offsetOfICEntries(); } |
| 267 |
Offset fallbackStubsOffset() const { return fallbackStubsOffset_; } |
| 268 |
Offset endOffset() const { return endOffset_; } |
| 269 |
|
| 270 |
public: |
| 271 |
ICEntry* icEntries() { return offsetToPointer<ICEntry>(icEntriesOffset()); } |
| 272 |
|
| 273 |
private: |
| 274 |
ICFallbackStub* fallbackStubs() { |
| 275 |
return offsetToPointer<ICFallbackStub>(fallbackStubsOffset()); |
| 276 |
} |
| 277 |
|
| 278 |
JitScript* outerJitScript(); |
| 279 |
|
| 280 |
friend class JitScript; |
| 281 |
}; |
| 282 |
|
| 283 |
// [SMDOC] JitScript |
| 284 |
// |
| 285 |
// JitScript stores type inference data, Baseline ICs and other JIT-related data |
| 286 |
// for a script. Scripts with a JitScript can run in the Baseline Interpreter. |
| 287 |
// |
| 288 |
// IC Data |
| 289 |
// ======= |
| 290 |
// All IC data for Baseline (Interpreter and JIT) is stored in an ICScript. Each |
| 291 |
// JitScript contains an ICScript as the last field. Additional free-standing |
| 292 |
// ICScripts may be created during trial inlining. Ion has its own IC chains |
| 293 |
// stored in IonScript. |
| 294 |
// |
| 295 |
// For each IC we store an ICEntry, which points to the first ICStub in the |
| 296 |
// chain, and an ICFallbackStub. Note that multiple stubs in the same zone can |
| 297 |
// share Baseline IC code. This works because the stub data is stored in the |
| 298 |
// ICStub instead of baked in in the stub code. |
| 299 |
// |
| 300 |
// Storing this separate from BaselineScript allows us to use the same ICs in |
| 301 |
// the Baseline Interpreter and Baseline JIT. It also simplifies debug mode OSR |
| 302 |
// because the JitScript can be reused when we have to recompile the |
| 303 |
// BaselineScript. |
| 304 |
// |
| 305 |
// An ICScript contains a list of IC entries and a list of fallback stubs. |
| 306 |
// There's one ICEntry and ICFallbackStub for each JOF_IC bytecode op. |
| 307 |
// |
| 308 |
// The ICScript also contains the warmUpCount for the script. |
| 309 |
// |
| 310 |
// Inlining Data |
| 311 |
// ============= |
| 312 |
// JitScript also contains a list of Warp compilations inlining this script, for |
| 313 |
// invalidation. |
| 314 |
// |
| 315 |
// Memory Layout |
| 316 |
// ============= |
| 317 |
// JitScript contains an ICScript as the last field. ICScript has trailing |
| 318 |
// (variable length) arrays for ICEntry and ICFallbackStub. The memory layout is |
| 319 |
// as follows: |
| 320 |
// |
| 321 |
// Item | Offset |
| 322 |
// ------------------------+------------------------ |
| 323 |
// JitScript | 0 |
| 324 |
// -->ICScript (field) | |
| 325 |
// ICEntry[] | icEntriesOffset() |
| 326 |
// ICFallbackStub[] | fallbackStubsOffset() |
| 327 |
// |
| 328 |
// These offsets are also used to compute numICEntries. |
| 329 |
class alignas(uintptr_t) JitScript final |
| 330 |
: public mozilla::LinkedListElement<JitScript>, |
| 331 |
public TrailingArray<JitScript> { |
| 332 |
friend class ::JSScript; |
| 333 |
|
| 334 |
// Profile string used by the profiler for Baseline Interpreter frames. |
| 335 |
const char* profileString_ = nullptr; |
| 336 |
|
| 337 |
HeapPtr<JSScript*> owningScript_; |
| 338 |
|
| 339 |
// Baseline code for the script. Either nullptr, BaselineDisabledScriptPtr, |
| 340 |
// BaselineQueuedScriptPtr, BaselineCompilingScriptPtr, |
| 341 |
// or a valid BaselineScript*. |
| 342 |
GCStructPtr<BaselineScript*> baselineScript_; |
| 343 |
|
| 344 |
// Ion code for this script. Either nullptr, IonDisabledScriptPtr, |
| 345 |
// IonCompilingScriptPtr or a valid IonScript*. |
| 346 |
GCStructPtr<IonScript*> ionScript_; |
| 347 |
|
| 348 |
// For functions that need a CallObject and/or NamedLambdaObject, the template |
| 349 |
// objects used by the Baseline JIT and Ion. If the function needs both a |
| 350 |
// named lambda object and a call object, the named lambda object template is |
| 351 |
// linked via the call object's enclosing environment. This field is set the |
| 352 |
// first time the Baseline JIT compiles this script. |
| 353 |
mozilla::Maybe<HeapPtr<EnvironmentObject*>> templateEnv_; |
| 354 |
|
| 355 |
// The size of this allocation. |
| 356 |
Offset endOffset_ = 0; |
| 357 |
|
| 358 |
// Analysis data computed lazily the first time this script is compiled or |
| 359 |
// inlined by WarpBuilder. |
| 360 |
mozilla::Maybe<bool> usesEnvironmentChain_; |
| 361 |
|
| 362 |
struct Flags { |
| 363 |
// True if this script entered Ion via OSR at a loop header. |
| 364 |
bool hadIonOSR : 1; |
| 365 |
}; |
| 366 |
Flags flags_ = {}; // Zero-initialize flags. |
| 367 |
|
| 368 |
js::UniquePtr<InliningRoot> inliningRoot_; |
| 369 |
|
| 370 |
#ifdef DEBUG |
| 371 |
// If the last warp compilation invalidated because of TranspiledCacheIR |
| 372 |
// bailouts, this is a hash of the ICScripts used in that compilation. |
| 373 |
// When recompiling, we assert that the hash has changed. |
| 374 |
mozilla::Maybe<mozilla::HashNumber> failedICHash_; |
| 375 |
|
| 376 |
// To avoid pathological cases, we skip the check if we have purged |
| 377 |
// stubs due to GC pressure. |
| 378 |
bool hasPurgedStubs_ = false; |
| 379 |
#endif |
| 380 |
|
| 381 |
// Value of the warmup counter when the last IC stub was attached, |
| 382 |
// used for Ion hints. |
| 383 |
uint32_t warmUpCountAtLastICStub_ = 0; |
| 384 |
|
| 385 |
ICScript icScript_; |
| 386 |
// End of fields. |
| 387 |
|
| 388 |
Offset endOffset() const { return endOffset_; } |
| 389 |
|
| 390 |
public: |
| 391 |
JitScript(JSScript* script, Offset fallbackStubsOffset, Offset endOffset, |
| 392 |
const char* profileString); |
| 393 |
|
| 394 |
~JitScript(); |
| 395 |
|
| 396 |
JSScript* owningScript() const { return owningScript_; } |
| 397 |
|
| 398 |
[[nodiscard]] bool ensureHasCachedBaselineJitData(JSContext* cx, |
| 399 |
HandleScript script); |
| 400 |
[[nodiscard]] bool ensureHasCachedIonData(JSContext* cx, HandleScript script); |
| 401 |
|
| 402 |
void setHadIonOSR() { flags_.hadIonOSR = true; } |
| 403 |
bool hadIonOSR() const { return flags_.hadIonOSR; } |
| 404 |
|
| 405 |
uint32_t numICEntries() const { return icScript_.numICEntries(); } |
| 406 |
|
| 407 |
#ifdef DEBUG |
| 408 |
bool hasActiveICScript() const; |
| 409 |
#endif |
| 410 |
void resetAllActiveFlags(); |
| 411 |
|
| 412 |
void ensureProfileString(JSContext* cx, JSScript* script); |
| 413 |
|
| 414 |
const char* profileString() const { |
| 415 |
MOZ_ASSERT(profileString_); |
| 416 |
return profileString_; |
| 417 |
} |
| 418 |
|
| 419 |
static void Destroy(Zone* zone, JitScript* script); |
| 420 |
|
| 421 |
static constexpr Offset offsetOfICEntries() { return sizeof(JitScript); } |
| 422 |
|
| 423 |
static constexpr size_t offsetOfBaselineScript() { |
| 424 |
return offsetof(JitScript, baselineScript_); |
| 425 |
} |
| 426 |
static constexpr size_t offsetOfIonScript() { |
| 427 |
return offsetof(JitScript, ionScript_); |
| 428 |
} |
| 429 |
static constexpr size_t offsetOfICScript() { |
| 430 |
return offsetof(JitScript, icScript_); |
| 431 |
} |
| 432 |
static constexpr size_t offsetOfWarmUpCount() { |
| 433 |
return offsetOfICScript() + ICScript::offsetOfWarmUpCount(); |
| 434 |
} |
| 435 |
|
| 436 |
uint32_t warmUpCount() const { return icScript_.warmUpCount_; } |
| 437 |
void incWarmUpCount() { icScript_.warmUpCount_++; } |
| 438 |
void resetWarmUpCount(uint32_t count); |
| 439 |
|
| 440 |
void prepareForDestruction(Zone* zone); |
| 441 |
|
| 442 |
void addSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf, size_t* data, |
| 443 |
size_t* allocSites) const; |
| 444 |
|
| 445 |
ICEntry& icEntry(size_t index) { return icScript_.icEntry(index); } |
| 446 |
|
| 447 |
ICFallbackStub* fallbackStub(size_t index) { |
| 448 |
return icScript_.fallbackStub(index); |
| 449 |
} |
| 450 |
|
| 451 |
ICEntry* icEntryForStub(const ICFallbackStub* stub) { |
| 452 |
return icScript_.icEntryForStub(stub); |
| 453 |
} |
| 454 |
ICFallbackStub* fallbackStubForICEntry(const ICEntry* entry) { |
| 455 |
return icScript_.fallbackStubForICEntry(entry); |
| 456 |
} |
| 457 |
|
| 458 |
void trace(JSTracer* trc); |
| 459 |
void traceWeak(JSTracer* trc); |
| 460 |
void purgeStubs(JSScript* script, ICStubSpace& newStubSpace); |
| 461 |
|
| 462 |
void purgeInactiveICScripts(); |
| 463 |
|
| 464 |
ICEntry& icEntryFromPCOffset(uint32_t pcOffset) { |
| 465 |
return icScript_.icEntryFromPCOffset(pcOffset); |
| 466 |
}; |
| 467 |
|
| 468 |
size_t allocBytes() const { return endOffset(); } |
| 469 |
|
| 470 |
EnvironmentObject* templateEnvironment() const { return templateEnv_.ref(); } |
| 471 |
|
| 472 |
std::pair<CallObject*, NamedLambdaObject*> functionEnvironmentTemplates( |
| 473 |
JSFunction* fun) const; |
| 474 |
|
| 475 |
bool usesEnvironmentChain() const { return *usesEnvironmentChain_; } |
| 476 |
|
| 477 |
bool resetAllocSites(bool resetNurserySites, bool resetPretenuredSites); |
| 478 |
bool hasPretenuredAllocSites(); |
| 479 |
|
| 480 |
void updateLastICStubCounter() { warmUpCountAtLastICStub_ = warmUpCount(); } |
| 481 |
uint32_t warmUpCountAtLastICStub() const { return warmUpCountAtLastICStub_; } |
| 482 |
|
| 483 |
bool hasEnvAllocSite() const { return icScript_.envAllocSite_; } |
| 484 |
|
| 485 |
private: |
| 486 |
// Methods to set baselineScript_ to a BaselineScript*, nullptr, or |
| 487 |
// BaselineDisabledScriptPtr. |
| 488 |
void setBaselineScriptImpl(JSScript* script, BaselineScript* baselineScript); |
| 489 |
void setBaselineScriptImpl(JS::GCContext* gcx, JSScript* script, |
| 490 |
BaselineScript* baselineScript); |
| 491 |
|
| 492 |
public: |
| 493 |
// Methods for getting/setting/clearing a BaselineScript*. |
| 494 |
bool hasBaselineScript() const { |
| 495 |
bool res = baselineScript_ && |
| 496 |
baselineScript_ != BaselineDisabledScriptPtr && |
| 497 |
baselineScript_ != BaselineQueuedScriptPtr && |
| 498 |
baselineScript_ != BaselineCompilingScriptPtr; |
| 499 |
MOZ_ASSERT_IF(!res, !hasIonScript()); |
| 500 |
return res; |
| 501 |
} |
| 502 |
BaselineScript* baselineScript() const { |
| 503 |
MOZ_ASSERT(hasBaselineScript()); |
| 504 |
return baselineScript_; |
| 505 |
} |
| 506 |
void setBaselineScript(JSScript* script, BaselineScript* baselineScript) { |
| 507 |
MOZ_ASSERT(!hasBaselineScript()); |
| 508 |
setBaselineScriptImpl(script, baselineScript); |
| 509 |
MOZ_ASSERT(hasBaselineScript()); |
| 510 |
} |
| 511 |
[[nodiscard]] BaselineScript* clearBaselineScript(JS::GCContext* gcx, |
| 512 |
JSScript* script) { |
| 513 |
BaselineScript* baseline = baselineScript(); |
| 514 |
setBaselineScriptImpl(gcx, script, nullptr); |
| 515 |
return baseline; |
| 516 |
} |
| 517 |
bool isBaselineQueued() const { |
| 518 |
return baselineScript_ == BaselineQueuedScriptPtr; |
| 519 |
} |
| 520 |
void clearIsBaselineQueued(JSScript* script) { |
| 521 |
MOZ_ASSERT(isBaselineQueued()); |
| 522 |
setBaselineScriptImpl(script, nullptr); |
| 523 |
} |
| 524 |
bool isBaselineCompiling() const { |
| 525 |
return baselineScript_ == BaselineCompilingScriptPtr; |
| 526 |
} |
| 527 |
void setIsBaselineCompiling(JSScript* script) { |
| 528 |
MOZ_ASSERT(baselineScript_ == nullptr); |
| 529 |
setBaselineScriptImpl(script, BaselineCompilingScriptPtr); |
| 530 |
} |
| 531 |
void clearIsBaselineCompiling(JSScript* script) { |
| 532 |
MOZ_ASSERT(isBaselineCompiling()); |
| 533 |
setBaselineScriptImpl(script, nullptr); |
| 534 |
} |
| 535 |
|
| 536 |
private: |
| 537 |
// Methods to set ionScript_ to an IonScript*, nullptr, or one of the special |
| 538 |
// Ion{Disabled,Compiling}ScriptPtr values. |
| 539 |
void setIonScriptImpl(JS::GCContext* gcx, JSScript* script, |
| 540 |
IonScript* ionScript); |
| 541 |
void setIonScriptImpl(JSScript* script, IonScript* ionScript); |
| 542 |
|
| 543 |
// Helper that calls the passed function for the outer ICScript and for each |
| 544 |
// inlined ICScript. |
| 545 |
template <typename F> |
| 546 |
void forEachICScript(const F& f); |
| 547 |
template <typename F> |
| 548 |
void forEachICScript(const F& f) const; |
| 549 |
|
| 550 |
public: |
| 551 |
// Methods for getting/setting/clearing an IonScript*. |
| 552 |
bool hasIonScript() const { |
| 553 |
bool res = ionScript_ && ionScript_ != IonDisabledScriptPtr && |
| 554 |
ionScript_ != IonCompilingScriptPtr; |
| 555 |
MOZ_ASSERT_IF(res, baselineScript_); |
| 556 |
return res; |
| 557 |
} |
| 558 |
IonScript* ionScript() const { |
| 559 |
MOZ_ASSERT(hasIonScript()); |
| 560 |
return ionScript_; |
| 561 |
} |
| 562 |
void setIonScript(JSScript* script, IonScript* ionScript) { |
| 563 |
MOZ_ASSERT(!hasIonScript()); |
| 564 |
setIonScriptImpl(script, ionScript); |
| 565 |
MOZ_ASSERT(hasIonScript()); |
| 566 |
} |
| 567 |
[[nodiscard]] IonScript* clearIonScript(JS::GCContext* gcx, |
| 568 |
JSScript* script) { |
| 569 |
IonScript* ion = ionScript(); |
| 570 |
setIonScriptImpl(gcx, script, nullptr); |
| 571 |
return ion; |
| 572 |
} |
| 573 |
|
| 574 |
// Methods for off-thread compilation. |
| 575 |
bool isIonCompilingOffThread() const { |
| 576 |
return ionScript_ == IonCompilingScriptPtr; |
| 577 |
} |
| 578 |
void setIsIonCompilingOffThread(JSScript* script) { |
| 579 |
MOZ_ASSERT(ionScript_ == nullptr); |
| 580 |
setIonScriptImpl(script, IonCompilingScriptPtr); |
| 581 |
} |
| 582 |
void clearIsIonCompilingOffThread(JSScript* script) { |
| 583 |
MOZ_ASSERT(isIonCompilingOffThread()); |
| 584 |
setIonScriptImpl(script, nullptr); |
| 585 |
} |
| 586 |
ICScript* icScript() { return &icScript_; } |
| 587 |
|
| 588 |
bool hasInliningRoot() const { return !!inliningRoot_; } |
| 589 |
InliningRoot* inliningRoot() const { return inliningRoot_.get(); } |
| 590 |
InliningRoot* getOrCreateInliningRoot(JSContext* cx, JSScript* script); |
| 591 |
|
| 592 |
inline void notePurgedStubs() { |
| 593 |
#ifdef DEBUG |
| 594 |
failedICHash_.reset(); |
| 595 |
hasPurgedStubs_ = true; |
| 596 |
#endif |
| 597 |
} |
| 598 |
|
| 599 |
#ifdef DEBUG |
| 600 |
bool hasPurgedStubs() const { return hasPurgedStubs_; } |
| 601 |
bool hasFailedICHash() const { return failedICHash_.isSome(); } |
| 602 |
mozilla::HashNumber getFailedICHash() { return failedICHash_.extract(); } |
| 603 |
void setFailedICHash(mozilla::HashNumber hash) { |
| 604 |
MOZ_ASSERT(failedICHash_.isNothing()); |
| 605 |
if (!hasPurgedStubs_) { |
| 606 |
failedICHash_.emplace(hash); |
| 607 |
} |
| 608 |
} |
| 609 |
#endif |
| 610 |
|
| 611 |
inline void clearFailedICHash() { |
| 612 |
#ifdef DEBUG |
| 613 |
failedICHash_.reset(); |
| 614 |
#endif |
| 615 |
} |
| 616 |
}; |
| 617 |
|
| 618 |
// Ensures no JitScripts are purged in the current zone. |
| 619 |
class MOZ_RAII AutoKeepJitScripts { |
| 620 |
jit::JitZone* zone_; |
| 621 |
bool prev_; |
| 622 |
|
| 623 |
AutoKeepJitScripts(const AutoKeepJitScripts&) = delete; |
| 624 |
void operator=(const AutoKeepJitScripts&) = delete; |
| 625 |
|
| 626 |
public: |
| 627 |
explicit inline AutoKeepJitScripts(JSContext* cx); |
| 628 |
inline ~AutoKeepJitScripts(); |
| 629 |
}; |
| 630 |
|
| 631 |
// Mark ICScripts on the stack as active, so that they are not discarded |
| 632 |
// during GC, and copy active Baseline IC stubs to the new stub space. |
| 633 |
void MarkActiveICScriptsAndCopyStubs(Zone* zone, ICStubSpace& newStubSpace); |
| 634 |
|
| 635 |
#ifdef JS_STRUCTURED_SPEW |
| 636 |
void JitSpewBaselineICStats(JSScript* script, const char* dumpReason); |
| 637 |
#endif |
| 638 |
|
| 639 |
} // namespace jit |
| 640 |
} // namespace js |
| 641 |
|
| 642 |
#endif /* jit_JitScript_h */ |