Commit 1684a68a authored by Jan de Mooij's avatar Jan de Mooij
Browse files

Bug 1832582 part 3 - Add JOF_USES_ENV and use it in ScriptUsesEnvironmentChain. r=iain a=pascalc

This eliminates the indirect jump in `ScriptUsesEnvironmentChain` which will
hopefully workaround the Atom CPU issue discussed in the bug.

Differential Revision: https://phabricator.services.mozilla.com/D178652
parent 7fc1f4ce
Loading
Loading
Loading
Loading
+2 −20
Original line number Diff line number Diff line
@@ -248,26 +248,8 @@ bool js::jit::ScriptUsesEnvironmentChain(JSScript* script) {
  AllBytecodesIterable iterator(script);

  for (const BytecodeLocation& location : iterator) {
    switch (location.getOp()) {
      case JSOp::GetName:
      case JSOp::BindName:
      case JSOp::BindVar:
      case JSOp::SetName:
      case JSOp::StrictSetName:
      case JSOp::DelName:
      case JSOp::GetAliasedVar:
      case JSOp::SetAliasedVar:
      case JSOp::Lambda:
      case JSOp::PushLexicalEnv:
      case JSOp::PopLexicalEnv:
      case JSOp::PushVarEnv:
      case JSOp::ImplicitThis:
      case JSOp::FunWithProto:
      case JSOp::GlobalOrEvalDeclInstantiation:
    if (OpUsesEnvironmentChain(location.getOp())) {
      return true;

      default:
        break;
    }
  }

+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ enum {
  JOF_SPREAD = 1 << 22,      /* invoke instruction using spread argument */
  JOF_GNAME = 1 << 23,       /* predicted global name */
  JOF_IC = 1 << 24,          /* baseline may use an IC for this op */
  JOF_USES_ENV = 1 << 25,    /* op uses the frame's environment chain */
};

#endif /* vm_BytecodeFormatFlags_h */
+4 −0
Original line number Diff line number Diff line
@@ -531,6 +531,10 @@ inline bool IsSpreadOp(JSOp op) { return CodeSpec(op).format & JOF_SPREAD; }

inline bool IsSpreadPC(const jsbytecode* pc) { return IsSpreadOp(JSOp(*pc)); }

inline bool OpUsesEnvironmentChain(JSOp op) {
  return CodeSpec(op).format & JOF_USES_ENV;
}

static inline int32_t GetBytecodeInteger(jsbytecode* pc) {
  switch (JSOp(*pc)) {
    case JSOp::Zero:
+15 −15
Original line number Diff line number Diff line
@@ -1665,7 +1665,7 @@
     *   Operands: uint32_t funcIndex
     *   Stack: => fn
     */ \
    MACRO(Lambda, lambda, NULL, 5, 0, 1, JOF_OBJECT) \
    MACRO(Lambda, lambda, NULL, 5, 0, 1, JOF_OBJECT|JOF_USES_ENV) \
    /*
     * Set the name of a function.
     *
@@ -1728,7 +1728,7 @@
     *   Operands: uint32_t funcIndex
     *   Stack: proto => obj
     */ \
    MACRO(FunWithProto, fun_with_proto, NULL, 5, 1, 1, JOF_OBJECT) \
    MACRO(FunWithProto, fun_with_proto, NULL, 5, 1, 1, JOF_OBJECT|JOF_USES_ENV) \
    /*
     * Pushes the current global's %BuiltinObject%.
     *
@@ -1891,7 +1891,7 @@
     *   Operands: uint32_t nameIndex
     *   Stack: => this
     */ \
    MACRO(ImplicitThis, implicit_this, "", 5, 0, 1, JOF_ATOM) \
    MACRO(ImplicitThis, implicit_this, "", 5, 0, 1, JOF_ATOM|JOF_USES_ENV) \
    /*
     * Push the call site object for a tagged template call.
     *
@@ -2783,7 +2783,7 @@
     *   Operands: uint32_t nameIndex
     *   Stack: => env
     */ \
    MACRO(BindName, bind_name, NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_IC) \
    MACRO(BindName, bind_name, NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_IC|JOF_USES_ENV) \
    /*
     * Find a binding on the environment chain and push its value.
     *
@@ -2805,7 +2805,7 @@
     *   Operands: uint32_t nameIndex
     *   Stack: => val
     */ \
    MACRO(GetName, get_name, NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_IC) \
    MACRO(GetName, get_name, NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_IC|JOF_USES_ENV) \
    /*
     * Find a global binding and push its value.
     *
@@ -2911,7 +2911,7 @@
     *   Operands: uint8_t hops, uint24_t slot
     *   Stack: => aliasedVar
     */ \
    MACRO(GetAliasedVar, get_aliased_var, NULL, 5, 0, 1, JOF_ENVCOORD|JOF_NAME) \
    MACRO(GetAliasedVar, get_aliased_var, NULL, 5, 0, 1, JOF_ENVCOORD|JOF_NAME|JOF_USES_ENV) \
    /*
     * Push the value of an aliased binding, which may have to bypass a DebugEnvironmentProxy
     * on the environment chain.
@@ -3028,7 +3028,7 @@
     *   Operands: uint32_t nameIndex
     *   Stack: env, val => val
     */ \
    MACRO(SetName, set_name, NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_PROPSET|JOF_CHECKSLOPPY|JOF_IC) \
    MACRO(SetName, set_name, NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_PROPSET|JOF_CHECKSLOPPY|JOF_IC|JOF_USES_ENV) \
    /*
     * Like `JSOp::SetName`, but throw a TypeError if there is no binding for
     * the specified name in `env`, or if the binding is immutable (a `const`
@@ -3043,7 +3043,7 @@
     *   Operands: uint32_t nameIndex
     *   Stack: env, val => val
     */ \
    MACRO(StrictSetName, strict_set_name, NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_PROPSET|JOF_CHECKSTRICT|JOF_IC) \
    MACRO(StrictSetName, strict_set_name, NULL, 5, 2, 1, JOF_ATOM|JOF_NAME|JOF_PROPSET|JOF_CHECKSTRICT|JOF_IC|JOF_USES_ENV) \
    /*
     * Like `JSOp::SetName`, but for assigning to globals. `env` must be an
     * environment pushed by `JSOp::BindGName`.
@@ -3097,7 +3097,7 @@
     *   Operands: uint8_t hops, uint24_t slot
     *   Stack: val => val
     */ \
    MACRO(SetAliasedVar, set_aliased_var, NULL, 5, 1, 1, JOF_ENVCOORD|JOF_NAME|JOF_PROPSET) \
    MACRO(SetAliasedVar, set_aliased_var, NULL, 5, 1, 1, JOF_ENVCOORD|JOF_NAME|JOF_PROPSET|JOF_USES_ENV) \
    /*
     * Assign to an intrinsic.
     *
@@ -3155,7 +3155,7 @@
     *   Operands: uint32_t lexicalScopeIndex
     *   Stack: =>
     */ \
    MACRO(PushLexicalEnv, push_lexical_env, NULL, 5, 0, 0, JOF_SCOPE) \
    MACRO(PushLexicalEnv, push_lexical_env, NULL, 5, 0, 0, JOF_SCOPE|JOF_USES_ENV) \
    /*
     * Pop a lexical or class-body environment from the environment chain.
     *
@@ -3166,7 +3166,7 @@
     *   Operands:
     *   Stack: =>
     */ \
    MACRO(PopLexicalEnv, pop_lexical_env, NULL, 1, 0, 0, JOF_BYTE) \
    MACRO(PopLexicalEnv, pop_lexical_env, NULL, 1, 0, 0, JOF_BYTE|JOF_USES_ENV) \
    /*
     * No-op instruction that indicates leaving an optimized lexical scope.
     *
@@ -3262,7 +3262,7 @@
     *   Operands: uint32_t scopeIndex
     *   Stack: =>
     */ \
    MACRO(PushVarEnv, push_var_env, NULL, 5, 0, 0, JOF_SCOPE) \
    MACRO(PushVarEnv, push_var_env, NULL, 5, 0, 0, JOF_SCOPE|JOF_USES_ENV) \
    /*
     * Push a `WithEnvironmentObject` wrapping ToObject(`val`) to the
     * environment chain.
@@ -3317,7 +3317,7 @@
     *   Operands:
     *   Stack: => env
     */ \
    MACRO(BindVar, bind_var, NULL, 1, 0, 1, JOF_BYTE) \
    MACRO(BindVar, bind_var, NULL, 1, 0, 1, JOF_BYTE|JOF_USES_ENV) \
    /*
     * Check for conflicting bindings and then initialize them in global or
     * sloppy eval scripts. This is required for global scripts with any
@@ -3339,7 +3339,7 @@
     *   Operands: uint32_t lastFun
     *   Stack: =>
     */ \
    MACRO(GlobalOrEvalDeclInstantiation, global_or_eval_decl_instantiation, NULL, 5, 0, 0, JOF_GCTHING) \
    MACRO(GlobalOrEvalDeclInstantiation, global_or_eval_decl_instantiation, NULL, 5, 0, 0, JOF_GCTHING|JOF_USES_ENV) \
    /*
     * Look up a variable on the environment chain and delete it. Push `true`
     * on success (if a binding was deleted, or if no such binding existed in
@@ -3357,7 +3357,7 @@
     *   Operands: uint32_t nameIndex
     *   Stack: => succeeded
     */ \
    MACRO(DelName, del_name, NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_CHECKSLOPPY) \
    MACRO(DelName, del_name, NULL, 5, 0, 1, JOF_ATOM|JOF_NAME|JOF_CHECKSLOPPY|JOF_USES_ENV) \
    /*
     * Create and push the `arguments` object for the current function activation.
     *