Closed Bug 1781183 Opened 3 years ago Closed 3 years ago

Precalculate principal for AutoCheckRecursionLimit in frontend

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
105 Branch
Tracking Status
firefox105 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(7 files)

The principal calculation requires JSContext*, and also the calculation inside AutoCheckRecursionLimit is problematic in term of performance.

https://searchfox.org/mozilla-central/rev/23bf1890e07f780ba70e075bc8f46ffb85d1128c/js/public/friend/StackLimits.h#161-172

MOZ_ALWAYS_INLINE bool AutoCheckRecursionLimit::checkWithStackPointerDontReport(
    JSContext* cx, void* sp) const {
  // getStackLimitSlow(cx) is pretty slow because it has to do an uninlined
  // call to runningWithTrustedPrincipals to determine which stack limit to
  // use. To work around this, check the untrusted limit first to avoid the
  // overhead in most cases.
  uintptr_t untrustedLimit =
      getStackLimitHelper(cx, JS::StackForUntrustedScript, 0);
  if (MOZ_LIKELY(checkLimitImpl(untrustedLimit, sp))) {
    return true;
  }
  return checkLimitImpl(getStackLimitSlow(cx), sp);

Inside frontend, the principal is already known and it doesn't change during single compilation, and we should pre-calculate it and feed the stack limit directly.

Instead of using JSContext* to calculate the stack limit internally,
receive the stack limit as parameter.

Move the stack limit calculation around principal into JSContext method,
so that some consumer can pre-calculate it and feed it to
AutoCheckRecursionLimit.

Depends on D152772

parent parameter is used only internally.
Remove parent parameter from public methods.

This simplifies the stack limit parameter in the next patch.

Depends on D152774

FoldVisitor is subclass of RewritingParseNodeVisitor, which has
JSContext* field. and FoldVisitor doesn't have to have the same field.

Depends on D152776

Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/4e1f50a9d0d7 Part 1: Add uintptr_t variant methods to AutoCheckRecursionLimit. r=bthrall https://hg.mozilla.org/integration/autoland/rev/17314cfdf984 Part 2: Add JSContext::stackLimitForCurrentPrincipal. r=bthrall https://hg.mozilla.org/integration/autoland/rev/a6da48864831 Part 3: Add ParserBase::stackLimit_. r=bthrall https://hg.mozilla.org/integration/autoland/rev/ad790c2acf09 Part 4: Simplify BytecodeEmitter constructor. r=bthrall https://hg.mozilla.org/integration/autoland/rev/aff25780db95 Part 5: Add BytecodeEmitter::stackLimit. r=bthrall https://hg.mozilla.org/integration/autoland/rev/240d1931ce20 Part 6: Remove redundant field from FoldVisitor. r=bthrall https://hg.mozilla.org/integration/autoland/rev/c6adbe1e7195 Part 7: Pass stack limit to AutoCheckRecursionLimit. r=bthrall
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: