- a/Source/JavaScriptCore/ChangeLog +99 lines
Lines 1-3 a/Source/JavaScriptCore/ChangeLog_sec1
1
2021-12-15  Yusuke Suzuki  <ysuzuki@apple.com>
2
3
        Rename Wasm::CodeBlock to Wasm::CalleeGroup
4
        https://bugs.webkit.org/show_bug.cgi?id=203694
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        This is not a CodeBlock. And it is confusing name to JSC::CodeBlock.
9
        This patch renames it to Wasm::CalleeGroup.
10
11
        * CMakeLists.txt:
12
        * JavaScriptCore.xcodeproj/project.pbxproj:
13
        * Sources.txt:
14
        * heap/Heap.cpp:
15
        (JSC::Heap::Heap):
16
        (JSC::Heap::finalizeUnconditionalFinalizers):
17
        (JSC::Heap::deleteAllCodeBlocks):
18
        * heap/Heap.h:
19
        (JSC::Heap::forEachCodeBlockSpace):
20
        * runtime/VM.cpp:
21
        (JSC::VM::VM):
22
        * runtime/VM.h:
23
        * wasm/WasmBBQPlan.cpp:
24
        (JSC::Wasm::BBQPlan::BBQPlan):
25
        (JSC::Wasm::BBQPlan::work):
26
        * wasm/WasmBBQPlan.h:
27
        * wasm/WasmCalleeGroup.cpp: Renamed from Source/JavaScriptCore/wasm/WasmCodeBlock.cpp.
28
        (JSC::Wasm::CalleeGroup::create):
29
        (JSC::Wasm::CalleeGroup::createFromExisting):
30
        (JSC::Wasm::CalleeGroup::CalleeGroup):
31
        (JSC::Wasm::CalleeGroup::~CalleeGroup):
32
        (JSC::Wasm::CalleeGroup::waitUntilFinished):
33
        (JSC::Wasm::CalleeGroup::compileAsync):
34
        (JSC::Wasm::CalleeGroup::isSafeToRun):
35
        (JSC::Wasm::CalleeGroup::setCompilationFinished):
36
        * wasm/WasmCalleeGroup.h: Renamed from Source/JavaScriptCore/wasm/WasmCodeBlock.h.
37
        * wasm/WasmInstance.cpp:
38
        (JSC::Wasm::Instance::initElementSegment):
39
        * wasm/WasmInstance.h:
40
        (JSC::Wasm::Instance::calleeGroup const):
41
        (JSC::Wasm::Instance::isImportFunction const):
42
        (JSC::Wasm::Instance::codeBlock const): Deleted.
43
        * wasm/WasmMachineThreads.h:
44
        * wasm/WasmModule.cpp:
45
        (JSC::Wasm::Module::getOrCreateCalleeGroup):
46
        (JSC::Wasm::Module::compileSync):
47
        (JSC::Wasm::Module::compileAsync):
48
        (JSC::Wasm::Module::copyInitialCalleeGroupToAllMemoryModes):
49
        (JSC::Wasm::Module::getOrCreateCodeBlock): Deleted.
50
        (JSC::Wasm::Module::copyInitialCodeBlockToAllMemoryModes): Deleted.
51
        * wasm/WasmModule.h:
52
        (JSC::Wasm::Module::calleeGroupFor):
53
        (JSC::Wasm::Module::codeBlockFor): Deleted.
54
        * wasm/WasmOMGForOSREntryPlan.cpp:
55
        (JSC::Wasm::OMGForOSREntryPlan::OMGForOSREntryPlan):
56
        (JSC::Wasm::OMGForOSREntryPlan::work):
57
        * wasm/WasmOMGForOSREntryPlan.h:
58
        * wasm/WasmOMGPlan.cpp:
59
        (JSC::Wasm::OMGPlan::OMGPlan):
60
        (JSC::Wasm::OMGPlan::work):
61
        * wasm/WasmOMGPlan.h:
62
        * wasm/WasmOperations.cpp:
63
        (JSC::Wasm::triggerOMGReplacementCompile):
64
        (JSC::Wasm::JSC_DEFINE_JIT_OPERATION):
65
        * wasm/WasmPlan.cpp:
66
        (JSC::Wasm::Plan::updateCallSitesToCallUs):
67
        * wasm/WasmPlan.h:
68
        * wasm/WasmSlowPaths.cpp:
69
        (JSC::LLInt::jitCompileAndSetHeuristics):
70
        (JSC::LLInt::doWasmCall):
71
        * wasm/js/JSWebAssembly.cpp:
72
        (JSC::resolve):
73
        (JSC::instantiate):
74
        * wasm/js/JSWebAssemblyCalleeGroup.cpp: Renamed from Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.cpp.
75
        (JSC::JSWebAssemblyCalleeGroup::create):
76
        (JSC::JSWebAssemblyCalleeGroup::JSWebAssemblyCalleeGroup):
77
        (JSC::JSWebAssemblyCalleeGroup::finishCreation):
78
        (JSC::JSWebAssemblyCalleeGroup::destroy):
79
        (JSC::JSWebAssemblyCalleeGroup::clearJSCallICs):
80
        (JSC::JSWebAssemblyCalleeGroup::visitChildrenImpl):
81
        (JSC::JSWebAssemblyCalleeGroup::finalizeUnconditionally):
82
        * wasm/js/JSWebAssemblyCalleeGroup.h: Renamed from Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.h.
83
        * wasm/js/JSWebAssemblyInstance.cpp:
84
        (JSC::JSWebAssemblyInstance::visitChildrenImpl):
85
        (JSC::JSWebAssemblyInstance::finalizeCreation):
86
        * wasm/js/JSWebAssemblyInstance.h:
87
        * wasm/js/JSWebAssemblyModule.cpp:
88
        (JSC::JSWebAssemblyModule::calleeGroup):
89
        (JSC::JSWebAssemblyModule::setCalleeGroup):
90
        (JSC::JSWebAssemblyModule::visitChildrenImpl):
91
        (JSC::JSWebAssemblyModule::codeBlock): Deleted.
92
        (JSC::JSWebAssemblyModule::setCodeBlock): Deleted.
93
        * wasm/js/JSWebAssemblyModule.h:
94
        * wasm/js/WebAssemblyFunction.cpp:
95
        (JSC::JSC_DEFINE_HOST_FUNCTION):
96
        * wasm/js/WebAssemblyModuleRecord.cpp:
97
        (JSC::WebAssemblyModuleRecord::initializeImportsAndExports):
98
        * wasm/js/WebAssemblyWrapperFunction.h:
99
1
2021-12-15  Joseph Griego  <jgriego@igalia.com>
100
2021-12-15  Joseph Griego  <jgriego@igalia.com>
2
101
3
        [Shadow Realms] Wrapped functions must only throw TypeError from calling realm
102
        [Shadow Realms] Wrapped functions must only throw TypeError from calling realm
- a/Source/JavaScriptCore/CMakeLists.txt -1 / +1 lines
Lines 1236-1243 set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS a/Source/JavaScriptCore/CMakeLists.txt_sec1
1236
    tools/VMInspectorInlines.h
1236
    tools/VMInspectorInlines.h
1237
1237
1238
    wasm/WasmCallee.h
1238
    wasm/WasmCallee.h
1239
    wasm/WasmCalleeGroup.h
1239
    wasm/WasmCapabilities.h
1240
    wasm/WasmCapabilities.h
1240
    wasm/WasmCodeBlock.h
1241
    wasm/WasmCompilationMode.h
1241
    wasm/WasmCompilationMode.h
1242
    wasm/WasmContext.h
1242
    wasm/WasmContext.h
1243
    wasm/WasmEmbedder.h
1243
    wasm/WasmEmbedder.h
- a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj -16 / +16 lines
Lines 893-899 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec1
893
		52678F8F1A031009006A306D /* BasicBlockLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 52678F8D1A031009006A306D /* BasicBlockLocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
893
		52678F8F1A031009006A306D /* BasicBlockLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 52678F8D1A031009006A306D /* BasicBlockLocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
894
		52678F911A04177C006A306D /* ControlFlowProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52678F901A04177C006A306D /* ControlFlowProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
894
		52678F911A04177C006A306D /* ControlFlowProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52678F901A04177C006A306D /* ControlFlowProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
895
		5267CF82249316B10022BF6D /* FastJITPermissions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5267CF81249316AD0022BF6D /* FastJITPermissions.h */; settings = {ATTRIBUTES = (Private, ); }; };
895
		5267CF82249316B10022BF6D /* FastJITPermissions.h in Headers */ = {isa = PBXBuildFile; fileRef = 5267CF81249316AD0022BF6D /* FastJITPermissions.h */; settings = {ATTRIBUTES = (Private, ); }; };
896
		526AC4B71E977C5D003500E1 /* WasmCodeBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = 526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
896
		526AC4B71E977C5D003500E1 /* WasmCalleeGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 526AC4B51E977C5D003500E1 /* WasmCalleeGroup.h */; settings = {ATTRIBUTES = (Private, ); }; };
897
		527CE35422555FE500C6F382 /* JSToWasmICCallee.h in Headers */ = {isa = PBXBuildFile; fileRef = 527CE35322555FDD00C6F382 /* JSToWasmICCallee.h */; };
897
		527CE35422555FE500C6F382 /* JSToWasmICCallee.h in Headers */ = {isa = PBXBuildFile; fileRef = 527CE35322555FDD00C6F382 /* JSToWasmICCallee.h */; };
898
		52847ADC21FFB8690061A9DB /* WasmAirIRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 52847ADA21FFB8630061A9DB /* WasmAirIRGenerator.h */; };
898
		52847ADC21FFB8690061A9DB /* WasmAirIRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 52847ADA21FFB8630061A9DB /* WasmAirIRGenerator.h */; };
899
		52B310FB1974AE610080857C /* FunctionHasExecutedCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 52B310FA1974AE610080857C /* FunctionHasExecutedCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
899
		52B310FB1974AE610080857C /* FunctionHasExecutedCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 52B310FA1974AE610080857C /* FunctionHasExecutedCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
Lines 1665-1671 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec2
1665
		AD7B4B2E1FA3E29800C9DF79 /* WasmNameSection.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7B4B2D1FA3E28600C9DF79 /* WasmNameSection.h */; settings = {ATTRIBUTES = (Private, ); }; };
1665
		AD7B4B2E1FA3E29800C9DF79 /* WasmNameSection.h in Headers */ = {isa = PBXBuildFile; fileRef = AD7B4B2D1FA3E28600C9DF79 /* WasmNameSection.h */; settings = {ATTRIBUTES = (Private, ); }; };
1666
		AD86A93E1AA4D88D002FE77F /* WeakGCMapInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
1666
		AD86A93E1AA4D88D002FE77F /* WeakGCMapInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = AD86A93D1AA4D87C002FE77F /* WeakGCMapInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
1667
		AD8FF3981EB5BDB20087FF82 /* WasmIndexOrName.h in Headers */ = {isa = PBXBuildFile; fileRef = AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */; settings = {ATTRIBUTES = (Private, ); }; };
1667
		AD8FF3981EB5BDB20087FF82 /* WasmIndexOrName.h in Headers */ = {isa = PBXBuildFile; fileRef = AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */; settings = {ATTRIBUTES = (Private, ); }; };
1668
		AD9E852F1E8A0C7C008DE39E /* JSWebAssemblyCodeBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCodeBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
1668
		AD9E852F1E8A0C7C008DE39E /* JSWebAssemblyCalleeGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCalleeGroup.h */; settings = {ATTRIBUTES = (Private, ); }; };
1669
		ADD8FA461EB3079700DF542F /* WasmNameSectionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = ADD8FA431EB3077100DF542F /* WasmNameSectionParser.h */; };
1669
		ADD8FA461EB3079700DF542F /* WasmNameSectionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = ADD8FA431EB3077100DF542F /* WasmNameSectionParser.h */; };
1670
		ADE802991E08F1DE0058DE78 /* JSWebAssemblyLinkError.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802941E08F1C90058DE78 /* JSWebAssemblyLinkError.h */; settings = {ATTRIBUTES = (Private, ); }; };
1670
		ADE802991E08F1DE0058DE78 /* JSWebAssemblyLinkError.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802941E08F1C90058DE78 /* JSWebAssemblyLinkError.h */; settings = {ATTRIBUTES = (Private, ); }; };
1671
		ADE8029A1E08F1DE0058DE78 /* WebAssemblyLinkErrorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802951E08F1C90058DE78 /* WebAssemblyLinkErrorConstructor.h */; settings = {ATTRIBUTES = (Private, ); }; };
1671
		ADE8029A1E08F1DE0058DE78 /* WebAssemblyLinkErrorConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = ADE802951E08F1C90058DE78 /* WebAssemblyLinkErrorConstructor.h */; settings = {ATTRIBUTES = (Private, ); }; };
Lines 3694-3701 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec3
3694
		52678F8D1A031009006A306D /* BasicBlockLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicBlockLocation.h; sourceTree = "<group>"; };
3694
		52678F8D1A031009006A306D /* BasicBlockLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicBlockLocation.h; sourceTree = "<group>"; };
3695
		52678F901A04177C006A306D /* ControlFlowProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControlFlowProfiler.h; sourceTree = "<group>"; };
3695
		52678F901A04177C006A306D /* ControlFlowProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ControlFlowProfiler.h; sourceTree = "<group>"; };
3696
		5267CF81249316AD0022BF6D /* FastJITPermissions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FastJITPermissions.h; sourceTree = "<group>"; };
3696
		5267CF81249316AD0022BF6D /* FastJITPermissions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FastJITPermissions.h; sourceTree = "<group>"; };
3697
		526AC4B41E977C5D003500E1 /* WasmCodeBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmCodeBlock.cpp; sourceTree = "<group>"; };
3697
		526AC4B41E977C5D003500E1 /* WasmCalleeGroup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmCalleeGroup.cpp; sourceTree = "<group>"; };
3698
		526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmCodeBlock.h; sourceTree = "<group>"; };
3698
		526AC4B51E977C5D003500E1 /* WasmCalleeGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmCalleeGroup.h; sourceTree = "<group>"; };
3699
		5272987B235FC8BA005C982C /* GCMemoryOperations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GCMemoryOperations.h; sourceTree = "<group>"; };
3699
		5272987B235FC8BA005C982C /* GCMemoryOperations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GCMemoryOperations.h; sourceTree = "<group>"; };
3700
		527773DD1AAF83AC00BDE7E8 /* RuntimeType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeType.cpp; sourceTree = "<group>"; };
3700
		527773DD1AAF83AC00BDE7E8 /* RuntimeType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RuntimeType.cpp; sourceTree = "<group>"; };
3701
		527CE35222555FDD00C6F382 /* JSToWasmICCallee.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JSToWasmICCallee.cpp; path = js/JSToWasmICCallee.cpp; sourceTree = "<group>"; };
3701
		527CE35222555FDD00C6F382 /* JSToWasmICCallee.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JSToWasmICCallee.cpp; path = js/JSToWasmICCallee.cpp; sourceTree = "<group>"; };
Lines 3934-3940 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec4
3934
		5373B4D422ADB31400803572 /* WeakObjectRefConstructor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WeakObjectRefConstructor.cpp; sourceTree = "<group>"; };
3934
		5373B4D422ADB31400803572 /* WeakObjectRefConstructor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WeakObjectRefConstructor.cpp; sourceTree = "<group>"; };
3935
		5381B9361E60E9660090F794 /* WasmFaultSignalHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmFaultSignalHandler.cpp; sourceTree = "<group>"; };
3935
		5381B9361E60E9660090F794 /* WasmFaultSignalHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmFaultSignalHandler.cpp; sourceTree = "<group>"; };
3936
		5381B9381E60E97D0090F794 /* WasmFaultSignalHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmFaultSignalHandler.h; sourceTree = "<group>"; };
3936
		5381B9381E60E97D0090F794 /* WasmFaultSignalHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmFaultSignalHandler.h; sourceTree = "<group>"; };
3937
		5383AA2F1E65E8A100A532FC /* JSWebAssemblyCodeBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSWebAssemblyCodeBlock.cpp; path = js/JSWebAssemblyCodeBlock.cpp; sourceTree = "<group>"; };
3937
		5383AA2F1E65E8A100A532FC /* JSWebAssemblyCalleeGroup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSWebAssemblyCalleeGroup.cpp; path = js/JSWebAssemblyCalleeGroup.cpp; sourceTree = "<group>"; };
3938
		538F15DD268FBBB300D601C4 /* UnifiedSource148.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnifiedSource148.cpp; path = "DerivedSources/JavaScriptCore/unified-sources/UnifiedSource148.cpp"; sourceTree = BUILT_PRODUCTS_DIR; };
3938
		538F15DD268FBBB300D601C4 /* UnifiedSource148.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnifiedSource148.cpp; path = "DerivedSources/JavaScriptCore/unified-sources/UnifiedSource148.cpp"; sourceTree = BUILT_PRODUCTS_DIR; };
3939
		538F15DE268FBBB300D601C4 /* UnifiedSource151.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnifiedSource151.cpp; path = "DerivedSources/JavaScriptCore/unified-sources/UnifiedSource151.cpp"; sourceTree = BUILT_PRODUCTS_DIR; };
3939
		538F15DE268FBBB300D601C4 /* UnifiedSource151.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnifiedSource151.cpp; path = "DerivedSources/JavaScriptCore/unified-sources/UnifiedSource151.cpp"; sourceTree = BUILT_PRODUCTS_DIR; };
3940
		538F15DF268FBBB300D601C4 /* UnifiedSource152.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnifiedSource152.cpp; path = "DerivedSources/JavaScriptCore/unified-sources/UnifiedSource152.cpp"; sourceTree = BUILT_PRODUCTS_DIR; };
3940
		538F15DF268FBBB300D601C4 /* UnifiedSource152.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UnifiedSource152.cpp; path = "DerivedSources/JavaScriptCore/unified-sources/UnifiedSource152.cpp"; sourceTree = BUILT_PRODUCTS_DIR; };
Lines 4925-4931 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec5
4925
		AD8DD6D01F6708A30004EB52 /* JSToWasm.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JSToWasm.cpp; path = js/JSToWasm.cpp; sourceTree = "<group>"; };
4925
		AD8DD6D01F6708A30004EB52 /* JSToWasm.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = JSToWasm.cpp; path = js/JSToWasm.cpp; sourceTree = "<group>"; };
4926
		AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmIndexOrName.h; sourceTree = "<group>"; };
4926
		AD8FF3951EB5BD850087FF82 /* WasmIndexOrName.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmIndexOrName.h; sourceTree = "<group>"; };
4927
		AD8FF3961EB5BD850087FF82 /* WasmIndexOrName.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmIndexOrName.cpp; sourceTree = "<group>"; };
4927
		AD8FF3961EB5BD850087FF82 /* WasmIndexOrName.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmIndexOrName.cpp; sourceTree = "<group>"; };
4928
		AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCodeBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWebAssemblyCodeBlock.h; path = js/JSWebAssemblyCodeBlock.h; sourceTree = "<group>"; };
4928
		AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCalleeGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSWebAssemblyCalleeGroup.h; path = js/JSWebAssemblyCalleeGroup.h; sourceTree = "<group>"; };
4929
		ADB6F67C1E15D7500082F384 /* WasmPageCount.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmPageCount.cpp; sourceTree = "<group>"; };
4929
		ADB6F67C1E15D7500082F384 /* WasmPageCount.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmPageCount.cpp; sourceTree = "<group>"; };
4930
		ADD09AEE1F5F623F001313C2 /* WasmToJS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WasmToJS.h; path = js/WasmToJS.h; sourceTree = "<group>"; };
4930
		ADD09AEE1F5F623F001313C2 /* WasmToJS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WasmToJS.h; path = js/WasmToJS.h; sourceTree = "<group>"; };
4931
		ADD09AEF1F5F623F001313C2 /* WasmToJS.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = WasmToJS.cpp; path = js/WasmToJS.cpp; sourceTree = "<group>"; };
4931
		ADD09AEF1F5F623F001313C2 /* WasmToJS.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = WasmToJS.cpp; path = js/WasmToJS.cpp; sourceTree = "<group>"; };
Lines 7199-7211 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec6
7199
				AD4B1DF81DF244D70071AE32 /* WasmBinding.h */,
7199
				AD4B1DF81DF244D70071AE32 /* WasmBinding.h */,
7200
				525C0DD71E935847002184CD /* WasmCallee.cpp */,
7200
				525C0DD71E935847002184CD /* WasmCallee.cpp */,
7201
				525C0DD81E935847002184CD /* WasmCallee.h */,
7201
				525C0DD81E935847002184CD /* WasmCallee.h */,
7202
				526AC4B41E977C5D003500E1 /* WasmCalleeGroup.cpp */,
7203
				526AC4B51E977C5D003500E1 /* WasmCalleeGroup.h */,
7202
				E3FB853922F36674008F90ED /* WasmCalleeRegistry.cpp */,
7204
				E3FB853922F36674008F90ED /* WasmCalleeRegistry.cpp */,
7203
				E3FB853822F36674008F90ED /* WasmCalleeRegistry.h */,
7205
				E3FB853822F36674008F90ED /* WasmCalleeRegistry.h */,
7204
				53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */,
7206
				53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */,
7205
				53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */,
7207
				53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */,
7206
				E337B966224324E50093A820 /* WasmCapabilities.h */,
7208
				E337B966224324E50093A820 /* WasmCapabilities.h */,
7207
				526AC4B41E977C5D003500E1 /* WasmCodeBlock.cpp */,
7208
				526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */,
7209
				E37CFB2D22F27C57009A7B38 /* WasmCompilationMode.cpp */,
7209
				E37CFB2D22F27C57009A7B38 /* WasmCompilationMode.cpp */,
7210
				E3BD2B7522F275020011765C /* WasmCompilationMode.h */,
7210
				E3BD2B7522F275020011765C /* WasmCompilationMode.h */,
