Skip to content

Commit fe931a8

Browse files
committed
WebAssembly: WasmB3IRGenerator should throw exceptions instead of crash
https://bugs.webkit.org/show_bug.cgi?id=165834 Reviewed by Keith Miller. JSTests: * wasm/function-tests/exceptions.js: Added. (import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance): * wasm/function-tests/table-basic.js: (i.i.42.throw.new.Error): Source/JavaScriptCore: This patch generalizes how we throw exceptions in the Wasm::B3IRGenerator. There are still places where we need to throw exceptions and we don't, but this patch removes most of those places inside the IR generator. There are still a few places we need to throw exceptions inside the IR generator, like div/mod by 0. Those will be done in a separate patch. Also, there are still some stubs we need to throw exceptions from; those will also be done in a separate patch. All exceptions thrown from Wasm share a common stub. The ABI for the stub is to move the Wasm::ExceptionType into argGPR1 and jump to the stub. The stub will then throw an exception with an error message tailored to the particular Wasm::ExceptionType failure. This patch also refactors B3::Compilation. Before, B3::Compilation(VM, Procedure) constructor would compile a B3 function. This patch makes B3::Compilation a simple tuple that keeps the necessary bits of B3 function alive in order to be runnable. There is a new function that actually does the compilation for you. It is: Compilation B3::compile(VM&, Procedure&) The reason for this change is that I'm now using B3::Compilation(CodeRef, OpaqueByproducts) constructor in Wasm code. It is weird to have a class both have a constructor that instantiates the tuple, and another that performs the compilation and then instantiates the tuple. It's more straight forward if Compilation's job wasn't to actually do the compilation but just to hold the necessary bits to keep a compiled B3 alive. * CMakeLists.txt: * JavaScriptCore.xcodeproj/project.pbxproj: * b3/B3Compilation.cpp: (JSC::B3::Compilation::Compilation): * b3/B3Compilation.h: * b3/B3Compile.cpp: Added. (JSC::B3::compile): * b3/B3Compile.h: Added. * b3/testb3.cpp: (JSC::B3::compile): * jit/ThunkGenerators.cpp: (JSC::throwExceptionFromWasmThunkGenerator): * jit/ThunkGenerators.h: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::emitExceptionCheck): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmExceptionType.h: Added. (JSC::Wasm::errorMessageForExceptionType): Canonical link: https://commits.webkit.org/183560@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209928 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 3d884f7 commit fe931a8

15 files changed

Lines changed: 437 additions & 105 deletions

File tree

JSTests/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2016-12-16 Saam Barati <[email protected]>
2+
3+
WebAssembly: WasmB3IRGenerator should throw exceptions instead of crash
4+
https://bugs.webkit.org/show_bug.cgi?id=165834
5+
6+
Reviewed by Keith Miller.
7+
8+
* wasm/function-tests/exceptions.js: Added.
9+
(import.Builder.from.string_appeared_here.import.as.assert.from.string_appeared_here.makeInstance):
10+
* wasm/function-tests/table-basic.js:
11+
(i.i.42.throw.new.Error):
12+
113
2016-12-16 Keith Miller <[email protected]>
214

315
i64.eqz should use an Int64 zero
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import Builder from '../Builder.js'
2+
import * as assert from '../assert.js'
3+
4+
function makeInstance() {
5+
const tableDescription = {initial: 1, element: "anyfunc"};
6+
const builder = new Builder()
7+
.Type()
8+
.Func(["i32", "i32"], "i32")
9+
.Func(["i32"], "i32")
10+
.End()
11+
.Import()
12+
.Table("imp", "table", tableDescription)
13+
.End()
14+
.Function().End()
15+
.Export()
16+
.Function("foo")
17+
.Function("bar")
18+
.End()
19+
.Code()
20+
.Function("foo", 0 /*['i32', 'i32'] => 'i32'*/)
21+
.GetLocal(1) // parameter to call
22+
.GetLocal(0) // call index
23+
.CallIndirect(1, 0) // calling function of type ['i32'] => 'i32'
24+
.Return()
25+
.End()
26+
.Function("bar", 1 /*['i32'] => 'i32'*/)
27+
.GetLocal(0)
28+
.I32Const(42)
29+
.I32Add()
30+
.Return()
31+
.End()
32+
.End();
33+
34+
35+
const bin = builder.WebAssembly().get();
36+
const module = new WebAssembly.Module(bin);
37+
const table = new WebAssembly.Table(tableDescription);
38+
return {instance: new WebAssembly.Instance(module, {imp: {table}}), table};
39+
}
40+
41+
{
42+
const {instance, table} = makeInstance();
43+
const foo = instance.exports.foo;
44+
const bar = instance.exports.bar;
45+
assert.eq(table.get(0), null);
46+
47+
for (let i = 0; i < 1000; i++) {
48+
assert.throws(() => foo(0, i), WebAssembly.RuntimeError, "call_indirect to a null table entry");
49+
}
50+
51+
table.set(0, foo);
52+
assert.eq(table.get(0), foo);
53+
54+
for (let i = 0; i < 1000; i++) {
55+
assert.throws(() => foo(1 + i, i), WebAssembly.RuntimeError, "Out of bounds call_indirect");
56+
}
57+
58+
for (let i = 0; i < 1000; i++) {
59+
assert.throws(() => foo(0, i), WebAssembly.RuntimeError, "call_indirect to a signature that does not match");
60+
}
61+
62+
table.set(0, bar);
63+
assert.eq(table.get(0), bar);
64+
for (let i = 0; i < 25; i++) {
65+
assert.eq(foo(0, i), i + 42);
66+
}
67+
}

JSTests/wasm/function-tests/table-basic.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ function makeInstance() {
5353
// FIXME: make this work cross module. The reason it doesn't
5454
// now is that we don't unique Signature*.
5555
// https://bugs.webkit.org/show_bug.cgi?id=165511
56-
/*
5756
{
5857
const {instance, table} = makeInstance();
5958
const foo = instance.exports.foo;
60-
//table.set(0, makeInstance().instance.exports.bar); // Cross instance function.
59+
table.set(0, makeInstance().instance.exports.bar); // Cross instance function.
6160

6261
for (let i = 0; i < 1000; i++) {
63-
if (foo(0, i) !== i + 42)
64-
throw new Error("Bad call indirect");
62+
assert.throws(() => foo(0, i), WebAssembly.RuntimeError, "call_indirect to a signature that does not match");
6563
}
6664
}
67-
*/

Source/JavaScriptCore/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ set(JavaScriptCore_SOURCES
116116
b3/B3CheckValue.cpp
117117
b3/B3Common.cpp
118118
b3/B3Commutativity.cpp
119+
b3/B3Compile.cpp
119120
b3/B3Compilation.cpp
120121
b3/B3Const32Value.cpp
121122
b3/B3Const64Value.cpp

Source/JavaScriptCore/ChangeLog

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
2016-12-16 Saam Barati <[email protected]>
2+
3+
WebAssembly: WasmB3IRGenerator should throw exceptions instead of crash
4+
https://bugs.webkit.org/show_bug.cgi?id=165834
5+
6+
Reviewed by Keith Miller.
7+
8+
This patch generalizes how we throw exceptions in the Wasm::B3IRGenerator.
9+
There are still places where we need to throw exceptions and we don't, but
10+
this patch removes most of those places inside the IR generator. There are
11+
still a few places we need to throw exceptions inside the IR generator, like
12+
div/mod by 0. Those will be done in a separate patch. Also, there are
13+
still some stubs we need to throw exceptions from; those will also be
14+
done in a separate patch.
15+
16+
All exceptions thrown from Wasm share a common stub. The ABI for the stub
17+
is to move the Wasm::ExceptionType into argGPR1 and jump to the stub.
18+
The stub will then throw an exception with an error message tailored
19+
to the particular Wasm::ExceptionType failure.
20+
21+
This patch also refactors B3::Compilation. Before, B3::Compilation(VM, Procedure)
22+
constructor would compile a B3 function. This patch makes B3::Compilation a simple
23+
tuple that keeps the necessary bits of B3 function alive in order to be runnable.
24+
There is a new function that actually does the compilation for you. It is:
25+
Compilation B3::compile(VM&, Procedure&)
26+
The reason for this change is that I'm now using B3::Compilation(CodeRef, OpaqueByproducts)
27+
constructor in Wasm code. It is weird to have a class both have a
28+
constructor that instantiates the tuple, and another that performs the
29+
compilation and then instantiates the tuple. It's more straight
30+
forward if Compilation's job wasn't to actually do the compilation
31+
but just to hold the necessary bits to keep a compiled B3 alive.
32+
33+
* CMakeLists.txt:
34+
* JavaScriptCore.xcodeproj/project.pbxproj:
35+
* b3/B3Compilation.cpp:
36+
(JSC::B3::Compilation::Compilation):
37+
* b3/B3Compilation.h:
38+
* b3/B3Compile.cpp: Added.
39+
(JSC::B3::compile):
40+
* b3/B3Compile.h: Added.
41+
* b3/testb3.cpp:
42+
(JSC::B3::compile):
43+
* jit/ThunkGenerators.cpp:
44+
(JSC::throwExceptionFromWasmThunkGenerator):
45+
* jit/ThunkGenerators.h:
46+
* wasm/WasmB3IRGenerator.cpp:
47+
(JSC::Wasm::B3IRGenerator::B3IRGenerator):
48+
(JSC::Wasm::B3IRGenerator::emitExceptionCheck):
49+
(JSC::Wasm::createJSToWasmWrapper):
50+
(JSC::Wasm::parseAndCompile):
51+
* wasm/WasmExceptionType.h: Added.
52+
(JSC::Wasm::errorMessageForExceptionType):
53+
154
2016-12-16 Keith Miller <[email protected]>
255

356
i64.eqz should use an Int64 zero

Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@
13021302
53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
13031303
53FA2AE31CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */; };
13041304
53FD04D31D7AB277003287D3 /* WasmCallingConvention.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */; };
1305-
53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */; };
1305+
53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */; settings = {ATTRIBUTES = (Private, ); }; };
13061306
53FF7F991DBFCD9000A26CCC /* WasmValidate.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FF7F981DBFCD9000A26CCC /* WasmValidate.h */; };
13071307
53FF7F9B1DBFD2B900A26CCC /* WasmValidate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FF7F9A1DBFD2B900A26CCC /* WasmValidate.cpp */; };
13081308
5B70CFDE1DB69E6600EC23F9 /* JSAsyncFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B70CFD81DB69E5C00EC23F9 /* JSAsyncFunction.h */; };
@@ -1406,11 +1406,13 @@
14061406
7905BB691D12050E0019FE57 /* InlineAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = 7905BB671D12050E0019FE57 /* InlineAccess.h */; settings = {ATTRIBUTES = (Private, ); }; };
14071407
79160DBD1C8E3EC8008C085A /* ProxyRevoke.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79160DBB1C8E3EC8008C085A /* ProxyRevoke.cpp */; };
14081408
79160DBE1C8E3EC8008C085A /* ProxyRevoke.h in Headers */ = {isa = PBXBuildFile; fileRef = 79160DBC1C8E3EC8008C085A /* ProxyRevoke.h */; settings = {ATTRIBUTES = (Private, ); }; };
1409+
7919B7801E03559C005BEED8 /* B3Compile.h in Headers */ = {isa = PBXBuildFile; fileRef = 7919B77F1E03559C005BEED8 /* B3Compile.h */; settings = {ATTRIBUTES = (Private, ); }; };
14091410
79233C2B1D34715700C5A834 /* JITMathIC.h in Headers */ = {isa = PBXBuildFile; fileRef = 79233C291D34715700C5A834 /* JITMathIC.h */; settings = {ATTRIBUTES = (Private, ); }; };
14101411
792CB3491C4EED5C00D13AF3 /* PCToCodeOriginMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 792CB3471C4EED5C00D13AF3 /* PCToCodeOriginMap.cpp */; };
14111412
792CB34A1C4EED5C00D13AF3 /* PCToCodeOriginMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 792CB3481C4EED5C00D13AF3 /* PCToCodeOriginMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
14121413
795B19971D78BE3500262FA0 /* MapBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 795B19951D78BE3500262FA0 /* MapBase.cpp */; };
14131414
795B19981D78BE3500262FA0 /* MapBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 795B19961D78BE3500262FA0 /* MapBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
1415+
795F099D1E03600500BBE37F /* B3Compile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 795F099C1E03600500BBE37F /* B3Compile.cpp */; };
14141416
7964656A1B952FF0003059EE /* GetPutInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 796465681B952FF0003059EE /* GetPutInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
14151417
796FB43A1DFF8C3F0039C95D /* JSWebAssemblyHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = 796FB4391DFF8C3F0039C95D /* JSWebAssemblyHelpers.h */; settings = {ATTRIBUTES = (Private, ); }; };
14161418
797E07A91B8FCFB9008400BA /* JSGlobalLexicalEnvironment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 797E07A71B8FCFB9008400BA /* JSGlobalLexicalEnvironment.cpp */; };
@@ -1437,6 +1439,7 @@
14371439
79CFC6F01C33B10000C768EA /* LLIntPCRanges.h in Headers */ = {isa = PBXBuildFile; fileRef = 79CFC6EF1C33B10000C768EA /* LLIntPCRanges.h */; settings = {ATTRIBUTES = (Private, ); }; };
14381440
79D5CD5A1C1106A900CECA07 /* SamplingProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79D5CD581C1106A900CECA07 /* SamplingProfiler.cpp */; };
14391441
79D5CD5B1C1106A900CECA07 /* SamplingProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 79D5CD591C1106A900CECA07 /* SamplingProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
1442+
79DAE27A1E03C82200B526AA /* WasmExceptionType.h in Headers */ = {isa = PBXBuildFile; fileRef = 79DAE2791E03C82200B526AA /* WasmExceptionType.h */; };
14401443
79DFCBDB1D88C59600527D03 /* HasOwnPropertyCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 79DFCBDA1D88C59600527D03 /* HasOwnPropertyCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
14411444
79E423E21DEE65320078D355 /* JSWebAssemblyCallee.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79E423E01DEE65320078D355 /* JSWebAssemblyCallee.cpp */; };
14421445
79E423E31DEE65320078D355 /* JSWebAssemblyCallee.h in Headers */ = {isa = PBXBuildFile; fileRef = 79E423E11DEE65320078D355 /* JSWebAssemblyCallee.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3835,11 +3838,13 @@
38353838
7905BB671D12050E0019FE57 /* InlineAccess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineAccess.h; sourceTree = "<group>"; };
38363839
79160DBB1C8E3EC8008C085A /* ProxyRevoke.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProxyRevoke.cpp; sourceTree = "<group>"; };
38373840
79160DBC1C8E3EC8008C085A /* ProxyRevoke.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyRevoke.h; sourceTree = "<group>"; };
3841+
7919B77F1E03559C005BEED8 /* B3Compile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3Compile.h; path = b3/B3Compile.h; sourceTree = "<group>"; };
38383842
79233C291D34715700C5A834 /* JITMathIC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITMathIC.h; sourceTree = "<group>"; };
38393843
792CB3471C4EED5C00D13AF3 /* PCToCodeOriginMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PCToCodeOriginMap.cpp; sourceTree = "<group>"; };
38403844
792CB3481C4EED5C00D13AF3 /* PCToCodeOriginMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PCToCodeOriginMap.h; sourceTree = "<group>"; };
38413845
795B19951D78BE3500262FA0 /* MapBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MapBase.cpp; sourceTree = "<group>"; };
38423846
795B19961D78BE3500262FA0 /* MapBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapBase.h; sourceTree = "<group>"; };
3847+
795F099C1E03600500BBE37F /* B3Compile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3Compile.cpp; path = b3/B3Compile.cpp; sourceTree = "<group>"; };
38433848
796465681B952FF0003059EE /* GetPutInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetPutInfo.h; sourceTree = "<group>"; };
38443849
796FB4391DFF8C3F0039C95D /* JSWebAssemblyHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWebAssemblyHelpers.h; path = js/JSWebAssemblyHelpers.h; sourceTree = "<group>"; };
38453850
797E07A71B8FCFB9008400BA /* JSGlobalLexicalEnvironment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSGlobalLexicalEnvironment.cpp; sourceTree = "<group>"; };
@@ -3866,6 +3871,7 @@
38663871
79CFC6EF1C33B10000C768EA /* LLIntPCRanges.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLIntPCRanges.h; path = llint/LLIntPCRanges.h; sourceTree = "<group>"; };
38673872
79D5CD581C1106A900CECA07 /* SamplingProfiler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SamplingProfiler.cpp; sourceTree = "<group>"; };
38683873
79D5CD591C1106A900CECA07 /* SamplingProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SamplingProfiler.h; sourceTree = "<group>"; };
3874+
79DAE2791E03C82200B526AA /* WasmExceptionType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmExceptionType.h; sourceTree = "<group>"; };
38693875
79DFCBDA1D88C59600527D03 /* HasOwnPropertyCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HasOwnPropertyCache.h; sourceTree = "<group>"; };
38703876
79E423E01DEE65320078D355 /* JSWebAssemblyCallee.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSWebAssemblyCallee.cpp; path = js/JSWebAssemblyCallee.cpp; sourceTree = "<group>"; };
38713877
79E423E11DEE65320078D355 /* JSWebAssemblyCallee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWebAssemblyCallee.h; path = js/JSWebAssemblyCallee.h; sourceTree = "<group>"; };
@@ -5178,6 +5184,8 @@
51785184
0FEC84C01BDACDAC0080FF74 /* B3Common.h */,
51795185
0FEC84C11BDACDAC0080FF74 /* B3Commutativity.cpp */,
51805186
0FEC84C21BDACDAC0080FF74 /* B3Commutativity.h */,
5187+
7919B77F1E03559C005BEED8 /* B3Compile.h */,
5188+
795F099C1E03600500BBE37F /* B3Compile.cpp */,
51815189
0F338DFF1BF0276C0013C88F /* B3Compilation.cpp */,
51825190
0F338E001BF0276C0013C88F /* B3Compilation.h */,
51835191
0F86AE1F1C5311C5006BE8EC /* B3ComputeDivisionMagic.h */,
@@ -6011,6 +6019,7 @@
60116019
AD4B1DF81DF244D70071AE32 /* WasmBinding.h */,
60126020
53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */,
60136021
53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */,
6022+
79DAE2791E03C82200B526AA /* WasmExceptionType.h */,
60146023
AD2FCC321DC4045300B3E736 /* WasmFormat.cpp */,
60156024
7BC547D21B69599B00959B58 /* WasmFormat.h */,
60166025
53F40E8A1D5901BB0099A1B6 /* WasmFunctionParser.h */,
@@ -8294,6 +8303,7 @@
82948303
52B310FB1974AE610080857C /* FunctionHasExecutedCache.h in Headers */,
82958304
FE4BFF2C1AD476E700088F87 /* FunctionOverrides.h in Headers */,
82968305
BC18C4050E16F5CD00B34460 /* FunctionPrototype.h in Headers */,
8306+
7919B7801E03559C005BEED8 /* B3Compile.h in Headers */,
82978307
62D2D3901ADF103F000206C1 /* FunctionRareData.h in Headers */,
82988308
FEA0C4031CDD7D1D00481991 /* FunctionWhitelist.h in Headers */,
82998309
2AACE63D18CA5A0300ED0191 /* GCActivityCallback.h in Headers */,
@@ -8345,6 +8355,7 @@
83458355
0F0332C418B01763005F979A /* GetByIdVariant.h in Headers */,
83468356
7964656A1B952FF0003059EE /* GetPutInfo.h in Headers */,
83478357
14AD910E1DCA92940014F9FE /* GlobalCodeBlock.h in Headers */,
8358+
79DAE27A1E03C82200B526AA /* WasmExceptionType.h in Headers */,
83488359
0F24E54417EA9F5900ABB217 /* GPRInfo.h in Headers */,
83498360
142E3134134FF0A600AFADB5 /* Handle.h in Headers */,
83508361
C283190016FE4B7D00157BFD /* HandleBlock.h in Headers */,
@@ -9838,6 +9849,7 @@
98389849
0FB17662196B8F9E0091052A /* DFGPureValue.cpp in Sources */,
98399850
0F3A1BF91A9ECB7D000DE01A /* DFGPutStackSinkingPhase.cpp in Sources */,
98409851
0F2FCCFB18A60070001A27F8 /* DFGSafepoint.cpp in Sources */,
9852+
795F099D1E03600500BBE37F /* B3Compile.cpp in Sources */,
98419853
86EC9DD21328DF82002B2AD7 /* DFGSpeculativeJIT.cpp in Sources */,
98429854
86880F1F14328BB900B08D42 /* DFGSpeculativeJIT32_64.cpp in Sources */,
98439855
86880F4D14353B2100B08D42 /* DFGSpeculativeJIT64.cpp in Sources */,

Source/JavaScriptCore/b3/B3Compilation.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,23 @@
2828

2929
#if ENABLE(B3_JIT)
3030

31-
#include "B3Generate.h"
3231
#include "B3OpaqueByproducts.h"
33-
#include "B3Procedure.h"
34-
#include "B3TimingScope.h"
3532
#include "CCallHelpers.h"
36-
#include "JSCInlines.h"
37-
#include "LinkBuffer.h"
3833

3934
namespace JSC { namespace B3 {
4035

41-
Compilation::Compilation(VM& vm, Procedure& proc, unsigned optLevel)
42-
{
43-
TimingScope timingScope("Compilation");
44-
45-
prepareForGeneration(proc, optLevel);
46-
47-
CCallHelpers jit(&vm);
48-
generate(proc, jit);
49-
LinkBuffer linkBuffer(vm, jit, nullptr);
50-
51-
m_codeRef = FINALIZE_CODE(linkBuffer, ("B3::Compilation"));
52-
m_byproducts = proc.releaseByproducts();
53-
}
54-
5536
Compilation::Compilation(MacroAssemblerCodeRef codeRef, std::unique_ptr<OpaqueByproducts> byproducts)
5637
: m_codeRef(codeRef)
5738
, m_byproducts(WTFMove(byproducts))
5839
{
5940
}
6041

42+
Compilation::Compilation(Compilation&& other)
43+
: m_codeRef(WTFMove(other.m_codeRef))
44+
, m_byproducts(WTFMove(other.m_byproducts))
45+
{
46+
}
47+
6148
Compilation::~Compilation()
6249
{
6350
}

Source/JavaScriptCore/b3/B3Compilation.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,16 @@ namespace B3 {
4040
class OpaqueByproducts;
4141
class Procedure;
4242

43-
// This is a fool-proof API for compiling a Procedure to code and then running that code. You compile
44-
// a Procedure using this API by doing:
45-
//
46-
// std::unique_ptr<Compilation> compilation = std::make_unique<Compilation>(vm, proc);
47-
//
48-
// Then you keep the Compilation object alive for as long as you want to be able to run the code. If
49-
// this API feels too high-level, you can use B3::generate() directly.
43+
// This class is a way to keep the result of a B3 compilation alive
44+
// and runnable.
5045

5146
class Compilation {
5247
WTF_MAKE_NONCOPYABLE(Compilation);
5348
WTF_MAKE_FAST_ALLOCATED;
5449

5550
public:
56-
JS_EXPORT_PRIVATE Compilation(VM&, Procedure&, unsigned optLevel = 1);
57-
58-
// This constructor allows you to manually create a Compilation. It's currently only used by test
59-
// code. Probably best to keep it that way.
6051
JS_EXPORT_PRIVATE Compilation(MacroAssemblerCodeRef, std::unique_ptr<OpaqueByproducts>);
61-
52+
JS_EXPORT_PRIVATE Compilation(Compilation&&);
6253
JS_EXPORT_PRIVATE ~Compilation();
6354

6455
MacroAssemblerCodePtr code() const { return m_codeRef.code(); }

0 commit comments

Comments
 (0)