DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef jit_IonIC_h
#define jit_IonIC_h

#include "jit/CacheIR.h"

namespace js {
namespace jit {

class CacheIRStubInfo;

// An optimized stub attached to an IonIC.
class IonICStub {
  // Code to jump to when this stub fails. This is either the next optimized
  // stub or the OOL fallback path.
  uint8_t* nextCodeRaw_;

  // The next optimized stub in this chain, or nullptr if this is the last
  // one.
  IonICStub* next_;

  // Info about this stub.
  CacheIRStubInfo* stubInfo_;

 public:
  IonICStub(uint8_t* fallbackCode, CacheIRStubInfo* stubInfo)
      : nextCodeRaw_(fallbackCode), next_(nullptr), stubInfo_(stubInfo) {}

  uint8_t* nextCodeRaw() const { return nextCodeRaw_; }
  uint8_t** nextCodeRawPtr() { return &nextCodeRaw_; }
  CacheIRStubInfo* stubInfo() const { return stubInfo_; }
  IonICStub* next() const { return next_; }

  uint8_t* stubDataStart();

  void setNext(IonICStub* next, JitCode* nextCode) {
    MOZ_ASSERT(!next_);
    MOZ_ASSERT(next && nextCode);
    next_ = next;
    nextCodeRaw_ = nextCode->raw();
  }

  // Null out pointers when we unlink stubs, to ensure we never use
  // discarded stubs.
  void poison() {
    nextCodeRaw_ = nullptr;
    next_ = nullptr;
    stubInfo_ = nullptr;
  }
};

class IonGetPropertyIC;
class IonSetPropertyIC;
class IonGetPropSuperIC;
class IonGetNameIC;
class IonBindNameIC;
class IonGetIteratorIC;
class IonHasOwnIC;
class IonInIC;
class IonInstanceOfIC;
class IonCompareIC;
class IonUnaryArithIC;
class IonBinaryArithIC;

class IonIC {
  // This either points at the OOL path for the fallback path, or the code for
  // the first stub.
  uint8_t* codeRaw_;

  // The first optimized stub, or nullptr.
  IonICStub* firstStub_;

  // The address stubs should jump to when done.
  CodeLocationLabel rejoinLabel_;

  // The OOL path that calls the IC's update function.
  CodeLocationLabel fallbackLabel_;

  // Location of this IC, nullptr for idempotent caches.
  JSScript* script_;
  jsbytecode* pc_;

  CacheKind kind_;
  bool idempotent_ : 1;
  ICState state_;

 protected:
  explicit IonIC(CacheKind kind)
      : codeRaw_(nullptr),
        firstStub_(nullptr),
        rejoinLabel_(),
        fallbackLabel_(),
        script_(nullptr),
        pc_(nullptr),
        kind_(kind),
        idempotent_(false),
        state_() {}

  void attachStub(IonICStub* newStub, JitCode* code);

 public:
  void setScriptedLocation(JSScript* script, jsbytecode* pc) {
    MOZ_ASSERT(!script_ && !pc_);
    MOZ_ASSERT(script && pc);
    script_ = script;
    pc_ = pc;
  }

  JSScript* script() const {
    MOZ_ASSERT(script_);
    return script_;
  }
  jsbytecode* pc() const {
    MOZ_ASSERT(pc_);
    return pc_;
  }

  CodeLocationLabel rejoinLabel() const { return rejoinLabel_; }

  // Discard all stubs.
  void discardStubs(Zone* zone);

  // Discard all stubs and reset the ICState.
  void reset(Zone* zone);

  ICState& state() { return state_; }

  CacheKind kind() const { return kind_; }
  uint8_t** codeRawPtr() { return &codeRaw_; }

  bool idempotent() const { return idempotent_; }
  void setIdempotent() { idempotent_ = true; }

  void setFallbackLabel(CodeOffset fallbackLabel) {
    fallbackLabel_ = fallbackLabel;
  }
  void setRejoinLabel(CodeOffset rejoinLabel) { rejoinLabel_ = rejoinLabel; }

