[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/+/1792168
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@google.com>
Cr-Commit-Position: refs/heads/master@{#63670}
This commit is contained in:
Victor Gomes 2019-09-09 15:33:18 +02:00 committed by Commit Bot
parent 6376671c9c
commit 1e42880ed4
4 changed files with 33 additions and 45 deletions

View File

@ -1981,14 +1981,13 @@ void BigInt::SerializeDigits(uint8_t* storage) {
// The serialization format MUST NOT CHANGE without updating the format
// version in value-serializer.cc!
MaybeHandle<BigInt> BigInt::FromSerializedDigits(
Isolate* isolate, uint32_t bitfield, Vector<const uint8_t> digits_storage,
AllocationType allocation) {
Isolate* isolate, uint32_t bitfield, Vector<const uint8_t> digits_storage) {
int bytelength = LengthBits::decode(bitfield);
DCHECK(digits_storage.length() == bytelength);
bool sign = SignBits::decode(bitfield);
int length = (bytelength + kDigitSize - 1) / kDigitSize; // Round up.
Handle<MutableBigInt> result =
MutableBigInt::Cast(isolate->factory()->NewBigInt(length, allocation));
MutableBigInt::Cast(isolate->factory()->NewBigInt(length));
result->initialize_bitfield(sign, length);
void* digits =
reinterpret_cast<void*>(result->ptr() + kDigitsOffset - kHeapObjectTag);

View File

@ -263,8 +263,8 @@ class BigInt : public BigIntBase {
// {DigitsByteLengthForBitfield(GetBitfieldForSerialization())}.
void SerializeDigits(uint8_t* storage);
V8_WARN_UNUSED_RESULT static MaybeHandle<BigInt> FromSerializedDigits(
Isolate* isolate, uint32_t bitfield, Vector<const uint8_t> digits_storage,
AllocationType allocation);
Isolate* isolate, uint32_t bitfield,
Vector<const uint8_t> digits_storage);
OBJECT_CONSTRUCTORS(BigInt, BigIntBase);
};

View File

@ -52,8 +52,6 @@ static const uint32_t kLatestVersion = 13;
static_assert(kLatestVersion == v8::CurrentValueSerializerFormatVersion(),
"Exported format version must match latest version.");
static const int kPretenureThreshold = 100 * KB;
template <typename T>
static size_t BytesNeededForVarint(T value) {
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
@ -1112,8 +1110,6 @@ ValueDeserializer::ValueDeserializer(Isolate* isolate,
delegate_(delegate),
position_(data.begin()),
end_(data.begin() + data.length()),
allocation_(data.length() > kPretenureThreshold ? AllocationType::kOld
: AllocationType::kYoung),
id_map_(isolate->global_handles()->Create(
ReadOnlyRoots(isolate_).empty_fixed_array())) {}
@ -1302,19 +1298,17 @@ MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() {
case SerializationTag::kInt32: {
Maybe<int32_t> number = ReadZigZag<int32_t>();
if (number.IsNothing()) return MaybeHandle<Object>();
return isolate_->factory()->NewNumberFromInt(number.FromJust(),
allocation_);
return isolate_->factory()->NewNumberFromInt(number.FromJust());
}
case SerializationTag::kUint32: {
Maybe<uint32_t> number = ReadVarint<uint32_t>();
if (number.IsNothing()) return MaybeHandle<Object>();
return isolate_->factory()->NewNumberFromUint(number.FromJust(),
allocation_);
return isolate_->factory()->NewNumberFromUint(number.FromJust());
}
case SerializationTag::kDouble: {
Maybe<double> number = ReadDouble();
if (number.IsNothing()) return MaybeHandle<Object>();
return isolate_->factory()->NewNumber(number.FromJust(), allocation_);
return isolate_->factory()->NewNumber(number.FromJust());
}
case SerializationTag::kBigInt:
return ReadBigInt();
@ -1398,8 +1392,7 @@ MaybeHandle<BigInt> ValueDeserializer::ReadBigInt() {
if (!ReadRawBytes(bytelength).To(&digits_storage)) {
return MaybeHandle<BigInt>();
}
return BigInt::FromSerializedDigits(isolate_, bitfield, digits_storage,
allocation_);
return BigInt::FromSerializedDigits(isolate_, bitfield, digits_storage);
}
MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
@ -1412,7 +1405,7 @@ MaybeHandle<String> ValueDeserializer::ReadUtf8String() {
return MaybeHandle<String>();
}
return isolate_->factory()->NewStringFromUtf8(
Vector<const char>::cast(utf8_bytes), allocation_);
Vector<const char>::cast(utf8_bytes));
}
MaybeHandle<String> ValueDeserializer::ReadOneByteString() {
@ -1424,7 +1417,7 @@ MaybeHandle<String> ValueDeserializer::ReadOneByteString() {
!ReadRawBytes(byte_length).To(&bytes)) {
return MaybeHandle<String>();
}
return isolate_->factory()->NewStringFromOneByte(bytes, allocation_);
return isolate_->factory()->NewStringFromOneByte(bytes);
}
MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
@ -1443,7 +1436,7 @@ MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
if (byte_length == 0) return isolate_->factory()->empty_string();
Handle<SeqTwoByteString> string;
if (!isolate_->factory()
->NewRawTwoByteString(byte_length / sizeof(uc16), allocation_)
->NewRawTwoByteString(byte_length / sizeof(uc16))
.ToHandle(&string)) {
return MaybeHandle<String>();
}
@ -1506,8 +1499,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadJSObject() {
uint32_t id = next_id_++;
HandleScope scope(isolate_);
Handle<JSObject> object = isolate_->factory()->NewJSObject(
isolate_->object_function(), allocation_);
Handle<JSObject> object =
isolate_->factory()->NewJSObject(isolate_->object_function());
AddObjectWithID(id, object);
uint32_t num_properties;
@ -1532,8 +1525,8 @@ MaybeHandle<JSArray> ValueDeserializer::ReadSparseJSArray() {
uint32_t id = next_id_++;
HandleScope scope(isolate_);
Handle<JSArray> array = isolate_->factory()->NewJSArray(
0, TERMINAL_FAST_ELEMENTS_KIND, allocation_);
Handle<JSArray> array =
isolate_->factory()->NewJSArray(0, TERMINAL_FAST_ELEMENTS_KIND);
JSArray::SetLength(array, length);
AddObjectWithID(id, array);
@ -1569,8 +1562,7 @@ MaybeHandle<JSArray> ValueDeserializer::ReadDenseJSArray() {
uint32_t id = next_id_++;
HandleScope scope(isolate_);
Handle<JSArray> array = isolate_->factory()->NewJSArray(
HOLEY_ELEMENTS, length, length, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE,
allocation_);
HOLEY_ELEMENTS, length, length, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
AddObjectWithID(id, array);
Handle<FixedArray> elements(FixedArray::cast(array->elements()), isolate_);
@ -1631,22 +1623,21 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper(
Handle<JSPrimitiveWrapper> value;
switch (tag) {
case SerializationTag::kTrueObject:
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject(
isolate_->boolean_function(), allocation_));
value = Handle<JSPrimitiveWrapper>::cast(
isolate_->factory()->NewJSObject(isolate_->boolean_function()));
value->set_value(ReadOnlyRoots(isolate_).true_value());
break;
case SerializationTag::kFalseObject:
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject(
isolate_->boolean_function(), allocation_));
value = Handle<JSPrimitiveWrapper>::cast(
isolate_->factory()->NewJSObject(isolate_->boolean_function()));
value->set_value(ReadOnlyRoots(isolate_).false_value());
break;
case SerializationTag::kNumberObject: {
double number;
if (!ReadDouble().To(&number)) return MaybeHandle<JSPrimitiveWrapper>();
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject(
isolate_->number_function(), allocation_));
Handle<Object> number_object =
isolate_->factory()->NewNumber(number, allocation_);
value = Handle<JSPrimitiveWrapper>::cast(
isolate_->factory()->NewJSObject(isolate_->number_function()));
Handle<Object> number_object = isolate_->factory()->NewNumber(number);
value->set_value(*number_object);
break;
}
@ -1654,8 +1645,8 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper(
Handle<BigInt> bigint;
if (!ReadBigInt().ToHandle(&bigint))
return MaybeHandle<JSPrimitiveWrapper>();
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject(
isolate_->bigint_function(), allocation_));
value = Handle<JSPrimitiveWrapper>::cast(
isolate_->factory()->NewJSObject(isolate_->bigint_function()));
value->set_value(*bigint);
break;
}
@ -1663,8 +1654,8 @@ MaybeHandle<JSPrimitiveWrapper> ValueDeserializer::ReadJSPrimitiveWrapper(
Handle<String> string;
if (!ReadString().ToHandle(&string))
return MaybeHandle<JSPrimitiveWrapper>();
value = Handle<JSPrimitiveWrapper>::cast(isolate_->factory()->NewJSObject(
isolate_->string_function(), allocation_));
value = Handle<JSPrimitiveWrapper>::cast(
isolate_->factory()->NewJSObject(isolate_->string_function()));
value->set_value(*string);
break;
}
@ -1803,7 +1794,7 @@ MaybeHandle<JSArrayBuffer> ValueDeserializer::ReadJSArrayBuffer(
}
MaybeHandle<JSArrayBuffer> result =
isolate_->factory()->NewJSArrayBufferAndBackingStore(
byte_length, InitializedFlag::kUninitialized, allocation_);
byte_length, InitializedFlag::kUninitialized);
Handle<JSArrayBuffer> array_buffer;
if (!result.ToHandle(&array_buffer)) return result;
@ -1870,8 +1861,7 @@ MaybeHandle<JSArrayBufferView> ValueDeserializer::ReadJSArrayBufferView(
return MaybeHandle<JSArrayBufferView>();
}
Handle<JSTypedArray> typed_array = isolate_->factory()->NewJSTypedArray(
external_array_type, buffer, byte_offset, byte_length / element_size,
allocation_);
external_array_type, buffer, byte_offset, byte_length / element_size);
AddObjectWithID(id, typed_array);
return typed_array;
}
@ -2312,8 +2302,8 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() {
size_t begin_properties =
stack.size() - 2 * static_cast<size_t>(num_properties);
Handle<JSObject> js_object = isolate_->factory()->NewJSObject(
isolate_->object_function(), allocation_);
Handle<JSObject> js_object =
isolate_->factory()->NewJSObject(isolate_->object_function());
if (num_properties &&
!SetPropertiesFromKeyValuePairs(
isolate_, js_object, &stack[begin_properties], num_properties)
@ -2340,8 +2330,8 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() {
return MaybeHandle<Object>();
}
Handle<JSArray> js_array = isolate_->factory()->NewJSArray(
0, TERMINAL_FAST_ELEMENTS_KIND, allocation_);
Handle<JSArray> js_array =
isolate_->factory()->NewJSArray(0, TERMINAL_FAST_ELEMENTS_KIND);
JSArray::SetLength(js_array, length);
size_t begin_properties =
stack.size() - 2 * static_cast<size_t>(num_properties);

View File

@ -298,7 +298,6 @@ class ValueDeserializer {
v8::ValueDeserializer::Delegate* const delegate_;
const uint8_t* position_;
const uint8_t* const end_;
AllocationType allocation_;
uint32_t version_ = 0;
uint32_t next_id_ = 0;
bool expect_inline_wasm_ = false;