Issue #1691 - Part 7e: Dependencies for required to finish part 7d. https://bugzilla.mozilla.org/show_bug.cgi?id=1331662 Reimplement EvaluateString using the ExecutionContext class. https://bugzilla.mozilla.org/show_bug.cgi?id=1316078 Extract redudant code into StartOffThreadParseTask. Use an ExclusiveContext instead of a JSContext in XDR functions. Add a script decoder as a valid off-main-thread parse-task. https://bugzilla.mozilla.org/show_bug.cgi?id=900784 Add nsJSUtils functions for encoding and decoding the bytecode. https://bugzilla.mozilla.org/show_bug.cgi?id=1316081 Add XDRIncrementalEncoder to replace delazified LazyScript in the encoded XDR buffer. Add an XDRIncrementalEncoder instance on the ScriptSource. Expose a new JSAPI to incrementally encode bytecode when it is generated. https://bugzilla.mozilla.org/show_bug.cgi?id=1334091 XDR function use the sourceObject instead of the enclosingScript as argument.

(cherry picked from commit d6de9a669f4b2f5115670bd771cd53d7cfb3956a)
This commit is contained in:
Brian Smith 2023-04-20 07:38:48 -05:00 committed by roytam1
commit 993476283d
22 changed files with 1224 additions and 171 deletions

View file

@ -431,6 +431,11 @@ class ScriptSource
// memory management.
const char* introductionType_;
// The bytecode cache encoder is used to encode only the content of function
// which are delazified. If this value is not nullptr, then each delazified
// function should be recorded before their first execution.
UniquePtr<XDRIncrementalEncoder> xdrEncoder_;
// True if we can call JSRuntime::sourceHook to load the source on
// demand. If sourceRetrievable_ and hasSourceData() are false, it is not
// possible to get source at all.
@ -452,6 +457,7 @@ class ScriptSource
parameterListEnd_(0),
introducerFilename_(nullptr),
introductionType_(nullptr),
xdrEncoder_(nullptr),
sourceRetrievable_(false),
hasIntroductionOffset_(false)
{
@ -574,6 +580,29 @@ class ScriptSource
introductionOffset_ = offset;
hasIntroductionOffset_ = true;
}
// Return wether an XDR encoder is present or not.
bool hasEncoder() const { return bool(xdrEncoder_); }
// Create a new XDR encoder, and encode the top-level JSScript. The result
// of the encoding would be available in the |buffer| provided as argument,
// as soon as |xdrFinalize| is called and all xdr function calls returned
// successfully.
bool xdrEncodeTopLevel(ExclusiveContext* cx, JS::TranscodeBuffer& buffer, HandleScript script);
// Encode a delazified JSFunction. In case of errors, the XDR encoder is
// freed and the |buffer| provided as argument to |xdrEncodeTopLevel| is
// considered undefined.
//
// The |sourceObject| argument is the object holding the current
// ScriptSource.
bool xdrEncodeFunction(ExclusiveContext* cx, HandleFunction fun,
HandleScriptSource sourceObject);
// Linearize the encoded content in the |buffer| provided as argument to
// |xdrEncodeTopLevel|, and free the XDR encoder. In case of errors, the
// |buffer| is considered undefined.
bool xdrFinalizeEncoder();
};
class ScriptSourceHolder
@ -695,12 +724,12 @@ AsyncKindFromBits(unsigned val) {
*/
template<XDRMode mode>
bool
XDRScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript enclosingScript,
XDRScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScriptSource sourceObject,
HandleFunction fun, MutableHandleScript scriptp);
template<XDRMode mode>
bool
XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScript enclosingScript,
XDRLazyScript(XDRState<mode>* xdr, HandleScope enclosingScope, HandleScriptSource sourceObject,
HandleFunction fun, MutableHandle<LazyScript*> lazy);
/*
@ -808,7 +837,7 @@ class JSScript : public js::gc::TenuredCell
friend
bool
js::XDRScript(js::XDRState<mode>* xdr, js::HandleScope enclosingScope,
js::HandleScript enclosingScript, js::HandleFunction fun,
js::HandleScriptSource sourceObject, js::HandleFunction fun,
js::MutableHandleScript scriptp);
friend bool
@ -1211,11 +1240,11 @@ class JSScript : public js::gc::TenuredCell
return funLength_;
}
size_t sourceStart() const {
uint32_t sourceStart() const {
return sourceStart_;
}
size_t sourceEnd() const {
uint32_t sourceEnd() const {
return sourceEnd_;
}
@ -2076,11 +2105,11 @@ class LazyScript : public gc::TenuredCell
// The "script" argument to this function can be null. If it's non-null,
// then this LazyScript should be associated with the given JSScript.
//
// The enclosingScript and enclosingScope arguments may be null if the
// The sourceObject and enclosingScope arguments may be null if the
// enclosing function is also lazy.
static LazyScript* Create(ExclusiveContext* cx, HandleFunction fun,
HandleScript script, HandleScope enclosingScope,
HandleScript enclosingScript,
HandleScriptSource sourceObject,
uint64_t packedData, uint32_t begin, uint32_t end,
uint32_t toStringStart, uint32_t lineno, uint32_t column);