Title: [248187] trunk
Revision
248187
Author
[email protected]
Date
2019-08-02 15:58:09 -0700 (Fri, 02 Aug 2019)

Log Message

[JSC] Support WebAssembly in SamplingProfiler
https://bugs.webkit.org/show_bug.cgi?id=200329

Reviewed by Saam Barati.

JSTests:

* stress/sampling-profiler-wasm-name-section.js: Added.
(const.compile):
(platformSupportsSamplingProfiler.vm.isWasmSupported.wasmEntry):
(platformSupportsSamplingProfiler.vm.isWasmSupported):
* stress/sampling-profiler-wasm.js: Added.
(platformSupportsSamplingProfiler.vm.isWasmSupported.wasmEntry):
(platformSupportsSamplingProfiler.vm.isWasmSupported):
* stress/sampling-profiler/loop.wasm: Added.
* stress/sampling-profiler/loop.wast: Added.
* stress/sampling-profiler/nameSection.wasm: Added.

Source/_javascript_Core:

The sampling profiler support is critical to investigate what is actually time-consuming. This patch adds the sampling profiler support for Wasm functions
to list up hot Wasm functions with compilation mode (BBQ or OMG). This allows us to investigate the hot functions in JetStream2 wasm tests.

In order to retrieve wasm function information from the sampling profiler safely, we need to know whether the given Wasm CalleeBits is valid in the call frame.
To achieve this, we start collecting valid Wasm::Callee pointers in a global hash set. Previously, each Wasm::Callee registered its code region to a hash set
for wasm fault signal handler to know whether the faulted program-counter is in wasm region. We reuse and change this mechanism. Instead of registering code region,
we register Wasm::Callee* to a hash set. The sampling profiler reuses this hash set to determine whether the given bits is a valid Wasm::Callee.

The sampling profiler retrieves the information safely from valid Wasm::Callee* pointer. It is possible that this Wasm::Callee is about to be dead: ref-count is 0,
now in the middle of the destructor of Wasm::Callee. Even in that case, fields of Wasm::Callee are still valid and can be accessed since destroying these fields happens
after we unregister Wasm::Callee from the global hash set.

We retrieve Wasm::IndexOrName and Wasm::CompilationMode. Copying them does not involve any allocations, locking etc. So we can safely copy them while some of threads are suspended.

This patch also fixes the issue that we never called `unregisterCode` while every Wasm::Calllee registers its code region through `registerCode`.

* CMakeLists.txt:
* _javascript_Core.xcodeproj/project.pbxproj:
* Sources.txt:
* runtime/InitializeThreading.cpp:
(JSC::initializeThreading):
* runtime/SamplingProfiler.cpp:
(JSC::FrameWalker::FrameWalker):
(JSC::FrameWalker::recordJSFrame):
(JSC::CFrameWalker::CFrameWalker):
(JSC::SamplingProfiler::takeSample):
(JSC::SamplingProfiler::processUnverifiedStackTraces):
(JSC::SamplingProfiler::StackFrame::displayName):
(JSC::SamplingProfiler::StackFrame::displayNameForJSONTests):
(JSC::SamplingProfiler::StackFrame::functionStartLine):
(JSC::SamplingProfiler::StackFrame::functionStartColumn):
(JSC::SamplingProfiler::StackFrame::sourceID):
(JSC::SamplingProfiler::StackFrame::url):
(JSC::SamplingProfiler::reportTopBytecodes):
(WTF::printInternal):
* runtime/SamplingProfiler.h:
* tools/JSDollarVM.cpp:
(JSC::functionIsWasmSupported):
(JSC::JSDollarVM::finishCreation):
* wasm/WasmB3IRGenerator.h:
* wasm/WasmBBQPlan.cpp:
(JSC::Wasm::BBQPlan::complete):
* wasm/WasmBBQPlanInlines.h:
(JSC::Wasm::BBQPlan::initializeCallees):
* wasm/WasmCallee.cpp:
(JSC::Wasm::Callee::Callee):
(JSC::Wasm::Callee::~Callee):
* wasm/WasmCallee.h:
(JSC::Wasm::Callee::create): Deleted.
(JSC::Wasm::Callee::entrypoint const): Deleted.
(JSC::Wasm::Callee::calleeSaveRegisters): Deleted.
(JSC::Wasm::Callee::indexOrName const): Deleted.
* wasm/WasmCalleeRegistry.cpp: Copied from Source/_javascript_Core/wasm/WasmFaultSignalHandler.h.
(JSC::Wasm::CalleeRegistry::initialize):
(JSC::Wasm::CalleeRegistry::singleton):
* wasm/WasmCalleeRegistry.h: Copied from Source/_javascript_Core/wasm/WasmCallee.cpp.
(JSC::Wasm::CalleeRegistry::getLock):
(JSC::Wasm::CalleeRegistry::registerCallee):
(JSC::Wasm::CalleeRegistry::unregisterCallee):
(JSC::Wasm::CalleeRegistry::isValidCallee):
* wasm/WasmCompilationMode.cpp: Copied from Source/_javascript_Core/wasm/WasmFaultSignalHandler.h.
(JSC::Wasm::makeString):
* wasm/WasmCompilationMode.h: Copied from Source/_javascript_Core/wasm/WasmFaultSignalHandler.h.
* wasm/WasmFaultSignalHandler.cpp:
(JSC::Wasm::trapHandler):
(JSC::Wasm::enableFastMemory):
(JSC::Wasm::registerCode): Deleted.
(JSC::Wasm::unregisterCode): Deleted.
* wasm/WasmFaultSignalHandler.h:
* wasm/WasmIndexOrName.h:
* wasm/WasmOMGPlan.cpp:
(JSC::Wasm::OMGPlan::work):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (248186 => 248187)


--- trunk/JSTests/ChangeLog	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/JSTests/ChangeLog	2019-08-02 22:58:09 UTC (rev 248187)
@@ -1,5 +1,23 @@
 2019-08-02  Yusuke Suzuki  <[email protected]>
 
+        [JSC] Support WebAssembly in SamplingProfiler
+        https://bugs.webkit.org/show_bug.cgi?id=200329
+
+        Reviewed by Saam Barati.
+
+        * stress/sampling-profiler-wasm-name-section.js: Added.
+        (const.compile):
+        (platformSupportsSamplingProfiler.vm.isWasmSupported.wasmEntry):
+        (platformSupportsSamplingProfiler.vm.isWasmSupported):
+        * stress/sampling-profiler-wasm.js: Added.
+        (platformSupportsSamplingProfiler.vm.isWasmSupported.wasmEntry):
+        (platformSupportsSamplingProfiler.vm.isWasmSupported):
+        * stress/sampling-profiler/loop.wasm: Added.
+        * stress/sampling-profiler/loop.wast: Added.
+        * stress/sampling-profiler/nameSection.wasm: Added.
+
+2019-08-02  Yusuke Suzuki  <[email protected]>
+
         [JSC] LazyJSValue should be robust for empty JSValue
         https://bugs.webkit.org/show_bug.cgi?id=200388
 

Added: trunk/JSTests/stress/sampling-profiler/loop.wasm (0 => 248187)


--- trunk/JSTests/stress/sampling-profiler/loop.wasm	                        (rev 0)
+++ trunk/JSTests/stress/sampling-profiler/loop.wasm	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,3 @@
+��asm������`����loop����
+-+A!A!@@  ��K+  l! Aj!�� 
\ No newline at end of file

Added: trunk/JSTests/stress/sampling-profiler/loop.wast (0 => 248187)


--- trunk/JSTests/stress/sampling-profiler/loop.wast	                        (rev 0)
+++ trunk/JSTests/stress/sampling-profiler/loop.wast	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,18 @@
+(module
+  (memory 1)
+
+  (func (export "loop") (param i32) (result i32)
+    (local i32 i32)
+    (local.set 1 (i32.const 1))
+    (local.set 2 (i32.const 2))
+    (block
+      (loop
+        (br_if 1 (i32.gt_u (local.get 2) (local.get 0)))
+        (local.set 1 (i32.mul (local.get 1) (local.get 2)))
+        (local.set 2 (i32.add (local.get 2) (i32.const 1)))
+        (br 0)
+      )
+    )
+    (local.get 1)
+  )
+)

Added: trunk/JSTests/stress/sampling-profiler/nameSection.wasm (0 => 248187)


--- trunk/JSTests/stress/sampling-profiler/nameSection.wasm	                        (rev 0)
+++ trunk/JSTests/stress/sampling-profiler/nameSection.wasm	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,151 @@
+��asm������\xAB\x80\x80\x80��```��`��`��`����``\x82\x83\x80\x80��envDYNAMICTOP_PTR��envSTACKTOP��env	STACK_MAX��envabort��env+enlargeMemory��envgetTotalMemory��envabortOnCannotGrowMemory��env_emscripten_memcpy_big����env___lock��env_abort��env___setErrNo��env___syscall6��env+___syscall140��env_silly��env___syscall54��env	___unlock��env+___syscall146��envmemory\x80\x80envtablepenv
+memoryBase��env	tableBase��\xA6\x80\x80\x80��%������������\x9F\x80\x80\x80��#��##A��A��A��\x84\x82\x80\x80��_malloc��)getTempRet0��_fflush��'runPostSets��+setTempRet0��establishStackSpace��	stackSave��_memset��-_sbrk��,_emscripten_get_global_libc��_memcpy��.
+stackAlloc��setThrew��_parrot��_free��*stackRestore��___errno_location��
+dynCall_ii��/dynCall_iiii��0	\x8C\x80\x80\x80����#12"
+\xB5܀\x80��%\x9E\x80\x80\x80��#!# ��j$#AjApq$ \x84\x80\x80\x80����#\x86\x80\x80\x80���� ��$\x8D\x80\x80\x80����@ ��$ $\x90\x80\x80\x80����#E@ ��$ $	\x86\x80\x80\x80���� ��$
+\x84\x80\x80\x80����#
+\x8F\x80\x80\x80�� ��
+! \x8F\x80\x80\x80�� ��! \x8F\x80\x80\x80�� ��! \x8F\x80\x80\x80�� ��! \x85\x80\x80\x80����A\xF4
+\xB0\x80\x80\x80��#!#Aj$ " ��(<!6��A !�� $ ��\xFD\x82\x80\x80��#!#A0j$ Aj! A j" ��Aj"	(��"6��  ��Aj"
+(�� k"6  6  6 " ��A<j"(��6��  6 A6@@  j"A\x92 +"F+��A!@ A��N@  k! Aj!  ("+K"@ ! AtAu j!  (��   +A��k"j6�� Aj" (�� k6��  (��6��  6  6 A\x92 +"F+ ��A��6 	A��6�� 
+A��6�� �� ��(��A r6�� AFA��  (k! �� ��(," ��(0j6 	 6�� 
+ 6�� $ 倀\x80��#!#A j$ " ��(<6�� A��6  6  Aj"��6  6A\x8C 	A��H ��A6��A ��(��!�� $ ��\x9A\x80\x80\x80���� ��A\x80`KA�� ��k6��A ��\x88\x80\x80\x80����A\xC0��j\x84\x80\x80\x80���� \x85\x80\x80\x80����A\x80\x84\x80\x80\x80���� ��뀀\x80��#!#A j$ ! Aj! ��A6$ ��(��A\xC0��qE@  ��(<6�� A\x93\xA86  6A6 @ ��A:��K ��  !�� $ ��\x84\x80\x80\x80����A��\x83\x80\x80\x80����\x8D\x80\x80\x80����A\xB4A\xBC\x87\x80\x80\x80����A\xB4\xA4\x81\x80\x80��@ ��@ ��(LAL@ ��(!�� ��#E! ��(!   ��$ !��A\xF0
+(��A\xF0
+(��'A��!��%(��"@@ (LAJ #A��! ( (K@ ( ��r!�� @ $ (8"+��& ��\x9C\x81\x80\x80��@ ��Aj"(�� ��Aj"(��M+�� ��A��A�� ��($AqAj���� (��+��A ��Aj"(��" ��Aj"(��"I@ ��  kA ��((AqAj���� ��A��6 A��6�� A��6�� A��6�� A��6��A��"��\xA6\xB8\x80\x80��#!+#Aj$ +!@ ��A\xF5I@ ��AjAxq!A\xC0(��" ��AIA" Av"��v"Aq@ AqAs ��j"AtA\xE8j"Aj"(��"Aj"(��!��  ��F@A\xC0 A tAsq6�� ��A\xD0(��I@ ��Aj"(�� F@  6��  ��6��  At"��Ar6  ��jAj"�� ��(��Ar6�� +$  A\xC8(��"K@ @  ��tA ��t"��A�� ��krq"��A�� ��kqAj"AvAq!��  ��v"AvAq" ��r  v"��AvAq"r �� v"��AvAq"r �� v"��AvAq"r �� vj"AtA\xE8j"Aj"(��"Aj"
+(��!��  ��F@A\xC0 A tAsq"6�� ��A\xD0(��I@ ��Aj"(�� F@  6��  ��6�� !  Ar6  j" At k"Ar6  j 6�� @A\xD4(��! Av"AtA\xE8j!�� A t"q@ ��Aj"(��"A\xD0(��I@ ! !A\xC0  r6�� ��Aj! ��!  6��  6  6  ��6A\xC8 6��A\xD4 6�� +$ 
+A\xC4(��"@ A�� kqAj"AvAq!��  ��v"AvAq" ��r  v"��AvAq"r �� v"��AvAq"r �� v"��AvAq"r �� vjAtA\xF0+j(��"(Axq k! Aj (EAtj(��"��@@ ��(Axq k" I"@ ! @ ��! ��Aj ��(EAtj(��"��+�� ! ! A\xD0(��"I@   j"	O@ (!@ ("�� F@ Aj"(��"��E@ Aj"(��"��E@A��!@ ��Aj"(��"
+@ 
+!�� ! ��Aj"(��"
+@ 
+!�� !  I@ A��6�� ��! (" I@ Aj"(�� G@ ��Aj"
+(�� F@  ��6�� 
+ 6�� ��!@ @  ("��AtA\xF0+j"(��F@  6�� E@A\xC4 A ��tAsq6�� A\xD0(��I@ Aj ( GAtj 6�� E+ A\xD0(��"I@  6 ("��@ �� I@  ��6 �� 6 ("��@ ��A\xD0(��I@  ��6 �� 6 AI@   j"��Ar6  ��jAj"�� ��(��Ar6��  Ar6 	 Ar6 	 j 6�� @A\xD4(��! Av"AtA\xE8j!�� A t"q@ ��Aj"(��"A\xD0(��I@ ! !A\xC0  r6�� ��Aj! ��!  6��  6  6  ��6A\xC8 6��A\xD4 	6�� +$ Aj ! ! ��A\xBFK@A! ��Aj"��Axq!A\xC4(��"@ ��Av"�� A\xFF\xFF\xFFKA A �� ��A\x80\xFE?jAvAq"��t"A\x80\xE0jAvAq" ��r  t"��A\x80\x80jAvAq"rk �� tAvj"��AjvAq ��AtrA��!A�� k!@@@ AtA\xF0+j(��"��@A Avk!A��!  AFA�� t!A��!@ ��(Axq k" I@ @ ! ��!A��! ��! ��("E  ��Aj AvAtj(��
 "Fr  !��  E"Ast! + ��! !������A��!��A��!
  ��E Eq A t"��A�� ��krq"��E@ ! ��A�� ��kqAj"AvAq!��  ��v"AvAq" ��r  v"��AvAq"r �� v"��AvAq"r �� v"��AvAq"r �� vjAtA\xF0+j(��!A�� ��! !�� @ ! ! ! ��!@ (Axq k" I"@ ! @ !�� Aj (EAtj(��"+�� ! ��! @ A\xC8(�� kI@ A\xD0(��"I@   j"	O@ (!@ ("�� F@ Aj"(��"��E@ Aj"(��"��E@A��!@ ��Aj"
+(��"@ !�� 
+! ��Aj"
+(��"@ !�� 
+!  I@ A��6�� ��! (" I@ Aj"
+(�� G@ ��Aj"(�� F@ 
+ ��6��  6�� ��!@ @  ("��AtA\xF0+j"(��F@  6�� E@A\xC4 A ��tAsq"6�� A\xD0(��I@ Aj ( GAtj 6�� E@ ! A\xD0(��"I@  6 ("��@ �� I@  ��6 �� 6 ("��@ ��A\xD0(��I@  ��6 �� 6 ! ! !@ AI@   j"��Ar6  ��jAj"�� ��(��Ar6��  Ar6 	 Ar6 	 j 6�� Av! A\x80I@ AtA\xE8j!��A\xC0(��"A t"q@ ��Aj"(��"A\xD0(��I@ ! !A\xC0  r6�� ��Aj! ��!  	6��  	6 	 6 	 ��6 Av"�� A\xFF\xFF\xFFKA A �� ��A\x80\xFE?jAvAq"��t"A\x80\xE0jAvAq" ��r  t"��A\x80\x80jAvAq"rk �� tAvj"��AjvAq ��AtrA��"AtA\xF0+j!�� 	 6 	Aj"A��6 A��6�� A t"qE@A\xC4  r6�� �� 	6�� 	 ��6 	 	6 	 	6 ��(��!��A Avk!  AFA�� t!@@@@ ��(Axq F+ At! ��Aj AvAtj"(��"E+ 
 ! !������ A\xD0(��I@  	6�� 	 ��6 	 	6 	 	6
  ��Aj"(��"A\xD0(��"O �� Oq@  	6  	6�� 	 6 	 ��6 	A��6 +$ Aj ! ! !A\xC8(��" O@A\xD4(��!��  k"AK@A\xD4 �� j"6��A\xC8 6��  Ar6  j 6�� �� Ar6A\xC8A��6��A\xD4A��6�� �� Ar6 �� jAj" (��Ar6�� +$ ��AjA\xCC(��" K@A\xCC  k"6��A\xD8A\xD8(��"�� j"6��  Ar6 �� Ar6 +$ ��AjA\x98(��A\xA0(��A\xA0A\x80 6��A\x9CA\x80 6��A\xA4A6��A\xA8A6��A\xACA��6��A\xFCA��6��  ApqAتժs"��6��A\x98 ��6��A\x80 "�� A/j"j"A�� ��k"q" M@ +$A��A\xF8(��"��@A\xF0(��" j" M  ��Kr@ +$A�� A0j!@@A\xFC(��Aq@A��!@@@A\xD8(��"��E+��A\x80!@@ (��" ��M@  Aj"(��j ��K+ ("+  k q"A\xFF\xFF\xFF\xFFI@ ,"�� (�� (��jF@ ��AG+A��!A��,"��AF@A��!A\x9C(��"Aj&qu
 ot; ��"jA�� kq k!  q A�� j"A\xF0(��"
 j!  K A\xFF\xFF\xFF\xFFIq@A\xF8(��"@  M  Kr@A��! ," ��F+ !��A��!  K A\xFF\xFF\xFF\xFFI ��AGqqE@ ��AF@A��!��  kA\xA0(��"jA�� kq"A\xFF\xFF\xFF\xFFO+A�� k! ,AF@ ,A��!  j!A\xFCA\xFC(��Ar6�� A\xFF\xFF\xFF\xFFI@ ,"��A��,"I ��AG AGqq!  ��k" A(jK"@ ! ��AF Asr AsrE+A\xF0A\xF0(�� j"6�� A\xF4(��K@A\xF4 6��@A\xD8(��"@A\x80!@@@ �� (��" Aj"(��"jF+ ("+�� (AqE@  ��I  Oq@   j6��A\xCC(��!A�� Aj"kAq!��A\xD8  Aq ��A��"��j"6��A\xCC   ��kj"��6��  ��Ar6  ��jA(6A\xDCA\xA8(��6�� ��A\xD0(��"I@A\xD0 ��6�� ��! �� j!A\x80!@@@ (�� F+ ("+�� (AqE@  ��6�� Aj" (�� j6��A�� ��Aj"kAq!A�� Aj"kAq! �� Aq A��j"	 j!  Aq A��j" 	k k! 
 	 Ar6@  F@A\xCCA\xCC(�� j"��6��A\xD8 6
 ��  ��Ar6 A\xD4(��F@A\xC8A\xC8(�� j"��6��A\xD4 6��  ��Ar6  ��j ��6�� ("��AqAF ��Axq! ��Av!@ ��A\x80I@ (!@ (" AtA\xE8j"��G@  I@ ( F+  F@A\xC0A\xC0(��A tAsq6��@  ��F@ Aj!  I@ Aj"��(�� F@ ��!  6  6�� (!@ ("�� F@ Aj"Aj"(��"��@ ! (��"��E@A��!
+@ ��Aj"(��"@ !�� ! ��Aj"(��"@ !�� !  I@ A��6�� ��!
+ (" I@ Aj"(�� G@ ��Aj"(�� F@  ��6��  6�� ��!
+ E+@  ("��AtA\xF0+j"(��F@  
+6�� 
++A\xC4A\xC4(��A ��tAsq6�� A\xD0(��I@ Aj ( GAtj 
+6�� 
+E+ 
+A\xD0(��"I@ 
+ 6 Aj"(��"��@ �� I@ 
+ ��6 �� 
+6 ("��E+ ��A\xD0(��I@ 
+ ��6 �� 
+6  j!  j ! Aj"�� ��(��A~q6��  Ar6  j 6�� Av! A\x80I@ AtA\xE8j!��@A\xC0(��"A t"q@ ��Aj"(��"A\xD0(��O@ ! !A\xC0  r6�� ��Aj! ��!  6��  6  6  ��6 Av"��A A\xFF\xFF\xFFK+ A �� ��A\x80\xFE?jAvAq"��t"A\x80\xE0jAvAq" ��r  t"��A\x80\x80jAvAq"rk �� tAvj"��AjvAq ��AtrA��"AtA\xF0+j!��  6 Aj"A��6 A��6��A\xC4(��"A t"qE@A\xC4  r6�� �� 6��  ��6  6  6 ��(��!��A Avk!  AFA�� t!@@@@ ��(Axq F+ At! ��Aj AvAtj"(��"E+ ! !������ A\xD0(��I@  6��  ��6  6  6 ��Aj"(��"A\xD0(��"O �� Oq@  6  6��  6  ��6 A��6 +$ 	AjA\x80!@@ (��" M@  (j"
+ K+ (!A�� 
+AQj"Aj"kAq!  Aq A��j" Aj"I " Aj! Aj! AXj!A�� ��Aj"kAq!A\xD8 �� Aq A��"j"6��A\xCC  k"6��  Ar6  jA(6A\xDCA\xA8(��6�� Aj"A6�� A\x80)��7�� A\x88)��7A\x80 ��6��A\x84 6��A\x8CA��6��A\x88 6�� !��@ ��Aj"A6�� ��Aj 
+I@ !��  G@  (��A~q6��   k"Ar6  6�� Av! A\x80I@ AtA\xE8j!��A\xC0(��"A t"q@ ��Aj"(��"A\xD0(��I@ ! !	A\xC0  r6�� ��Aj! ��!	  6�� 	 6  	6  ��6 Av"�� A\xFF\xFF\xFFKA A �� ��A\x80\xFE?jAvAq"��t"A\x80\xE0jAvAq" ��r  t"��A\x80\x80jAvAq"rk �� tAvj"��AjvAq ��AtrA��"AtA\xF0+j!��  6 A��6 A��6��A\xC4(��"A t"qE@A\xC4  r6�� �� 6��  ��6  6  6 ��(��!��A Avk!  AFA�� t!@@@@ ��(Axq F+ At! ��Aj AvAtj"(��"E+ ! !������ A\xD0(��I@  6��  ��6  6  6 ��Aj"(��"A\xD0(��"O �� Oq@  6  6��  6  ��6 A��6A\xD0(��"E �� Ir@A\xD0 ��6��A\x80 ��6��A\x84 6��A\x8CA��6��A\xE4A\x98(��6��A\xE0A6��A��!@ AtA\xE8j" 6  6 Aj"A G+�� AXj!A�
 � ��Aj"kAq!A\xD8 �� Aq A��"j"��6��A\xCC
   k"6�� �� Ar6 �� jA(6A\xDCA\xA8(��6��A\xCC(��"�� K@A\xCC �� k"6��A\xD8A\xD8(��"�� j"6��  Ar6 �� Ar6 +$ ��AjA6�� +$A��’\x80\x80��@ ��E@ ��Axj"A\xD0(��"I@ ��A|j(��"��Aq"AF@  ��Axq"j!@ ��Aq@ ! ! ! (��!	 E@ A�� 	kj"�� I@ 	 j! ��A\xD4(��F@ Aj"(��"AqAG@ ��! ��! !A\xC8 6��  A~q6�� �� Ar6 �� j 6�� 	Av! 	A\x80I@ ��(! ��(" AtA\xE8j"G@  I@ ( ��G@  F@A\xC0A\xC0(��A tAsq6�� ��! ��! !  F@ Aj!  I@ Aj"(�� ��F@ !  6  6�� ��! ��! ! ��(!+@ ��(" ��F@ ��Aj"Aj"	(��"@ 	! (��"E@A��!@ Aj"	(��"@ ! 	! Aj"	(��"@ ! 	!  I@ A��6�� ! ��(" I@ Aj"	(�� ��G@ Aj"(�� ��F@ 	 6��  6�
 � ! +@ �� ��("AtA\xF0+j"(��F@  6�� E
 @A\xC4A\xC4(��A tAsq6�� ��! ��! ! +A\xD0(��I@ +Aj +( ��GAtj 6�� E@ ��! ��! ! A\xD0(��"I@  +6 ��Aj"	(��"@  I@  6  6 	("@ A\xD0(��I@  6  6 ��! ��! ! ��! ��! ! ��! ��! !  O@ Aj"(��"��AqE@ ��Aq@  ��A~q6��  Ar6  j 6��A\xD4(��! A\xD8(��F@A\xCCA\xCC(�� j"��6��A\xD8 6��  ��Ar6  G@A\xD4A��6��A\xC8A��6��  F@A\xC8A\xC8(�� j"��6��A\xD4 6��  ��Ar6  ��j ��6�� ��Axq j! ��Av!@ ��A\x80I@ (! (" AtA\xE8j"��G@ A\xD0(��I@ ( G@  F@A\xC0A\xC0(��A tAsq6��  ��F@ Aj! A\xD0(��I@ Aj"��(�� F@ ��!  6  6�� (!@ ("�� F@ Aj"Aj"(��"��@ ! (��"��E@A��!
+@ ��Aj"(��"@ !�� ! ��Aj"(��"@ !�� ! A\xD0(��I@ A��6�� ��!
+ ("A\xD0(��I@ Aj"(�� G@ ��Aj"(�� F@  ��6��  6�� ��!
+ @  ("��AtA\xF0+j"(��F@  
+6�� 
+E@A\xC4A\xC4(��A ��tAsq6�� A\xD0(��I@ Aj ( GAtj 
+6�� 
+E+ 
+A\xD0(��"I@ 
+ 6 Aj"(��"��@ �� I@ 
+ ��6 �� 
+6 ("��@ ��A\xD0(��I@ 
+ ��6 �� 
+6  Ar6  j 6�� A\xD4(��F@A\xC8 6�� ! Av! A\x80I@ AtA\xE8j!��A\xC0(��"A t"q@ ��Aj"(��"A\xD0(��I@ ! !A\xC0  r6�� ��Aj! ��!  6��  6  6  ��6 Av"�� A\xFF\xFF\xFFKA A �� ��A\x80\xFE?jAvAq"��t"A\x80\xE0jAvAq" ��r  t"��A\x80\x80jAvAq"rk �� tAvj"��AjvAq ��AtrA��"AtA\xF0+j!��  6 A��6 A��6@A\xC4(��"A t"q@ ��(��!��A Avk!  AFA�� t!@@@@ ��(Axq F+ At! ��Aj AvAtj"(��"E+ ! !������ A\xD0(��I@  6��  ��6  6  6 ��Aj"(��"A\xD0(��"O �� Oq@  6  6��  6  ��6 A��6A\xC4  r6�� �� 6��  ��6  6  6A\xE0A\xE0(��Aj"��6�� ��@A\x88!��@ ��(��"Aj!�� +��A\xE0A6��\x83\x80\x80\x80����ހ\x80\x80��#(��" ��AjApq"��j! ��A��J  Hq A
 ��Hr@AA# 6�� J@E@A# 6��A \x9D\x82\x
 80\x80�� �� j! A\xFFq! A\xC3��N@@ ��Aq@ �� :���� ��Aj!�� A|q"A\xC0��k!  Atr Atr Atr!@ �� L@ �� 6�� �� 6 �� 6 �� 6 �� 6 �� 6 �� 6 �� 6 �� 6  �� 6$ �� 6( �� 6, �� 60 �� 64 �� 68 �� 6< ��A\xC0��j!��@ �� H@ �� 6�� ��Aj!��@ �� H@ �� :���� ��Aj!��  kɃ\x80\x80�� A\x80\xC0��N@ ��   ��! �� j! ��Aq AqF@@ ��Aq@ E@  �� ,����:���� ��Aj!�� Aj! Ak! A|q"A\xC0��k!@ �� L@ �� (��6�� �� (6 �� (6 �� (6 �� (6 �� (6 �� (6 �� (6 �� ( 6  �� ($6$ �� ((6( �� (,6, �� (060 �� (464 �� (868 �� (<6< ��A\xC0��j!�� A\xC0��j!@ �� H@ �� (��6�� ��Aj!�� Aj! Ak!@ �� H@ �� ,����:���� �� ,��:�� �� ,��:�� �� ,��:�� ��Aj!�� Aj!@ �� H@ �� ,����:���� ��Aj!�� Aj! \x8C\x80\x80\x80����  ��Aq��\x93\x80\x80\x80����    ��AqAj����\x8B\x
 80\x80\x80����A����A��\x8B\x80\x80\x80����A��A��ŀ\x80\x80����A\xBC	\x9C��A\xF4	��A\x80
+��A\x98
+������������\xB8��������A\xB0
+��A\xBF
+
+\xFF\xFF\xFF\xFF��A\xF0
+\xF4��\xA7\x85\x80\x80��name\x9C\x85\x80\x80��3��abort+enlargeMemorygetTotalMemoryabortOnCannotGrowMemory_emscripten_memcpy_big___lock_abort___setErrNo___syscall6	+___syscall140
+_silly___syscall54	___unlock++___syscall146
+stackAlloc	stackSavestackRestoreestablishStackSpacesetThrewsetTempRet0getTempRet0_eggs_bacon_spam_parrot_emscripten_get_global_libc___stdio_close___stdio_write+___stdio_seek___syscall_ret___errno_location___pthread_self_103 +_pthread_self!
+_dummy_570"___stdout_write#___lockfile$+___unlockfile%___ofl_lock&+___ofl_unlock'_fflush(___fflush_unlocked)_malloc*_free+runPostSets,_sbrk-_memset._memcpy/
+dynCall_ii0dynCall_iiii1b02b1
\ No newline at end of file

Added: trunk/JSTests/stress/sampling-profiler-wasm-name-section.js (0 => 248187)


--- trunk/JSTests/stress/sampling-profiler-wasm-name-section.js	                        (rev 0)
+++ trunk/JSTests/stress/sampling-profiler-wasm-name-section.js	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,73 @@
+//@ runDefault
+
+/*
+This test loads a WebAssembly file compiled by Emscripten with:
+  ./emsdk-portable/emscripten/incoming/em++ ./nameSection.cc -O2 -g4 -s WASM=1 -o nameSection.js -s EXPORTED_FUNCTIONS="['_parrot']"
+
+From the following C++ source file:
+  extern "C" {
+  int silly(int);
+  __attribute__((noinline)) int eggs(int i) { return silly(i); }
+  __attribute__((noinline)) int bacon(int i) { return eggs(i); }
+  __attribute__((noinline)) int spam(int i) { return bacon(i); }
+  __attribute__((noinline)) int parrot(int i) { return spam(i); }
+  }
+*/
+
+if (platformSupportsSamplingProfiler() && $vm.isWasmSupported()) {
+    const verbose = false;
+    const wasmFile = './sampling-profiler/nameSection.wasm';
+
+    const compile = (location, importObject = {}) => {
+        if (verbose)
+            print(`Processing ${location}`);
+        let buf = typeof readbuffer !== "undefined"? readbuffer(location) : read(location, 'binary');
+        if (verbose)
+            print(`  Size: ${buf.byteLength}`);
+
+        let t0 = Date.now();
+        let module = new WebAssembly.Module(buf);
+        let t1 = Date.now();
+        if (verbose)
+            print(`new WebAssembly.Module(buf) took ${t1-t0} ms.`);
+
+        if (verbose)
+            print(`Creating fake import object with ${WebAssembly.Module.imports(module).length} imports`);
+        for (let imp of WebAssembly.Module.imports(module)) {
+            if (typeof importObject[imp.module] === "undefined")
+                importObject[imp.module] = {};
+            if (typeof importObject[imp.module][imp.name] === "undefined") {
+                switch (imp.kind) {
+                case "function": importObject[imp.module][imp.name] = () => {}; break;
+                case "table": importObject[imp.module][imp.name] = new WebAssembly.Table({ initial: 6, maximum: 6, element: "funcref" }); break;
+                case "memory": importObject[imp.module][imp.name] = new WebAssembly.Memory({ initial: 16777216 / (64 * 1024), maximum: 16777216 / (64 * 1024) }); break;
+                case "global": importObject[imp.module][imp.name] = 0; break;
+                }
+            }
+
+        }
+
+        let t2 = Date.now();
+        let instance = new WebAssembly.Instance(module, importObject);
+        let t3 = Date.now();
+        if (verbose)
+            print(`new WebAssembly.Module(buf) took ${t3-t2} ms.`);
+
+        return instance;
+    };
+
+    const importObject = { env: { _silly: i => {
+        var result = 0;
+        for (var i = 0; i < 100000; ++i)
+            result++;
+        return result;
+    } } };
+    const instance = compile(wasmFile, importObject);
+    const result = instance.exports._parrot(1);
+
+    load("./sampling-profiler/samplingProfiler.js");
+    var wasmEntry = function() {
+        return instance.exports._parrot(1);
+    };
+    runTest(wasmEntry, ["_silly", "(unknown)", "<?>.wasm-function[_eggs]", "<?>.wasm-function[_bacon]", "<?>.wasm-function[_spam]", "<?>.wasm-function[_parrot]", "wasm-stub", "_parrot", "wasmEntry"]);
+}

Added: trunk/JSTests/stress/sampling-profiler-wasm.js (0 => 248187)


--- trunk/JSTests/stress/sampling-profiler-wasm.js	                        (rev 0)
+++ trunk/JSTests/stress/sampling-profiler-wasm.js	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,12 @@
+//@ runDefault
+
+if (platformSupportsSamplingProfiler() && $vm.isWasmSupported()) {
+    load("./sampling-profiler/samplingProfiler.js");
+    let buf = read("./sampling-profiler/loop.wasm", "binary");
+    let module = new WebAssembly.Module(buf);
+    let instance = new WebAssembly.Instance(module);
+    var wasmEntry = function() {
+        return instance.exports.loop(10000000);
+    };
+    runTest(wasmEntry, ["<?>.wasm-function[0]", "wasm-stub", "loop", "wasmEntry"]);
+}

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (248186 => 248187)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2019-08-02 22:58:09 UTC (rev 248187)
@@ -997,6 +997,7 @@
 
     wasm/WasmCapabilities.h
     wasm/WasmCodeBlock.h
+    wasm/WasmCompilationMode.h
     wasm/WasmContext.h
     wasm/WasmEmbedder.h
     wasm/WasmExceptionType.h

Modified: trunk/Source/_javascript_Core/ChangeLog (248186 => 248187)


--- trunk/Source/_javascript_Core/ChangeLog	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-08-02 22:58:09 UTC (rev 248187)
@@ -1,5 +1,85 @@
 2019-08-02  Yusuke Suzuki  <[email protected]>
 
+        [JSC] Support WebAssembly in SamplingProfiler
+        https://bugs.webkit.org/show_bug.cgi?id=200329
+
+        Reviewed by Saam Barati.
+
+        The sampling profiler support is critical to investigate what is actually time-consuming. This patch adds the sampling profiler support for Wasm functions
+        to list up hot Wasm functions with compilation mode (BBQ or OMG). This allows us to investigate the hot functions in JetStream2 wasm tests.
+
+        In order to retrieve wasm function information from the sampling profiler safely, we need to know whether the given Wasm CalleeBits is valid in the call frame.
+        To achieve this, we start collecting valid Wasm::Callee pointers in a global hash set. Previously, each Wasm::Callee registered its code region to a hash set
+        for wasm fault signal handler to know whether the faulted program-counter is in wasm region. We reuse and change this mechanism. Instead of registering code region,
+        we register Wasm::Callee* to a hash set. The sampling profiler reuses this hash set to determine whether the given bits is a valid Wasm::Callee.
+
+        The sampling profiler retrieves the information safely from valid Wasm::Callee* pointer. It is possible that this Wasm::Callee is about to be dead: ref-count is 0,
+        now in the middle of the destructor of Wasm::Callee. Even in that case, fields of Wasm::Callee are still valid and can be accessed since destroying these fields happens
+        after we unregister Wasm::Callee from the global hash set.
+
+        We retrieve Wasm::IndexOrName and Wasm::CompilationMode. Copying them does not involve any allocations, locking etc. So we can safely copy them while some of threads are suspended.
+
+        This patch also fixes the issue that we never called `unregisterCode` while every Wasm::Calllee registers its code region through `registerCode`.
+
+        * CMakeLists.txt:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * runtime/InitializeThreading.cpp:
+        (JSC::initializeThreading):
+        * runtime/SamplingProfiler.cpp:
+        (JSC::FrameWalker::FrameWalker):
+        (JSC::FrameWalker::recordJSFrame):
+        (JSC::CFrameWalker::CFrameWalker):
+        (JSC::SamplingProfiler::takeSample):
+        (JSC::SamplingProfiler::processUnverifiedStackTraces):
+        (JSC::SamplingProfiler::StackFrame::displayName):
+        (JSC::SamplingProfiler::StackFrame::displayNameForJSONTests):
+        (JSC::SamplingProfiler::StackFrame::functionStartLine):
+        (JSC::SamplingProfiler::StackFrame::functionStartColumn):
+        (JSC::SamplingProfiler::StackFrame::sourceID):
+        (JSC::SamplingProfiler::StackFrame::url):
+        (JSC::SamplingProfiler::reportTopBytecodes):
+        (WTF::printInternal):
+        * runtime/SamplingProfiler.h:
+        * tools/JSDollarVM.cpp:
+        (JSC::functionIsWasmSupported):
+        (JSC::JSDollarVM::finishCreation):
+        * wasm/WasmB3IRGenerator.h:
+        * wasm/WasmBBQPlan.cpp:
+        (JSC::Wasm::BBQPlan::complete):
+        * wasm/WasmBBQPlanInlines.h:
+        (JSC::Wasm::BBQPlan::initializeCallees):
+        * wasm/WasmCallee.cpp:
+        (JSC::Wasm::Callee::Callee):
+        (JSC::Wasm::Callee::~Callee):
+        * wasm/WasmCallee.h:
+        (JSC::Wasm::Callee::create): Deleted.
+        (JSC::Wasm::Callee::entrypoint const): Deleted.
+        (JSC::Wasm::Callee::calleeSaveRegisters): Deleted.
+        (JSC::Wasm::Callee::indexOrName const): Deleted.
+        * wasm/WasmCalleeRegistry.cpp: Copied from Source/_javascript_Core/wasm/WasmFaultSignalHandler.h.
+        (JSC::Wasm::CalleeRegistry::initialize):
+        (JSC::Wasm::CalleeRegistry::singleton):
+        * wasm/WasmCalleeRegistry.h: Copied from Source/_javascript_Core/wasm/WasmCallee.cpp.
+        (JSC::Wasm::CalleeRegistry::getLock):
+        (JSC::Wasm::CalleeRegistry::registerCallee):
+        (JSC::Wasm::CalleeRegistry::unregisterCallee):
+        (JSC::Wasm::CalleeRegistry::isValidCallee):
+        * wasm/WasmCompilationMode.cpp: Copied from Source/_javascript_Core/wasm/WasmFaultSignalHandler.h.
+        (JSC::Wasm::makeString):
+        * wasm/WasmCompilationMode.h: Copied from Source/_javascript_Core/wasm/WasmFaultSignalHandler.h.
+        * wasm/WasmFaultSignalHandler.cpp:
+        (JSC::Wasm::trapHandler):
+        (JSC::Wasm::enableFastMemory):
+        (JSC::Wasm::registerCode): Deleted.
+        (JSC::Wasm::unregisterCode): Deleted.
+        * wasm/WasmFaultSignalHandler.h:
+        * wasm/WasmIndexOrName.h:
+        * wasm/WasmOMGPlan.cpp:
+        (JSC::Wasm::OMGPlan::work):
+
+2019-08-02  Yusuke Suzuki  <[email protected]>
+
         [JSC] LazyJSValue should be robust for empty JSValue
         https://bugs.webkit.org/show_bug.cgi?id=200388
 

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (248186 => 248187)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2019-08-02 22:58:09 UTC (rev 248187)
@@ -1815,6 +1815,7 @@
 		E3A32BC71FC83147007D7E76 /* WeakMapImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = E3A32BC61FC8312E007D7E76 /* WeakMapImpl.h */; };
 		E3A421431D6F58930007C617 /* PreciseJumpTargetsInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = E3A421421D6F588F0007C617 /* PreciseJumpTargetsInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E3AC277721FDB4940024452C /* RegExpCachedResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 86F75EFC151C062F007C9BA3 /* RegExpCachedResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3BD2B7622F275020011765C /* WasmCompilationMode.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BD2B7522F275020011765C /* WasmCompilationMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E3BFA5D021E853A1009C0EBA /* DFGDesiredGlobalProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BFA5CD21E853A1009C0EBA /* DFGDesiredGlobalProperty.h */; };
 		E3BFD0BC1DAF808E0065DEA2 /* AccessCaseSnippetParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BFD0BA1DAF807C0065DEA2 /* AccessCaseSnippetParams.h */; };
 		E3C295DD1ED2CBDA00D3016F /* ObjectPropertyChangeAdaptiveWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C295DC1ED2CBAA00D3016F /* ObjectPropertyChangeAdaptiveWatchpoint.h */; };
@@ -1826,6 +1827,7 @@
 		E3F23A801ECF13F500978D99 /* SnippetReg.h in Headers */ = {isa = PBXBuildFile; fileRef = E3F23A7D1ECF13E500978D99 /* SnippetReg.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E3F23A811ECF13FA00978D99 /* SnippetParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E3F23A7C1ECF13E500978D99 /* SnippetParams.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E3F23A821ECF13FE00978D99 /* Snippet.h in Headers */ = {isa = PBXBuildFile; fileRef = E3F23A7B1ECF13E500978D99 /* Snippet.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E3FB853A22F3667B008F90ED /* WasmCalleeRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FB853822F36674008F90ED /* WasmCalleeRegistry.h */; };
 		E3FF75331D9CEA1800C7E16D /* DOMJITGetterSetter.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FF752F1D9CEA1200C7E16D /* DOMJITGetterSetter.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC15112EF272200184A1F /* SourceProviderCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4815,6 +4817,7 @@
 		E36CC9462086314F0051FFD6 /* WasmCreationMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmCreationMode.h; sourceTree = "<group>"; };
 		E3794E731B77EB97005543AE /* ModuleAnalyzer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModuleAnalyzer.cpp; sourceTree = "<group>"; };
 		E3794E741B77EB97005543AE /* ModuleAnalyzer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleAnalyzer.h; sourceTree = "<group>"; };
+		E37CFB2D22F27C57009A7B38 /* WasmCompilationMode.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmCompilationMode.cpp; sourceTree = "<group>"; };
 		E380A76B1DCD7195000F89E6 /* MacroAssemblerHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MacroAssemblerHelpers.h; sourceTree = "<group>"; };
 		E380D66B1F19249D00A59095 /* BuiltinNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BuiltinNames.cpp; sourceTree = "<group>"; };
 		E3850B14226ED63E009ABF9C /* DFGMinifiedIDInlines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DFGMinifiedIDInlines.h; path = dfg/DFGMinifiedIDInlines.h; sourceTree = "<group>"; };
@@ -4841,6 +4844,7 @@
 		E3A32BC51FC8312D007D7E76 /* WeakMapImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakMapImpl.cpp; sourceTree = "<group>"; };
 		E3A32BC61FC8312E007D7E76 /* WeakMapImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakMapImpl.h; sourceTree = "<group>"; };
 		E3A421421D6F588F0007C617 /* PreciseJumpTargetsInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PreciseJumpTargetsInlines.h; sourceTree = "<group>"; };
+		E3BD2B7522F275020011765C /* WasmCompilationMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WasmCompilationMode.h; sourceTree = "<group>"; };
 		E3BFA5CB21E853A0009C0EBA /* DFGDesiredGlobalProperties.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGDesiredGlobalProperties.cpp; path = dfg/DFGDesiredGlobalProperties.cpp; sourceTree = "<group>"; };
 		E3BFA5CC21E853A0009C0EBA /* DFGDesiredGlobalProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGDesiredGlobalProperties.h; path = dfg/DFGDesiredGlobalProperties.h; sourceTree = "<group>"; };
 		E3BFA5CD21E853A1009C0EBA /* DFGDesiredGlobalProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGDesiredGlobalProperty.h; path = dfg/DFGDesiredGlobalProperty.h; sourceTree = "<group>"; };
@@ -4863,6 +4867,8 @@
 		E3F23A7C1ECF13E500978D99 /* SnippetParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SnippetParams.h; sourceTree = "<group>"; };
 		E3F23A7D1ECF13E500978D99 /* SnippetReg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SnippetReg.h; sourceTree = "<group>"; };
 		E3F23A7E1ECF13E500978D99 /* SnippetSlowPathCalls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SnippetSlowPathCalls.h; sourceTree = "<group>"; };
+		E3FB853822F36674008F90ED /* WasmCalleeRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WasmCalleeRegistry.h; sourceTree = "<group>"; };
+		E3FB853922F36674008F90ED /* WasmCalleeRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WasmCalleeRegistry.cpp; sourceTree = "<group>"; };
 		E3FC25102256ECF400583518 /* DoublePredictionFuzzerAgent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DoublePredictionFuzzerAgent.cpp; sourceTree = "<group>"; };
 		E3FC25112256ECF400583518 /* DoublePredictionFuzzerAgent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DoublePredictionFuzzerAgent.h; sourceTree = "<group>"; };
 		E3FF752F1D9CEA1200C7E16D /* DOMJITGetterSetter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITGetterSetter.h; sourceTree = "<group>"; };
@@ -6605,11 +6611,15 @@
 				AD4B1DF81DF244D70071AE32 /* WasmBinding.h */,
 				525C0DD71E935847002184CD /* WasmCallee.cpp */,
 				525C0DD81E935847002184CD /* WasmCallee.h */,
+				E3FB853922F36674008F90ED /* WasmCalleeRegistry.cpp */,
+				E3FB853822F36674008F90ED /* WasmCalleeRegistry.h */,
 				53FD04D11D7AB187003287D3 /* WasmCallingConvention.cpp */,
 				53FD04D21D7AB187003287D3 /* WasmCallingConvention.h */,
 				E337B966224324E50093A820 /* WasmCapabilities.h */,
 				526AC4B41E977C5D003500E1 /* WasmCodeBlock.cpp */,
 				526AC4B51E977C5D003500E1 /* WasmCodeBlock.h */,
+				E37CFB2D22F27C57009A7B38 /* WasmCompilationMode.cpp */,
+				E3BD2B7522F275020011765C /* WasmCompilationMode.h */,
 				AD412B321E7B2E8A008AF157 /* WasmContext.h */,
 				A27958D7FA1142B0AC9E364D /* WasmContextInlines.h */,
 				E36CC9462086314F0051FFD6 /* WasmCreationMode.h */,
@@ -10008,9 +10018,11 @@
 				53F8D2001E8387D400D21116 /* WasmBBQPlanInlines.h in Headers */,
 				AD4B1DFA1DF244E20071AE32 /* WasmBinding.h in Headers */,
 				525C0DDA1E935847002184CD /* WasmCallee.h in Headers */,
+				E3FB853A22F3667B008F90ED /* WasmCalleeRegistry.h in Headers */,
 				53FD04D41D7AB291003287D3 /* WasmCallingConvention.h in Headers */,
 				E337B967224324EA0093A820 /* WasmCapabilities.h in Headers */,
 				526AC4B71E977C5D003500E1 /* WasmCodeBlock.h in Headers */,
+				E3BD2B7622F275020011765C /* WasmCompilationMode.h in Headers */,
 				AD412B341E7B2E9E008AF157 /* WasmContext.h in Headers */,
 				7593C898BE714A64BE93A6E7 /* WasmContextInlines.h in Headers */,
 				E36CC9472086314F0051FFD6 /* WasmCreationMode.h in Headers */,

Modified: trunk/Source/_javascript_Core/Sources.txt (248186 => 248187)


--- trunk/Source/_javascript_Core/Sources.txt	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/Sources.txt	2019-08-02 22:58:09 UTC (rev 248187)
@@ -996,8 +996,10 @@
 wasm/WasmBBQPlan.cpp
 wasm/WasmBinding.cpp
 wasm/WasmCallee.cpp
+wasm/WasmCalleeRegistry.cpp
 wasm/WasmCallingConvention.cpp
 wasm/WasmCodeBlock.cpp
+wasm/WasmCompilationMode.cpp
 wasm/WasmEmbedder.h
 wasm/WasmFaultSignalHandler.cpp
 wasm/WasmFormat.cpp

Modified: trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -43,6 +43,7 @@
 #include "SigillCrashAnalyzer.h"
 #include "StructureIDTable.h"
 #include "SuperSampler.h"
+#include "WasmCalleeRegistry.h"
 #include "WasmCapabilities.h"
 #include "WasmThunks.h"
 #include "WriteBarrier.h"
@@ -86,8 +87,10 @@
         thread.setSavedLastStackTop(thread.stack().origin());
 
 #if ENABLE(WEBASSEMBLY)
-        if (Wasm::isSupported())
+        if (Wasm::isSupported()) {
             Wasm::Thunks::initialize();
+            Wasm::CalleeRegistry::initialize();
+        }
 #endif
 
         if (VM::isInMiniMode())

Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -48,6 +48,8 @@
 #include "SlotVisitor.h"
 #include "StrongInlines.h"
 #include "VM.h"
+#include "WasmCallee.h"
+#include "WasmCalleeRegistry.h"
 #include <thread>
 #include <wtf/FilePrintStream.h>
 #include <wtf/HashSet.h>
@@ -81,12 +83,13 @@
 
 class FrameWalker {
 public:
-    FrameWalker(VM& vm, ExecState* callFrame, const AbstractLocker& codeBlockSetLocker, const AbstractLocker& machineThreadsLocker)
+    FrameWalker(VM& vm, ExecState* callFrame, const AbstractLocker& codeBlockSetLocker, const AbstractLocker& machineThreadsLocker, const AbstractLocker& wasmCalleeLocker)
         : m_vm(vm)
         , m_callFrame(callFrame)
         , m_entryFrame(vm.topEntryFrame)
         , m_codeBlockSetLocker(codeBlockSetLocker)
         , m_machineThreadsLocker(machineThreadsLocker)
+        , m_wasmCalleeLocker(wasmCalleeLocker)
     {
     }
 
@@ -98,7 +101,7 @@
         resetAtMachineFrame();
         size_t maxStackTraceSize = stackTrace.size();
         while (!isAtTop() && !m_bailingOut && m_depth < maxStackTraceSize) {
-            recordJSFrame(stackTrace);
+            recordJITFrame(stackTrace);
             advanceToParentFrame();
             resetAtMachineFrame();
         }
@@ -115,7 +118,7 @@
 protected:
 
     SUPPRESS_ASAN
-    void recordJSFrame(Vector<UnprocessedStackFrame>& stackTrace)
+    void recordJITFrame(Vector<UnprocessedStackFrame>& stackTrace)
     {
         CallSiteIndex callSiteIndex;
         CalleeBits unsafeCallee = m_callFrame->unsafeCallee();
@@ -125,6 +128,17 @@
             callSiteIndex = m_callFrame->unsafeCallSiteIndex();
         }
         stackTrace[m_depth] = UnprocessedStackFrame(codeBlock, unsafeCallee, callSiteIndex);
+#if ENABLE(WEBASSEMBLY)
+        if (unsafeCallee.isWasm()) {
+            auto* wasmCallee = unsafeCallee.asWasmCallee();
+            if (Wasm::CalleeRegistry::singleton().isValidCallee(m_wasmCalleeLocker, wasmCallee)) {
+                // At this point, Wasm::Callee would be dying (ref count is 0), but its fields are still live.
+                // And we can safely copy Wasm::IndexOrName even when any lock is held by suspended threads.
+                stackTrace[m_depth].wasmIndexOrName = wasmCallee->indexOrName();
+                stackTrace[m_depth].wasmCompilationMode = wasmCallee->compilationMode();
+            }
+        }
+#endif
         m_depth++;
     }
 
@@ -193,6 +207,7 @@
     EntryFrame* m_entryFrame;
     const AbstractLocker& m_codeBlockSetLocker;
     const AbstractLocker& m_machineThreadsLocker;
+    const AbstractLocker& m_wasmCalleeLocker;
     bool m_bailingOut { false };
     size_t m_depth { 0 };
 };
@@ -201,8 +216,8 @@
 public:
     typedef FrameWalker Base;
 
-    CFrameWalker(VM& vm, void* machineFrame, ExecState* callFrame, const AbstractLocker& codeBlockSetLocker, const AbstractLocker& machineThreadsLocker)
-        : Base(vm, callFrame, codeBlockSetLocker, machineThreadsLocker)
+    CFrameWalker(VM& vm, void* machineFrame, ExecState* callFrame, const AbstractLocker& codeBlockSetLocker, const AbstractLocker& machineThreadsLocker, const AbstractLocker& wasmCalleeLocker)
+        : Base(vm, callFrame, codeBlockSetLocker, machineThreadsLocker, wasmCalleeLocker)
         , m_machineFrame(machineFrame)
     {
     }
@@ -216,7 +231,7 @@
         // The way the C walker decides if a frame it is about to trace is C or JS is by
         // ensuring m_callFrame points to some frame above the machineFrame.
         if (!isAtTop() && !m_bailingOut && m_machineFrame == m_callFrame) {
-            recordJSFrame(stackTrace);
+            recordJITFrame(stackTrace);
             Base::advanceToParentFrame();
             resetAtMachineFrame();
         }
@@ -233,7 +248,7 @@
                 stackTrace[m_depth] = UnprocessedStackFrame(frame()->returnPC);
                 m_depth++;
             } else
-                recordJSFrame(stackTrace);
+                recordJITFrame(stackTrace);
             advanceToParentFrame();
             resetAtMachineFrame();
         }
@@ -341,8 +356,13 @@
         Seconds nowTime = m_stopwatch->elapsedTime();
 
         auto machineThreadsLocker = holdLock(m_vm.heap.machineThreads().getLock());
-        LockHolder codeBlockSetLocker(m_vm.heap.codeBlockSet().getLock());
-        LockHolder executableAllocatorLocker(ExecutableAllocator::singleton().getLock());
+        auto codeBlockSetLocker = holdLock(m_vm.heap.codeBlockSet().getLock());
+        auto executableAllocatorLocker = holdLock(ExecutableAllocator::singleton().getLock());
+#if ENABLE(WEBASSEMBLY)
+        auto wasmCalleesLocker = holdLock(Wasm::CalleeRegistry::singleton().getLock());
+#else
+        LockHolder wasmCalleesLocker(NoLockingNecessary);
+#endif
 
         auto didSuspend = m_jscExecutionThread->suspend();
         if (didSuspend) {
@@ -388,11 +408,11 @@
             bool wasValidWalk;
             bool didRunOutOfVectorSpace;
             if (Options::sampleCCode()) {
-                CFrameWalker walker(m_vm, machineFrame, callFrame, codeBlockSetLocker, machineThreadsLocker);
+                CFrameWalker walker(m_vm, machineFrame, callFrame, codeBlockSetLocker, machineThreadsLocker, wasmCalleesLocker);
                 walkSize = walker.walk(m_currentFrames, didRunOutOfVectorSpace);
                 wasValidWalk = walker.wasValidWalk();
             } else {
-                FrameWalker walker(m_vm, callFrame, codeBlockSetLocker, machineThreadsLocker);
+                FrameWalker walker(m_vm, callFrame, codeBlockSetLocker, machineThreadsLocker, wasmCalleesLocker);
                 walkSize = walker.walk(m_currentFrames, didRunOutOfVectorSpace);
                 wasValidWalk = walker.wasValidWalk();
             }
@@ -489,14 +509,19 @@
             stackTrace.frames.append(StackFrame());
         };
 
-        auto storeCalleeIntoLastFrame = [&] (CalleeBits calleeBits) {
+        auto storeCalleeIntoLastFrame = [&] (UnprocessedStackFrame& unprocessedStackFrame) {
             // Set the callee if it's a valid GC object.
+            CalleeBits calleeBits = unprocessedStackFrame.unverifiedCallee;
             StackFrame& stackFrame = stackTrace.frames.last();
             bool alreadyHasExecutable = !!stackFrame.executable;
+#if ENABLE(WEBASSEMBLY)
             if (calleeBits.isWasm()) {
-                stackFrame.frameType = FrameType::Unknown;
+                stackFrame.frameType = FrameType::Wasm;
+                stackFrame.wasmIndexOrName = unprocessedStackFrame.wasmIndexOrName;
+                stackFrame.wasmCompilationMode = unprocessedStackFrame.wasmCompilationMode;
                 return;
             }
+#endif
 
             JSValue callee = calleeBits.asCell();
             if (!HeapUtil::isValueGCObject(m_vm.heap, filter, callee)) {
@@ -603,7 +628,7 @@
                     UNUSED_PARAM(isValidPC); // FIXME: do something with this info for the web inspector: https://bugs.webkit.org/show_bug.cgi?id=153455
 
                     appendCodeBlock(topCodeBlock, bytecodeIndex);
-                    storeCalleeIntoLastFrame(unprocessedStackTrace.frames[0].unverifiedCallee);
+                    storeCalleeIntoLastFrame(unprocessedStackTrace.frames[0]);
                     startIndex = 1;
                 }
             } else {
@@ -610,7 +635,7 @@
 #if ENABLE(JIT)
                 if (Optional<CodeOrigin> codeOrigin = topCodeBlock->findPC(unprocessedStackTrace.topPC)) {
                     appendCodeOrigin(topCodeBlock, *codeOrigin);
-                    storeCalleeIntoLastFrame(unprocessedStackTrace.frames[0].unverifiedCallee);
+                    storeCalleeIntoLastFrame(unprocessedStackTrace.frames[0]);
                     startIndex = 1;
                 }
 #endif
@@ -649,7 +674,7 @@
             // Note that this is okay to do if we walked the inline stack because
             // the machine frame will be at the top of the processed stack trace.
             if (!unprocessedStackFrame.cCodePC)
-                storeCalleeIntoLastFrame(unprocessedStackFrame.unverifiedCallee);
+                storeCalleeIntoLastFrame(unprocessedStackFrame);
         }
     }
 
@@ -761,7 +786,9 @@
             return name;
     }
 
-    if (frameType == FrameType::Unknown || frameType == FrameType::C) {
+    switch (frameType) {
+    case FrameType::Unknown:
+    case FrameType::C:
 #if HAVE(DLADDR)
         if (frameType == FrameType::C) {
             auto demangled = WTF::StackTrace::demangle(const_cast<void*>(cCodePC));
@@ -771,20 +798,31 @@
         }
 #endif
         return "(unknown)"_s;
-    }
-    if (frameType == FrameType::Host)
+
+    case FrameType::Host:
         return "(host)"_s;
 
-    if (executable->isHostFunction())
-        return static_cast<NativeExecutable*>(executable)->name();
+    case FrameType::Wasm:
+#if ENABLE(WEBASSEMBLY)
+        if (wasmIndexOrName)
+            return makeString(wasmIndexOrName.value());
+#endif
+        return "(wasm)"_s;
 
-    if (executable->isFunctionExecutable())
-        return static_cast<FunctionExecutable*>(executable)->ecmaName().string();
-    if (executable->isProgramExecutable() || executable->isEvalExecutable())
-        return "(program)"_s;
-    if (executable->isModuleProgramExecutable())
-        return "(module)"_s;
+    case FrameType::Executable:
+        if (executable->isHostFunction())
+            return static_cast<NativeExecutable*>(executable)->name();
 
+        if (executable->isFunctionExecutable())
+            return static_cast<FunctionExecutable*>(executable)->ecmaName().string();
+        if (executable->isProgramExecutable() || executable->isEvalExecutable())
+            return "(program)"_s;
+        if (executable->isModuleProgramExecutable())
+            return "(module)"_s;
+
+        RELEASE_ASSERT_NOT_REACHED();
+        return String();
+    }
     RELEASE_ASSERT_NOT_REACHED();
     return String();
 }
@@ -797,27 +835,42 @@
             return name;
     }
 
-    if (frameType == FrameType::Unknown || frameType == FrameType::C)
+    switch (frameType) {
+    case FrameType::Unknown:
+    case FrameType::C:
         return "(unknown)"_s;
-    if (frameType == FrameType::Host)
+
+    case FrameType::Host:
         return "(host)"_s;
 
-    if (executable->isHostFunction())
-        return static_cast<NativeExecutable*>(executable)->name();
+    case FrameType::Wasm: {
+#if ENABLE(WEBASSEMBLY)
+        if (wasmIndexOrName)
+            return makeString(wasmIndexOrName.value());
+#endif
+        return "(wasm)"_s;
+    }
 
-    if (executable->isFunctionExecutable()) {
-        String result = static_cast<FunctionExecutable*>(executable)->ecmaName().string();
-        if (result.isEmpty())
-            return "(anonymous function)"_s;
-        return result;
+    case FrameType::Executable:
+        if (executable->isHostFunction())
+            return static_cast<NativeExecutable*>(executable)->name();
+
+        if (executable->isFunctionExecutable()) {
+            String result = static_cast<FunctionExecutable*>(executable)->ecmaName().string();
+            if (result.isEmpty())
+                return "(anonymous function)"_s;
+            return result;
+        }
+        if (executable->isEvalExecutable())
+            return "(eval)"_s;
+        if (executable->isProgramExecutable())
+            return "(program)"_s;
+        if (executable->isModuleProgramExecutable())
+            return "(module)"_s;
+
+        RELEASE_ASSERT_NOT_REACHED();
+        return String();
     }
-    if (executable->isEvalExecutable())
-        return "(eval)"_s;
-    if (executable->isProgramExecutable())
-        return "(program)"_s;
-    if (executable->isModuleProgramExecutable())
-        return "(module)"_s;
-
     RELEASE_ASSERT_NOT_REACHED();
     return String();
 }
@@ -824,48 +877,79 @@
 
 int SamplingProfiler::StackFrame::functionStartLine()
 {
-    if (frameType == FrameType::Unknown || frameType == FrameType::Host || frameType == FrameType::C)
+    switch (frameType) {
+    case FrameType::Unknown:
+    case FrameType::Host:
+    case FrameType::C:
+    case FrameType::Wasm:
         return -1;
 
-    if (executable->isHostFunction())
-        return -1;
-    return static_cast<ScriptExecutable*>(executable)->firstLine();
+    case FrameType::Executable:
+        if (executable->isHostFunction())
+            return -1;
+        return static_cast<ScriptExecutable*>(executable)->firstLine();
+    }
+    RELEASE_ASSERT_NOT_REACHED();
+    return -1;
 }
 
 unsigned SamplingProfiler::StackFrame::functionStartColumn()
 {
-    if (frameType == FrameType::Unknown || frameType == FrameType::Host || frameType == FrameType::C)
+    switch (frameType) {
+    case FrameType::Unknown:
+    case FrameType::Host:
+    case FrameType::C:
+    case FrameType::Wasm:
         return std::numeric_limits<unsigned>::max();
 
-    if (executable->isHostFunction())
-        return std::numeric_limits<unsigned>::max();
+    case FrameType::Executable:
+        if (executable->isHostFunction())
+            return std::numeric_limits<unsigned>::max();
 
-    return static_cast<ScriptExecutable*>(executable)->startColumn();
+        return static_cast<ScriptExecutable*>(executable)->startColumn();
+    }
+    RELEASE_ASSERT_NOT_REACHED();
+    return std::numeric_limits<unsigned>::max();
 }
 
 intptr_t SamplingProfiler::StackFrame::sourceID()
 {
-    if (frameType == FrameType::Unknown || frameType == FrameType::Host || frameType == FrameType::C)
+    switch (frameType) {
+    case FrameType::Unknown:
+    case FrameType::Host:
+    case FrameType::C:
+    case FrameType::Wasm:
         return -1;
 
-    if (executable->isHostFunction())
-        return -1;
+    case FrameType::Executable:
+        if (executable->isHostFunction())
+            return -1;
 
-    return static_cast<ScriptExecutable*>(executable)->sourceID();
+        return static_cast<ScriptExecutable*>(executable)->sourceID();
+    }
+    RELEASE_ASSERT_NOT_REACHED();
+    return -1;
 }
 
 String SamplingProfiler::StackFrame::url()
 {
-    if (frameType == FrameType::Unknown || frameType == FrameType::Host || frameType == FrameType::C)
+    switch (frameType) {
+    case FrameType::Unknown:
+    case FrameType::Host:
+    case FrameType::C:
+    case FrameType::Wasm:
         return emptyString();
+    case FrameType::Executable:
+        if (executable->isHostFunction())
+            return emptyString();
 
-    if (executable->isHostFunction())
-        return emptyString();
-
-    String url = ""
-    if (url.isEmpty())
-        return static_cast<ScriptExecutable*>(executable)->source().provider()->sourceURLDirective(); // Fall back to sourceURL directive.
-    return url;
+        String url = ""
+        if (url.isEmpty())
+            return static_cast<ScriptExecutable*>(executable)->source().provider()->sourceURLDirective(); // Fall back to sourceURL directive.
+        return url;
+    }
+    RELEASE_ASSERT_NOT_REACHED();
+    return String();
 }
 
 Vector<SamplingProfiler::StackTrace> SamplingProfiler::releaseStackTraces(const AbstractLocker& locker)
@@ -1025,9 +1109,10 @@
         if (!stackTrace.frames.size())
             continue;
 
-        auto descriptionForLocation = [&] (StackFrame::CodeLocation location) -> String {
+        auto descriptionForLocation = [&] (StackFrame::CodeLocation location, Optional<Wasm::CompilationMode> wasmCompilationMode) -> String {
             String bytecodeIndex;
             String codeBlockHash;
+            String jitType;
             if (location.hasBytecodeIndex())
                 bytecodeIndex = String::number(location.bytecodeIndex);
             else
@@ -1040,14 +1125,19 @@
             } else
                 codeBlockHash = "<nil>";
 
-            return makeString("#", codeBlockHash, ":", JITCode::typeName(location.jitType), ":", bytecodeIndex);
+            if (wasmCompilationMode)
+                jitType = Wasm::makeString(wasmCompilationMode.value());
+            else
+                jitType = JITCode::typeName(location.jitType);
+
+            return makeString("#", codeBlockHash, ":", jitType, ":", bytecodeIndex);
         };
 
         StackFrame& frame = stackTrace.frames.first();
-        String frameDescription = makeString(frame.displayName(m_vm), descriptionForLocation(frame.semanticLocation));
+        String frameDescription = makeString(frame.displayName(m_vm), descriptionForLocation(frame.semanticLocation, frame.wasmCompilationMode));
         if (Optional<std::pair<StackFrame::CodeLocation, CodeBlock*>> machineLocation = frame.machineLocation) {
             frameDescription = makeString(frameDescription, " <-- ",
-                machineLocation->second->inferredName().data(), descriptionForLocation(machineLocation->first));
+                machineLocation->second->inferredName().data(), descriptionForLocation(machineLocation->first, WTF::nullopt));
         }
         bytecodeCounts.add(frameDescription, 0).iterator->value++;
     }
@@ -1101,6 +1191,9 @@
     case SamplingProfiler::FrameType::Executable:
         out.print("Executable");
         break;
+    case SamplingProfiler::FrameType::Wasm:
+        out.print("Wasm");
+        break;
     case SamplingProfiler::FrameType::Host:
         out.print("Host");
         break;

Modified: trunk/Source/_javascript_Core/runtime/SamplingProfiler.h (248186 => 248187)


--- trunk/Source/_javascript_Core/runtime/SamplingProfiler.h	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/runtime/SamplingProfiler.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -31,6 +31,8 @@
 #include "CodeBlockHash.h"
 #include "JITCode.h"
 #include "MachineStackMarker.h"
+#include "WasmCompilationMode.h"
+#include "WasmIndexOrName.h"
 #include <wtf/HashSet.h>
 #include <wtf/Lock.h>
 #include <wtf/Stopwatch.h>
@@ -63,13 +65,18 @@
         CalleeBits unverifiedCallee;
         CodeBlock* verifiedCodeBlock { nullptr };
         CallSiteIndex callSiteIndex;
+#if ENABLE(WEBASSEMBLY)
+        Optional<Wasm::IndexOrName> wasmIndexOrName;
+#endif
+        Optional<Wasm::CompilationMode> wasmCompilationMode;
     };
 
     enum class FrameType { 
         Executable,
+        Wasm,
         Host,
         C,
-        Unknown
+        Unknown,
     };
 
     struct StackFrame {
@@ -85,6 +92,10 @@
         const void* cCodePC { nullptr };
         ExecutableBase* executable { nullptr };
         JSObject* callee { nullptr };
+#if ENABLE(WEBASSEMBLY)
+        Optional<Wasm::IndexOrName> wasmIndexOrName;
+#endif
+        Optional<Wasm::CompilationMode> wasmCompilationMode;
 
         struct CodeLocation {
             bool hasCodeBlockHash() const

Modified: trunk/Source/_javascript_Core/tools/JSDollarVM.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/tools/JSDollarVM.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/tools/JSDollarVM.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -47,6 +47,7 @@
 #include "TypeProfiler.h"
 #include "TypeProfilerLog.h"
 #include "VMInspector.h"
+#include "WasmCapabilities.h"
 #include <wtf/Atomics.h>
 #include <wtf/DataLog.h>
 #include <wtf/ProcessID.h>
@@ -2201,6 +2202,15 @@
     return JSValue::encode(jsNumber(globalParseCount.load()));
 }
 
+static EncodedJSValue JSC_HOST_CALL functionIsWasmSupported(ExecState*)
+{
+#if ENABLE(WEBASSEMBLY)
+    return JSValue::encode(jsBoolean(Wasm::isSupported()));
+#else
+    return JSValue::encode(jsBoolean(false));
+#endif
+}
+
 void JSDollarVM::finishCreation(VM& vm)
 {
     Base::finishCreation(vm);
@@ -2317,6 +2327,8 @@
     addFunction(vm, "totalGCTime", functionTotalGCTime, 0);
 
     addFunction(vm, "parseCount", functionParseCount, 0);
+
+    addFunction(vm, "isWasmSupported", functionIsWasmSupported, 0);
 }
 
 void JSDollarVM::addFunction(VM& vm, JSGlobalObject* globalObject, const char* name, NativeFunction function, unsigned arguments)

Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.h (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.h	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -31,6 +31,7 @@
 #include "B3Compilation.h"
 #include "B3OpaqueByproducts.h"
 #include "CCallHelpers.h"
+#include "WasmCompilationMode.h"
 #include "WasmEmbedder.h"
 #include "WasmMemory.h"
 #include "WasmModuleInformation.h"
@@ -43,11 +44,6 @@
 
 class MemoryInformation;
 
-enum class CompilationMode {
-    BBQMode,
-    OMGMode,
-};
-
 struct CompilationContext {
     std::unique_ptr<CCallHelpers> embedderEntrypointJIT;
     std::unique_ptr<B3::OpaqueByproducts> embedderEntrypointByproducts;

Modified: trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmBBQPlan.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -306,6 +306,8 @@
             CompilationContext& context = m_compilationContexts[functionIndex];
             SignatureIndex signatureIndex = m_moduleInformation->internalFunctionSignatureIndices[functionIndex];
             const Signature& signature = SignatureInformation::get(signatureIndex);
+            const uint32_t functionIndexSpace = functionIndex + m_moduleInformation->importFunctionCount();
+            ASSERT(functionIndexSpace < m_moduleInformation->functionIndexSpaceSize());
             {
                 LinkBuffer linkBuffer(*context.wasmEntrypointJIT, nullptr, JITCompilationCanFail);
                 if (UNLIKELY(linkBuffer.didFailToAllocate())) {
@@ -314,7 +316,7 @@
                 }
 
                 m_wasmInternalFunctions[functionIndex]->entrypoint.compilation = std::make_unique<B3::Compilation>(
-                    FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "WebAssembly BBQ function[%i] %s", functionIndex, signature.toString().ascii().data()),
+                    FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "WebAssembly BBQ function[%i] %s name %s", functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
                     WTFMove(context.wasmEntrypointByproducts));
             }
 
@@ -326,7 +328,7 @@
                 }
 
                 embedderToWasmInternalFunction->entrypoint.compilation = std::make_unique<B3::Compilation>(
-                    FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "Embedder->WebAssembly entrypoint[%i] %s", functionIndex, signature.toString().ascii().data()),
+                    FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "Embedder->WebAssembly entrypoint[%i] %s name %s", functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
                     WTFMove(context.embedderEntrypointByproducts));
             }
         }

Modified: trunk/Source/_javascript_Core/wasm/WasmBBQPlanInlines.h (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmBBQPlanInlines.h	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmBBQPlanInlines.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -42,13 +42,13 @@
 
         RefPtr<Wasm::Callee> embedderEntrypointCallee;
         if (auto embedderToWasmFunction = m_embedderToWasmInternalFunctions.get(internalFunctionIndex)) {
-            embedderEntrypointCallee = Wasm::Callee::create(WTFMove(embedderToWasmFunction->entrypoint));
+            embedderEntrypointCallee = Wasm::Callee::create(CompilationMode::BBQMode, WTFMove(embedderToWasmFunction->entrypoint));
             MacroAssembler::repatchPointer(embedderToWasmFunction->calleeMoveLocation, CalleeBits::boxWasm(embedderEntrypointCallee.get()));
         }
 
         InternalFunction* function = m_wasmInternalFunctions[internalFunctionIndex].get();
         size_t functionIndexSpace = internalFunctionIndex + m_moduleInformation->importFunctionCount();
-        Ref<Wasm::Callee> wasmEntrypointCallee = Wasm::Callee::create(WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace));
+        Ref<Wasm::Callee> wasmEntrypointCallee = Wasm::Callee::create(CompilationMode::BBQMode, WTFMove(function->entrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace));
         MacroAssembler::repatchPointer(function->calleeMoveLocation, CalleeBits::boxWasm(wasmEntrypointCallee.ptr()));
 
         callback(internalFunctionIndex, WTFMove(embedderEntrypointCallee), WTFMove(wasmEntrypointCallee));

Modified: trunk/Source/_javascript_Core/wasm/WasmCallee.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmCallee.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmCallee.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -28,23 +28,30 @@
 
 #if ENABLE(WEBASSEMBLY)
 
-#include "WasmFaultSignalHandler.h"
+#include "WasmCalleeRegistry.h"
 
 namespace JSC { namespace Wasm {
 
-Callee::Callee(Entrypoint&& entrypoint)
-    : m_entrypoint(WTFMove(entrypoint))
+Callee::Callee(Wasm::CompilationMode compilationMode, Entrypoint&& entrypoint)
+    : m_compilationMode(compilationMode)
+    , m_entrypoint(WTFMove(entrypoint))
 {
-    registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start().untaggedPtr(), m_entrypoint.compilation->codeRef().executableMemory()->end().untaggedPtr());
+    CalleeRegistry::singleton().registerCallee(this);
 }
 
-Callee::Callee(Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name)
-    : m_entrypoint(WTFMove(entrypoint))
+Callee::Callee(Wasm::CompilationMode compilationMode, Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name)
+    : m_compilationMode(compilationMode)
+    , m_entrypoint(WTFMove(entrypoint))
     , m_indexOrName(index, WTFMove(name))
 {
-    registerCode(m_entrypoint.compilation->codeRef().executableMemory()->start().untaggedPtr(), m_entrypoint.compilation->codeRef().executableMemory()->end().untaggedPtr());
+    CalleeRegistry::singleton().registerCallee(this);
 }
 
+Callee::~Callee()
+{
+    CalleeRegistry::singleton().unregisterCallee(this);
+}
+
 } } // namespace JSC::Wasm
 
 #endif // ENABLE(WEBASSEMBLY)

Modified: trunk/Source/_javascript_Core/wasm/WasmCallee.h (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmCallee.h	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmCallee.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -29,6 +29,7 @@
 
 #include "B3Compilation.h"
 #include "RegisterAtOffsetList.h"
+#include "WasmCompilationMode.h"
 #include "WasmFormat.h"
 #include "WasmIndexOrName.h"
 #include <wtf/ThreadSafeRefCounted.h>
@@ -35,18 +36,18 @@
 
 namespace JSC { namespace Wasm {
 
-class Callee : public ThreadSafeRefCounted<Callee> {
+class Callee final : public ThreadSafeRefCounted<Callee> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<Callee> create(Wasm::Entrypoint&& entrypoint)
+    static Ref<Callee> create(Wasm::CompilationMode compilationMode, Wasm::Entrypoint&& entrypoint)
     {
-        Callee* callee = new Callee(WTFMove(entrypoint));
+        Callee* callee = new Callee(compilationMode, WTFMove(entrypoint));
         return adoptRef(*callee);
     }
 
-    static Ref<Callee> create(Wasm::Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name)
+    static Ref<Callee> create(Wasm::CompilationMode compilationMode, Wasm::Entrypoint&& entrypoint, size_t index, std::pair<const Name*, RefPtr<NameSection>>&& name)
     {
-        Callee* callee = new Callee(WTFMove(entrypoint), index, WTFMove(name));
+        Callee* callee = new Callee(compilationMode, WTFMove(entrypoint), index, WTFMove(name));
         return adoptRef(*callee);
     }
 
@@ -54,11 +55,22 @@
 
     RegisterAtOffsetList* calleeSaveRegisters() { return &m_entrypoint.calleeSaveRegisters; }
     IndexOrName indexOrName() const { return m_indexOrName; }
+    CompilationMode compilationMode() const { return m_compilationMode; }
 
+    std::tuple<void*, void*> range() const
+    {
+        void* start = m_entrypoint.compilation->codeRef().executableMemory()->start().untaggedPtr();
+        void* end = m_entrypoint.compilation->codeRef().executableMemory()->end().untaggedPtr();
+        return { start, end };
+    }
+
+    JS_EXPORT_PRIVATE ~Callee();
+
 private:
-    JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&);
-    JS_EXPORT_PRIVATE Callee(Wasm::Entrypoint&&, size_t, std::pair<const Name*, RefPtr<NameSection>>&&);
+    JS_EXPORT_PRIVATE Callee(Wasm::CompilationMode, Wasm::Entrypoint&&);
+    JS_EXPORT_PRIVATE Callee(Wasm::CompilationMode, Wasm::Entrypoint&&, size_t, std::pair<const Name*, RefPtr<NameSection>>&&);
 
+    CompilationMode m_compilationMode;
     Wasm::Entrypoint m_entrypoint;
     IndexOrName m_indexOrName;
 };

Copied: trunk/Source/_javascript_Core/wasm/WasmCalleeRegistry.cpp (from rev 248185, trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h) (0 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmCalleeRegistry.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/wasm/WasmCalleeRegistry.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WasmCalleeRegistry.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include <wtf/NeverDestroyed.h>
+
+namespace JSC { namespace Wasm {
+
+static LazyNeverDestroyed<CalleeRegistry> calleeRegistry;
+
+void CalleeRegistry::initialize()
+{
+    calleeRegistry.construct();
+}
+
+CalleeRegistry& CalleeRegistry::singleton()
+{
+    return calleeRegistry.get();
+}
+
+} } // namespace JSC::Wasm
+
+#endif // ENABLE(WEBASSEMBLY)

Copied: trunk/Source/_javascript_Core/wasm/WasmCalleeRegistry.h (from rev 248185, trunk/Source/_javascript_Core/wasm/WasmCallee.cpp) (0 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmCalleeRegistry.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/wasm/WasmCalleeRegistry.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include <wtf/HashSet.h>
+#include <wtf/Lock.h>
+
+namespace JSC { namespace Wasm {
+
+class Callee;
+
+class CalleeRegistry {
+    WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(CalleeRegistry);
+public:
+    static void initialize();
+    static CalleeRegistry& singleton();
+
+    Lock& getLock() { return m_lock; }
+
+    void registerCallee(Callee* callee)
+    {
+        auto locker = holdLock(m_lock);
+        m_calleeSet.add(callee);
+    }
+
+    void unregisterCallee(Callee* callee)
+    {
+        auto locker = holdLock(m_lock);
+        m_calleeSet.remove(callee);
+    }
+
+    const HashSet<Callee*>& allCallees(const AbstractLocker&)
+    {
+        return m_calleeSet;
+    }
+
+    bool isValidCallee(const AbstractLocker&, Callee* callee)
+    {
+        return m_calleeSet.contains(callee);
+    }
+
+    CalleeRegistry() = default;
+
+private:
+    Lock m_lock;
+    HashSet<Callee*> m_calleeSet;
+};
+
+} } // namespace JSC::Wasm
+
+#endif // ENABLE(WEBASSEMBLY)

Copied: trunk/Source/_javascript_Core/wasm/WasmCompilationMode.cpp (from rev 248185, trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h) (0 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmCompilationMode.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/wasm/WasmCompilationMode.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WasmCompilationMode.h"
+
+#include <wtf/Assertions.h>
+
+namespace JSC { namespace Wasm {
+
+const char* makeString(CompilationMode mode)
+{
+    switch (mode) {
+    case CompilationMode::BBQMode:
+        return "BBQ";
+    case CompilationMode::OMGMode:
+        return "OMG";
+    }
+    RELEASE_ASSERT_NOT_REACHED();
+    return "";
+}
+
+} } // namespace JSC::Wasm

Copied: trunk/Source/_javascript_Core/wasm/WasmCompilationMode.h (from rev 248185, trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h) (0 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmCompilationMode.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/wasm/WasmCompilationMode.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace JSC { namespace Wasm {
+
+enum class CompilationMode : uint8_t {
+    BBQMode,
+    OMGMode,
+};
+
+const char* makeString(CompilationMode);
+
+} } // namespace JSC::Wasm

Modified: trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -30,6 +30,8 @@
 
 #include "ExecutableAllocator.h"
 #include "MachineContext.h"
+#include "WasmCallee.h"
+#include "WasmCalleeRegistry.h"
 #include "WasmCapabilities.h"
 #include "WasmExceptionType.h"
 #include "WasmMemory.h"
@@ -48,9 +50,6 @@
 }
 }
 
-static Lock codeLocationsLock;
-static LazyNeverDestroyed<HashSet<std::tuple<void*, void*>>> codeLocations; // (start, end)
-
 static bool fastHandlerInstalled { false };
 
 #if ENABLE(WEBASSEMBLY_FAST_MEMORY)
@@ -76,8 +75,10 @@
         }
         if (faultedInActiveFastMemory) {
             dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "found active fast memory for faulting address");
-            LockHolder locker(codeLocationsLock);
-            for (auto [start, end] : codeLocations.get()) {
+            auto& calleeRegistry = CalleeRegistry::singleton();
+            auto locker = holdLock(calleeRegistry.getLock());
+            for (auto* callee : calleeRegistry.allCallees(locker)) {
+                auto [start, end] = callee->range();
                 dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "function start: ", RawPointer(start), " end: ", RawPointer(end));
                 if (start <= faultingInstruction && faultingInstruction < end) {
                     dataLogLnIf(WasmFaultSignalHandlerInternal::verbose, "found match");
@@ -98,22 +99,6 @@
 
 #endif // ENABLE(WEBASSEMBLY_FAST_MEMORY)
 
-void registerCode(void* start, void* end)
-{
-    if (!fastMemoryEnabled())
-        return;
-    LockHolder locker(codeLocationsLock);
-    codeLocations->add(std::make_tuple(start, end));
-}
-
-void unregisterCode(void* start, void* end)
-{
-    if (!fastMemoryEnabled())
-        return;
-    LockHolder locker(codeLocationsLock);
-    codeLocations->remove(std::make_tuple(start, end));
-}
-
 bool fastMemoryEnabled()
 {
     return fastHandlerInstalled;
@@ -134,7 +119,6 @@
             return trapHandler(signal, sigInfo, ucontext);
         });
 
-        codeLocations.construct();
         fastHandlerInstalled = true;
     });
 #endif // ENABLE(WEBASSEMBLY_FAST_MEMORY)

Modified: trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -29,9 +29,6 @@
 
 namespace Wasm {
 
-void registerCode(void* start, void* end);
-void unregisterCode(void* start, void* end);
-
 bool fastMemoryEnabled();
 JS_EXPORT_PRIVATE void enableFastMemory();
 

Modified: trunk/Source/_javascript_Core/wasm/WasmIndexOrName.h (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmIndexOrName.h	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmIndexOrName.h	2019-08-02 22:58:09 UTC (rev 248187)
@@ -35,6 +35,8 @@
 
 struct NameSection;
 
+// Keep this class copyable when the world is stopped: do not allocate any memory while copying this.
+// SamplingProfiler copies it while suspending threads.
 struct IndexOrName {
     typedef size_t Index;
 

Modified: trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp (248186 => 248187)


--- trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp	2019-08-02 22:57:58 UTC (rev 248186)
+++ trunk/Source/_javascript_Core/wasm/WasmOMGPlan.cpp	2019-08-02 22:58:09 UTC (rev 248187)
@@ -96,7 +96,7 @@
     }
 
     omgEntrypoint.compilation = std::make_unique<B3::Compilation>(
-        FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "WebAssembly OMG function[%i] %s", m_functionIndex, signature.toString().ascii().data()),
+        FINALIZE_CODE(linkBuffer, B3CompilationPtrTag, "WebAssembly OMG function[%i] %s name %s", m_functionIndex, signature.toString().ascii().data(), makeString(IndexOrName(functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace))).ascii().data()),
         WTFMove(context.wasmEntrypointByproducts));
 
     omgEntrypoint.calleeSaveRegisters = WTFMove(parseAndCompileResult.value()->entrypoint.calleeSaveRegisters);
@@ -104,7 +104,7 @@
     MacroAssemblerCodePtr<WasmEntryPtrTag> entrypoint;
     {
         ASSERT(m_codeBlock.ptr() == m_module->codeBlockFor(mode()));
-        Ref<Callee> callee = Callee::create(WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace));
+        Ref<Callee> callee = Callee::create(CompilationMode::OMGMode, WTFMove(omgEntrypoint), functionIndexSpace, m_moduleInformation->nameSection->get(functionIndexSpace));
         MacroAssembler::repatchPointer(parseAndCompileResult.value()->calleeMoveLocation, CalleeBits::boxWasm(callee.ptr()));
         ASSERT(!m_codeBlock->m_optimizedCallees[m_functionIndex]);
         entrypoint = callee->entrypoint();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to