  IonGetPropertyIC* asGetPropertyIC() {
    MOZ_ASSERT(kind_ == CacheKind::GetProp || kind_ == CacheKind::GetElem);
    return (IonGetPropertyIC*)this;
  }
  IonSetPropertyIC* asSetPropertyIC() {
    MOZ_ASSERT(kind_ == CacheKind::SetProp || kind_ == CacheKind::SetElem);
    return (IonSetPropertyIC*)this;
  }
  IonGetPropSuperIC* asGetPropSuperIC() {
    MOZ_ASSERT(kind_ == CacheKind::GetPropSuper ||
               kind_ == CacheKind::GetElemSuper);
    return (IonGetPropSuperIC*)this;
  }
  IonGetNameIC* asGetNameIC() {
    MOZ_ASSERT(kind_ == CacheKind::GetName);
    return (IonGetNameIC*)this;
  }
  IonBindNameIC* asBindNameIC() {
    MOZ_ASSERT(kind_ == CacheKind::BindName);
    return (IonBindNameIC*)this;
  }
  IonGetIteratorIC* asGetIteratorIC() {
    MOZ_ASSERT(kind_ == CacheKind::GetIterator);
    return (IonGetIteratorIC*)this;
  }
  IonHasOwnIC* asHasOwnIC() {
    MOZ_ASSERT(kind_ == CacheKind::HasOwn);
    return (IonHasOwnIC*)this;
  }
  IonInIC* asInIC() {
    MOZ_ASSERT(kind_ == CacheKind::In);
    return (IonInIC*)this;
  }
  IonInstanceOfIC* asInstanceOfIC() {
    MOZ_ASSERT(kind_ == CacheKind::InstanceOf);
    return (IonInstanceOfIC*)this;
  }
  IonCompareIC* asCompareIC() {
    MOZ_ASSERT(kind_ == CacheKind::Compare);
    return (IonCompareIC*)this;
  }
  IonUnaryArithIC* asUnaryArithIC() {
    MOZ_ASSERT(kind_ == CacheKind::UnaryArith);
    return (IonUnaryArithIC*)this;
  }
  IonBinaryArithIC* asBinaryArithIC() {
    MOZ_ASSERT(kind_ == CacheKind::BinaryArith);
    return (IonBinaryArithIC*)this;
  }

  void updateBaseAddress(JitCode* code);

  // Returns the Register to use as scratch when entering IC stubs. This
  // should either be an output register or a temp.
  Register scratchRegisterForEntryJump();

  void trace(JSTracer* trc);

  void attachCacheIRStub(JSContext* cx, const CacheIRWriter& writer,
                         CacheKind kind, IonScript* ionScript, bool* attached,
                         const PropertyTypeCheckInfo* typeCheckInfo = nullptr);
};

class IonGetPropertyIC : public IonIC {
 private:
  LiveRegisterSet liveRegs_;

  TypedOrValueRegister value_;
  ConstantOrRegister id_;
  TypedOrValueRegister output_;
  Register maybeTemp_;  // Might be InvalidReg.

  GetPropertyResultFlags resultFlags_;

 public:
  IonGetPropertyIC(CacheKind kind, LiveRegisterSet liveRegs,
                   TypedOrValueRegister value, const ConstantOrRegister& id,
                   TypedOrValueRegister output, Register maybeTemp,
                   GetPropertyResultFlags resultFlags)
      : IonIC(kind),
        liveRegs_(liveRegs),
        value_(value),
        id_(id),
        output_(output),
        maybeTemp_(maybeTemp),
        resultFlags_(resultFlags) {}

  TypedOrValueRegister value() const { return value_; }
  ConstantOrRegister id() const { return id_; }
  TypedOrValueRegister output() const { return output_; }
  Register maybeTemp() const { return maybeTemp_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }
  GetPropertyResultFlags resultFlags() const { return resultFlags_; }
  bool monitoredResult() const {
    return resultFlags_ & GetPropertyResultFlags::Monitored;
  }
  bool allowDoubleResult() const {
    return resultFlags_ & GetPropertyResultFlags::AllowDouble;
  }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonGetPropertyIC* ic, HandleValue val,
                                  HandleValue idVal, MutableHandleValue res);
};

class IonGetPropSuperIC : public IonIC {
  LiveRegisterSet liveRegs_;

  Register object_;
  TypedOrValueRegister receiver_;
  ConstantOrRegister id_;
  TypedOrValueRegister output_;

 public:
  IonGetPropSuperIC(CacheKind kind, LiveRegisterSet liveRegs, Register object,
                    TypedOrValueRegister receiver, const ConstantOrRegister& id,
                    TypedOrValueRegister output)
      : IonIC(kind),
        liveRegs_(liveRegs),
        object_(object),
        receiver_(receiver),
        id_(id),
        output_(output) {}

  Register object() const { return object_; }
  TypedOrValueRegister receiver() const { return receiver_; }
  ConstantOrRegister id() const { return id_; }
  TypedOrValueRegister output() const { return output_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonGetPropSuperIC* ic, HandleObject obj,
                                  HandleValue receiver, HandleValue idVal,
                                  MutableHandleValue res);
};

class IonSetPropertyIC : public IonIC {
  LiveRegisterSet liveRegs_;

