Bug 1633425 - Add js::jit::CodegenSafepointIndex type. r=jandem
authorTed Campbell <tcampbell@mozilla.com>
Tue, 28 Apr 2020 07:08:27 +0000
changeset 526466 cfb27a4b9c645e31ef11d8e009296c67e55f5ead
parent 526465 24af87fb0f32e8921f37e61d922875b40e95e4b0
child 526467 e099704046879b480e57ec590e1fefe6521d755e
push id37357
push useropoprus@mozilla.com
push dateTue, 28 Apr 2020 21:47:47 +0000
treeherdermozilla-central@a34695d9b99d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1633425
milestone77.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 1633425 - Add js::jit::CodegenSafepointIndex type. r=jandem This is used during codegen only so we can simplify the SafepointIndex that is stored in the IonScript. The resolve method is replaced by a constructor from CodegenSafepointIndex to SafepointIndex. Differential Revision: https://phabricator.services.mozilla.com/D72671
js/src/jit/CodeGenerator.cpp
js/src/jit/Ion.cpp
js/src/jit/IonCode.h
js/src/jit/JitFrames-inl.h
js/src/jit/JitFrames.h
js/src/jit/shared/CodeGenerator-shared.cpp
js/src/jit/shared/CodeGenerator-shared.h
--- a/js/src/jit/CodeGenerator.cpp
+++ b/js/src/jit/CodeGenerator.cpp
@@ -10783,17 +10783,17 @@ bool CodeGenerator::generateWasm(wasm::F
   MOZ_ASSERT(graph.numConstants() == 0);
   MOZ_ASSERT(osiIndices_.empty());
   MOZ_ASSERT(icList_.empty());
   MOZ_ASSERT(safepoints_.size() == 0);
   MOZ_ASSERT(!scriptCounts_);
 
   // Convert the safepoints to stackmaps and add them to our running
   // collection thereof.
-  for (SafepointIndex& index : safepointIndices_) {
+  for (CodegenSafepointIndex& index : safepointIndices_) {
     wasm::StackMap* stackMap = nullptr;
     if (!CreateStackMapFromLSafepoint(*index.safepoint(), trapExitLayout,
                                       trapExitLayoutNumWords,
                                       nInboundStackArgBytes, &stackMap)) {
       return false;
     }
 
     // In debug builds, we'll always have a stack map.
--- a/js/src/jit/Ion.cpp
+++ b/js/src/jit/Ion.cpp
@@ -775,22 +775,22 @@ void IonScript::copyBailoutTable(const S
 }
 
 void IonScript::copyConstants(const Value* vp) {
   for (size_t i = 0; i < constantEntries_; i++) {
     constants()[i].init(vp[i]);
   }
 }
 
-void IonScript::copySafepointIndices(const SafepointIndex* si) {
-  // Jumps in the caches reflect the offset of those jumps in the compiled
-  // code, not the absolute positions of the jumps. Update according to the
-  // final code address now.
+void IonScript::copySafepointIndices(const CodegenSafepointIndex* si) {
+  // Convert CodegenSafepointIndex to more compact form.
   SafepointIndex* table = safepointIndices();
-  memcpy(table, si, safepointIndexEntries_ * sizeof(SafepointIndex));
+  for (size_t i = 0; i < safepointIndexEntries_; ++i) {
+    table[i] = SafepointIndex(si[i]);
+  }
 }
 
 void IonScript::copyOsiIndices(const OsiIndex* oi) {
   memcpy(osiIndices(), oi, osiIndexEntries_ * sizeof(OsiIndex));
 }
 
 void IonScript::copyRuntimeData(const uint8_t* data) {
   memcpy(runtimeData(), data, runtimeSize());
--- a/js/src/jit/IonCode.h
+++ b/js/src/jit/IonCode.h
@@ -141,16 +141,17 @@ class JitCode : public gc::TenuredCell {
  public:
   static const JS::TraceKind TraceKind = JS::TraceKind::JitCode;
   const gc::CellHeader& cellHeader() const { return cellHeaderAndCode_; }
 };
 
 class SnapshotWriter;
 class RecoverWriter;
 class SafepointWriter;
+class CodegenSafepointIndex;
 class SafepointIndex;
 class OsiIndex;
 class IonIC;
 
 // An IonScript attaches Ion-generated information to a JSScript.
 struct IonScript {
  private:
   // Code pointer containing the actual method.
@@ -421,17 +422,17 @@ struct IonScript {
   }
   size_t numICs() const { return icEntries_; }
   size_t runtimeSize() const { return runtimeSize_; }
   void purgeICs(Zone* zone);
   void copySnapshots(const SnapshotWriter* writer);
   void copyRecovers(const RecoverWriter* writer);
   void copyBailoutTable(const SnapshotOffset* table);
   void copyConstants(const Value* vp);
-  void copySafepointIndices(const SafepointIndex* firstSafepointIndex);
+  void copySafepointIndices(const CodegenSafepointIndex* firstSafepointIndex);
   void copyOsiIndices(const OsiIndex* firstOsiIndex);
   void copyRuntimeData(const uint8_t* data);
   void copyICEntries(const uint32_t* caches);
   void copySafepoints(const SafepointWriter* writer);
 
   bool invalidated() const { return invalidationCount_ != 0; }
 
   // Invalidate the current compilation.
--- a/js/src/jit/JitFrames-inl.h
+++ b/js/src/jit/JitFrames-inl.h
@@ -11,23 +11,19 @@
 
 #include "jit/LIR.h"
 
 #include "jit/JSJitFrameIter-inl.h"
 
 namespace js {
 namespace jit {
 
-inline void SafepointIndex::resolve() {
-  MOZ_ASSERT(!resolved);
-  safepointOffset_ = safepoint_->offset();
-#ifdef DEBUG
-  resolved = true;
-#endif
-}
+inline SafepointIndex::SafepointIndex(const CodegenSafepointIndex& csi)
+    : displacement_(csi.displacement()),
+      safepointOffset_(csi.safepoint()->offset()) {}
 
 inline BaselineFrame* GetTopBaselineFrame(JSContext* cx) {
   JSJitFrameIter frame(cx->activation()->asJit());
   MOZ_ASSERT(frame.type() == FrameType::Exit);
   ++frame;
   if (frame.isBaselineStub()) {
     ++frame;
   }
--- a/js/src/jit/JitFrames.h
+++ b/js/src/jit/JitFrames.h
@@ -85,54 +85,46 @@ JSScript* MaybeForwardedScriptFromCallee
 //
 // Two special frame types exist:
 // - Entry frames begin a JitActivation, and therefore there is exactly one
 // per activation of EnterIon or EnterBaseline. These reuse JitFrameLayout.
 // - Exit frames are necessary to leave JIT code and enter C++, and thus,
 // C++ code will always begin iterating from the topmost exit frame.
 
 class LSafepoint;
+class CodegenSafepointIndex;
 
 // Two-tuple that lets you look up the safepoint entry given the
 // displacement of a call instruction within the JIT code.
 class SafepointIndex {
   // The displacement is the distance from the first byte of the JIT'd code
   // to the return address (of the call that the safepoint was generated for).
-  uint32_t displacement_;
-
-  union {
-    LSafepoint* safepoint_;
+  uint32_t displacement_ = 0;
 
-    // Offset to the start of the encoded safepoint in the safepoint stream.
-    uint32_t safepointOffset_;
-  };
-
-#ifdef DEBUG
-  bool resolved;
-#endif
+  // Offset within the safepoint buffer.
+  uint32_t safepointOffset_ = 0;
 
  public:
-  SafepointIndex(uint32_t displacement, LSafepoint* safepoint)
-      : displacement_(displacement),
-        safepoint_(safepoint)
-#ifdef DEBUG
-        ,
-        resolved(false)
-#endif
-  {
-  }
+  inline explicit SafepointIndex(const CodegenSafepointIndex& csi);
 
-  void resolve();
-
-  LSafepoint* safepoint() {
-    MOZ_ASSERT(!resolved);
-    return safepoint_;
-  }
   uint32_t displacement() const { return displacement_; }
   uint32_t safepointOffset() const { return safepointOffset_; }
+};
+
+class CodegenSafepointIndex {
+  uint32_t displacement_ = 0;
+
+  LSafepoint* safepoint_ = nullptr;
+
+ public:
+  CodegenSafepointIndex(uint32_t displacement, LSafepoint* safepoint)
+      : displacement_(displacement), safepoint_(safepoint) {}
+
+  LSafepoint* safepoint() const { return safepoint_; }
+  uint32_t displacement() const { return displacement_; }
   void adjustDisplacement(uint32_t offset) {
     MOZ_ASSERT(offset >= displacement_);
     displacement_ = offset;
   }
   inline SnapshotOffset snapshotOffset() const;
   inline bool hasSnapshotOffset() const;
 };
 
--- a/js/src/jit/shared/CodeGenerator-shared.cpp
+++ b/js/src/jit/shared/CodeGenerator-shared.cpp
@@ -615,24 +615,22 @@ bool CodeGeneratorShared::assignBailoutI
   unsigned bailoutId = bailouts_.length();
   snapshot->setBailoutId(bailoutId);
   JitSpew(JitSpew_IonSnapshots, "Assigned snapshot bailout id %u", bailoutId);
   masm.propagateOOM(bailouts_.append(snapshot->snapshotOffset()));
   return true;
 }
 
 bool CodeGeneratorShared::encodeSafepoints() {
-  for (SafepointIndex& index : safepointIndices_) {
+  for (CodegenSafepointIndex& index : safepointIndices_) {
     LSafepoint* safepoint = index.safepoint();
 
     if (!safepoint->encoded()) {
       safepoints_.encode(safepoint);
     }
-
-    index.resolve();
   }
 
   return !safepoints_.oom();
 }
 
 bool CodeGeneratorShared::createNativeToBytecodeScriptList(JSContext* cx) {
   js::Vector<JSScript*, 0, SystemAllocPolicy> scriptList;
   InlineScriptTree* tree = gen->outerInfo().inlineScriptTree();
@@ -835,18 +833,18 @@ void CodeGeneratorShared::verifyCompactN
 void CodeGeneratorShared::markSafepoint(LInstruction* ins) {
   markSafepointAt(masm.currentOffset(), ins);
 }
 
 void CodeGeneratorShared::markSafepointAt(uint32_t offset, LInstruction* ins) {
   MOZ_ASSERT_IF(
       !safepointIndices_.empty() && !masm.oom(),
       offset - safepointIndices_.back().displacement() >= sizeof(uint32_t));
-  masm.propagateOOM(
-      safepointIndices_.append(SafepointIndex(offset, ins->safepoint())));
+  masm.propagateOOM(safepointIndices_.append(
+      CodegenSafepointIndex(offset, ins->safepoint())));
 }
 
 void CodeGeneratorShared::ensureOsiSpace() {
   // For a refresher, an invalidation point is of the form:
   // 1: call <target>
   // 2: ...
   // 3: <osipoint>
   //
--- a/js/src/jit/shared/CodeGenerator-shared.h
+++ b/js/src/jit/shared/CodeGenerator-shared.h
@@ -58,17 +58,17 @@ class CodeGeneratorShared : public LElem
   uint32_t lastOsiPointOffset_;
   SafepointWriter safepoints_;
   Label invalidate_;
   CodeOffset invalidateEpilogueData_;
 
   // Label for the common return path.
   NonAssertingLabel returnLabel_;
 
-  js::Vector<SafepointIndex, 0, SystemAllocPolicy> safepointIndices_;
+  js::Vector<CodegenSafepointIndex, 0, SystemAllocPolicy> safepointIndices_;
   js::Vector<OsiIndex, 0, SystemAllocPolicy> osiIndices_;
 
   // Mapping from bailout table ID to an offset in the snapshot buffer.
   js::Vector<SnapshotOffset, 0, SystemAllocPolicy> bailouts_;
 
   // Allocated data space needed at runtime.
   js::Vector<uint8_t, 0, SystemAllocPolicy> runtimeData_;
 
@@ -129,17 +129,18 @@ class CodeGeneratorShared : public LElem
   inline void setSkipArgCheckEntryOffset(size_t offset) {
     MOZ_ASSERT(skipArgCheckEntryOffset_ == 0);
     skipArgCheckEntryOffset_ = offset;
   }
   inline size_t getSkipArgCheckEntryOffset() const {
     return skipArgCheckEntryOffset_;
   }
 
-  typedef js::Vector<SafepointIndex, 8, SystemAllocPolicy> SafepointIndices;
+  typedef js::Vector<CodegenSafepointIndex, 8, SystemAllocPolicy>
+      SafepointIndices;
 
  protected:
 #ifdef CHECK_OSIPOINT_REGISTERS
   // See JitOptions.checkOsiPointRegisters. We set this here to avoid
   // races when enableOsiPointRegisterChecks is called while we're generating
   // code off-thread.
   bool checkOsiPointRegisters;
 #endif