7211
				E3915C062309682900CB2561 /* WasmContext.cpp */,
7211
				E3915C062309682900CB2561 /* WasmContext.cpp */,
Lines 9186-9193 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec7
9186
				527CE35322555FDD00C6F382 /* JSToWasmICCallee.h */,
9186
				527CE35322555FDD00C6F382 /* JSToWasmICCallee.h */,
9187
				ADD09AF21F624829001313C2 /* JSWebAssembly.cpp */,
9187
				ADD09AF21F624829001313C2 /* JSWebAssembly.cpp */,
9188
				ADD09AF31F62482E001313C2 /* JSWebAssembly.h */,
9188
				ADD09AF31F62482E001313C2 /* JSWebAssembly.h */,
9189
				5383AA2F1E65E8A100A532FC /* JSWebAssemblyCodeBlock.cpp */,
9189
				5383AA2F1E65E8A100A532FC /* JSWebAssemblyCalleeGroup.cpp */,
9190
				AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCodeBlock.h */,
9190
				AD9E852E1E8A0C6E008DE39E /* JSWebAssemblyCalleeGroup.h */,
9191
				AD2FCBA61DB58DA400B3E736 /* JSWebAssemblyCompileError.cpp */,
9191
				AD2FCBA61DB58DA400B3E736 /* JSWebAssemblyCompileError.cpp */,
9192
				AD2FCBA71DB58DA400B3E736 /* JSWebAssemblyCompileError.h */,
9192
				AD2FCBA71DB58DA400B3E736 /* JSWebAssemblyCompileError.h */,
9193
				14D01BDC26DEEF3700CAE0D0 /* JSWebAssemblyException.cpp */,
9193
				14D01BDC26DEEF3700CAE0D0 /* JSWebAssemblyException.cpp */,
Lines 9542-9547 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec8
9542
				0F725CA81C503DED00AD943A /* B3EliminateCommonSubexpressions.h in Headers */,
9542
				0F725CA81C503DED00AD943A /* B3EliminateCommonSubexpressions.h in Headers */,
9543
				3395C70722555F6D00BDBFAD /* B3EliminateDeadCode.h in Headers */,
9543
				3395C70722555F6D00BDBFAD /* B3EliminateDeadCode.h in Headers */,
9544
				0F5BF1711F23A5A10029D91D /* B3EnsureLoopPreHeaders.h in Headers */,
9544
				0F5BF1711F23A5A10029D91D /* B3EnsureLoopPreHeaders.h in Headers */,
9545
				52E65A1E27682771002B4C0A /* B3EstimateStaticExecutionCounts.h in Headers */,
9545
				5318045C22EAAC4B004A7342 /* B3ExtractValue.h in Headers */,
9546
				5318045C22EAAC4B004A7342 /* B3ExtractValue.h in Headers */,
9546
				0F6971EA1D92F42400BA02A5 /* B3FenceValue.h in Headers */,
9547
				0F6971EA1D92F42400BA02A5 /* B3FenceValue.h in Headers */,
9547
				0F6B8AE51C4EFE1700969052 /* B3FixSSA.h in Headers */,
9548
				0F6B8AE51C4EFE1700969052 /* B3FixSSA.h in Headers */,
Lines 9918-9924 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec9
9918
				0FFB921D16D02F300055A5DB /* DFGSlowPathGenerator.h in Headers */,
9919
				0FFB921D16D02F300055A5DB /* DFGSlowPathGenerator.h in Headers */,
9919
				E322E5A31DA64439006E7709 /* DFGSnippetParams.h in Headers */,
9920
				E322E5A31DA64439006E7709 /* DFGSnippetParams.h in Headers */,
9920
				86EC9DD31328DF82002B2AD7 /* DFGSpeculativeJIT.h in Headers */,
9921
				86EC9DD31328DF82002B2AD7 /* DFGSpeculativeJIT.h in Headers */,
9921
				52E65A1E27682771002B4C0A /* B3EstimateStaticExecutionCounts.h in Headers */,
9922
				0F682FB319BCB36400FA3BAD /* DFGSSACalculator.h in Headers */,
9922
				0F682FB319BCB36400FA3BAD /* DFGSSACalculator.h in Headers */,
9923
				A7D89D0017A0B8CC00773AD8 /* DFGSSAConversionPhase.h in Headers */,
9923
				A7D89D0017A0B8CC00773AD8 /* DFGSSAConversionPhase.h in Headers */,
9924
				0FC20CBA18556A3500C9E954 /* DFGSSALoweringPhase.h in Headers */,
9924
				0FC20CBA18556A3500C9E954 /* DFGSSALoweringPhase.h in Headers */,
Lines 10158-10163 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec10
10158
				A5398FAB1C750DA40060A963 /* HeapProfiler.h in Headers */,
10158
				A5398FAB1C750DA40060A963 /* HeapProfiler.h in Headers */,
10159
				A54C2AB11C6544F200A18D78 /* HeapSnapshot.h in Headers */,
10159
				A54C2AB11C6544F200A18D78 /* HeapSnapshot.h in Headers */,
10160
				A5311C361C77CEC500E6B1B6 /* HeapSnapshotBuilder.h in Headers */,
10160
				A5311C361C77CEC500E6B1B6 /* HeapSnapshotBuilder.h in Headers */,
10161
				FE2CC9302756B2B9003F5AB8 /* HeapSubspaceTypes.h in Headers */,
10161
				0FADE6731D4D23BE00768457 /* HeapUtil.h in Headers */,
10162
				0FADE6731D4D23BE00768457 /* HeapUtil.h in Headers */,
10162
				FE1BD0251E72053800134BC9 /* HeapVerifier.h in Headers */,
10163
				FE1BD0251E72053800134BC9 /* HeapVerifier.h in Headers */,
10163
				DC2143071CA32E55000A8869 /* ICStats.h in Headers */,
10164
				DC2143071CA32E55000A8869 /* ICStats.h in Headers */,
Lines 10274-10279 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec11
10274
				0FB467811FDDA6F7003FCB09 /* IsoCellSetInlines.h in Headers */,
10275
				0FB467811FDDA6F7003FCB09 /* IsoCellSetInlines.h in Headers */,
10275
				E3BF1BAE238AAEDB003A1C2B /* IsoHeapCellType.h in Headers */,
10276
				E3BF1BAE238AAEDB003A1C2B /* IsoHeapCellType.h in Headers */,
10276
				E3C8ED4323A1DBCB00131958 /* IsoInlinedHeapCellType.h in Headers */,
10277
				E3C8ED4323A1DBCB00131958 /* IsoInlinedHeapCellType.h in Headers */,
10278
				FE65B1512748601F00DB5B16 /* IsoInlinedHeapCellTypeInlines.h in Headers */,
10277
				0FDCE12D1FAFB4E5006F3901 /* IsoSubspace.h in Headers */,
10279
				0FDCE12D1FAFB4E5006F3901 /* IsoSubspace.h in Headers */,
10278
				0FD2FD9520B52BE200F09441 /* IsoSubspaceInlines.h in Headers */,
10280
				0FD2FD9520B52BE200F09441 /* IsoSubspaceInlines.h in Headers */,
10279
				0F5E0FE72086AD480097F0DE /* IsoSubspacePerVM.h in Headers */,
10281
				0F5E0FE72086AD480097F0DE /* IsoSubspacePerVM.h in Headers */,
Lines 10422-10428 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec12
10422
				E33F50811B8429A400413856 /* JSInternalPromise.h in Headers */,
10424
				E33F50811B8429A400413856 /* JSInternalPromise.h in Headers */,
10423
				E33F50791B84225700413856 /* JSInternalPromiseConstructor.h in Headers */,
10425
				E33F50791B84225700413856 /* JSInternalPromiseConstructor.h in Headers */,
10424
				E33F50871B8449EF00413856 /* JSInternalPromiseConstructor.lut.h in Headers */,
10426
				E33F50871B8449EF00413856 /* JSInternalPromiseConstructor.lut.h in Headers */,
10425
				FE65B1512748601F00DB5B16 /* IsoInlinedHeapCellTypeInlines.h in Headers */,
10426
				E33F50751B8421C000413856 /* JSInternalPromisePrototype.h in Headers */,
10427
				E33F50751B8421C000413856 /* JSInternalPromisePrototype.h in Headers */,
10427
				A503FA1E188E0FB000110F14 /* JSJavaScriptCallFramePrototype.h in Headers */,
10428
				A503FA1E188E0FB000110F14 /* JSJavaScriptCallFramePrototype.h in Headers */,
10428
				BC18C4160E16F5CD00B34460 /* JSLexicalEnvironment.h in Headers */,
10429
				BC18C4160E16F5CD00B34460 /* JSLexicalEnvironment.h in Headers */,
Lines 10511-10517 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec13
10511
				709FB8681AE335C60039D069 /* JSWeakSet.h in Headers */,
10512
				709FB8681AE335C60039D069 /* JSWeakSet.h in Headers */,
10512
				7A9774A8206B82E4008D03D0 /* JSWeakValue.h in Headers */,
10513
				7A9774A8206B82E4008D03D0 /* JSWeakValue.h in Headers */,
10513
				AD5C36EB1F75AD73000BCAAF /* JSWebAssembly.h in Headers */,
10514
				AD5C36EB1F75AD73000BCAAF /* JSWebAssembly.h in Headers */,
10514
				AD9E852F1E8A0C7C008DE39E /* JSWebAssemblyCodeBlock.h in Headers */,
10515
				AD9E852F1E8A0C7C008DE39E /* JSWebAssemblyCalleeGroup.h in Headers */,
10515
				AD2FCBE31DB58DAD00B3E736 /* JSWebAssemblyCompileError.h in Headers */,
10516
				AD2FCBE31DB58DAD00B3E736 /* JSWebAssemblyCompileError.h in Headers */,
10516
				14D01BED26DEEF3800CAE0D0 /* JSWebAssemblyException.h in Headers */,
10517
				14D01BED26DEEF3800CAE0D0 /* JSWebAssemblyException.h in Headers */,
10517
				E3BF3C4D2390D1E8008BC752 /* JSWebAssemblyGlobal.h in Headers */,
10518
				E3BF3C4D2390D1E8008BC752 /* JSWebAssemblyGlobal.h in Headers */,
Lines 10945-10956 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec14
10945
				53CA730A1EA533D80076049D /* WasmBBQPlan.h in Headers */,
10946
				53CA730A1EA533D80076049D /* WasmBBQPlan.h in Headers */,
10946
				AD4B1DFA1DF244E20071AE32 /* WasmBinding.h in Headers */,
10947
				AD4B1DFA1DF244E20071AE32 /* WasmBinding.h in Headers */,
10947
				525C0DDA1E935847002184CD /* WasmCallee.h in Headers */,
10948
				525C0DDA1E935847002184CD /* WasmCallee.h in Headers */,
10949
				526AC4B71E977C5D003500E1 /* WasmCalleeGroup.h in Headers */,
10948
				E3FB853A22F3667B008F90ED /* WasmCalleeRegistry.h in Headers */,
10950
				E3FB853A22F3667B008F90ED /* WasmCalleeRegistry.h in Headers */,
10949
				53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */,
10951
				53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */,
10950
				E337B967224324EA0093A820 /* WasmCapabilities.h in Headers */,
10952
				E337B967224324EA0093A820 /* WasmCapabilities.h in Headers */,
10951
				526AC4B71E977C5D003500E1 /* WasmCodeBlock.h in Headers */,
10952
				E3BD2B7622F275020011765C /* WasmCompilationMode.h in Headers */,
10953
				E3BD2B7622F275020011765C /* WasmCompilationMode.h in Headers */,
10953
				FE2CC9302756B2B9003F5AB8 /* HeapSubspaceTypes.h in Headers */,
10954
				AD412B341E7B2E9E008AF157 /* WasmContext.h in Headers */,
10954
				AD412B341E7B2E9E008AF157 /* WasmContext.h in Headers */,
10955
				7593C898BE714A64BE93A6E7 /* WasmContextInlines.h in Headers */,
10955
				7593C898BE714A64BE93A6E7 /* WasmContextInlines.h in Headers */,
10956
				E36CC9472086314F0051FFD6 /* WasmCreationMode.h in Headers */,
10956
				E36CC9472086314F0051FFD6 /* WasmCreationMode.h in Headers */,
Lines 11786-11796 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec15
11786
			buildActionMask = 2147483647;
11786
			buildActionMask = 2147483647;
11787
			files = (
11787
			files = (
11788
				E392E6F824D25FA600B20767 /* B3BottomTupleValue.cpp in Sources */,
11788
				E392E6F824D25FA600B20767 /* B3BottomTupleValue.cpp in Sources */,
11789
				52E65A1C27682760002B4C0A /* B3EstimateStaticExecutionCounts.cpp in Sources */,
11789
				0FEC85AF1BDB5D5E0080FF74 /* testb3_1.cpp in Sources */,
11790
				0FEC85AF1BDB5D5E0080FF74 /* testb3_1.cpp in Sources */,
11790
				5C3A77BA22F2480F003827FF /* testb3_2.cpp in Sources */,
11791
				5C3A77BA22F2480F003827FF /* testb3_2.cpp in Sources */,
11791
				5C3A77B922F2480B003827FF /* testb3_3.cpp in Sources */,
11792
				5C3A77B922F2480B003827FF /* testb3_3.cpp in Sources */,
11792
				5C3A77B822F24809003827FF /* testb3_4.cpp in Sources */,
11793
				5C3A77B822F24809003827FF /* testb3_4.cpp in Sources */,
11793
				52E65A1C27682760002B4C0A /* B3EstimateStaticExecutionCounts.cpp in Sources */,
11794
				5C3A77B722F24806003827FF /* testb3_5.cpp in Sources */,
11794
				5C3A77B722F24806003827FF /* testb3_5.cpp in Sources */,
11795
				5C3A77B622F24803003827FF /* testb3_6.cpp in Sources */,
11795
				5C3A77B622F24803003827FF /* testb3_6.cpp in Sources */,
11796
				5C3A77B522F24800003827FF /* testb3_7.cpp in Sources */,
11796
				5C3A77B522F24800003827FF /* testb3_7.cpp in Sources */,
- a/Source/JavaScriptCore/Sources.txt -2 / +2 lines
Lines 1073-1081 wasm/WasmB3IRGenerator.cpp a/Source/JavaScriptCore/Sources.txt_sec1
1073
wasm/WasmBBQPlan.cpp
1073
wasm/WasmBBQPlan.cpp
1074
wasm/WasmBinding.cpp
1074
wasm/WasmBinding.cpp
1075
wasm/WasmCallee.cpp
1075
wasm/WasmCallee.cpp
1076
wasm/WasmCalleeGroup.cpp
1076
wasm/WasmCalleeRegistry.cpp
1077
wasm/WasmCalleeRegistry.cpp
1077
wasm/WasmCallingConvention.cpp
1078
wasm/WasmCallingConvention.cpp
1078
wasm/WasmCodeBlock.cpp
1079
wasm/WasmCompilationMode.cpp
1079
wasm/WasmCompilationMode.cpp
1080
wasm/WasmContext.cpp
1080
wasm/WasmContext.cpp
1081
wasm/WasmEmbedder.h
1081
wasm/WasmEmbedder.h
Lines 1121-1127 wasm/js/JSToWasm.cpp a/Source/JavaScriptCore/Sources.txt_sec2
1121
wasm/js/JSToWasm.h
1121
wasm/js/JSToWasm.h
1122
wasm/js/JSToWasmICCallee.cpp
1122
wasm/js/JSToWasmICCallee.cpp
1123
wasm/js/JSWebAssembly.cpp
1123
wasm/js/JSWebAssembly.cpp
1124
wasm/js/JSWebAssemblyCodeBlock.cpp
1124
wasm/js/JSWebAssemblyCalleeGroup.cpp
1125
wasm/js/JSWebAssemblyCompileError.cpp
1125
wasm/js/JSWebAssemblyCompileError.cpp
1126
wasm/js/JSWebAssemblyException.cpp
1126
wasm/js/JSWebAssemblyException.cpp
1127
wasm/js/JSWebAssemblyGlobal.cpp
1127
wasm/js/JSWebAssemblyGlobal.cpp
- a/Source/JavaScriptCore/heap/Heap.cpp -9 / +8 lines
Lines 55-61 a/Source/JavaScriptCore/heap/Heap.cpp_sec1
55
#include "JSWeakMap.h"
55
#include "JSWeakMap.h"
56
#include "JSWeakObjectRef.h"
56
#include "JSWeakObjectRef.h"
57
#include "JSWeakSet.h"
57
#include "JSWeakSet.h"
58
#include "JSWebAssemblyCodeBlock.h"
58
#include "JSWebAssemblyCalleeGroup.h"
59
#include "MachineStackMarker.h"
59
#include "MachineStackMarker.h"
60
#include "MarkStackMergingConstraint.h"
60
#include "MarkStackMergingConstraint.h"
61
#include "MarkedJSValueRefArray.h"
61
#include "MarkedJSValueRefArray.h"
Lines 335-341 Heap::Heap(VM& vm, HeapType heapType) a/Source/JavaScriptCore/heap/Heap.cpp_sec2
335
    , intlSegmenterHeapCellType(IsoHeapCellType::Args<IntlSegmenter>())
335
    , intlSegmenterHeapCellType(IsoHeapCellType::Args<IntlSegmenter>())
336
    , intlSegmentsHeapCellType(IsoHeapCellType::Args<IntlSegments>())
336
    , intlSegmentsHeapCellType(IsoHeapCellType::Args<IntlSegments>())
337
#if ENABLE(WEBASSEMBLY)
337
#if ENABLE(WEBASSEMBLY)
338
    , webAssemblyCodeBlockHeapCellType(IsoHeapCellType::Args<JSWebAssemblyCodeBlock>())
338
    , webAssemblyCalleeGroupHeapCellType(IsoHeapCellType::Args<JSWebAssemblyCalleeGroup>())
339
    , webAssemblyExceptionHeapCellType(IsoHeapCellType::Args<JSWebAssemblyException>())
339
    , webAssemblyExceptionHeapCellType(IsoHeapCellType::Args<JSWebAssemblyException>())
340
    , webAssemblyFunctionHeapCellType(IsoHeapCellType::Args<WebAssemblyFunction>())
340
    , webAssemblyFunctionHeapCellType(IsoHeapCellType::Args<WebAssemblyFunction>())
341
    , webAssemblyGlobalHeapCellType(IsoHeapCellType::Args<JSWebAssemblyGlobal>())
341
    , webAssemblyGlobalHeapCellType(IsoHeapCellType::Args<JSWebAssemblyGlobal>())
Lines 714-721 void Heap::finalizeUnconditionalFinalizers() a/Source/JavaScriptCore/heap/Heap.cpp_sec3
714
        finalizeMarkedUnconditionalFinalizers<JSFinalizationRegistry>(*m_finalizationRegistrySpace);
714
        finalizeMarkedUnconditionalFinalizers<JSFinalizationRegistry>(*m_finalizationRegistrySpace);
715
715
716
#if ENABLE(WEBASSEMBLY)
716
#if ENABLE(WEBASSEMBLY)
717
    if (m_webAssemblyCodeBlockSpace)
717
    if (m_webAssemblyCalleeGroupSpace)
718
        finalizeMarkedUnconditionalFinalizers<JSWebAssemblyCodeBlock>(*m_webAssemblyCodeBlockSpace);
718
        finalizeMarkedUnconditionalFinalizers<JSWebAssemblyCalleeGroup>(*m_webAssemblyCalleeGroupSpace);
719
#endif
719
#endif
720
}
720
}
721
721
Lines 1036-1046 void Heap::deleteAllCodeBlocks(DeleteAllCodeEffort effort) a/Source/JavaScriptCore/heap/Heap.cpp_sec4
1036
        // points into a CodeBlock that could be dead. The IC will still succeed because
1036
        // points into a CodeBlock that could be dead. The IC will still succeed because
1037
        // it uses a callee check, but then it will call into dead code.
1037
        // it uses a callee check, but then it will call into dead code.
1038
        HeapIterationScope heapIterationScope(*this);
1038
        HeapIterationScope heapIterationScope(*this);
1039
        if (m_webAssemblyCodeBlockSpace) {
1039
        if (m_webAssemblyCalleeGroupSpace) {
1040
            m_webAssemblyCodeBlockSpace->forEachLiveCell([&] (HeapCell* cell, HeapCell::Kind kind) {
1040
            m_webAssemblyCalleeGroupSpace->forEachLiveCell([&] (HeapCell* cell, HeapCell::Kind kind) {
1041
                ASSERT_UNUSED(kind, kind == HeapCell::JSCell);
1041
                ASSERT_UNUSED(kind, kind == HeapCell::JSCell);
1042
                JSWebAssemblyCodeBlock* codeBlock = static_cast<JSWebAssemblyCodeBlock*>(cell);
1042
                static_cast<JSWebAssemblyCalleeGroup*>(cell)->clearJSCallICs(vm);
1043
                codeBlock->clearJSCallICs(vm);
1044
            });
1043
            });
1045
        }
1044
        }
1046
    }
1045
    }
