From 97c11967489b2edaafa2db6001741e58bc3cafb2 Mon Sep 17 00:00:00 2001 From: Iain Ireland Date: Tue, 19 Mar 2019 22:57:44 +0000 Subject: [PATCH] Bug 1533890: Add simulator support for IgnoresReturnValue version of native functions r=mgaudet Native calls in the simulator have to be redirected to a special swi instruction. In the old implementation, this redirection did not support calling the IgnoresReturnValue version of a native function. This patch fixes that problem in the new implementation. Differential Revision: https://phabricator.services.mozilla.com/D22775 --HG-- extra : moz-landing-system : lando --- js/src/jit/CacheIR.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/js/src/jit/CacheIR.h b/js/src/jit/CacheIR.h index 438c42eaaafa..011819261743 100644 --- a/js/src/jit/CacheIR.h +++ b/js/src/jit/CacheIR.h @@ -1125,18 +1125,28 @@ class MOZ_RAII CacheIRWriter : public JS::CustomAutoRooter { bool isCrossRealm = cx_->realm() != calleeFunc->realm(); buffer_.writeByte(uint32_t(isCrossRealm)); + // Some native functions can be implemented faster if we know that + // the return value is ignored. + bool ignoresReturnValue = + op == JSOP_CALL_IGNORES_RV && calleeFunc->hasJitInfo() && + calleeFunc->jitInfo()->type() == JSJitInfo::IgnoresReturnValueNative; + #ifdef JS_SIMULATOR // The simulator requires VM calls to be redirected to a special // swi instruction to handle them, so we store the redirected // pointer in the stub and use that instead of the original one. + // If we are calling the ignoresReturnValue version of a native + // function, we bake it into the redirected pointer. // (See BaselineCacheIRCompiler::emitCallNativeFunction.) - void* target = JS_FUNC_TO_DATA_PTR(void*, calleeFunc->native()); - void* redirected = Simulator::RedirectNativeFunction(target, Args_General3); + JSNative target = ignoresReturnValue + ? calleeFunc->jitInfo()->ignoresReturnValueMethod + : calleeFunc->native(); + void* rawPtr = JS_FUNC_TO_DATA_PTR(void*, target); + void* redirected = Simulator::RedirectNativeFunction(rawPtr, Args_General3); addStubField(uintptr_t(redirected), StubField::Type::RawWord); #else - bool ignoresReturnValue = - op == JSOP_CALL_IGNORES_RV && calleeFunc->hasJitInfo() && - calleeFunc->jitInfo()->type() == JSJitInfo::IgnoresReturnValueNative; + // If we are not running in the simulator, we generate different jitcode + // to find the ignoresReturnValue version of a native function. buffer_.writeByte(ignoresReturnValue); #endif }