diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-11-08 15:39:11 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-11-08 15:46:25 +0100 |
commit | 6ca81ad72a3c6fdf16c683335be748f22aaa9a0d (patch) | |
tree | 33c8ee75f729aed76c2c0b89c63f9bf1b4dd66aa /deps/v8/src/utils | |
parent | 1eee0b8bf8bba39b600fb16a9223e545e3bac2bc (diff) | |
download | android-node-v8-6ca81ad72a3c6fdf16c683335be748f22aaa9a0d.tar.gz android-node-v8-6ca81ad72a3c6fdf16c683335be748f22aaa9a0d.tar.bz2 android-node-v8-6ca81ad72a3c6fdf16c683335be748f22aaa9a0d.zip |
deps: update V8 to 7.9.317.20
PR-URL: https://github.com/nodejs/node/pull/30020
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'deps/v8/src/utils')
-rw-r--r-- | deps/v8/src/utils/allocation.cc | 4 | ||||
-rw-r--r-- | deps/v8/src/utils/memcopy.cc | 13 | ||||
-rw-r--r-- | deps/v8/src/utils/memcopy.h | 331 | ||||
-rw-r--r-- | deps/v8/src/utils/utils-inl.h | 36 | ||||
-rw-r--r-- | deps/v8/src/utils/utils.h | 13 | ||||
-rw-r--r-- | deps/v8/src/utils/vector.h | 1 |
6 files changed, 65 insertions, 333 deletions
diff --git a/deps/v8/src/utils/allocation.cc b/deps/v8/src/utils/allocation.cc index f44b3c42ea..c89f83ba85 100644 --- a/deps/v8/src/utils/allocation.cc +++ b/deps/v8/src/utils/allocation.cc @@ -10,6 +10,7 @@ #include "src/base/logging.h" #include "src/base/page-allocator.h" #include "src/base/platform/platform.h" +#include "src/flags/flags.h" #include "src/init/v8.h" #include "src/sanitizer/lsan-page-allocator.h" #include "src/utils/memcopy.h" @@ -166,6 +167,9 @@ void* AllocatePages(v8::PageAllocator* page_allocator, void* hint, size_t size, DCHECK_NOT_NULL(page_allocator); DCHECK_EQ(hint, AlignedAddress(hint, alignment)); DCHECK(IsAligned(size, page_allocator->AllocatePageSize())); + if (FLAG_randomize_all_allocations) { + hint = page_allocator->GetRandomMmapAddr(); + } void* result = nullptr; for (int i = 0; i < kAllocationTries; ++i) { result = page_allocator->AllocatePages(hint, size, alignment, access); diff --git a/deps/v8/src/utils/memcopy.cc b/deps/v8/src/utils/memcopy.cc index 1cac2189d0..c67d1d359a 100644 --- a/deps/v8/src/utils/memcopy.cc +++ b/deps/v8/src/utils/memcopy.cc @@ -25,18 +25,8 @@ V8_EXPORT_PRIVATE void MemMove(void* dest, const void* src, size_t size) { (*memmove_function)(dest, src, size); } #elif V8_OS_POSIX && V8_HOST_ARCH_ARM -void MemCopyUint16Uint8Wrapper(uint16_t* dest, const uint8_t* src, - size_t chars) { - uint16_t* limit = dest + chars; - while (dest < limit) { - *dest++ = static_cast<uint16_t>(*src++); - } -} - V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function = &MemCopyUint8Wrapper; -MemCopyUint16Uint8Function memcopy_uint16_uint8_function = - &MemCopyUint16Uint8Wrapper; #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function = &MemCopyUint8Wrapper; @@ -54,9 +44,6 @@ void init_memcopy_functions() { EmbeddedData d = EmbeddedData::FromBlob(); memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>( d.InstructionStartOfBuiltin(Builtins::kMemCopyUint8Uint8)); - memcopy_uint16_uint8_function = - reinterpret_cast<MemCopyUint16Uint8Function>( - d.InstructionStartOfBuiltin(Builtins::kMemCopyUint16Uint8)); } #elif V8_OS_POSIX && V8_HOST_ARCH_MIPS if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) { diff --git a/deps/v8/src/utils/memcopy.h b/deps/v8/src/utils/memcopy.h index c1a0afbcb4..7e1b8539df 100644 --- a/deps/v8/src/utils/memcopy.h +++ b/deps/v8/src/utils/memcopy.h @@ -8,6 +8,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <algorithm> #include "src/base/logging.h" #include "src/base/macros.h" @@ -55,17 +56,8 @@ V8_EXPORT_PRIVATE V8_INLINE void MemMove(void* dest, const void* src, memmove(dest, src, size); } -using MemCopyUint16Uint8Function = void (*)(uint16_t* dest, const uint8_t* src, - size_t size); -extern MemCopyUint16Uint8Function memcopy_uint16_uint8_function; -void MemCopyUint16Uint8Wrapper(uint16_t* dest, const uint8_t* src, - size_t chars); // For values < 12, the assembler function is slower than the inlined C code. const int kMinComplexConvertMemCopy = 12; -V8_INLINE void MemCopyUint16Uint8(uint16_t* dest, const uint8_t* src, - size_t size) { - (*memcopy_uint16_uint8_function)(dest, src, size); -} #elif defined(V8_HOST_ARCH_MIPS) using MemCopyUint8Function = void (*)(uint8_t* dest, const uint8_t* src, size_t size); @@ -109,6 +101,7 @@ inline void CopyImpl(T* dst_ptr, const T* src_ptr, size_t count) { DCHECK(((src <= dst) && ((src + count * kTWordSize) <= dst)) || ((dst <= src) && ((dst + count * kTWordSize) <= src))); #endif + if (count == 0) return; // Use block copying MemCopy if the segment we're copying is // enough to justify the extra call/setup overhead. @@ -204,308 +197,32 @@ inline void MemsetPointer(T** dest, U* value, size_t counter) { reinterpret_cast<Address>(value), counter); } -template <typename sourcechar, typename sinkchar> -V8_INLINE static void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, - size_t chars); -#if defined(V8_HOST_ARCH_ARM) -V8_INLINE void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, - size_t chars); -V8_INLINE void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, - size_t chars); -V8_INLINE void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, - size_t chars); -#elif defined(V8_HOST_ARCH_MIPS) -V8_INLINE void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, - size_t chars); -V8_INLINE void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, - size_t chars); -#elif defined(V8_HOST_ARCH_PPC) || defined(V8_HOST_ARCH_S390) -V8_INLINE void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, - size_t chars); -V8_INLINE void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, - size_t chars); -#endif - -// Copy from 8bit/16bit chars to 8bit/16bit chars. -template <typename sourcechar, typename sinkchar> -V8_INLINE void CopyChars(sinkchar* dest, const sourcechar* src, size_t chars); - -template <typename sourcechar, typename sinkchar> -void CopyChars(sinkchar* dest, const sourcechar* src, size_t chars) { - DCHECK_LE(sizeof(sourcechar), 2); - DCHECK_LE(sizeof(sinkchar), 2); - if (sizeof(sinkchar) == 1) { - if (sizeof(sourcechar) == 1) { - CopyCharsUnsigned(reinterpret_cast<uint8_t*>(dest), - reinterpret_cast<const uint8_t*>(src), chars); - } else { - CopyCharsUnsigned(reinterpret_cast<uint8_t*>(dest), - reinterpret_cast<const uint16_t*>(src), chars); - } - } else { - if (sizeof(sourcechar) == 1) { - CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), - reinterpret_cast<const uint8_t*>(src), chars); - } else { - CopyCharsUnsigned(reinterpret_cast<uint16_t*>(dest), - reinterpret_cast<const uint16_t*>(src), chars); - } - } -} - -template <typename sourcechar, typename sinkchar> -void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, size_t chars) { - sinkchar* limit = dest + chars; - if ((sizeof(*dest) == sizeof(*src)) && - (chars >= kMinComplexMemCopy / sizeof(*dest))) { - MemCopy(dest, src, chars * sizeof(*dest)); - } else { - while (dest < limit) *dest++ = static_cast<sinkchar>(*src++); - } -} +// Copy from 8bit/16bit chars to 8bit/16bit chars. Values are zero-extended if +// needed. Ranges are not allowed to overlap. +// The separate declaration is needed for the V8_NONNULL, which is not allowed +// on a definition. +template <typename SrcType, typename DstType> +void CopyChars(DstType* dst, const SrcType* src, size_t count) V8_NONNULL(1, 2); -#if defined(V8_HOST_ARCH_ARM) -void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, size_t chars) { - switch (static_cast<unsigned>(chars)) { - case 0: - break; - case 1: - *dest = *src; - break; - case 2: - memcpy(dest, src, 2); - break; - case 3: - memcpy(dest, src, 3); - break; - case 4: - memcpy(dest, src, 4); - break; - case 5: - memcpy(dest, src, 5); - break; - case 6: - memcpy(dest, src, 6); - break; - case 7: - memcpy(dest, src, 7); - break; - case 8: - memcpy(dest, src, 8); - break; - case 9: - memcpy(dest, src, 9); - break; - case 10: - memcpy(dest, src, 10); - break; - case 11: - memcpy(dest, src, 11); - break; - case 12: - memcpy(dest, src, 12); - break; - case 13: - memcpy(dest, src, 13); - break; - case 14: - memcpy(dest, src, 14); - break; - case 15: - memcpy(dest, src, 15); - break; - default: - MemCopy(dest, src, chars); - break; - } -} - -void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, size_t chars) { - if (chars >= static_cast<size_t>(kMinComplexConvertMemCopy)) { - MemCopyUint16Uint8(dest, src, chars); - } else { - MemCopyUint16Uint8Wrapper(dest, src, chars); - } -} +template <typename SrcType, typename DstType> +void CopyChars(DstType* dst, const SrcType* src, size_t count) { + STATIC_ASSERT(std::is_integral<SrcType>::value); + STATIC_ASSERT(std::is_integral<DstType>::value); -void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, size_t chars) { - switch (static_cast<unsigned>(chars)) { - case 0: - break; - case 1: - *dest = *src; - break; - case 2: - memcpy(dest, src, 4); - break; - case 3: - memcpy(dest, src, 6); - break; - case 4: - memcpy(dest, src, 8); - break; - case 5: - memcpy(dest, src, 10); - break; - case 6: - memcpy(dest, src, 12); - break; - case 7: - memcpy(dest, src, 14); - break; - default: - MemCopy(dest, src, chars * sizeof(*dest)); - break; - } -} - -#elif defined(V8_HOST_ARCH_MIPS) -void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, size_t chars) { - if (chars < kMinComplexMemCopy) { - memcpy(dest, src, chars); - } else { - MemCopy(dest, src, chars); - } -} - -void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, size_t chars) { - if (chars < kMinComplexMemCopy) { - memcpy(dest, src, chars * sizeof(*dest)); - } else { - MemCopy(dest, src, chars * sizeof(*dest)); - } -} -#elif defined(V8_HOST_ARCH_PPC) || defined(V8_HOST_ARCH_S390) -#define CASE(n) \ - case n: \ - memcpy(dest, src, n); \ - break -void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, size_t chars) { - switch (static_cast<unsigned>(chars)) { - case 0: - break; - case 1: - *dest = *src; - break; - CASE(2); - CASE(3); - CASE(4); - CASE(5); - CASE(6); - CASE(7); - CASE(8); - CASE(9); - CASE(10); - CASE(11); - CASE(12); - CASE(13); - CASE(14); - CASE(15); - CASE(16); - CASE(17); - CASE(18); - CASE(19); - CASE(20); - CASE(21); - CASE(22); - CASE(23); - CASE(24); - CASE(25); - CASE(26); - CASE(27); - CASE(28); - CASE(29); - CASE(30); - CASE(31); - CASE(32); - CASE(33); - CASE(34); - CASE(35); - CASE(36); - CASE(37); - CASE(38); - CASE(39); - CASE(40); - CASE(41); - CASE(42); - CASE(43); - CASE(44); - CASE(45); - CASE(46); - CASE(47); - CASE(48); - CASE(49); - CASE(50); - CASE(51); - CASE(52); - CASE(53); - CASE(54); - CASE(55); - CASE(56); - CASE(57); - CASE(58); - CASE(59); - CASE(60); - CASE(61); - CASE(62); - CASE(63); - CASE(64); - default: - memcpy(dest, src, chars); - break; - } -} -#undef CASE +#ifdef DEBUG + // Check for no overlap, otherwise {std::copy_n} cannot be used. + Address src_start = reinterpret_cast<Address>(src); + Address src_end = src_start + count * sizeof(SrcType); + Address dst_start = reinterpret_cast<Address>(dst); + Address dst_end = dst_start + count * sizeof(DstType); + DCHECK(src_end <= dst_start || dst_end <= src_start); +#endif -#define CASE(n) \ - case n: \ - memcpy(dest, src, n * 2); \ - break -void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, size_t chars) { - switch (static_cast<unsigned>(chars)) { - case 0: - break; - case 1: - *dest = *src; - break; - CASE(2); - CASE(3); - CASE(4); - CASE(5); - CASE(6); - CASE(7); - CASE(8); - CASE(9); - CASE(10); - CASE(11); - CASE(12); - CASE(13); - CASE(14); - CASE(15); - CASE(16); - CASE(17); - CASE(18); - CASE(19); - CASE(20); - CASE(21); - CASE(22); - CASE(23); - CASE(24); - CASE(25); - CASE(26); - CASE(27); - CASE(28); - CASE(29); - CASE(30); - CASE(31); - CASE(32); - default: - memcpy(dest, src, chars * 2); - break; - } + using SrcTypeUnsigned = typename std::make_unsigned<SrcType>::type; + using DstTypeUnsigned = typename std::make_unsigned<DstType>::type; + std::copy_n(reinterpret_cast<const SrcTypeUnsigned*>(src), count, + reinterpret_cast<DstTypeUnsigned*>(dst)); } -#undef CASE -#endif } // namespace internal } // namespace v8 diff --git a/deps/v8/src/utils/utils-inl.h b/deps/v8/src/utils/utils-inl.h index e88055023e..0c8af7cb88 100644 --- a/deps/v8/src/utils/utils-inl.h +++ b/deps/v8/src/utils/utils-inl.h @@ -36,13 +36,30 @@ template <typename Char> bool TryAddIndexChar(uint32_t* index, Char c) { if (!IsDecimalDigit(c)) return false; int d = c - '0'; + // The maximum index is 4294967294; for the computation below to not + // exceed that, the previous index value must be <= 429496729 if d <= 4, + // or <= 429496728 if d >= 5. The (d+3)>>3 computation is a branch-free + // way to express that. if (*index > 429496729U - ((d + 3) >> 3)) return false; *index = (*index) * 10 + d; return true; } -template <typename Stream> -bool StringToArrayIndex(Stream* stream, uint32_t* index) { +template <typename Char> +bool TryAddIndexChar(uint64_t* index, Char c) { + if (!IsDecimalDigit(c)) return false; + int d = c - '0'; + // The maximum uint64_t is 18446744073709551615; for the computation below to + // not exceed that, the previous index value must be <= 1844674407370955161 + // if d <= 5, or <= 1844674407370955160 if d >= 6. The (d+2)>>3 computation + // is a branch-free way to express that. + if (*index > 1844674407370955161ull - ((d + 2) >> 3)) return false; + *index = (*index) * 10 + d; + return true; +} + +template <typename Stream, typename index_t> +bool StringToArrayIndex(Stream* stream, index_t* index) { uint16_t ch = stream->GetNext(); // If the string begins with a '0' character, it must only consist @@ -55,9 +72,20 @@ bool StringToArrayIndex(Stream* stream, uint32_t* index) { // Convert string to uint32 array index; character by character. if (!IsDecimalDigit(ch)) return false; int d = ch - '0'; - uint32_t result = d; + index_t result = d; while (stream->HasMore()) { - if (!TryAddIndexChar(&result, stream->GetNext())) return false; + // Clang on Mac doesn't think that size_t and uint*_t should be + // implicitly convertible. + if (sizeof(index_t) == 8) { + if (!TryAddIndexChar(reinterpret_cast<uint64_t*>(&result), + stream->GetNext())) { + return false; + } + } else { + if (!TryAddIndexChar(reinterpret_cast<uint32_t*>(&result), + stream->GetNext())) + return false; + } } *index = result; diff --git a/deps/v8/src/utils/utils.h b/deps/v8/src/utils/utils.h index 27d3d5ef21..b414a4c52b 100644 --- a/deps/v8/src/utils/utils.h +++ b/deps/v8/src/utils/utils.h @@ -760,13 +760,8 @@ inline uint64_t unsigned_bitextract_64(int msb, int lsb, uint64_t x) { return (x >> lsb) & ((static_cast<uint64_t>(1) << (1 + msb - lsb)) - 1); } -inline int32_t signed_bitextract_32(int msb, int lsb, int32_t x) { - return (x << (31 - msb)) >> (lsb + 31 - msb); -} - -inline int signed_bitextract_64(int msb, int lsb, int x) { - // TODO(jbramley): This is broken for big bitfields. - return (x << (63 - msb)) >> (lsb + 63 - msb); +inline int32_t signed_bitextract_32(int msb, int lsb, uint32_t x) { + return static_cast<int32_t>(x << (31 - msb)) >> (lsb + 31 - msb); } // Check number width. @@ -978,8 +973,8 @@ bool DoubleToBoolean(double d); template <typename Char> bool TryAddIndexChar(uint32_t* index, Char c); -template <typename Stream> -bool StringToArrayIndex(Stream* stream, uint32_t* index); +template <typename Stream, typename index_t> +bool StringToArrayIndex(Stream* stream, index_t* index); // Returns the current stack top. Works correctly with ASAN and SafeStack. // GetCurrentStackPosition() should not be inlined, because it works on stack diff --git a/deps/v8/src/utils/vector.h b/deps/v8/src/utils/vector.h index dd5c59e553..e0c13afc90 100644 --- a/deps/v8/src/utils/vector.h +++ b/deps/v8/src/utils/vector.h @@ -8,6 +8,7 @@ #include <algorithm> #include <cstring> #include <iterator> +#include <memory> #include "src/common/checks.h" #include "src/common/globals.h" |