Bug 1505784 part 3 - Copy immutableFlags_ word in XDRScript instead of copying each flag separately. r=tcampbell
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 08 Nov 2018 19:35:26 +0000
changeset 445378 648aae3548989d0495cc03093ec9a9a6f531e443
parent 445377 e82a6edf415cf70486ad69959a4db6faf2aa80a9
child 445379 1f940df360da2cd74197285dd5f998991e4c92d8
push id35015
push userdluca@mozilla.com
push dateFri, 09 Nov 2018 17:45:20 +0000
treeherdermozilla-central@2f1158e5e0ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1505784
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1505784 part 3 - Copy immutableFlags_ word in XDRScript instead of copying each flag separately. r=tcampbell Depends on D11335 Differential Revision: https://phabricator.services.mozilla.com/D11336
js/src/vm/JSScript.cpp
--- a/js/src/vm/JSScript.cpp
+++ b/js/src/vm/JSScript.cpp
@@ -335,50 +335,30 @@ js::XDRScript(XDRState<mode>* xdr, Handl
               HandleScriptSourceObject sourceObjectArg, HandleFunction fun,
               MutableHandleScript scriptp)
 {
     using ImmutableFlags = JSScript::ImmutableFlags;
 
     /* NB: Keep this in sync with CopyScript. */
 
     enum ScriptBits {
-        NoScriptRval,
-        Strict,
-        ContainsDynamicNameAccess,
-        FunHasExtensibleScope,
-        FunHasAnyAliasedFormal,
-        ArgumentsHasVarBinding,
         NeedsArgsObj,
-        HasMappedArgsObj,
-        FunctionHasThisBinding,
-        FunctionHasExtraBodyVarScope,
-        IsGenerator,
-        IsAsync,
-        HasRest,
         OwnSource,
-        ExplicitUseStrict,
-        SelfHosted,
-        HasSingleton,
-        TreatAsRunOnce,
         HasLazyScript,
-        HasNonSyntacticScope,
-        HasInnerFunctions,
-        NeedsHomeObject,
-        IsDerivedClassConstructor,
-        IsDefaultClassConstructor,
     };
 
     uint32_t length, lineno, column, nfixed, nslots;
     uint32_t natoms, nsrcnotes;
     uint32_t nconsts, nobjects, nscopes, nregexps, ntrynotes, nscopenotes, nresumeoffsets;
     uint32_t prologueLength;
     uint32_t funLength = 0;
     uint32_t nTypeSets = 0;
     uint32_t scriptBits = 0;
     uint32_t bodyScopeIndex = 0;
+    uint32_t immutableFlags = 0;
 
     JSContext* cx = xdr->cx();
     RootedScript script(cx);
     natoms = nsrcnotes = 0;
     nconsts = nobjects = nscopes = nregexps = ntrynotes = nscopenotes = nresumeoffsets = 0;
 
     if (mode == XDR_ENCODE) {
         script = scriptp.get();
@@ -409,16 +389,18 @@ js::XDRScript(XDRState<mode>* xdr, Handl
         lineno = script->lineno();
         column = script->column();
         nfixed = script->nfixed();
         nslots = script->nslots();
 
         bodyScopeIndex = script->bodyScopeIndex();
         natoms = script->natoms();
 
+        immutableFlags = script->immutableFlags_;
+
         nsrcnotes = script->numNotes();
 
         nscopes = script->scopes().size();
         if (script->hasConsts()) {
             nconsts = script->consts().size();
         }
         if (script->hasObjects()) {
             nobjects = script->objects().size();
@@ -431,126 +413,66 @@ js::XDRScript(XDRState<mode>* xdr, Handl
         }
         if (script->hasResumeOffsets()) {
             nresumeoffsets = script->resumeOffsets().size();
         }
 
         nTypeSets = script->nTypeSets();
         funLength = script->funLength();
 
-        if (script->noScriptRval()) {
-            scriptBits |= (1 << NoScriptRval);
-        }
-        if (script->strict()) {
-            scriptBits |= (1 << Strict);
-        }
-        if (script->explicitUseStrict()) {
-            scriptBits |= (1 << ExplicitUseStrict);
-        }
-        if (script->selfHosted()) {
-            scriptBits |= (1 << SelfHosted);
-        }
-        if (script->bindingsAccessedDynamically()) {
-            scriptBits |= (1 << ContainsDynamicNameAccess);
-        }
-        if (script->funHasExtensibleScope()) {
-            scriptBits |= (1 << FunHasExtensibleScope);
-        }
-        if (script->funHasAnyAliasedFormal()) {
-            scriptBits |= (1 << FunHasAnyAliasedFormal);
-        }
-        if (script->argumentsHasVarBinding()) {
-            scriptBits |= (1 << ArgumentsHasVarBinding);
-        }
         if (script->analyzedArgsUsage() && script->needsArgsObj()) {
             scriptBits |= (1 << NeedsArgsObj);
         }
-        if (script->hasMappedArgsObj()) {
-            scriptBits |= (1 << HasMappedArgsObj);
-        }
-        if (script->functionHasThisBinding()) {
-            scriptBits |= (1 << FunctionHasThisBinding);
-        }
-        if (script->functionHasExtraBodyVarScope()) {
-            scriptBits |= (1 << FunctionHasExtraBodyVarScope);
-        }
         MOZ_ASSERT_IF(sourceObjectArg, sourceObjectArg->source() == script->scriptSource());
         if (!sourceObjectArg) {
             scriptBits |= (1 << OwnSource);
         }
-        if (script->isGenerator()) {
-            scriptBits |= (1 << IsGenerator);
-        }
-        if (script->isAsync()) {
-            scriptBits |= (1 << IsAsync);
-        }
-        if (script->hasRest()) {
-            scriptBits |= (1 << HasRest);
-        }
-        if (script->hasSingletons()) {
-            scriptBits |= (1 << HasSingleton);
-        }
-        if (script->treatAsRunOnce()) {
-            scriptBits |= (1 << TreatAsRunOnce);
-        }
         if (script->isRelazifiable()) {
             scriptBits |= (1 << HasLazyScript);
         }
-        if (script->hasNonSyntacticScope()) {
-            scriptBits |= (1 << HasNonSyntacticScope);
-        }
-        if (script->hasInnerFunctions()) {
-            scriptBits |= (1 << HasInnerFunctions);
-        }
-        if (script->needsHomeObject()) {
-            scriptBits |= (1 << NeedsHomeObject);
-        }
-        if (script->isDerivedClassConstructor()) {
-            scriptBits |= (1 << IsDerivedClassConstructor);
-        }
-        if (script->isDefaultClassConstructor()) {
-            scriptBits |= (1 << IsDefaultClassConstructor);
-        }
     }
 
     MOZ_TRY(xdr->codeUint32(&prologueLength));
 
     // To fuse allocations, we need lengths of all embedded arrays early.
     MOZ_TRY(xdr->codeUint32(&natoms));
     MOZ_TRY(xdr->codeUint32(&nsrcnotes));
     MOZ_TRY(xdr->codeUint32(&nconsts));
     MOZ_TRY(xdr->codeUint32(&nobjects));
     MOZ_TRY(xdr->codeUint32(&nscopes));
     MOZ_TRY(xdr->codeUint32(&ntrynotes));
     MOZ_TRY(xdr->codeUint32(&nscopenotes));
     MOZ_TRY(xdr->codeUint32(&nresumeoffsets));
     MOZ_TRY(xdr->codeUint32(&nTypeSets));
     MOZ_TRY(xdr->codeUint32(&funLength));
     MOZ_TRY(xdr->codeUint32(&scriptBits));
+    MOZ_TRY(xdr->codeUint32(&immutableFlags));
 
     MOZ_ASSERT(!!(scriptBits & (1 << OwnSource)) == !sourceObjectArg);
     RootedScriptSourceObject sourceObject(cx, sourceObjectArg);
 
     if (mode == XDR_DECODE) {
         // When loading from the bytecode cache, we get the CompileOptions from
         // the document. If the noScriptRval or selfHostingMode flag doesn't
         // match, we should fail. This only applies to the top-level and not
         // its inner functions.
+        bool noScriptRval = !!(immutableFlags & uint32_t(ImmutableFlags::NoScriptRval));
+        bool selfHosted = !!(immutableFlags & uint32_t(ImmutableFlags::SelfHosted));
         mozilla::Maybe<CompileOptions> options;
         if (xdr->hasOptions() && (scriptBits & (1 << OwnSource))) {
             options.emplace(xdr->cx(), xdr->options());
-            if (options->noScriptRval != !!(scriptBits & (1 << NoScriptRval)) ||
-                options->selfHostingMode != !!(scriptBits & (1 << SelfHosted)))
+            if (options->noScriptRval != noScriptRval ||
+                options->selfHostingMode != selfHosted)
             {
                 return xdr->fail(JS::TranscodeResult_Failure_WrongCompileOption);
             }
         } else {
             options.emplace(xdr->cx());
-            (*options).setNoScriptRval(!!(scriptBits & (1 << NoScriptRval)))
-                      .setSelfHostingMode(!!(scriptBits & (1 << SelfHosted)));
+            (*options).setNoScriptRval(noScriptRval)
+                      .setSelfHostingMode(selfHosted);
         }
 
         if (scriptBits & (1 << OwnSource)) {
             ScriptSource* ss = cx->new_<ScriptSource>();
             if (!ss) {
                 return xdr->fail(JS::TranscodeResult_Throw);
             }
             ScriptSourceHolder ssHolder(ss);
@@ -606,76 +528,26 @@ js::XDRScript(XDRState<mode>* xdr, Handl
         script->mainOffset_ = prologueLength;
         script->funLength_ = funLength;
 
         MOZ_ASSERT(nTypeSets <= UINT16_MAX);
         script->nTypeSets_ = uint16_t(nTypeSets);
 
         scriptp.set(script);
 
-        if (scriptBits & (1 << Strict)) {
-            script->setFlag(ImmutableFlags::Strict);
-        }
-        if (scriptBits & (1 << ExplicitUseStrict)) {
-            script->setFlag(ImmutableFlags::ExplicitUseStrict);
-        }
-        if (scriptBits & (1 << ContainsDynamicNameAccess)) {
-            script->setFlag(ImmutableFlags::BindingsAccessedDynamically);
-        }
-        if (scriptBits & (1 << FunHasExtensibleScope)) {
-            script->setFlag(ImmutableFlags::FunHasExtensibleScope);
-        }
-        if (scriptBits & (1 << FunHasAnyAliasedFormal)) {
-            script->setFlag(ImmutableFlags::FunHasAnyAliasedFormal);
-        }
-        if (scriptBits & (1 << ArgumentsHasVarBinding)) {
+        script->immutableFlags_ = immutableFlags;
+
+        if (script->hasFlag(ImmutableFlags::ArgsHasVarBinding)) {
+            // Call setArgumentsHasVarBinding to initialize the
+            // NeedsArgsAnalysis flag.
             script->setArgumentsHasVarBinding();
         }
         if (scriptBits & (1 << NeedsArgsObj)) {
             script->setNeedsArgsObj(true);
         }
-        if (scriptBits & (1 << HasMappedArgsObj)) {
-            script->setFlag(ImmutableFlags::HasMappedArgsObj);
-        }
-        if (scriptBits & (1 << FunctionHasThisBinding)) {
-            script->setFlag(ImmutableFlags::FunctionHasThisBinding);
-        }
-        if (scriptBits & (1 << FunctionHasExtraBodyVarScope)) {
-            script->setFlag(ImmutableFlags::FunctionHasExtraBodyVarScope);
-        }
-        if (scriptBits & (1 << HasSingleton)) {
-            script->setFlag(ImmutableFlags::HasSingletons);
-        }
-        if (scriptBits & (1 << TreatAsRunOnce)) {
-            script->setFlag(ImmutableFlags::TreatAsRunOnce);
-        }
-        if (scriptBits & (1 << HasNonSyntacticScope)) {
-            script->setFlag(ImmutableFlags::HasNonSyntacticScope);
-        }
-        if (scriptBits & (1 << HasInnerFunctions)) {
-            script->setFlag(ImmutableFlags::HasInnerFunctions);
-        }
-        if (scriptBits & (1 << NeedsHomeObject)) {
-            script->setFlag(ImmutableFlags::NeedsHomeObject);
-        }
-        if (scriptBits & (1 << IsDerivedClassConstructor)) {
-            script->setFlag(ImmutableFlags::IsDerivedClassConstructor);
-        }
-        if (scriptBits & (1 << IsDefaultClassConstructor)) {
-            script->setFlag(ImmutableFlags::IsDefaultClassConstructor);
-        }
-        if (scriptBits & (1 << IsGenerator)) {
-            script->setFlag(ImmutableFlags::IsGenerator);
-        }
-        if (scriptBits & (1 << IsAsync)) {
-            script->setFlag(ImmutableFlags::IsAsync);
-        }
-        if (scriptBits & (1 << HasRest)) {
-            script->setFlag(ImmutableFlags::HasRest);
-        }
     }
 
     JS_STATIC_ASSERT(sizeof(jsbytecode) == 1);
     JS_STATIC_ASSERT(sizeof(jssrcnote) == 1);
 
     if (scriptBits & (1 << OwnSource)) {
         MOZ_TRY(sourceObject->source()->performXDR<mode>(xdr));
     }