Bug 1276028 - Baldr: move and privatize callImport (r=bbouvier)

MozReview-Commit-ID: LISVD5fg83L

--HG--
extra : rebase_source : 4dc05a115ce239883a9a67e3847041aeb176bb30
This commit is contained in:
Luke Wagner 2016-06-06 17:18:55 -05:00
parent f3ec612c0a
commit 57323900e3
5 changed files with 104 additions and 121 deletions

View File

@ -1283,6 +1283,33 @@ Module::deoptimizeImportExit(uint32_t importIndex)
exit.baselineScript = nullptr;
}
static bool
ReadI64Object(JSContext* cx, HandleValue v, int64_t* i64)
{
if (!v.isObject()) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_FAIL,
"i64 JS value must be an object");
return false;
}
RootedObject obj(cx, &v.toObject());
int32_t* i32 = (int32_t*)i64;
RootedValue val(cx);
if (!JS_GetProperty(cx, obj, "low", &val))
return false;
if (!ToInt32(cx, val, &i32[0]))
return false;
if (!JS_GetProperty(cx, obj, "high", &val))
return false;
if (!ToInt32(cx, val, &i32[1]))
return false;
return true;
}
static JSObject*
CreateI64Object(JSContext* cx, int64_t i64)
{
@ -1622,6 +1649,55 @@ Module::callImport(JSContext* cx, uint32_t importIndex, unsigned argc, const uin
return true;
}
/* static */ int32_t
Module::callImport_void(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
return activation->module().callImport(cx, importIndex, argc, argv, &rval);
}
/* static */ int32_t
Module::callImport_i32(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
if (!activation->module().callImport(cx, importIndex, argc, argv, &rval))
return false;
return ToInt32(cx, rval, (int32_t*)argv);
}
/* static */ int32_t
Module::callImport_i64(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
if (!activation->module().callImport(cx, importIndex, argc, argv, &rval))
return false;
return ReadI64Object(cx, rval, (int64_t*)argv);
}
/* static */ int32_t
Module::callImport_f64(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
if (!activation->module().callImport(cx, importIndex, argc, argv, &rval))
return false;
return ToNumber(cx, rval, (double*)argv);
}
const char*
Module::maybePrettyFuncName(uint32_t funcIndex) const
{

View File

@ -498,7 +498,15 @@ class Module : public mozilla::LinkedListElement<Module>
MOZ_MUST_USE bool setProfilingEnabled(JSContext* cx, bool enabled);
ImportExit& importToExit(const Import& import);
bool callImport(JSContext* cx, uint32_t importIndex, unsigned argc, const uint64_t* argv,
MutableHandleValue rval);
static int32_t callImport_void(int32_t importIndex, int32_t argc, uint64_t* argv);
static int32_t callImport_i32(int32_t importIndex, int32_t argc, uint64_t* argv);
static int32_t callImport_i64(int32_t importIndex, int32_t argc, uint64_t* argv);
static int32_t callImport_f64(int32_t importIndex, int32_t argc, uint64_t* argv);
friend class js::WasmActivation;
friend void* wasm::AddressOf(SymbolicAddress, ExclusiveContext*);
protected:
const ModuleData& base() const { return *module_; }
@ -595,8 +603,6 @@ class Module : public mozilla::LinkedListElement<Module>
// directly into the JIT code. If the JIT code is released, the Module must
// be notified so it can go back to the generic callImport.
MOZ_MUST_USE bool callImport(JSContext* cx, uint32_t importIndex, unsigned argc,
const uint64_t* argv, MutableHandleValue rval);
void deoptimizeImportExit(uint32_t importIndex);
// At runtime, when $pc is in wasm function code (containsFunctionPC($pc)),

View File

@ -395,7 +395,7 @@ FillArgumentArray(MacroAssembler& masm, const ValTypeVector& args, unsigned argO
}
// Generate a stub that is called via the internal ABI derived from the
// signature of the import and calls into an appropriate InvokeImport C++
// signature of the import and calls into an appropriate callImport C++
// function, having boxed all the ABI arguments into a homogeneous Value array.
ProfilingOffsets
wasm::GenerateInterpExit(MacroAssembler& masm, const Import& import, uint32_t importIndex)
@ -404,7 +404,7 @@ wasm::GenerateInterpExit(MacroAssembler& masm, const Import& import, uint32_t im
masm.setFramePushed(0);
// Argument types for InvokeImport_*:
// Argument types for Module::callImport_*:
static const MIRType typeArray[] = { MIRType::Pointer, // ImportExit
MIRType::Int32, // argc
MIRType::Pointer }; // argv
@ -427,7 +427,7 @@ wasm::GenerateInterpExit(MacroAssembler& masm, const Import& import, uint32_t im
Register scratch = ABINonArgReturnReg0;
FillArgumentArray(masm, sig.args(), argOffset, offsetToCallerStackArgs, scratch, ToValue(false));
// Prepare the arguments for the call to InvokeImport_*.
// Prepare the arguments for the call to Module::callImport_*.
ABIArgMIRTypeIter i(invokeArgTypes);
// argument 0: importIndex
@ -460,28 +460,28 @@ wasm::GenerateInterpExit(MacroAssembler& masm, const Import& import, uint32_t im
AssertStackAlignment(masm, ABIStackAlignment);
switch (sig.ret()) {
case ExprType::Void:
masm.call(SymbolicAddress::InvokeImport_Void);
masm.call(SymbolicAddress::CallImport_Void);
masm.branchTest32(Assembler::Zero, ReturnReg, ReturnReg, JumpTarget::Throw);
break;
case ExprType::I32:
masm.call(SymbolicAddress::InvokeImport_I32);
masm.call(SymbolicAddress::CallImport_I32);
masm.branchTest32(Assembler::Zero, ReturnReg, ReturnReg, JumpTarget::Throw);
masm.load32(argv, ReturnReg);
break;
case ExprType::I64:
MOZ_ASSERT(JitOptions.wasmTestMode);
masm.call(SymbolicAddress::InvokeImport_I64);
masm.call(SymbolicAddress::CallImport_I64);
masm.branchTest32(Assembler::Zero, ReturnReg, ReturnReg, JumpTarget::Throw);
masm.load64(argv, ReturnReg64);
break;
case ExprType::F32:
masm.call(SymbolicAddress::InvokeImport_F64);
masm.call(SymbolicAddress::CallImport_F64);
masm.branchTest32(Assembler::Zero, ReturnReg, ReturnReg, JumpTarget::Throw);
masm.loadDouble(argv, ReturnDoubleReg);
masm.convertDoubleToFloat32(ReturnDoubleReg, ReturnFloat32Reg);
break;
case ExprType::F64:
masm.call(SymbolicAddress::InvokeImport_F64);
masm.call(SymbolicAddress::CallImport_F64);
masm.branchTest32(Assembler::Zero, ReturnReg, ReturnReg, JumpTarget::Throw);
masm.loadDouble(argv, ReturnDoubleReg);
break;

View File

@ -131,101 +131,6 @@ CoerceInPlace_ToNumber(MutableHandleValue val)
return true;
}
// Use an int32_t return type instead of bool since bool does not have a
// specified width and the caller is assuming a word-sized return.
static int32_t
InvokeImport_Void(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
return activation->module().callImport(cx, importIndex, argc, argv, &rval);
}
// Use an int32_t return type instead of bool since bool does not have a
// specified width and the caller is assuming a word-sized return.
static int32_t
InvokeImport_I32(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
if (!activation->module().callImport(cx, importIndex, argc, argv, &rval))
return false;
int32_t i32;
if (!ToInt32(cx, rval, &i32))
return false;
argv[0] = i32;
return true;
}
bool
js::wasm::ReadI64Object(JSContext* cx, HandleValue v, int64_t* i64)
{
if (!v.isObject()) {
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_WASM_FAIL,
"i64 JS value must be an object");
return false;
}
RootedObject obj(cx, &v.toObject());
int32_t* i32 = (int32_t*)i64;
RootedValue val(cx);
if (!JS_GetProperty(cx, obj, "low", &val))
return false;
if (!ToInt32(cx, val, &i32[0]))
return false;
if (!JS_GetProperty(cx, obj, "high", &val))
return false;
if (!ToInt32(cx, val, &i32[1]))
return false;
return true;
}
static int32_t
InvokeImport_I64(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
if (!activation->module().callImport(cx, importIndex, argc, argv, &rval))
return false;
if (!ReadI64Object(cx, rval, (int64_t*)argv))
return false;
return true;
}
// Use an int32_t return type instead of bool since bool does not have a
// specified width and the caller is assuming a word-sized return.
static int32_t
InvokeImport_F64(int32_t importIndex, int32_t argc, uint64_t* argv)
{
WasmActivation* activation = JSRuntime::innermostWasmActivation();
JSContext* cx = activation->cx();
RootedValue rval(cx);
if (!activation->module().callImport(cx, importIndex, argc, argv, &rval))
return false;
double dbl;
if (!ToNumber(cx, rval, &dbl))
return false;
((double*)argv)[0] = dbl;
return true;
}
template <class F>
static inline void*
FuncCast(F* pf, ABIFunctionType type)
@ -253,14 +158,14 @@ wasm::AddressOf(SymbolicAddress imm, ExclusiveContext* cx)
return FuncCast(WasmHandleExecutionInterrupt, Args_General0);
case SymbolicAddress::HandleTrap:
return FuncCast(HandleTrap, Args_General1);
case SymbolicAddress::InvokeImport_Void:
return FuncCast(InvokeImport_Void, Args_General3);
case SymbolicAddress::InvokeImport_I32:
return FuncCast(InvokeImport_I32, Args_General3);
case SymbolicAddress::InvokeImport_I64:
return FuncCast(InvokeImport_I64, Args_General3);
case SymbolicAddress::InvokeImport_F64:
return FuncCast(InvokeImport_F64, Args_General3);
case SymbolicAddress::CallImport_Void:
return FuncCast(Module::callImport_void, Args_General3);
case SymbolicAddress::CallImport_I32:
return FuncCast(Module::callImport_i32, Args_General3);
case SymbolicAddress::CallImport_I64:
return FuncCast(Module::callImport_i64, Args_General3);
case SymbolicAddress::CallImport_F64:
return FuncCast(Module::callImport_f64, Args_General3);
case SymbolicAddress::CoerceInPlace_ToInt32:
return FuncCast(CoerceInPlace_ToInt32, Args_General1);
case SymbolicAddress::CoerceInPlace_ToNumber:

View File

@ -702,10 +702,10 @@ enum class SymbolicAddress
ReportOverRecursed,
HandleExecutionInterrupt,
HandleTrap,
InvokeImport_Void,
InvokeImport_I32,
InvokeImport_I64,
InvokeImport_F64,
CallImport_Void,
CallImport_I32,
CallImport_I64,
CallImport_F64,
CoerceInPlace_ToInt32,
CoerceInPlace_ToNumber,
Limit
@ -714,10 +714,6 @@ enum class SymbolicAddress
void*
AddressOf(SymbolicAddress imm, ExclusiveContext* cx);
// Extracts low and high from an int64 object {low: int32, high: int32}, for
// testing purposes mainly.
MOZ_MUST_USE bool ReadI64Object(JSContext* cx, HandleValue v, int64_t* val);
// A wasm::Trap is a reason for why we reached a trap in executed code. Each
// different trap is mapped to a different error message.