Changeset 245496 in webkit
- Timestamp:
- May 17, 2019 9:58:36 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r245406 r245496 1 2019-05-17 Justin Michaud <justin_michaud@apple.com> 2 3 [WASM-References] Add support for Anyref in parameters and return types, Ref.null and Ref.is_null for Anyref values. 4 https://bugs.webkit.org/show_bug.cgi?id=197969 5 6 Reviewed by Keith Miller. 7 8 Support the anyref type in Builder.js, plus add some extra error logging. 9 Add new folder for wasm references tests. 10 11 * wasm.yaml: 12 * wasm/Builder.js: 13 (const._isValidValue): 14 * wasm/references/anyref_modules.js: Added. 15 (Call.3.RefIsNull.End.End.WebAssembly.js.ident): 16 (Call.3.RefIsNull.End.End.WebAssembly.js.make_null): 17 (Call.3.RefIsNull.End.End.WebAssembly): 18 (undefined): 19 * wasm/references/is_null.js: Added. 20 * wasm/references/is_null_error.js: Added. 21 * wasm/spec-harness/index.js: 22 * wasm/wasm.json: 23 1 24 2019-05-16 Ross Kirsling <ross.kirsling@sony.com> 2 25 -
trunk/JSTests/wasm.yaml
r230763 r245496 29 29 cmd: runNoJIT unless parseRunCommands 30 30 - path: wasm/function-tests 31 cmd: runWebAssemblySuite unless parseRunCommands 32 - path: wasm/references 31 33 cmd: runWebAssemblySuite unless parseRunCommands 32 34 - path: wasm/fuzz -
trunk/JSTests/wasm/Builder.js
r232970 r245496 34 34 // We allow both signed and unsigned numbers. 35 35 case "i32": return Math.round(value) === value && LLB.varint32Min <= value && value <= LLB.varuint32Max; 36 case "anyref": return true; 36 37 case "i64": return true; // FIXME https://bugs.webkit.org/show_bug.cgi?id=163420 64-bit values 37 38 case "f32": return typeof(value) === "number" && isFinite(value); -
trunk/JSTests/wasm/spec-harness/index.js
r218216 r245496 191 191 uniqueTest(() => { 192 192 let instantiated = err === null; 193 if (!instantiated) print(err); 193 194 assert_true(instantiated, err); 194 195 }, "module successfully instantiated"); -
trunk/JSTests/wasm/wasm.json
r243514 r245496 13 13 "f64": { "type": "varint7", "value": -4, "b3type": "B3::Double" }, 14 14 "anyfunc": { "type": "varint7", "value": -16, "b3type": "B3::Void" }, 15 "anyref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" }, 15 16 "func": { "type": "varint7", "value": -32, "b3type": "B3::Void" }, 16 17 "void": { "type": "varint7", "value": -64, "b3type": "B3::Void" } 17 18 }, 18 "value_type": ["i32", "i64", "f32", "f64" ],19 "block_type": ["i32", "i64", "f32", "f64", "void" ],19 "value_type": ["i32", "i64", "f32", "f64", "anyref"], 20 "block_type": ["i32", "i64", "f32", "f64", "void", "anyref"], 20 21 "elem_type": ["anyfunc"], 21 22 "external_kind": { … … 59 60 "f64.const": { "category": "special", "value": 68, "return": ["f64"], "parameter": [], "immediate": [{"name": "value", "type": "double"}], "description": "a constant value interpreted as f64" }, 60 61 "f32.const": { "category": "special", "value": 67, "return": ["f32"], "parameter": [], "immediate": [{"name": "value", "type": "float"}], "description": "a constant value interpreted as f32" }, 62 "ref.null": { "category": "special", "value": 208, "return": ["anyref"], "parameter": [], "immediate": [], "description": "a constant null reference" }, 63 "ref.is_null": { "category": "special", "value": 209, "return": ["i32"], "parameter": ["anyref"], "immediate": [], "description": "determine if a reference is null" }, 61 64 "get_local": { "category": "special", "value": 32, "return": ["any"], "parameter": [], "immediate": [{"name": "local_index", "type": "varuint32"}], "description": "read a local variable or parameter" }, 62 65 "set_local": { "category": "special", "value": 33, "return": [], "parameter": ["any"], "immediate": [{"name": "local_index", "type": "varuint32"}], "description": "write a local variable or parameter" }, -
trunk/Source/JavaScriptCore/ChangeLog
r245492 r245496 1 2019-05-17 Justin Michaud <justin_michaud@apple.com> 2 3 [WASM-References] Add support for Anyref in parameters and return types, Ref.null and Ref.is_null for Anyref values. 4 https://bugs.webkit.org/show_bug.cgi?id=197969 5 6 Reviewed by Keith Miller. 7 8 Add a new runtime option for wasm references. 9 Add support for Anyref as a value type. 10 Add support for Anyref in parameters and return types of Wasm functions. JSValues are marshalled into/out of wasm Anyrefs 11 as a black box, except null which becomes a Nullref value. Nullref is not expressible in the bytecode or in the js API. 12 Add Ref.null and Ref.is_null for Anyref values. Support for these functions with funcrefs is out of scope. 13 14 * runtime/Options.h: 15 * wasm/WasmAirIRGenerator.cpp: 16 (JSC::Wasm::AirIRGenerator::tmpForType): 17 (JSC::Wasm::AirIRGenerator::AirIRGenerator): 18 (JSC::Wasm::AirIRGenerator::addConstant): 19 (JSC::Wasm::AirIRGenerator::addRefIsNull): 20 (JSC::Wasm::AirIRGenerator::addReturn): 21 * wasm/WasmB3IRGenerator.cpp: 22 (JSC::Wasm::B3IRGenerator::addRefIsNull): 23 * wasm/WasmCallingConvention.h: 24 (JSC::Wasm::CallingConventionAir::marshallArgument const): 25 (JSC::Wasm::CallingConventionAir::setupCall const): 26 * wasm/WasmFormat.h: 27 (JSC::Wasm::isValueType): 28 * wasm/WasmFunctionParser.h: 29 (JSC::Wasm::FunctionParser<Context>::FunctionParser): 30 (JSC::Wasm::FunctionParser<Context>::parseExpression): 31 (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression): 32 * wasm/WasmValidate.cpp: 33 (JSC::Wasm::Validate::addRefIsNull): 34 * wasm/generateWasmOpsHeader.py: 35 (bitSet): 36 * wasm/js/JSToWasm.cpp: 37 (JSC::Wasm::createJSToWasmWrapper): 38 * wasm/js/WasmToJS.cpp: 39 (JSC::Wasm::wasmToJS): 40 * wasm/js/WebAssemblyFunction.cpp: 41 (JSC::callWebAssemblyFunction): 42 (JSC::WebAssemblyFunction::jsCallEntrypointSlow): 43 * wasm/wasm.json: 44 1 45 2019-05-17 Don Olmstead <don.olmstead@sony.com> 2 46 -
trunk/Source/JavaScriptCore/runtime/Options.h
r245084 r245496 503 503 v(bool, useCallICsForWebAssemblyToJSCalls, true, Normal, "If true, we will use CallLinkInfo to inline cache Wasm to JS calls.") \ 504 504 v(bool, useEagerWebAssemblyModuleHashing, false, Normal, "Unnamed WebAssembly modules are identified in backtraces through their hash, if available.") \ 505 v(bool, useWebAssemblyReferences, true, Normal, "Allow types from the wasm references spec.") \ 505 506 v(bool, useBigInt, false, Normal, "If true, we will enable BigInt support.") \ 506 507 v(bool, useIntlNumberFormatToParts, enableIntlNumberFormatToParts, Normal, "If true, we will enable Intl.NumberFormat.prototype.formatToParts") \ -
trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp
r245432 r245496 42 42 #include "BinarySwitch.h" 43 43 #include "DisallowMacroScratchRegisterUsage.h" 44 #include "JSCInlines.h" 44 45 #include "ScratchRegisterAllocator.h" 45 46 #include "VirtualRegister.h" … … 231 232 ExpressionType addConstant(BasicBlock*, Type, uint64_t); 232 233 234 PartialResult WARN_UNUSED_RETURN addRefIsNull(ExpressionType& value, ExpressionType& result); 235 233 236 // Locals 234 237 PartialResult WARN_UNUSED_RETURN getLocal(uint32_t index, ExpressionType& result); … … 361 364 return g32(); 362 365 case Type::I64: 366 case Type::Anyref: 363 367 return g64(); 364 368 case Type::F32: … … 787 791 break; 788 792 case Type::I64: 793 case Type::Anyref: 789 794 append(Move, arg, m_locals[i]); 790 795 break; … … 903 908 case Type::I32: 904 909 case Type::I64: 910 case Type::Anyref: 905 911 append(block, Move, Arg::bigImm(value), result); 906 912 break; … … 923 929 { 924 930 RELEASE_ASSERT(m_locals.size() == signature.argumentCount()); // We handle arguments in the prologue 931 return { }; 932 } 933 934 auto AirIRGenerator::addRefIsNull(ExpressionType& value, ExpressionType& result) -> PartialResult 935 { 936 ASSERT(value.tmp()); 937 result = tmpForType(Type::I32); 938 auto tmp = g64(); 939 940 append(Move, Arg::bigImm(JSValue::encode(jsNull())), tmp); 941 append(Compare64, Arg::relCond(MacroAssembler::Equal), value, tmp, result); 942 925 943 return { }; 926 944 } … … 1510 1528 break; 1511 1529 case Type::I64: 1530 case Type::Anyref: 1512 1531 append(Move, returnValues[0], returnValueGPR); 1513 1532 append(Ret64, returnValueGPR); -
trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
r245432 r245496 185 185 ExpressionType addConstant(Type, uint64_t); 186 186 187 PartialResult WARN_UNUSED_RETURN addRefIsNull(ExpressionType& value, ExpressionType& result); 188 187 189 // Locals 188 190 PartialResult WARN_UNUSED_RETURN getLocal(uint32_t index, ExpressionType& result); … … 551 553 } 552 554 555 auto B3IRGenerator::addRefIsNull(ExpressionType& value, ExpressionType& result) -> PartialResult 556 { 557 result = m_currentBlock->appendNew<Value>(m_proc, B3::Equal, origin(), value, m_currentBlock->appendNew<Const64Value>(m_proc, origin(), JSValue::encode(jsNull()))); 558 return { }; 559 } 560 553 561 auto B3IRGenerator::getLocal(uint32_t index, ExpressionType& result) -> PartialResult 554 562 { -
trunk/Source/JavaScriptCore/wasm/WasmCallingConvention.h
r240752 r245496 236 236 case Type::I32: 237 237 case Type::I64: 238 case Type::Anyref: 238 239 marshallArgumentImpl(m_gprArgs, gpArgumentCount, stackOffset, regFunc, stackFunc); 239 240 break; … … 300 301 case Type::I32: 301 302 case Type::I64: 303 case Type::Anyref: 302 304 patchpoint->resultConstraint = B3::ValueRep::reg(GPRInfo::returnValueGPR); 303 305 break; -
trunk/Source/JavaScriptCore/wasm/WasmFormat.h
r239427 r245496 63 63 case F64: 64 64 return true; 65 case Anyref: 66 return Options::useWebAssemblyReferences(); 65 67 default: 66 68 break; -
trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h
r241579 r245496 106 106 { 107 107 if (verbose) 108 dataLogLn("Parsing function starting at: ", (uintptr_t)functionStart, " of length: ", functionLength );108 dataLogLn("Parsing function starting at: ", (uintptr_t)functionStart, " of length: ", functionLength, " with signature: ", signature); 109 109 m_context.setParser(this); 110 110 } … … 282 282 } 283 283 284 case RefNull: { 285 WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled"); 286 m_expressionStack.append(m_context.addConstant(Anyref, JSValue::encode(jsNull()))); 287 return { }; 288 } 289 290 case RefIsNull: { 291 WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled"); 292 ExpressionType result, value; 293 WASM_TRY_POP_EXPRESSION_STACK_INTO(value, "ref.is_null"); 294 WASM_TRY_ADD_TO_CONTEXT(addRefIsNull(value, result)); 295 m_expressionStack.append(result); 296 return { }; 297 } 298 284 299 case GetLocal: { 285 300 uint32_t index; … … 640 655 } 641 656 657 case RefNull: { 658 WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled"); 659 return { }; 660 } 661 662 case RefIsNull: { 663 WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled"); 664 return { }; 665 } 666 642 667 case GrowMemory: 643 668 case CurrentMemory: { -
trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp
r241579 r245496 101 101 ExpressionType addConstant(Type type, uint64_t) { return type; } 102 102 103 Result WARN_UNUSED_RETURN addRefIsNull(ExpressionType& value, ExpressionType& result); 104 103 105 // Locals 104 106 Result WARN_UNUSED_RETURN getLocal(uint32_t index, ExpressionType& result); … … 167 169 for (size_t i = 0; i < signature.argumentCount(); ++i) 168 170 WASM_FAIL_IF_HELPER_FAILS(addLocal(signature.argument(i), 1)); 171 return { }; 172 } 173 174 auto Validate::addRefIsNull(ExpressionType& value, ExpressionType& result) -> Result 175 { 176 result = Type::I32; 177 WASM_VALIDATOR_FAIL_IF(Type::Anyref != value, "ref.is_null to type ", value, " expected ", Type::Anyref); 178 169 179 return { }; 170 180 } -
trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py
r226395 r245496 96 96 def bitSet(): 97 97 v = "" 98 for i in range(ceilDiv(maxOpValue , 8)):98 for i in range(ceilDiv(maxOpValue + 1, 8)): 99 99 entry = 0 100 100 for j in range(8): -
trunk/Source/JavaScriptCore/wasm/js/JSToWasm.cpp
r245432 r245496 83 83 FALLTHROUGH; 84 84 case Wasm::I32: 85 case Wasm::Anyref: 85 86 if (numGPRs >= wasmCallingConvention().m_gprArgs.size()) 86 87 totalFrameSize += sizeof(void*); … … 165 166 case Wasm::I32: 166 167 case Wasm::I64: 168 case Wasm::Anyref: 167 169 if (numGPRs >= wasmCallingConvention().m_gprArgs.size()) { 168 170 if (signature.argument(i) == Wasm::I32) { … … 248 250 jit.moveTrustedValue(jsUndefined(), JSValueRegs { GPRInfo::returnValueGPR }); 249 251 break; 252 case Wasm::Anyref: 253 // FIXME: We need to box wasm Funcrefs once they are supported here. 254 break; 250 255 case Wasm::I32: 251 256 jit.zeroExtend32ToPtr(GPRInfo::returnValueGPR, GPRInfo::returnValueGPR); -
trunk/Source/JavaScriptCore/wasm/js/WasmToJS.cpp
r243051 r245496 166 166 case I64: 167 167 RELEASE_ASSERT_NOT_REACHED(); 168 case Anyref: 168 169 case I32: { 169 170 GPRReg gprReg; … … 176 177 frOffset += sizeof(Register); 177 178 } 178 jit.zeroExtend32ToPtr(gprReg, gprReg); 179 if (argType == I32) 180 jit.zeroExtend32ToPtr(gprReg, gprReg); 179 181 jit.store64(gprReg, buffer + bufferOffset); 180 182 ++marshalledGPRs; … … 242 244 arg = jsNumber(static_cast<int32_t>(buffer[argNum])); 243 245 break; 246 case Anyref: 247 // FIXME: We need to box wasm Funcrefs once they are supported here. 248 arg = JSValue::decode(buffer[argNum]); 249 break; 244 250 case F32: 245 251 case F64: … … 271 277 case I32: { 272 278 realResult = static_cast<uint64_t>(static_cast<uint32_t>(result.toInt32(exec))); 279 break; 280 } 281 case Anyref: { 282 realResult = JSValue::encode(result); 273 283 break; 274 284 } … … 365 375 case I64: 366 376 RELEASE_ASSERT_NOT_REACHED(); // Handled above. 377 case Anyref: 367 378 case I32: { 368 379 GPRReg gprReg; … … 376 387 } 377 388 ++marshalledGPRs; 378 jit.zeroExtend32ToPtr(gprReg, gprReg); // Clear non-int32 and non-tag bits. 379 jit.boxInt32(gprReg, JSValueRegs(gprReg), DoNotHaveTagRegisters); 389 if (argType == I32) { 390 jit.zeroExtend32ToPtr(gprReg, gprReg); // Clear non-int32 and non-tag bits. 391 jit.boxInt32(gprReg, JSValueRegs(gprReg), DoNotHaveTagRegisters); 392 } 393 // FIXME: We need to box wasm Funcrefs once they are supported here. 380 394 jit.store64(gprReg, calleeFrame.withOffset(calleeFrameOffset)); 381 395 calleeFrameOffset += sizeof(Register); … … 431 445 case I64: 432 446 RELEASE_ASSERT_NOT_REACHED(); // Handled above. 447 case Anyref: 433 448 case I32: 434 449 // Skipped: handled above. … … 539 554 break; 540 555 } 556 case Anyref: 557 break; 541 558 case F32: { 542 559 CCallHelpers::JumpList done; -
trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
r245432 r245496 85 85 arg = JSValue::decode(arg.toInt32(exec)); 86 86 break; 87 case Wasm::Anyref: 88 break; 87 89 case Wasm::I64: 88 90 arg = JSValue(); … … 226 228 argumentsIncludeI64 = true; 227 229 break; 230 case Wasm::Anyref: 228 231 case Wasm::I32: 229 232 if (numGPRs >= Wasm::wasmCallingConvention().m_gprArgs.size()) … … 301 304 } 302 305 break; 306 case Wasm::Anyref: { 307 jit.load64(CCallHelpers::Address(GPRInfo::callFrameRegister, jsOffset), scratchGPR); 308 309 if (numGPRs >= Wasm::wasmCallingConvention().m_gprArgs.size()) { 310 jit.store64(scratchGPR, calleeFrame.withOffset(wasmOffset)); 311 wasmOffset += sizeof(CPURegister); 312 } else { 313 jit.move(scratchGPR, Wasm::wasmCallingConvention().m_gprArgs[numGPRs].gpr()); 314 ++numGPRs; 315 } 316 break; 317 } 303 318 case Wasm::F32: 304 319 case Wasm::F64: … … 452 467 break; 453 468 } 469 case Wasm::Anyref: { 470 // FIXME: We need to box wasm Funcrefs once they are supported here. 471 break; 472 } 454 473 case Wasm::I64: 455 474 case Wasm::Func: -
trunk/Source/JavaScriptCore/wasm/wasm.json
r243514 r245496 13 13 "f64": { "type": "varint7", "value": -4, "b3type": "B3::Double" }, 14 14 "anyfunc": { "type": "varint7", "value": -16, "b3type": "B3::Void" }, 15 "anyref": { "type": "varint7", "value": -17, "b3type": "B3::Int64" }, 15 16 "func": { "type": "varint7", "value": -32, "b3type": "B3::Void" }, 16 17 "void": { "type": "varint7", "value": -64, "b3type": "B3::Void" } 17 18 }, 18 "value_type": ["i32", "i64", "f32", "f64" ],19 "block_type": ["i32", "i64", "f32", "f64", "void" ],19 "value_type": ["i32", "i64", "f32", "f64", "anyref"], 20 "block_type": ["i32", "i64", "f32", "f64", "void", "anyref"], 20 21 "elem_type": ["anyfunc"], 21 22 "external_kind": { … … 59 60 "f64.const": { "category": "special", "value": 68, "return": ["f64"], "parameter": [], "immediate": [{"name": "value", "type": "double"}], "description": "a constant value interpreted as f64" }, 60 61 "f32.const": { "category": "special", "value": 67, "return": ["f32"], "parameter": [], "immediate": [{"name": "value", "type": "float"}], "description": "a constant value interpreted as f32" }, 62 "ref.null": { "category": "special", "value": 208, "return": ["anyref"], "parameter": [], "immediate": [], "description": "a constant null reference" }, 63 "ref.is_null": { "category": "special", "value": 209, "return": ["i32"], "parameter": ["anyref"], "immediate": [], "description": "determine if a reference is null" }, 61 64 "get_local": { "category": "special", "value": 32, "return": ["any"], "parameter": [], "immediate": [{"name": "local_index", "type": "varuint32"}], "description": "read a local variable or parameter" }, 62 65 "set_local": { "category": "special", "value": 33, "return": [], "parameter": ["any"], "immediate": [{"name": "local_index", "type": "varuint32"}], "description": "write a local variable or parameter" }, -
trunk/Tools/ChangeLog
r245492 r245496 1 2019-05-17 Justin Michaud <justin_michaud@apple.com> 2 3 [WASM-References] Add support for Anyref in parameters and return types, Ref.null and Ref.is_null for Anyref values. 4 https://bugs.webkit.org/show_bug.cgi?id=197969 5 6 Run wasm tests additionally with wasmBBQUsesAir=0. 7 8 Reviewed by Keith Miller. 9 10 * Scripts/run-jsc-stress-tests: 11 1 12 2019-05-17 Don Olmstead <don.olmstead@sony.com> 2 13 -
trunk/Tools/Scripts/run-jsc-stress-tests
r244915 r245496 1081 1081 run("wasm-no-tls-context", "-m", "--useFastTLSForWasmContext=false", *FTL_OPTIONS) 1082 1082 run("wasm-slow-memory", "-m", "--useWebAssemblyFastMemory=false", *FTL_OPTIONS) 1083 run("wasm-no-air", "-m", "--wasmBBQUsesAir=false", *FTL_OPTIONS) 1083 1084 end 1084 1085 end … … 1097 1098 run("wasm-no-tls-context", "-m", "--useFastTLSForWasmContext=false", *FTL_OPTIONS) 1098 1099 run("wasm-slow-memory", "-m", "--useWebAssemblyFastMemory=false", *FTL_OPTIONS) 1100 run("wasm-no-air", "-m", "--wasmBBQUsesAir=false", *FTL_OPTIONS) 1099 1101 end 1100 1102 end … … 1115 1117 run("wasm-no-call-ic", "--useCallICsForWebAssemblyToJSCalls=false", *FTL_OPTIONS) 1116 1118 run("wasm-no-tls-context", "--useFastTLSForWasmContext=false", *FTL_OPTIONS) 1119 run("wasm-no-air", "--wasmBBQUsesAir=false", *FTL_OPTIONS) 1117 1120 end 1118 1121 end … … 1139 1142 runWithOutputHandler("wasm-no-call-ic", noisyOutputHandler, "../spec-harness.js", "--useCallICsForWebAssemblyToJSCalls=false", *FTL_OPTIONS) 1140 1143 runWithOutputHandler("wasm-no-tls-context", noisyOutputHandler, "../spec-harness.js", "--useFastTLSForWasmContext=false", *FTL_OPTIONS) 1144 runWithOutputHandler("wasm-no-air", noisyOutputHandler, "../spec-harness.js", "--wasmBBQUsesAir=false", *FTL_OPTIONS) 1141 1145 end 1142 1146 end
Note: See TracChangeset
for help on using the changeset viewer.