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}
This commit is contained in:
ishell 2016-06-01 14:08:22 -07:00 committed by Commit bot
parent e60c4053c7
commit 9b4f836a2d
12 changed files with 560 additions and 1541 deletions

View File

@ -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);
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();
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);
// 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);
{
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);
// 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);

View File

@ -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)

View File

@ -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 {

View File

@ -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: {

View File

@ -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;

View File

@ -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;

View File

@ -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.

View File

@ -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",

View File

@ -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',

View File

@ -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) {

View File

@ -0,0 +1,394 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/interface-descriptors.h"
#include "src/isolate.h"
#include "test/cctest/compiler/function-tester.h"
namespace v8 {
namespace internal {
namespace compiler {
class CodeStubAssemblerTester : public CodeStubAssembler {
public:
// Test generating code for a stub.
CodeStubAssemblerTester(Isolate* isolate,
const CallInterfaceDescriptor& descriptor)
: CodeStubAssembler(isolate, isolate->runtime_zone(), descriptor,
Code::ComputeFlags(Code::STUB), "test"),
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"),
scope_(isolate) {}
private:
HandleScope scope_;
LocalContext context_;
};
TEST(SimpleSmiReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
m.Return(m.SmiTag(m.Int32Constant(37)));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(37, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleIntPtrReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
int test;
m.Return(m.IntPtrConstant(reinterpret_cast<intptr_t>(&test)));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(reinterpret_cast<intptr_t>(&test),
reinterpret_cast<intptr_t>(*result.ToHandleChecked()));
}
TEST(SimpleDoubleReturn) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
m.Return(m.NumberConstant(0.5));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0.5, Handle<HeapNumber>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* b = m.SmiTag(m.Int32Constant(0));
m.Return(m.CallRuntime(Runtime::kNumberToSmi, context, b));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime1Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* b = m.SmiTag(m.Int32Constant(0));
m.TailCallRuntime(Runtime::kNumberToSmi, context, b);
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(0, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* a = m.SmiTag(m.Int32Constant(2));
Node* b = m.SmiTag(m.Int32Constant(4));
m.Return(m.CallRuntime(Runtime::kMathPow, context, a, b));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SimpleTailCallRuntime2Arg) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
Node* a = m.SmiTag(m.Int32Constant(2));
Node* b = m.SmiTag(m.Int32Constant(4));
m.TailCallRuntime(Runtime::kMathPow, context, a, b);
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(16, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(VariableMerge1) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&merge);
CHECK_EQ(var1.value(), temp);
}
TEST(VariableMerge2) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&merge);
CHECK_NE(var1.value(), temp);
}
TEST(VariableMerge3) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
var2.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&merge);
CHECK_NE(var1.value(), temp);
CHECK_NE(var1.value(), temp2);
CHECK_EQ(var2.value(), temp);
}
TEST(VariableMergeBindFirst) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
m.Bind(&l1);
CHECK_EQ(var1.value(), temp);
m.Goto(&merge);
m.Bind(&merge);
CHECK(var1.value() != temp);
CHECK(var1.value() != nullptr);
m.Goto(&end);
m.Bind(&l2);
Node* temp2 = m.Int32Constant(2);
var1.Bind(temp2);
CHECK_EQ(var1.value(), temp2);
m.Goto(&merge);
m.Bind(&end);
CHECK(var1.value() != temp);
CHECK(var1.value() != nullptr);
}
TEST(VariableMergeSwitch) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
m.Bind(&l2);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
m.Bind(&default_label);
DCHECK_EQ(temp, var1.value());
m.Return(temp);
}
TEST(FixedArrayAccessSmiIndex) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Handle<FixedArray> array = isolate->factory()->NewFixedArray(5);
array->set(4, Smi::FromInt(733));
m.Return(m.LoadFixedArrayElement(m.HeapConstant(array),
m.SmiTag(m.Int32Constant(4)), 0,
CodeStubAssembler::SMI_PARAMETERS));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(733, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(LoadHeapNumberValue) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Handle<HeapNumber> number = isolate->factory()->NewHeapNumber(1234);
m.Return(m.SmiTag(
m.ChangeFloat64ToUint32(m.LoadHeapNumberValue(m.HeapConstant(number)))));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(1234, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(LoadInstanceType) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
Handle<HeapObject> undefined = isolate->factory()->undefined_value();
m.Return(m.SmiTag(m.LoadInstanceType(m.HeapConstant(undefined))));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
CHECK_EQ(InstanceType::ODDBALL_TYPE,
Handle<Smi>::cast(result.ToHandleChecked())->value());
}
namespace {
class TestBitField : public BitField<unsigned, 3, 3> {};
} // namespace
TEST(BitFieldDecode) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
m.Return(m.SmiTag(m.BitFieldDecode<TestBitField>(m.Int32Constant(0x2f))));
Handle<Code> code = m.GenerateCode();
FunctionTester ft(descriptor, code);
MaybeHandle<Object> result = ft.Call();
// value = 00101111
// mask = 00111000
// result = 101
CHECK_EQ(5, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
namespace {
Handle<JSFunction> CreateFunctionFromCode(int parameter_count_with_receiver,
Handle<Code> code) {
Isolate* isolate = code->GetIsolate();
Handle<String> name = isolate->factory()->InternalizeUtf8String("test");
Handle<JSFunction> function =
isolate->factory()->NewFunctionWithoutPrototype(name, code);
function->shared()->set_internal_formal_parameter_count(
parameter_count_with_receiver - 1); // Implicit undefined receiver.
return function;
}
} // namespace
TEST(JSFunction) {
const int kNumParams = 3; // Receiver, left, right.
Isolate* isolate(CcTest::InitIsolateOnce());
CodeStubAssemblerTester m(isolate, kNumParams);
m.Return(m.SmiTag(m.Int32Add(m.SmiToWord32(m.Parameter(1)),
m.SmiToWord32(m.Parameter(2)))));
Handle<Code> code = m.GenerateCode();
Handle<JSFunction> function = CreateFunctionFromCode(kNumParams, code);
Handle<Object> args[] = {Handle<Smi>(Smi::FromInt(23), isolate),
Handle<Smi>(Smi::FromInt(34), isolate)};
MaybeHandle<Object> result =
Execution::Call(isolate, function, isolate->factory()->undefined_value(),
arraysize(args), args);
CHECK_EQ(57, Handle<Smi>::cast(result.ToHandleChecked())->value());
}
TEST(SplitEdgeBranchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Label l1(&m), merge(&m);
m.Branch(m.Int32Constant(1), &l1, &merge);
m.Bind(&l1);
m.Goto(&merge);
m.Bind(&merge);
USE(m.GenerateCode());
}
TEST(SplitEdgeSwitchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
CodeStubAssembler::Label l1(&m), l2(&m), l3(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
m.Branch(m.Int32Constant(1), &l3, &l1);
m.Bind(&l3);
m.Switch(m.Int32Constant(2), &default_label, values, labels, 2);
m.Bind(&l1);
m.Goto(&l2);
m.Bind(&l2);
m.Goto(&default_label);
m.Bind(&default_label);
USE(m.GenerateCode());
}
TEST(TestToConstant) {
Isolate* isolate(CcTest::InitIsolateOnce());
VoidDescriptor descriptor(isolate);
CodeStubAssemblerTester m(isolate, descriptor);
int32_t value32;
int64_t value64;
Node* a = m.Int32Constant(5);
CHECK(m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.Int64Constant(static_cast<int64_t>(1) << 32);
CHECK(!m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.Int64Constant(13);
CHECK(m.ToInt32Constant(a, value32));
CHECK(m.ToInt64Constant(a, value64));
a = m.UndefinedConstant();
CHECK(!m.ToInt32Constant(a, value32));
CHECK(!m.ToInt64Constant(a, value64));
a = m.UndefinedConstant();
CHECK(!m.ToInt32Constant(a, value32));
CHECK(!m.ToInt64Constant(a, value64));
}
} // namespace compiler
} // namespace internal
} // namespace v8

File diff suppressed because it is too large Load Diff