From f5dde549cca5193743d11daa1c5f08258bee9d42 Mon Sep 17 00:00:00 2001
From: Jan de Mooij <jdemooij@mozilla.com>
Date: Sat, 3 Jun 2023 05:31:20 +0000
Subject: [PATCH] Bug 1836489 - Remove code and fieldTypes pointers from
 CacheIRStubInfo. r=iain

The CacheIR ops and stub field types are stored as trailing arrays, so we can
just compute these values.

Differential Revision: https://phabricator.services.mozilla.com/D179825
---
 js/src/jit/CacheIRCompiler.cpp |  2 +-
 js/src/jit/CacheIRCompiler.h   | 33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/js/src/jit/CacheIRCompiler.cpp b/js/src/jit/CacheIRCompiler.cpp
index 51c2d9639b2c7..53b694eee6874 100644
--- a/js/src/jit/CacheIRCompiler.cpp
+++ b/js/src/jit/CacheIRCompiler.cpp
@@ -1358,7 +1358,7 @@ CacheIRStubInfo* CacheIRStubInfo::New(CacheKind kind, ICStubEngine engine,
   fieldTypes[numStubFields] = uint8_t(StubField::Type::Limit);
 
   return new (p) CacheIRStubInfo(kind, engine, makesGCCalls, stubDataOffset,
-                                 codeStart, writer.codeLength(), fieldTypes);
+                                 writer.codeLength());
 }
 
 bool OperandLocation::operator==(const OperandLocation& other) const {
diff --git a/js/src/jit/CacheIRCompiler.h b/js/src/jit/CacheIRCompiler.h
index 45066a1b177e2..465db7a9b8ce0 100644
--- a/js/src/jit/CacheIRCompiler.h
+++ b/js/src/jit/CacheIRCompiler.h
@@ -1227,22 +1227,27 @@ class MOZ_RAII AutoAvailableFloatRegister {
 
 // See the 'Sharing Baseline stub code' comment in CacheIR.h for a description
 // of this class.
+//
+// CacheIRStubInfo has a trailing variable-length array of bytes. The memory
+// layout is as follows:
+//
+//   Item             | Offset
+//   -----------------+--------------------------------------
+//   CacheIRStubInfo  | 0
+//   CacheIR bytecode | sizeof(CacheIRStubInfo)
+//   Stub field types | sizeof(CacheIRStubInfo) + codeLength_
+//
+// The array of stub field types is terminated by StubField::Type::Limit.
 class CacheIRStubInfo {
-  const uint8_t* code_;
-  const uint8_t* fieldTypes_;
-  uint32_t length_;
-
+  uint32_t codeLength_;
   CacheKind kind_;
   ICStubEngine engine_;
   uint8_t stubDataOffset_;
   bool makesGCCalls_;
 
   CacheIRStubInfo(CacheKind kind, ICStubEngine engine, bool makesGCCalls,
-                  uint32_t stubDataOffset, const uint8_t* code,
-                  uint32_t codeLength, const uint8_t* fieldTypes)
-      : code_(code),
-        fieldTypes_(fieldTypes),
-        length_(codeLength),
+                  uint32_t stubDataOffset, uint32_t codeLength)
+      : codeLength_(codeLength),
         kind_(kind),
         engine_(engine),
         stubDataOffset_(stubDataOffset),
@@ -1261,14 +1266,18 @@ class CacheIRStubInfo {
   ICStubEngine engine() const { return engine_; }
   bool makesGCCalls() const { return makesGCCalls_; }
 
-  const uint8_t* code() const { return code_; }
-  uint32_t codeLength() const { return length_; }
+  const uint8_t* code() const {
+    return reinterpret_cast<const uint8_t*>(this) + sizeof(CacheIRStubInfo);
+  }
+  uint32_t codeLength() const { return codeLength_; }
   uint32_t stubDataOffset() const { return stubDataOffset_; }
 
   size_t stubDataSize() const;
 
   StubField::Type fieldType(uint32_t i) const {
-    return (StubField::Type)fieldTypes_[i];
+    static_assert(sizeof(StubField::Type) == sizeof(uint8_t));
+    const uint8_t* fieldTypes = code() + codeLength_;
+    return static_cast<StubField::Type>(fieldTypes[i]);
   }
 
   static CacheIRStubInfo* New(CacheKind kind, ICStubEngine engine,
-- 
GitLab