Lines 3275-3281 DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlSegmenterSpace, intlSegmenterHeapCel a/Source/JavaScriptCore/heap/Heap.cpp_sec5
3275
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlSegmentsSpace, intlSegmentsHeapCellType, IntlSegments)
3274
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(intlSegmentsSpace, intlSegmentsHeapCellType, IntlSegments)
3276
#if ENABLE(WEBASSEMBLY)
3275
#if ENABLE(WEBASSEMBLY)
3277
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(jsToWasmICCalleeSpace, cellHeapCellType, JSToWasmICCallee)
3276
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(jsToWasmICCalleeSpace, cellHeapCellType, JSToWasmICCallee)
3278
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyCodeBlockSpace, webAssemblyCodeBlockHeapCellType, JSWebAssemblyCodeBlock) // Hash:0x9ad995cd
3277
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyCalleeGroupSpace, webAssemblyCalleeGroupHeapCellType, JSWebAssemblyCalleeGroup) // Hash:0x9ad995cd
3279
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyExceptionSpace, webAssemblyExceptionHeapCellType, JSWebAssemblyException)
3278
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyExceptionSpace, webAssemblyExceptionHeapCellType, JSWebAssemblyException)
3280
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyFunctionSpace, webAssemblyFunctionHeapCellType, WebAssemblyFunction) // Hash:0x8b7c32db
3279
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyFunctionSpace, webAssemblyFunctionHeapCellType, WebAssemblyFunction) // Hash:0x8b7c32db
3281
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyGlobalSpace, webAssemblyGlobalHeapCellType, JSWebAssemblyGlobal)
3280
DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER_SLOW(webAssemblyGlobalSpace, webAssemblyGlobalHeapCellType, JSWebAssemblyGlobal)
- a/Source/JavaScriptCore/heap/Heap.h -4 / +2 lines
Lines 785-791 class Heap { a/Source/JavaScriptCore/heap/Heap.h_sec1
785
    IsoHeapCellType intlSegmenterHeapCellType;
785
    IsoHeapCellType intlSegmenterHeapCellType;
786
    IsoHeapCellType intlSegmentsHeapCellType;
786
    IsoHeapCellType intlSegmentsHeapCellType;
787
#if ENABLE(WEBASSEMBLY)
787
#if ENABLE(WEBASSEMBLY)
788
    IsoHeapCellType webAssemblyCodeBlockHeapCellType;
788
    IsoHeapCellType webAssemblyCalleeGroupHeapCellType;
789
    IsoHeapCellType webAssemblyExceptionHeapCellType;
789
    IsoHeapCellType webAssemblyExceptionHeapCellType;
790
    IsoHeapCellType webAssemblyFunctionHeapCellType;
790
    IsoHeapCellType webAssemblyFunctionHeapCellType;
791
    IsoHeapCellType webAssemblyGlobalHeapCellType;
791
    IsoHeapCellType webAssemblyGlobalHeapCellType;
Lines 967-973 class Heap { a/Source/JavaScriptCore/heap/Heap.h_sec2
967
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlSegmentsSpace)
967
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlSegmentsSpace)
968
#if ENABLE(WEBASSEMBLY)
968
#if ENABLE(WEBASSEMBLY)
969
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(jsToWasmICCalleeSpace)
969
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(jsToWasmICCalleeSpace)
970
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyCodeBlockSpace)
970
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyCalleeGroupSpace)
971
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyExceptionSpace)
971
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyExceptionSpace)
972
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyFunctionSpace)
972
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyFunctionSpace)
973
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyGlobalSpace)
973
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyGlobalSpace)
Lines 1025-1032 class Heap { a/Source/JavaScriptCore/heap/Heap.h_sec3
1025
    template<typename Func>
1025
    template<typename Func>
1026
    void forEachCodeBlockSpace(const Func& func)
1026
    void forEachCodeBlockSpace(const Func& func)
1027
    {
1027
    {
1028
        // This should not include webAssemblyCodeBlockSpace because this is about subsclasses of
1029
        // JSC::CodeBlock.
1030
        func(codeBlockSpace);
1028
        func(codeBlockSpace);
1031
    }
1029
    }
1032
1030
- a/Source/JavaScriptCore/runtime/VM.cpp -2 / +2 lines
Lines 77-83 a/Source/JavaScriptCore/runtime/VM.cpp_sec1
77
#include "JSSet.h"
77
#include "JSSet.h"
78
#include "JSSourceCode.h"
78
#include "JSSourceCode.h"
79
#include "JSTemplateObjectDescriptor.h"
79
#include "JSTemplateObjectDescriptor.h"
80
#include "JSWebAssemblyCodeBlock.h"
80
#include "JSWebAssemblyCalleeGroup.h"
81
#include "LLIntData.h"
81
#include "LLIntData.h"
82
#include "LLIntExceptions.h"
82
#include "LLIntExceptions.h"
83
#include "MarkedBlockInlines.h"
83
#include "MarkedBlockInlines.h"
Lines 271-277 VM::VM(VMType vmType, HeapType heapType, WTF::RunLoop* runLoop, bool* success) a/Source/JavaScriptCore/runtime/VM.cpp_sec2
271
    programExecutableStructure.set(*this, ProgramExecutable::createStructure(*this, nullptr, jsNull()));
271
    programExecutableStructure.set(*this, ProgramExecutable::createStructure(*this, nullptr, jsNull()));
272
    functionExecutableStructure.set(*this, FunctionExecutable::createStructure(*this, nullptr, jsNull()));
272
    functionExecutableStructure.set(*this, FunctionExecutable::createStructure(*this, nullptr, jsNull()));
273
#if ENABLE(WEBASSEMBLY)
273
#if ENABLE(WEBASSEMBLY)
274
    webAssemblyCodeBlockStructure.set(*this, JSWebAssemblyCodeBlock::createStructure(*this, nullptr, jsNull()));
274
    webAssemblyCalleeGroupStructure.set(*this, JSWebAssemblyCalleeGroup::createStructure(*this, nullptr, jsNull()));
275
#endif
275
#endif
276
    moduleProgramExecutableStructure.set(*this, ModuleProgramExecutable::createStructure(*this, nullptr, jsNull()));
276
    moduleProgramExecutableStructure.set(*this, ModuleProgramExecutable::createStructure(*this, nullptr, jsNull()));
277
    regExpStructure.set(*this, RegExp::createStructure(*this, nullptr, jsNull()));
277
    regExpStructure.set(*this, RegExp::createStructure(*this, nullptr, jsNull()));
- a/Source/JavaScriptCore/runtime/VM.h -2 / +2 lines
Lines 476-482 class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> { a/Source/JavaScriptCore/runtime/VM.h_sec1
476
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlSegmentsSpace)
476
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(intlSegmentsSpace)
477
#if ENABLE(WEBASSEMBLY)
477
#if ENABLE(WEBASSEMBLY)
478
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(jsToWasmICCalleeSpace)
478
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(jsToWasmICCalleeSpace)
479
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyCodeBlockSpace)
479
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyCalleeGroupSpace)
480
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyExceptionSpace)
480
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyExceptionSpace)
481
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyFunctionSpace)
481
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyFunctionSpace)
482
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyGlobalSpace)
482
    DYNAMIC_ISO_SUBSPACE_DEFINE_MEMBER(webAssemblyGlobalSpace)
Lines 533-539 class VM : public ThreadSafeRefCounted<VM>, public DoublyLinkedListNode<VM> { a/Source/JavaScriptCore/runtime/VM.h_sec2
533
    Strong<Structure> programExecutableStructure;
533
    Strong<Structure> programExecutableStructure;
534
    Strong<Structure> functionExecutableStructure;
534
    Strong<Structure> functionExecutableStructure;
535
#if ENABLE(WEBASSEMBLY)
535
#if ENABLE(WEBASSEMBLY)
536
    Strong<Structure> webAssemblyCodeBlockStructure;
536
    Strong<Structure> webAssemblyCalleeGroupStructure;
537
#endif
537
#endif
538
    Strong<Structure> moduleProgramExecutableStructure;
538
    Strong<Structure> moduleProgramExecutableStructure;
539
    Strong<Structure> regExpStructure;
539
    Strong<Structure> regExpStructure;
- a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp -12 / +12 lines
Lines 34-41 a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp_sec1
34
#include "WasmAirIRGenerator.h"
34
#include "WasmAirIRGenerator.h"
35
#include "WasmB3IRGenerator.h"
35
#include "WasmB3IRGenerator.h"
36
#include "WasmCallee.h"
36
#include "WasmCallee.h"
37
#include "WasmCalleeGroup.h"
37
#include "WasmCalleeRegistry.h"
38
#include "WasmCalleeRegistry.h"
38
#include "WasmCodeBlock.h"
39
#include "WasmSignatureInlines.h"
39
#include "WasmSignatureInlines.h"
40
#include "WasmTierUpCount.h"
40
#include "WasmTierUpCount.h"
41
#include <wtf/DataLog.h>
41
#include <wtf/DataLog.h>
Lines 48-60 namespace WasmBBQPlanInternal { a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp_sec2
48
static constexpr bool verbose = false;
48
static constexpr bool verbose = false;
49
}
49
}
50
50
51
BBQPlan::BBQPlan(Context* context, Ref<ModuleInformation> moduleInformation, uint32_t functionIndex, CodeBlock* codeBlock, CompletionTask&& completionTask)
51
BBQPlan::BBQPlan(Context* context, Ref<ModuleInformation> moduleInformation, uint32_t functionIndex, CalleeGroup* calleeGroup, CompletionTask&& completionTask)
52
    : EntryPlan(context, WTFMove(moduleInformation), CompilerMode::FullCompile, WTFMove(completionTask))
52
    : EntryPlan(context, WTFMove(moduleInformation), CompilerMode::FullCompile, WTFMove(completionTask))
53
    , m_codeBlock(codeBlock)
53
    , m_calleeGroup(calleeGroup)
54
    , m_functionIndex(functionIndex)
54
    , m_functionIndex(functionIndex)
