Bug 947601 - OdinMonkey: Add support for assume_unreachable. r=luke
authorRomain Perier <romain.perier@gmail.com>
Mon, 10 Mar 2014 09:06:44 +0100
changeset 173072 77b2ebd5ffff0e7cbe98b6c058ba3fc00a0433cd
parent 173071 dfd483bbeea6180c64d4229740da9cc17c1bef0e
child 173073 3788d8852f6291079111f6f02ca9ac9c6c376aed
push id40912
push userryanvm@gmail.com
push dateTue, 11 Mar 2014 21:07:57 +0000
treeherdermozilla-inbound@3788d8852f62 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs947601
milestone30.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 947601 - OdinMonkey: Add support for assume_unreachable. r=luke
js/src/jit/AsmJSModule.cpp
js/src/jit/IonMacroAssembler.cpp
js/src/jit/shared/Assembler-shared.h
--- a/js/src/jit/AsmJSModule.cpp
+++ b/js/src/jit/AsmJSModule.cpp
@@ -205,16 +205,24 @@ static void *
 RedirectCall(void *fun, ABIFunctionType type)
 {
 #ifdef JS_ARM_SIMULATOR
     fun = Simulator::RedirectNativeFunction(fun, type);
 #endif
     return fun;
 }
 
+#ifdef DEBUG
+static void
+AssumeUnreachable()
+{
+    MOZ_CRASH("Reached unreachable code in asm.js");
+}
+#endif
+
 static void *
 AddressOf(AsmJSImmKind kind, ExclusiveContext *cx)
 {
     switch (kind) {
       case AsmJSImm_Runtime:
         return cx->runtimeAddressForJit();
       case AsmJSImm_StackLimit:
         return cx->stackLimitAddressForJitCode(StackForUntrustedScript);
@@ -269,16 +277,20 @@ AddressOf(AsmJSImmKind kind, ExclusiveCo
       case AsmJSImm_ExpD:
         return RedirectCall(FuncCast<double (double)>(exp), Args_Double_Double);
       case AsmJSImm_LogD:
         return RedirectCall(FuncCast<double (double)>(log), Args_Double_Double);
       case AsmJSImm_PowD:
         return RedirectCall(FuncCast(ecmaPow), Args_Double_DoubleDouble);
       case AsmJSImm_ATan2D:
         return RedirectCall(FuncCast(ecmaAtan2), Args_Double_DoubleDouble);
+#ifdef DEBUG
+      case AsmJSImm_AssumeUnreachable:
+        return RedirectCall(FuncCast(AssumeUnreachable), Args_General0);
+#endif
       case AsmJSImm_Invalid:
         break;
     }
 
     MOZ_ASSUME_UNREACHABLE("Bad AsmJSImmKind");
     return nullptr;
 }
 
--- a/js/src/jit/IonMacroAssembler.cpp
+++ b/js/src/jit/IonMacroAssembler.cpp
@@ -1274,30 +1274,34 @@ AssumeUnreachable_(const char *output) {
     MOZ_ReportAssertionFailure(output, __FILE__, __LINE__);
 }
 #endif
 
 void
 MacroAssembler::assumeUnreachable(const char *output)
 {
 #ifdef DEBUG
-    // AsmJS forbids use of ImmPtr.
-    if (!IsCompilingAsmJS()) {
-        RegisterSet regs = RegisterSet::Volatile();
-        PushRegsInMask(regs);
+    RegisterSet regs = RegisterSet::Volatile();
+    PushRegsInMask(regs);
+    Register temp = regs.takeGeneral();
 
-        Register temp = regs.takeGeneral();
-
+    // With ASLR, we can't rely on 'output' to point to the
+    // same char array after serialization/deserialization.
+    // It is not possible until we modify AsmJsImmPtr and
+    // the underlying "patching" mechanism.
+    if (IsCompilingAsmJS()) {
+        setupUnalignedABICall(0, temp);
+        callWithABINoProfiling(AsmJSImm_AssumeUnreachable);
+    } else {
         setupUnalignedABICall(1, temp);
         movePtr(ImmPtr(output), temp);
         passABIArg(temp);
         callWithABINoProfiling(JS_FUNC_TO_DATA_PTR(void *, AssumeUnreachable_));
-
-        PopRegsInMask(RegisterSet::Volatile());
     }
+    PopRegsInMask(RegisterSet::Volatile());
 #endif
 
     breakpoint();
 }
 
 static void
 Printf0_(const char *output) {
     printf("%s", output);
--- a/js/src/jit/shared/Assembler-shared.h
+++ b/js/src/jit/shared/Assembler-shared.h
@@ -699,16 +699,19 @@ enum AsmJSImmKind
     AsmJSImm_CeilD,
     AsmJSImm_CeilF,
     AsmJSImm_FloorD,
     AsmJSImm_FloorF,
     AsmJSImm_ExpD,
     AsmJSImm_LogD,
     AsmJSImm_PowD,
     AsmJSImm_ATan2D,
+#ifdef DEBUG
+    AsmJSImm_AssumeUnreachable,
+#endif
     AsmJSImm_Invalid
 };
 
 // Pointer to be embedded as an immediate in asm.js code.
 class AsmJSImmPtr
 {
     AsmJSImmKind kind_;
   public: