Bug 1700954 - Remove remaining BinAST fragments from ScriptLoader. r=arai,hsivonen,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D109765
This commit is contained in:
Ted Campbell 2021-03-26 13:01:40 +00:00
parent eebd53c51c
commit 9b6e632d81
9 changed files with 19 additions and 144 deletions

View file

@ -133,7 +133,6 @@ js/public/
js/xpconnect/ js/xpconnect/
js/src/devtools/ js/src/devtools/
js/src/jit-test/ js/src/jit-test/
js/src/jsapi-tests/binast/
js/src/tests/ js/src/tests/
js/src/Y.js js/src/Y.js

View file

@ -247,16 +247,6 @@ nsresult JSExecutionContext::JoinDecode(JS::OffThreadToken** aOffThreadToken) {
return NS_OK; return NS_OK;
} }
nsresult JSExecutionContext::JoinDecodeBinAST(
JS::OffThreadToken** aOffThreadToken) {
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult JSExecutionContext::DecodeBinAST(JS::CompileOptions& aCompileOptions,
const uint8_t* aBuf, size_t aLength) {
return NS_ERROR_NOT_IMPLEMENTED;
}
JSScript* JSExecutionContext::GetScript() { JSScript* JSExecutionContext::GetScript() {
#ifdef DEBUG #ifdef DEBUG
MOZ_ASSERT(!mSkip); MOZ_ASSERT(!mSkip);

View file

@ -137,12 +137,6 @@ class MOZ_STACK_CLASS JSExecutionContext final {
// thread. // thread.
nsresult JoinDecode(JS::OffThreadToken** aOffThreadToken); nsresult JoinDecode(JS::OffThreadToken** aOffThreadToken);
nsresult JoinDecodeBinAST(JS::OffThreadToken** aOffThreadToken);
// Decode a BinAST encoded script contained in a buffer.
nsresult DecodeBinAST(JS::CompileOptions& aCompileOptions,
const uint8_t* aBuf, size_t aLength);
// Get a successfully compiled script. // Get a successfully compiled script.
JSScript* GetScript(); JSScript* GetScript();

View file

@ -63,8 +63,6 @@ class nsJSUtils {
const nsAString& aBody, const nsAString& aBody,
JSObject** aFunctionObject); JSObject** aFunctionObject);
static bool BinASTEncodingEnabled() { return false; }
static nsresult CompileModule(JSContext* aCx, static nsresult CompileModule(JSContext* aCx,
JS::SourceText<char16_t>& aSrcBuf, JS::SourceText<char16_t>& aSrcBuf,
JS::Handle<JSObject*> aEvaluationGlobal, JS::Handle<JSObject*> aEvaluationGlobal,

View file

@ -151,18 +151,6 @@ ScriptLoadHandler::OnIncrementalData(nsIIncrementalStreamLoader* aLoader,
rv = DecodeRawData(aData, aDataLength, /* aEndOfStream = */ false); rv = DecodeRawData(aData, aDataLength, /* aEndOfStream = */ false);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// If SRI is required for this load, appending new bytes to the hash.
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
}
} else if (mRequest->IsBinASTSource()) {
if (!mRequest->ScriptBinASTData().append(aData, aDataLength)) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Below we will/shall consume entire data chunk.
*aConsumedLength = aDataLength;
// If SRI is required for this load, appending new bytes to the hash. // If SRI is required for this load, appending new bytes to the hash.
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) { if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
@ -326,28 +314,6 @@ nsresult ScriptLoadHandler::EnsureKnownDataType(
MOZ_ASSERT(altDataType.IsEmpty()); MOZ_ASSERT(altDataType.IsEmpty());
} }
if (nsJSUtils::BinASTEncodingEnabled()) {
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(req);
if (httpChannel) {
nsAutoCString mimeType;
httpChannel->GetContentType(mimeType);
if (mimeType.LowerCaseEqualsASCII(APPLICATION_JAVASCRIPT_BINAST)) {
if (mRequest->ShouldAcceptBinASTEncoding()) {
mRequest->SetBinASTSource();
TRACE_FOR_TEST(mRequest->GetScriptElement(),
"scriptloader_load_source");
return NS_OK;
}
// If the request isn't allowed to accept BinAST, fallback to text
// source. The possibly binary source will be passed to normal
// JS parser and will throw error there.
mRequest->SetTextSource();
return NS_OK;
}
}
}
mRequest->SetTextSource(); mRequest->SetTextSource();
TRACE_FOR_TEST(mRequest->GetScriptElement(), "scriptloader_load_source"); TRACE_FOR_TEST(mRequest->GetScriptElement(), "scriptloader_load_source");
@ -396,15 +362,6 @@ ScriptLoadHandler::OnStreamComplete(nsIIncrementalStreamLoader* aLoader,
LOG(("ScriptLoadRequest (%p): Source length in code units = %u", LOG(("ScriptLoadRequest (%p): Source length in code units = %u",
mRequest.get(), unsigned(mRequest->ScriptTextLength()))); mRequest.get(), unsigned(mRequest->ScriptTextLength())));
// If SRI is required for this load, appending new bytes to the hash.
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
}
} else if (mRequest->IsBinASTSource()) {
if (!mRequest->ScriptBinASTData().append(aData, aDataLength)) {
return NS_ERROR_OUT_OF_MEMORY;
}
// If SRI is required for this load, appending new bytes to the hash. // If SRI is required for this load, appending new bytes to the hash.
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) { if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData); mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);

View file

@ -221,22 +221,14 @@ void ScriptLoadRequest::SetTextSource() {
} }
} }
void ScriptLoadRequest::SetBinASTSource() { MOZ_CRASH("BinAST not supported"); }
void ScriptLoadRequest::SetBytecode() { void ScriptLoadRequest::SetBytecode() {
MOZ_ASSERT(IsUnknownDataType()); MOZ_ASSERT(IsUnknownDataType());
mDataType = DataType::eBytecode; mDataType = DataType::eBytecode;
} }
bool ScriptLoadRequest::ShouldAcceptBinASTEncoding() const {
MOZ_CRASH("BinAST not supported");
}
void ScriptLoadRequest::ClearScriptSource() { void ScriptLoadRequest::ClearScriptSource() {
if (IsTextSource()) { if (IsTextSource()) {
ClearScriptText(); ClearScriptText();
} else if (IsBinASTSource()) {
ScriptBinASTData().clearAndFree();
} }
} }