55
{
55
{
56
    ASSERT(Options::useBBQJIT());
56
    ASSERT(Options::useBBQJIT());
57
    setMode(m_codeBlock->mode());
57
    setMode(m_calleeGroup->mode());
58
    dataLogLnIf(WasmBBQPlanInternal::verbose, "Starting BBQ plan for ", functionIndex);
58
    dataLogLnIf(WasmBBQPlanInternal::verbose, "Starting BBQ plan for ", functionIndex);
59
}
59
}
60
60
Lines 76-82 bool BBQPlan::prepareImpl() a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp_sec3
76
76
77
void BBQPlan::work(CompilationEffort effort)
77
void BBQPlan::work(CompilationEffort effort)
78
{
78
{
79
    if (!m_codeBlock) {
79
    if (!m_calleeGroup) {
80
        switch (m_state) {
80
        switch (m_state) {
81
        case State::Initial:
81
        case State::Initial:
82
            parseAndValidateModule();
82
            parseAndValidateModule();
Lines 127-133 void BBQPlan::work(CompilationEffort effort) a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp_sec4
127
    {
127
    {
128
        Ref<BBQCallee> callee = BBQCallee::create(WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), WTFMove(tierUp), WTFMove(unlinkedWasmToWasmCalls), WTFMove(function->stackmaps), WTFMove(function->exceptionHandlers), WTFMove(exceptionHandlerLocations));
128
        Ref<BBQCallee> callee = BBQCallee::create(WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), WTFMove(tierUp), WTFMove(unlinkedWasmToWasmCalls), WTFMove(function->stackmaps), WTFMove(function->exceptionHandlers), WTFMove(exceptionHandlerLocations));
129
        MacroAssembler::repatchPointer(function->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
129
        MacroAssembler::repatchPointer(function->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
130
        ASSERT(!m_codeBlock->m_bbqCallees[m_functionIndex]);
130
        ASSERT(!m_calleeGroup->m_bbqCallees[m_functionIndex]);
131
        entrypoint = callee->entrypoint();
131
        entrypoint = callee->entrypoint();
132
132
133
        if (context.pcToCodeOriginMap)
133
        if (context.pcToCodeOriginMap)
Lines 137-160 void BBQPlan::work(CompilationEffort effort) a/Source/JavaScriptCore/wasm/WasmBBQPlan.cpp_sec5
137
        // always call the fastest code. Any function linked after us will see our new code and the new callsites, which they
137
        // always call the fastest code. Any function linked after us will see our new code and the new callsites, which they
138
        // will update. It's also ok if they publish their code before we reset the instruction caches because after we release
138
        // will update. It's also ok if they publish their code before we reset the instruction caches because after we release
139
        // the lock our code is ready to be published too.
139
        // the lock our code is ready to be published too.
140
        Locker locker { m_codeBlock->m_lock };
140
        Locker locker { m_calleeGroup->m_lock };
141
141
142
        m_codeBlock->m_bbqCallees[m_functionIndex] = callee.copyRef();
142
        m_calleeGroup->m_bbqCallees[m_functionIndex] = callee.copyRef();
143
143
144
        for (auto& call : callee->wasmToWasmCallsites()) {
144
        for (auto& call : callee->wasmToWasmCallsites()) {
145
            MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
145
            MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
146
            if (call.functionIndexSpace < m_moduleInformation->importFunctionCount())
146
            if (call.functionIndexSpace < m_moduleInformation->importFunctionCount())
147
                entrypoint = m_codeBlock->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
147
                entrypoint = m_calleeGroup->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
148
            else
148
            else
149
                entrypoint = m_codeBlock->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
149
                entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
150
150
151
            MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
151
            MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
152
        }
152
        }
153
153
154
        Plan::updateCallSitesToCallUs(*m_codeBlock, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
154
        Plan::updateCallSitesToCallUs(*m_calleeGroup, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
155
155
156
        {
156
        {
157
            LLIntCallee& llintCallee = m_codeBlock->m_llintCallees->at(m_functionIndex).get();
157
            LLIntCallee& llintCallee = m_calleeGroup->m_llintCallees->at(m_functionIndex).get();
158
            Locker locker { llintCallee.tierUpCounter().m_lock };
158
            Locker locker { llintCallee.tierUpCounter().m_lock };
159
            llintCallee.setReplacement(callee.copyRef(), mode());
159
            llintCallee.setReplacement(callee.copyRef(), mode());
160
            llintCallee.tierUpCounter().m_compilationStatus = LLIntTierUpCounter::CompilationStatus::Compiled;
160
            llintCallee.tierUpCounter().m_compilationStatus = LLIntTierUpCounter::CompilationStatus::Compiled;
- a/Source/JavaScriptCore/wasm/WasmBBQPlan.h -3 / +3 lines
Lines 45-51 class CallLinkInfo; a/Source/JavaScriptCore/wasm/WasmBBQPlan.h_sec1
45
namespace Wasm {
45
namespace Wasm {
46
46
47
class BBQCallee;
47
class BBQCallee;
48
class CodeBlock;
48
class CalleeGroup;
49
class EmbedderEntrypointCallee;
49
class EmbedderEntrypointCallee;
50
50
51
class BBQPlan final : public EntryPlan {
51
class BBQPlan final : public EntryPlan {
Lines 54-60 class BBQPlan final : public EntryPlan { a/Source/JavaScriptCore/wasm/WasmBBQPlan.h_sec2
54
54
55
    using Base::Base;
55
    using Base::Base;
56
56
57
    BBQPlan(Context*, Ref<ModuleInformation>, uint32_t functionIndex, CodeBlock*, CompletionTask&&);
57
    BBQPlan(Context*, Ref<ModuleInformation>, uint32_t functionIndex, CalleeGroup*, CompletionTask&&);
58
58
59
    bool hasWork() const final
59
    bool hasWork() const final
60
    {
60
    {
Lines 88-94 class BBQPlan final : public EntryPlan { a/Source/JavaScriptCore/wasm/WasmBBQPlan.h_sec3
88
    Vector<CompilationContext> m_compilationContexts;
88
    Vector<CompilationContext> m_compilationContexts;
89
    Vector<std::unique_ptr<TierUpCount>> m_tierUpCounts;
89
    Vector<std::unique_ptr<TierUpCount>> m_tierUpCounts;
90
90
91
    RefPtr<CodeBlock> m_codeBlock { nullptr };
91
    RefPtr<CalleeGroup> m_calleeGroup { nullptr };
92
    uint32_t m_functionIndex;
92
    uint32_t m_functionIndex;
93
};
93
};
94
94
- a/Source/JavaScriptCore/wasm/WasmCalleeGroup.cpp +199 lines
Line 0 a/Source/JavaScriptCore/wasm/WasmCalleeGroup.cpp_sec1
1
/*
2
 * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "WasmCalleeGroup.h"
28
29
#if ENABLE(WEBASSEMBLY)
30
31
#include "WasmBBQPlan.h"
32
#include "WasmCallee.h"
33
#include "WasmLLIntPlan.h"
34
#include "WasmWorklist.h"
35
36
namespace JSC { namespace Wasm {
37
38
Ref<CalleeGroup> CalleeGroup::create(Context* context, MemoryMode mode, ModuleInformation& moduleInformation, RefPtr<LLIntCallees> llintCallees)
39
{
40
    return adoptRef(*new CalleeGroup(context, mode, moduleInformation, llintCallees));
41
}
42
43
Ref<CalleeGroup> CalleeGroup::createFromExisting(MemoryMode mode, const CalleeGroup& other)
44
{
45
    return adoptRef(*new CalleeGroup(mode, other));
46
}
47
48
CalleeGroup::CalleeGroup(MemoryMode mode, const CalleeGroup& other)
49
    : m_calleeCount(other.m_calleeCount)
50
    , m_mode(mode)
51
#if ENABLE(WEBASSEMBLY_B3JIT)
52
    , m_omgCallees(m_calleeCount)
53
    , m_bbqCallees(m_calleeCount)
54
#endif
55
    , m_llintCallees(other.m_llintCallees)
56
    , m_embedderCallees(other.m_embedderCallees)
57
    , m_wasmIndirectCallEntryPoints(other.m_wasmIndirectCallEntryPoints)
58
    , m_wasmToWasmCallsites(other.m_wasmToWasmCallsites)
59
    , m_wasmToWasmExitStubs(other.m_wasmToWasmExitStubs)
60
{
61
    setCompilationFinished();
62
}
63
64
CalleeGroup::CalleeGroup(Context* context, MemoryMode mode, ModuleInformation& moduleInformation, RefPtr<LLIntCallees> llintCallees)
65
    : m_calleeCount(moduleInformation.internalFunctionCount())
66
    , m_mode(mode)
67
    , m_llintCallees(llintCallees)
68
{
69
    RefPtr<CalleeGroup> protectedThis = this;
70
71
    if (Options::useWasmLLInt()) {
72
        m_plan = adoptRef(*new LLIntPlan(context, moduleInformation, m_llintCallees->data(), createSharedTask<Plan::CallbackType>([this, protectedThis = WTFMove(protectedThis)] (Plan&) {
73
            Locker locker { m_lock };
74
            if (m_plan->failed()) {
75
                m_errorMessage = m_plan->errorMessage();
76
                setCompilationFinished();
77
                return;
78
            }
79
80
#if ENABLE(WEBASSEMBLY_B3JIT)
81
            // FIXME: we should eventually collect the BBQ code.
82
            m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
83
            m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
84
#endif
85
            m_wasmIndirectCallEntryPoints = FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>>(m_calleeCount);
86
87
            for (unsigned i = 0; i < m_calleeCount; ++i)
88
                m_wasmIndirectCallEntryPoints[i] = m_llintCallees->at(i)->entrypoint();
89
90
            m_wasmToWasmExitStubs = m_plan->takeWasmToWasmExitStubs();
91
            m_wasmToWasmCallsites = m_plan->takeWasmToWasmCallsites();
92
            m_embedderCallees = static_cast<LLIntPlan*>(m_plan.get())->takeEmbedderCallees();
93
94
            setCompilationFinished();
95
        })));
96
    }
97
#if ENABLE(WEBASSEMBLY_B3JIT)
98
    else {
99
        m_plan = adoptRef(*new BBQPlan(context, moduleInformation, CompilerMode::FullCompile, createSharedTask<Plan::CallbackType>([this, protectedThis = WTFMove(protectedThis)] (Plan&) {
100
            Locker locker { m_lock };
101
            if (m_plan->failed()) {
102
                m_errorMessage = m_plan->errorMessage();
103
                setCompilationFinished();
104
                return;
105
            }
106
107
            // FIXME: we should eventually collect the BBQ code.
108
            m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
109
            m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
110
            m_wasmIndirectCallEntryPoints = FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>>(m_calleeCount);
111
112
            BBQPlan* bbqPlan = static_cast<BBQPlan*>(m_plan.get());
113
            bbqPlan->initializeCallees([&] (unsigned calleeIndex, RefPtr<EmbedderEntrypointCallee>&& embedderEntrypointCallee, RefPtr<BBQCallee>&& wasmEntrypoint) {
114
                if (embedderEntrypointCallee) {
115
                    auto result = m_embedderCallees.set(calleeIndex, WTFMove(embedderEntrypointCallee));
116
                    ASSERT_UNUSED(result, result.isNewEntry);
117
                }
118
                m_wasmIndirectCallEntryPoints[calleeIndex] = wasmEntrypoint->entrypoint();
119
                m_bbqCallees[calleeIndex] = adoptRef(static_cast<BBQCallee*>(wasmEntrypoint.leakRef()));
120
            });
121
122
            m_wasmToWasmExitStubs = m_plan->takeWasmToWasmExitStubs();
123
            m_wasmToWasmCallsites = m_plan->takeWasmToWasmCallsites();
124
125
            setCompilationFinished();
126
        })));
127
    }
128
#endif
129
    m_plan->setMode(mode);
130
131
    auto& worklist = Wasm::ensureWorklist();
132
    // Note, immediately after we enqueue the plan, there is a chance the above callback will be called.
133
    worklist.enqueue(*m_plan.get());
134
}
135
136
CalleeGroup::~CalleeGroup() { }
137
138
void CalleeGroup::waitUntilFinished()
139
{
140
    RefPtr<Plan> plan;
141
    {
142
        Locker locker { m_lock };
143
        plan = m_plan;
144
    }
145
146
    if (plan) {
147
        auto& worklist = Wasm::ensureWorklist();
148
        worklist.completePlanSynchronously(*plan.get());
149
    }
150
    // else, if we don't have a plan, we're already compiled.
151
}
152
153
void CalleeGroup::compileAsync(Context* context, AsyncCompilationCallback&& task)
154
{
155
    RefPtr<Plan> plan;
156
    {
157
        Locker locker { m_lock };
158
        plan = m_plan;
159
    }
160
161
    if (plan) {
162
        // We don't need to keep a RefPtr on the Plan because the worklist will keep
163
        // a RefPtr on the Plan until the plan finishes notifying all of its callbacks.
164
        RefPtr<CalleeGroup> protectedThis = this;
165
        plan->addCompletionTask(context, createSharedTask<Plan::CallbackType>([this, task = WTFMove(task), protectedThis = WTFMove(protectedThis)] (Plan&) {
166
            task->run(Ref { *this });
167
        }));
168
    } else
169
        task->run(Ref { *this });
170
}
171
172
bool CalleeGroup::isSafeToRun(MemoryMode memoryMode)
173
{
174
    if (!runnable())
175
        return false;
176
177
    switch (m_mode) {
178
    case Wasm::MemoryMode::BoundsChecking:
179
        return true;
180
    case Wasm::MemoryMode::Signaling:
181
        // Code being in Signaling mode means that it performs no bounds checks.
182
        // Its memory, even if empty, absolutely must also be in Signaling mode
183
        // because the page protection detects out-of-bounds accesses.
184
        return memoryMode == Wasm::MemoryMode::Signaling;
185
    }
186
    RELEASE_ASSERT_NOT_REACHED();
187
    return false;
188
}
189
190
191
void CalleeGroup::setCompilationFinished()
192
{
193
    m_plan = nullptr;
194
    m_compilationFinished.store(true);
195
}
196
197
} } // namespace JSC::Wasm
198
199
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WasmCalleeGroup.h +161 lines
Line 0 a/Source/JavaScriptCore/wasm/WasmCalleeGroup.h_sec1
1
/*
2
 * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBASSEMBLY)
29
30
#include "MacroAssemblerCodeRef.h"
31
#include "WasmCallee.h"
32
#include "WasmEmbedder.h"
33
#include <wtf/CrossThreadCopier.h>
34
#include <wtf/FixedVector.h>
35
#include <wtf/Lock.h>
36
#include <wtf/RefPtr.h>
37
#include <wtf/SharedTask.h>
38
#include <wtf/ThreadSafeRefCounted.h>
39
#include <wtf/text/WTFString.h>
40
41
namespace JSC {
42
43
namespace Wasm {
44
45
struct Context;
46
class EntryPlan;
47
struct ModuleInformation;
48
struct UnlinkedWasmToWasmCall;
49
enum class MemoryMode : uint8_t;
50
51
class CalleeGroup : public ThreadSafeRefCounted<CalleeGroup> {
52
public:
53
    typedef void CallbackType(Ref<CalleeGroup>&&);
54
    using AsyncCompilationCallback = RefPtr<WTF::SharedTask<CallbackType>>;
55
    static Ref<CalleeGroup> create(Context*, MemoryMode, ModuleInformation&, RefPtr<LLIntCallees>);
56
    static Ref<CalleeGroup> createFromExisting(MemoryMode, const CalleeGroup&);
57
58
    void waitUntilFinished();
59
    void compileAsync(Context*, AsyncCompilationCallback&&);
60
61
    bool compilationFinished()
62
    {
63
        return m_compilationFinished.load();
64
    }
65
    bool runnable() { return compilationFinished() && !m_errorMessage; }
66
67
    // Note, we do this copy to ensure it's thread safe to have this
68
    // called from multiple threads simultaneously.
69
    String errorMessage()
70
    {
71
        ASSERT(!runnable());
72
        return crossThreadCopy(m_errorMessage);
73
    }
74
75
    unsigned functionImportCount() const { return m_wasmToWasmExitStubs.size(); }
76
77
    // These two callee getters are only valid once the callees have been populated.
78
79
    Callee& embedderEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
80
    {
81
        ASSERT(runnable());
82
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
83
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
84
85
        auto callee = m_embedderCallees.get(calleeIndex);
86
        RELEASE_ASSERT(callee);
87
        return *callee;
88
    }
89
90
    Callee& wasmEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
91
    {
92
        ASSERT(runnable());
93
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
94
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
95
#if ENABLE(WEBASSEMBLY_B3JIT)
96
        if (m_omgCallees[calleeIndex])
97
            return *m_omgCallees[calleeIndex].get();
98
        if (m_bbqCallees[calleeIndex])
99
            return *m_bbqCallees[calleeIndex].get();
100
#endif
101
        return m_llintCallees->at(calleeIndex).get();
102
    }
103
104
#if ENABLE(WEBASSEMBLY_B3JIT)
105
    BBQCallee& wasmBBQCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
106
    {
107
        ASSERT(runnable());
108
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
109
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
110
        return *m_bbqCallees[calleeIndex].get();
111
    }
112
#endif
113
114
    MacroAssemblerCodePtr<WasmEntryPtrTag>* entrypointLoadLocationFromFunctionIndexSpace(unsigned functionIndexSpace)
115
    {
116
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
117
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
118
        return &m_wasmIndirectCallEntryPoints[calleeIndex];
119
    }
120
121
    MacroAssemblerCodePtr<WasmEntryPtrTag> wasmToWasmExitStub(unsigned functionIndex)
122
    {
123
        return m_wasmToWasmExitStubs[functionIndex].code();
124
    }
125
126
    bool isSafeToRun(MemoryMode);
127
128
    MemoryMode mode() const { return m_mode; }
129
130
    ~CalleeGroup();
131
private:
132
    friend class Plan;
133
#if ENABLE(WEBASSEMBLY_B3JIT)
134
    friend class BBQPlan;
135
    friend class OMGPlan;
136
    friend class OMGForOSREntryPlan;
137
#endif
138
139
    CalleeGroup(Context*, MemoryMode, ModuleInformation&, RefPtr<LLIntCallees>);
140
    CalleeGroup(MemoryMode, const CalleeGroup&);
141
    void setCompilationFinished();
142
    unsigned m_calleeCount;
143
    MemoryMode m_mode;
144
#if ENABLE(WEBASSEMBLY_B3JIT)
145
    FixedVector<RefPtr<OMGCallee>> m_omgCallees;
146
    FixedVector<RefPtr<BBQCallee>> m_bbqCallees;
147
#endif
148
    RefPtr<LLIntCallees> m_llintCallees;
149
    HashMap<uint32_t, RefPtr<EmbedderEntrypointCallee>, DefaultHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_embedderCallees;
150
    FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>> m_wasmIndirectCallEntryPoints;
151
    FixedVector<Vector<UnlinkedWasmToWasmCall>> m_wasmToWasmCallsites;
152
    FixedVector<MacroAssemblerCodeRef<WasmEntryPtrTag>> m_wasmToWasmExitStubs;
153
    RefPtr<EntryPlan> m_plan;
154
    std::atomic<bool> m_compilationFinished { false };
155
    String m_errorMessage;
156
    Lock m_lock;
157
};
158
159
} } // namespace JSC::Wasm
160
161
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WasmCodeBlock.cpp -199 lines
Lines 1-199 a/Source/JavaScriptCore/wasm/WasmCodeBlock.cpp_sec1
1
/*
2
 * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "WasmCodeBlock.h"
28
29
#if ENABLE(WEBASSEMBLY)
30
31
#include "WasmBBQPlan.h"
32
#include "WasmCallee.h"
33
#include "WasmLLIntPlan.h"
34
#include "WasmWorklist.h"
35
36
namespace JSC { namespace Wasm {
37
38
Ref<CodeBlock> CodeBlock::create(Context* context, MemoryMode mode, ModuleInformation& moduleInformation, RefPtr<LLIntCallees> llintCallees)
39
{
40
    return adoptRef(*new CodeBlock(context, mode, moduleInformation, llintCallees));
41
}
42
43
Ref<CodeBlock> CodeBlock::createFromExisting(MemoryMode mode, const CodeBlock& other)
44
{
45
    return adoptRef(*new CodeBlock(mode, other));
46
}
47
48
CodeBlock::CodeBlock(MemoryMode mode, const CodeBlock& other)
49
    : m_calleeCount(other.m_calleeCount)
50
    , m_mode(mode)
51
#if ENABLE(WEBASSEMBLY_B3JIT)
52
    , m_omgCallees(m_calleeCount)
53
    , m_bbqCallees(m_calleeCount)
54
#endif
55
    , m_llintCallees(other.m_llintCallees)
56
    , m_embedderCallees(other.m_embedderCallees)
57
    , m_wasmIndirectCallEntryPoints(other.m_wasmIndirectCallEntryPoints)
58
    , m_wasmToWasmCallsites(other.m_wasmToWasmCallsites)
59
    , m_wasmToWasmExitStubs(other.m_wasmToWasmExitStubs)
60
{
61
    setCompilationFinished();
62
}
63
64
CodeBlock::CodeBlock(Context* context, MemoryMode mode, ModuleInformation& moduleInformation, RefPtr<LLIntCallees> llintCallees)
65
    : m_calleeCount(moduleInformation.internalFunctionCount())
66
    , m_mode(mode)
67
    , m_llintCallees(llintCallees)
68
{
69
    RefPtr<CodeBlock> protectedThis = this;
70
71
    if (Options::useWasmLLInt()) {
72
        m_plan = adoptRef(*new LLIntPlan(context, moduleInformation, m_llintCallees->data(), createSharedTask<Plan::CallbackType>([this, protectedThis = WTFMove(protectedThis)] (Plan&) {
73
            Locker locker { m_lock };
74
            if (m_plan->failed()) {
75
                m_errorMessage = m_plan->errorMessage();
76
                setCompilationFinished();
77
                return;
78
            }
79
80
#if ENABLE(WEBASSEMBLY_B3JIT)
81
            // FIXME: we should eventually collect the BBQ code.
82
            m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
83
            m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
84
#endif
85
            m_wasmIndirectCallEntryPoints = FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>>(m_calleeCount);
86
87
            for (unsigned i = 0; i < m_calleeCount; ++i)
88
                m_wasmIndirectCallEntryPoints[i] = m_llintCallees->at(i)->entrypoint();
89
90
            m_wasmToWasmExitStubs = m_plan->takeWasmToWasmExitStubs();
91
            m_wasmToWasmCallsites = m_plan->takeWasmToWasmCallsites();
92
            m_embedderCallees = static_cast<LLIntPlan*>(m_plan.get())->takeEmbedderCallees();
93
94
            setCompilationFinished();
95
        })));
96
    }
97
#if ENABLE(WEBASSEMBLY_B3JIT)
98
    else {
99
        m_plan = adoptRef(*new BBQPlan(context, moduleInformation, CompilerMode::FullCompile, createSharedTask<Plan::CallbackType>([this, protectedThis = WTFMove(protectedThis)] (Plan&) {
100
            Locker locker { m_lock };
101
            if (m_plan->failed()) {
102
                m_errorMessage = m_plan->errorMessage();
103
                setCompilationFinished();
104
                return;
105
            }
106
107
            // FIXME: we should eventually collect the BBQ code.
108
            m_bbqCallees = FixedVector<RefPtr<BBQCallee>>(m_calleeCount);
109
            m_omgCallees = FixedVector<RefPtr<OMGCallee>>(m_calleeCount);
110
            m_wasmIndirectCallEntryPoints = FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>>(m_calleeCount);
111
112
            BBQPlan* bbqPlan = static_cast<BBQPlan*>(m_plan.get());
113
            bbqPlan->initializeCallees([&] (unsigned calleeIndex, RefPtr<EmbedderEntrypointCallee>&& embedderEntrypointCallee, RefPtr<BBQCallee>&& wasmEntrypoint) {
114
                if (embedderEntrypointCallee) {
115
                    auto result = m_embedderCallees.set(calleeIndex, WTFMove(embedderEntrypointCallee));
116
                    ASSERT_UNUSED(result, result.isNewEntry);
117
                }
118
                m_wasmIndirectCallEntryPoints[calleeIndex] = wasmEntrypoint->entrypoint();
119
                m_bbqCallees[calleeIndex] = adoptRef(static_cast<BBQCallee*>(wasmEntrypoint.leakRef()));
120
            });
121
122
            m_wasmToWasmExitStubs = m_plan->takeWasmToWasmExitStubs();
123
            m_wasmToWasmCallsites = m_plan->takeWasmToWasmCallsites();
124
125
            setCompilationFinished();
126
        })));
127
    }
128
#endif
129
    m_plan->setMode(mode);
130
131
    auto& worklist = Wasm::ensureWorklist();
132
    // Note, immediately after we enqueue the plan, there is a chance the above callback will be called.
133
    worklist.enqueue(*m_plan.get());
134
}
135
136
CodeBlock::~CodeBlock() { }
137
138
void CodeBlock::waitUntilFinished()
139
{
140
    RefPtr<Plan> plan;
141
    {
142
        Locker locker { m_lock };
143
        plan = m_plan;
144
    }
145
146
    if (plan) {
147
        auto& worklist = Wasm::ensureWorklist();
148
        worklist.completePlanSynchronously(*plan.get());
149
    }
150
    // else, if we don't have a plan, we're already compiled.
151
}
152
153
void CodeBlock::compileAsync(Context* context, AsyncCompilationCallback&& task)
154
{
155
    RefPtr<Plan> plan;
156
    {
157
        Locker locker { m_lock };
158
        plan = m_plan;
159
    }
160
161
    if (plan) {
162
        // We don't need to keep a RefPtr on the Plan because the worklist will keep
163
        // a RefPtr on the Plan until the plan finishes notifying all of its callbacks.
164
        RefPtr<CodeBlock> protectedThis = this;
165
        plan->addCompletionTask(context, createSharedTask<Plan::CallbackType>([this, task = WTFMove(task), protectedThis = WTFMove(protectedThis)] (Plan&) {
166
            task->run(Ref { *this });
167
        }));
168
    } else
169
        task->run(Ref { *this });
170
}
171
172
bool CodeBlock::isSafeToRun(MemoryMode memoryMode)
173
{
174
    if (!runnable())
175
        return false;
176
177
    switch (m_mode) {
178
    case Wasm::MemoryMode::BoundsChecking:
179
        return true;
180
    case Wasm::MemoryMode::Signaling:
181
        // Code being in Signaling mode means that it performs no bounds checks.
182
        // Its memory, even if empty, absolutely must also be in Signaling mode
183
        // because the page protection detects out-of-bounds accesses.
184
        return memoryMode == Wasm::MemoryMode::Signaling;
185
    }
186
    RELEASE_ASSERT_NOT_REACHED();
187
    return false;
188
}
189
190
191
void CodeBlock::setCompilationFinished()
192
{
193
    m_plan = nullptr;
194
    m_compilationFinished.store(true);
195
}
196
197
} } // namespace JSC::Wasm
198
199
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WasmCodeBlock.h -163 lines
Lines 1-163 a/Source/JavaScriptCore/wasm/WasmCodeBlock.h_sec1
1
/*
2
 * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBASSEMBLY)
29
30
#include "MacroAssemblerCodeRef.h"
31
#include "WasmCallee.h"
32
#include "WasmEmbedder.h"
33
#include <wtf/CrossThreadCopier.h>
34
#include <wtf/FixedVector.h>
35
#include <wtf/Lock.h>
36
#include <wtf/RefPtr.h>
37
#include <wtf/SharedTask.h>
38
#include <wtf/ThreadSafeRefCounted.h>
39
#include <wtf/text/WTFString.h>
40
41
namespace JSC {
42
43
namespace Wasm {
44
45
struct Context;
46
class EntryPlan;
47
struct ModuleInformation;
48
struct UnlinkedWasmToWasmCall;
49
enum class MemoryMode : uint8_t;
50
    
51
// FIXME: Rename this, since it's not a CodeBlock
52
// https://bugs.webkit.org/show_bug.cgi?id=203694
53
class CodeBlock : public ThreadSafeRefCounted<CodeBlock> {
54
public:
55
    typedef void CallbackType(Ref<CodeBlock>&&);
56
    using AsyncCompilationCallback = RefPtr<WTF::SharedTask<CallbackType>>;
57
    static Ref<CodeBlock> create(Context*, MemoryMode, ModuleInformation&, RefPtr<LLIntCallees>);
58
    static Ref<CodeBlock> createFromExisting(MemoryMode, const CodeBlock&);
59
60
    void waitUntilFinished();
61
    void compileAsync(Context*, AsyncCompilationCallback&&);
62
63
    bool compilationFinished()
64
    {
65
        return m_compilationFinished.load();
66
    }
67
    bool runnable() { return compilationFinished() && !m_errorMessage; }
68
69
    // Note, we do this copy to ensure it's thread safe to have this
70
    // called from multiple threads simultaneously.
71
    String errorMessage()
72
    {
73
        ASSERT(!runnable());
74
        return crossThreadCopy(m_errorMessage);
75
    }
76
77
    unsigned functionImportCount() const { return m_wasmToWasmExitStubs.size(); }
78
79
    // These two callee getters are only valid once the callees have been populated.
80
81
    Callee& embedderEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
82
    {
83
        ASSERT(runnable());
84
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
85
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
86
87
        auto callee = m_embedderCallees.get(calleeIndex);
88
        RELEASE_ASSERT(callee);
89
        return *callee;
90
    }
91
92
    Callee& wasmEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
93
    {
94
        ASSERT(runnable());
95
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
96
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
97
#if ENABLE(WEBASSEMBLY_B3JIT)
98
        if (m_omgCallees[calleeIndex])
99
            return *m_omgCallees[calleeIndex].get();
100
        if (m_bbqCallees[calleeIndex])
101
            return *m_bbqCallees[calleeIndex].get();
102
#endif
103
        return m_llintCallees->at(calleeIndex).get();
104
    }
105
106
#if ENABLE(WEBASSEMBLY_B3JIT)
107
    BBQCallee& wasmBBQCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
108
    {
109
        ASSERT(runnable());
110
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
111
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
112
        return *m_bbqCallees[calleeIndex].get();
113
    }
114
#endif
115
116
    MacroAssemblerCodePtr<WasmEntryPtrTag>* entrypointLoadLocationFromFunctionIndexSpace(unsigned functionIndexSpace)
117
    {
118
        RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
119
        unsigned calleeIndex = functionIndexSpace - functionImportCount();
120
        return &m_wasmIndirectCallEntryPoints[calleeIndex];
121
    }
122
123
    MacroAssemblerCodePtr<WasmEntryPtrTag> wasmToWasmExitStub(unsigned functionIndex)
124
    {
125
        return m_wasmToWasmExitStubs[functionIndex].code();
126
    }
127
128
    bool isSafeToRun(MemoryMode);
129
130
    MemoryMode mode() const { return m_mode; }
131
132
    ~CodeBlock();
133
private:
134
    friend class Plan;
135
#if ENABLE(WEBASSEMBLY_B3JIT)
136
    friend class BBQPlan;
137
    friend class OMGPlan;
138
    friend class OMGForOSREntryPlan;
139
#endif
140
141
    CodeBlock(Context*, MemoryMode, ModuleInformation&, RefPtr<LLIntCallees>);
142
    CodeBlock(MemoryMode, const CodeBlock&);
143
    void setCompilationFinished();
144
    unsigned m_calleeCount;
145
    MemoryMode m_mode;
146
#if ENABLE(WEBASSEMBLY_B3JIT)
147
    FixedVector<RefPtr<OMGCallee>> m_omgCallees;
148
    FixedVector<RefPtr<BBQCallee>> m_bbqCallees;
149
#endif
150
    RefPtr<LLIntCallees> m_llintCallees;
151
    HashMap<uint32_t, RefPtr<EmbedderEntrypointCallee>, DefaultHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>> m_embedderCallees;
152
    FixedVector<MacroAssemblerCodePtr<WasmEntryPtrTag>> m_wasmIndirectCallEntryPoints;
153
    FixedVector<Vector<UnlinkedWasmToWasmCall>> m_wasmToWasmCallsites;
154
    FixedVector<MacroAssemblerCodeRef<WasmEntryPtrTag>> m_wasmToWasmExitStubs;
155
    RefPtr<EntryPlan> m_plan;
156
    std::atomic<bool> m_compilationFinished { false };
157
    String m_errorMessage;
158
    Lock m_lock;
159
};
160
161
} } // namespace JSC::Wasm
162
163
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WasmInstance.cpp -2 / +2 lines
Lines 256-263 void Instance::initElementSegment(uint32_t tableIndex, const Element& segment, u a/Source/JavaScriptCore/wasm/WasmInstance.cpp_sec1
256
            continue;
256
            continue;
257
        }
257
        }
258
258
259
        Callee& embedderEntrypointCallee = codeBlock()->embedderEntrypointCalleeFromFunctionIndexSpace(functionIndex);
259
        Callee& embedderEntrypointCallee = calleeGroup()->embedderEntrypointCalleeFromFunctionIndexSpace(functionIndex);
260
        WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation = codeBlock()->entrypointLoadLocationFromFunctionIndexSpace(functionIndex);
260
        WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation = calleeGroup()->entrypointLoadLocationFromFunctionIndexSpace(functionIndex);
261
        const Signature& signature = SignatureInformation::get(signatureIndex);
261
        const Signature& signature = SignatureInformation::get(signatureIndex);
262
        // FIXME: Say we export local function "foo" at function index 0.
262
        // FIXME: Say we export local function "foo" at function index 0.
263
        // What if we also set it to the table an Element w/ index 0.
263
        // What if we also set it to the table an Element w/ index 0.
- a/Source/JavaScriptCore/wasm/WasmInstance.h -2 / +2 lines
Lines 71-77 class Instance : public ThreadSafeRefCounted<Instance>, public CanMakeWeakPtr<In a/Source/JavaScriptCore/wasm/WasmInstance.h_sec1
71
    Wasm::Context* context() const { return m_context; }
71
    Wasm::Context* context() const { return m_context; }
72
72
73
    Module& module() const { return m_module.get(); }
73
    Module& module() const { return m_module.get(); }
74
    CodeBlock* codeBlock() const { return module().codeBlockFor(memory()->mode()); }
74
    CalleeGroup* calleeGroup() const { return module().calleeGroupFor(memory()->mode()); }
75
    Memory* memory() const { return m_memory.get(); }
75
    Memory* memory() const { return m_memory.get(); }
76
    Table* table(unsigned);
76
    Table* table(unsigned);
77
    void setTable(unsigned, Ref<Table>&&);
77
    void setTable(unsigned, Ref<Table>&&);
Lines 81-87 class Instance : public ThreadSafeRefCounted<Instance>, public CanMakeWeakPtr<In a/Source/JavaScriptCore/wasm/WasmInstance.h_sec2
81
81
82
    bool isImportFunction(uint32_t functionIndex) const
82
    bool isImportFunction(uint32_t functionIndex) const
83
    {
83
    {
84
        return functionIndex < codeBlock()->functionImportCount();
84
        return functionIndex < calleeGroup()->functionImportCount();
85
    }
85
    }
86
86
87
    void tableInit(uint32_t dstOffset, uint32_t srcOffset, uint32_t length, uint32_t elementIndex, uint32_t tableIndex);
87
    void tableInit(uint32_t dstOffset, uint32_t srcOffset, uint32_t length, uint32_t elementIndex, uint32_t tableIndex);
- a/Source/JavaScriptCore/wasm/WasmMachineThreads.h -1 / +1 lines
Lines 27-33 a/Source/JavaScriptCore/wasm/WasmMachineThreads.h_sec1
27
27
28
#if ENABLE(WEBASSEMBLY)
28
#if ENABLE(WEBASSEMBLY)
29
29
30
#include "WasmCodeBlock.h"
30
#include "WasmCalleeGroup.h"
31
#include "WasmMemory.h"
31
#include "WasmMemory.h"
32
#include <wtf/Expected.h>
32
#include <wtf/Expected.h>
33
#include <wtf/Lock.h>
33
#include <wtf/Lock.h>
- a/Source/JavaScriptCore/wasm/WasmModule.cpp -19 / +19 lines
Lines 78-125 void Module::validateAsync(Context* context, Vector<uint8_t>&& source, Module::A a/Source/JavaScriptCore/wasm/WasmModule.cpp_sec1
78
    Wasm::ensureWorklist().enqueue(WTFMove(plan));
78
    Wasm::ensureWorklist().enqueue(WTFMove(plan));
79
}
79
}
80
80
81
Ref<CodeBlock> Module::getOrCreateCodeBlock(Context* context, MemoryMode mode)
81
Ref<CalleeGroup> Module::getOrCreateCalleeGroup(Context* context, MemoryMode mode)
82
{
82
{
83
    RefPtr<CodeBlock> codeBlock;
83
    RefPtr<CalleeGroup> calleeGroup;
84
    Locker locker { m_lock };
84
    Locker locker { m_lock };
85
    codeBlock = m_codeBlocks[static_cast<uint8_t>(mode)];
85
    calleeGroup = m_calleeGroups[static_cast<uint8_t>(mode)];
86
    // If a previous attempt at a compile errored out, let's try again.
86
    // If a previous attempt at a compile errored out, let's try again.
87
    // Compilations from valid modules can fail because OOM and cancellation.
87
    // Compilations from valid modules can fail because OOM and cancellation.
88
    // It's worth retrying.
88
    // It's worth retrying.
89
    // FIXME: We might want to back off retrying at some point:
89
    // FIXME: We might want to back off retrying at some point:
90
    // https://bugs.webkit.org/show_bug.cgi?id=170607
90
    // https://bugs.webkit.org/show_bug.cgi?id=170607
91
    if (!codeBlock || (codeBlock->compilationFinished() && !codeBlock->runnable())) {
91
    if (!calleeGroup || (calleeGroup->compilationFinished() && !calleeGroup->runnable())) {
92
        RefPtr<LLIntCallees> llintCallees = nullptr;
92
        RefPtr<LLIntCallees> llintCallees = nullptr;
93
        if (Options::useWasmLLInt())
93
        if (Options::useWasmLLInt())
94
            llintCallees = m_llintCallees;
94
            llintCallees = m_llintCallees;
95
        codeBlock = CodeBlock::create(context, mode, const_cast<ModuleInformation&>(moduleInformation()), llintCallees);
95
        calleeGroup = CalleeGroup::create(context, mode, const_cast<ModuleInformation&>(moduleInformation()), llintCallees);
96
        m_codeBlocks[static_cast<uint8_t>(mode)] = codeBlock;
96
        m_calleeGroups[static_cast<uint8_t>(mode)] = calleeGroup;
97
    }
97
    }
98
    return codeBlock.releaseNonNull();
98
    return calleeGroup.releaseNonNull();
99
}
99
}
100
100
101
Ref<CodeBlock> Module::compileSync(Context* context, MemoryMode mode)
101
Ref<CalleeGroup> Module::compileSync(Context* context, MemoryMode mode)
102
{
102
{
103
    Ref<CodeBlock> codeBlock = getOrCreateCodeBlock(context, mode);
103
    Ref<CalleeGroup> calleeGroup = getOrCreateCalleeGroup(context, mode);
104
    codeBlock->waitUntilFinished();
104
    calleeGroup->waitUntilFinished();
105
    return codeBlock;
105
    return calleeGroup;
106
}
106
}
107
107
108
void Module::compileAsync(Context* context, MemoryMode mode, CodeBlock::AsyncCompilationCallback&& task)
108
void Module::compileAsync(Context* context, MemoryMode mode, CalleeGroup::AsyncCompilationCallback&& task)
109
{
109
{
110
    Ref<CodeBlock> codeBlock = getOrCreateCodeBlock(context, mode);
110
    Ref<CalleeGroup> calleeGroup = getOrCreateCalleeGroup(context, mode);
111
    codeBlock->compileAsync(context, WTFMove(task));
111
    calleeGroup->compileAsync(context, WTFMove(task));
112
}
112
}
113
113
114
void Module::copyInitialCodeBlockToAllMemoryModes(MemoryMode initialMode)
114
void Module::copyInitialCalleeGroupToAllMemoryModes(MemoryMode initialMode)
115
{
115
{
116
    ASSERT(m_codeBlocks[static_cast<uint8_t>(initialMode)]);
116
    ASSERT(m_calleeGroups[static_cast<uint8_t>(initialMode)]);
117
    const CodeBlock& initialBlock = *m_codeBlocks[static_cast<uint8_t>(initialMode)];
117
    const CalleeGroup& initialBlock = *m_calleeGroups[static_cast<uint8_t>(initialMode)];
118
    for (unsigned i = 0; i < Wasm::NumberOfMemoryModes; i++) {
118
    for (unsigned i = 0; i < Wasm::NumberOfMemoryModes; i++) {
119
        if (i == static_cast<uint8_t>(initialMode))
119
        if (i == static_cast<uint8_t>(initialMode))
120
            continue;
120
            continue;
121
        Ref<CodeBlock> newBlock = CodeBlock::createFromExisting(static_cast<MemoryMode>(i), initialBlock);
121
        Ref<CalleeGroup> newBlock = CalleeGroup::createFromExisting(static_cast<MemoryMode>(i), initialBlock);
122
        m_codeBlocks[i] = WTFMove(newBlock);
122
        m_calleeGroups[i] = WTFMove(newBlock);
123
    }
123
    }
124
}
124
}
125
125
- a/Source/JavaScriptCore/wasm/WasmModule.h -7 / +7 lines
Lines 27-33 a/Source/JavaScriptCore/wasm/WasmModule.h_sec1
27
27
28
#if ENABLE(WEBASSEMBLY)
28
#if ENABLE(WEBASSEMBLY)
29
29
30
#include "WasmCodeBlock.h"
30
#include "WasmCalleeGroup.h"
31
#include "WasmEmbedder.h"
31
#include "WasmEmbedder.h"
32
#include "WasmMemory.h"
32
#include "WasmMemory.h"
33
#include "WasmOps.h"
33
#include "WasmOps.h"
Lines 59-79 class Module : public ThreadSafeRefCounted<Module> { a/Source/JavaScriptCore/wasm/WasmModule.h_sec2
59
    Wasm::SignatureIndex signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const;
59
    Wasm::SignatureIndex signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const;
60
    const Wasm::ModuleInformation& moduleInformation() const { return m_moduleInformation.get(); }
60
    const Wasm::ModuleInformation& moduleInformation() const { return m_moduleInformation.get(); }
61
61
62
    Ref<CodeBlock> compileSync(Context*, MemoryMode);
62
    Ref<CalleeGroup> compileSync(Context*, MemoryMode);
63
    void compileAsync(Context*, MemoryMode, CodeBlock::AsyncCompilationCallback&&);
63
    void compileAsync(Context*, MemoryMode, CalleeGroup::AsyncCompilationCallback&&);
64
64
65
    JS_EXPORT_PRIVATE ~Module();
65
    JS_EXPORT_PRIVATE ~Module();
66
66
67
    CodeBlock* codeBlockFor(MemoryMode mode) { return m_codeBlocks[static_cast<uint8_t>(mode)].get(); }
67
    CalleeGroup* calleeGroupFor(MemoryMode mode) { return m_calleeGroups[static_cast<uint8_t>(mode)].get(); }
68
68
69
    void copyInitialCodeBlockToAllMemoryModes(MemoryMode);
69
    void copyInitialCalleeGroupToAllMemoryModes(MemoryMode);
70
70
71
private:
71
private:
72
    Ref<CodeBlock> getOrCreateCodeBlock(Context*, MemoryMode);
72
    Ref<CalleeGroup> getOrCreateCalleeGroup(Context*, MemoryMode);
73
73
74
    Module(LLIntPlan&);
74
    Module(LLIntPlan&);
75
    Ref<ModuleInformation> m_moduleInformation;
75
    Ref<ModuleInformation> m_moduleInformation;
76
    RefPtr<CodeBlock> m_codeBlocks[Wasm::NumberOfMemoryModes];
76
    RefPtr<CalleeGroup> m_calleeGroups[Wasm::NumberOfMemoryModes];
77
    RefPtr<LLIntCallees> m_llintCallees;
77
    RefPtr<LLIntCallees> m_llintCallees;
78
    MacroAssemblerCodeRef<JITCompilationPtrTag> m_llintEntryThunks;
78
    MacroAssemblerCodeRef<JITCompilationPtrTag> m_llintEntryThunks;
79
    Lock m_lock;
79
    Lock m_lock;
- a/Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.cpp -9 / +9 lines
Lines 48-69 static constexpr bool verbose = false; a/Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.cpp_sec1
48
OMGForOSREntryPlan::OMGForOSREntryPlan(Context* context, Ref<Module>&& module, Ref<Callee>&& callee, uint32_t functionIndex, uint32_t loopIndex, MemoryMode mode, CompletionTask&& task)
48
OMGForOSREntryPlan::OMGForOSREntryPlan(Context* context, Ref<Module>&& module, Ref<Callee>&& callee, uint32_t functionIndex, uint32_t loopIndex, MemoryMode mode, CompletionTask&& task)
49
    : Base(context, const_cast<ModuleInformation&>(module->moduleInformation()), WTFMove(task))
49
    : Base(context, const_cast<ModuleInformation&>(module->moduleInformation()), WTFMove(task))
50
    , m_module(WTFMove(module))
50
    , m_module(WTFMove(module))
51
    , m_codeBlock(*m_module->codeBlockFor(mode))
51
    , m_calleeGroup(*m_module->calleeGroupFor(mode))
52
    , m_callee(WTFMove(callee))
52
    , m_callee(WTFMove(callee))
53
    , m_functionIndex(functionIndex)
53
    , m_functionIndex(functionIndex)
54
    , m_loopIndex(loopIndex)
54
    , m_loopIndex(loopIndex)
55
{
55
{
56
    ASSERT(Options::useOMGJIT());
56
    ASSERT(Options::useOMGJIT());
57
    setMode(mode);
57
    setMode(mode);
58
    ASSERT(m_codeBlock->runnable());
58
    ASSERT(m_calleeGroup->runnable());
59
    ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(m_mode));
59
    ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(m_mode));
60
    dataLogLnIf(WasmOMGForOSREntryPlanInternal::verbose, "Starting OMGForOSREntry plan for ", functionIndex, " of module: ", RawPointer(&m_module.get()));
60
    dataLogLnIf(WasmOMGForOSREntryPlanInternal::verbose, "Starting OMGForOSREntry plan for ", functionIndex, " of module: ", RawPointer(&m_module.get()));
61
}
61
}
62
62
63
void OMGForOSREntryPlan::work(CompilationEffort)
63
void OMGForOSREntryPlan::work(CompilationEffort)
64
{
64
{
65
    ASSERT(m_codeBlock->runnable());
65
    ASSERT(m_calleeGroup->runnable());
66
    ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode()));
66
    ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(mode()));
67
    const FunctionData& function = m_moduleInformation->functions[m_functionIndex];
67
    const FunctionData& function = m_moduleInformation->functions[m_functionIndex];
68
68
69
    const uint32_t functionIndexSpace = m_functionIndex + m_module->moduleInformation().importFunctionCount();
69
    const uint32_t functionIndexSpace = m_functionIndex + m_module->moduleInformation().importFunctionCount();
Lines 101-118 void OMGForOSREntryPlan::work(CompilationEffort) a/Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.cpp_sec2
101
101
102
    omgEntrypoint.calleeSaveRegisters = WTFMove(internalFunction->entrypoint.calleeSaveRegisters);
102
    omgEntrypoint.calleeSaveRegisters = WTFMove(internalFunction->entrypoint.calleeSaveRegisters);
103
103
104
    ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode()));
104
    ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(mode()));
105
    Ref<OMGForOSREntryCallee> callee = OMGForOSREntryCallee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), osrEntryScratchBufferSize, m_loopIndex, WTFMove(unlinkedCalls), WTFMove(internalFunction->stackmaps), WTFMove(internalFunction->exceptionHandlers), WTFMove(exceptionHandlerLocations));
105
    Ref<OMGForOSREntryCallee> callee = OMGForOSREntryCallee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), osrEntryScratchBufferSize, m_loopIndex, WTFMove(unlinkedCalls), WTFMove(internalFunction->stackmaps), WTFMove(internalFunction->exceptionHandlers), WTFMove(exceptionHandlerLocations));
106
    {
106
    {
107
        MacroAssembler::repatchPointer(internalFunction->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
107
        MacroAssembler::repatchPointer(internalFunction->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
108
108
109
        Locker locker { m_codeBlock->m_lock };
109
        Locker locker { m_calleeGroup->m_lock };
110
        for (auto& call : callee->wasmToWasmCallsites()) {
110
        for (auto& call : callee->wasmToWasmCallsites()) {
111
            MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
111
            MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
112
            if (call.functionIndexSpace < m_module->moduleInformation().importFunctionCount())
112
            if (call.functionIndexSpace < m_module->moduleInformation().importFunctionCount())
113
                entrypoint = m_codeBlock->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
113
                entrypoint = m_calleeGroup->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
114
            else
114
            else
115
                entrypoint = m_codeBlock->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
115
                entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
116
116
117
            MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
117
            MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
118
        }
118
        }
- a/Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.h -1 / +1 lines
Lines 62-68 class OMGForOSREntryPlan final : public Plan { a/Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.h_sec1
62
    }
62
    }
63
63
64
    Ref<Module> m_module;
64
    Ref<Module> m_module;
65
    Ref<CodeBlock> m_codeBlock;
65
    Ref<CalleeGroup> m_calleeGroup;
66
    Ref<Callee> m_callee;
66
    Ref<Callee> m_callee;
67
    bool m_completed { false };
67
    bool m_completed { false };
68
    uint32_t m_functionIndex;
68
    uint32_t m_functionIndex;
- a/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp -15 / +15 lines
Lines 48-67 static constexpr bool verbose = false; a/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp_sec1
48
OMGPlan::OMGPlan(Context* context, Ref<Module>&& module, uint32_t functionIndex, MemoryMode mode, CompletionTask&& task)
48
OMGPlan::OMGPlan(Context* context, Ref<Module>&& module, uint32_t functionIndex, MemoryMode mode, CompletionTask&& task)
49
    : Base(context, const_cast<ModuleInformation&>(module->moduleInformation()), WTFMove(task))
49
    : Base(context, const_cast<ModuleInformation&>(module->moduleInformation()), WTFMove(task))
50
    , m_module(WTFMove(module))
50
    , m_module(WTFMove(module))
51
    , m_codeBlock(*m_module->codeBlockFor(mode))
51
    , m_calleeGroup(*m_module->calleeGroupFor(mode))
52
    , m_functionIndex(functionIndex)
52
    , m_functionIndex(functionIndex)
53
{
53
{
54
    ASSERT(Options::useOMGJIT());
54
    ASSERT(Options::useOMGJIT());
55
    setMode(mode);
55
    setMode(mode);
56
    ASSERT(m_codeBlock->runnable());
56
    ASSERT(m_calleeGroup->runnable());
57
    ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(m_mode));
57
    ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(m_mode));
58
    dataLogLnIf(WasmOMGPlanInternal::verbose, "Starting OMG plan for ", functionIndex, " of module: ", RawPointer(&m_module.get()));
58
    dataLogLnIf(WasmOMGPlanInternal::verbose, "Starting OMG plan for ", functionIndex, " of module: ", RawPointer(&m_module.get()));
59
}
59
}
60
60
61
void OMGPlan::work(CompilationEffort)
61
void OMGPlan::work(CompilationEffort)
62
{
62
{
63
    ASSERT(m_codeBlock->runnable());
63
    ASSERT(m_calleeGroup->runnable());
64
    ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode()));
64
    ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(mode()));
65
    const FunctionData& function = m_moduleInformation->functions[m_functionIndex];
65
    const FunctionData& function = m_moduleInformation->functions[m_functionIndex];
66
66
67
    const uint32_t functionIndexSpace = m_functionIndex + m_module->moduleInformation().importFunctionCount();
67
    const uint32_t functionIndexSpace = m_functionIndex + m_module->moduleInformation().importFunctionCount();
Lines 103-112 void OMGPlan::work(CompilationEffort) a/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp_sec2
103
103
104
    MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
104
    MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
105
    {
105
    {
106
        ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode()));
106
        ASSERT(m_calleeGroup.ptr() == m_module->calleeGroupFor(mode()));
107
        Ref<OMGCallee> callee = OMGCallee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), WTFMove(unlinkedCalls), WTFMove(internalFunction->stackmaps), WTFMove(internalFunction->exceptionHandlers), WTFMove(exceptionHandlerLocations));
107
        Ref<OMGCallee> callee = OMGCallee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace), WTFMove(unlinkedCalls), WTFMove(internalFunction->stackmaps), WTFMove(internalFunction->exceptionHandlers), WTFMove(exceptionHandlerLocations));
108
        MacroAssembler::repatchPointer(internalFunction->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
108
        MacroAssembler::repatchPointer(internalFunction->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
109
        ASSERT(!m_codeBlock->m_omgCallees[m_functionIndex]);
109
        ASSERT(!m_calleeGroup->m_omgCallees[m_functionIndex]);
110
        entrypoint = callee->entrypoint();
110
        entrypoint = callee->entrypoint();
111
111
112
        if (context.pcToCodeOriginMap)
112
        if (context.pcToCodeOriginMap)
Lines 116-145 void OMGPlan::work(CompilationEffort) a/Source/JavaScriptCore/wasm/WasmOMGPlan.cpp_sec3
116
        // always call the fastest code. Any function linked after us will see our new code and the new callsites, which they
116
        // always call the fastest code. Any function linked after us will see our new code and the new callsites, which they
117
        // will update. It's also ok if they publish their code before we reset the instruction caches because after we release
117
        // will update. It's also ok if they publish their code before we reset the instruction caches because after we release
118
        // the lock our code is ready to be published too.
118
        // the lock our code is ready to be published too.
119
        Locker locker { m_codeBlock->m_lock };
119
        Locker locker { m_calleeGroup->m_lock };
120
120
121
        m_codeBlock->m_omgCallees[m_functionIndex] = callee.copyRef();
121
        m_calleeGroup->m_omgCallees[m_functionIndex] = callee.copyRef();
122
122
123
        for (auto& call : callee->wasmToWasmCallsites()) {
123
        for (auto& call : callee->wasmToWasmCallsites()) {
124
            MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
124
            MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
125
            if (call.functionIndexSpace < m_module->moduleInformation().importFunctionCount())
125
            if (call.functionIndexSpace < m_module->moduleInformation().importFunctionCount())
126
                entrypoint = m_codeBlock->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
126
                entrypoint = m_calleeGroup->m_wasmToWasmExitStubs[call.functionIndexSpace].code();
127
            else
127
            else
128
                entrypoint = m_codeBlock->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
128
                entrypoint = m_calleeGroup->wasmEntrypointCalleeFromFunctionIndexSpace(call.functionIndexSpace).entrypoint().retagged<WasmEntryPtrTag>();
129
129
130
            MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
130
            MacroAssembler::repatchNearCall(call.callLocation, CodeLocationLabel<WasmEntryPtrTag>(entrypoint));
131
        }
131
        }
132
132
133
        Plan::updateCallSitesToCallUs(m_codeBlock, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
133
        Plan::updateCallSitesToCallUs(m_calleeGroup, CodeLocationLabel<WasmEntryPtrTag>(entrypoint), m_functionIndex, functionIndexSpace);
134
134
135
        {
135
        {
136
            if (BBQCallee* bbqCallee = m_codeBlock->m_bbqCallees[m_functionIndex].get()) {
136
            if (BBQCallee* bbqCallee = m_calleeGroup->m_bbqCallees[m_functionIndex].get()) {
137
                Locker locker { bbqCallee->tierUpCount()->getLock() };
137
                Locker locker { bbqCallee->tierUpCount()->getLock() };
138
                bbqCallee->setReplacement(callee.copyRef());
138
                bbqCallee->setReplacement(callee.copyRef());
139
                bbqCallee->tierUpCount()->m_compilationStatusForOMG = TierUpCount::CompilationStatus::Compiled;
139
                bbqCallee->tierUpCount()->m_compilationStatusForOMG = TierUpCount::CompilationStatus::Compiled;
140
            }
140
            }
141
            if (m_codeBlock->m_llintCallees) {
141
            if (m_calleeGroup->m_llintCallees) {
142
                LLIntCallee& llintCallee = m_codeBlock->m_llintCallees->at(m_functionIndex).get();
142
                LLIntCallee& llintCallee = m_calleeGroup->m_llintCallees->at(m_functionIndex).get();
143
                Locker locker { llintCallee.tierUpCounter().m_lock };
143
                Locker locker { llintCallee.tierUpCounter().m_lock };
144
                llintCallee.setReplacement(callee.copyRef(), mode());
144
                llintCallee.setReplacement(callee.copyRef(), mode());
145
                llintCallee.tierUpCounter().m_compilationStatus = LLIntTierUpCounter::CompilationStatus::Compiled;
145
                llintCallee.tierUpCounter().m_compilationStatus = LLIntTierUpCounter::CompilationStatus::Compiled;
- a/Source/JavaScriptCore/wasm/WasmOMGPlan.h -1 / +1 lines
Lines 60-66 class OMGPlan final : public Plan { a/Source/JavaScriptCore/wasm/WasmOMGPlan.h_sec1
60
    }
60
    }
61
    
61
    
62
    Ref<Module> m_module;
62
    Ref<Module> m_module;
63
    Ref<CodeBlock> m_codeBlock;
63
    Ref<CalleeGroup> m_calleeGroup;
64
    bool m_completed { false };
64
    bool m_completed { false };
65
    uint32_t m_functionIndex;
65
    uint32_t m_functionIndex;
66
};
66
};
- a/Source/JavaScriptCore/wasm/WasmOperations.cpp -16 / +16 lines
Lines 71-77 static bool shouldTriggerOMGCompile(TierUpCount& tierUp, OMGCallee* replacement, a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec1
71
    return true;
71
    return true;
72
}
72
}
73
73
74
static void triggerOMGReplacementCompile(TierUpCount& tierUp, OMGCallee* replacement, Instance* instance, Wasm::CodeBlock& codeBlock, uint32_t functionIndex)
74
static void triggerOMGReplacementCompile(TierUpCount& tierUp, OMGCallee* replacement, Instance* instance, Wasm::CalleeGroup& calleeGroup, uint32_t functionIndex)
75
{
75
{
76
    if (replacement) {
76
    if (replacement) {
77
        tierUp.optimizeSoon(functionIndex);
77
        tierUp.optimizeSoon(functionIndex);
Lines 97-103 static void triggerOMGReplacementCompile(TierUpCount& tierUp, OMGCallee* replace a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec2
97
    if (compile) {
97
    if (compile) {
98
        dataLogLnIf(Options::verboseOSR(), "triggerOMGReplacement for ", functionIndex);
98
        dataLogLnIf(Options::verboseOSR(), "triggerOMGReplacement for ", functionIndex);
99
        // We need to compile the code.
99
        // We need to compile the code.
100
        Ref<Plan> plan = adoptRef(*new OMGPlan(instance->context(), Ref<Wasm::Module>(instance->module()), functionIndex, codeBlock.mode(), Plan::dontFinalize()));
100
        Ref<Plan> plan = adoptRef(*new OMGPlan(instance->context(), Ref<Wasm::Module>(instance->module()), functionIndex, calleeGroup.mode(), Plan::dontFinalize()));
101
        ensureWorklist().enqueue(plan.copyRef());
101
        ensureWorklist().enqueue(plan.copyRef());
102
        if (UNLIKELY(!Options::useConcurrentJIT()))
102
        if (UNLIKELY(!Options::useConcurrentJIT()))
103
            plan->waitForCompletion();
103
            plan->waitForCompletion();
Lines 234-245 JSC_DEFINE_JIT_OPERATION(operationWasmTriggerOSREntryNow, void, (Probe::Context& a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec3
234
        context.gpr(GPRInfo::argumentGPR0) = 0;
234
        context.gpr(GPRInfo::argumentGPR0) = 0;
235
    };
235
    };
236
236
237
    Wasm::CodeBlock& codeBlock = *instance->codeBlock();
237
    Wasm::CalleeGroup& calleeGroup = *instance->calleeGroup();
238
    ASSERT(instance->memory()->mode() == codeBlock.mode());
238
    ASSERT(instance->memory()->mode() == calleeGroup.mode());
239
239
240
    uint32_t functionIndexInSpace = functionIndex + codeBlock.functionImportCount();
240
    uint32_t functionIndexInSpace = functionIndex + calleeGroup.functionImportCount();
241
    ASSERT(codeBlock.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace).compilationMode() == Wasm::CompilationMode::BBQMode);
241
    ASSERT(calleeGroup.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace).compilationMode() == Wasm::CompilationMode::BBQMode);
242
    BBQCallee& callee = static_cast<BBQCallee&>(codeBlock.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace));
242
    BBQCallee& callee = static_cast<BBQCallee&>(calleeGroup.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace));
243
    TierUpCount& tierUp = *callee.tierUpCount();
243
    TierUpCount& tierUp = *callee.tierUpCount();
244
244
245
    if (!shouldJIT(functionIndex)) {
245
    if (!shouldJIT(functionIndex)) {
Lines 251-257 JSC_DEFINE_JIT_OPERATION(operationWasmTriggerOSREntryNow, void, (Probe::Context& a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec4
251
251
252
    if (!Options::useWebAssemblyOSR()) {
252
    if (!Options::useWebAssemblyOSR()) {
253
        if (shouldTriggerOMGCompile(tierUp, callee.replacement(), functionIndex))
253
        if (shouldTriggerOMGCompile(tierUp, callee.replacement(), functionIndex))
254
            triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
254
            triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, calleeGroup, functionIndex);
255
255
256
        // We already have an OMG replacement.
256
        // We already have an OMG replacement.
257
        if (callee.replacement()) {
257
        if (callee.replacement()) {
Lines 316-322 JSC_DEFINE_JIT_OPERATION(operationWasmTriggerOSREntryNow, void, (Probe::Context& a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec5
316
        return returnWithoutOSREntry();
316
        return returnWithoutOSREntry();
317
317
318
    if (!triggeredSlowPathToStartCompilation) {
318
    if (!triggeredSlowPathToStartCompilation) {
319
        triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
319
        triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, calleeGroup, functionIndex);
320
320
321
        if (!callee.replacement())
321
        if (!callee.replacement())
322
            return returnWithoutOSREntry();
322
            return returnWithoutOSREntry();
Lines 390-396 JSC_DEFINE_JIT_OPERATION(operationWasmTriggerOSREntryNow, void, (Probe::Context& a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec6
390
390
391
    if (startOSREntryCompilation) {
391
    if (startOSREntryCompilation) {
392
        dataLogLnIf(Options::verboseOSR(), "triggerOMGOSR for ", functionIndex);
392
        dataLogLnIf(Options::verboseOSR(), "triggerOMGOSR for ", functionIndex);
393
        Ref<Plan> plan = adoptRef(*new OMGForOSREntryPlan(instance->context(), Ref<Wasm::Module>(instance->module()), Ref<Wasm::BBQCallee>(callee), functionIndex, loopIndex, codeBlock.mode(), Plan::dontFinalize()));
393
        Ref<Plan> plan = adoptRef(*new OMGForOSREntryPlan(instance->context(), Ref<Wasm::Module>(instance->module()), Ref<Wasm::BBQCallee>(callee), functionIndex, loopIndex, calleeGroup.mode(), Plan::dontFinalize()));
394
        ensureWorklist().enqueue(plan.copyRef());
394
        ensureWorklist().enqueue(plan.copyRef());
395
        if (UNLIKELY(!Options::useConcurrentJIT()))
395
        if (UNLIKELY(!Options::useConcurrentJIT()))
396
            plan->waitForCompletion();
396
            plan->waitForCompletion();
Lines 413-424 JSC_DEFINE_JIT_OPERATION(operationWasmTriggerOSREntryNow, void, (Probe::Context& a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec7
413
413
414
JSC_DEFINE_JIT_OPERATION(operationWasmTriggerTierUpNow, void, (Instance* instance, uint32_t functionIndex))
414
JSC_DEFINE_JIT_OPERATION(operationWasmTriggerTierUpNow, void, (Instance* instance, uint32_t functionIndex))
415
{
415
{
416
    Wasm::CodeBlock& codeBlock = *instance->codeBlock();
416
    Wasm::CalleeGroup& calleeGroup = *instance->calleeGroup();
417
    ASSERT(instance->memory()->mode() == codeBlock.mode());
417
    ASSERT(instance->memory()->mode() == calleeGroup.mode());
418
418
419
    uint32_t functionIndexInSpace = functionIndex + codeBlock.functionImportCount();
419
    uint32_t functionIndexInSpace = functionIndex + calleeGroup.functionImportCount();
420
    ASSERT(codeBlock.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace).compilationMode() == Wasm::CompilationMode::BBQMode);
420
    ASSERT(calleeGroup.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace).compilationMode() == Wasm::CompilationMode::BBQMode);
421
    BBQCallee& callee = static_cast<BBQCallee&>(codeBlock.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace));
421
    BBQCallee& callee = static_cast<BBQCallee&>(calleeGroup.wasmBBQCalleeFromFunctionIndexSpace(functionIndexInSpace));
422
    TierUpCount& tierUp = *callee.tierUpCount();
422
    TierUpCount& tierUp = *callee.tierUpCount();
423
423
424
    if (!shouldJIT(functionIndex)) {
424
    if (!shouldJIT(functionIndex)) {
Lines 429-435 JSC_DEFINE_JIT_OPERATION(operationWasmTriggerTierUpNow, void, (Instance* instanc a/Source/JavaScriptCore/wasm/WasmOperations.cpp_sec8
429
    dataLogLnIf(Options::verboseOSR(), "Consider OMGPlan for [", functionIndex, "] with executeCounter = ", tierUp, " ", RawPointer(callee.replacement()));
429
    dataLogLnIf(Options::verboseOSR(), "Consider OMGPlan for [", functionIndex, "] with executeCounter = ", tierUp, " ", RawPointer(callee.replacement()));
430
430
431
    if (shouldTriggerOMGCompile(tierUp, callee.replacement(), functionIndex))
431
    if (shouldTriggerOMGCompile(tierUp, callee.replacement(), functionIndex))
432
        triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, codeBlock, functionIndex);
432
        triggerOMGReplacementCompile(tierUp, callee.replacement(), instance, calleeGroup, functionIndex);
433
433
434
    // We already have an OMG replacement.
434
    // We already have an OMG replacement.
435
    if (callee.replacement()) {
435
    if (callee.replacement()) {
- a/Source/JavaScriptCore/wasm/WasmPlan.cpp -17 / +17 lines
Lines 29-35 a/Source/JavaScriptCore/wasm/WasmPlan.cpp_sec1
29
#if ENABLE(WEBASSEMBLY)
29
#if ENABLE(WEBASSEMBLY)
30
30
31
#include "WasmCallee.h"
31
#include "WasmCallee.h"
32
#include "WasmCodeBlock.h"
32
#include "WasmCalleeGroup.h"
33
#include "WasmMachineThreads.h"
33
#include "WasmMachineThreads.h"
34
#include <wtf/DataLog.h>
34
#include <wtf/DataLog.h>
35
#include <wtf/Locker.h>
35
#include <wtf/Locker.h>
Lines 124-130 void Plan::fail(String&& errorMessage) a/Source/JavaScriptCore/wasm/WasmPlan.cpp_sec2
124
}
124
}
125
125
126
#if ENABLE(WEBASSEMBLY_B3JIT)
126
#if ENABLE(WEBASSEMBLY_B3JIT)
127
void Plan::updateCallSitesToCallUs(CodeBlock& codeBlock, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace)
127
void Plan::updateCallSitesToCallUs(CalleeGroup& calleeGroup, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace)
128
{
128
{
129
    HashMap<void*, CodeLocationLabel<WasmEntryPtrTag>> stagedCalls;
129
    HashMap<void*, CodeLocationLabel<WasmEntryPtrTag>> stagedCalls;
130
    auto stageRepatch = [&] (const auto& callsites) {
130
    auto stageRepatch = [&] (const auto& callsites) {
Lines 135-150 void Plan::updateCallSitesToCallUs(CodeBlock& codeBlock, CodeLocationLabel<WasmE a/Source/JavaScriptCore/wasm/WasmPlan.cpp_sec3
135
            }
135
            }
136
        }
136
        }
137
    };
137
    };
138
    for (unsigned i = 0; i < codeBlock.m_wasmToWasmCallsites.size(); ++i) {
138
    for (unsigned i = 0; i < calleeGroup.m_wasmToWasmCallsites.size(); ++i) {
139
        stageRepatch(codeBlock.m_wasmToWasmCallsites[i]);
139
        stageRepatch(calleeGroup.m_wasmToWasmCallsites[i]);
140
        if (codeBlock.m_llintCallees) {
140
        if (calleeGroup.m_llintCallees) {
141
            LLIntCallee& llintCallee = codeBlock.m_llintCallees->at(i).get();
141
            LLIntCallee& llintCallee = calleeGroup.m_llintCallees->at(i).get();
142
            if (JITCallee* replacementCallee = llintCallee.replacement(codeBlock.mode()))
142
            if (JITCallee* replacementCallee = llintCallee.replacement(calleeGroup.mode()))
143
                stageRepatch(replacementCallee->wasmToWasmCallsites());
143
                stageRepatch(replacementCallee->wasmToWasmCallsites());
144
            if (OMGForOSREntryCallee* osrEntryCallee = llintCallee.osrEntryCallee(codeBlock.mode()))
144
            if (OMGForOSREntryCallee* osrEntryCallee = llintCallee.osrEntryCallee(calleeGroup.mode()))
145
                stageRepatch(osrEntryCallee->wasmToWasmCallsites());
145
                stageRepatch(osrEntryCallee->wasmToWasmCallsites());
146
        }
146
        }
147
        if (BBQCallee* bbqCallee = codeBlock.m_bbqCallees[i].get()) {
147
        if (BBQCallee* bbqCallee = calleeGroup.m_bbqCallees[i].get()) {
148
            if (OMGCallee* replacementCallee = bbqCallee->replacement())
148
            if (OMGCallee* replacementCallee = bbqCallee->replacement())
149
                stageRepatch(replacementCallee->wasmToWasmCallsites());
149
                stageRepatch(replacementCallee->wasmToWasmCallsites());
150
            if (OMGForOSREntryCallee* osrEntryCallee = bbqCallee->osrEntryCallee())
150
            if (OMGForOSREntryCallee* osrEntryCallee = bbqCallee->osrEntryCallee())
Lines 158-164 void Plan::updateCallSitesToCallUs(CodeBlock& codeBlock, CodeLocationLabel<WasmE a/Source/JavaScriptCore/wasm/WasmPlan.cpp_sec4
158
    resetInstructionCacheOnAllThreads();
158
    resetInstructionCacheOnAllThreads();
159
    WTF::storeStoreFence(); // This probably isn't necessary but it's good to be paranoid.
159
    WTF::storeStoreFence(); // This probably isn't necessary but it's good to be paranoid.
160
160
161
    codeBlock.m_wasmIndirectCallEntryPoints[functionIndex] = entrypoint;
161
    calleeGroup.m_wasmIndirectCallEntryPoints[functionIndex] = entrypoint;
162
162
163
    auto repatchCalls = [&] (const auto& callsites) {
163
    auto repatchCalls = [&] (const auto& callsites) {
164
        for (auto& call : callsites) {
164
        for (auto& call : callsites) {
Lines 170-185 void Plan::updateCallSitesToCallUs(CodeBlock& codeBlock, CodeLocationLabel<WasmE a/Source/JavaScriptCore/wasm/WasmPlan.cpp_sec5
170
        }
170
        }
171
    };
171
    };
172
172
173
    for (unsigned i = 0; i < codeBlock.m_wasmToWasmCallsites.size(); ++i) {
173
    for (unsigned i = 0; i < calleeGroup.m_wasmToWasmCallsites.size(); ++i) {
174
        repatchCalls(codeBlock.m_wasmToWasmCallsites[i]);
174
        repatchCalls(calleeGroup.m_wasmToWasmCallsites[i]);
175
        if (codeBlock.m_llintCallees) {
175
        if (calleeGroup.m_llintCallees) {
176
            LLIntCallee& llintCallee = codeBlock.m_llintCallees->at(i).get();
176
            LLIntCallee& llintCallee = calleeGroup.m_llintCallees->at(i).get();
177
            if (JITCallee* replacementCallee = llintCallee.replacement(codeBlock.mode()))
177
            if (JITCallee* replacementCallee = llintCallee.replacement(calleeGroup.mode()))
178
                repatchCalls(replacementCallee->wasmToWasmCallsites());
178
                repatchCalls(replacementCallee->wasmToWasmCallsites());
179
            if (OMGForOSREntryCallee* osrEntryCallee = llintCallee.osrEntryCallee(codeBlock.mode()))
179
            if (OMGForOSREntryCallee* osrEntryCallee = llintCallee.osrEntryCallee(calleeGroup.mode()))
180
                repatchCalls(osrEntryCallee->wasmToWasmCallsites());
180
                repatchCalls(osrEntryCallee->wasmToWasmCallsites());
181
        }
181
        }
182
        if (BBQCallee* bbqCallee = codeBlock.m_bbqCallees[i].get()) {
182
        if (BBQCallee* bbqCallee = calleeGroup.m_bbqCallees[i].get()) {
183
            if (OMGCallee* replacementCallee = bbqCallee->replacement())
183
            if (OMGCallee* replacementCallee = bbqCallee->replacement())
184
                repatchCalls(replacementCallee->wasmToWasmCallsites());
184
                repatchCalls(replacementCallee->wasmToWasmCallsites());
185
            if (OMGForOSREntryCallee* osrEntryCallee = bbqCallee->osrEntryCallee())
185
            if (OMGForOSREntryCallee* osrEntryCallee = bbqCallee->osrEntryCallee())
- a/Source/JavaScriptCore/wasm/WasmPlan.h -2 / +2 lines
Lines 43-49 class CallLinkInfo; a/Source/JavaScriptCore/wasm/WasmPlan.h_sec1
43
43
44
namespace Wasm {
44
namespace Wasm {
45
45
46
class CodeBlock;
46
class CalleeGroup;
47
struct Context;
47
struct Context;
48
48
49
class Plan : public ThreadSafeRefCounted<Plan> {
49
class Plan : public ThreadSafeRefCounted<Plan> {
Lines 85-91 class Plan : public ThreadSafeRefCounted<Plan> { a/Source/JavaScriptCore/wasm/WasmPlan.h_sec2
85
    virtual void complete() WTF_REQUIRES_LOCK(m_lock) = 0;
85
    virtual void complete() WTF_REQUIRES_LOCK(m_lock) = 0;
86
86
87
#if ENABLE(WEBASSEMBLY_B3JIT)
87
#if ENABLE(WEBASSEMBLY_B3JIT)
88
    static void updateCallSitesToCallUs(CodeBlock&, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace);
88
    static void updateCallSitesToCallUs(CalleeGroup&, CodeLocationLabel<WasmEntryPtrTag> entrypoint, uint32_t functionIndex, uint32_t functionIndexSpace);
89
#endif
89
#endif
90
90
91
    Ref<ModuleInformation> m_moduleInformation;
91
    Ref<ModuleInformation> m_moduleInformation;
- a/Source/JavaScriptCore/wasm/WasmSlowPaths.cpp -3 / +3 lines
Lines 132-138 inline bool jitCompileAndSetHeuristics(Wasm::LLIntCallee* callee, Wasm::Function a/Source/JavaScriptCore/wasm/WasmSlowPaths.cpp_sec1
132
        uint32_t functionIndex = codeBlock->functionIndex();
132
        uint32_t functionIndex = codeBlock->functionIndex();
133
        RefPtr<Wasm::Plan> plan;
133
        RefPtr<Wasm::Plan> plan;
134
        if (Options::wasmLLIntTiersUpToBBQ())
134
        if (Options::wasmLLIntTiersUpToBBQ())
135
            plan = adoptRef(*new Wasm::BBQPlan(instance->context(), const_cast<Wasm::ModuleInformation&>(instance->module().moduleInformation()), functionIndex, instance->codeBlock(), Wasm::Plan::dontFinalize()));
135
            plan = adoptRef(*new Wasm::BBQPlan(instance->context(), const_cast<Wasm::ModuleInformation&>(instance->module().moduleInformation()), functionIndex, instance->calleeGroup(), Wasm::Plan::dontFinalize()));
136
        else
136
        else
137
            plan = adoptRef(*new Wasm::OMGPlan(instance->context(), Ref<Wasm::Module>(instance->module()), functionIndex, instance->memory()->mode(), Wasm::Plan::dontFinalize()));
137
            plan = adoptRef(*new Wasm::OMGPlan(instance->context(), Ref<Wasm::Module>(instance->module()), functionIndex, instance->memory()->mode(), Wasm::Plan::dontFinalize()));
138
138
Lines 435-448 inline SlowPathReturnType doWasmCall(Wasm::Instance* instance, unsigned function a/Source/JavaScriptCore/wasm/WasmSlowPaths.cpp_sec2
435
        Wasm::Instance::ImportFunctionInfo* functionInfo = instance->importFunctionInfo(functionIndex);
435
        Wasm::Instance::ImportFunctionInfo* functionInfo = instance->importFunctionInfo(functionIndex);
436
        if (functionInfo->targetInstance) {
436
        if (functionInfo->targetInstance) {
437
            // target is a wasm function from a different instance
437
            // target is a wasm function from a different instance
438
            codePtr = instance->codeBlock()->wasmToWasmExitStub(functionIndex);
438
            codePtr = instance->calleeGroup()->wasmToWasmExitStub(functionIndex);
439
        } else {
439
        } else {
440
            // target is JS
440
            // target is JS
441
            codePtr = functionInfo->wasmToEmbedderStub;
441
            codePtr = functionInfo->wasmToEmbedderStub;
442
        }
442
        }
443
    } else {
443
    } else {
444
        // Target is a wasm function within the same instance
444
        // Target is a wasm function within the same instance
445
        codePtr = *instance->codeBlock()->entrypointLoadLocationFromFunctionIndexSpace(functionIndex);
445
        codePtr = *instance->calleeGroup()->entrypointLoadLocationFromFunctionIndexSpace(functionIndex);
446
    }
446
    }
447
447
448
    WASM_CALL_RETURN(instance, codePtr.executableAddress(), WasmEntryPtrTag);
448
    WASM_CALL_RETURN(instance, codePtr.executableAddress(), WasmEntryPtrTag);
- a/Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp -6 / +6 lines
Lines 138-147 JSC_DEFINE_HOST_FUNCTION(webAssemblyCompileFunc, (JSGlobalObject* globalObject, a/Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp_sec1
138
}
138
}
139
139
140
enum class Resolve { WithInstance, WithModuleRecord, WithModuleAndInstance };
140
enum class Resolve { WithInstance, WithModuleRecord, WithModuleAndInstance };
141
static void resolve(VM& vm, JSGlobalObject* globalObject, JSPromise* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, JSObject* importObject, Ref<Wasm::CodeBlock>&& codeBlock, Resolve resolveKind, Wasm::CreationMode creationMode)
141
static void resolve(VM& vm, JSGlobalObject* globalObject, JSPromise* promise, JSWebAssemblyInstance* instance, JSWebAssemblyModule* module, JSObject* importObject, Ref<Wasm::CalleeGroup>&& calleeGroup, Resolve resolveKind, Wasm::CreationMode creationMode)
142
{
142
{
143
    auto scope = DECLARE_THROW_SCOPE(vm);
143
    auto scope = DECLARE_THROW_SCOPE(vm);
144
    instance->finalizeCreation(vm, globalObject, WTFMove(codeBlock), importObject, creationMode);
144
    instance->finalizeCreation(vm, globalObject, WTFMove(calleeGroup), importObject, creationMode);
145
    if (UNLIKELY(scope.exception())) {
145
    if (UNLIKELY(scope.exception())) {
146
        promise->rejectWithCaughtException(globalObject, scope);
146
        promise->rejectWithCaughtException(globalObject, scope);
147
        return;
147
        return;
Lines 204-214 static void instantiate(VM& vm, JSGlobalObject* globalObject, JSPromise* promise a/Source/JavaScriptCore/wasm/js/JSWebAssembly.cpp_sec2
204
204
205
    vm.deferredWorkTimer->addPendingWork(vm, instance, WTFMove(dependencies));
205
    vm.deferredWorkTimer->addPendingWork(vm, instance, WTFMove(dependencies));
206
    // Note: This completion task may or may not get called immediately.
206
    // Note: This completion task may or may not get called immediately.
207
    module->module().compileAsync(&vm.wasmContext, instance->memoryMode(), createSharedTask<Wasm::CodeBlock::CallbackType>([promise, instance, module, importObject, resolveKind, creationMode, &vm] (Ref<Wasm::CodeBlock>&& refCodeBlock) mutable {
207
    module->module().compileAsync(&vm.wasmContext, instance->memoryMode(), createSharedTask<Wasm::CalleeGroup::CallbackType>([promise, instance, module, importObject, resolveKind, creationMode, &vm] (Ref<Wasm::CalleeGroup>&& refCalleeGroup) mutable {
208
        RefPtr<Wasm::CodeBlock> codeBlock = WTFMove(refCodeBlock);
208
        RefPtr<Wasm::CalleeGroup> calleeGroup = WTFMove(refCalleeGroup);
209
        vm.deferredWorkTimer->scheduleWorkSoon(instance, [promise, instance, module, importObject, resolveKind, creationMode, &vm, codeBlock = WTFMove(codeBlock)](DeferredWorkTimer::Ticket, DeferredWorkTimer::TicketData&&) mutable {
209
        vm.deferredWorkTimer->scheduleWorkSoon(instance, [promise, instance, module, importObject, resolveKind, creationMode, &vm, calleeGroup = WTFMove(calleeGroup)](DeferredWorkTimer::Ticket, DeferredWorkTimer::TicketData&&) mutable {
210
            JSGlobalObject* globalObject = instance->globalObject();
210
            JSGlobalObject* globalObject = instance->globalObject();
211
            resolve(vm, globalObject, promise, instance, module, importObject, codeBlock.releaseNonNull(), resolveKind, creationMode);
211
            resolve(vm, globalObject, promise, instance, module, importObject, calleeGroup.releaseNonNull(), resolveKind, creationMode);
212
        });
212
        });
213
    }));
213
    }));
214
}
214
}
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCalleeGroup.cpp +104 lines
Line 0 a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCalleeGroup.cpp_sec1
1
/*
2
 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "JSWebAssemblyCalleeGroup.h"
28
29
#if ENABLE(WEBASSEMBLY)
30
31
#include "JSCJSValueInlines.h"
32
#include "JSCellInlines.h"
33
#include "WasmModuleInformation.h"
34
#include "WasmToJS.h"
35
36
namespace JSC {
37
38
const ClassInfo JSWebAssemblyCalleeGroup::s_info = { "WebAssemblyCalleeGroup", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebAssemblyCalleeGroup) };
39
40
JSWebAssemblyCalleeGroup* JSWebAssemblyCalleeGroup::create(VM& vm, Ref<Wasm::CalleeGroup> calleeGroup, const Wasm::ModuleInformation& moduleInformation)
41
{
42
    auto* result = new (NotNull, allocateCell<JSWebAssemblyCalleeGroup>(vm)) JSWebAssemblyCalleeGroup(vm, WTFMove(calleeGroup), moduleInformation);
43
    result->finishCreation(vm);
44
    return result;
45
}
46
47
JSWebAssemblyCalleeGroup::JSWebAssemblyCalleeGroup(VM& vm, Ref<Wasm::CalleeGroup>&& calleeGroup, const Wasm::ModuleInformation& moduleInformation)
48
    : Base(vm, vm.webAssemblyCalleeGroupStructure.get())
49
    , m_calleeGroup(WTFMove(calleeGroup))
50
    , m_wasmToJSExitStubs(m_calleeGroup->functionImportCount())
51
{
52
    // FIXME: We should not need to do this synchronously.
53
    // https://bugs.webkit.org/show_bug.cgi?id=170567
54
    for (unsigned importIndex = 0; importIndex < m_calleeGroup->functionImportCount(); ++importIndex) {
55
        Wasm::SignatureIndex signatureIndex = moduleInformation.importFunctionSignatureIndices.at(importIndex);
56
        auto binding = Wasm::wasmToJS(vm, m_callLinkInfos, signatureIndex, importIndex);
57
        if (UNLIKELY(!binding)) {
58
            switch (binding.error()) {
59
            case Wasm::BindingFailure::OutOfMemory:
60
                m_errorMessage = "Out of executable memory"_s;
61
                return;
62
            }
63
            RELEASE_ASSERT_NOT_REACHED();
64
        }
65
        m_wasmToJSExitStubs[importIndex] = binding.value();
66
    }
67
}
68
69
void JSWebAssemblyCalleeGroup::finishCreation(VM& vm)
70
{
71
    Base::finishCreation(vm);
72
}
73
74
void JSWebAssemblyCalleeGroup::destroy(JSCell* cell)
75
{
76
    static_cast<JSWebAssemblyCalleeGroup*>(cell)->JSWebAssemblyCalleeGroup::~JSWebAssemblyCalleeGroup();
77
}
78
79
void JSWebAssemblyCalleeGroup::clearJSCallICs(VM& vm)
80
{
81
    for (auto iter = m_callLinkInfos.begin(); !!iter; ++iter)
82
        (*iter)->unlink(vm);
83
}
84
85
template<typename Visitor>
86
void JSWebAssemblyCalleeGroup::visitChildrenImpl(JSCell* cell, Visitor& visitor)
87
{
88
    JSWebAssemblyCalleeGroup* thisObject = jsCast<JSWebAssemblyCalleeGroup*>(cell);
89
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
90
91
    Base::visitChildren(thisObject, visitor);
92
}
93
94
DEFINE_VISIT_CHILDREN(JSWebAssemblyCalleeGroup);
95
96
void JSWebAssemblyCalleeGroup::finalizeUnconditionally(VM& vm)
97
{
98
    for (auto iter = m_callLinkInfos.begin(); !!iter; ++iter)
99
        (*iter)->visitWeak(vm);
100
}
101
102
} // namespace JSC
103
104
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCalleeGroup.h +99 lines
Line 0 a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCalleeGroup.h_sec1
1
/*
2
 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBASSEMBLY)
29
30
#include "CallLinkInfo.h"
31
#include "DeferredWorkTimer.h"
32
#include "JSCast.h"
33
#include "Structure.h"
34
#include "WasmCallee.h"
35
#include "WasmFormat.h"
36
#include "WasmModule.h"
37
#include <wtf/Bag.h>
38
#include <wtf/Ref.h>
39
#include <wtf/Vector.h>
40
41
namespace JSC {
42
43
class JSWebAssemblyMemory;
44
45
namespace Wasm {
46
class Plan;
47
}
48
49
class JSWebAssemblyCalleeGroup final : public JSCell {
50
public:
51
    typedef JSCell Base;
52
    static constexpr unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
53
54
    static JSWebAssemblyCalleeGroup* create(VM&, Ref<Wasm::CalleeGroup>, const Wasm::ModuleInformation&);
55
    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
56
    {
57
        return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
58
    }
59
60
    template<typename CellType, SubspaceAccess mode>
61
    static IsoSubspace* subspaceFor(VM& vm)
62
    {
63
        return vm.webAssemblyCalleeGroupSpace<mode>();
64
    }
65
66
    Wasm::CalleeGroup& calleeGroup() { return m_calleeGroup.get(); }
67
    
68
    MacroAssemblerCodePtr<WasmEntryPtrTag> wasmToEmbedderStub(size_t importFunctionNum) { return m_wasmToJSExitStubs[importFunctionNum].code(); }
69
70
    void finishCreation(VM&);
71
72
    void clearJSCallICs(VM&);
73
74
    bool runnable() const { return !m_errorMessage; }
75
76
    String errorMessage()
77
    {
78
        ASSERT(!runnable());
79
        return m_errorMessage;
80
    }
81
82
    void finalizeUnconditionally(VM&);
83
84
private:
85
    JSWebAssemblyCalleeGroup(VM&, Ref<Wasm::CalleeGroup>&&, const Wasm::ModuleInformation&);
86
    DECLARE_EXPORT_INFO;
87
    static constexpr bool needsDestruction = true;
88
    static void destroy(JSCell*);
89
    DECLARE_VISIT_CHILDREN;
90
91
    Ref<Wasm::CalleeGroup> m_calleeGroup;
92
    FixedVector<MacroAssemblerCodeRef<WasmEntryPtrTag>> m_wasmToJSExitStubs;
93
    Bag<OptimizingCallLinkInfo> m_callLinkInfos;
94
    String m_errorMessage;
95
};
96
97
} // namespace JSC
98
99
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.cpp -104 lines
Lines 1-104 a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.cpp_sec1
1
/*
2
 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#include "config.h"
27
#include "JSWebAssemblyCodeBlock.h"
28
29
#if ENABLE(WEBASSEMBLY)
30
31
#include "JSCJSValueInlines.h"
32
#include "JSCellInlines.h"
33
#include "WasmModuleInformation.h"
34
#include "WasmToJS.h"
35
36
namespace JSC {
37
38
const ClassInfo JSWebAssemblyCodeBlock::s_info = { "WebAssemblyCodeBlock", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(JSWebAssemblyCodeBlock) };
39
40
JSWebAssemblyCodeBlock* JSWebAssemblyCodeBlock::create(VM& vm, Ref<Wasm::CodeBlock> codeBlock, const Wasm::ModuleInformation& moduleInformation)
41
{
42
    auto* result = new (NotNull, allocateCell<JSWebAssemblyCodeBlock>(vm)) JSWebAssemblyCodeBlock(vm, WTFMove(codeBlock), moduleInformation);
43
    result->finishCreation(vm);
44
    return result;
45
}
46
47
JSWebAssemblyCodeBlock::JSWebAssemblyCodeBlock(VM& vm, Ref<Wasm::CodeBlock>&& codeBlock, const Wasm::ModuleInformation& moduleInformation)
48
    : Base(vm, vm.webAssemblyCodeBlockStructure.get())
49
    , m_codeBlock(WTFMove(codeBlock))
50
    , m_wasmToJSExitStubs(m_codeBlock->functionImportCount())
51
{
52
    // FIXME: We should not need to do this synchronously.
53
    // https://bugs.webkit.org/show_bug.cgi?id=170567
54
    for (unsigned importIndex = 0; importIndex < m_codeBlock->functionImportCount(); ++importIndex) {
55
        Wasm::SignatureIndex signatureIndex = moduleInformation.importFunctionSignatureIndices.at(importIndex);
56
        auto binding = Wasm::wasmToJS(vm, m_callLinkInfos, signatureIndex, importIndex);
57
        if (UNLIKELY(!binding)) {
58
            switch (binding.error()) {
59
            case Wasm::BindingFailure::OutOfMemory:
60
                m_errorMessage = "Out of executable memory"_s;
61
                return;
62
            }
63
            RELEASE_ASSERT_NOT_REACHED();
64
        }
65
        m_wasmToJSExitStubs[importIndex] = binding.value();
66
    }
67
}
68
69
void JSWebAssemblyCodeBlock::finishCreation(VM& vm)
70
{
71
    Base::finishCreation(vm);
72
}
73
74
void JSWebAssemblyCodeBlock::destroy(JSCell* cell)
75
{
76
    static_cast<JSWebAssemblyCodeBlock*>(cell)->JSWebAssemblyCodeBlock::~JSWebAssemblyCodeBlock();
77
}
78
79
void JSWebAssemblyCodeBlock::clearJSCallICs(VM& vm)
80
{
81
    for (auto iter = m_callLinkInfos.begin(); !!iter; ++iter)
82
        (*iter)->unlink(vm);
83
}
84
85
template<typename Visitor>
86
void JSWebAssemblyCodeBlock::visitChildrenImpl(JSCell* cell, Visitor& visitor)
87
{
88
    JSWebAssemblyCodeBlock* thisObject = jsCast<JSWebAssemblyCodeBlock*>(cell);
89
    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
90
91
    Base::visitChildren(thisObject, visitor);
92
}
93
94
DEFINE_VISIT_CHILDREN(JSWebAssemblyCodeBlock);
95
96
void JSWebAssemblyCodeBlock::finalizeUnconditionally(VM& vm)
97
{
98
    for (auto iter = m_callLinkInfos.begin(); !!iter; ++iter)
99
        (*iter)->visitWeak(vm);
100
}
101
102
} // namespace JSC
103
104
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.h -99 lines
Lines 1-99 a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCodeBlock.h_sec1
1
/*
2
 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBASSEMBLY)
29
30
#include "CallLinkInfo.h"
31
#include "DeferredWorkTimer.h"
32
#include "JSCast.h"
33
#include "Structure.h"
34
#include "WasmCallee.h"
35
#include "WasmFormat.h"
36
#include "WasmModule.h"
37
#include <wtf/Bag.h>
38
#include <wtf/Ref.h>
39
#include <wtf/Vector.h>
40
41
namespace JSC {
42
43
class JSWebAssemblyMemory;
44
45
namespace Wasm {
46
class Plan;
47
}
48
49
class JSWebAssemblyCodeBlock final : public JSCell {
50
public:
51
    typedef JSCell Base;
52
    static constexpr unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
53
54
    static JSWebAssemblyCodeBlock* create(VM&, Ref<Wasm::CodeBlock>, const Wasm::ModuleInformation&);
55
    static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
56
    {
57
        return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
58
    }
59
60
    template<typename CellType, SubspaceAccess mode>
61
    static IsoSubspace* subspaceFor(VM& vm)
62
    {
63
        return vm.webAssemblyCodeBlockSpace<mode>();
64
    }
65
66
    Wasm::CodeBlock& codeBlock() { return m_codeBlock.get(); }
67
    
68
    MacroAssemblerCodePtr<WasmEntryPtrTag> wasmToEmbedderStub(size_t importFunctionNum) { return m_wasmToJSExitStubs[importFunctionNum].code(); }
69
70
    void finishCreation(VM&);
71
72
    void clearJSCallICs(VM&);
73
74
    bool runnable() const { return !m_errorMessage; }
75
76
    String errorMessage()
77
    {
78
        ASSERT(!runnable());
79
        return m_errorMessage;
80
    }
81
82
    void finalizeUnconditionally(VM&);
83
84
private:
85
    JSWebAssemblyCodeBlock(VM&, Ref<Wasm::CodeBlock>&&, const Wasm::ModuleInformation&);
86
    DECLARE_EXPORT_INFO;
87
    static constexpr bool needsDestruction = true;
88
    static void destroy(JSCell*);
89
    DECLARE_VISIT_CHILDREN;
90
91
    Ref<Wasm::CodeBlock> m_codeBlock;
92
    FixedVector<MacroAssemblerCodeRef<WasmEntryPtrTag>> m_wasmToJSExitStubs;
93
    Bag<OptimizingCallLinkInfo> m_callLinkInfos;
94
    String m_errorMessage;
95
};
96
97
} // namespace JSC
98
99
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp -25 / +25 lines
Lines 81-87 void JSWebAssemblyInstance::visitChildrenImpl(JSCell* cell, Visitor& visitor) a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp_sec1
81
81
82
    Base::visitChildren(thisObject, visitor);
82
    Base::visitChildren(thisObject, visitor);
83
    visitor.append(thisObject->m_module);
83
    visitor.append(thisObject->m_module);
84
    visitor.append(thisObject->m_codeBlock);
84
    visitor.append(thisObject->m_calleeGroup);
85
    visitor.append(thisObject->m_moduleRecord);
85
    visitor.append(thisObject->m_moduleRecord);
86
    visitor.append(thisObject->m_memory);
86
    visitor.append(thisObject->m_memory);
87
    for (auto& table : thisObject->m_tables)
87
    for (auto& table : thisObject->m_tables)
Lines 105-166 void JSWebAssemblyInstance::visitChildrenImpl(JSCell* cell, Visitor& visitor) a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp_sec2
105
105
106
DEFINE_VISIT_CHILDREN(JSWebAssemblyInstance);
106
DEFINE_VISIT_CHILDREN(JSWebAssemblyInstance);
107
107
108
void JSWebAssemblyInstance::finalizeCreation(VM& vm, JSGlobalObject* globalObject, Ref<Wasm::CodeBlock>&& wasmCodeBlock, JSObject* importObject, Wasm::CreationMode creationMode)
108
void JSWebAssemblyInstance::finalizeCreation(VM& vm, JSGlobalObject* globalObject, Ref<Wasm::CalleeGroup>&& wasmCalleeGroup, JSObject* importObject, Wasm::CreationMode creationMode)
109
{
109
{
110
    m_instance->finalizeCreation(this);
110
    m_instance->finalizeCreation(this);
111
111
112
    auto scope = DECLARE_THROW_SCOPE(vm);
112
    auto scope = DECLARE_THROW_SCOPE(vm);
113
113
114
    if (!wasmCodeBlock->runnable()) {
114
    if (!wasmCalleeGroup->runnable()) {
115
        throwException(globalObject, scope, createJSWebAssemblyLinkError(globalObject, vm, wasmCodeBlock->errorMessage()));
115
        throwException(globalObject, scope, createJSWebAssemblyLinkError(globalObject, vm, wasmCalleeGroup->errorMessage()));
116
        return;
116
        return;
117
    }
117
    }
118
118
119
    RELEASE_ASSERT(wasmCodeBlock->isSafeToRun(memoryMode()));
119
    RELEASE_ASSERT(wasmCalleeGroup->isSafeToRun(memoryMode()));
120
    JSWebAssemblyCodeBlock* jsCodeBlock = m_module->codeBlock(memoryMode());
120
    JSWebAssemblyCalleeGroup* jsCalleeGroup = m_module->calleeGroup(memoryMode());
121
    if (jsCodeBlock) {
121
    if (jsCalleeGroup) {
122
        // A CodeBlock might have already been compiled. If so, it means
122
        // A CalleeGroup might have already been compiled. If so, it means
123
        // that the CodeBlock we are trying to compile must be the same
123
        // that the CalleeGroup we are trying to compile must be the same
124
        // because we will never compile a CodeBlock again once it's
124
        // because we will never compile a CalleeGroup again once it's
125
        // runnable.
125
        // runnable.
126
        ASSERT(&jsCodeBlock->codeBlock() == wasmCodeBlock.ptr());
126
        ASSERT(&jsCalleeGroup->calleeGroup() == wasmCalleeGroup.ptr());
127
        m_codeBlock.set(vm, this, jsCodeBlock);
127
        m_calleeGroup.set(vm, this, jsCalleeGroup);
128
    } else {
128
    } else {
129
        jsCodeBlock = JSWebAssemblyCodeBlock::create(vm, WTFMove(wasmCodeBlock), module()->module().moduleInformation());
129
        jsCalleeGroup = JSWebAssemblyCalleeGroup::create(vm, WTFMove(wasmCalleeGroup), module()->module().moduleInformation());
130
        if (UNLIKELY(!jsCodeBlock->runnable())) {
130
        if (UNLIKELY(!jsCalleeGroup->runnable())) {
131
            throwException(globalObject, scope, createJSWebAssemblyLinkError(globalObject, vm, jsCodeBlock->errorMessage()));
131
            throwException(globalObject, scope, createJSWebAssemblyLinkError(globalObject, vm, jsCalleeGroup->errorMessage()));
132
            return;
132
            return;
133
        }
133
        }
134
        m_codeBlock.set(vm, this, jsCodeBlock);
134
        m_calleeGroup.set(vm, this, jsCalleeGroup);
135
        m_module->setCodeBlock(vm, memoryMode(), jsCodeBlock);
135
        m_module->setCalleeGroup(vm, memoryMode(), jsCalleeGroup);
136
    }
136
    }
137
137
138
    // In the module loader case, we will initialize all memory modes with the initial LLInt compilation
138
    // In the module loader case, we will initialize all memory modes with the initial LLInt compilation
139
    // results, so that later when memory imports become available, the appropriate CodeBlock can be used.
139
    // results, so that later when memory imports become available, the appropriate CalleeGroup can be used.
140
    // If LLInt is disabled, we instead defer compilation to module evaluation.
140
    // If LLInt is disabled, we instead defer compilation to module evaluation.
141
    bool hasMemoryImport = module()->moduleInformation().memory.isImport();
141
    bool hasMemoryImport = module()->moduleInformation().memory.isImport();
142
    if (creationMode == Wasm::CreationMode::FromModuleLoader && Options::useWasmLLInt() && hasMemoryImport) {
142
    if (creationMode == Wasm::CreationMode::FromModuleLoader && Options::useWasmLLInt() && hasMemoryImport) {
143
        Wasm::MemoryMode initialMode = Wasm::MemoryMode::BoundsChecking;
143
        Wasm::MemoryMode initialMode = Wasm::MemoryMode::BoundsChecking;
144
        ASSERT(memoryMode() == initialMode);
144
        ASSERT(memoryMode() == initialMode);
145
        module()->module().copyInitialCodeBlockToAllMemoryModes(initialMode);
145
        module()->module().copyInitialCalleeGroupToAllMemoryModes(initialMode);
146
146
147
        for (unsigned i = 0; i < Wasm::NumberOfMemoryModes; i++) {
147
        for (unsigned i = 0; i < Wasm::NumberOfMemoryModes; i++) {
148
            if (i == static_cast<uint8_t>(initialMode))
148
            if (i == static_cast<uint8_t>(initialMode))
149
                continue;
149
                continue;
150
            Wasm::MemoryMode memoryMode = static_cast<Wasm::MemoryMode>(i);
150
            Wasm::MemoryMode memoryMode = static_cast<Wasm::MemoryMode>(i);
151
            RefPtr<Wasm::CodeBlock> codeBlock = module()->module().codeBlockFor(memoryMode);
151
            RefPtr<Wasm::CalleeGroup> calleeGroup = module()->module().calleeGroupFor(memoryMode);
152
            jsCodeBlock = JSWebAssemblyCodeBlock::create(vm, codeBlock.releaseNonNull(), module()->module().moduleInformation());
152
            jsCalleeGroup = JSWebAssemblyCalleeGroup::create(vm, calleeGroup.releaseNonNull(), module()->module().moduleInformation());
153
            if (UNLIKELY(!jsCodeBlock->runnable())) {
153
            if (UNLIKELY(!jsCalleeGroup->runnable())) {
154
                throwException(globalObject, scope, createJSWebAssemblyLinkError(globalObject, vm, jsCodeBlock->errorMessage()));
154
                throwException(globalObject, scope, createJSWebAssemblyLinkError(globalObject, vm, jsCalleeGroup->errorMessage()));
155
                return;
155
                return;
156
            }
156
            }
157
            m_module->setCodeBlock(vm, memoryMode, jsCodeBlock);
157
            m_module->setCalleeGroup(vm, memoryMode, jsCalleeGroup);
158
        }
158
        }
159
    }
159
    }
160
160
161
    for (unsigned importFunctionNum = 0; importFunctionNum < instance().numImportFunctions(); ++importFunctionNum) {
161
    for (unsigned importFunctionNum = 0; importFunctionNum < instance().numImportFunctions(); ++importFunctionNum) {
162
        auto* info = instance().importFunctionInfo(importFunctionNum);
162
        auto* info = instance().importFunctionInfo(importFunctionNum);
163
        info->wasmToEmbedderStub = m_codeBlock->wasmToEmbedderStub(importFunctionNum);
163
        info->wasmToEmbedderStub = m_calleeGroup->wasmToEmbedderStub(importFunctionNum);
164
    }
164
    }
165
165
166
    m_moduleRecord->prepareLink(vm, this);
166
    m_moduleRecord->prepareLink(vm, this);
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h -4 / +4 lines
Lines 28-34 a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h_sec1
28
#if ENABLE(WEBASSEMBLY)
28
#if ENABLE(WEBASSEMBLY)
29
29
30
#include "JSDestructibleObject.h"
30
#include "JSDestructibleObject.h"
31
#include "JSWebAssemblyCodeBlock.h"
31
#include "JSWebAssemblyCalleeGroup.h"
32
#include "JSWebAssemblyGlobal.h"
32
#include "JSWebAssemblyGlobal.h"
33
#include "JSWebAssemblyMemory.h"
33
#include "JSWebAssemblyMemory.h"
34
#include "JSWebAssemblyTable.h"
34
#include "JSWebAssemblyTable.h"
Lines 44-50 class JSWebAssemblyModule; a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h_sec2
44
class WebAssemblyModuleRecord;
44
class WebAssemblyModuleRecord;
45
45
46
namespace Wasm {
46
namespace Wasm {
47
class CodeBlock;
47
class CalleeGroup;
48
}
48
}
49
49
50
class JSWebAssemblyInstance final : public JSNonFinalObject {
50
class JSWebAssemblyInstance final : public JSNonFinalObject {
Lines 68-74 class JSWebAssemblyInstance final : public JSNonFinalObject { a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h_sec3
68
68
69
    DECLARE_EXPORT_INFO;
69
    DECLARE_EXPORT_INFO;
70
70
71
    void finalizeCreation(VM&, JSGlobalObject*, Ref<Wasm::CodeBlock>&&, JSObject* importObject, Wasm::CreationMode);
71
    void finalizeCreation(VM&, JSGlobalObject*, Ref<Wasm::CalleeGroup>&&, JSObject* importObject, Wasm::CreationMode);
72
    
72
    
73
    Wasm::Instance& instance() { return m_instance.get(); }
73
    Wasm::Instance& instance() { return m_instance.get(); }
74
    WebAssemblyModuleRecord* moduleRecord() { return m_moduleRecord.get(); }
74
    WebAssemblyModuleRecord* moduleRecord() { return m_moduleRecord.get(); }
Lines 114-120 class JSWebAssemblyInstance final : public JSNonFinalObject { a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h_sec4
114
114
115
    WriteBarrier<JSGlobalObject> m_globalObject;
115
    WriteBarrier<JSGlobalObject> m_globalObject;
116
    WriteBarrier<JSWebAssemblyModule> m_module;
116
    WriteBarrier<JSWebAssemblyModule> m_module;
117
    WriteBarrier<JSWebAssemblyCodeBlock> m_codeBlock;
117
    WriteBarrier<JSWebAssemblyCalleeGroup> m_calleeGroup;
118
    WriteBarrier<WebAssemblyModuleRecord> m_moduleRecord;
118
    WriteBarrier<WebAssemblyModuleRecord> m_moduleRecord;
119
    WriteBarrier<JSWebAssemblyMemory> m_memory;
119
    WriteBarrier<JSWebAssemblyMemory> m_memory;
120
    FixedVector<WriteBarrier<JSWebAssemblyTable>> m_tables;
120
    FixedVector<WriteBarrier<JSWebAssemblyTable>> m_tables;
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp -6 / +6 lines
Lines 29-35 a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp_sec1
29
#if ENABLE(WEBASSEMBLY)
29
#if ENABLE(WEBASSEMBLY)
30
30
31
#include "JSCInlines.h"
31
#include "JSCInlines.h"
32
#include "JSWebAssemblyCodeBlock.h"
32
#include "JSWebAssemblyCalleeGroup.h"
33
#include "JSWebAssemblyCompileError.h"
33
#include "JSWebAssemblyCompileError.h"
34
#include "WasmFormat.h"
34
#include "WasmFormat.h"
35
#include "WasmModule.h"
35
#include "WasmModule.h"
Lines 109-117 Wasm::SignatureIndex JSWebAssemblyModule::signatureIndexFromFunctionIndexSpace(u a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp_sec2
109
    return m_module->signatureIndexFromFunctionIndexSpace(functionIndexSpace);
109
    return m_module->signatureIndexFromFunctionIndexSpace(functionIndexSpace);
110
}
110
}
111
111
112
JSWebAssemblyCodeBlock* JSWebAssemblyModule::codeBlock(Wasm::MemoryMode mode)
112
JSWebAssemblyCalleeGroup* JSWebAssemblyModule::calleeGroup(Wasm::MemoryMode mode)
113
{
113
{
114
    return m_codeBlocks[static_cast<size_t>(mode)].get();
114
    return m_calleeGroups[static_cast<size_t>(mode)].get();
115
}
115
}
116
116
117
Wasm::Module& JSWebAssemblyModule::module()
117
Wasm::Module& JSWebAssemblyModule::module()
Lines 119-127 Wasm::Module& JSWebAssemblyModule::module() a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp_sec3
119
    return m_module.get();
119
    return m_module.get();
120
}
120
}
121
121
122
void JSWebAssemblyModule::setCodeBlock(VM& vm, Wasm::MemoryMode mode, JSWebAssemblyCodeBlock* codeBlock)
122
void JSWebAssemblyModule::setCalleeGroup(VM& vm, Wasm::MemoryMode mode, JSWebAssemblyCalleeGroup* calleeGroup)
123
{
123
{
124
    m_codeBlocks[static_cast<size_t>(mode)].set(vm, this, codeBlock);
124
    m_calleeGroups[static_cast<size_t>(mode)].set(vm, this, calleeGroup);
125
}
125
}
126
126
127
template<typename Visitor>
127
template<typename Visitor>
Lines 133-139 void JSWebAssemblyModule::visitChildrenImpl(JSCell* cell, Visitor& visitor) a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp_sec4
133
    Base::visitChildren(thisObject, visitor);
133
    Base::visitChildren(thisObject, visitor);
134
    visitor.append(thisObject->m_exportSymbolTable);
134
    visitor.append(thisObject->m_exportSymbolTable);
135
    for (unsigned i = 0; i < Wasm::NumberOfMemoryModes; ++i)
135
    for (unsigned i = 0; i < Wasm::NumberOfMemoryModes; ++i)
136
        visitor.append(thisObject->m_codeBlocks[i]);
136
        visitor.append(thisObject->m_calleeGroups[i]);
137
}
137
}
138
138
139
DEFINE_VISIT_CHILDREN(JSWebAssemblyModule);
139
DEFINE_VISIT_CHILDREN(JSWebAssemblyModule);
- a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h -5 / +5 lines
Lines 46-52 class Plan; a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h_sec1
46
}
46
}
47
47
48
class SymbolTable;
48
class SymbolTable;
49
class JSWebAssemblyCodeBlock;
49
class JSWebAssemblyCalleeGroup;
50
class JSWebAssemblyMemory;
50
class JSWebAssemblyMemory;
51
51
52
class JSWebAssemblyModule final : public JSNonFinalObject {
52
class JSWebAssemblyModule final : public JSNonFinalObject {
Lines 70-82 class JSWebAssemblyModule final : public JSNonFinalObject { a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h_sec2
70
    SymbolTable* exportSymbolTable() const;
70
    SymbolTable* exportSymbolTable() const;
71
    Wasm::SignatureIndex signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const;
71
    Wasm::SignatureIndex signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const;
72
72
73
    JSWebAssemblyCodeBlock* codeBlock(Wasm::MemoryMode mode);
73
    JSWebAssemblyCalleeGroup* calleeGroup(Wasm::MemoryMode);
74
    void setCodeBlock(VM&, Wasm::MemoryMode, JSWebAssemblyCodeBlock*);
74
    void setCalleeGroup(VM&, Wasm::MemoryMode, JSWebAssemblyCalleeGroup*);
75
75
76
    JS_EXPORT_PRIVATE Wasm::Module& module();
76
    JS_EXPORT_PRIVATE Wasm::Module& module();
77
77
78
private:
78
private:
79
    friend class JSWebAssemblyCodeBlock;
79
    friend class JSWebAssemblyCalleeGroup;
80
80
81
    JSWebAssemblyModule(VM&, Structure*, Ref<Wasm::Module>&&);
81
    JSWebAssemblyModule(VM&, Structure*, Ref<Wasm::Module>&&);
82
    void finishCreation(VM&);
82
    void finishCreation(VM&);
Lines 84-90 class JSWebAssemblyModule final : public JSNonFinalObject { a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h_sec3
84
84
85
    Ref<Wasm::Module> m_module;
85
    Ref<Wasm::Module> m_module;
86
    WriteBarrier<SymbolTable> m_exportSymbolTable;
86
    WriteBarrier<SymbolTable> m_exportSymbolTable;
87
    WriteBarrier<JSWebAssemblyCodeBlock> m_codeBlocks[Wasm::NumberOfMemoryModes];
87
    WriteBarrier<JSWebAssemblyCalleeGroup> m_calleeGroups[Wasm::NumberOfMemoryModes];
88
};
88
};
89
89
90
} // namespace JSC
90
} // namespace JSC
- a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp -1 / +1 lines
Lines 67-73 JSC_DEFINE_HOST_FUNCTION(callWebAssemblyFunction, (JSGlobalObject* globalObject, a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp_sec1
67
    const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex);
67
    const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex);
68
68
69
    // Make sure that the memory we think we are going to run with matches the one we expect.
69
    // Make sure that the memory we think we are going to run with matches the one we expect.
70
    ASSERT(wasmFunction->instance()->instance().codeBlock()->isSafeToRun(wasmFunction->instance()->memory()->memory().mode()));
70
    ASSERT(wasmFunction->instance()->instance().calleeGroup()->isSafeToRun(wasmFunction->instance()->memory()->memory().mode()));
71
71
72
    std::optional<TraceScope> traceScope;
72
    std::optional<TraceScope> traceScope;
73
    if (Options::useTracePoints())
73
    if (Options::useTracePoints())
- a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp -13 / +13 lines
Lines 442-454 void WebAssemblyModuleRecord::initializeImportsAndExports(JSGlobalObject* global a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp_sec1
442
            // runnable due to the LLint tier code being shared among all modes. However,
442
            // runnable due to the LLint tier code being shared among all modes. However,
443
            // if LLInt is disabled, it is possible that the code needs to be compiled at
443
            // if LLInt is disabled, it is possible that the code needs to be compiled at
444
            // this point when we know which memory mode to use.
444
            // this point when we know which memory mode to use.
445
            Wasm::CodeBlock* codeBlock = m_instance->instance().codeBlock();
445
            Wasm::CalleeGroup* calleeGroup = m_instance->instance().calleeGroup();
446
            if (!codeBlock || !codeBlock->runnable()) {
446
            if (!calleeGroup || !calleeGroup->runnable()) {
447
                codeBlock = m_instance->module()->module().compileSync(&vm.wasmContext, memory->memory().mode()).ptr();
447
                calleeGroup = m_instance->module()->module().compileSync(&vm.wasmContext, memory->memory().mode()).ptr();
448
                if (!codeBlock->runnable())
448
                if (!calleeGroup->runnable())
449
                    return exception(createJSWebAssemblyLinkError(globalObject, vm, codeBlock->errorMessage()));
449
                    return exception(createJSWebAssemblyLinkError(globalObject, vm, calleeGroup->errorMessage()));
450
            }
450
            }
451
            RELEASE_ASSERT(codeBlock->isSafeToRun(memory->memory().mode()));
451
            RELEASE_ASSERT(calleeGroup->isSafeToRun(memory->memory().mode()));
452
            break;
452
            break;
453
        }
453
        }
454
    }
454
    }
Lines 476-489 void WebAssemblyModuleRecord::initializeImportsAndExports(JSGlobalObject* global a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp_sec2
476
    }
476
    }
477
477
478
    // This needs to be looked up after the memory is initialized, as the codeBlock depends on the memory mode.
478
    // This needs to be looked up after the memory is initialized, as the codeBlock depends on the memory mode.
479
    Wasm::CodeBlock* codeBlock = m_instance->instance().codeBlock();
479
    Wasm::CalleeGroup* calleeGroup = m_instance->instance().calleeGroup();
480
480
481
    for (unsigned index = 0; index < moduleInformation.internalExceptionSignatureIndices.size(); ++index) {
481
    for (unsigned index = 0; index < moduleInformation.internalExceptionSignatureIndices.size(); ++index) {
482
        Wasm::SignatureIndex signatureIndex = moduleInformation.internalExceptionSignatureIndices[index];
482
        Wasm::SignatureIndex signatureIndex = moduleInformation.internalExceptionSignatureIndices[index];
483
        m_instance->instance().setTag(moduleInformation.importExceptionCount() + index, Wasm::Tag::create(Wasm::SignatureInformation::get(signatureIndex)));
483
        m_instance->instance().setTag(moduleInformation.importExceptionCount() + index, Wasm::Tag::create(Wasm::SignatureInformation::get(signatureIndex)));
484
    }
484
    }
485
485
486
    unsigned functionImportCount = codeBlock->functionImportCount();
486
    unsigned functionImportCount = calleeGroup->functionImportCount();
487
    auto makeFunctionWrapper = [&] (uint32_t index) -> JSValue {
487
    auto makeFunctionWrapper = [&] (uint32_t index) -> JSValue {
488
        // If we already made a wrapper, do not make a new one.
488
        // If we already made a wrapper, do not make a new one.
489
        JSValue wrapper = m_instance->instance().getFunctionWrapper(index);
489
        JSValue wrapper = m_instance->instance().getFunctionWrapper(index);
Lines 507-514 void WebAssemblyModuleRecord::initializeImportsAndExports(JSGlobalObject* global a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp_sec3
507
            //     a. Let func be an Exported Function Exotic Object created from c.
507
            //     a. Let func be an Exported Function Exotic Object created from c.
508
            //     b. Append func to funcs.
508
            //     b. Append func to funcs.
509
            //     c. Return func.
509
            //     c. Return func.
510
            Wasm::Callee& embedderEntrypointCallee = codeBlock->embedderEntrypointCalleeFromFunctionIndexSpace(index);
510
            Wasm::Callee& embedderEntrypointCallee = calleeGroup->embedderEntrypointCalleeFromFunctionIndexSpace(index);
511
            Wasm::WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation = codeBlock->entrypointLoadLocationFromFunctionIndexSpace(index);
511
            Wasm::WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation = calleeGroup->entrypointLoadLocationFromFunctionIndexSpace(index);
512
            Wasm::SignatureIndex signatureIndex = module->signatureIndexFromFunctionIndexSpace(index);
512
            Wasm::SignatureIndex signatureIndex = module->signatureIndexFromFunctionIndexSpace(index);
513
            const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex);
513
            const Wasm::Signature& signature = Wasm::SignatureInformation::get(signatureIndex);
514
            WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, globalObject->webAssemblyFunctionStructure(), signature.argumentCount(), makeString(index), m_instance.get(), embedderEntrypointCallee, entrypointLoadLocation, signatureIndex);
514
            WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, globalObject->webAssemblyFunctionStructure(), signature.argumentCount(), makeString(index), m_instance.get(), embedderEntrypointCallee, entrypointLoadLocation, signatureIndex);
Lines 652-663 void WebAssemblyModuleRecord::initializeImportsAndExports(JSGlobalObject* global a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp_sec4
652
        // The start function must not take any arguments or return anything. This is enforced by the parser.
652
        // The start function must not take any arguments or return anything. This is enforced by the parser.
653
        ASSERT(!signature.argumentCount());
653
        ASSERT(!signature.argumentCount());
654
        ASSERT(signature.returnsVoid());
654
        ASSERT(signature.returnsVoid());
655
        if (startFunctionIndexSpace < codeBlock->functionImportCount()) {
655
        if (startFunctionIndexSpace < calleeGroup->functionImportCount()) {
656
            JSObject* startFunction = m_instance->instance().importFunction<WriteBarrier<JSObject>>(startFunctionIndexSpace)->get();
656
            JSObject* startFunction = m_instance->instance().importFunction<WriteBarrier<JSObject>>(startFunctionIndexSpace)->get();
657
            m_startFunction.set(vm, this, startFunction);
657
            m_startFunction.set(vm, this, startFunction);
658
        } else {
658
        } else {
659
            Wasm::Callee& embedderEntrypointCallee = codeBlock->embedderEntrypointCalleeFromFunctionIndexSpace(startFunctionIndexSpace);
659
            Wasm::Callee& embedderEntrypointCallee = calleeGroup->embedderEntrypointCalleeFromFunctionIndexSpace(startFunctionIndexSpace);
660
            Wasm::WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation = codeBlock->entrypointLoadLocationFromFunctionIndexSpace(startFunctionIndexSpace);
660
            Wasm::WasmToWasmImportableFunction::LoadLocation entrypointLoadLocation = calleeGroup->entrypointLoadLocationFromFunctionIndexSpace(startFunctionIndexSpace);
661
            WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, globalObject->webAssemblyFunctionStructure(), signature.argumentCount(), "start", m_instance.get(), embedderEntrypointCallee, entrypointLoadLocation, signatureIndex);
661
            WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, globalObject->webAssemblyFunctionStructure(), signature.argumentCount(), "start", m_instance.get(), embedderEntrypointCallee, entrypointLoadLocation, signatureIndex);
662
            m_startFunction.set(vm, this, function);
662
            m_startFunction.set(vm, this, function);
663
        }
663
        }
- a/Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.h -1 / +1 lines
Lines 27-33 a/Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.h_sec1
27
27
28
#if ENABLE(WEBASSEMBLY)
28
#if ENABLE(WEBASSEMBLY)
29
29
30
#include "JSWebAssemblyCodeBlock.h"
30
#include "JSWebAssemblyCalleeGroup.h"
31
#include "WebAssemblyFunctionBase.h"
31
#include "WebAssemblyFunctionBase.h"
32
32
33
namespace JSC {
33
namespace JSC {

Return to Bug 203694