  Register object_;
  Register temp_;
  FloatRegister maybeTempDouble_;
  FloatRegister maybeTempFloat32_;
  ConstantOrRegister id_;
  ConstantOrRegister rhs_;
  bool strict_ : 1;
  bool needsPostBarrier_ : 1;
  bool needsTypeBarrier_ : 1;
  bool guardHoles_ : 1;

 public:
  IonSetPropertyIC(CacheKind kind, LiveRegisterSet liveRegs, Register object,
                   Register temp, FloatRegister maybeTempDouble,
                   FloatRegister maybeTempFloat32, const ConstantOrRegister& id,
                   const ConstantOrRegister& rhs, bool strict,
                   bool needsPostBarrier, bool needsTypeBarrier,
                   bool guardHoles)
      : IonIC(kind),
        liveRegs_(liveRegs),
        object_(object),
        temp_(temp),
        maybeTempDouble_(maybeTempDouble),
        maybeTempFloat32_(maybeTempFloat32),
        id_(id),
        rhs_(rhs),
        strict_(strict),
        needsPostBarrier_(needsPostBarrier),
        needsTypeBarrier_(needsTypeBarrier),
        guardHoles_(guardHoles) {}

  LiveRegisterSet liveRegs() const { return liveRegs_; }
  Register object() const { return object_; }
  ConstantOrRegister id() const { return id_; }
  ConstantOrRegister rhs() const { return rhs_; }

  Register temp() const { return temp_; }
  FloatRegister maybeTempDouble() const { return maybeTempDouble_; }
  FloatRegister maybeTempFloat32() const { return maybeTempFloat32_; }

  bool strict() const { return strict_; }
  bool needsPostBarrier() const { return needsPostBarrier_; }
  bool needsTypeBarrier() const { return needsTypeBarrier_; }
  bool guardHoles() const { return guardHoles_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonSetPropertyIC* ic, HandleObject obj,
                                  HandleValue idVal, HandleValue rhs);
};

class IonGetNameIC : public IonIC {
  LiveRegisterSet liveRegs_;

  Register environment_;
  ValueOperand output_;
  Register temp_;

 public:
  IonGetNameIC(LiveRegisterSet liveRegs, Register environment,
               ValueOperand output, Register temp)
      : IonIC(CacheKind::GetName),
        liveRegs_(liveRegs),
        environment_(environment),
        output_(output),
        temp_(temp) {}

  Register environment() const { return environment_; }
  ValueOperand output() const { return output_; }
  Register temp() const { return temp_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonGetNameIC* ic, HandleObject envChain,
                                  MutableHandleValue res);
};

class IonBindNameIC : public IonIC {
  LiveRegisterSet liveRegs_;

  Register environment_;
  Register output_;
  Register temp_;

 public:
  IonBindNameIC(LiveRegisterSet liveRegs, Register environment, Register output,
                Register temp)
      : IonIC(CacheKind::BindName),
        liveRegs_(liveRegs),
        environment_(environment),
        output_(output),
        temp_(temp) {}

  Register environment() const { return environment_; }
  Register output() const { return output_; }
  Register temp() const { return temp_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }

  static JSObject* update(JSContext* cx, HandleScript outerScript,
                          IonBindNameIC* ic, HandleObject envChain);
};

class IonGetIteratorIC : public IonIC {
  LiveRegisterSet liveRegs_;
  TypedOrValueRegister value_;
  Register output_;
  Register temp1_;
  Register temp2_;

 public:
  IonGetIteratorIC(LiveRegisterSet liveRegs, TypedOrValueRegister value,
                   Register output, Register temp1, Register temp2)
      : IonIC(CacheKind::GetIterator),
        liveRegs_(liveRegs),
        value_(value),
        output_(output),
        temp1_(temp1),
        temp2_(temp2) {}

  TypedOrValueRegister value() const { return value_; }
  Register output() const { return output_; }
  Register temp1() const { return temp1_; }
  Register temp2() const { return temp2_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }

  static JSObject* update(JSContext* cx, HandleScript outerScript,
                          IonGetIteratorIC* ic, HandleValue value);
};

class IonHasOwnIC : public IonIC {
  LiveRegisterSet liveRegs_;

  TypedOrValueRegister value_;
  TypedOrValueRegister id_;
  Register output_;

 public:
  IonHasOwnIC(LiveRegisterSet liveRegs, TypedOrValueRegister value,
              TypedOrValueRegister id, Register output)
      : IonIC(CacheKind::HasOwn),
        liveRegs_(liveRegs),
        value_(value),
        id_(id),
        output_(output) {}

