arai-a / smoosh-sync

Automation to make jsparagus and SpiderMonkey bytecode in sync
2 stars 0 forks source link

/js/src/vm/SharedStencil.h has been updated (868c4382) #309

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

Files

Changesets

Diffs

/js/src/vm/SharedStencil.h

--- b08446bfcd74acd3221ea43ce71e56ef8b0e1637/js/src/vm/SharedStencil.h
+++ 868c43822c86c2edb307c0b3559627647e7b585d/js/src/vm/SharedStencil.h
@@ -639,16 +639,17 @@ class SharedImmutableScriptData {
   // script data table.
   mozilla::Atomic<uint32_t, mozilla::SequentiallyConsistent> refCount_ = {};

  public:
   bool isExternal = false;

  private:
   ImmutableScriptData* isd_ = nullptr;
+  mozilla::HashNumber hash_;

   // End of fields.

   friend class ::JSScript;
   friend class js::frontend::StencilXDR;

  public:
   SharedImmutableScriptData() = default;
@@ -658,16 +659,21 @@ class SharedImmutableScriptData {
  private:
   void reset() {
     if (isd_ && !isExternal) {
       js_delete(isd_);
     }
     isd_ = nullptr;
   }

+  mozilla::HashNumber calculateHash() const {
+    mozilla::Span<const uint8_t> immutableData = isd_->immutableData();
+    return mozilla::HashBytes(immutableData.data(), immutableData.size());
+  }
+
  public:
   // Hash over the contents of SharedImmutableScriptData and its
   // ImmutableScriptData.
   struct Hasher;

   uint32_t refCount() const { return refCount_; }
   void AddRef() { refCount_++; }
   void Release() {
@@ -702,39 +708,60 @@ class SharedImmutableScriptData {

   static bool shareScriptData(FrontendContext* fc,
                               RefPtr<SharedImmutableScriptData>& sisd);

   size_t immutableDataLength() const { return isd_->immutableData().Length(); }
   uint32_t nfixed() const { return isd_->nfixed; }

   ImmutableScriptData* get() { return isd_; }
+  mozilla::HashNumber hash() const { return hash_; }

   void setOwn(js::UniquePtr<ImmutableScriptData>&& isd) {
     MOZ_ASSERT(!isd_);
     isd_ = isd.release();
     isExternal = false;
+
+    hash_ = calculateHash();
+  }
+
+  void setOwn(js::UniquePtr<ImmutableScriptData>&& isd,
+              mozilla::HashNumber hash) {
+    MOZ_ASSERT(!isd_);
+    isd_ = isd.release();
+    isExternal = false;
+
+    MOZ_ASSERT(hash == calculateHash());
+    hash_ = hash;
   }

   void setExternal(ImmutableScriptData* isd) {
     MOZ_ASSERT(!isd_);
     isd_ = isd;
     isExternal = true;
+
+    hash_ = calculateHash();
+  }
+
+  void setExternal(ImmutableScriptData* isd, mozilla::HashNumber hash) {
+    MOZ_ASSERT(!isd_);
+    isd_ = isd;
+    isExternal = true;
+
+    MOZ_ASSERT(hash == calculateHash());
+    hash_ = hash;
   }
 };

 // Matches SharedImmutableScriptData objects that have the same atoms as well as
 // contain the same bytes in their ImmutableScriptData.
 struct SharedImmutableScriptData::Hasher {
   using Lookup = RefPtr<SharedImmutableScriptData>;

-  static mozilla::HashNumber hash(const Lookup& l) {
-    mozilla::Span<const uint8_t> immutableData = l->isd_->immutableData();
-    return mozilla::HashBytes(immutableData.data(), immutableData.size());
-  }
+  static mozilla::HashNumber hash(const Lookup& l) { return l->hash(); }

   static bool match(SharedImmutableScriptData* entry, const Lookup& lookup) {
     return (entry->isd_->immutableData() == lookup->isd_->immutableData());
   }
 };

 using SharedImmutableScriptDataTable =
     mozilla::HashSet<SharedImmutableScriptData*,