Bug 1276028 - Baldr: move x64 global patching out of MacroAssembler (r=bbouvier)
authorLuke Wagner <luke@mozilla.com>
Fri, 10 Jun 2016 13:28:04 -0500
changeset 377703 e6c1eef4b409e4b50e14a40f82cfba53fadbbe96
parent 377702 3f58e166483ba47f945bc7f6d51ad73aa2f44ced
child 377704 5b796f519ed0da9d83ed22f8a11d0d6a60161bd3
push id20857
push userbmo:james@hoppipolla.co.uk
push dateSun, 12 Jun 2016 16:59:39 +0000
reviewersbbouvier
bugs1276028
milestone50.0a1
Bug 1276028 - Baldr: move x64 global patching out of MacroAssembler (r=bbouvier) MozReview-Commit-ID: EmMmfhnf2dI
js/src/asmjs/WasmGenerator.cpp
js/src/jit/arm64/MacroAssembler-arm64.h
js/src/jit/x64/MacroAssembler-x64.h
--- a/js/src/asmjs/WasmGenerator.cpp
+++ b/js/src/asmjs/WasmGenerator.cpp
@@ -482,26 +482,28 @@ ModuleGenerator::finishStaticLinkData(ui
     for (size_t i = 0; i < masm_.numAsmJSGlobalAccesses(); i++) {
         AsmJSGlobalAccess a = masm_.asmJSGlobalAccess(i);
         StaticLinkData::InternalLink inLink(StaticLinkData::InternalLink::RawPointer);
         inLink.patchAtOffset = masm_.labelToPatchOffset(a.patchAt);
         inLink.targetOffset = codeLength + a.globalDataOffset;
         if (!link->internalLinks.append(inLink))
             return false;
     }
-#endif
-
-#if defined(JS_CODEGEN_X64)
-    // Global data accesses on x64 use rip-relative addressing and thus do
-    // not need patching after deserialization.
-    uint8_t* globalData = code + codeLength;
+#elif defined(JS_CODEGEN_X64)
+    // Global data accesses on x64 use rip-relative addressing and thus we can
+    // patch here, now that we know the final codeLength.
     for (size_t i = 0; i < masm_.numAsmJSGlobalAccesses(); i++) {
         AsmJSGlobalAccess a = masm_.asmJSGlobalAccess(i);
-        masm_.patchAsmJSGlobalAccess(a.patchAt, code, globalData, a.globalDataOffset);
+        void* from = code + a.patchAt.offset();
+        void* to = code + codeLength + a.globalDataOffset;
+        X86Encoding::SetRel32(from, to);
     }
+#else
+    // Global access is performed using the GlobalReg and requires no patching.
+    MOZ_ASSERT(masm_.numAsmJSGlobalAccesses() == 0);
 #endif
 
     // Function pointer table elements
 
     if (shared_->wasmTable.numElems > 0) {
         const TableModuleGeneratorData& table = shared_->wasmTable;
 
         Uint32Vector elemOffsets;
--- a/js/src/jit/arm64/MacroAssembler-arm64.h
+++ b/js/src/jit/arm64/MacroAssembler-arm64.h
@@ -1869,23 +1869,16 @@ class MacroAssemblerCompat : public vixl
 
   public:
     CodeOffset labelForPatch() {
         return CodeOffset(nextOffset().getOffset());
     }
 
     void handleFailureWithHandlerTail(void* handler);
 
-    // FIXME: See CodeGeneratorX64 calls to noteAsmJSGlobalAccess.
-    void patchAsmJSGlobalAccess(CodeOffset patchAt, uint8_t* code,
-                                uint8_t* globalData, unsigned globalDataOffset)
-    {
-        MOZ_CRASH("patchAsmJSGlobalAccess");
-    }
-
     void profilerEnterFrame(Register framePtr, Register scratch) {
         AbsoluteAddress activation(GetJitContext()->runtime->addressOfProfilingActivation());
         loadPtr(activation, scratch);
         storePtr(framePtr, Address(scratch, JitActivation::offsetOfLastProfilingFrame()));
         storePtr(ImmPtr(nullptr), Address(scratch, JitActivation::offsetOfLastProfilingCallSite()));
     }
     void profilerExitFrame() {
         branch(GetJitContext()->runtime->jitRuntime()->getProfilerExitFrameTail());
--- a/js/src/jit/x64/MacroAssembler-x64.h
+++ b/js/src/jit/x64/MacroAssembler-x64.h
@@ -925,26 +925,16 @@ class MacroAssemblerX64 : public MacroAs
 
     inline void incrementInt32Value(const Address& addr);
 
     inline void ensureDouble(const ValueOperand& source, FloatRegister dest, Label* failure);
 
   public:
     void handleFailureWithHandlerTail(void* handler);
 
-    // See CodeGeneratorX64 calls to noteAsmJSGlobalAccess.
-    void patchAsmJSGlobalAccess(CodeOffset patchAt, uint8_t* code, uint8_t* globalData,
-                                unsigned globalDataOffset)
-    {
-        uint8_t* nextInsn = code + patchAt.offset();
-        MOZ_ASSERT(nextInsn <= globalData);
-        uint8_t* target = globalData + globalDataOffset;
-        ((int32_t*)nextInsn)[-1] = target - nextInsn;
-    }
-
     // Instrumentation for entering and leaving the profiler.
     void profilerEnterFrame(Register framePtr, Register scratch);
     void profilerExitFrame();
 };
 
 typedef MacroAssemblerX64 MacroAssemblerSpecific;
 
 } // namespace jit