Commit 9b4f836a authored by ishell's avatar ishell Committed by Commit bot

Revert of Extend HasProperty stub with dictionary-mode and double-elements...

Revert of Extend HasProperty stub with dictionary-mode and double-elements objects support. (patchset #8 id:280001 of https://codereview.chromium.org/1995453002/ )

Reason for revert:
There are crashes on Win32 and Win64 bots.

Original issue's description:
> Extend HasProperty stub with dictionary-mode, string wrapper and double-elements objects support.
>
> This CL also replaces some Branch() usages with GotoIf/GotoUnless.
>
> BUG=v8:2743
> LOG=Y
>
> Committed: https://crrev.com/24066b6df4259b302edfa1db884c479008776a7e
> Cr-Commit-Position: refs/heads/master@{#36657}

TBR=verwaest@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:2743

Review-Url: https://codereview.chromium.org/2028333002
Cr-Commit-Position: refs/heads/master@{#36659}
parent e60c4053
......@@ -58,14 +58,6 @@ Node* CodeStubAssembler::UndefinedConstant() {
return LoadRoot(Heap::kUndefinedValueRootIndex);
}
Node* CodeStubAssembler::TheHoleConstant() {
return LoadRoot(Heap::kTheHoleValueRootIndex);
}
Node* CodeStubAssembler::HashSeed() {
return SmiToWord32(LoadRoot(Heap::kHashSeedRootIndex));
}
Node* CodeStubAssembler::StaleRegisterConstant() {
return LoadRoot(Heap::kStaleRegisterRootIndex);
}
......@@ -493,10 +485,6 @@ Node* CodeStubAssembler::LoadInstanceType(Node* object) {
return LoadMapInstanceType(LoadMap(object));
}
Node* CodeStubAssembler::LoadProperties(Node* object) {
return LoadObjectField(object, JSObject::kPropertiesOffset);
}
Node* CodeStubAssembler::LoadElements(Node* object) {
return LoadObjectField(object, JSObject::kElementsOffset);
}
......@@ -533,35 +521,11 @@ Node* CodeStubAssembler::LoadMapPrototype(Node* map) {
return LoadObjectField(map, Map::kPrototypeOffset);
}
Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) {
return Load(MachineType::Uint8(), map,
IntPtrConstant(Map::kInstanceSizeOffset - kHeapObjectTag));
}
Node* CodeStubAssembler::LoadNameHashField(Node* name) {
Node* CodeStubAssembler::LoadNameHash(Node* name) {
return Load(MachineType::Uint32(), name,
IntPtrConstant(Name::kHashFieldOffset - kHeapObjectTag));
}
Node* CodeStubAssembler::LoadNameHash(Node* name, Label* if_hash_not_computed) {
Node* hash_field = LoadNameHashField(name);
if (if_hash_not_computed != nullptr) {
GotoIf(WordEqual(
Word32And(hash_field, Int32Constant(Name::kHashNotComputedMask)),
Int32Constant(0)),
if_hash_not_computed);
}
return Word32Shr(hash_field, Int32Constant(Name::kHashShift));
}
Node* CodeStubAssembler::LoadStringLength(Node* object) {
return LoadObjectField(object, String::kLengthOffset);
}
Node* CodeStubAssembler::LoadJSValueValue(Node* object) {
return LoadObjectField(object, JSValue::kValueOffset);
}
Node* CodeStubAssembler::AllocateUninitializedFixedArray(Node* length) {
Node* header_size = IntPtrConstant(FixedArray::kHeaderSize);
Node* data_size = WordShl(length, IntPtrConstant(kPointerSizeLog2));
......@@ -585,14 +549,9 @@ Node* CodeStubAssembler::LoadFixedArrayElement(Node* object, Node* index_node,
return Load(MachineType::AnyTagged(), object, offset);
}
Node* CodeStubAssembler::LoadFixedDoubleArrayElement(
Node* object, Node* index_node, MachineType machine_type,
int additional_offset, ParameterMode parameter_mode) {
int32_t header_size =
FixedDoubleArray::kHeaderSize + additional_offset - kHeapObjectTag;
Node* offset = ElementOffsetFromIndex(index_node, FAST_HOLEY_DOUBLE_ELEMENTS,
parameter_mode, header_size);
return Load(machine_type, object, offset);
Node* CodeStubAssembler::LoadMapInstanceSize(Node* map) {
return Load(MachineType::Uint8(), map,
IntPtrConstant(Map::kInstanceSizeOffset - kHeapObjectTag));
}
Node* CodeStubAssembler::LoadNativeContext(Node* context) {
......@@ -1434,7 +1393,7 @@ Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift,
void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
Variable* var_index, Label* if_keyisunique,
Label* if_bailout) {
Label* call_runtime) {
DCHECK_EQ(MachineRepresentation::kWord32, var_index->rep());
Label if_keyissmi(this), if_keyisnotsmi(this);
......@@ -1442,7 +1401,9 @@ void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
Bind(&if_keyissmi);
{
// Negative smi keys are named properties. Handle in the runtime.
GotoUnless(WordIsPositiveSmi(key), if_bailout);
Label if_keyispositive(this);
Branch(WordIsPositiveSmi(key), &if_keyispositive, call_runtime);
Bind(&if_keyispositive);
var_index->Bind(SmiToWord32(key));
Goto(if_keyisindex);
......@@ -1451,372 +1412,125 @@ void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
Bind(&if_keyisnotsmi);
Node* key_instance_type = LoadInstanceType(key);
// Symbols are unique.
GotoIf(Word32Equal(key_instance_type, Int32Constant(SYMBOL_TYPE)),
if_keyisunique);
Label if_keyisinternalized(this);
Node* bits =
WordAnd(key_instance_type,
Int32Constant(kIsNotStringMask | kIsNotInternalizedMask));
Branch(Word32Equal(bits, Int32Constant(kStringTag | kInternalizedTag)),
&if_keyisinternalized, if_bailout);
Bind(&if_keyisinternalized);
// Check whether the key is an array index passed in as string. Handle
// uniform with smi keys if so.
// TODO(verwaest): Also support non-internalized strings.
Node* hash = LoadNameHashField(key);
Node* bit = Word32And(hash, Int32Constant(Name::kIsNotArrayIndexMask));
GotoIf(Word32NotEqual(bit, Int32Constant(0)), if_keyisunique);
// Key is an index. Check if it is small enough to be encoded in the
// hash_field. Handle too big array index in runtime.
bit = Word32And(hash, Int32Constant(Name::kContainsCachedArrayIndexMask));
GotoIf(Word32NotEqual(bit, Int32Constant(0)), if_bailout);
var_index->Bind(BitFieldDecode<Name::ArrayIndexValueBits>(hash));
Goto(if_keyisindex);
}
template <typename Dictionary>
void CodeStubAssembler::NameDictionaryLookup(
Node* dictionary, Node* unique_name, Label* if_found_, Variable* var_entry,
Label* if_not_found, int inlined_probes) {
DCHECK_EQ(MachineRepresentation::kWord32, var_entry->rep());
// TODO(ishell): Remove this trampoline block once crbug/615621 is fixed.
// This trampoline block is currently necessary here to generate a correct
// phi for |var_entry|.
Label if_found(this, var_entry);
const int kElementsStartOffset =
Dictionary::kElementsStartIndex * kPointerSize;
Node* capacity = SmiToWord32(LoadFixedArrayElement(
dictionary, Int32Constant(Dictionary::kCapacityIndex)));
Node* mask = Int32Sub(capacity, Int32Constant(1));
Node* hash = LoadNameHash(unique_name);
// See Dictionary::FirstProbe().
Node* count = Int32Constant(0);
Node* entry = Word32And(hash, mask);
for (int i = 0; i < inlined_probes; i++) {
// See Dictionary::EntryToIndex()
Node* index = Int32Mul(entry, Int32Constant(Dictionary::kEntrySize));
Node* current =
LoadFixedArrayElement(dictionary, index, kElementsStartOffset);
var_entry->Bind(entry);
GotoIf(WordEqual(current, unique_name), &if_found);
// See Dictionary::NextProbe().
count = Int32Constant(i + 1);
entry = Word32And(Int32Add(entry, count), mask);
}
Node* undefined = UndefinedConstant();
Variable var_count(this, MachineRepresentation::kWord32);
Variable* loop_vars[] = {&var_count, var_entry};
Label loop(this, 2, loop_vars);
var_count.Bind(count);
var_entry->Bind(entry);
Goto(&loop);
Bind(&loop);
{
Node* count = var_count.value();
Node* entry = var_entry->value();
// See Dictionary::EntryToIndex()
Node* index = Int32Mul(entry, Int32Constant(Dictionary::kEntrySize));
Node* current =
LoadFixedArrayElement(dictionary, index, kElementsStartOffset);
GotoIf(WordEqual(current, undefined), if_not_found);
GotoIf(WordEqual(current, unique_name), &if_found);
// See Dictionary::NextProbe().
count = Int32Add(count, Int32Constant(1));
entry = Word32And(Int32Add(entry, count), mask);
var_count.Bind(count);
var_entry->Bind(entry);
Goto(&loop);
}
Bind(&if_found);
Goto(if_found_);
}
// Instantiate template methods to workaround GCC compilation issue.
template void CodeStubAssembler::NameDictionaryLookup<NameDictionary>(
Node*, Node*, Label*, Variable*, Label*, int);
template void CodeStubAssembler::NameDictionaryLookup<GlobalDictionary>(
Node*, Node*, Label*, Variable*, Label*, int);
Node* CodeStubAssembler::ComputeIntegerHash(Node* key, Node* seed) {
// See v8::internal::ComputeIntegerHash()
Node* hash = key;
hash = Word32Xor(hash, seed);
hash = Int32Add(Word32Xor(hash, Int32Constant(0xffffffff)),
Word32Shl(hash, Int32Constant(15)));
hash = Word32Xor(hash, Word32Shr(hash, Int32Constant(12)));
hash = Int32Add(hash, Word32Shl(hash, Int32Constant(2)));
hash = Word32Xor(hash, Word32Shr(hash, Int32Constant(4)));
hash = Int32Mul(hash, Int32Constant(2057));
hash = Word32Xor(hash, Word32Shr(hash, Int32Constant(16)));
return Word32And(hash, Int32Constant(0x3fffffff));
}
template <typename Dictionary>
void CodeStubAssembler::NumberDictionaryLookup(Node* dictionary, Node* key,
Label* if_found,
Variable* var_entry,
Label* if_not_found) {
DCHECK_EQ(MachineRepresentation::kWord32, var_entry->rep());
const int kElementsStartOffset =
Dictionary::kElementsStartIndex * kPointerSize;
Node* capacity = SmiToWord32(LoadFixedArrayElement(
dictionary, Int32Constant(Dictionary::kCapacityIndex)));
Node* mask = Int32Sub(capacity, Int32Constant(1));
Node* seed;
if (Dictionary::ShapeT::UsesSeed) {
seed = HashSeed();
} else {
seed = Int32Constant(kZeroHashSeed);
}
Node* hash = ComputeIntegerHash(key, seed);
Node* key_as_float64 = ChangeUint32ToFloat64(key);
// See Dictionary::FirstProbe().
Node* count = Int32Constant(0);
Node* entry = Word32And(hash, mask);
Node* undefined = UndefinedConstant();
Node* the_hole = TheHoleConstant();
Variable var_count(this, MachineRepresentation::kWord32);
Variable* loop_vars[] = {&var_count, var_entry};
Label loop(this, 2, loop_vars);
var_count.Bind(count);
var_entry->Bind(entry);
Goto(&loop);
Bind(&loop);
Label if_keyisnotsymbol(this);
Branch(Word32Equal(key_instance_type, Int32Constant(SYMBOL_TYPE)),
if_keyisunique, &if_keyisnotsymbol);
Bind(&if_keyisnotsymbol);
{
Node* count = var_count.value();
Node* entry = var_entry->value();
// See Dictionary::EntryToIndex()
Node* index = Int32Mul(entry, Int32Constant(Dictionary::kEntrySize));
Node* current =
LoadFixedArrayElement(dictionary, index, kElementsStartOffset);
GotoIf(WordEqual(current, undefined), if_not_found);
Label next_probe(this);
{
Label if_currentissmi(this), if_currentisnotsmi(this);
Branch(WordIsSmi(current), &if_currentissmi, &if_currentisnotsmi);
Bind(&if_currentissmi);
{
Node* current_value = SmiToWord32(current);
Branch(Word32Equal(current_value, key), if_found, &next_probe);
}
Bind(&if_currentisnotsmi);
{
GotoIf(WordEqual(current, the_hole), &next_probe);
// Current must be the Number.
Node* current_value = LoadHeapNumberValue(current);
Branch(Float64Equal(current_value, key_as_float64), if_found,
&next_probe);
}
}
Bind(&next_probe);
// See Dictionary::NextProbe().
count = Int32Add(count, Int32Constant(1));
entry = Word32And(Int32Add(entry, count), mask);
var_count.Bind(count);
var_entry->Bind(entry);
Goto(&loop);
Label if_keyisinternalized(this);
Node* bits =
WordAnd(key_instance_type,
Int32Constant(kIsNotStringMask | kIsNotInternalizedMask));
Branch(Word32Equal(bits, Int32Constant(kStringTag | kInternalizedTag)),
&if_keyisinternalized, call_runtime);
Bind(&if_keyisinternalized);
// Check whether the key is an array index passed in as string. Handle
// uniform with smi keys if so.
// TODO(verwaest): Also support non-internalized strings.
Node* hash = LoadNameHash(key);
Node* bit =
Word32And(hash, Int32Constant(internal::Name::kIsNotArrayIndexMask));
Label if_isarrayindex(this);
Branch(Word32Equal(bit, Int32Constant(0)), &if_isarrayindex,
if_keyisunique);
Bind(&if_isarrayindex);
var_index->Bind(BitFieldDecode<internal::Name::ArrayIndexValueBits>(hash));
Goto(if_keyisindex);
}
}
void CodeStubAssembler::TryLookupProperty(Node* object, Node* map,
Node* instance_type,
Node* unique_name, Label* if_found,
Label* if_not_found,
Label* if_bailout) {
Label if_objectisspecial(this);
STATIC_ASSERT(JS_GLOBAL_OBJECT_TYPE <= LAST_SPECIAL_RECEIVER_TYPE);
GotoIf(Int32LessThanOrEqual(instance_type,
Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)),
&if_objectisspecial);
Node* instance_type, Node* name,
Label* if_found, Label* if_not_found,
Label* call_runtime) {
{
Label if_objectissimple(this);
Branch(Int32LessThanOrEqual(instance_type,
Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)),
call_runtime, &if_objectissimple);
Bind(&if_objectissimple);
}
// TODO(verwaest): Perform a dictonary lookup on slow-mode receivers.
Node* bit_field3 = LoadMapBitField3(map);
Node* bit = BitFieldDecode<Map::DictionaryMap>(bit_field3);
Label if_isfastmap(this), if_isslowmap(this);
Branch(Word32Equal(bit, Int32Constant(0)), &if_isfastmap, &if_isslowmap);
Label if_isfastmap(this);
Branch(Word32Equal(bit, Int32Constant(0)), &if_isfastmap, call_runtime);
Bind(&if_isfastmap);
Node* nof = BitFieldDecode<Map::NumberOfOwnDescriptorsBits>(bit_field3);
// Bail out to the runtime for large numbers of own descriptors. The stub only
// does linear search, which becomes too expensive in that case.
{
Node* nof = BitFieldDecode<Map::NumberOfOwnDescriptorsBits>(bit_field3);
// Bail out to the runtime for large numbers of own descriptors. The stub
// only does linear search, which becomes too expensive in that case.
{
static const int32_t kMaxLinear = 210;
GotoIf(Int32GreaterThan(nof, Int32Constant(kMaxLinear)), if_bailout);
}
Node* descriptors = LoadMapDescriptors(map);
static const int32_t kMaxLinear = 210;
Label above_max(this), below_max(this);
Branch(Int32LessThanOrEqual(nof, Int32Constant(kMaxLinear)), &below_max,
call_runtime);
Bind(&below_max);
}
Node* descriptors = LoadMapDescriptors(map);
Variable var_descriptor(this, MachineRepresentation::kWord32);
Label loop(this, &var_descriptor);
var_descriptor.Bind(Int32Constant(0));
Goto(&loop);
Bind(&loop);
Variable var_descriptor(this, MachineRepresentation::kWord32);
Label loop(this, &var_descriptor);
var_descriptor.Bind(Int32Constant(0));
Goto(&loop);
Bind(&loop);
{
Node* index = var_descriptor.value();
Node* offset = Int32Constant(DescriptorArray::ToKeyIndex(0));
Node* factor = Int32Constant(DescriptorArray::kDescriptorSize);
Label if_notdone(this);
Branch(Word32Equal(index, nof), if_not_found, &if_notdone);
Bind(&if_notdone);
{
Node* index = var_descriptor.value();
Node* offset = Int32Constant(DescriptorArray::ToKeyIndex(0));
Node* factor = Int32Constant(DescriptorArray::kDescriptorSize);
GotoIf(Word32Equal(index, nof), if_not_found);
Node* array_index = Int32Add(offset, Int32Mul(index, factor));
Node* current = LoadFixedArrayElement(descriptors, array_index);
GotoIf(WordEqual(current, unique_name), if_found);
Label if_unequal(this);
Branch(WordEqual(current, name), if_found, &if_unequal);
Bind(&if_unequal);
var_descriptor.Bind(Int32Add(index, Int32Constant(1)));
Goto(&loop);
}
}
Bind(&if_isslowmap);
{
Variable var_entry(this, MachineRepresentation::kWord32);
Node* dictionary = LoadProperties(object);
NameDictionaryLookup<NameDictionary>(dictionary, unique_name, if_found,
&var_entry, if_not_found);
}
Bind(&if_objectisspecial);
{
// Handle global object here and other special objects in runtime.
GotoUnless(Word32Equal(instance_type, Int32Constant(JS_GLOBAL_OBJECT_TYPE)),
if_bailout);
Variable var_entry(this, MachineRepresentation::kWord32);
Node* dictionary = LoadProperties(object);
NameDictionaryLookup<GlobalDictionary>(dictionary, unique_name, if_found,
&var_entry, if_not_found);
}
}
void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
Node* instance_type, Node* index,
Label* if_found, Label* if_not_found,
Label* if_bailout) {
// Handle special objects in runtime.
GotoIf(Int32LessThanOrEqual(instance_type,
Int32Constant(LAST_SPECIAL_RECEIVER_TYPE)),
if_bailout);
Label* call_runtime) {
{
Label if_objectissimple(this);
Branch(Int32LessThanOrEqual(instance_type,
Int32Constant(LAST_CUSTOM_ELEMENTS_RECEIVER)),
call_runtime, &if_objectissimple);
Bind(&if_objectissimple);
}
Node* bit_field2 = LoadMapBitField2(map);
Node* elements_kind = BitFieldDecode<Map::ElementsKindBits>(bit_field2);
// TODO(verwaest): Support other elements kinds as well.
Label if_isobjectorsmi(this), if_isdouble(this), if_isdictionary(this),
if_isfaststringwrapper(this), if_isslowstringwrapper(this);
// clang-format off
int32_t values[] = {
// Handled by {if_isobjectorsmi}.
FAST_SMI_ELEMENTS, FAST_HOLEY_SMI_ELEMENTS, FAST_ELEMENTS,
FAST_HOLEY_ELEMENTS,
// Handled by {if_isdouble}.
FAST_DOUBLE_ELEMENTS, FAST_HOLEY_DOUBLE_ELEMENTS,
// Handled by {if_isdictionary}.
DICTIONARY_ELEMENTS,
// Handled by {if_isfaststringwrapper}.
FAST_STRING_WRAPPER_ELEMENTS,
// Handled by {if_isslowstringwrapper}.
SLOW_STRING_WRAPPER_ELEMENTS,
// Handled by {if_not_found}.
NO_ELEMENTS,
};
Label* labels[] = {
&if_isobjectorsmi, &if_isobjectorsmi, &if_isobjectorsmi,
&if_isobjectorsmi,
&if_isdouble, &if_isdouble,
&if_isdictionary,
&if_isfaststringwrapper,
&if_isslowstringwrapper,
if_not_found,
};
// clang-format on
STATIC_ASSERT(arraysize(values) == arraysize(labels));
Switch(elements_kind, if_bailout, values, labels, arraysize(values));
Label if_isobjectorsmi(this);
Branch(
Int32LessThanOrEqual(elements_kind, Int32Constant(FAST_HOLEY_ELEMENTS)),
&if_isobjectorsmi, call_runtime);
Bind(&if_isobjectorsmi);
{
Node* elements = LoadElements(object);
Node* length = LoadFixedArrayBaseLength(elements);
GotoIf(Int32GreaterThanOrEqual(index, SmiToWord32(length)), if_not_found);
Label if_iskeyinrange(this);
Branch(Int32LessThan(index, SmiToWord32(length)), &if_iskeyinrange,
if_not_found);
Bind(&if_iskeyinrange);
Node* element = LoadFixedArrayElement(elements, index);
Node* the_hole = TheHoleConstant();
Node* the_hole = LoadRoot(Heap::kTheHoleValueRootIndex);
Branch(WordEqual(element, the_hole), if_not_found, if_found);
}
Bind(&if_isdouble);
{
Node* elements = LoadElements(object);
Node* length = LoadFixedArrayBaseLength(elements);
GotoIf(Int32GreaterThanOrEqual(index, SmiToWord32(length)), if_not_found);
if (kPointerSize == kDoubleSize) {
Node* element =
LoadFixedDoubleArrayElement(elements, index, MachineType::Uint64());
Node* the_hole = Int64Constant(kHoleNanInt64);
Branch(Word64Equal(element, the_hole), if_not_found, if_found);
} else {
Node* element_upper =
LoadFixedDoubleArrayElement(elements, index, MachineType::Uint32(),
kIeeeDoubleExponentWordOffset);
Branch(Word32Equal(element_upper, Int32Constant(kHoleNanUpper32)),
if_not_found, if_found);
}
}
Bind(&if_isdictionary);
{
Variable var_entry(this, MachineRepresentation::kWord32);
Node* elements = LoadElements(object);
NumberDictionaryLookup<SeededNumberDictionary>(elements, index, if_found,
&var_entry, if_not_found);
}
Bind(&if_isfaststringwrapper);
{
Assert(Word32Equal(LoadInstanceType(object), Int32Constant(JS_VALUE_TYPE)));
Node* string = LoadJSValueValue(object);
Assert(Int32LessThan(LoadInstanceType(string),
Int32Constant(FIRST_NONSTRING_TYPE)));
Node* length = LoadStringLength(string);
GotoIf(Int32LessThan(index, SmiToWord32(length)), if_found);
Goto(&if_isobjectorsmi);
}
Bind(&if_isslowstringwrapper);
{
Assert(Word32Equal(LoadInstanceType(object), Int32Constant(JS_VALUE_TYPE)));
Node* string = LoadJSValueValue(object);
Assert(Int32LessThan(LoadInstanceType(string),
Int32Constant(FIRST_NONSTRING_TYPE)));
Node* length = LoadStringLength(string);
GotoIf(Int32LessThan(index, SmiToWord32(length)), if_found);
Goto(&if_isdictionary);
}
}
// Instantiate template methods to workaround GCC compilation issue.
template void CodeStubAssembler::NumberDictionaryLookup<SeededNumberDictionary>(
Node*, Node*, Label*, Variable*, Label*);
template void CodeStubAssembler::NumberDictionaryLookup<
UnseededNumberDictionary>(Node*, Node*, Label*, Variable*, Label*);
Node* CodeStubAssembler::OrdinaryHasInstance(Node* context, Node* callable,
Node* object) {
Variable var_result(this, MachineRepresentation::kTagged);
......
......@@ -40,8 +40,6 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* NoContextConstant();
compiler::Node* NullConstant();
compiler::Node* UndefinedConstant();
compiler::Node* TheHoleConstant();
compiler::Node* HashSeed();
compiler::Node* StaleRegisterConstant();
// Float64 operations.
......@@ -114,8 +112,6 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* LoadMap(compiler::Node* object);
// Load the instance type of an HeapObject.
compiler::Node* LoadInstanceType(compiler::Node* object);
// Load the properties backing store of a JSObject.
compiler::Node* LoadProperties(compiler::Node* object);
// Load the elements backing store of a JSObject.
compiler::Node* LoadElements(compiler::Node* object);
// Load the length of a fixed array base instance.
......@@ -132,20 +128,11 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* LoadMapDescriptors(compiler::Node* map);
// Load the prototype of a map.
compiler::Node* LoadMapPrototype(compiler::Node* map);
// Load the instance size of a Map.
compiler::Node* LoadMapInstanceSize(compiler::Node* map);
// Load the hash field of a name.
compiler::Node* LoadNameHashField(compiler::Node* name);
// Load the hash value of a name. If {if_hash_not_computed} label
// is specified then it also checks if hash is actually computed.
compiler::Node* LoadNameHash(compiler::Node* name,
Label* if_hash_not_computed = nullptr);
// Load length field of a String object.
compiler::Node* LoadStringLength(compiler::Node* object);
// Load value field of a JSValue object.
compiler::Node* LoadJSValueValue(compiler::Node* object);
compiler::Node* LoadNameHash(compiler::Node* name);
// Load the instance size of a Map.
compiler::Node* LoadMapInstanceSize(compiler::Node* map);
compiler::Node* AllocateUninitializedFixedArray(compiler::Node* length);
......@@ -154,11 +141,6 @@ class CodeStubAssembler : public compiler::CodeAssembler {
compiler::Node* object, compiler::Node* int32_index,
int additional_offset = 0,
ParameterMode parameter_mode = INTEGER_PARAMETERS);
// Load an array element from a FixedDoubleArray.
compiler::Node* LoadFixedDoubleArrayElement(
compiler::Node* object, compiler::Node* int32_index,
MachineType machine_type, int additional_offset = 0,
ParameterMode parameter_mode = INTEGER_PARAMETERS);
// Context manipulation
compiler::Node* LoadNativeContext(compiler::Node* context);
......@@ -248,31 +230,17 @@ class CodeStubAssembler : public compiler::CodeAssembler {
// Various building blocks for stubs doing property lookups.
void TryToName(compiler::Node* key, Label* if_keyisindex, Variable* var_index,
Label* if_keyisunique, Label* if_bailout);
static const int kInlinedDictionaryProbes = 4;
template <typename Dictionary>
void NameDictionaryLookup(compiler::Node* dictionary,
compiler::Node* unique_name, Label* if_found,
Variable* var_entry, Label* if_not_found,
int inlined_probes = kInlinedDictionaryProbes);
compiler::Node* ComputeIntegerHash(compiler::Node* key, compiler::Node* seed);
template <typename Dictionary>
void NumberDictionaryLookup(compiler::Node* dictionary, compiler::Node* key,
Label* if_found, Variable* var_entry,
Label* if_not_found);
Label* if_keyisunique, Label* call_runtime);
void TryLookupProperty(compiler::Node* object, compiler::Node* map,
compiler::Node* instance_type,
compiler::Node* unique_name, Label* if_found,
Label* if_not_found, Label* if_bailout);
compiler::Node* instance_type, compiler::Node* name,
Label* if_found, Label* if_not_found,
Label* call_runtime);
void TryLookupElement(compiler::Node* object, compiler::Node* map,
compiler::Node* instance_type, compiler::Node* index,
Label* if_found, Label* if_not_found,
Label* if_bailout);
Label* call_runtime);
// Instanceof helpers.
// ES6 section 7.3.19 OrdinaryHasInstance (C, O)
......
......@@ -644,15 +644,6 @@ union IeeeDoubleBigEndianArchType {
} bits;
};
#if V8_TARGET_LITTLE_ENDIAN
typedef IeeeDoubleLittleEndianArchType IeeeDoubleArchType;
const int kIeeeDoubleMantissaWordOffset = 0;
const int kIeeeDoubleExponentWordOffset = 4;
#else
typedef IeeeDoubleBigEndianArchType IeeeDoubleArchType;
const int kIeeeDoubleMantissaWordOffset = 4;
const int kIeeeDoubleExponentWordOffset = 0;
#endif
// AccessorCallback
struct AccessorDescriptor {
......
......@@ -380,7 +380,7 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT
case DICTIONARY_ELEMENTS:
case SLOW_STRING_WRAPPER_ELEMENTS:
SeededNumberDictionary::cast(elements())->Print(os);
elements()->Print(os);
break;
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
......
......@@ -11139,8 +11139,8 @@ uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) {
value |= length << String::ArrayIndexLengthBits::kShift;
DCHECK((value & String::kIsNotArrayIndexMask) == 0);
DCHECK_EQ(length <= String::kMaxCachedArrayIndexLength,
(value & String::kContainsCachedArrayIndexMask) == 0);
DCHECK((length > String::kMaxCachedArrayIndexLength) ||
(value & String::kContainsCachedArrayIndexMask) == 0);
return value;
}
......@@ -15170,11 +15170,6 @@ void Dictionary<Derived, Shape, Key>::Print(std::ostream& os) { // NOLINT
}
}
}
template <typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::Print() {
OFStream os(stdout);
Print(os);
}
#endif
......@@ -15906,7 +15901,15 @@ int NameDictionaryBase<Derived, Shape>::FindEntry(Handle<Name> key) {
Object* element = this->get(index);
if (element->IsUndefined()) break; // Empty entry.
if (*key == element) return entry;
DCHECK(element->IsTheHole() || element->IsUniqueName());
if (!element->IsUniqueName() &&
!element->IsTheHole() &&
Name::cast(element)->Equals(*key)) {
// Replace a key that is a non-internalized string by the equivalent
// internalized string for faster further lookups.
this->set(index, *key);
return entry;
}
DCHECK(element->IsTheHole() || !Name::cast(element)->Equals(*key));
entry = Derived::NextProbe(entry, count++, capacity);
}
return Derived::kNotFound;
......
......@@ -3189,8 +3189,6 @@ class HashTableBase : public FixedArray {
template <typename Derived, typename Shape, typename Key>
class HashTable : public HashTableBase {
public:
typedef Shape ShapeT;
// Wrapper methods
inline uint32_t Hash(Key key) {
if (Shape::UsesSeed) {
......@@ -3477,9 +3475,6 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key);
#ifdef OBJECT_PRINT
// For our gdb macros, we should perhaps change these in the future.
void Print();
void Print(std::ostream& os); // NOLINT
#endif
// Returns the key (slow).
......@@ -8575,10 +8570,6 @@ class Name: public HeapObject {
// Array index strings this short can keep their index in the hash field.
static const int kMaxCachedArrayIndexLength = 7;
// Maximum number of characters to consider when trying to convert a string
// value into an array index.
static const int kMaxArrayIndexSize = 10;
// For strings which are array indexes the hash value has the string length
// mixed into the hash, mainly to avoid a hash value of zero which would be
// the case for the string '0'. 24 bits are used for the array index value.
......@@ -8586,8 +8577,7 @@ class Name: public HeapObject {
static const int kArrayIndexLengthBits =
kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
STATIC_ASSERT(kArrayIndexLengthBits > 0);
STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
STATIC_ASSERT((kArrayIndexLengthBits > 0));
class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
kArrayIndexValueBits> {}; // NOLINT
......@@ -8677,6 +8667,34 @@ class String: public Name {
public:
enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING };
// Array index strings this short can keep their index in the hash field.
static const int kMaxCachedArrayIndexLength = 7;
// For strings which are array indexes the hash value has the string length
// mixed into the hash, mainly to avoid a hash value of zero which would be
// the case for the string '0'. 24 bits are used for the array index value.
static const int kArrayIndexValueBits = 24;
static const int kArrayIndexLengthBits =
kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
STATIC_ASSERT((kArrayIndexLengthBits > 0));
class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
kArrayIndexValueBits> {}; // NOLINT
class ArrayIndexLengthBits : public BitField<unsigned int,
kNofHashBitFields + kArrayIndexValueBits,
kArrayIndexLengthBits> {}; // NOLINT
// Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
// could use a mask to test if the length of string is less than or equal to
// kMaxCachedArrayIndexLength.
STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
static const unsigned int kContainsCachedArrayIndexMask =
(~static_cast<unsigned>(kMaxCachedArrayIndexLength)
<< ArrayIndexLengthBits::kShift) |
kIsNotArrayIndexMask;
class SubStringRange {
public:
explicit inline SubStringRange(String* string, int first = 0,
......@@ -8888,6 +8906,11 @@ class String: public Name {
static const int kLengthOffset = Name::kSize;
static const int kSize = kLengthOffset + kPointerSize;
// Maximum number of characters to consider when trying to convert a string
// value into an array index.
static const int kMaxArrayIndexSize = 10;
STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
// Max char codes.
static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar;
......
......@@ -430,8 +430,11 @@ void init_memcopy_functions(Isolate* isolate) {
bool DoubleToBoolean(double d) {
// NaN, +0, and -0 should return the false object
IeeeDoubleArchType u;
#if V8_TARGET_LITTLE_ENDIAN
union IeeeDoubleLittleEndianArchType u;
#else
union IeeeDoubleBigEndianArchType u;
#endif
u.d = d;
if (u.bits.exp == 2047) {
// Detect NaN for IEEE double precision floating point.
......
......@@ -19,6 +19,7 @@ executable("cctest") {
"compiler/graph-builder-tester.h",
"compiler/test-basic-block-profiler.cc",
"compiler/test-branch-combine.cc",
"compiler/test-code-stub-assembler.cc",
"compiler/test-gap-resolver.cc",
"compiler/test-graph-visualizer.cc",
"compiler/test-instruction.cc",
......@@ -92,7 +93,6 @@ executable("cctest") {
"test-bignum.cc",
"test-bit-vector.cc",
"test-circular-queue.cc",
"test-code-stub-assembler.cc",
"test-compiler.cc",
"test-constantpool.cc",
"test-conversions.cc",
......
......@@ -53,6 +53,7 @@
'compiler/graph-builder-tester.h',
'compiler/test-basic-block-profiler.cc',
'compiler/test-branch-combine.cc',
'compiler/test-code-stub-assembler.cc',
'compiler/test-gap-resolver.cc',
'compiler/test-graph-visualizer.cc',
'compiler/test-instruction.cc',
......@@ -128,7 +129,6 @@
'test-bignum-dtoa.cc',
'test-bit-vector.cc',
'test-circular-queue.cc',
'test-code-stub-assembler.cc',
'test-compiler.cc',
'test-constantpool.cc',
'test-conversions.cc',
......
......@@ -42,18 +42,16 @@ class FunctionTester : public InitializedHandleScope {
CompileGraph(graph);
}
FunctionTester(Handle<Code> code, int param_count)
FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code)
: isolate(main_isolate()),
function((FLAG_allow_natives_syntax = true,
NewFunction(BuildFunction(param_count).c_str()))),
function(
(FLAG_allow_natives_syntax = true,
NewFunction(BuildFunctionFromDescriptor(descriptor).c_str()))),
flags_(0) {
Compile(function);
function->ReplaceCode(*code);
}
FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code)
: FunctionTester(code, descriptor.GetParameterCount()) {}
Isolate* isolate;
Handle<JSFunction> function;
......@@ -66,12 +64,6 @@ class FunctionTester : public InitializedHandleScope {
return Execution::Call(isolate, function, undefined(), 2, args);
}
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b,
Handle<Object> c) {
Handle<Object> args[] = {a, b, c};
return Execution::Call(isolate, function, undefined(), 3, args);
}
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b, Handle<Object> c,
Handle<Object> d) {
Handle<Object> args[] = {a, b, c, d};
......@@ -99,56 +91,41 @@ class FunctionTester : public InitializedHandleScope {
return try_catch.Message();
}
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
Handle<Object> c, Handle<Object> d) {
Handle<Object> result = Call(a, b, c, d).ToHandleChecked();
CHECK(expected->SameValue(*result));
}
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b,
Handle<Object> c) {
return CheckCall(expected, a, b, c, undefined());
}
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
return CheckCall(expected, a, b, undefined());
Handle<Object> result = Call(a, b).ToHandleChecked();
CHECK(expected->SameValue(*result));
}
void CheckCall(Handle<Object> expected, Handle<Object> a) {
CheckCall(expected, a, undefined());
}
void CheckCall(Handle<Object> expected) { CheckCall(expected, undefined()); }
void CheckCall(Handle<Object> expected) {
CheckCall(expected, undefined(), undefined());
}
void CheckCall(double expected, double a, double b) {
CheckCall(Val(expected), Val(a), Val(b));
}
void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a); }
void CheckTrue(Handle<Object> a, Handle<Object> b) {
CheckCall(true_value(), a, b);
}
void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c) {
CheckCall(true_value(), a, b, c);
}
void CheckTrue(Handle<Object> a, Handle<Object> b, Handle<Object> c,
Handle<Object> d) {
CheckCall(true_value(), a, b, c, d);
}
void CheckTrue(Handle<Object> a) { CheckCall(true_value(), a, undefined()); }
void CheckTrue(double a, double b) {
CheckCall(true_value(), Val(a), Val(b));
}
void CheckFalse(Handle<Object> a) { CheckCall(false_value(), a); }
void CheckFalse(Handle<Object> a, Handle<Object> b) {
CheckCall(false_value(), a, b);
}
void CheckFalse(Handle<Object> a) {
CheckCall(false_value(), a, undefined());
}
void CheckFalse(double a, double b) {
CheckCall(false_value(), Val(a), Val(b));
}
......@@ -240,6 +217,11 @@ class FunctionTester : public InitializedHandleScope {
return function_string;
}
std::string BuildFunctionFromDescriptor(
const CallInterfaceDescriptor& descriptor) {
return BuildFunction(descriptor.GetParameterCount());
}
// Compile the given machine graph instead of the source of the function
// and replace the JSFunction's code with the result.
Handle<JSFunction> CompileGraph(Graph* graph) {
......
......@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/utils/random-number-generator.h"
#include "src/interface-descriptors.h"
#include "src/isolate.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
using compiler::FunctionTester;
using compiler::Node;
class CodeStubAssemblerTester : public CodeStubAssembler {
public:
......@@ -20,22 +18,20 @@ class CodeStubAssemblerTester : public CodeStubAssembler {
const CallInterfaceDescriptor& descriptor)
: CodeStubAssembler(isolate, isolate->runtime_zone(), descriptor,
Code::ComputeFlags(Code::STUB), "test"),
zone_scope_(isolate->runtime_zone()),
scope_(isolate) {}
// Test generating code for a JS function (e.g. builtins).
CodeStubAssemblerTester(Isolate* isolate, int parameter_count)
: CodeStubAssembler(isolate, isolate->runtime_zone(), parameter_count,
Code::ComputeFlags(Code::FUNCTION), "test"),
zone_scope_(isolate->runtime_zone()),
scope_(isolate) {}
private:
ZoneScope zone_scope_;
HandleScope scope_;
LocalContext context_;
};
TEST(SimpleSmiReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -47,6 +43,7 @@ TEST(SimpleSmiReturn) {
CHECK_EQ(37, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleIntPtrReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -60,6 +57,7 @@ TEST(SimpleIntPtrReturn) {
reinterpret_cast<intptr_t>(*result.ToHandleChecked()));
}
TEST(SimpleDoubleReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -71,6 +69,7 @@ TEST(SimpleDoubleReturn) {
CHECK_EQ(0.5, Handle<HeapNumber>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -84,6 +83,7 @@ TEST(SimpleCallRuntime1Arg) {
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -97,6 +97,7 @@ TEST(SimpleTailCallRuntime1Arg) {
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -111,6 +112,7 @@ TEST(SimpleCallRuntime2Arg) {
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
......@@ -387,673 +389,6 @@ TEST(TestToConstant) {
CHECK(!m.ToInt64Constant(a, value64));
}
TEST(ComputeIntegerHash) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 2;
CodeStubAssemblerTester m(isolate, param_count);
m.Return(m.SmiFromWord32(m.ComputeIntegerHash(
m.SmiToWord32(m.Parameter(0)), m.SmiToWord32(m.Parameter(1)))));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count);
Handle<Smi> hash_seed = isolate->factory()->hash_seed();
base::RandomNumberGenerator rand_gen(FLAG_random_seed);
for (int i = 0; i < 1024; i++) {
int k = rand_gen.NextInt(Smi::kMaxValue);
Handle<Smi> key(Smi::FromInt(k), isolate);
Handle<Object> result = ft.Call(key, hash_seed).ToHandleChecked();
uint32_t hash = ComputeIntegerHash(k, hash_seed->value());
Smi* expected = Smi::FromInt(hash & Smi::kMaxValue);
CHECK_EQ(expected, Smi::cast(*result));
}
}
TEST(TryToName) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 3;
CodeStubAssemblerTester m(isolate, param_count);
enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
{
Node* key = m.Parameter(0);
Node* expected_result = m.Parameter(1);
Node* expected_arg = m.Parameter(2);
Label passed(&m), failed(&m);
Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m);
Variable var_index(&m, MachineRepresentation::kWord32);
m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &if_bailout);
m.Bind(&if_keyisindex);
m.GotoUnless(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsIndex))),
&failed);
m.Branch(m.Word32Equal(m.SmiToWord32(expected_arg), var_index.value()),
&passed, &failed);
m.Bind(&if_keyisunique);
m.GotoUnless(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsUnique))),
&failed);
m.Branch(m.WordEqual(expected_arg, key), &passed, &failed);
m.Bind(&if_bailout);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
&passed, &failed);
m.Bind(&passed);
m.Return(m.BooleanConstant(true));
m.Bind(&failed);
m.Return(m.BooleanConstant(false));
}
Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count);
Handle<Object> expect_index(Smi::FromInt(kKeyIsIndex), isolate);
Handle<Object> expect_unique(Smi::FromInt(kKeyIsUnique), isolate);
Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
{
// TryToName(<zero smi>) => if_keyisindex: smi value.
Handle<Object> key(Smi::FromInt(0), isolate);
ft.CheckTrue(key, expect_index, key);
}
{
// TryToName(<positive smi>) => if_keyisindex: smi value.
Handle<Object> key(Smi::FromInt(153), isolate);
ft.CheckTrue(key, expect_index, key);
}
{
// TryToName(<negative smi>) => bailout.
Handle<Object> key(Smi::FromInt(-1), isolate);
ft.CheckTrue(key, expect_bailout);
}
{
// TryToName(<symbol>) => if_keyisunique: <symbol>.
Handle<Object> key = isolate->factory()->NewSymbol();
ft.CheckTrue(key, expect_unique, key);
}
{
// TryToName(<internalized string>) => if_keyisunique: <internalized string>
Handle<Object> key = isolate->factory()->InternalizeUtf8String("test");
ft.CheckTrue(key, expect_unique, key);
}
{
// TryToName(<internalized number string>) => if_keyisindex: number.
Handle<Object> key = isolate->factory()->InternalizeUtf8String("153");
Handle<Object> index(Smi::FromInt(153), isolate);
ft.CheckTrue(key, expect_index, index);
}
{
// TryToName(<non-internalized string>) => bailout.
Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test");
ft.CheckTrue(key, expect_bailout);
}
}
namespace {
template <typename Dictionary>
void TestNameDictionaryLookup() {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4;
CodeStubAssemblerTester m(isolate, param_count);
enum Result { kFound, kNotFound };
{
Node* dictionary = m.Parameter(0);
Node* unique_name = m.Parameter(1);
Node* expected_result = m.Parameter(2);
Node* expected_arg = m.Parameter(3);
Label passed(&m), failed(&m);
Label if_found(&m), if_not_found(&m);
Variable var_entry(&m, MachineRepresentation::kWord32);
m.NameDictionaryLookup<Dictionary>(dictionary, unique_name, &if_found,
&var_entry, &if_not_found);
m.Bind(&if_found);
m.GotoUnless(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))),
&failed);
m.Branch(m.Word32Equal(m.SmiToWord32(expected_arg), var_entry.value()),
&passed, &failed);
m.Bind(&if_not_found);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
&passed, &failed);
m.Bind(&passed);
m.Return(m.BooleanConstant(true));
m.Bind(&failed);
m.Return(m.BooleanConstant(false));
}
Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
Handle<Dictionary> dictionary = Dictionary::New(isolate, 40);
PropertyDetails fake_details = PropertyDetails::Empty();
Factory* factory = isolate->factory();
Handle<Name> keys[] = {
factory->InternalizeUtf8String("0"),
factory->InternalizeUtf8String("42"),
factory->InternalizeUtf8String("-153"),
factory->InternalizeUtf8String("0.0"),
factory->InternalizeUtf8String("4.2"),
factory->InternalizeUtf8String(""),
factory->InternalizeUtf8String("name"),
factory->NewSymbol(),
factory->NewPrivateSymbol(),
};
for (size_t i = 0; i < arraysize(keys); i++) {
Handle<Object> value = factory->NewPropertyCell();
dictionary = Dictionary::Add(dictionary, keys[i], value, fake_details);
}
for (size_t i = 0; i < arraysize(keys); i++) {
int entry = dictionary->FindEntry(keys[i]);
CHECK_NE(Dictionary::kNotFound, entry);
Handle<Object> expected_entry(Smi::FromInt(entry), isolate);
ft.CheckTrue(dictionary, keys[i], expect_found, expected_entry);
}
Handle<Name> non_existing_keys[] = {
factory->InternalizeUtf8String("1"),
factory->InternalizeUtf8String("-42"),
factory->InternalizeUtf8String("153"),
factory->InternalizeUtf8String("-1.0"),
factory->InternalizeUtf8String("1.3"),
factory->InternalizeUtf8String("a"),
factory->InternalizeUtf8String("boom"),
factory->NewSymbol(),
factory->NewPrivateSymbol(),
};
for (size_t i = 0; i < arraysize(non_existing_keys); i++) {
int entry = dictionary->FindEntry(non_existing_keys[i]);
CHECK_EQ(Dictionary::kNotFound, entry);
ft.CheckTrue(dictionary, non_existing_keys[i], expect_not_found);
}
}
} // namespace
TEST(NameDictionaryLookup) { TestNameDictionaryLookup<NameDictionary>(); }
TEST(GlobalDictionaryLookup) { TestNameDictionaryLookup<GlobalDictionary>(); }
namespace {
template <typename Dictionary>
void TestNumberDictionaryLookup() {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4;
CodeStubAssemblerTester m(isolate, param_count);
enum Result { kFound, kNotFound };
{
Node* dictionary = m.Parameter(0);
Node* key = m.SmiToWord32(m.Parameter(1));
Node* expected_result = m.Parameter(2);
Node* expected_arg = m.Parameter(3);
Label passed(&m), failed(&m);
Label if_found(&m), if_not_found(&m);
Variable var_entry(&m, MachineRepresentation::kWord32);
m.NumberDictionaryLookup<Dictionary>(dictionary, key, &if_found, &var_entry,
&if_not_found);
m.Bind(&if_found);
m.GotoUnless(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))),
&failed);
m.Branch(m.Word32Equal(m.SmiToWord32(expected_arg), var_entry.value()),
&passed, &failed);
m.Bind(&if_not_found);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
&passed, &failed);
m.Bind(&passed);
m.Return(m.BooleanConstant(true));
m.Bind(&failed);
m.Return(m.BooleanConstant(false));
}
Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
const int kKeysCount = 1000;
Handle<Dictionary> dictionary = Dictionary::New(isolate, kKeysCount);
uint32_t keys[kKeysCount];
Handle<Object> fake_value(Smi::FromInt(42), isolate);
PropertyDetails fake_details = PropertyDetails::Empty();
base::RandomNumberGenerator rand_gen(FLAG_random_seed);
for (int i = 0; i < kKeysCount; i++) {
int random_key = rand_gen.NextInt(Smi::kMaxValue);
keys[i] = static_cast<uint32_t>(random_key);
dictionary = Dictionary::Add(dictionary, keys[i], fake_value, fake_details);
}
// Now try querying existing keys.
for (int i = 0; i < kKeysCount; i++) {
int entry = dictionary->FindEntry(keys[i]);
CHECK_NE(Dictionary::kNotFound, entry);
Handle<Object> key(Smi::FromInt(keys[i]), isolate);
Handle<Object> expected_entry(Smi::FromInt(entry), isolate);
ft.CheckTrue(dictionary, key, expect_found, expected_entry);
}
// Now try querying random keys which do not exist in the dictionary.
for (int i = 0; i < kKeysCount;) {
int random_key = rand_gen.NextInt(Smi::kMaxValue);
int entry = dictionary->FindEntry(random_key);
if (entry != Dictionary::kNotFound) continue;
i++;
Handle<Object> key(Smi::FromInt(random_key), isolate);
ft.CheckTrue(dictionary, key, expect_not_found);
}
}
} // namespace
TEST(SeededNumberDictionaryLookup) {
TestNumberDictionaryLookup<SeededNumberDictionary>();
}
TEST(UnseededNumberDictionaryLookup) {
TestNumberDictionaryLookup<UnseededNumberDictionary>();
}
namespace {
void AddProperties(Handle<JSObject> object, Handle<Name> names[],
size_t count) {
Handle<Object> value(Smi::FromInt(42), object->GetIsolate());
for (size_t i = 0; i < count; i++) {
JSObject::AddProperty(object, names[i], value, NONE);
}
}
} // namespace
TEST(TryLookupProperty) {
typedef CodeStubAssembler::Label Label;
Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4;
CodeStubAssemblerTester m(isolate, param_count);
enum Result { kFound, kNotFound, kBailout };
{
Node* object = m.Parameter(0);
Node* unique_name = m.Parameter(1);
Node* expected_result = m.Parameter(2);
Label passed(&m), failed(&m);
Label if_found(&m), if_not_found(&m), if_bailout(&m);
Node* map = m.LoadMap(object);
Node* instance_type = m.LoadMapInstanceType(map);
m.TryLookupProperty(object, map, instance_type, unique_name, &if_found,
&if_not_found, &if_bailout);
m.Bind(&if_found);
m.Branch(m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))),
&passed, &failed);
m.Bind(&if_not_found);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
&passed, &failed);
m.Bind(&if_bailout);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
&passed, &failed);
m.Bind(&passed);
m.Return(m.BooleanConstant(true));
m.Bind(&failed);
m.Return(m.BooleanConstant(false));
}
Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
Factory* factory = isolate->factory();
Handle<Name> names[] = {
factory->InternalizeUtf8String("a"),
factory->InternalizeUtf8String("bb"),
factory->InternalizeUtf8String("ccc"),
factory->InternalizeUtf8String("dddd"),
factory->InternalizeUtf8String("eeeee"),
factory->InternalizeUtf8String(""),
factory->InternalizeUtf8String("name"),
factory->NewSymbol(),
factory->NewPrivateSymbol(),
};
std::vector<Handle<JSObject>> objects;
{
Handle<JSFunction> function = factory->NewFunction(factory->empty_string());
Handle<JSObject> object = factory->NewJSObject(function);
AddProperties(object, names, arraysize(names));
CHECK_EQ(JS_OBJECT_TYPE, object->map()->instance_type());
CHECK(!object->map()->is_dictionary_map());
objects.push_back(object);
}
{
Handle<JSFunction> function = factory->NewFunction(factory->empty_string());
Handle<JSObject> object = factory->NewJSObject(function);
AddProperties(object, names, arraysize(names));
JSObject::NormalizeProperties(object, CLEAR_INOBJECT_PROPERTIES, 0, "test");
CHECK_EQ(JS_OBJECT_TYPE, object->map()->instance_type());
CHECK(object->map()->is_dictionary_map());
objects.push_back(object);
}
{
Handle<JSFunction> function = factory->NewFunction(factory->empty_string());
JSFunction::EnsureHasInitialMap(function);
function->initial_map()->set_instance_type(JS_GLOBAL_OBJECT_TYPE);
function->initial_map()->set_is_prototype_map(true);
function->initial_map()->set_dictionary_map(true);
Handle<JSObject> object = factory->NewJSGlobalObject(function);
AddProperties(object, names, arraysize(names));
CHECK_EQ(JS_GLOBAL_OBJECT_TYPE, object->map()->instance_type());
CHECK(object->map()->is_dictionary_map());
objects.push_back(object);
}
{
for (Handle<JSObject> object : objects) {
for (size_t name_index = 0; name_index < arraysize(names); name_index++) {
Handle<Name> name = names[name_index];
CHECK(JSReceiver::HasProperty(object, name).FromJust());
ft.CheckTrue(object, name, expect_found);
}
}
}
{
Handle<Name> non_existing_names[] = {
factory->InternalizeUtf8String("ne_a"),
factory->InternalizeUtf8String("ne_bb"),
factory->InternalizeUtf8String("ne_ccc"),
factory->InternalizeUtf8String("ne_dddd"),
};
for (Handle<JSObject> object : objects) {
for (size_t key_index = 0; key_index < arraysize(non_existing_names);
key_index++) {
Handle<Name> key = non_existing_names[key_index];
CHECK(!JSReceiver::HasProperty(object, key).FromJust());
ft.CheckTrue(object, key, expect_not_found);
}
}
}
{
Handle<JSFunction> function = factory->NewFunction(factory->empty_string());
Handle<JSProxy> object = factory->NewJSProxy(function, objects[0]);
CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type());
ft.CheckTrue(object, names[0], expect_bailout);
}
{
Handle<JSObject> object = isolate->global_proxy();
CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type());
ft.CheckTrue(object, names[0], expect_bailout);
}
}
namespace {
void AddElement(Handle<JSObject> object, uint32_t index, Handle<Object> value,
PropertyAttributes attributes = NONE) {
JSObject::AddDataElement(object, index, value, attributes).ToHandleChecked();
}
} // namespace
TEST(TryLookupElement) {
typedef CodeStubAssembler::Label Label;
Isolate* isolate(CcTest::InitIsolateOnce());
const int param_count = 4;
CodeStubAssemblerTester m(isolate, param_count);
enum Result { kFound, kNotFound, kBailout };
{
Node* object = m.Parameter(0);
Node* index = m.SmiToWord32(m.Parameter(1));
Node* expected_result = m.Parameter(2);
Label passed(&m), failed(&m);
Label if_found(&m), if_not_found(&m), if_bailout(&m);
Node* map = m.LoadMap(object);
Node* instance_type = m.LoadMapInstanceType(map);
m.TryLookupElement(object, map, instance_type, index, &if_found,
&if_not_found, &if_bailout);
m.Bind(&if_found);
m.Branch(m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kFound))),
&passed, &failed);
m.Bind(&if_not_found);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kNotFound))),
&passed, &failed);
m.Bind(&if_bailout);
m.Branch(
m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
&passed, &failed);
m.Bind(&passed);
m.Return(m.BooleanConstant(true));
m.Bind(&failed);
m.Return(m.BooleanConstant(false));
}
Handle<Code> code = m.GenerateCode();
FunctionTester ft(code, param_count);
Factory* factory = isolate->factory();
Handle<Object> smi0(Smi::FromInt(0), isolate);
Handle<Object> smi1(Smi::FromInt(1), isolate);
Handle<Object> smi7(Smi::FromInt(7), isolate);
Handle<Object> smi13(Smi::FromInt(13), isolate);
Handle<Object> smi42(Smi::FromInt(42), isolate);
Handle<Object> expect_found(Smi::FromInt(kFound), isolate);
Handle<Object> expect_not_found(Smi::FromInt(kNotFound), isolate);
Handle<Object> expect_bailout(Smi::FromInt(kBailout), isolate);
#define CHECK_FOUND(object, index) \
CHECK(JSReceiver::HasElement(object, index).FromJust()); \
ft.CheckTrue(object, smi##index, expect_found);
#define CHECK_NOT_FOUND(object, index) \
CHECK(!JSReceiver::HasElement(object, index).FromJust()); \
ft.CheckTrue(object, smi##index, expect_not_found);
{
Handle<JSArray> object = factory->NewJSArray(0, FAST_SMI_ELEMENTS);
AddElement(object, 0, smi0);
AddElement(object, 1, smi0);
CHECK_EQ(FAST_SMI_ELEMENTS, object->map()->elements_kind());
CHECK_FOUND(object, 0);
CHECK_FOUND(object, 1);
CHECK_NOT_FOUND(object, 7);
CHECK_NOT_FOUND(object, 13);
CHECK_NOT_FOUND(object, 42);
}
{
Handle<JSArray> object = factory->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
AddElement(object, 0, smi0);
AddElement(object, 13, smi0);
CHECK_EQ(FAST_HOLEY_SMI_ELEMENTS, object->map()->elements_kind());
CHECK_FOUND(object, 0);
CHECK_NOT_FOUND(object, 1);
CHECK_NOT_FOUND(object, 7);
CHECK_FOUND(object, 13);
CHECK_NOT_FOUND(object, 42);
}
{
Handle<JSArray> object = factory->NewJSArray(0, FAST_ELEMENTS);
AddElement(object, 0, smi0);
AddElement(object, 1, smi0);
CHECK_EQ(FAST_ELEMENTS, object->map()->elements_kind());
CHECK_FOUND(object, 0);
CHECK_FOUND(object, 1);
CHECK_NOT_FOUND(object, 7);
CHECK_NOT_FOUND(object, 13);
CHECK_NOT_FOUND(object, 42);
}
{
Handle<JSArray> object = factory->NewJSArray(0, FAST_HOLEY_ELEMENTS);
AddElement(object, 0, smi0);
AddElement(object, 13, smi0);
CHECK_EQ(FAST_HOLEY_ELEMENTS, object->map()->elements_kind());
CHECK_FOUND(object, 0);
CHECK_NOT_FOUND(object, 1);
CHECK_NOT_FOUND(object, 7);
CHECK_FOUND(object, 13);
CHECK_NOT_FOUND(object, 42);
}
{
Handle<JSFunction> constructor = isolate->string_function();
Handle<JSObject> object = factory->NewJSObject(constructor);
Handle<String> str = factory->InternalizeUtf8String("ab");
Handle<JSValue>::cast(object)->set_value(*str);
AddElement(object, 13, smi0);
CHECK_EQ(FAST_STRING_WRAPPER_ELEMENTS, object->map()->elements_kind());
CHECK_FOUND(object, 0);
CHECK_FOUND(object, 1);
CHECK_NOT_FOUND(object, 7);
CHECK_FOUND(object, 13);
CHECK_NOT_FOUND(object, 42);
}
{
Handle<JSFunction> constructor = isolate->string_function();
Handle<JSObject> object = factory->NewJSObject(constructor);
Handle<String> str = factory->InternalizeUtf8String("ab");
Handle<JSValue>::cast(object)->set_value(*str);
AddElement(object, 13, smi0);
JSObject::NormalizeElements(object);
CHECK_EQ(SLOW_STRING_WRAPPER_ELEMENTS, object->map()->elements_kind());
CHECK_FOUND(object, 0);
CHECK_FOUND(object, 1);
CHECK_NOT_FOUND(object, 7);
CHECK_FOUND(object, 13);
CHECK_NOT_FOUND(object, 42);
}
// TODO(ishell): uncomment once NO_ELEMENTS kind is supported.
// {
// Handle<Map> map = Map::Create(isolate, 0);
// map->set_elements_kind(NO_ELEMENTS);
// Handle<JSObject> object = factory->NewJSObjectFromMap(map);
// CHECK_EQ(NO_ELEMENTS, object->map()->elements_kind());
//
// CHECK_NOT_FOUND(object, 0);
// CHECK_NOT_FOUND(object, 1);
// CHECK_NOT_FOUND(object, 7);
// CHECK_NOT_FOUND(object, 13);
// CHECK_NOT_FOUND(object, 42);
// }
#undef CHECK_FOUND
#undef CHECK_NOT_FOUND
{
Handle<JSArray> handler = factory->NewJSArray(0);
Handle<JSFunction> function = factory->NewFunction(factory->empty_string());
Handle<JSProxy> object = factory->NewJSProxy(function, handler);
CHECK_EQ(JS_PROXY_TYPE, object->map()->instance_type());
ft.CheckTrue(object, smi0, expect_bailout);
}
{
Handle<JSObject> object = isolate->global_object();
CHECK_EQ(JS_GLOBAL_OBJECT_TYPE, object->map()->instance_type());
ft.CheckTrue(object, smi0, expect_bailout);
}
{
Handle<JSObject> object = isolate->global_proxy();
CHECK_EQ(JS_GLOBAL_PROXY_TYPE, object->map()->instance_type());
ft.CheckTrue(object, smi0, expect_bailout);
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
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