Bug 1522075 part 4 - Some JitContext assertions and clean up. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 24 Jan 2019 17:36:42 +0000
changeset 455293 ced24b663e6593c79917f8af47256e2ea9ca83d1
parent 455292 eff43158adb80f26363c448b52f5d37dbfae7575
child 455294 c61a5f1a655c186a6f187f5d2cf9f55846331b5b
push id35428
push usernbeleuzu@mozilla.com
push dateThu, 24 Jan 2019 21:42:11 +0000
treeherdermozilla-central@6b7bc4002311 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1522075
milestone66.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 1522075 part 4 - Some JitContext assertions and clean up. r=luke When we generate the Baseline interpreter and other trampolines, JitContext's realm is nullptr. We now assert it's non-null in JitContext::realm(). I also replaced JitContext::zone with JitContext::isCompilingWasm_. Differential Revision: https://phabricator.services.mozilla.com/D17368
js/src/jit/Ion.cpp
js/src/jit/Ion.h
js/src/jit/MacroAssembler-inl.h
js/src/jit/MacroAssembler.cpp
js/src/jit/shared/Assembler-shared.h
--- a/js/src/jit/Ion.cpp
+++ b/js/src/jit/Ion.cpp
@@ -93,30 +93,34 @@ JitContext* jit::GetJitContext() {
 
 JitContext* jit::MaybeGetJitContext() { return CurrentJitContext(); }
 
 JitContext::JitContext(CompileRuntime* rt, CompileRealm* realm,
                        TempAllocator* temp)
     : cx(nullptr),
       temp(temp),
       runtime(rt),
-      realm(realm),
-      zone(realm ? realm->zone() : nullptr),
       prev_(CurrentJitContext()),
+      realm_(realm),
+#ifdef DEBUG
+      isCompilingWasm_(!realm),
+#endif
       assemblerCount_(0) {
   SetJitContext(this);
 }
 
 JitContext::JitContext(JSContext* cx, TempAllocator* temp)
     : cx(cx),
       temp(temp),
       runtime(CompileRuntime::get(cx->runtime())),
-      realm(CompileRealm::get(cx->realm())),
-      zone(CompileZone::get(cx->zone())),
       prev_(CurrentJitContext()),
+      realm_(CompileRealm::get(cx->realm())),
+#ifdef DEBUG
+      isCompilingWasm_(false),
+#endif
       assemblerCount_(0) {
   SetJitContext(this);
 }
 
 JitContext::JitContext(TempAllocator* temp)
     : JitContext(nullptr, nullptr, temp) {}
 
 JitContext::JitContext() : JitContext(nullptr, nullptr, nullptr) {}
--- a/js/src/jit/Ion.h
+++ b/js/src/jit/Ion.h
@@ -64,23 +64,35 @@ class JitContext {
   JSContext* cx;
 
   // Allocator for temporary memory during compilation.
   TempAllocator* temp;
 
   // Wrappers with information about the current runtime/realm for use
   // during compilation.
   CompileRuntime* runtime;
-  CompileRealm* realm;
-  CompileZone* zone;
 
   int getNextAssemblerId() { return assemblerCount_++; }
 
+  CompileRealm* maybeRealm() const { return realm_; }
+  CompileRealm* realm() const {
+    MOZ_ASSERT(maybeRealm());
+    return maybeRealm();
+  }
+
+#ifdef DEBUG
+  bool isCompilingWasm() { return isCompilingWasm_; }
+#endif
+
  private:
   JitContext* prev_;
+  CompileRealm* realm_;
+#ifdef DEBUG
+  bool isCompilingWasm_;
+#endif
   int assemblerCount_;
 };
 
 // Initialize Ion statically for all JSRuntimes.
 MOZ_MUST_USE bool InitializeIon();
 
 // Get and set the current JIT context.
 JitContext* GetJitContext();
--- a/js/src/jit/MacroAssembler-inl.h
+++ b/js/src/jit/MacroAssembler-inl.h
@@ -597,25 +597,25 @@ void MacroAssembler::branchTestProxyHand
   loadPtr(handlerAddr, scratch);
   Address familyAddr(scratch, BaseProxyHandler::offsetOfFamily());
   branchPtr(cond, familyAddr, ImmPtr(handlerp), label);
 }
 
 void MacroAssembler::branchTestNeedsIncrementalBarrier(Condition cond,
                                                        Label* label) {
   MOZ_ASSERT(cond == Zero || cond == NonZero);
-  CompileZone* zone = GetJitContext()->realm->zone();
+  CompileZone* zone = GetJitContext()->realm()->zone();
   const uint32_t* needsBarrierAddr = zone->addressOfNeedsIncrementalBarrier();
   branchTest32(cond, AbsoluteAddress(needsBarrierAddr), Imm32(0x1), label);
 }
 
 void MacroAssembler::branchTestNeedsIncrementalBarrierAnyZone(
     Condition cond, Label* label, Register scratch) {
   MOZ_ASSERT(cond == Zero || cond == NonZero);
-  if (GetJitContext()->realm) {
+  if (GetJitContext()->maybeRealm()) {
     branchTestNeedsIncrementalBarrier(cond, label);
   } else {
     // We are compiling the interpreter or another runtime-wide trampoline, so
     // we have to load cx->zone.
     loadPtr(AbsoluteAddress(GetJitContext()->runtime->addressOfZone()),
             scratch);
     Address needsBarrierAddr(scratch, Zone::offsetOfNeedsIncrementalBarrier());
     branchTest32(cond, needsBarrierAddr, Imm32(0x1), label);
--- a/js/src/jit/MacroAssembler.cpp
+++ b/js/src/jit/MacroAssembler.cpp
@@ -762,17 +762,17 @@ void MacroAssembler::checkAllocatorState
       GetJitContext()->runtime->addressOfGCZealModeBits();
   branch32(Assembler::NotEqual, AbsoluteAddress(ptrZealModeBits), Imm32(0),
            fail);
 #endif
 
   // Don't execute the inline path if the realm has an object metadata callback,
   // as the metadata to use for the object may vary between executions of the
   // op.
-  if (GetJitContext()->realm->hasAllocationMetadataBuilder()) {
+  if (GetJitContext()->realm()->hasAllocationMetadataBuilder()) {
     jump(fail);
   }
 }
 
 bool MacroAssembler::shouldNurseryAllocate(gc::AllocKind allocKind,
                                            gc::InitialHeap initialHeap) {
   // Note that Ion elides barriers on writes to objects known to be in the
   // nursery, so any allocation that can be made into the nursery must be made
@@ -795,17 +795,17 @@ void MacroAssembler::nurseryAllocateObje
   // interpreter.
   if (nDynamicSlots >= Nursery::MaxNurseryBufferSize / sizeof(Value)) {
     jump(fail);
     return;
   }
 
   // No explicit check for nursery.isEnabled() is needed, as the comparison
   // with the nursery's end will always fail in such cases.
-  CompileZone* zone = GetJitContext()->realm->zone();
+  CompileZone* zone = GetJitContext()->realm()->zone();
   size_t thingSize = gc::Arena::thingSize(allocKind);
   size_t totalSize = thingSize + nDynamicSlots * sizeof(HeapSlot);
   MOZ_ASSERT(totalSize < INT32_MAX);
   MOZ_ASSERT(totalSize % gc::CellAlignBytes == 0);
 
   bumpPointerAllocate(result, temp, fail, zone->addressOfNurseryPosition(),
                       zone->addressOfNurseryCurrentEnd(), totalSize, totalSize);
 
@@ -813,17 +813,17 @@ void MacroAssembler::nurseryAllocateObje
     computeEffectiveAddress(Address(result, thingSize), temp);
     storePtr(temp, Address(result, NativeObject::offsetOfSlots()));
   }
 }
 
 // Inlined version of FreeSpan::allocate. This does not fill in slots_.
 void MacroAssembler::freeListAllocate(Register result, Register temp,
                                       gc::AllocKind allocKind, Label* fail) {
-  CompileZone* zone = GetJitContext()->realm->zone();
+  CompileZone* zone = GetJitContext()->realm()->zone();
   int thingSize = int(gc::Arena::thingSize(allocKind));
 
   Label fallback;
   Label success;
 
   // Load the first and last offsets of |zone|'s free list for |allocKind|.
   // If there is no room remaining in the span, fall back to get the next one.
   gc::FreeSpan** ptrFreeList = zone->addressOfFreeList(allocKind);
@@ -876,17 +876,17 @@ void MacroAssembler::callMallocStub(size
   if (regZone != result) {
     push(regZone);
   }
   if (regNBytes != result) {
     push(regNBytes);
   }
 
   move32(Imm32(nbytes), regNBytes);
-  movePtr(ImmPtr(GetJitContext()->realm->zone()), regZone);
+  movePtr(ImmPtr(GetJitContext()->realm()->zone()), regZone);
   call(GetJitContext()->runtime->jitRuntime()->mallocStub());
   if (regReturn != result) {
     movePtr(regReturn, result);
   }
 
   if (regNBytes != result) {
     pop(regNBytes);
   }
@@ -986,17 +986,17 @@ void MacroAssembler::allocateNonObject(R
 void MacroAssembler::nurseryAllocateString(Register result, Register temp,
                                            gc::AllocKind allocKind,
                                            Label* fail) {
   MOZ_ASSERT(IsNurseryAllocable(allocKind));
 
   // No explicit check for nursery.isEnabled() is needed, as the comparison
   // with the nursery's end will always fail in such cases.
 
-  CompileZone* zone = GetJitContext()->realm->zone();
+  CompileZone* zone = GetJitContext()->realm()->zone();
   size_t thingSize = gc::Arena::thingSize(allocKind);
   size_t totalSize = js::Nursery::stringHeaderSize() + thingSize;
   MOZ_ASSERT(totalSize < INT32_MAX, "Nursery allocation too large");
   MOZ_ASSERT(totalSize % gc::CellAlignBytes == 0);
 
   bumpPointerAllocate(
       result, temp, fail, zone->addressOfStringNurseryPosition(),
       zone->addressOfStringNurseryCurrentEnd(), totalSize, thingSize);
@@ -1022,17 +1022,17 @@ void MacroAssembler::bumpPointerAllocate
        CheckedInt<uintptr_t>(uintptr_t(posAddr)))
           .toChecked<int32_t>();
   MOZ_ASSERT(endOffset.isValid(), "Position and end pointers must be nearby");
   branchPtr(Assembler::Below, Address(temp, endOffset.value()), result, fail);
   storePtr(result, Address(temp, 0));
   subPtr(Imm32(size), result);
 
   if (GetJitContext()->runtime->geckoProfiler().enabled()) {
-    CompileZone* zone = GetJitContext()->realm->zone();
+    CompileZone* zone = GetJitContext()->realm()->zone();
     uint32_t* countAddress = zone->addressOfNurseryAllocCount();
     CheckedInt<int32_t> counterOffset =
         (CheckedInt<uintptr_t>(uintptr_t(countAddress)) -
          CheckedInt<uintptr_t>(uintptr_t(posAddr)))
             .toChecked<int32_t>();
     if (counterOffset.isValid()) {
       add32(Imm32(1), Address(temp, counterOffset.value()));
     } else {
--- a/js/src/jit/shared/Assembler-shared.h
+++ b/js/src/jit/shared/Assembler-shared.h
@@ -133,18 +133,17 @@ struct Imm64 {
   Imm32 hi() const { return Imm32(int32_t(value >> 32)); }
 
   inline Imm32 firstHalf() const;
   inline Imm32 secondHalf() const;
 };
 
 #ifdef DEBUG
 static inline bool IsCompilingWasm() {
-  // wasm compilation pushes a JitContext with a null Zone.
-  return GetJitContext()->zone == nullptr;
+  return GetJitContext()->isCompilingWasm();
 }
 #endif
 
 // Pointer to be embedded as an immediate in an instruction.
 struct ImmPtr {
   void* value;
 
   struct NoCheckToken {};