Commit 24066b6d authored by ishell's avatar ishell Committed by Commit bot

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

Review-Url: https://codereview.chromium.org/1995453002
Cr-Commit-Position: refs/heads/master@{#36657}
parent ee43805a
This diff is collapsed.
......@@ -40,6 +40,8 @@ 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.
......@@ -112,6 +114,8 @@ 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.
......@@ -128,12 +132,21 @@ 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 hash field of a name.
compiler::Node* LoadNameHash(compiler::Node* name);
// 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* AllocateUninitializedFixedArray(compiler::Node* length);
// Load an array element from a FixedArray.
......@@ -141,6 +154,11 @@ 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);
......@@ -230,17 +248,31 @@ 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* call_runtime);
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);
void TryLookupProperty(compiler::Node* object, compiler::Node* map,
compiler::Node* instance_type, compiler::Node* name,
Label* if_found, Label* if_not_found,
Label* call_runtime);
compiler::Node* instance_type,
compiler::Node* unique_name, Label* if_found,
Label* if_not_found, Label* if_bailout);
void TryLookupElement(compiler::Node* object, compiler::Node* map,
compiler::Node* instance_type, compiler::Node* index,
Label* if_found, Label* if_not_found,
Label* call_runtime);
Label* if_bailout);
// Instanceof helpers.
// ES6 section 7.3.19 OrdinaryHasInstance (C, O)
......
......@@ -644,6 +644,15 @@ 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:
elements()->Print(os);
SeededNumberDictionary::cast(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((length > String::kMaxCachedArrayIndexLength) ||
(value & String::kContainsCachedArrayIndexMask) == 0);
DCHECK_EQ(length <= String::kMaxCachedArrayIndexLength,
(value & String::kContainsCachedArrayIndexMask) == 0);
return value;
}
......@@ -15170,6 +15170,11 @@ 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
......@@ -15901,15 +15906,7 @@ int NameDictionaryBase<Derived, Shape>::FindEntry(Handle<Name> key) {
Object* element = this->get(index);
if (element->IsUndefined()) break; // Empty entry.
if (*key == element) return entry;
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));
DCHECK(element->IsTheHole() || element->IsUniqueName());
entry = Derived::NextProbe(entry, count++, capacity);
}
return Derived::kNotFound;
......
......@@ -3189,6 +3189,8 @@ 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) {
......@@ -3475,6 +3477,9 @@ 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).
......@@ -8570,6 +8575,10 @@ 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.
......@@ -8577,7 +8586,8 @@ class Name: public HeapObject {
static const int kArrayIndexLengthBits =
kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
STATIC_ASSERT((kArrayIndexLengthBits > 0));
STATIC_ASSERT(kArrayIndexLengthBits > 0);
STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
kArrayIndexValueBits> {}; // NOLINT
......@@ -8667,34 +8677,6 @@ 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,
......@@ -8906,11 +8888,6 @@ 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,11 +430,8 @@ void init_memcopy_functions(Isolate* isolate) {
bool DoubleToBoolean(double d) {
// NaN, +0, and -0 should return the false object
#if V8_TARGET_LITTLE_ENDIAN
union IeeeDoubleLittleEndianArchType u;
#else
union IeeeDoubleBigEndianArchType u;
#endif
IeeeDoubleArchType u;
u.d = d;
if (u.bits.exp == 2047) {
// Detect NaN for IEEE double precision floating point.
......
......@@ -19,7 +19,6 @@ 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",
......@@ -93,6 +92,7 @@ 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,7 +53,6 @@
'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',
......@@ -129,6 +128,7 @@
'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,16 +42,18 @@ class FunctionTester : public InitializedHandleScope {
CompileGraph(graph);
}
FunctionTester(const CallInterfaceDescriptor& descriptor, Handle<Code> code)
FunctionTester(Handle<Code> code, int param_count)
: isolate(main_isolate()),
function(
(FLAG_allow_natives_syntax = true,
NewFunction(BuildFunctionFromDescriptor(descriptor).c_str()))),
function((FLAG_allow_natives_syntax = true,
NewFunction(BuildFunction(param_count).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;
......@@ -64,6 +66,12 @@ 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};
......@@ -91,41 +99,56 @@ class FunctionTester : public InitializedHandleScope {
return try_catch.Message();
}
void CheckCall(Handle<Object> expected, Handle<Object> a, Handle<Object> b) {
Handle<Object> result = Call(a, b).ToHandleChecked();
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());
}
void CheckCall(Handle<Object> expected, Handle<Object> a) {
CheckCall(expected, a, undefined());
}
void CheckCall(Handle<Object> expected) {
CheckCall(expected, undefined(), undefined());
}
void CheckCall(Handle<Object> expected) { CheckCall(expected, 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) { CheckCall(true_value(), a, undefined()); }
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(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));
}
......@@ -217,11 +240,6 @@ 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) {
......
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