Enable SamplingProfiler on POSIX environment
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jan 2016 12:53:59 +0000 (12:53 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jan 2016 12:53:59 +0000 (12:53 +0000)
commit56bb2fe564bdad8b1b36f63d25598b4da8956360
tree095ccc8c9f49a3fa67356af77e6dc6ea3f2dc6b9
parentf107ada22f74ba58785f7f7f06e85ed5bc80a00d
Enable SamplingProfiler on POSIX environment
https://bugs.webkit.org/show_bug.cgi?id=153584

Reviewed by Michael Saboff.

.:

Add features.h header check. It will define __GLIBC__.

* Source/cmake/OptionsCommon.cmake:

Source/JavaScriptCore:

In this patch, we implement suspend and resume mechanizm for POSIX threads.
And with GLIBC, we can retrieve registers from it.

We take the following strategy.

Suspend side.
1. install sigaction to the threads.
2. in the profiler (suspend / resume callers), emit signal with pthread_kill and wait with POSIX semaphore.
3. in the signal handler, up the POSIX semaphore. Use sem_post because it is the async-signal-safe function in POSIX.
4. in the signal handler, perform sigsuspend to stop the thread until being resumed.
5. in the profiler, we can be waken up from the semaphore because (3) ups.

Resume side.
1. in the profiler, emit signal and wait on the semaphore.
2. in the signal handler, it is waken up from the sigsuspend.
3. in the signal handler, up the semaphore.
4. in the profiler, the profiler is waken up from the semaphore. It is ensured that the given thread is resumed by the signal.

* heap/MachineStackMarker.cpp:
(pthreadSignalHandlerSuspendResume):
(JSC::MachineThreads::Thread::Thread):
(JSC::MachineThreads::Thread::~Thread):
(JSC::MachineThreads::Thread::suspend):
(JSC::MachineThreads::Thread::resume):
(JSC::MachineThreads::Thread::getRegisters):
(JSC::MachineThreads::Thread::Registers::stackPointer):
(JSC::MachineThreads::Thread::Registers::framePointer):
(JSC::MachineThreads::Thread::Registers::instructionPointer):
(JSC::MachineThreads::Thread::Registers::llintPC):
(JSC::MachineThreads::Thread::freeRegisters):
* heap/MachineStackMarker.h:
* runtime/SamplingProfiler.cpp:
(JSC::reportStats):
* tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js:
* tests/stress/call-varargs-from-inlined-code.js:
* tests/stress/v8-earley-boyer-strict.js:

Source/WTF:

Use __GLIBC__ since mcontext_t layout depends on it.

* wtf/Platform.h:

Tools:

* Scripts/run-jsc-stress-tests:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
ChangeLog
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/heap/MachineStackMarker.cpp
Source/JavaScriptCore/heap/MachineStackMarker.h
Source/JavaScriptCore/runtime/SamplingProfiler.cpp
Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js
Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code.js
Source/JavaScriptCore/tests/stress/v8-earley-boyer-strict.js
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/cmake/OptionsCommon.cmake
Tools/ChangeLog
Tools/Scripts/run-jsc-stress-tests