1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "jit/JitScript-inl.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/CheckedInt.h"
#include <utility>
#include "jit/BaselineIC.h"
#include "jit/BaselineJIT.h"
#include "jit/BytecodeAnalysis.h"
#include "jit/IonScript.h"
#include "jit/JitFrames.h"
#include "jit/JitSpewer.h"
#include "jit/ScriptFromCalleeToken.h"
#include "jit/TrialInlining.h"
#include "vm/BytecodeUtil.h"
#include "vm/Compartment.h"
#include "vm/FrameIter.h" // js::OnlyJSJitFrameIter
#include "vm/JitActivation.h"
#include "vm/JSScript.h"
#include "gc/GCContext-inl.h"
#include "jit/JSJitFrameIter-inl.h"
#include "vm/JSContext-inl.h"
#include "vm/JSScript-inl.h"
using namespace js;
using namespace js::jit;
using mozilla::CheckedInt;
JitScript::JitScript(JSScript* script, Offset fallbackStubsOffset,
Offset endOffset, const char* profileString)
: profileString_(profileString),
endOffset_(endOffset),
icScript_(script->getWarmUpCount(),
fallbackStubsOffset - offsetOfICScript(),
endOffset - offsetOfICScript(),
/*depth=*/0) {
// Ensure the baselineScript_ and ionScript_ fields match the BaselineDisabled
// and IonDisabled script flags.
if (!script->canBaselineCompile()) {
setBaselineScriptImpl(script, BaselineDisabledScriptPtr);
}
if (!script->canIonCompile()) {
setIonScriptImpl(script, IonDisabledScriptPtr);
}
}
#ifdef DEBUG
JitScript::~JitScript() {
// The contents of the stub space are removed and freed separately after the
// next minor GC. See prepareForDestruction.
MOZ_ASSERT(jitScriptStubSpace_.isEmpty());
// BaselineScript and IonScript must have been destroyed at this point.
MOZ_ASSERT(!hasBaselineScript());
MOZ_ASSERT(!hasIonScript());
}
#else
JitScript::~JitScript() = default;
#endif
bool JSScript::createJitScript(JSContext* cx) {
MOZ_ASSERT(!hasJitScript());
cx->check(this);
// Scripts with a JitScript can run in the Baseline Interpreter. Make sure
// we don't create a JitScript for scripts we shouldn't Baseline interpret.
MOZ_ASSERT_IF(IsBaselineInterpreterEnabled(),
CanBaselineInterpretScript(this));
// Store the profile string in the JitScript if the profiler is enabled.
const char* profileString = nullptr;
if (cx->runtime()->geckoProfiler().enabled()) {
profileString = cx->runtime()->geckoProfiler().profileString(cx, this);
if (!profileString) {
return false;
}
}
static_assert(sizeof(JitScript) % sizeof(uintptr_t) == 0,
"Trailing arrays must be aligned properly");
static_assert(sizeof(ICEntry) % sizeof(uintptr_t) == 0,
"Trailing arrays must be aligned properly");
static_assert(
sizeof(JitScript) == offsetof(JitScript, icScript_) + sizeof(ICScript),
"icScript_ must be the last field");
// Calculate allocation size.
CheckedInt<uint32_t> allocSize = sizeof(JitScript);
allocSize += CheckedInt<uint32_t>(numICEntries()) * sizeof(ICEntry);
allocSize += CheckedInt<uint32_t>(numICEntries()) * sizeof(ICFallbackStub);
if (!allocSize.isValid()) {
ReportAllocationOverflow(cx);
return false;
}
void* raw = cx->pod_malloc<uint8_t>(allocSize.value());
MOZ_ASSERT(uintptr_t(raw) % alignof(JitScript) == 0);
if (!raw) {
return false;
}
size_t fallbackStubsOffset =
sizeof(JitScript) + numICEntries() * sizeof(ICEntry);
UniquePtr<JitScript> jitScript(new (raw) JitScript(
this, fallbackStubsOffset, allocSize.value(), profileString));
// Sanity check the length computation.
MOZ_ASSERT(jitScript->numICEntries() == numICEntries());
jitScript->icScript()->initICEntries(cx, this);
warmUpData_.initJitScript(jitScript.release());
AddCellMemory(this, allocSize.value(), MemoryUse::JitScript);
// We have a JitScript so we can set the script's jitCodeRaw pointer to the
// Baseline Interpreter code.
updateJitCodeRaw(cx->runtime());
return true;
}
void JSScript::maybeReleaseJitScript(JS::GCContext* gcx) {
MOZ_ASSERT(hasJitScript());
if (zone()->jitZone()->keepJitScripts() || jitScript()->hasBaselineScript() ||
jitScript()->active()) {
return;
}
releaseJitScript(gcx);
}
void JSScript::releaseJitScript(JS::GCContext* gcx) {
MOZ_ASSERT(hasJitScript());
MOZ_ASSERT(!hasBaselineScript());
MOZ_ASSERT(!hasIonScript());
gcx->removeCellMemory(this, jitScript()->allocBytes(), MemoryUse::JitScript);
JitScript::Destroy(zone(), jitScript());
warmUpData_.clearJitScript();
updateJitCodeRaw(gcx->runtime());
}
void JSScript::releaseJitScriptOnFinalize(JS::GCContext* gcx) {
MOZ_ASSERT(hasJitScript());
if (hasIonScript()) {
IonScript* ion = jitScript()->clearIonScript(gcx, this);
jit::IonScript::Destroy(gcx, ion);
}
if (hasBaselineScript()) {
BaselineScript* baseline = jitScript()->clearBaselineScript(gcx, this);
jit::BaselineScript::Destroy(gcx, baseline);
}
releaseJitScript(gcx);
}
void JitScript::trace(JSTracer* trc) {
icScript_.trace(trc);
if (hasBaselineScript()) {
baselineScript()->trace(trc);
}
if (hasIonScript()) {
ionScript()->trace(trc);
}
if (templateEnv_.isSome()) {
TraceNullableEdge(trc, templateEnv_.ptr(), "jitscript-template-env");
}
if (hasInliningRoot()) {
inliningRoot()->trace(trc);
}
}
void ICScript::trace(JSTracer* trc) {
// Mark all IC stub codes hanging off the IC stub entries.
for (size_t i = 0; i < numICEntries(); i++) {
ICEntry& ent = icEntry(i);
ent.trace(trc);
}
}
bool ICScript::addInlinedChild(JSContext* cx, UniquePtr<ICScript> child,
uint32_t pcOffset) {
MOZ_ASSERT(!hasInlinedChild(pcOffset));
if (!inlinedChildren_) {
inlinedChildren_ = cx->make_unique<Vector<CallSite>>(cx);
if (!inlinedChildren_) {
return false;
}
}
// First reserve space in inlinedChildren_ to ensure that if the ICScript is
// added to the inlining root, it can also be added to inlinedChildren_.
CallSite callsite(child.get(), pcOffset);
if (!inlinedChildren_->reserve(inlinedChildren_->length() + 1)) {
return false;
}
if (!inliningRoot()->addInlinedScript(std::move(child))) {
return false;
}
inlinedChildren_->infallibleAppend(callsite);
return true;
}
ICScript* ICScript::findInlinedChild(uint32_t pcOffset) {
for (auto& callsite : *inlinedChildren_) {
if (callsite.pcOffset_ == pcOffset) {
return callsite.callee_;
}
}
MOZ_CRASH("Inlined child expected at pcOffset");
}
void ICScript::removeInlinedChild(uint32_t pcOffset) {
MOZ_ASSERT(inliningRoot());
inlinedChildren_->eraseIf([pcOffset](const CallSite& callsite) -> bool {
return callsite.pcOffset_ == pcOffset;
});
}
bool ICScript::hasInlinedChild(uint32_t pcOffset) {
if (!inlinedChildren_) {
return false;
}
for (auto& callsite : *inlinedChildren_) {
if (callsite.pcOffset_ == pcOffset) {
return true;
}
}
return false;
}
void JitScript::resetWarmUpCount(uint32_t count) {
icScript_.resetWarmUpCount(count);
if (hasInliningRoot()) {
inliningRoot()->resetWarmUpCounts(count);
}
}
void JitScript::ensureProfileString(JSContext* cx, JSScript* script) {
MOZ_ASSERT(cx->runtime()->geckoProfiler().enabled());
if (profileString_) {
return;
}
AutoEnterOOMUnsafeRegion oomUnsafe;
profileString_ = cx->runtime()->geckoProfiler().profileString(cx, script);
if (!profileString_) {
oomUnsafe.crash("Failed to allocate profile string");
}
}
/* static */
void JitScript::Destroy(Zone* zone, JitScript* script) {
script->prepareForDestruction(zone);
js_delete(script);
}
void JitScript::prepareForDestruction(Zone* zone) {
// When the script contains pointers to nursery things, the store buffer can
// contain entries that point into the fallback stub space. Since we can
// destroy scripts outside the context of a GC, this situation could result
// in us trying to mark invalid store buffer entries.
//
// Defer freeing any allocated blocks until after the next minor GC.
jitScriptStubSpace_.freeAllAfterMinorGC(zone);
// Trigger write barriers.
baselineScript_.set(zone, nullptr);
ionScript_.set(zone, nullptr);
}
struct FallbackStubs {
ICScript* const icScript_;
explicit FallbackStubs(ICScript* icScript) : icScript_(icScript) {}
size_t numEntries() const { return icScript_->numICEntries(); }
ICFallbackStub* operator[](size_t index) const {
return icScript_->fallbackStub(index);
}
};
static bool ComputeBinarySearchMid(FallbackStubs stubs, uint32_t pcOffset,
size_t* loc) {
return mozilla::BinarySearchIf(
stubs, 0, stubs.numEntries(),
[pcOffset](const ICFallbackStub* stub) {
if (pcOffset < stub->pcOffset()) {
return -1;
}
if (stub->pcOffset() < pcOffset) {
return 1;
}
return 0;
},
loc);
}
ICEntry& ICScript::icEntryFromPCOffset(uint32_t pcOffset) {
size_t mid;
MOZ_ALWAYS_TRUE(ComputeBinarySearchMid(FallbackStubs(this), pcOffset, &mid));
MOZ_ASSERT(mid < numICEntries());
ICEntry& entry = icEntry(mid);
MOZ_ASSERT(fallbackStubForICEntry(&entry)->pcOffset() == pcOffset);
return entry;
}
ICEntry* ICScript::interpreterICEntryFromPCOffset(uint32_t pcOffset) {
// We have to return the entry to store in BaselineFrame::interpreterICEntry
// when resuming in the Baseline Interpreter at pcOffset. The bytecode op at
// pcOffset does not necessarily have an ICEntry, so we want to return the
// first ICEntry for which the following is true:
//
// entry.pcOffset() >= pcOffset
//
// Fortunately, ComputeBinarySearchMid returns exactly this entry.
size_t mid;
ComputeBinarySearchMid(FallbackStubs(this), pcOffset, &mid);
if (mid < numICEntries()) {
ICEntry& entry = icEntry(mid);
MOZ_ASSERT(fallbackStubForICEntry(&entry)->pcOffset() >= pcOffset);
return &entry;
}
// Resuming at a pc after the last ICEntry. Just return nullptr:
// BaselineFrame::interpreterICEntry will never be used in this case.
return nullptr;
}
void JitScript::purgeOptimizedStubs(JSScript* script) {
MOZ_ASSERT(script->jitScript() == this);
Zone* zone = script->zone();
if (IsAboutToBeFinalizedUnbarriered(script)) {
// We're sweeping and the script is dead. Don't purge optimized stubs
// because (1) accessing CacheIRStubInfo pointers in ICStubs is invalid
// because we may have swept them already when we started (incremental)
// sweeping and (2) it's unnecessary because this script will be finalized
// soon anyway.
return;
}
JitSpew(JitSpew_BaselineIC, "Purging optimized stubs");
icScript()->purgeOptimizedStubs(zone);
if (hasInliningRoot()) {
inliningRoot()->purgeOptimizedStubs(zone);
}
#ifdef DEBUG
failedICHash_.reset();
hasPurgedStubs_ = true;
#endif
}
void ICScript::purgeOptimizedStubs(Zone* zone) {
for (size_t i = 0; i < numICEntries(); i++) {
ICEntry& entry = icEntry(i);
ICStub* lastStub = entry.firstStub();
while (!lastStub->isFallback()) {
lastStub = lastStub->toCacheIRStub()->next();
}
// Unlink all stubs allocated in the optimized space.
ICStub* stub = entry.firstStub();
ICCacheIRStub* prev = nullptr;
while (stub != lastStub) {
if (!stub->toCacheIRStub()->allocatedInFallbackSpace()) {
lastStub->toFallbackStub()->unlinkStub(zone, &entry, prev,
stub->toCacheIRStub());
stub = stub->toCacheIRStub()->next();
continue;
}
prev = stub->toCacheIRStub();
stub = stub->toCacheIRStub()->next();
}
lastStub->toFallbackStub()->clearHasFoldedStub();
}
#ifdef DEBUG
// All remaining stubs must be allocated in the fallback space.
for (size_t i = 0; i < numICEntries(); i++) {
ICEntry& entry = icEntry(i);
ICStub* stub = entry.firstStub();
while (!stub->isFallback()) {
MOZ_ASSERT(stub->toCacheIRStub()->allocatedInFallbackSpace());
stub = stub->toCacheIRStub()->next();
}
}
#endif
}
bool JitScript::ensureHasCachedBaselineJitData(JSContext* cx,
HandleScript script) {
if (templateEnv_.isSome()) {
return true;
}
if (!script->function() ||
!script->function()->needsFunctionEnvironmentObjects()) {
templateEnv_.emplace();
return true;
}
Rooted<EnvironmentObject*> templateEnv(cx);
Rooted<JSFunction*> fun(cx, script->function());
if (fun->needsNamedLambdaEnvironment()) {
templateEnv = NamedLambdaObject::createTemplateObject(cx, fun);
if (!templateEnv) {
return false;
}
}
if (fun->needsCallObject()) {
templateEnv = CallObject::createTemplateObject(cx, script, templateEnv);
if (!templateEnv) {
return false;
}
}
templateEnv_.emplace(templateEnv);
return true;
}
bool JitScript::ensureHasCachedIonData(JSContext* cx, HandleScript script) {
MOZ_ASSERT(script->jitScript() == this);
if (usesEnvironmentChain_.isSome()) {
return true;
}
if (!ensureHasCachedBaselineJitData(cx, script)) {
return false;
}
usesEnvironmentChain_.emplace(ScriptUsesEnvironmentChain(script));
return true;
}
void JitScript::setBaselineScriptImpl(JSScript* script,
BaselineScript* baselineScript) {
JSRuntime* rt = script->runtimeFromMainThread();
setBaselineScriptImpl(rt->gcContext(), script, baselineScript);
}
void JitScript::setBaselineScriptImpl(JS::GCContext* gcx, JSScript* script,
BaselineScript* baselineScript) {
if (hasBaselineScript()) {
gcx->removeCellMemory(script, baselineScript_->allocBytes(),
MemoryUse::BaselineScript);
baselineScript_.set(script->zone(), nullptr);
}
MOZ_ASSERT(ionScript_ == nullptr || ionScript_ == IonDisabledScriptPtr);
baselineScript_.set(script->zone(), baselineScript);
if (hasBaselineScript()) {
AddCellMemory(script, baselineScript_->allocBytes(),
MemoryUse::BaselineScript);
}
script->resetWarmUpResetCounter();
script->updateJitCodeRaw(gcx->runtime());
}
void JitScript::setIonScriptImpl(JSScript* script, IonScript* ionScript) {
JSRuntime* rt = script->runtimeFromMainThread();
setIonScriptImpl(rt->gcContext(), script, ionScript);
}
void JitScript::setIonScriptImpl(JS::GCContext* gcx, JSScript* script,
IonScript* ionScript) {
MOZ_ASSERT_IF(ionScript != IonDisabledScriptPtr,
!baselineScript()->hasPendingIonCompileTask());
JS::Zone* zone = script->zone();
if (hasIonScript()) {
gcx->removeCellMemory(script, ionScript_->allocBytes(),
MemoryUse::IonScript);
ionScript_.set(zone, nullptr);
}
ionScript_.set(zone, ionScript);
MOZ_ASSERT_IF(hasIonScript(), hasBaselineScript());
if (hasIonScript()) {
AddCellMemory(script, ionScript_->allocBytes(), MemoryUse::IonScript);
}
script->updateJitCodeRaw(gcx->runtime());
}
#ifdef JS_STRUCTURED_SPEW
static bool HasEnteredCounters(ICEntry& entry) {
ICStub* stub = entry.firstStub();
if (stub && !stub->isFallback()) {
return true;
}
return false;
}
void jit::JitSpewBaselineICStats(JSScript* script, const char* dumpReason) {
MOZ_ASSERT(script->hasJitScript());
JSContext* cx = TlsContext.get();
AutoStructuredSpewer spew(cx, SpewChannel::BaselineICStats, script);
if (!spew) {
return;
}
JitScript* jitScript = script->jitScript();
spew->property("reason", dumpReason);
spew->beginListProperty("entries");
for (size_t i = 0; i < jitScript->numICEntries(); i++) {
ICEntry& entry = jitScript->icEntry(i);
ICFallbackStub* fallback = jitScript->fallbackStub(i);
if (!HasEnteredCounters(entry)) {
continue;
}
uint32_t pcOffset = fallback->pcOffset();
jsbytecode* pc = script->offsetToPC(pcOffset);
unsigned column;
unsigned int line = PCToLineNumber(script, pc, &column);
spew->beginObject();
spew->property("op", CodeName(JSOp(*pc)));
spew->property("pc", pcOffset);
spew->property("line", line);
spew->property("column", column);
spew->beginListProperty("counts");
ICStub* stub = entry.firstStub();
while (stub && !stub->isFallback()) {
uint32_t count = stub->enteredCount();
spew->value(count);
stub = stub->toCacheIRStub()->next();
}
spew->endList();
spew->property("fallback_count", fallback->enteredCount());
spew->endObject();
}
spew->endList();
}
#endif
static void MarkActiveJitScripts(JSContext* cx,
const JitActivationIterator& activation) {
for (OnlyJSJitFrameIter iter(activation); !iter.done(); ++iter) {
const JSJitFrameIter& frame = iter.frame();
switch (frame.type()) {
case FrameType::BaselineJS:
frame.script()->jitScript()->setActive();
break;
case FrameType::Exit:
if (frame.exitFrame()->is<LazyLinkExitFrameLayout>()) {
LazyLinkExitFrameLayout* ll =
frame.exitFrame()->as<LazyLinkExitFrameLayout>();
JSScript* script =
ScriptFromCalleeToken(ll->jsFrame()->calleeToken());
script->jitScript()->setActive();
}
break;
case FrameType::Bailout:
case FrameType::IonJS: {
// Keep the JitScript and BaselineScript around, since bailouts from
// the ion jitcode need to re-enter into the Baseline code.
frame.script()->jitScript()->setActive();
for (InlineFrameIterator inlineIter(cx, &frame); inlineIter.more();
++inlineIter) {
inlineIter.script()->jitScript()->setActive();
}
break;
}
default:;
}
}
}
void jit::MarkActiveJitScripts(Zone* zone) {
if (zone->isAtomsZone()) {
return;
}
JSContext* cx = TlsContext.get();
for (JitActivationIterator iter(cx); !iter.done(); ++iter) {
if (iter->compartment()->zone() == zone) {
MarkActiveJitScripts(cx, iter);
}
}
}
InliningRoot* JitScript::getOrCreateInliningRoot(JSContext* cx,
JSScript* script) {
if (!inliningRoot_) {
inliningRoot_ = js::MakeUnique<InliningRoot>(cx, script);
if (!inliningRoot_) {
ReportOutOfMemory(cx);
return nullptr;
}
icScript_.inliningRoot_ = inliningRoot_.get();
}
return inliningRoot_.get();
}
gc::AllocSite* JitScript::createAllocSite(JSScript* script) {
MOZ_ASSERT(script->jitScript() == this);
Nursery& nursery = script->runtimeFromMainThread()->gc.nursery();
if (!nursery.canCreateAllocSite()) {
// Don't block attaching an optimized stub, but don't process allocations
// for this site.
return script->zone()->unknownAllocSite(JS::TraceKind::Object);
}
if (!allocSites_.reserve(allocSites_.length() + 1)) {
return nullptr;
}
ICStubSpace* stubSpace = jitScriptStubSpace();
auto* site =
static_cast<gc::AllocSite*>(stubSpace->alloc(sizeof(gc::AllocSite)));
if (!site) {
return nullptr;
}
new (site) gc::AllocSite(script->zone(), script, JS::TraceKind::Object);
allocSites_.infallibleAppend(site);
nursery.noteAllocSiteCreated();
return site;
}
bool JitScript::resetAllocSites(bool resetNurserySites,
bool resetPretenuredSites) {
MOZ_ASSERT(resetNurserySites || resetPretenuredSites);
bool anyReset = false;
for (gc::AllocSite* site : allocSites_) {
if ((resetNurserySites && site->initialHeap() == gc::Heap::Default) ||
(resetPretenuredSites && site->initialHeap() == gc::Heap::Tenured)) {
if (site->maybeResetState()) {
anyReset = true;
}
}
}
return anyReset;
}
JitScriptICStubSpace* ICScript::jitScriptStubSpace() {
if (isInlined()) {
return inliningRoot_->jitScriptStubSpace();
}
return outerJitScript()->jitScriptStubSpace();
}
JitScript* ICScript::outerJitScript() {
MOZ_ASSERT(!isInlined());
uint8_t* ptr = reinterpret_cast<uint8_t*>(this);
return reinterpret_cast<JitScript*>(ptr - JitScript::offsetOfICScript());
}
#ifdef DEBUG
// This hash is used to verify that we do not recompile after a
// TranspiledCacheIR invalidation with the exact same ICs.
//
// It should change iff an ICEntry in this ICScript (or an ICScript
// inlined into this ICScript) is modified such that we will make a
// different decision in WarpScriptOracle::maybeInlineIC. This means:
//
// 1. The hash will change if we attach a new stub.
// 2. The hash will change if the entered count of any CacheIR stub
// other than the first changes from 0.
// 3. The hash will change if the entered count of the fallback stub
// changes from 0.
//
HashNumber ICScript::hash() {
HashNumber h = 0;
for (size_t i = 0; i < numICEntries(); i++) {
ICStub* stub = icEntry(i).firstStub();
// Hash the address of the first stub.
h = mozilla::AddToHash(h, stub);
// Hash whether subsequent stubs have entry count 0.
if (!stub->isFallback()) {
stub = stub->toCacheIRStub()->next();
while (!stub->isFallback()) {
h = mozilla::AddToHash(h, stub->enteredCount() == 0);
stub = stub->toCacheIRStub()->next();
}
}
// Hash whether the fallback has entry count 0.
MOZ_ASSERT(stub->isFallback());
h = mozilla::AddToHash(h, stub->enteredCount() == 0);
}
return h;
}
#endif
|