Bug 1364615 - Baldr: remove unlinkedBytesForDebugging (r=lth)
authorLuke Wagner <luke@mozilla.com>
Mon, 15 May 2017 14:27:10 -0500
changeset 406648 b8bbd7e9579a199a02caf025e7becebb67188724
parent 406647 94bc2a2c7274340118d59e845ecc90bcd20ec268
child 406649 4901d885b1a4ae5248345bb2a740d0135c0d1216
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1364615
milestone55.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 1364615 - Baldr: remove unlinkedBytesForDebugging (r=lth) MozReview-Commit-ID: BIizDn89igc
js/src/wasm/WasmCode.cpp
js/src/wasm/WasmCode.h
js/src/wasm/WasmGenerator.cpp
--- a/js/src/wasm/WasmCode.cpp
+++ b/js/src/wasm/WasmCode.cpp
@@ -243,23 +243,27 @@ CodeSegment::create(MacroAssembler& masm
 }
 
 /* static */ UniqueConstCodeSegment
 CodeSegment::create(const Bytes& unlinkedBytes,
                     const ShareableBytes& bytecode,
                     const LinkData& linkData,
                     const Metadata& metadata)
 {
-    uint32_t codeLength = unlinkedBytes.length();
-    MOZ_ASSERT(codeLength % gc::SystemPageSize() == 0);
+    // The unlinked bytes are a snapshot of the MacroAssembler's contents so
+    // round up just like in the MacroAssembler overload above.
+    uint32_t padding = ComputeByteAlignment(unlinkedBytes.length(), gc::SystemPageSize());
+    uint32_t codeLength = unlinkedBytes.length() + padding;
 
     UniqueCodeBytes codeBytes = AllocateCodeBytes(codeLength);
     if (!codeBytes)
         return nullptr;
-    memcpy(codeBytes.get(), unlinkedBytes.begin(), codeLength);
+
+    memcpy(codeBytes.get(), unlinkedBytes.begin(), unlinkedBytes.length());
+    memset(codeBytes.get() + unlinkedBytes.length(), 0, padding);
 
     return create(Move(codeBytes), codeLength, bytecode, linkData, metadata);
 }
 
 /* static */ UniqueConstCodeSegment
 CodeSegment::create(UniqueCodeBytes codeBytes,
                     uint32_t codeLength,
                     const ShareableBytes& bytecode,
@@ -306,28 +310,16 @@ CodeSegment::initialize(UniqueCodeBytes 
     if (!ExecutableAllocator::makeExecutable(bytes_.get(), RoundupCodeLength(codeLength)))
         return false;
 
     SendCodeRangesToProfiler(*this, bytecode.bytes, metadata);
 
     return true;
 }
 
-UniqueConstBytes
-CodeSegment::unlinkedBytesForDebugging(const LinkData& linkData) const
-{
-    UniqueBytes unlinkedBytes = js::MakeUnique<Bytes>();
-    if (!unlinkedBytes)
-        return nullptr;
-    if (!unlinkedBytes->append(base(), length()))
-        return nullptr;
-    StaticallyUnlink(unlinkedBytes->begin(), linkData);
-    return UniqueConstBytes(unlinkedBytes.release());
-}
-
 size_t
 CodeSegment::serializedSize() const
 {
     return sizeof(uint32_t) + length_;
 }
 
 void
 CodeSegment::addSizeOfMisc(mozilla::MallocSizeOf mallocSizeOf, size_t* code, size_t* data) const
--- a/js/src/wasm/WasmCode.h
+++ b/js/src/wasm/WasmCode.h
@@ -129,18 +129,16 @@ class CodeSegment
 
     bool containsFunctionPC(const void* pc) const {
         return pc >= base() && pc < (base() + functionLength_);
     }
     bool containsCodePC(const void* pc) const {
         return pc >= base() && pc < (base() + length_);
     }
 
-    UniqueConstBytes unlinkedBytesForDebugging(const LinkData& linkData) const;
-
     // Structured clone support:
 
     size_t serializedSize() const;
     uint8_t* serialize(uint8_t* cursor, const LinkData& linkData) const;
     const uint8_t* deserialize(const uint8_t* cursor, const ShareableBytes& bytecode,
                                const LinkData& linkData, const Metadata& metadata);
 
     void addSizeOfMisc(mozilla::MallocSizeOf mallocSizeOf, size_t* code, size_t* data) const;
--- a/js/src/wasm/WasmGenerator.cpp
+++ b/js/src/wasm/WasmGenerator.cpp
@@ -1184,17 +1184,21 @@ ModuleGenerator::finish(const ShareableB
     generateBytecodeHash(bytecode);
 
     UniqueConstCodeSegment codeSegment = CodeSegment::create(masm_, bytecode, linkData_, *metadata_);
     if (!codeSegment)
         return nullptr;
 
     UniqueConstBytes maybeDebuggingBytes;
     if (metadata_->debugEnabled) {
-        maybeDebuggingBytes = codeSegment->unlinkedBytesForDebugging(linkData_);
+        Bytes bytes;
+        if (!bytes.resize(masm_.bytesNeeded()))
+            return nullptr;
+        masm_.executableCopy(bytes.begin(), /* flushICache = */ false);
+        maybeDebuggingBytes = js::MakeUnique<Bytes>(Move(bytes));
         if (!maybeDebuggingBytes)
             return nullptr;
     }
 
     const ShareableBytes* maybeBytecode = nullptr;
     if (metadata_->debugEnabled || !metadata_->funcNames.empty())
         maybeBytecode = &bytecode;