Ignore:
Timestamp:
Nov 6, 2011, 3:39:12 AM (14 years ago)
Author:
[email protected]
Message:

JSC should be able to sample itself in a more flexible way than just sampling flags
https://bugs.webkit.org/show_bug.cgi?id=71522

Source/JavaScriptCore:

Reviewed by Gavin Barraclough.

Added a construct that looks like SamplingRegion samplingRegion("name").

(JSC::SamplingRegion::Locker::Locker):
(JSC::SamplingRegion::Locker::~Locker):
(JSC::SamplingRegion::sample):
(JSC::SamplingRegion::dump):
(JSC::SamplingRegion::dumpInternal):
(JSC::SamplingThread::threadStartFunc):

  • bytecode/SamplingTool.h:

(JSC::SamplingRegion::SamplingRegion):
(JSC::SamplingRegion::~SamplingRegion):
(JSC::SamplingRegion::exchangeCurrent):

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):

  • dfg/DFGDriver.cpp:

(JSC::DFG::compile):

  • heap/Heap.cpp:

(JSC::Heap::markRoots):
(JSC::Heap::collect):

  • heap/VTableSpectrum.cpp:

(JSC::VTableSpectrum::countVPtr):
(JSC::VTableSpectrum::dump):

  • heap/VTableSpectrum.h:
  • jsc.cpp:

(main):
(runWithScripts):

  • parser/Parser.h:

(JSC::parse):

  • runtime/Executable.cpp:

(JSC::EvalExecutable::compileInternal):
(JSC::ProgramExecutable::compileInternal):
(JSC::FunctionExecutable::compileForCallInternal):
(JSC::FunctionExecutable::compileForConstructInternal):

  • wtf/Atomics.h:

(WTF::weakCompareAndSwap):

  • wtf/Platform.h:
  • wtf/Spectrum.h: Added.

(WTF::Spectrum::Spectrum):
(WTF::Spectrum::add):
(WTF::Spectrum::get):
(WTF::Spectrum::begin):
(WTF::Spectrum::end):
(WTF::Spectrum::KeyAndCount::KeyAndCount):
(WTF::Spectrum::KeyAndCount::operator<):
(WTF::Spectrum::buildList):

  • wtf/wtf.pri:

Source/JavaScriptGlue:

Reviewed by Gavin Barraclough.

  • ForwardingHeaders/wtf/Spectrum.h: Added.

Source/WebCore:

Reviewed by Gavin Barraclough.

No new tests, since no functionality changed.

  • ForwardingHeaders/wtf/Spectrum.h: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecode/SamplingTool.h

    r95901 r99374  
    3535#include "SamplingCounter.h"
    3636#include <wtf/Assertions.h>
     37#include <wtf/Atomics.h>
    3738#include <wtf/HashMap.h>
     39#include <wtf/MainThread.h>
    3840#include <wtf/Threading.h>
    3941
     
    9395#endif
    9496    };
     97
     98#if ENABLE(SAMPLING_REGIONS)
     99    class SamplingRegion {
     100    public:
     101        // Create a scoped sampling region using a C string constant name that describes
     102        // what you are doing. This must be a string constant that persists for the
     103        // lifetime of the process and is immutable.
     104        SamplingRegion(const char* name)
     105        {
     106            if (!isMainThread()) {
     107                m_name = 0;
     108                return;
     109            }
     110           
     111            m_name = name;
     112            exchangeCurrent(this, &m_previous);
     113            ASSERT(!m_previous || m_previous > this);
     114        }
     115       
     116        ~SamplingRegion()
     117        {
     118            if (!m_name)
     119                return;
     120           
     121            ASSERT(bitwise_cast<SamplingRegion*>(s_currentOrReserved & ~1) == this);
     122            exchangeCurrent(m_previous);
     123        }
     124       
     125        static void sample();
     126       
     127        static void dump();
     128       
     129    private:
     130        const char* m_name;
     131        SamplingRegion* m_previous;
     132
     133        static void exchangeCurrent(SamplingRegion* current, SamplingRegion** previousPtr = 0)
     134        {
     135            uintptr_t previous;
     136            while (true) {
     137                previous = s_currentOrReserved;
     138               
     139                // If it's reserved (i.e. sampling thread is reading it), loop around.
     140                if (previous & 1) {
     141#if OS(UNIX)
     142                    sched_yield();
     143#endif
     144                    continue;
     145                }
     146               
     147                // If we're going to CAS, then make sure previous is set.
     148                if (previousPtr)
     149                    *previousPtr = bitwise_cast<SamplingRegion*>(previous);
     150               
     151                if (WTF::weakCompareAndSwap(&s_currentOrReserved, previous, bitwise_cast<uintptr_t>(current)))
     152                    break;
     153            }
     154        }
     155       
     156        static void dumpInternal();
     157
     158        class Locker {
     159        public:
     160            Locker();
     161            ~Locker();
     162        };
     163
     164        static volatile uintptr_t s_currentOrReserved;
     165       
     166        // rely on identity hashing of string constants
     167        static Spectrum<const char*>* s_spectrum;
     168       
     169        static unsigned long s_noneOfTheAbove;
     170       
     171        static unsigned s_numberOfSamplesSinceDump;
     172    };
     173#else // ENABLE(SAMPLING_REGIONS)
     174    class SamplingRegion {
     175    public:
     176        SamplingRegion(const char*) { }
     177        void dump();
     178    };
     179#endif // ENABLE(SAMPLING_REGIONS)
    95180
    96181    class CodeBlock;
Note: See TracChangeset for help on using the changeset viewer.