Bug 1207827 - Add AssemblerBuffer::putBytesLarge. r=nbp
☠☠ backed out by d3659c740f48 ☠ ☠
authorJakob Olesen <jolesen@mozilla.com>
Tue, 20 Oct 2015 12:57:38 -0700
changeset 303821 3175d41f0acf0d01699e5b8c1d433089a260e36c
parent 303820 76b54ac73786eb8f095531680db0651078b6ce98
child 303822 5e6973f92d22078b8cb4f81227114df37242391a
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp
bugs1207827
milestone44.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 1207827 - Add AssemblerBuffer::putBytesLarge. r=nbp This new method copies a large amount of data into the assembler buffer, potentially splitting it across multiple slices. The existing putBytes() method can only copy into a single slice which limits the maximum since of data that can be inserted and potentially wastes space at the end of the previous slice.
js/src/jit/shared/IonAssemblerBuffer.h
--- a/js/src/jit/shared/IonAssemblerBuffer.h
+++ b/js/src/jit/shared/IonAssemblerBuffer.h
@@ -109,32 +109,30 @@ class AssemblerBuffer
 
   public:
     bool m_oom;
     bool m_bail;
 
     // How many bytes has been committed to the buffer thus far.
     // Does not include tail.
     uint32_t bufferSize;
-    uint32_t lastInstSize;
 
     // Finger for speeding up accesses.
     Slice* finger;
     int finger_offset;
 
     LifoAlloc lifoAlloc_;
 
   public:
     explicit AssemblerBuffer()
       : head(nullptr),
         tail(nullptr),
         m_oom(false),
         m_bail(false),
         bufferSize(0),
-        lastInstSize(0),
         finger(nullptr),
         finger_offset(0),
         lifoAlloc_(8192)
     { }
 
   public:
     bool isAligned(int alignment) const {
         MOZ_ASSERT(IsPowerOfTwo(alignment));
@@ -188,25 +186,47 @@ class AssemblerBuffer
 
     BufferOffset putShort(uint16_t value) {
         return putBytes(sizeof(value), (uint8_t*)&value);
     }
 
     BufferOffset putInt(uint32_t value) {
         return putBytes(sizeof(value), (uint8_t*)&value);
     }
+
+    // Add instSize bytes to this buffer.
+    // The data must fit in a single slice.
     BufferOffset putBytes(uint32_t instSize, uint8_t* inst) {
         if (!ensureSpace(instSize))
             return BufferOffset();
 
         BufferOffset ret = nextOffset();
         tail->putBytes(instSize, inst);
         return ret;
     }
 
+    // Add a potentially large amount of data to this buffer.
+    // The data may be distrubuted across multiple slices.
+    // Return the buffer offset of the first added byte.
+    BufferOffset putBytesLarge(size_t numBytes, const uint8_t* data)
+    {
+        BufferOffset ret = nextOffset();
+        while (numBytes > 0) {
+            if (!ensureSpace(1))
+                return BufferOffset();
+            size_t avail = tail->Capacity() - tail->length();
+            size_t xfer = numBytes < avail ? numBytes : avail;
+            MOZ_ASSERT(xfer > 0, "ensureSpace should have allocated a slice");
+            tail->putBytes(xfer, data);
+            data += xfer;
+            numBytes -= xfer;
+        }
+        return ret;
+    }
+
     unsigned int size() const {
         if (tail)
             return bufferSize + tail->length();
         return bufferSize;
     }
 
     bool oom() const { return m_oom || m_bail; }
     bool bail() const { return m_bail; }