  TypedOrValueRegister value() const { return value_; }
  TypedOrValueRegister id() const { return id_; }
  Register output() const { return output_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonHasOwnIC* ic, HandleValue val,
                                  HandleValue idVal, int32_t* res);
};

class IonInIC : public IonIC {
  LiveRegisterSet liveRegs_;

  ConstantOrRegister key_;
  Register object_;
  Register output_;
  Register temp_;

 public:
  IonInIC(LiveRegisterSet liveRegs, const ConstantOrRegister& key,
          Register object, Register output, Register temp)
      : IonIC(CacheKind::In),
        liveRegs_(liveRegs),
        key_(key),
        object_(object),
        output_(output),
        temp_(temp) {}

  ConstantOrRegister key() const { return key_; }
  Register object() const { return object_; }
  Register output() const { return output_; }
  Register temp() const { return temp_; }
  LiveRegisterSet liveRegs() const { return liveRegs_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonInIC* ic, HandleValue key,
                                  HandleObject obj, bool* res);
};

class IonInstanceOfIC : public IonIC {
  LiveRegisterSet liveRegs_;

  TypedOrValueRegister lhs_;
  Register rhs_;
  Register output_;

 public:
  IonInstanceOfIC(LiveRegisterSet liveRegs, TypedOrValueRegister lhs,
                  Register rhs, Register output)
      : IonIC(CacheKind::InstanceOf),
        liveRegs_(liveRegs),
        lhs_(lhs),
        rhs_(rhs),
        output_(output) {}

  LiveRegisterSet liveRegs() const { return liveRegs_; }
  TypedOrValueRegister lhs() const { return lhs_; }
  Register rhs() const { return rhs_; }
  Register output() const { return output_; }

  // This signature mimics that of TryAttachInstanceOfStub in baseline
  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonInstanceOfIC* ic, HandleValue lhs,
                                  HandleObject rhs, bool* attached);
};

class IonCompareIC : public IonIC {
  LiveRegisterSet liveRegs_;

  TypedOrValueRegister lhs_;
  TypedOrValueRegister rhs_;
  Register output_;

 public:
  IonCompareIC(LiveRegisterSet liveRegs, TypedOrValueRegister lhs,
               TypedOrValueRegister rhs, Register output)
      : IonIC(CacheKind::Compare),
        liveRegs_(liveRegs),
        lhs_(lhs),
        rhs_(rhs),
        output_(output) {}

  LiveRegisterSet liveRegs() const { return liveRegs_; }
  TypedOrValueRegister lhs() const { return lhs_; }
  TypedOrValueRegister rhs() const { return rhs_; }
  Register output() const { return output_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonCompareIC* stub, HandleValue lhs,
                                  HandleValue rhs, bool* res);
};

class IonUnaryArithIC : public IonIC {
  LiveRegisterSet liveRegs_;

  TypedOrValueRegister input_;
  ValueOperand output_;

 public:
  IonUnaryArithIC(LiveRegisterSet liveRegs, TypedOrValueRegister input,
                  ValueOperand output)
      : IonIC(CacheKind::UnaryArith),
        liveRegs_(liveRegs),
        input_(input),
        output_(output) {}

  LiveRegisterSet liveRegs() const { return liveRegs_; }
  TypedOrValueRegister input() const { return input_; }
  ValueOperand output() const { return output_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonUnaryArithIC* stub, HandleValue val,
                                  MutableHandleValue res);
};

class IonBinaryArithIC : public IonIC {
  LiveRegisterSet liveRegs_;

  TypedOrValueRegister lhs_;
  TypedOrValueRegister rhs_;
  ValueOperand output_;

 public:
  IonBinaryArithIC(LiveRegisterSet liveRegs, TypedOrValueRegister lhs,
                   TypedOrValueRegister rhs, ValueOperand output)
      : IonIC(CacheKind::BinaryArith),
        liveRegs_(liveRegs),
        lhs_(lhs),
        rhs_(rhs),
        output_(output) {}

  LiveRegisterSet liveRegs() const { return liveRegs_; }
  TypedOrValueRegister lhs() const { return lhs_; }
  TypedOrValueRegister rhs() const { return rhs_; }
  ValueOperand output() const { return output_; }

  static MOZ_MUST_USE bool update(JSContext* cx, HandleScript outerScript,
                                  IonBinaryArithIC* stub, HandleValue lhs,
                                  HandleValue rhs, MutableHandleValue res);
};

}  // namespace jit
}  // namespace js

#endif /* jit_IonIC_h */