<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[214950] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/214950">214950</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2017-04-05 10:19:16 -0700 (Wed, 05 Apr 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>WebAssembly: We shouldn't need to pin size registers if we have a fast memory.
https://bugs.webkit.org/show_bug.cgi?id=170504
Reviewed by Mark Lam.
JSTests:
* wasm/function-tests/trap-after-cross-instance-call.js: Added.
(b.new.WebAssembly.Memory):
(importObject.foo.bar):
(wasmFrameCountFromError):
Source/JavaScriptCore:
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
(JSC::Wasm::createJSToWasmWrapper):
(JSC::Wasm::parseAndCompile):
* wasm/WasmMemoryInformation.h:
(JSC::Wasm::PinnedRegisterInfo::toSave):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkJSTestsChangeLog">trunk/JSTests/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmMemoryInformationh">trunk/Source/JavaScriptCore/wasm/WasmMemoryInformation.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkJSTestswasmfunctionteststrapaftercrossinstancecalljs">trunk/JSTests/wasm/function-tests/trap-after-cross-instance-call.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkJSTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/JSTests/ChangeLog (214949 => 214950)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/ChangeLog        2017-04-05 17:15:55 UTC (rev 214949)
+++ trunk/JSTests/ChangeLog        2017-04-05 17:19:16 UTC (rev 214950)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2017-04-05 Keith Miller <keith_miller@apple.com>
+
+ WebAssembly: We shouldn't need to pin size registers if we have a fast memory.
+ https://bugs.webkit.org/show_bug.cgi?id=170504
+
+ Reviewed by Mark Lam.
+
+ * wasm/function-tests/trap-after-cross-instance-call.js: Added.
+ (b.new.WebAssembly.Memory):
+ (importObject.foo.bar):
+ (wasmFrameCountFromError):
+
</ins><span class="cx"> 2017-03-16 Yusuke Suzuki <utatane.tea@gmail.com>
</span><span class="cx">
</span><span class="cx"> [JSC] Generate TemplateObjects at linking time
</span></span></pre></div>
<a id="trunkJSTestswasmfunctionteststrapaftercrossinstancecalljs"></a>
<div class="addfile"><h4>Added: trunk/JSTests/wasm/function-tests/trap-after-cross-instance-call.js (0 => 214950)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/JSTests/wasm/function-tests/trap-after-cross-instance-call.js         (rev 0)
+++ trunk/JSTests/wasm/function-tests/trap-after-cross-instance-call.js        2017-04-05 17:19:16 UTC (rev 214950)
</span><span class="lines">@@ -0,0 +1,64 @@
</span><ins>+import Builder from '../Builder.js'
+import * as assert from '../assert.js'
+
+const pageSize = 64 * 1024;
+const numPages = 10;
+
+const builder = (new Builder())
+ .Type().End()
+ .Import()
+ .Memory("a", "b", {initial: numPages})
+ .Function("foo", "bar", { params: [], ret: "void" })
+ .End()
+ .Function().End()
+ .Export().Function("foo").End()
+ .Code()
+ .Function("foo", {params: ["i32"], ret: "i32"})
+ .Call(0)
+ .GetLocal(0)
+ .I32Load(2, 0)
+ .Return()
+ .End()
+ .End();
+
+const bin = builder.WebAssembly().get();
+const module = new WebAssembly.Module(bin);
+
+let importObject = {a: {b: new WebAssembly.Memory({initial: numPages})}};
+
+{
+ const builder = (new Builder())
+ .Type().End()
+ .Import()
+ .Memory("a", "b", {initial: numPages})
+ .End()
+ .Function().End()
+ .Export().Function("bar").End()
+ .Code()
+ .Function("bar", { params: [], ret: "void" })
+ .Return()
+ .End()
+ .End();
+
+ const bin = builder.WebAssembly().get();
+ const module = new WebAssembly.Module(bin);
+
+ importObject.foo = new WebAssembly.Instance(module, {a: {b: new WebAssembly.Memory({initial: numPages})}}).exports
+}
+
+let foo1 = new WebAssembly.Instance(module, importObject).exports.foo;
+importObject.foo = { bar() { } };
+let foo2 = new WebAssembly.Instance(module, importObject).exports.foo;
+
+
+function wasmFrameCountFromError(e) {
+ let stackFrames = e.stack.split("\n").filter((s) => s.indexOf("<wasm>@[wasm code]") !== -1);
+ return stackFrames.length;
+}
+
+for (let i = 0; i < 1000; i++) {
+ const e1 = assert.throws(() => foo1(numPages * pageSize + 1), WebAssembly.RuntimeError, "Out of bounds memory access");
+ assert.eq(wasmFrameCountFromError(e1), 2);
+ const e2 = assert.throws(() => foo1(numPages * pageSize + 1), WebAssembly.RuntimeError, "Out of bounds memory access");
+ assert.eq(wasmFrameCountFromError(e2), 2);
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (214949 => 214950)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-04-05 17:15:55 UTC (rev 214949)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-04-05 17:19:16 UTC (rev 214950)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2017-04-05 Keith Miller <keith_miller@apple.com>
+
+ WebAssembly: We shouldn't need to pin size registers if we have a fast memory.
+ https://bugs.webkit.org/show_bug.cgi?id=170504
+
+ Reviewed by Mark Lam.
+
+ * wasm/WasmB3IRGenerator.cpp:
+ (JSC::Wasm::B3IRGenerator::B3IRGenerator):
+ (JSC::Wasm::createJSToWasmWrapper):
+ (JSC::Wasm::parseAndCompile):
+ * wasm/WasmMemoryInformation.h:
+ (JSC::Wasm::PinnedRegisterInfo::toSave):
+
</ins><span class="cx"> 2017-04-05 Yusuke Suzuki <utatane.tea@gmail.com>
</span><span class="cx">
</span><span class="cx"> [JSC] Suppress warnings in GCC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp (214949 => 214950)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2017-04-05 17:15:55 UTC (rev 214949)
+++ trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2017-04-05 17:19:16 UTC (rev 214950)
</span><span class="lines">@@ -243,7 +243,7 @@
</span><span class="cx"> HashMap<ValueKey, Value*> m_constantPool;
</span><span class="cx"> InsertionSet m_constantInsertionValues;
</span><span class="cx"> GPRReg m_memoryBaseGPR;
</span><del>- GPRReg m_memorySizeGPR;
</del><ins>+ GPRReg m_memorySizeGPR { InvalidGPRReg };
</ins><span class="cx"> GPRReg m_wasmContextGPR;
</span><span class="cx"> Value* m_instanceValue; // FIXME: make this lazy https://bugs.webkit.org/show_bug.cgi?id=169792
</span><span class="cx"> };
</span><span class="lines">@@ -313,16 +313,21 @@
</span><span class="cx">
</span><span class="cx"> // FIXME we don't really need to pin registers here if there's no memory. It makes wasm -> wasm thunks simpler for now. https://bugs.webkit.org/show_bug.cgi?id=166623
</span><span class="cx"> const PinnedRegisterInfo& pinnedRegs = PinnedRegisterInfo::get();
</span><ins>+
</ins><span class="cx"> m_memoryBaseGPR = pinnedRegs.baseMemoryPointer;
</span><ins>+ m_proc.pinRegister(m_memoryBaseGPR);
+
</ins><span class="cx"> m_wasmContextGPR = pinnedRegs.wasmContextPointer;
</span><del>- m_proc.pinRegister(m_memoryBaseGPR);
</del><span class="cx"> if (!useFastTLSForContext())
</span><span class="cx"> m_proc.pinRegister(m_wasmContextGPR);
</span><del>- ASSERT(!pinnedRegs.sizeRegisters[0].sizeOffset);
- m_memorySizeGPR = pinnedRegs.sizeRegisters[0].sizeRegister;
- for (const PinnedSizeRegisterInfo& regInfo : pinnedRegs.sizeRegisters)
- m_proc.pinRegister(regInfo.sizeRegister);
</del><span class="cx">
</span><ins>+ if (mode != MemoryMode::Signaling) {
+ ASSERT(!pinnedRegs.sizeRegisters[0].sizeOffset);
+ m_memorySizeGPR = pinnedRegs.sizeRegisters[0].sizeRegister;
+ for (const PinnedSizeRegisterInfo& regInfo : pinnedRegs.sizeRegisters)
+ m_proc.pinRegister(regInfo.sizeRegister);
+ }
+
</ins><span class="cx"> if (info.memory) {
</span><span class="cx"> m_proc.setWasmBoundsCheckGenerator([=] (CCallHelpers& jit, GPRReg pinnedGPR, unsigned) {
</span><span class="cx"> AllowMacroScratchRegisterUsage allowScratch(jit);
</span><span class="lines">@@ -903,6 +908,7 @@
</span><span class="cx"> [=] (PatchpointValue* patchpoint) {
</span><span class="cx"> patchpoint->effects.writesPinned = true;
</span><span class="cx"> patchpoint->effects.readsPinned = true;
</span><ins>+ // We need to clobber all potential pinned registers since we might be leaving the instance.
</ins><span class="cx"> patchpoint->clobberLate(PinnedRegisterInfo::get().toSave());
</span><span class="cx"> patchpoint->setGenerator([unlinkedWasmToWasmCalls, functionIndex] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
</span><span class="cx"> AllowMacroScratchRegisterUsage allowScratch(jit);
</span><span class="lines">@@ -928,6 +934,7 @@
</span><span class="cx"> patchpoint->effects.writesPinned = true;
</span><span class="cx"> patchpoint->effects.readsPinned = true;
</span><span class="cx"> patchpoint->append(jumpDestination, ValueRep::SomeRegister);
</span><ins>+ // We need to clobber all potential pinned registers since we might be leaving the instance.
</ins><span class="cx"> patchpoint->clobberLate(PinnedRegisterInfo::get().toSave());
</span><span class="cx"> patchpoint->setGenerator([unlinkedWasmToWasmCalls, functionIndex, returnType] (CCallHelpers& jit, const B3::StackmapGenerationParams& params) {
</span><span class="cx"> AllowMacroScratchRegisterUsage allowScratch(jit);
</span><span class="lines">@@ -1032,6 +1039,7 @@
</span><span class="cx"> [=] (PatchpointValue* patchpoint) {
</span><span class="cx"> patchpoint->effects.writesPinned = true;
</span><span class="cx"> patchpoint->effects.readsPinned = true;
</span><ins>+ // We need to clobber all potential pinned registers since we might be leaving the instance.
</ins><span class="cx"> patchpoint->clobberLate(PinnedRegisterInfo::get().toSave());
</span><span class="cx">
</span><span class="cx"> patchpoint->append(calleeCode, ValueRep::SomeRegister);
</span><span class="lines">@@ -1088,7 +1096,7 @@
</span><span class="cx"> dataLogLn();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void createJSToWasmWrapper(CompilationContext& compilationContext, WasmInternalFunction& function, const Signature& signature, const ModuleInformation& info)
</del><ins>+static void createJSToWasmWrapper(CompilationContext& compilationContext, WasmInternalFunction& function, const Signature& signature, const ModuleInformation& info, MemoryMode mode)
</ins><span class="cx"> {
</span><span class="cx"> CCallHelpers& jit = *compilationContext.jsEntrypointJIT;
</span><span class="cx">
</span><span class="lines">@@ -1104,7 +1112,7 @@
</span><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> const PinnedRegisterInfo& pinnedRegs = PinnedRegisterInfo::get();
</span><del>- RegisterSet toSave = pinnedRegs.toSave();
</del><ins>+ RegisterSet toSave = pinnedRegs.toSave(mode);
</ins><span class="cx">
</span><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx"> unsigned toSaveSize = toSave.numberOfSetGPRs();
</span><span class="lines">@@ -1230,13 +1238,17 @@
</span><span class="cx"> jit.loadWasmContext(baseMemory);
</span><span class="cx"> jit.loadPtr(CCallHelpers::Address(baseMemory, JSWebAssemblyInstance::offsetOfMemory()), baseMemory);
</span><span class="cx"> }
</span><del>- const auto& sizeRegs = pinnedRegs.sizeRegisters;
- ASSERT(sizeRegs.size() >= 1);
- ASSERT(!sizeRegs[0].sizeOffset); // The following code assumes we start at 0, and calculates subsequent size registers relative to 0.
- jit.loadPtr(CCallHelpers::Address(baseMemory, JSWebAssemblyMemory::offsetOfSize()), sizeRegs[0].sizeRegister);
</del><ins>+
+ if (mode != MemoryMode::Signaling) {
+ const auto& sizeRegs = pinnedRegs.sizeRegisters;
+ ASSERT(sizeRegs.size() >= 1);
+ ASSERT(!sizeRegs[0].sizeOffset); // The following code assumes we start at 0, and calculates subsequent size registers relative to 0.
+ jit.loadPtr(CCallHelpers::Address(baseMemory, JSWebAssemblyMemory::offsetOfSize()), sizeRegs[0].sizeRegister);
+ for (unsigned i = 1; i < sizeRegs.size(); ++i)
+ jit.add64(CCallHelpers::TrustedImm32(-sizeRegs[i].sizeOffset), sizeRegs[0].sizeRegister, sizeRegs[i].sizeRegister);
+ }
+
</ins><span class="cx"> jit.loadPtr(CCallHelpers::Address(baseMemory, JSWebAssemblyMemory::offsetOfMemory()), baseMemory);
</span><del>- for (unsigned i = 1; i < sizeRegs.size(); ++i)
- jit.add64(CCallHelpers::TrustedImm32(-sizeRegs[i].sizeOffset), sizeRegs[0].sizeRegister, sizeRegs[i].sizeRegister);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> compilationContext.jsEntrypointToWasmEntrypointCall = jit.call();
</span><span class="lines">@@ -1311,7 +1323,7 @@
</span><span class="cx"> result->wasmEntrypoint.calleeSaveRegisters = procedure.calleeSaveRegisters();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- createJSToWasmWrapper(compilationContext, *result, signature, info);
</del><ins>+ createJSToWasmWrapper(compilationContext, *result, signature, info, mode);
</ins><span class="cx"> return WTFMove(result);
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmMemoryInformationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmMemoryInformation.h (214949 => 214950)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmMemoryInformation.h        2017-04-05 17:15:55 UTC (rev 214949)
+++ trunk/Source/JavaScriptCore/wasm/WasmMemoryInformation.h        2017-04-05 17:19:16 UTC (rev 214950)
</span><span class="lines">@@ -48,14 +48,16 @@
</span><span class="cx"> static const PinnedRegisterInfo& get();
</span><span class="cx"> PinnedRegisterInfo(Vector<PinnedSizeRegisterInfo>&&, GPRReg, GPRReg);
</span><span class="cx">
</span><del>- RegisterSet toSave() const
</del><ins>+ RegisterSet toSave(MemoryMode mode = MemoryMode::BoundsChecking) const
</ins><span class="cx"> {
</span><span class="cx"> RegisterSet result;
</span><span class="cx"> result.set(baseMemoryPointer);
</span><span class="cx"> if (wasmContextPointer != InvalidGPRReg)
</span><span class="cx"> result.set(wasmContextPointer);
</span><del>- for (const auto& info : sizeRegisters)
- result.set(info.sizeRegister);
</del><ins>+ if (mode != MemoryMode::Signaling) {
+ for (const auto& info : sizeRegisters)
+ result.set(info.sizeRegister);
+ }
</ins><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx"> };
</span></span></pre>
</div>
</div>
</body>
</html>