Commit ea56bf55 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[ptr-compr] Bump max string length to ~2**29

Without pointer compression, the max string length on 64-bit platforms
used to be 2**30 (minus header). With pointer-compression, this was
accidentally lowered to 2**28 (which is the historical limit for 32-bit
platforms). This CL bumps the limit on 64-bit platforms to 2**29, which
is the maximum we can support given that any heap object's size in bytes
must fit into a Smi (which are now 31-bit on all 64-bit platforms, with
or without pointer compression).

Change-Id: I263544317d9e6137f6b6a044784a21f41a2761b0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2030916Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66083}
parent 4eac274d
......@@ -2983,9 +2983,8 @@ enum class NewStringType {
*/
class V8_EXPORT String : public Name {
public:
static constexpr int kMaxLength = internal::kApiTaggedSize == 4
? (1 << 28) - 16
: internal::kSmiMaxValue / 2 - 24;
static constexpr int kMaxLength =
internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
enum Encoding {
UNKNOWN_ENCODING = 0x1,
......
......@@ -363,16 +363,28 @@ class String : public TorqueGeneratedString<String, Name> {
static const uc32 kMaxCodePoint = 0x10ffff;
// Maximal string length.
// The max length is different on 32 and 64 bit platforms. Max length for a
// 32-bit platform is ~268.4M chars. On 64-bit platforms, max length is
// ~1.073B chars. The limit on 64-bit is so that SeqTwoByteString::kMaxSize
// can fit in a 32bit int: 2^31 - 1 is the max positive int, minus one bit as
// each char needs two bytes, subtract 24 bytes for the string header size.
// The max length is different on 32 and 64 bit platforms. Max length for
// 32-bit platforms is ~268.4M chars. On 64-bit platforms, max length is
// ~536.8M chars.
// See include/v8.h for the definition.
static const int kMaxLength = v8::String::kMaxLength;
static_assert(kMaxLength <= (Smi::kMaxValue / 2 - kHeaderSize),
"Unexpected max String length");
// There are several defining limits imposed by our current implementation:
// - any string's length must fit into a Smi.
static_assert(kMaxLength <= kSmiMaxValue,
"String length must fit into a Smi");
// - adding two string lengths must still fit into a 32-bit int without
// overflow
static_assert(kMaxLength * 2 <= kMaxInt,
"String::kMaxLength * 2 must fit into an int32");
// - any heap object's size in bytes must be able to fit into a Smi, because
// its space on the heap might be filled with a Filler; for strings this
// means SeqTwoByteString::kMaxSize must be able to fit into a Smi.
static_assert(kMaxLength * 2 + kHeaderSize <= kSmiMaxValue,
"String object size in bytes must fit into a Smi");
// - any heap object's size in bytes must be able to fit into an int, because
// that's what our object handling code uses almost everywhere.
static_assert(kMaxLength * 2 + kHeaderSize <= kMaxInt,
"String object size in bytes must fit into an int");
// Max length for computing hash. For strings longer than this limit the
// string length is used as the hash value.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment