Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v8.x] deps: cherry-pick a803fad from upstream V8 #19824

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 6
#define V8_MINOR_VERSION 2
#define V8_BUILD_NUMBER 414
#define V8_PATCH_LEVEL 50
#define V8_PATCH_LEVEL 53

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5190,6 +5190,7 @@ Local<v8::Context> v8::Object::CreationContext() {


int v8::Object::GetIdentityHash() {
i::DisallowHeapAllocation no_gc;
auto isolate = Utils::OpenHandle(this)->GetIsolate();
i::HandleScope scope(isolate);
auto self = Utils::OpenHandle(this);
Expand Down
7 changes: 4 additions & 3 deletions deps/v8/src/code-stub-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,8 @@ TNode<Int32T> CodeStubAssembler::LoadHashForJSObject(
{
Node* length_and_hash_int32 = LoadAndUntagToWord32ObjectField(
properties_or_hash, PropertyArray::kLengthAndHashOffset);
var_hash.Bind(Word32And(length_and_hash_int32,
Int32Constant(PropertyArray::kHashMask)));
var_hash.Bind(
DecodeWord32<PropertyArray::HashField>(length_and_hash_int32));
Goto(&done);
}

Expand Down Expand Up @@ -2508,7 +2508,8 @@ void CodeStubAssembler::InitializePropertyArrayLength(Node* property_array,
CSA_ASSERT(
this,
IntPtrOrSmiLessThanOrEqual(
length, IntPtrOrSmiConstant(PropertyArray::kMaxLength, mode), mode));
length, IntPtrOrSmiConstant(PropertyArray::LengthField::kMax, mode),
mode));
StoreObjectFieldNoWriteBarrier(
property_array, PropertyArray::kLengthAndHashOffset,
ParameterToTagged(length, mode), MachineRepresentation::kTaggedSigned);
Expand Down
8 changes: 6 additions & 2 deletions deps/v8/src/compiler/js-native-context-specialization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2255,14 +2255,18 @@ Node* JSNativeContextSpecialization::BuildExtendPropertiesBackingStore(
jsgraph()->SmiConstant(PropertyArray::kNoHashSentinel));
hash = graph()->NewNode(common()->TypeGuard(Type::SignedSmall()), hash,
control);
hash =
graph()->NewNode(simplified()->NumberShiftLeft(), hash,
jsgraph()->Constant(PropertyArray::HashField::kShift));
} else {
hash = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForPropertyArrayLengthAndHash()),
properties, effect, control);
effect = graph()->NewNode(
common()->BeginRegion(RegionObservability::kNotObservable), effect);
hash = graph()->NewNode(simplified()->NumberBitwiseAnd(), hash,
jsgraph()->Constant(JSReceiver::kHashMask));
hash =
graph()->NewNode(simplified()->NumberBitwiseAnd(), hash,
jsgraph()->Constant(PropertyArray::HashField::kMask));
}

Node* new_length_and_hash = graph()->NewNode(
Expand Down
18 changes: 11 additions & 7 deletions deps/v8/src/ic/accessor-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ void AccessorAssembler::ExtendPropertiesBackingStore(Node* object,
// TODO(gsathya): Clean up the type conversions by creating smarter
// helpers that do the correct op based on the mode.
VARIABLE(var_properties, MachineRepresentation::kTaggedPointer);
VARIABLE(var_hash, MachineRepresentation::kWord32);
VARIABLE(var_encoded_hash, MachineRepresentation::kWord32);
VARIABLE(var_length, ParameterRepresentation(mode));

Node* properties = LoadObjectField(object, JSObject::kPropertiesOrHashOffset);
Expand All @@ -1102,7 +1102,10 @@ void AccessorAssembler::ExtendPropertiesBackingStore(Node* object,

BIND(&if_smi_hash);
{
var_hash.Bind(SmiToWord32(properties));
Node* hash = SmiToWord32(properties);
Node* encoded_hash =
Word32Shl(hash, Int32Constant(PropertyArray::HashField::kShift));
var_encoded_hash.Bind(encoded_hash);
var_length.Bind(IntPtrOrSmiConstant(0, mode));
var_properties.Bind(EmptyFixedArrayConstant());
Goto(&extend_store);
Expand All @@ -1112,10 +1115,11 @@ void AccessorAssembler::ExtendPropertiesBackingStore(Node* object,
{
Node* length_and_hash_int32 = LoadAndUntagToWord32ObjectField(
var_properties.value(), PropertyArray::kLengthAndHashOffset);
var_hash.Bind(Word32And(length_and_hash_int32,
Int32Constant(PropertyArray::kHashMask)));
Node* length_intptr = ChangeInt32ToIntPtr(Word32And(
length_and_hash_int32, Int32Constant(PropertyArray::kLengthMask)));
var_encoded_hash.Bind(Word32And(
length_and_hash_int32, Int32Constant(PropertyArray::HashField::kMask)));
Node* length_intptr = ChangeInt32ToIntPtr(
Word32And(length_and_hash_int32,
Int32Constant(PropertyArray::LengthField::kMask)));
Node* length = WordToParameter(length_intptr, mode);
var_length.Bind(length);
Goto(&extend_store);
Expand Down Expand Up @@ -1161,7 +1165,7 @@ void AccessorAssembler::ExtendPropertiesBackingStore(Node* object,
Node* new_capacity_int32 =
TruncateWordToWord32(ParameterToWord(new_capacity, mode));
Node* new_length_and_hash_int32 =
Word32Or(var_hash.value(), new_capacity_int32);
Word32Or(var_encoded_hash.value(), new_capacity_int32);
StoreObjectField(new_properties, PropertyArray::kLengthAndHashOffset,
SmiFromWord32(new_length_and_hash_int32));
StoreObjectField(object, JSObject::kPropertiesOrHashOffset, new_properties);
Expand Down
14 changes: 6 additions & 8 deletions deps/v8/src/objects-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2679,33 +2679,31 @@ SYNCHRONIZED_SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset)
int PropertyArray::length() const {
Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
return value & kLengthMask;
return LengthField::decode(value);
}

void PropertyArray::initialize_length(int len) {
SLOW_DCHECK(len >= 0);
SLOW_DCHECK(len < kMaxLength);
SLOW_DCHECK(len < LengthField::kMax);
WRITE_FIELD(this, kLengthAndHashOffset, Smi::FromInt(len));
}

int PropertyArray::synchronized_length() const {
Object* value_obj = ACQUIRE_READ_FIELD(this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
return value & kLengthMask;
return LengthField::decode(value);
}

int PropertyArray::Hash() const {
Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
int hash = value & kHashMask;
return hash;
return HashField::decode(value);
}

void PropertyArray::SetHash(int masked_hash) {
DCHECK_EQ(masked_hash & JSReceiver::kHashMask, masked_hash);
void PropertyArray::SetHash(int hash) {
Object* value_obj = READ_FIELD(this, kLengthAndHashOffset);
int value = Smi::ToInt(value_obj);
value = (value & kLengthMask) | masked_hash;
value = HashField::update(value, hash);
WRITE_FIELD(this, kLengthAndHashOffset, Smi::FromInt(value));
}

Expand Down
44 changes: 24 additions & 20 deletions deps/v8/src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@ namespace {
// objects. This avoids a double lookup in the cases where we know we will
// add the hash to the JSObject if it does not already exist.
Object* GetSimpleHash(Object* object) {
DisallowHeapAllocation no_gc;
// The object is either a Smi, a HeapNumber, a name, an odd-ball, a real JS
// object, or a Harmony proxy.
if (object->IsSmi()) {
Expand Down Expand Up @@ -2333,10 +2334,10 @@ Object* GetSimpleHash(Object* object) {
} // namespace

Object* Object::GetHash() {
DisallowHeapAllocation no_gc;
Object* hash = GetSimpleHash(this);
if (hash->IsSmi()) return hash;

DisallowHeapAllocation no_gc;
DCHECK(IsJSReceiver());
JSReceiver* receiver = JSReceiver::cast(this);
Isolate* isolate = receiver->GetIsolate();
Expand All @@ -2345,10 +2346,12 @@ Object* Object::GetHash() {

// static
Smi* Object::GetOrCreateHash(Isolate* isolate, Object* key) {
DisallowHeapAllocation no_gc;
return key->GetOrCreateHash(isolate);
}

Smi* Object::GetOrCreateHash(Isolate* isolate) {
DisallowHeapAllocation no_gc;
Object* hash = GetSimpleHash(this);
if (hash->IsSmi()) return Smi::cast(hash);

Expand Down Expand Up @@ -6266,26 +6269,27 @@ Handle<SeededNumberDictionary> JSObject::NormalizeElements(

namespace {

Object* SetHashAndUpdateProperties(HeapObject* properties, int masked_hash) {
DCHECK_NE(PropertyArray::kNoHashSentinel, masked_hash);
DCHECK_EQ(masked_hash & JSReceiver::kHashMask, masked_hash);
Object* SetHashAndUpdateProperties(HeapObject* properties, int hash) {
DCHECK_NE(PropertyArray::kNoHashSentinel, hash);
DCHECK(PropertyArray::HashField::is_valid(hash));

if (properties == properties->GetHeap()->empty_fixed_array() ||
properties == properties->GetHeap()->empty_property_dictionary()) {
return Smi::FromInt(masked_hash);
return Smi::FromInt(hash);
}

if (properties->IsPropertyArray()) {
PropertyArray::cast(properties)->SetHash(masked_hash);
PropertyArray::cast(properties)->SetHash(hash);
return properties;
}

DCHECK(properties->IsDictionary());
NameDictionary::cast(properties)->SetHash(masked_hash);
NameDictionary::cast(properties)->SetHash(hash);
return properties;
}

int GetIdentityHashHelper(Isolate* isolate, JSReceiver* object) {
DisallowHeapAllocation no_gc;
Object* properties = object->raw_properties_or_hash();
if (properties->IsSmi()) {
return Smi::ToInt(properties);
Expand All @@ -6311,17 +6315,19 @@ int GetIdentityHashHelper(Isolate* isolate, JSReceiver* object) {
}
} // namespace

void JSReceiver::SetIdentityHash(int masked_hash) {
DCHECK_NE(PropertyArray::kNoHashSentinel, masked_hash);
DCHECK_EQ(masked_hash & JSReceiver::kHashMask, masked_hash);
void JSReceiver::SetIdentityHash(int hash) {
DisallowHeapAllocation no_gc;
DCHECK_NE(PropertyArray::kNoHashSentinel, hash);
DCHECK(PropertyArray::HashField::is_valid(hash));

HeapObject* existing_properties = HeapObject::cast(raw_properties_or_hash());
Object* new_properties =
SetHashAndUpdateProperties(existing_properties, masked_hash);
SetHashAndUpdateProperties(existing_properties, hash);
set_raw_properties_or_hash(new_properties);
}

void JSReceiver::SetProperties(HeapObject* properties) {
DisallowHeapAllocation no_gc;
Isolate* isolate = properties->GetIsolate();
int hash = GetIdentityHashHelper(isolate, this);
Object* new_properties = properties;
Expand All @@ -6337,6 +6343,7 @@ void JSReceiver::SetProperties(HeapObject* properties) {

template <typename ProxyType>
Smi* GetOrCreateIdentityHashHelper(Isolate* isolate, ProxyType* proxy) {
DisallowHeapAllocation no_gc;
Object* maybe_hash = proxy->hash();
if (maybe_hash->IsSmi()) return Smi::cast(maybe_hash);

Expand All @@ -6346,6 +6353,7 @@ Smi* GetOrCreateIdentityHashHelper(Isolate* isolate, ProxyType* proxy) {
}

Object* JSObject::GetIdentityHash(Isolate* isolate) {
DisallowHeapAllocation no_gc;
if (IsJSGlobalProxy()) {
return JSGlobalProxy::cast(this)->hash();
}
Expand All @@ -6359,6 +6367,7 @@ Object* JSObject::GetIdentityHash(Isolate* isolate) {
}

Smi* JSObject::GetOrCreateIdentityHash(Isolate* isolate) {
DisallowHeapAllocation no_gc;
if (IsJSGlobalProxy()) {
return GetOrCreateIdentityHashHelper(isolate, JSGlobalProxy::cast(this));
}
Expand All @@ -6368,16 +6377,11 @@ Smi* JSObject::GetOrCreateIdentityHash(Isolate* isolate) {
return Smi::cast(hash_obj);
}

int masked_hash;
// TODO(gsathya): Remove the loop and pass kHashMask directly to
// GenerateIdentityHash.
do {
int hash = isolate->GenerateIdentityHash(Smi::kMaxValue);
masked_hash = hash & JSReceiver::kHashMask;
} while (masked_hash == PropertyArray::kNoHashSentinel);
int hash = isolate->GenerateIdentityHash(PropertyArray::HashField::kMax);
DCHECK_NE(PropertyArray::kNoHashSentinel, hash);

SetIdentityHash(masked_hash);
return Smi::FromInt(masked_hash);
SetIdentityHash(hash);
return Smi::FromInt(hash);
}

Object* JSProxy::GetIdentityHash() { return hash(); }
Expand Down
12 changes: 5 additions & 7 deletions deps/v8/src/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -1953,12 +1953,10 @@ class PropertyArray : public HeapObject {
// No weak fields.
typedef BodyDescriptor BodyDescriptorWeak;

static const int kLengthMask = 0x3ff;
static const int kHashMask = 0x7ffffc00;
STATIC_ASSERT(kLengthMask + kHashMask == 0x7fffffff);

static const int kMaxLength = kLengthMask;
STATIC_ASSERT(kMaxLength > kMaxNumberOfDescriptors);
static const int kLengthFieldSize = 10;
class LengthField : public BitField<int, 0, kLengthFieldSize> {};
class HashField : public BitField<int, kLengthFieldSize,
kSmiValueSize - kLengthFieldSize - 1> {};

static const int kNoHashSentinel = 0;

Expand Down Expand Up @@ -2185,7 +2183,7 @@ class JSReceiver: public HeapObject {
MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnEntries(
Handle<JSReceiver> object, PropertyFilter filter);

static const int kHashMask = PropertyArray::kHashMask;
static const int kHashMask = PropertyArray::HashField::kMask;

// Layout description.
static const int kPropertiesOrHashOffset = HeapObject::kHeaderSize;
Expand Down
10 changes: 6 additions & 4 deletions deps/v8/src/objects/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,16 @@ class BaseNameDictionary : public Dictionary<Derived, Shape> {
return Smi::ToInt(this->get(kNextEnumerationIndexIndex));
}

void SetHash(int masked_hash) {
DCHECK_EQ(masked_hash & JSReceiver::kHashMask, masked_hash);
this->set(kObjectHashIndex, Smi::FromInt(masked_hash));
void SetHash(int hash) {
DCHECK(PropertyArray::HashField::is_valid(hash));
this->set(kObjectHashIndex, Smi::FromInt(hash));
}

int Hash() const {
Object* hash_obj = this->get(kObjectHashIndex);
return Smi::ToInt(hash_obj);
int hash = Smi::ToInt(hash_obj);
DCHECK(PropertyArray::HashField::is_valid(hash));
return hash;
}

// Creates a new dictionary.
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/test/cctest/test-weakmaps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST(Regress2060a) {
Handle<JSObject> object = factory->NewJSObject(function, TENURED);
CHECK(!heap->InNewSpace(*object));
CHECK(!first_page->Contains(object->address()));
int32_t hash = object->GetOrCreateHash(isolate)->value();
int32_t hash = key->GetOrCreateHash(isolate)->value();
JSWeakCollection::Set(weakmap, key, object, hash);
}
}
Expand Down