Commit 1e42880e authored by Victor Gomes's avatar Victor Gomes Committed by Commit Bot

[Value Serializer] Remove allocation flag

From verwaest@ work on the Json's parser, we know that removing the allocation type argument when creating objects using the factory class increases performance. This will also allow us to optimise these functions in a latter CL.

Change-Id: If78f62a63fe41453f4def8bea77b6eddc2ab7f36
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1792168Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@google.com>
Cr-Commit-Position: refs/heads/master@{#63670}
parent 6376671c
...@@ -1981,14 +1981,13 @@ void BigInt::SerializeDigits(uint8_t* storage) { ...@@ -1981,14 +1981,13 @@ void BigInt::SerializeDigits(uint8_t* storage) {
// The serialization format MUST NOT CHANGE without updating the format // The serialization format MUST NOT CHANGE without updating the format
// version in value-serializer.cc! // version in value-serializer.cc!
MaybeHandle<BigInt> BigInt::FromSerializedDigits( MaybeHandle<BigInt> BigInt::FromSerializedDigits(
Isolate* isolate, uint32_t bitfield, Vector<const uint8_t> digits_storage, Isolate* isolate, uint32_t bitfield, Vector<const uint8_t> digits_storage) {
AllocationType allocation) {
int bytelength = LengthBits::decode(bitfield); int bytelength = LengthBits::decode(bitfield);
DCHECK(digits_storage.length() == bytelength); DCHECK(digits_storage.length() == bytelength);
bool sign = SignBits::decode(bitfield); bool sign = SignBits::decode(bitfield);
int length = (bytelength + kDigitSize - 1) / kDigitSize; // Round up. int length = (bytelength + kDigitSize - 1) / kDigitSize; // Round up.
Handle<MutableBigInt> result = Handle<MutableBigInt> result =
MutableBigInt::Cast(isolate->factory()->NewBigInt(length, allocation)); MutableBigInt::Cast(isolate->factory()->NewBigInt(length));
result->initialize_bitfield(sign, length); result->initialize_bitfield(sign, length);
void* digits = void* digits =
reinterpret_cast<void*>(result->ptr() + kDigitsOffset - kHeapObjectTag); reinterpret_cast<void*>(result->ptr() + kDigitsOffset - kHeapObjectTag);
......
...@@ -263,8 +263,8 @@ class BigInt : public BigIntBase { ...@@ -263,8 +263,8 @@ class BigInt : public BigIntBase {
// {DigitsByteLengthForBitfield(GetBitfieldForSerialization())}. // {DigitsByteLengthForBitfield(GetBitfieldForSerialization())}.
void SerializeDigits(uint8_t* storage); void SerializeDigits(uint8_t* storage);
V8_WARN_UNUSED_RESULT static MaybeHandle<BigInt> FromSerializedDigits( V8_WARN_UNUSED_RESULT static MaybeHandle<BigInt> FromSerializedDigits(
Isolate* isolate, uint32_t bitfield, Vector<const uint8_t> digits_storage, Isolate* isolate, uint32_t bitfield,
AllocationType allocation); Vector<const uint8_t> digits_storage);
OBJECT_CONSTRUCTORS(BigInt, BigIntBase); OBJECT_CONSTRUCTORS(BigInt, BigIntBase);
}; };
......
...@@ -52,8 +52,6 @@ static const uint32_t kLatestVersion = 13; ...@@ -52,8 +52,6 @@ static const uint32_t kLatestVersion = 13;
static_assert(kLatestVersion == v8::CurrentValueSerializerFormatVersion(), static_assert(kLatestVersion == v8::CurrentValueSerializerFormatVersion(),
"Exported format version must match latest version."); "Exported format version must match latest version.");
static const int kPretenureThreshold = 100 * KB;
template <typename T> template <typename T>
static size_t BytesNeededForVarint(T value) { static size_t BytesNeededForVarint(T value) {
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value, static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
...@@ -1112,8 +1110,6 @@ ValueDeserializer::ValueDeserializer(Isolate* isolate, ...@@ -1112,8 +1110,6 @@ ValueDeserializer::ValueDeserializer(Isolate* isolate,
delegate_(delegate), delegate_(delegate),
position_(data.begin()), position_(data.begin()),
end_(data.begin() + data.length()), end_(data.begin() + data.length()),
allocation_(data.length() > kPretenureThreshold ? AllocationType::kOld
: AllocationType::kYoung),
id_map_(isolate->global_handles()->Create( id_map_(isolate->global_handles()->Create(
ReadOnlyRoots(isolate_).empty_fixed_array())) {} ReadOnlyRoots(isolate_).empty_fixed_array())) {}
...@@ -1302,19 +1298,17 @@ MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() { ...@@ -1302,19 +1298,17 @@ MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() {
case SerializationTag::kInt32: { case SerializationTag::kInt32: {
Maybe<int32_t> number = ReadZigZag<int32_t>(); Maybe<int32_t> number = ReadZigZag<int32_t>();
if (number.IsNothing()) return MaybeHandle<Object>(); if (number.IsNothing()) return MaybeHandle<Object>();
return isolate_->factory()->NewNumberFromInt(number.FromJust(), return isolate_->factory()->NewNumberFromInt(number.FromJust());
allocation_);
} }
case SerializationTag::kUint32: { case SerializationTag::kUint32: {
Maybe<uint32_t> number = ReadVarint<uint32_t>(); Maybe<uint32_t> number = ReadVarint<uint32_t>();
if (number.IsNothing()) return MaybeHandle<Object>(); if (number.IsNothing()) return MaybeHandle<Object>();
return isolate_->factory()->NewNumberFromUint(number.FromJust(), return isolate_->factory()->NewNumberFromUint(number.FromJust());
allocation_);
} }
case SerializationTag::kDouble: { case SerializationTag::kDouble: {
Maybe<double> number = ReadDouble(); Maybe<double> number = ReadDouble();
if (number.IsNothing()) return MaybeHandle<Object>(); if (number.IsNothing()) return MaybeHandle<Object>();
return isolate_->factory()->NewNumber(number.FromJust(), allocation_); return isolate_->factory()->NewNumber(number.FromJust());
} }
case SerializationTag::kBigInt: case SerializationTag::kBigInt:
return ReadBigInt(); return ReadBigInt();
...@@ -1398,8 +1392,7 @@ MaybeHandle<BigInt> ValueDeserializer::ReadBigInt() { ...@@ -1398,8 +1392,7 @@ MaybeHandle<BigInt> ValueDeserializer::ReadBigInt() {
if (!ReadRawBytes(bytelength).To(&digits_storage)) { if (!ReadRawBytes(bytelength).To(&digits_storage)) {
return MaybeHandle<BigInt>(); return MaybeHandle<BigInt>();
} }
return BigInt::FromSerializedDigits(isolate_, bitfield, digits_storage, return BigInt::FromSerializedDigits(isolate_, bitfield, digits_storage);
allocation_);
} }
MaybeHandle<String> ValueDeserializer::ReadUtf8String() { MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
...@@ -1412,7 +1405,7 @@ MaybeHandle<String> ValueDeserializer::ReadUtf8String() { ...@@ -1412,7 +1405,7 @@ MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
return MaybeHandle<String>(); return MaybeHandle<String>();
} }
return isolate_->factory()->NewStringFromUtf8( return isolate_->factory()->NewStringFromUtf8(
Vector<const char>::cast(utf8_bytes), allocation_); Vector<const char>::cast(utf8_bytes));
} }
MaybeHandle<String> ValueDeserializer::ReadOneByteString() { MaybeHandle<String> ValueDeserializer::ReadOneByteString() {
...@@ -1424,7 +1417,7 @@ MaybeHandle<String> ValueDeserializer::ReadOneByteString() { ...@@ -1424,7 +1417,7 @@ MaybeHandle<String> ValueDeserializer::ReadOneByteString() {
!ReadRawBytes(byte_length).To(&bytes)) { !ReadRawBytes(byte_length).To(&bytes)) {
return MaybeHandle<String>(); return MaybeHandle<String>();
} }
return isolate_->factory()->NewStringFromOneByte(bytes, allocation_); return isolate_->factory()->NewStringFromOneByte(bytes);
} }
MaybeHandle<String> ValueDeserializer::ReadTwoByteString() { MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
...@@ -1443,7 +1436,7 @@ MaybeHandle<String> ValueDeserializer::ReadTwoByteString() { ...@@ -1443,7 +1436,7 @@ MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
if (byte_length == 0) return isolate_->factory()->empty_string(); if (byte_length == 0) return isolate_->factory()->empty_string();
Handle<SeqTwoByteString> string; Handle<SeqTwoByteString> string;
if (!isolate_->factory() if (!isolate_->factory()
->NewRawTwoByteString(byte_length / sizeof(uc16), allocation_) ->NewRawTwoByteString(byte_length / sizeof(uc16))
.ToHandle(&string)) { .ToHandle(&string)) {
return MaybeHandle<String>(); return MaybeHandle<String>();
} }
...@@ -1506,8 +1499,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadJSObject() { ...@@ -1506,8 +1499,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadJSObject() {
uint32_t id = next_id_++; uint32_t id = next_id_++;
HandleScope scope(isolate_); HandleScope scope(isolate_);
Handle<JSObject> object = isolate_->factory()->NewJSObject( Handle<JSObject> object =
isolate_->object_function(), allocation_); isolate_->factory()->NewJSObject(isolate_->object_function());
AddObjectWithID(id, object); AddObjectWithID(id, object);
uint32_t num_properties; uint32_t num_properties;
...@@ -1532,8 +1525,8 @@ MaybeHandle<JSArray> ValueDeserializer::ReadSparseJSArray() { ...@@ -1532,8 +1525,8 @@ MaybeHandle<JSArray> ValueDeserializer::ReadSparseJSArray() {
uint32_t id = next_id_++; uint32_t id = next_id_++;
HandleScope scope(isolate_); HandleScope scope(isolate_);
Handle<JSArray> array = isolate_->factory()->NewJSArray( Handle<JSArray> array =
0, TERMINAL_FAST_ELEMENTS_KIND, allocation_); isolate_->factory()->NewJSArray(0, TERMINAL_FAST_ELEMENTS_KIND);
JSArray::SetLength(array, length); JSArray::SetLength(array, length);
AddObjectWithID(id, array); AddObjectWithID(id, array);
...@@ -1569,8 +1562,7 @@ MaybeHandle<JSArray> ValueDeserializer::ReadDenseJSArray() { ...@@ -1569,8 +1562,7 @@ MaybeHandle<JSArray> ValueDeserializer::ReadDenseJSArray() {
uint32_t id = next_id_++; uint32_t id = next_id_++;
HandleScope scope(isolate_); HandleScope scope(isolate_);
Handle<JSArray> array = isolate_->factory()->NewJSArray( Handle<JSArray> array = isolate_->factory()->NewJSArray(
HOLEY_ELEMENTS, length, length, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, HOLEY_ELEMENTS, length, length, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
allocation_);
AddObjectWithID(id, array); AddObjectWithID(id, array);
Handle<FixedArray> elements(FixedArray::cast(array->elements()), isolate_); Handle<FixedArray> elements(FixedArray::cast(array->elements()), isolate_);
...@@ -1631,22 +1623,21 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper( ...@@ -1631,22 +1623,21 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper(
Handle<JSPrimitiveWrapper> value; Handle<JSPrimitiveWrapper> value;
switch (tag) { switch (tag) {
case SerializationTag::kTrueObject: case SerializationTag::kTrueObject:
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject( value = Handle<JSPrimitiveWrapper>::cast(
isolate_->boolean_function(), allocation_)); isolate_->factory()->NewJSObject(isolate_->boolean_function()));
value->set_value(ReadOnlyRoots(isolate_).true_value()); value->set_value(ReadOnlyRoots(isolate_).true_value());
break; break;
case SerializationTag::kFalseObject: case SerializationTag::kFalseObject:
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject( value = Handle<JSPrimitiveWrapper>::cast(
isolate_->boolean_function(), allocation_)); isolate_->factory()->NewJSObject(isolate_->boolean_function()));
value->set_value(ReadOnlyRoots(isolate_).false_value()); value->set_value(ReadOnlyRoots(isolate_).false_value());
break; break;
case SerializationTag::kNumberObject: { case SerializationTag::kNumberObject: {
double number; double number;
if (!ReadDouble().To(&number)) return MaybeHandle<JSPrimitiveWrapper>(); if (!ReadDouble().To(&number)) return MaybeHandle<JSPrimitiveWrapper>();
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject( value = Handle<JSPrimitiveWrapper>::cast(
isolate_->number_function(), allocation_)); isolate_->factory()->NewJSObject(isolate_->number_function()));
Handle<Object> number_object = Handle<Object> number_object = isolate_->factory()->NewNumber(number);
isolate_->factory()->NewNumber(number, allocation_);
value->set_value(*number_object); value->set_value(*number_object);
break; break;
} }
...@@ -1654,8 +1645,8 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper( ...@@ -1654,8 +1645,8 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper(
Handle<BigInt> bigint; Handle<BigInt> bigint;
if (!ReadBigInt().ToHandle(&bigint)) if (!ReadBigInt().ToHandle(&bigint))
return MaybeHandle<JSPrimitiveWrapper>(); return MaybeHandle<JSPrimitiveWrapper>();
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject( value = Handle<JSPrimitiveWrapper>::cast(
isolate_->bigint_function(), allocation_)); isolate_->factory()->NewJSObject(isolate_->bigint_function()));
value->set_value(*bigint); value->set_value(*bigint);
break; break;
} }
...@@ -1663,8 +1654,8 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper( ...@@ -1663,8 +1654,8 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper(
Handle<String> string; Handle<String> string;
if (!ReadString().ToHandle(&string)) if (!ReadString().ToHandle(&string))
return MaybeHandle<JSPrimitiveWrapper>(); return MaybeHandle<JSPrimitiveWrapper>();
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject( value = Handle<JSPrimitiveWrapper>::cast(
isolate_->string_function(), allocation_)); isolate_->factory()->NewJSObject(isolate_->string_function()));
value->set_value(*string); value->set_value(*string);
break; break;
} }
...@@ -1803,7 +1794,7 @@ MaybeHandle<JSArrayBuffer> ValueDeserializer::ReadJSArrayBuffer( ...@@ -1803,7 +1794,7 @@ MaybeHandle<JSArrayBuffer> ValueDeserializer::ReadJSArrayBuffer(
} }
MaybeHandle<JSArrayBuffer> result = MaybeHandle<JSArrayBuffer> result =
isolate_->factory()->NewJSArrayBufferAndBackingStore( isolate_->factory()->NewJSArrayBufferAndBackingStore(
byte_length, InitializedFlag::kUninitialized, allocation_); byte_length, InitializedFlag::kUninitialized);
Handle<JSArrayBuffer> array_buffer; Handle<JSArrayBuffer> array_buffer;
if (!result.ToHandle(&array_buffer)) return result; if (!result.ToHandle(&array_buffer)) return result;
...@@ -1870,8 +1861,7 @@ MaybeHandle<JSArrayBufferView> ValueDeserializer::ReadJSArrayBufferView( ...@@ -1870,8 +1861,7 @@ MaybeHandle<JSArrayBufferView> ValueDeserializer::ReadJSArrayBufferView(
return MaybeHandle<JSArrayBufferView>(); return MaybeHandle<JSArrayBufferView>();
} }
Handle<JSTypedArray> typed_array = isolate_->factory()->NewJSTypedArray( Handle<JSTypedArray> typed_array = isolate_->factory()->NewJSTypedArray(
external_array_type, buffer, byte_offset, byte_length / element_size, external_array_type, buffer, byte_offset, byte_length / element_size);
allocation_);
AddObjectWithID(id, typed_array); AddObjectWithID(id, typed_array);
return typed_array; return typed_array;
} }
...@@ -2312,8 +2302,8 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { ...@@ -2312,8 +2302,8 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() {
size_t begin_properties = size_t begin_properties =
stack.size() - 2 * static_cast<size_t>(num_properties); stack.size() - 2 * static_cast<size_t>(num_properties);
Handle<JSObject> js_object = isolate_->factory()->NewJSObject( Handle<JSObject> js_object =
isolate_->object_function(), allocation_); isolate_->factory()->NewJSObject(isolate_->object_function());
if (num_properties && if (num_properties &&
!SetPropertiesFromKeyValuePairs( !SetPropertiesFromKeyValuePairs(
isolate_, js_object, &stack[begin_properties], num_properties) isolate_, js_object, &stack[begin_properties], num_properties)
...@@ -2340,8 +2330,8 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { ...@@ -2340,8 +2330,8 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() {
return MaybeHandle<Object>(); return MaybeHandle<Object>();
} }
Handle<JSArray> js_array = isolate_->factory()->NewJSArray( Handle<JSArray> js_array =
0, TERMINAL_FAST_ELEMENTS_KIND, allocation_); isolate_->factory()->NewJSArray(0, TERMINAL_FAST_ELEMENTS_KIND);
JSArray::SetLength(js_array, length); JSArray::SetLength(js_array, length);
size_t begin_properties = size_t begin_properties =
stack.size() - 2 * static_cast<size_t>(num_properties); stack.size() - 2 * static_cast<size_t>(num_properties);
......
...@@ -298,7 +298,6 @@ class ValueDeserializer { ...@@ -298,7 +298,6 @@ class ValueDeserializer {
v8::ValueDeserializer::Delegate* const delegate_; v8::ValueDeserializer::Delegate* const delegate_;
const uint8_t* position_; const uint8_t* position_;
const uint8_t* const end_; const uint8_t* const end_;
AllocationType allocation_;
uint32_t version_ = 0; uint32_t version_ = 0;
uint32_t next_id_ = 0; uint32_t next_id_ = 0;
bool expect_inline_wasm_ = false; bool expect_inline_wasm_ = false;
......
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