Commit e282f9af authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[bigint] Pretenure BigInt literals

This is the same treatment we give other numeric literals, and seems
sensible since they end up referenced from Ignition's constant pool.

R=jkummerow@chromium.org

Bug: v8:6791
Change-Id: Ia689c709d402e4e87b7d2d22c582108400c25580
Reviewed-on: https://chromium-review.googlesource.com/922283
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51409}
parent ef8dae3f
...@@ -917,9 +917,12 @@ class StringToBigIntHelper : public StringToIntHelper { ...@@ -917,9 +917,12 @@ class StringToBigIntHelper : public StringToIntHelper {
// Optimization opportunity: Would it makes sense to scan for trailing // Optimization opportunity: Would it makes sense to scan for trailing
// junk before allocating the result? // junk before allocating the result?
int charcount = length() - cursor(); int charcount = length() - cursor();
// TODO(adamk): Pretenure if this is for a literal. // For literals, we pretenure the allocated BigInt, since it's about
MaybeHandle<FreshlyAllocatedBigInt> maybe = // to be stored in the interpreter's constants array.
BigInt::AllocateFor(isolate(), radix(), charcount, should_throw()); PretenureFlag pretenure =
behavior_ == Behavior::kLiteral ? TENURED : NOT_TENURED;
MaybeHandle<FreshlyAllocatedBigInt> maybe = BigInt::AllocateFor(
isolate(), radix(), charcount, should_throw(), pretenure);
if (!maybe.ToHandle(&result_)) { if (!maybe.ToHandle(&result_)) {
set_state(kError); set_state(kError);
} }
......
...@@ -1459,8 +1459,10 @@ Handle<HeapNumber> Factory::NewHeapNumber(MutableMode mode, ...@@ -1459,8 +1459,10 @@ Handle<HeapNumber> Factory::NewHeapNumber(MutableMode mode,
HeapNumber); HeapNumber);
} }
Handle<FreshlyAllocatedBigInt> Factory::NewBigInt(int length) { Handle<FreshlyAllocatedBigInt> Factory::NewBigInt(int length,
CALL_HEAP_FUNCTION(isolate(), isolate()->heap()->AllocateBigInt(length), PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(isolate(),
isolate()->heap()->AllocateBigInt(length, pretenure),
FreshlyAllocatedBigInt); FreshlyAllocatedBigInt);
} }
......
...@@ -500,7 +500,8 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -500,7 +500,8 @@ class V8_EXPORT_PRIVATE Factory final {
// Allocates a new BigInt with {length} digits. Only to be used by // Allocates a new BigInt with {length} digits. Only to be used by
// MutableBigInt::New*. // MutableBigInt::New*.
Handle<FreshlyAllocatedBigInt> NewBigInt(int length); Handle<FreshlyAllocatedBigInt> NewBigInt(
int length, PretenureFlag pretenure = NOT_TENURED);
Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length); Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
......
...@@ -2570,12 +2570,12 @@ AllocationResult Heap::AllocateHeapNumber(MutableMode mode, ...@@ -2570,12 +2570,12 @@ AllocationResult Heap::AllocateHeapNumber(MutableMode mode,
return result; return result;
} }
AllocationResult Heap::AllocateBigInt(int length) { AllocationResult Heap::AllocateBigInt(int length, PretenureFlag pretenure) {
if (length < 0 || length > BigInt::kMaxLength) { if (length < 0 || length > BigInt::kMaxLength) {
v8::internal::Heap::FatalProcessOutOfMemory("invalid BigInt length", true); v8::internal::Heap::FatalProcessOutOfMemory("invalid BigInt length", true);
} }
int size = BigInt::SizeFor(length); int size = BigInt::SizeFor(length);
AllocationSpace space = SelectSpace(NOT_TENURED); AllocationSpace space = SelectSpace(pretenure);
HeapObject* result = nullptr; HeapObject* result = nullptr;
{ {
AllocationResult allocation = AllocateRaw(size, space); AllocationResult allocation = AllocateRaw(size, space);
......
...@@ -2092,7 +2092,8 @@ class Heap { ...@@ -2092,7 +2092,8 @@ class Heap {
MUST_USE_RESULT AllocationResult AllocateHeapNumber( MUST_USE_RESULT AllocationResult AllocateHeapNumber(
MutableMode mode = IMMUTABLE, PretenureFlag pretenure = NOT_TENURED); MutableMode mode = IMMUTABLE, PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT AllocationResult AllocateBigInt(int length); MUST_USE_RESULT AllocationResult
AllocateBigInt(int length, PretenureFlag pretenure = NOT_TENURED);
// Allocates a byte array of the specified length // Allocates a byte array of the specified length
MUST_USE_RESULT AllocationResult MUST_USE_RESULT AllocationResult
......
...@@ -40,7 +40,8 @@ class MutableBigInt : public FreshlyAllocatedBigInt { ...@@ -40,7 +40,8 @@ class MutableBigInt : public FreshlyAllocatedBigInt {
static Handle<BigInt> MakeImmutable(Handle<MutableBigInt> result); static Handle<BigInt> MakeImmutable(Handle<MutableBigInt> result);
// Allocation helpers. // Allocation helpers.
static MaybeHandle<MutableBigInt> New(Isolate* isolate, int length); static MaybeHandle<MutableBigInt> New(Isolate* isolate, int length,
PretenureFlag pretenure = NOT_TENURED);
static Handle<BigInt> NewFromInt(Isolate* isolate, int value); static Handle<BigInt> NewFromInt(Isolate* isolate, int value);
static Handle<BigInt> NewFromSafeInteger(Isolate* isolate, double value); static Handle<BigInt> NewFromSafeInteger(Isolate* isolate, double value);
void InitializeDigits(int length, byte value = 0); void InitializeDigits(int length, byte value = 0);
...@@ -182,12 +183,14 @@ class MutableBigInt : public FreshlyAllocatedBigInt { ...@@ -182,12 +183,14 @@ class MutableBigInt : public FreshlyAllocatedBigInt {
void set_64_bits(uint64_t bits); void set_64_bits(uint64_t bits);
}; };
MaybeHandle<MutableBigInt> MutableBigInt::New(Isolate* isolate, int length) { MaybeHandle<MutableBigInt> MutableBigInt::New(Isolate* isolate, int length,
PretenureFlag pretenure) {
if (length > BigInt::kMaxLength) { if (length > BigInt::kMaxLength) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kBigIntTooBig), THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kBigIntTooBig),
MutableBigInt); MutableBigInt);
} }
Handle<MutableBigInt> result = Cast(isolate->factory()->NewBigInt(length)); Handle<MutableBigInt> result =
Cast(isolate->factory()->NewBigInt(length, pretenure));
result->set_length(length); result->set_length(length);
result->set_sign(false); result->set_sign(false);
#if DEBUG #if DEBUG
...@@ -1702,7 +1705,8 @@ static const int kBitsPerCharTableShift = 5; ...@@ -1702,7 +1705,8 @@ static const int kBitsPerCharTableShift = 5;
static const size_t kBitsPerCharTableMultiplier = 1u << kBitsPerCharTableShift; static const size_t kBitsPerCharTableMultiplier = 1u << kBitsPerCharTableShift;
MaybeHandle<FreshlyAllocatedBigInt> BigInt::AllocateFor( MaybeHandle<FreshlyAllocatedBigInt> BigInt::AllocateFor(
Isolate* isolate, int radix, int charcount, ShouldThrow should_throw) { Isolate* isolate, int radix, int charcount, ShouldThrow should_throw,
PretenureFlag pretenure) {
DCHECK(2 <= radix && radix <= 36); DCHECK(2 <= radix && radix <= 36);
DCHECK_GE(charcount, 0); DCHECK_GE(charcount, 0);
size_t bits_per_char = kMaxBitsPerChar[radix]; size_t bits_per_char = kMaxBitsPerChar[radix];
...@@ -1717,7 +1721,7 @@ MaybeHandle<FreshlyAllocatedBigInt> BigInt::AllocateFor( ...@@ -1717,7 +1721,7 @@ MaybeHandle<FreshlyAllocatedBigInt> BigInt::AllocateFor(
int length = (static_cast<int>(bits_min) + kDigitBits - 1) / kDigitBits; int length = (static_cast<int>(bits_min) + kDigitBits - 1) / kDigitBits;
if (length <= kMaxLength) { if (length <= kMaxLength) {
Handle<MutableBigInt> result = Handle<MutableBigInt> result =
MutableBigInt::New(isolate, length).ToHandleChecked(); MutableBigInt::New(isolate, length, pretenure).ToHandleChecked();
result->InitializeDigits(length); result->InitializeDigits(length);
return result; return result;
} }
......
...@@ -172,7 +172,8 @@ class V8_EXPORT_PRIVATE BigInt : public BigIntBase { ...@@ -172,7 +172,8 @@ class V8_EXPORT_PRIVATE BigInt : public BigIntBase {
// Special functions for StringToBigIntHelper: // Special functions for StringToBigIntHelper:
static Handle<BigInt> Zero(Isolate* isolate); static Handle<BigInt> Zero(Isolate* isolate);
static MaybeHandle<FreshlyAllocatedBigInt> AllocateFor( static MaybeHandle<FreshlyAllocatedBigInt> AllocateFor(
Isolate* isolate, int radix, int charcount, ShouldThrow should_throw); Isolate* isolate, int radix, int charcount, ShouldThrow should_throw,
PretenureFlag pretenure);
static void InplaceMultiplyAdd(Handle<FreshlyAllocatedBigInt> x, static void InplaceMultiplyAdd(Handle<FreshlyAllocatedBigInt> x,
uintptr_t factor, uintptr_t summand); uintptr_t factor, uintptr_t summand);
static Handle<BigInt> Finalize(Handle<FreshlyAllocatedBigInt> x, bool sign); static Handle<BigInt> Finalize(Handle<FreshlyAllocatedBigInt> x, bool sign);
......
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