View file

@ -162,22 +162,15 @@ class ScriptLoadRequest
} }
// Type of data provided by the nsChannel. // Type of data provided by the nsChannel.
enum class DataType : uint8_t { enum class DataType : uint8_t { eUnknown, eTextSource, eBytecode };
eUnknown,
eTextSource,
eBinASTSource,
eBytecode
};
bool IsUnknownDataType() const { return mDataType == DataType::eUnknown; } bool IsUnknownDataType() const { return mDataType == DataType::eUnknown; }
bool IsTextSource() const { return mDataType == DataType::eTextSource; } bool IsTextSource() const { return mDataType == DataType::eTextSource; }
bool IsBinASTSource() const { return false; } bool IsSource() const { return IsTextSource(); }
bool IsSource() const { return IsTextSource() || IsBinASTSource(); }
bool IsBytecode() const { return mDataType == DataType::eBytecode; } bool IsBytecode() const { return mDataType == DataType::eBytecode; }
void SetUnknownDataType(); void SetUnknownDataType();
void SetTextSource(); void SetTextSource();
void SetBinASTSource();
void SetBytecode(); void SetBytecode();
// Use a vector backed by the JS allocator for script text so that contents // Use a vector backed by the JS allocator for script text so that contents
@ -186,10 +179,6 @@ class ScriptLoadRequest
template <typename Unit> template <typename Unit>
using ScriptTextBuffer = Vector<Unit, 0, js::MallocAllocPolicy>; using ScriptTextBuffer = Vector<Unit, 0, js::MallocAllocPolicy>;
// BinAST data isn't transferred to the JS engine, so it doesn't need to use
// the JS allocator.
using BinASTSourceBuffer = Vector<uint8_t>;
bool IsUTF16Text() const { bool IsUTF16Text() const {
return mScriptData->is<ScriptTextBuffer<char16_t>>(); return mScriptData->is<ScriptTextBuffer<char16_t>>();
} }
@ -208,15 +197,6 @@ class ScriptLoadRequest
return mScriptData->as<ScriptTextBuffer<Unit>>(); return mScriptData->as<ScriptTextBuffer<Unit>>();
} }
const BinASTSourceBuffer& ScriptBinASTData() const {
MOZ_ASSERT(IsBinASTSource());
return mScriptData->as<BinASTSourceBuffer>();
}
BinASTSourceBuffer& ScriptBinASTData() {
MOZ_ASSERT(IsBinASTSource());
return mScriptData->as<BinASTSourceBuffer>();
}
size_t ScriptTextLength() const { size_t ScriptTextLength() const {
MOZ_ASSERT(IsTextSource()); MOZ_ASSERT(IsTextSource());
return IsUTF16Text() ? ScriptText<char16_t>().length() return IsUTF16Text() ? ScriptText<char16_t>().length()
@ -288,8 +268,6 @@ class ScriptLoadRequest
return element->GetParserCreated(); return element->GetParserCreated();
} }
bool ShouldAcceptBinASTEncoding() const;
void ClearScriptSource(); void ClearScriptSource();
void SetScript(JSScript* aScript); void SetScript(JSScript* aScript);
@ -334,8 +312,7 @@ class ScriptLoadRequest
JS::Heap<JSScript*> mScript; JS::Heap<JSScript*> mScript;
// Holds script source data for non-inline scripts. // Holds script source data for non-inline scripts.
Maybe<Variant<ScriptTextBuffer<char16_t>, ScriptTextBuffer<Utf8Unit>, Maybe<Variant<ScriptTextBuffer<char16_t>, ScriptTextBuffer<Utf8Unit>>>
BinASTSourceBuffer>>
mScriptData; mScriptData;
// The length of script source text, set when reading completes. This is used // The length of script source text, set when reading completes. This is used

View file

@ -324,7 +324,6 @@ static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
} else if (aRequest->IsTextSource()) { } else if (aRequest->IsTextSource()) {
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::SourceFallback); AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::SourceFallback);
} }
// TODO: Add telemetry for BinAST encoded source.
} else { } else {
MOZ_ASSERT(aRequest->IsLoading()); MOZ_ASSERT(aRequest->IsLoading());
if (aRequest->IsTextSource()) { if (aRequest->IsTextSource()) {
@ -332,7 +331,6 @@ static void CollectScriptTelemetry(ScriptLoadRequest* aRequest) {
} else if (aRequest->IsBytecode()) { } else if (aRequest->IsBytecode()) {
AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::AltData); AccumulateCategorical(LABELS_DOM_SCRIPT_LOADING_SOURCE::AltData);
} }
// TODO: Add telemetry for BinAST encoded source.
} }
} }
@ -1667,10 +1665,6 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) {
if (httpChannel) { if (httpChannel) {
// HTTP content negotation has little value in this context. // HTTP content negotation has little value in this context.
nsAutoCString acceptTypes("*/*"); nsAutoCString acceptTypes("*/*");
if (nsJSUtils::BinASTEncodingEnabled() &&
aRequest->ShouldAcceptBinASTEncoding()) {
acceptTypes = APPLICATION_JAVASCRIPT_BINAST ", */*";
}
rv = httpChannel->SetRequestHeader("Accept"_ns, acceptTypes, false); rv = httpChannel->SetRequestHeader("Accept"_ns, acceptTypes, false);
MOZ_ASSERT(NS_SUCCEEDED(rv)); MOZ_ASSERT(NS_SUCCEEDED(rv));
@ -2446,8 +2440,6 @@ NotifyOffThreadScriptLoadCompletedRunnable::Run() {
ProfilerString8View scriptSourceString; ProfilerString8View scriptSourceString;
if (request->IsTextSource()) { if (request->IsTextSource()) {
scriptSourceString = "ScriptCompileOffThread"; scriptSourceString = "ScriptCompileOffThread";
} else if (request->IsBinASTSource()) {
scriptSourceString = "BinASTDecodeOffThread";
} else { } else {
MOZ_ASSERT(request->IsBytecode()); MOZ_ASSERT(request->IsBytecode());
scriptSourceString = "BytecodeDecodeOffThread"; scriptSourceString = "BytecodeDecodeOffThread";
@ -2955,7 +2947,6 @@ bool ScriptLoader::ShouldCacheBytecode(ScriptLoadRequest* aRequest) {
bool hasSourceLengthMin = false; bool hasSourceLengthMin = false;
bool hasFetchCountMin = false; bool hasFetchCountMin = false;
size_t sourceLengthMin = 100; size_t sourceLengthMin = 100;
size_t binASTLengthMin = 70;
int32_t fetchCountMin = 4; int32_t fetchCountMin = 4;
LOG(("ScriptLoadRequest (%p): Bytecode-cache: strategy = %d.", aRequest, LOG(("ScriptLoadRequest (%p): Bytecode-cache: strategy = %d.", aRequest,
@ -2978,7 +2969,6 @@ bool ScriptLoader::ShouldCacheBytecode(ScriptLoadRequest* aRequest) {
hasSourceLengthMin = true; hasSourceLengthMin = true;
hasFetchCountMin = true; hasFetchCountMin = true;
sourceLengthMin = 1024; sourceLengthMin = 1024;
binASTLengthMin = 700;
// If we were to optimize only for speed, without considering the impact // If we were to optimize only for speed, without considering the impact
// on memory, we should set this threshold to 2. (Bug 900784 comment 120) // on memory, we should set this threshold to 2. (Bug 900784 comment 120)
fetchCountMin = 4; fetchCountMin = 4;
@ -2992,14 +2982,9 @@ bool ScriptLoader::ShouldCacheBytecode(ScriptLoadRequest* aRequest) {
if (hasSourceLengthMin) { if (hasSourceLengthMin) {
size_t sourceLength; size_t sourceLength;
size_t minLength; size_t minLength;
if (aRequest->IsTextSource()) { MOZ_ASSERT(aRequest->IsTextSource());
sourceLength = aRequest->mScriptTextLength; sourceLength = aRequest->mScriptTextLength;
minLength = sourceLengthMin; minLength = sourceLengthMin;
} else {
MOZ_ASSERT(aRequest->IsBinASTSource());
sourceLength = aRequest->ScriptBinASTData().length();
minLength = binASTLengthMin;
}
if (sourceLength < minLength) { if (sourceLength < minLength) {
LOG(("ScriptLoadRequest (%p): Bytecode-cache: Script is too small.", LOG(("ScriptLoadRequest (%p): Bytecode-cache: Script is too small.",
aRequest)); aRequest));
@ -3292,42 +3277,26 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
("ScriptLoadRequest (%p): Join (off-thread parsing) and " ("ScriptLoadRequest (%p): Join (off-thread parsing) and "
"Execute", "Execute",
aRequest)); aRequest));
if (aRequest->IsBinASTSource()) { MOZ_ASSERT(aRequest->IsTextSource());
rv = exec.JoinDecodeBinAST(&aRequest->mOffThreadToken); rv = exec.JoinCompile(&aRequest->mOffThreadToken);
} else {
MOZ_ASSERT(aRequest->IsTextSource());
rv = exec.JoinCompile(&aRequest->mOffThreadToken);
}
} else { } else {
// Main thread parsing (inline and small scripts) // Main thread parsing (inline and small scripts)
LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest)); LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest));
if (aRequest->IsBinASTSource()) { MOZ_ASSERT(aRequest->IsTextSource());
MaybeSourceText maybeSource;
rv = GetScriptSource(cx, aRequest, &maybeSource);
if (NS_SUCCEEDED(rv)) {
AUTO_PROFILER_MARKER_TEXT( AUTO_PROFILER_MARKER_TEXT(
"BinASTDecodeMainThread", JS, "ScriptCompileMainThread", JS,
MarkerInnerWindowIdFromDocShell(docShell), MarkerInnerWindowIdFromDocShell(docShell),
profilerLabelString); profilerLabelString);
rv = exec.DecodeBinAST(options, rv =
aRequest->ScriptBinASTData().begin(), maybeSource.constructed<SourceText<char16_t>>()
aRequest->ScriptBinASTData().length()); ? exec.Compile(options,
} else { maybeSource.ref<SourceText<char16_t>>())
MOZ_ASSERT(aRequest->IsTextSource()); : exec.Compile(options,
MaybeSourceText maybeSource; maybeSource.ref<SourceText<Utf8Unit>>());
rv = GetScriptSource(cx, aRequest, &maybeSource);
if (NS_SUCCEEDED(rv)) {
AUTO_PROFILER_MARKER_TEXT(
"ScriptCompileMainThread", JS,
MarkerInnerWindowIdFromDocShell(docShell),
profilerLabelString);
rv = maybeSource.constructed<SourceText<char16_t>>()
? exec.Compile(
options,
maybeSource.ref<SourceText<char16_t>>())
: exec.Compile(
options,
maybeSource.ref<SourceText<Utf8Unit>>());
}
} }
} }

View file

@ -75,7 +75,6 @@
#define APPLICATION_RDF_XML "application/rdf+xml" #define APPLICATION_RDF_XML "application/rdf+xml"
#define APPLICATION_WAPXHTML_XML "application/vnd.wap.xhtml+xml" #define APPLICATION_WAPXHTML_XML "application/vnd.wap.xhtml+xml"
#define APPLICATION_PACKAGE "application/package" #define APPLICATION_PACKAGE "application/package"
#define APPLICATION_JAVASCRIPT_BINAST "application/javascript-binast"
#define APPLICATION_WASM "application/wasm" #define APPLICATION_WASM "application/wasm"
#define AUDIO_BASIC "audio/basic" #define AUDIO_BASIC "audio/basic"