diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/JavaScriptCore/wtf | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/JavaScriptCore/wtf')
23 files changed, 362 insertions, 73 deletions
diff --git a/Source/JavaScriptCore/wtf/Assertions.cpp b/Source/JavaScriptCore/wtf/Assertions.cpp index 3c4fc77..77e30c1 100644 --- a/Source/JavaScriptCore/wtf/Assertions.cpp +++ b/Source/JavaScriptCore/wtf/Assertions.cpp @@ -24,6 +24,12 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// The vprintf_stderr_common function triggers this error in the Mac build. +// Feel free to remove this pragma if this file builds on Mac. +// According to http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas +// we need to place this directive before any data or functions are defined. +#pragma GCC diagnostic ignored "-Wmissing-format-attribute" + #include "config.h" #include "Assertions.h" diff --git a/Source/JavaScriptCore/wtf/Assertions.h b/Source/JavaScriptCore/wtf/Assertions.h index 13ece31..1d108e4 100644 --- a/Source/JavaScriptCore/wtf/Assertions.h +++ b/Source/JavaScriptCore/wtf/Assertions.h @@ -142,14 +142,14 @@ typedef struct { WTFLogChannelState state; } WTFLogChannel; -void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion); -void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); -void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion); -void WTFReportBacktrace(); -void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); -void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); -void WTFLog(WTFLogChannel* channel, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); -void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); +WTF_EXPORT_PRIVATE void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion); +WTF_EXPORT_PRIVATE void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); +WTF_EXPORT_PRIVATE void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion); +WTF_EXPORT_PRIVATE void WTFReportBacktrace(); +WTF_EXPORT_PRIVATE void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); +WTF_EXPORT_PRIVATE void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5); +WTF_EXPORT_PRIVATE void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); +WTF_EXPORT_PRIVATE void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6); #ifdef __cplusplus } diff --git a/Source/JavaScriptCore/wtf/Atomics.h b/Source/JavaScriptCore/wtf/Atomics.h index 1d190a3..1ebd487 100644 --- a/Source/JavaScriptCore/wtf/Atomics.h +++ b/Source/JavaScriptCore/wtf/Atomics.h @@ -78,7 +78,7 @@ namespace WTF { #if OS(WINDOWS) -#define WTF_USE_LOCKFREE_THREADSAFESHARED 1 +#define WTF_USE_LOCKFREE_THREADSAFEREFCOUNTED 1 #if COMPILER(MINGW) || COMPILER(MSVC7_OR_LOWER) || OS(WINCE) inline int atomicIncrement(int* addend) { return InterlockedIncrement(reinterpret_cast<long*>(addend)); } @@ -89,7 +89,7 @@ inline int atomicDecrement(int volatile* addend) { return InterlockedDecrement(r #endif #elif OS(DARWIN) -#define WTF_USE_LOCKFREE_THREADSAFESHARED 1 +#define WTF_USE_LOCKFREE_THREADSAFEREFCOUNTED 1 inline int atomicIncrement(int volatile* addend) { return OSAtomicIncrement32Barrier(const_cast<int*>(addend)); } inline int atomicDecrement(int volatile* addend) { return OSAtomicDecrement32Barrier(const_cast<int*>(addend)); } @@ -100,7 +100,7 @@ inline int atomicIncrement(int volatile* addend) { return android_atomic_inc(add inline int atomicDecrement(int volatile* addend) { return android_atomic_dec(addend); } #elif COMPILER(GCC) && !CPU(SPARC64) && !OS(SYMBIAN) // sizeof(_Atomic_word) != sizeof(int) on sparc64 gcc -#define WTF_USE_LOCKFREE_THREADSAFESHARED 1 +#define WTF_USE_LOCKFREE_THREADSAFEREFCOUNTED 1 inline int atomicIncrement(int volatile* addend) { return __gnu_cxx::__exchange_and_add(addend, 1) + 1; } inline int atomicDecrement(int volatile* addend) { return __gnu_cxx::__exchange_and_add(addend, -1) - 1; } @@ -109,7 +109,7 @@ inline int atomicDecrement(int volatile* addend) { return __gnu_cxx::__exchange_ } // namespace WTF -#if USE(LOCKFREE_THREADSAFESHARED) +#if USE(LOCKFREE_THREADSAFEREFCOUNTED) using WTF::atomicDecrement; using WTF::atomicIncrement; #endif diff --git a/Source/JavaScriptCore/wtf/CMakeLists.txt b/Source/JavaScriptCore/wtf/CMakeLists.txt index c27b2e5..304be73 100644 --- a/Source/JavaScriptCore/wtf/CMakeLists.txt +++ b/Source/JavaScriptCore/wtf/CMakeLists.txt @@ -30,6 +30,7 @@ SET(WTF_HEADERS HashSet.h HashTable.h HashTraits.h + HexNumber.h ListHashSet.h ListRefPtr.h Locker.h @@ -76,7 +77,7 @@ SET(WTF_HEADERS TCSpinLock.h TCSystemAlloc.h ThreadIdentifierDataPthreads.h - ThreadSafeShared.h + ThreadSafeRefCounted.h ThreadSpecific.h Threading.h ThreadingPrimitives.h diff --git a/Source/JavaScriptCore/wtf/CrossThreadRefCounted.h b/Source/JavaScriptCore/wtf/CrossThreadRefCounted.h index 8b65977..9d093ee 100644 --- a/Source/JavaScriptCore/wtf/CrossThreadRefCounted.h +++ b/Source/JavaScriptCore/wtf/CrossThreadRefCounted.h @@ -38,10 +38,10 @@ namespace WTF { - // Used to allowing sharing data across classes and threads (like ThreadedSafeShared). + // Used to allowing sharing data across classes and threads (like ThreadSafeRefCounted). // - // Why not just use ThreadSafeShared? - // ThreadSafeShared can have a significant perf impact when used in low level classes + // Why not just use ThreadSafeRefCounted? + // ThreadSafeRefCounted can have a significant perf impact when used in low level classes // (like UString) that get ref/deref'ed a lot. This class has the benefit of doing fast ref // counts like RefPtr whenever possible, but it has the downside that you need to copy it // to use it on another thread. @@ -72,7 +72,7 @@ namespace WTF { } private: - CrossThreadRefCounted(T* data, ThreadSafeSharedBase* threadedCounter) + CrossThreadRefCounted(T* data, ThreadSafeRefCountedBase* threadedCounter) : m_threadSafeRefCounter(threadedCounter) , m_data(data) #ifndef NDEBUG @@ -97,7 +97,7 @@ namespace WTF { #endif RefCountedBase m_refCounter; - ThreadSafeSharedBase* m_threadSafeRefCounter; + ThreadSafeRefCountedBase* m_threadSafeRefCounter; T* m_data; #ifndef NDEBUG ThreadIdentifier m_threadId; @@ -154,7 +154,7 @@ namespace WTF { if (m_threadSafeRefCounter) m_threadSafeRefCounter->ref(); else - m_threadSafeRefCounter = new ThreadSafeSharedBase(2); + m_threadSafeRefCounter = new ThreadSafeRefCountedBase(2); return adoptRef(new CrossThreadRefCounted<T>(m_data, m_threadSafeRefCounter)); } diff --git a/Source/JavaScriptCore/wtf/DateMath.cpp b/Source/JavaScriptCore/wtf/DateMath.cpp index 062cc1b..70c0cf4 100644 --- a/Source/JavaScriptCore/wtf/DateMath.cpp +++ b/Source/JavaScriptCore/wtf/DateMath.cpp @@ -75,6 +75,9 @@ #include "Assertions.h" #include "ASCIICType.h" #include "CurrentTime.h" +#if USE(JSC) +#include "JSObject.h" +#endif #include "MathExtras.h" #if USE(JSC) #include "ScopeChain.h" @@ -924,8 +927,10 @@ static double parseDateFromNullTerminatedCharacters(const char* dateString, bool } } - // The year may be after the time but before the time zone. - if (year <= 0) { + // The year may be after the time but before the time zone, but don't + // confuse a time zone specificed as an offset from UTC (e.g. +0100) with a + // four-digit year. + if (year <= 0 && *dateString != '+' && *dateString != '-') { if (!parseLong(dateString, &newPosStr, 10, &year)) year = 0; dateString = newPosStr; diff --git a/Source/JavaScriptCore/wtf/ExportMacros.h b/Source/JavaScriptCore/wtf/ExportMacros.h new file mode 100644 index 0000000..3fadd37 --- /dev/null +++ b/Source/JavaScriptCore/wtf/ExportMacros.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 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 COMPUTER, 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 COMPUTER, 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. + * + * This file handles shared library symbol export decorations. It is recommended + * that all WebKit projects use these definitions so that symbol exports work + * properly on all platforms and compilers that WebKit builds under. + */ + +#ifndef ExportMacros_h +#define ExportMacros_h + +#include "Platform.h" + +#if !PLATFORM(CHROMIUM) && OS(WINDOWS) && !COMPILER(GCC) +#define WTF_EXPORT __declspec(dllexport) +#define WTF_IMPORT __declspec(dllimport) +#elif defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC__) +#define WTF_EXPORT __attribute__((visibility("default"))) +#define WTF_IMPORT WTF_EXPORT +#else +#define WTF_EXPORT +#define WTF_IMPORT +#endif + +#endif /* ExportMacros_h */ diff --git a/Source/JavaScriptCore/wtf/HexNumber.h b/Source/JavaScriptCore/wtf/HexNumber.h new file mode 100644 index 0000000..8fd6032 --- /dev/null +++ b/Source/JavaScriptCore/wtf/HexNumber.h @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2011 Research In Motion Limited. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef HexNumber_h +#define HexNumber_h + +#include <wtf/text/StringConcatenate.h> + +namespace WTF { + +enum HexConversionMode { + Lowercase, + Uppercase +}; + +namespace Internal { + +static const char* hexDigitsForMode(HexConversionMode mode) +{ + static const char lowerHexDigits[17] = "0123456789abcdef"; + static const char upperHexDigits[17] = "0123456789ABCDEF"; + return mode == Lowercase ? lowerHexDigits : upperHexDigits; +} + +}; // namespace Internal + +template<typename T> +inline void appendByteAsHex(unsigned char byte, T& destination, HexConversionMode mode = Uppercase) +{ + const char* hexDigits = Internal::hexDigitsForMode(mode); + destination.append(hexDigits[byte >> 4]); + destination.append(hexDigits[byte & 0xF]); +} + +template<typename T> +inline void placeByteAsHexCompressIfPossible(unsigned char byte, T& destination, unsigned& index, HexConversionMode mode = Uppercase) +{ + const char* hexDigits = Internal::hexDigitsForMode(mode); + if (byte >= 0x10) + destination[index++] = hexDigits[byte >> 4]; + destination[index++] = hexDigits[byte & 0xF]; +} + +template<typename T> +inline void placeByteAsHex(unsigned char byte, T& destination, HexConversionMode mode = Uppercase) +{ + const char* hexDigits = Internal::hexDigitsForMode(mode); + *destination++ = hexDigits[byte >> 4]; + *destination++ = hexDigits[byte & 0xF]; +} + +template<typename T> +inline void appendUnsignedAsHex(unsigned number, T& destination, HexConversionMode mode = Uppercase) +{ + const char* hexDigits = Internal::hexDigitsForMode(mode); + Vector<UChar, 8> result; + do { + result.prepend(hexDigits[number % 16]); + number >>= 4; + } while (number > 0); + + destination.append(result.data(), result.size()); +} + +// Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the conversion. +template<typename T> +inline void appendUnsignedAsHexFixedSize(unsigned number, T& destination, unsigned desiredDigits, HexConversionMode mode = Uppercase) +{ + ASSERT(desiredDigits); + + const char* hexDigits = Internal::hexDigitsForMode(mode); + Vector<UChar, 8> result; + do { + result.prepend(hexDigits[number % 16]); + number >>= 4; + } while (result.size() < desiredDigits); + + ASSERT(result.size() == desiredDigits); + destination.append(result.data(), result.size()); +} + +} // namespace WTF + +using WTF::appendByteAsHex; +using WTF::appendUnsignedAsHex; +using WTF::appendUnsignedAsHexFixedSize; +using WTF::placeByteAsHex; +using WTF::placeByteAsHexCompressIfPossible; +using WTF::Lowercase; + +#endif // HexNumber_h diff --git a/Source/JavaScriptCore/wtf/MathExtras.h b/Source/JavaScriptCore/wtf/MathExtras.h index ec27f5f..66e557f 100644 --- a/Source/JavaScriptCore/wtf/MathExtras.h +++ b/Source/JavaScriptCore/wtf/MathExtras.h @@ -90,7 +90,7 @@ inline bool isfinite(double x) { return finite(x) && !isnand(x); } inline bool isinf(double x) { return !finite(x) && !isnand(x); } #endif #ifndef signbit -inline bool signbit(double x) { return x < 0.0; } // FIXME: Wrong for negative 0. +inline bool signbit(double x) { return copysign(1.0, x) < 0; } #endif #endif @@ -106,7 +106,7 @@ inline bool signbit(double x) { struct ieee_double *p = (struct ieee_double *)&x #endif -#if COMPILER(MSVC) || COMPILER(RVCT) +#if COMPILER(MSVC) || (COMPILER(RVCT) && !(RVCT_VERSION_AT_LEAST(3, 0, 0, 0))) // We must not do 'num + 0.5' or 'num - 0.5' because they can cause precision loss. static double round(double num) @@ -233,7 +233,12 @@ inline int clampToPositiveInteger(float d) return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0)); } -#if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP))) +inline int clampToInteger(unsigned value) +{ + return static_cast<int>(std::min(value, static_cast<unsigned>(std::numeric_limits<int>::max()))); +} + +#if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP))) && !OS(SOLARIS) using std::isfinite; using std::isinf; using std::isnan; diff --git a/Source/JavaScriptCore/wtf/MessageQueue.h b/Source/JavaScriptCore/wtf/MessageQueue.h index 7c18a0c..2b774fb 100644 --- a/Source/JavaScriptCore/wtf/MessageQueue.h +++ b/Source/JavaScriptCore/wtf/MessageQueue.h @@ -41,7 +41,7 @@ namespace WTF { enum MessageQueueWaitResult { MessageQueueTerminated, // Queue was destroyed while waiting for message. MessageQueueTimeout, // Timeout was specified and it expired. - MessageQueueMessageReceived, // A message was successfully received and returned. + MessageQueueMessageReceived // A message was successfully received and returned. }; // The queue takes ownership of messages and transfer it to the new owner diff --git a/Source/JavaScriptCore/wtf/Platform.h b/Source/JavaScriptCore/wtf/Platform.h index f4fdbcb..aee03e6 100644 --- a/Source/JavaScriptCore/wtf/Platform.h +++ b/Source/JavaScriptCore/wtf/Platform.h @@ -114,6 +114,11 @@ #define WTF_COMPILER_INTEL 1 #endif +/* COMPILER(SUNCC) */ +#if defined(__SUNPRO_CC) || defined(__SUNPRO_C) +#define WTF_COMPILER_SUNCC 1 +#endif + /* ==== CPU() - the target CPU architecture ==== */ /* This also defines CPU(BIG_ENDIAN) or CPU(MIDDLE_ENDIAN) or neither, as appropriate. */ @@ -565,7 +570,11 @@ #define WTF_USE_MERSENNE_TWISTER_19937 1 #endif -#if (PLATFORM(GTK) || PLATFORM(IOS) || PLATFORM(MAC) || PLATFORM(WIN) || (PLATFORM(QT) && OS(DARWIN) && !ENABLE(SINGLE_THREADED))) && !defined(ENABLE_JSC_MULTIPLE_THREADS) +#if PLATFORM(QT) && OS(UNIX) && !OS(SYMBIAN) && !OS(DARWIN) +#define WTF_USE_PTHREAD_BASED_QT 1 +#endif + +#if (PLATFORM(GTK) || PLATFORM(IOS) || PLATFORM(MAC) || PLATFORM(WIN) || (PLATFORM(QT) && (OS(DARWIN) || USE(PTHREAD_BASED_QT)) && !ENABLE(SINGLE_THREADED))) && !defined(ENABLE_JSC_MULTIPLE_THREADS) #define ENABLE_JSC_MULTIPLE_THREADS 1 #endif @@ -598,10 +607,6 @@ #define WTF_USE_ICU_UNICODE 1 #endif -#if !PLATFORM(CHROMIUM) /* Chromium controls this macro with a gyp define */ -#define WTF_USE_BUILTIN_UTF8_CODEC 1 -#endif - #if PLATFORM(MAC) && !PLATFORM(IOS) #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_TIGER) && CPU(X86_64) #define WTF_USE_PLUGIN_HOST_PROCESS 1 @@ -963,6 +968,10 @@ #define ENABLE_GEOLOCATION 0 #endif +#if !defined(ENABLE_GESTURE_RECOGNIZER) +#define ENABLE_GESTURE_RECOGNIZER 0 +#endif + #if !defined(ENABLE_NOTIFICATIONS) #define ENABLE_NOTIFICATIONS 0 #endif @@ -1022,6 +1031,13 @@ #define ENABLE_JIT 1 #endif +/* Currently only implemented for JSVALUE64, only tested on PLATFORM(MAC) */ +#if ENABLE(JIT) && USE(JSVALUE64) && PLATFORM(MAC) +#define ENABLE_DFG_JIT 1 +/* Enabled with restrictions to circumvent known performance regressions. */ +#define ENABLE_DFG_JIT_RESTRICTIONS 1 +#endif + /* Ensure that either the JIT or the interpreter has been enabled. */ #if !defined(ENABLE_INTERPRETER) && !ENABLE(JIT) #define ENABLE_INTERPRETER 1 @@ -1145,6 +1161,10 @@ #define WTF_USE_PROTECTION_SPACE_AUTH_CALLBACK 1 #endif +#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) +#define WTF_USE_AVFOUNDATION 1 +#endif + #if COMPILER(GCC) #define WARN_UNUSED_RETURN __attribute__ ((warn_unused_result)) #else @@ -1184,4 +1204,10 @@ #include "GTypedefs.h" #endif +/* FIXME: This define won't be needed once #27551 is fully landed. However, + since most ports try to support sub-project independence, adding new headers + to WTF causes many ports to break, and so this way we can address the build + breakages one port at a time. */ +#define WTF_USE_EXPORT_MACROS 0 + #endif /* WTF_Platform_h */ diff --git a/Source/JavaScriptCore/wtf/RefCounted.h b/Source/JavaScriptCore/wtf/RefCounted.h index da178b2..12b670e 100644 --- a/Source/JavaScriptCore/wtf/RefCounted.h +++ b/Source/JavaScriptCore/wtf/RefCounted.h @@ -59,6 +59,12 @@ public: #endif } + // Helper for generating JIT code. Please do not use for non-JIT purposes. + const int* addressOfCount() const + { + return &m_refCount; + } + protected: RefCountedBase() : m_refCount(1) @@ -93,12 +99,6 @@ protected: return false; } - // Helper for generating JIT code. Please do not use for non-JIT purposes. - int* addressOfCount() - { - return &m_refCount; - } - #ifndef NDEBUG bool deletionHasBegun() const { diff --git a/Source/JavaScriptCore/wtf/StdLibExtras.h b/Source/JavaScriptCore/wtf/StdLibExtras.h index 4bb0076..0dacb91 100644 --- a/Source/JavaScriptCore/wtf/StdLibExtras.h +++ b/Source/JavaScriptCore/wtf/StdLibExtras.h @@ -114,6 +114,53 @@ inline size_t bitCount(unsigned bits) template<typename T, size_t Size> char (&ArrayLengthHelperFunction(T (&)[Size]))[Size]; #define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array)) +// Efficient implementation that takes advantage of powers of two. +template<size_t divisor> inline size_t roundUpToMultipleOf(size_t x) +{ + COMPILE_ASSERT(divisor && !(divisor & (divisor - 1)), divisor_is_a_power_of_two); + + size_t remainderMask = divisor - 1; + return (x + remainderMask) & ~remainderMask; +} + +// Binary search algorithm, calls extractKey on pre-sorted elements in array, +// compares result with key (KeyTypes should be comparable with '--', '<', '>'). +// Optimized for cases where the array contains the key, checked by assertions. +template<typename ArrayType, typename KeyType, KeyType(*extractKey)(ArrayType*)> +inline ArrayType* binarySearch(ArrayType* array, size_t size, KeyType key) +{ + // The array must contain at least one element (pre-condition, array does conatin key). + // If the array only contains one element, no need to do the comparison. + while (size > 1) { + // Pick an element to check, half way through the array, and read the value. + int pos = (size - 1) >> 1; + KeyType val = extractKey(&array[pos]); + + // If the key matches, success! + if (val == key) + return &array[pos]; + // The item we are looking for is smaller than the item being check; reduce the value of 'size', + // chopping off the right hand half of the array. + else if (key < val) + size = pos; + // Discard all values in the left hand half of the array, up to and including the item at pos. + else { + size -= (pos + 1); + array += (pos + 1); + } + + // 'size' should never reach zero. + ASSERT(size); + } + + // If we reach this point we've chopped down to one element, no need to check it matches + ASSERT(size == 1); + ASSERT(key == extractKey(&array[0])); + return &array[0]; +} + } // namespace WTF +using WTF::binarySearch; + #endif // WTF_StdLibExtras_h diff --git a/Source/JavaScriptCore/wtf/StringHasher.h b/Source/JavaScriptCore/wtf/StringHasher.h index a84b2c4..5a2c36c 100644 --- a/Source/JavaScriptCore/wtf/StringHasher.h +++ b/Source/JavaScriptCore/wtf/StringHasher.h @@ -88,7 +88,7 @@ public: return result; } - template<typename T, UChar Converter(T)> static inline unsigned createHash(const T* data, unsigned length) + template<typename T, UChar Converter(T)> static inline unsigned computeHash(const T* data, unsigned length) { StringHasher hasher; bool rem = length & 1; @@ -105,7 +105,7 @@ public: return hasher.hash(); } - template<typename T, UChar Converter(T)> static inline unsigned createHash(const T* data) + template<typename T, UChar Converter(T)> static inline unsigned computeHash(const T* data) { StringHasher hasher; @@ -125,26 +125,26 @@ public: return hasher.hash(); } - template<typename T> static inline unsigned createHash(const T* data, unsigned length) + template<typename T> static inline unsigned computeHash(const T* data, unsigned length) { - return createHash<T, defaultCoverter>(data, length); + return computeHash<T, defaultCoverter>(data, length); } - template<typename T> static inline unsigned createHash(const T* data) + template<typename T> static inline unsigned computeHash(const T* data) { - return createHash<T, defaultCoverter>(data); + return computeHash<T, defaultCoverter>(data); } - template<size_t length> static inline unsigned createBlobHash(const void* data) + template<size_t length> static inline unsigned hashMemory(const void* data) { COMPILE_ASSERT(!(length % 4), length_must_be_a_multible_of_four); - return createHash<UChar>(static_cast<const UChar*>(data), length / sizeof(UChar)); + return computeHash<UChar>(static_cast<const UChar*>(data), length / sizeof(UChar)); } - static inline unsigned createBlobHash(const void* data, unsigned size) + static inline unsigned hashMemory(const void* data, unsigned size) { ASSERT(!(size % 2)); - return createHash<UChar>(static_cast<const UChar*>(data), size / sizeof(UChar)); + return computeHash<UChar>(static_cast<const UChar*>(data), size / sizeof(UChar)); } private: @@ -173,4 +173,6 @@ private: } // namespace WTF +using WTF::StringHasher; + #endif // WTF_StringHasher_h diff --git a/Source/JavaScriptCore/wtf/ThreadSafeShared.h b/Source/JavaScriptCore/wtf/ThreadSafeRefCounted.h index a6a1cf2..c9beec4 100644 --- a/Source/JavaScriptCore/wtf/ThreadSafeShared.h +++ b/Source/JavaScriptCore/wtf/ThreadSafeRefCounted.h @@ -56,8 +56,8 @@ * DEALINGS IN THE SOFTWARE. */ -#ifndef ThreadSafeShared_h -#define ThreadSafeShared_h +#ifndef ThreadSafeRefCounted_h +#define ThreadSafeRefCounted_h #include "Platform.h" @@ -66,17 +66,18 @@ namespace WTF { -class ThreadSafeSharedBase { - WTF_MAKE_NONCOPYABLE(ThreadSafeSharedBase); WTF_MAKE_FAST_ALLOCATED; +class ThreadSafeRefCountedBase { + WTF_MAKE_NONCOPYABLE(ThreadSafeRefCountedBase); + WTF_MAKE_FAST_ALLOCATED; public: - ThreadSafeSharedBase(int initialRefCount = 1) + ThreadSafeRefCountedBase(int initialRefCount = 1) : m_refCount(initialRefCount) { } void ref() { -#if USE(LOCKFREE_THREADSAFESHARED) +#if USE(LOCKFREE_THREADSAFEREFCOUNTED) atomicIncrement(&m_refCount); #else MutexLocker locker(m_mutex); @@ -91,7 +92,7 @@ public: int refCount() const { -#if !USE(LOCKFREE_THREADSAFESHARED) +#if !USE(LOCKFREE_THREADSAFEREFCOUNTED) MutexLocker locker(m_mutex); #endif return static_cast<int const volatile &>(m_refCount); @@ -101,7 +102,7 @@ protected: // Returns whether the pointer should be freed or not. bool derefBase() { -#if USE(LOCKFREE_THREADSAFESHARED) +#if USE(LOCKFREE_THREADSAFEREFCOUNTED) if (atomicDecrement(&m_refCount) <= 0) return true; #else @@ -122,12 +123,12 @@ private: friend class CrossThreadRefCounted; int m_refCount; -#if !USE(LOCKFREE_THREADSAFESHARED) +#if !USE(LOCKFREE_THREADSAFEREFCOUNTED) mutable Mutex m_mutex; #endif }; -template<class T> class ThreadSafeShared : public ThreadSafeSharedBase { +template<class T> class ThreadSafeRefCounted : public ThreadSafeRefCountedBase { public: void deref() { @@ -136,13 +137,13 @@ public: } protected: - ThreadSafeShared() + ThreadSafeRefCounted() { } }; } // namespace WTF -using WTF::ThreadSafeShared; +using WTF::ThreadSafeRefCounted; -#endif // ThreadSafeShared_h +#endif // ThreadSafeRefCounted_h diff --git a/Source/JavaScriptCore/wtf/Threading.h b/Source/JavaScriptCore/wtf/Threading.h index 044365f..b6f8c24 100644 --- a/Source/JavaScriptCore/wtf/Threading.h +++ b/Source/JavaScriptCore/wtf/Threading.h @@ -67,7 +67,7 @@ #include <wtf/Locker.h> #include <wtf/MainThread.h> #include <wtf/Noncopyable.h> -#include <wtf/ThreadSafeShared.h> +#include <wtf/ThreadSafeRefCounted.h> #include <wtf/ThreadingPrimitives.h> // For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc). diff --git a/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp b/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp index aa63f33..0ffcfe2 100644 --- a/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp +++ b/Source/JavaScriptCore/wtf/ThreadingPthreads.cpp @@ -55,6 +55,10 @@ #include <wtf/PassOwnPtr.h> #endif +#if OS(MAC_OS_X) && !defined(BUILDING_ON_LEOPARD) +#include <objc/objc-auto.h> +#endif + namespace WTF { typedef HashMap<ThreadIdentifier, pthread_t> ThreadMap; @@ -190,6 +194,12 @@ void initializeCurrentThreadInternal(const char* threadName) UNUSED_PARAM(threadName); #endif +#if OS(MAC_OS_X) && !defined(BUILDING_ON_LEOPARD) + // All threads that potentially use APIs above the BSD layer must be registered with the Objective-C + // garbage collector in case API implementations use garbage-collected memory. + objc_registerThreadWithCollector(); +#endif + ThreadIdentifier id = identifierByPthreadHandle(pthread_self()); ASSERT(id); ThreadIdentifierData::initialize(id); diff --git a/Source/JavaScriptCore/wtf/Vector.h b/Source/JavaScriptCore/wtf/Vector.h index 2fb4114..b26857c 100644 --- a/Source/JavaScriptCore/wtf/Vector.h +++ b/Source/JavaScriptCore/wtf/Vector.h @@ -40,7 +40,7 @@ namespace WTF { using std::max; // WTF_ALIGN_OF / WTF_ALIGNED - #if COMPILER(GCC) || COMPILER(MINGW) || COMPILER(RVCT) || COMPILER(WINSCW) + #if COMPILER(GCC) || COMPILER(MINGW) || COMPILER(RVCT) || COMPILER(WINSCW) || COMPILER(SUNCC) #define WTF_ALIGN_OF(type) __alignof__(type) #define WTF_ALIGNED(variable_type, variable, n) variable_type variable __attribute__((__aligned__(n))) #elif COMPILER(MSVC) @@ -566,6 +566,7 @@ namespace WTF { T& last() { return at(size() - 1); } const T& last() const { return at(size() - 1); } + template<typename U> bool contains(const U&) const; template<typename U> size_t find(const U&) const; template<typename U> size_t reverseFind(const U&) const; @@ -745,6 +746,13 @@ namespace WTF { template<typename T, size_t inlineCapacity> template<typename U> + bool Vector<T, inlineCapacity>::contains(const U& value) const + { + return find(value) != notFound; + } + + template<typename T, size_t inlineCapacity> + template<typename U> size_t Vector<T, inlineCapacity>::find(const U& value) const { for (size_t i = 0; i < size(); ++i) { diff --git a/Source/JavaScriptCore/wtf/text/AtomicString.cpp b/Source/JavaScriptCore/wtf/text/AtomicString.cpp index e0a866d..eb0dbbb 100644 --- a/Source/JavaScriptCore/wtf/text/AtomicString.cpp +++ b/Source/JavaScriptCore/wtf/text/AtomicString.cpp @@ -87,7 +87,7 @@ static inline PassRefPtr<StringImpl> addToStringTable(const T& value) struct CStringTranslator { static unsigned hash(const char* c) { - return StringImpl::computeHash(c); + return StringHasher::computeHash(c); } static bool equal(StringImpl* r, const char* s) @@ -142,7 +142,7 @@ static inline bool equal(StringImpl* string, const UChar* characters, unsigned l // FIXME: perhaps we should have a more abstract macro that indicates when // going 4 bytes at a time is unsafe -#if CPU(ARM) || CPU(SH4) || CPU(MIPS) +#if CPU(ARM) || CPU(SH4) || CPU(MIPS) || CPU(SPARC) const UChar* stringCharacters = string->characters(); for (unsigned i = 0; i != length; ++i) { if (*stringCharacters++ != *characters++) @@ -176,7 +176,7 @@ bool operator==(const AtomicString& string, const Vector<UChar>& vector) struct UCharBufferTranslator { static unsigned hash(const UCharBuffer& buf) { - return StringImpl::computeHash(buf.s, buf.length); + return StringHasher::computeHash(buf.s, buf.length); } static bool equal(StringImpl* const& str, const UCharBuffer& buf) @@ -201,7 +201,7 @@ struct HashAndCharacters { struct HashAndCharactersTranslator { static unsigned hash(const HashAndCharacters& buffer) { - ASSERT(buffer.hash == StringImpl::computeHash(buffer.characters, buffer.length)); + ASSERT(buffer.hash == StringHasher::computeHash(buffer.characters, buffer.length)); return buffer.hash; } diff --git a/Source/JavaScriptCore/wtf/text/StringConcatenate.h b/Source/JavaScriptCore/wtf/text/StringConcatenate.h index 92a2d06..7fa7d2c 100644 --- a/Source/JavaScriptCore/wtf/text/StringConcatenate.h +++ b/Source/JavaScriptCore/wtf/text/StringConcatenate.h @@ -89,6 +89,34 @@ private: }; template<> +class StringTypeAdapter<const UChar*> { +public: + StringTypeAdapter<const UChar*>(const UChar* buffer) + : m_buffer(buffer) + { + size_t len = 0; + while (m_buffer[len] != UChar(0)) + len++; + + if (len > std::numeric_limits<unsigned>::max()) + CRASH(); + + m_length = len; + } + + unsigned length() { return m_length; } + + void writeTo(UChar* destination) + { + memcpy(destination, m_buffer, static_cast<size_t>(m_length) * sizeof(UChar)); + } + +private: + const UChar* m_buffer; + unsigned m_length; +}; + +template<> class StringTypeAdapter<const char*> { public: StringTypeAdapter<const char*>(const char* buffer) diff --git a/Source/JavaScriptCore/wtf/text/StringHash.h b/Source/JavaScriptCore/wtf/text/StringHash.h index d7aabdb..80193a6 100644 --- a/Source/JavaScriptCore/wtf/text/StringHash.h +++ b/Source/JavaScriptCore/wtf/text/StringHash.h @@ -104,7 +104,7 @@ namespace WTF { static unsigned hash(const UChar* data, unsigned length) { - return StringHasher::createHash<UChar, foldCase<UChar> >(data, length); + return StringHasher::computeHash<UChar, foldCase<UChar> >(data, length); } static unsigned hash(StringImpl* str) @@ -114,7 +114,7 @@ namespace WTF { static unsigned hash(const char* data, unsigned length) { - return StringHasher::createHash<char, foldCase<char> >(data, length); + return StringHasher::computeHash<char, foldCase<char> >(data, length); } static bool equal(const StringImpl* a, const StringImpl* b) diff --git a/Source/JavaScriptCore/wtf/text/StringImpl.h b/Source/JavaScriptCore/wtf/text/StringImpl.h index a08427b..81911b3 100644 --- a/Source/JavaScriptCore/wtf/text/StringImpl.h +++ b/Source/JavaScriptCore/wtf/text/StringImpl.h @@ -136,7 +136,7 @@ private: { ASSERT(!isStatic()); ASSERT(!m_hash); - ASSERT(hash == computeHash(m_data, m_length)); + ASSERT(hash == StringHasher::computeHash(m_data, m_length)); m_hash = hash; } @@ -235,11 +235,8 @@ public: m_refCountAndFlags &= ~s_refCountFlagIsAtomic; } - unsigned hash() const { if (!m_hash) m_hash = computeHash(m_data, m_length); return m_hash; } + unsigned hash() const { if (!m_hash) m_hash = StringHasher::computeHash(m_data, m_length); return m_hash; } unsigned existingHash() const { ASSERT(m_hash); return m_hash; } - static unsigned computeHash(const UChar* data, unsigned length) { return WTF::StringHasher::createHash<UChar>(data, length); } - static unsigned computeHash(const char* data, unsigned length) { return WTF::StringHasher::createHash<char>(data, length); } - static unsigned computeHash(const char* data) { return WTF::StringHasher::createHash<char>(data); } ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & (s_refCountMask | s_refCountFlagStatic))) delete this; } ALWAYS_INLINE bool hasOneRef() const { return (m_refCountAndFlags & (s_refCountMask | s_refCountFlagStatic)) == s_refCountIncrement; } diff --git a/Source/JavaScriptCore/wtf/unicode/UTF8.cpp b/Source/JavaScriptCore/wtf/unicode/UTF8.cpp index 4c3738b..6981fe4 100644 --- a/Source/JavaScriptCore/wtf/unicode/UTF8.cpp +++ b/Source/JavaScriptCore/wtf/unicode/UTF8.cpp @@ -319,7 +319,7 @@ static inline unsigned calculateStringHashAndLengthFromUTF8Internal(const char* if (!data) return 0; - WTF::StringHasher stringHasher; + StringHasher stringHasher; dataLength = 0; utf16Length = 0; |