Ignore:
Timestamp:
Aug 19, 2011, 7:17:49 PM (14 years ago)
Author:
[email protected]
Message:

The JSC JIT currently has no facility to profile and report
the types of values
https://bugs.webkit.org/show_bug.cgi?id=65901

Reviewed by Gavin Barraclough.

Added the ability to profile the values seen at function calls (both
arguments and results) and heap loads. This is done with emphasis
on performance. A value profiling site consists of: add, and,
move, and store; no branching is necessary. Each value profiling
site (called a ValueProfile) has a ring buffer of 8 recently-seen
values. ValueProfiles are stored in the CodeBlock; there will be
one for each argument (excluding this) and each heap load or callsite.
Each time a value profiling site executes, it stores the value into
a pseudo-random element in the ValueProfile buffer. The point is
that for frequently executed code, we will have 8 somewhat recent
values in the buffer and will be able to not only figure out what
type it is, but also to be able to reason about the actual values
if we wish to do so.

This feature is currently disabled by default. When enabled, it
results in a 3.7% slow-down on SunSpider.

(JSC::CodeBlock::~CodeBlock):

  • bytecode/CodeBlock.h:

(JSC::CodeBlock::addValueProfile):
(JSC::CodeBlock::numberOfValueProfiles):
(JSC::CodeBlock::valueProfile):
(JSC::CodeBlock::valueProfileForBytecodeOffset):

  • bytecode/ValueProfile.h: Added.

(JSC::ValueProfile::ValueProfile):
(JSC::ValueProfile::numberOfSamples):
(JSC::ValueProfile::computeProbability):
(JSC::ValueProfile::numberOfInt32s):
(JSC::ValueProfile::numberOfDoubles):
(JSC::ValueProfile::numberOfCells):
(JSC::ValueProfile::probabilityOfInt32):
(JSC::ValueProfile::probabilityOfDouble):
(JSC::ValueProfile::probabilityOfCell):
(JSC::getValueProfileBytecodeOffset):

  • jit/JIT.cpp:

(JSC::JIT::privateCompileSlowCases):
(JSC::JIT::privateCompile):

  • jit/JIT.h:

(JSC::JIT::emitValueProfilingSite):

  • jit/JITCall.cpp:

(JSC::JIT::emit_op_call_put_result):

  • jit/JITInlineMethods.h:

(JSC::JIT::emitValueProfilingSite):

  • jit/JITPropertyAccess.cpp:

(JSC::JIT::emit_op_get_by_val):
(JSC::JIT::emitSlow_op_get_by_val):
(JSC::JIT::emit_op_method_check):
(JSC::JIT::emit_op_get_by_id):
(JSC::JIT::emitSlow_op_get_by_id):

  • jit/JSInterfaceJIT.h:
  • wtf/Platform.h:
  • wtf/StdLibExtras.h:

(WTF::binarySearch):
(WTF::genericBinarySearch):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/StdLibExtras.h

    r93039 r93466  
    131131// Binary search algorithm, calls extractKey on pre-sorted elements in array,
    132132// compares result with key (KeyTypes should be comparable with '--', '<', '>').
    133 template<typename ArrayType, typename KeyType, KeyType(*extractKey)(ArrayType*)>
    134 inline ArrayType* binarySearch(ArrayType* array, size_t size, KeyType key, BinarySearchMode mode = KeyMustBePresentInArray)
     133template<typename ArrayElementType, typename KeyType, KeyType(*extractKey)(ArrayElementType*)>
     134inline ArrayElementType* binarySearch(ArrayElementType* array, size_t size, KeyType key, BinarySearchMode mode = KeyMustBePresentInArray)
    135135{
    136136    // The array must contain at least one element (pre-condition, array does contain key).
     
    169169}
    170170
     171// Modified binarySearch() algorithm designed for array-like classes that support
     172// operator[] but not operator+=. One example of a class that qualifies is
     173// SegmentedVector.
     174template<typename ArrayElementType, typename KeyType, KeyType(*extractKey)(ArrayElementType*), typename ArrayType>
     175inline ArrayElementType* genericBinarySearch(ArrayType& array, size_t size, KeyType key)
     176{
     177    // The array must contain at least one element (pre-condition, array does conatin key).
     178    // If the array only contains one element, no need to do the comparison.
     179    size_t offset = 0;
     180    while (size > 1) {
     181        // Pick an element to check, half way through the array, and read the value.
     182        int pos = (size - 1) >> 1;
     183        KeyType val = extractKey(&array[offset + pos]);
     184       
     185        // If the key matches, success!
     186        if (val == key)
     187            return &array[offset + pos];
     188        // The item we are looking for is smaller than the item being check; reduce the value of 'size',
     189        // chopping off the right hand half of the array.
     190        if (key < val)
     191            size = pos;
     192        // Discard all values in the left hand half of the array, up to and including the item at pos.
     193        else {
     194            size -= (pos + 1);
     195            offset += (pos + 1);
     196        }
     197
     198        // 'size' should never reach zero.
     199        ASSERT(size);
     200    }
     201   
     202    // If we reach this point we've chopped down to one element, no need to check it matches
     203    ASSERT(size == 1);
     204    ASSERT(key == extractKey(&array[offset]));
     205    return &array[offset];
     206}
     207
    171208} // namespace WTF
    172209
Note: See TracChangeset for help on using the changeset viewer.