[turbofan] Precompute array index represented by an internalized string

Bug: v8:7790
Change-Id: I223f01bc7f26de234b41e6ab249bb41f822c835f
Reviewed-on: https://chromium-review.googlesource.com/c/1411602
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58875}
This commit is contained in:
Georg Neis 2019-01-15 14:23:46 +01:00 committed by Commit Bot
parent 65bb02593f
commit 66b616f450
3 changed files with 58 additions and 9 deletions

View File

@ -486,6 +486,12 @@ class StringData : public NameData {
static constexpr int kMaxLengthForDoubleConversion = 23; static constexpr int kMaxLengthForDoubleConversion = 23;
}; };
class SymbolData : public NameData {
public:
SymbolData(JSHeapBroker* broker, ObjectData** storage, Handle<Symbol> object)
: NameData(broker, storage, object) {}
};
StringData::StringData(JSHeapBroker* broker, ObjectData** storage, StringData::StringData(JSHeapBroker* broker, ObjectData** storage,
Handle<String> object) Handle<String> object)
: NameData(broker, storage, object), : NameData(broker, storage, object),
@ -502,10 +508,23 @@ StringData::StringData(JSHeapBroker* broker, ObjectData** storage,
class InternalizedStringData : public StringData { class InternalizedStringData : public StringData {
public: public:
InternalizedStringData(JSHeapBroker* broker, ObjectData** storage, InternalizedStringData(JSHeapBroker* broker, ObjectData** storage,
Handle<InternalizedString> object) Handle<InternalizedString> object);
: StringData(broker, storage, object) {}
uint32_t array_index() const { return array_index_; }
private:
uint32_t array_index_;
}; };
InternalizedStringData::InternalizedStringData(
JSHeapBroker* broker, ObjectData** storage,
Handle<InternalizedString> object)
: StringData(broker, storage, object) {
if (!object->AsArrayIndex(&array_index_)) {
array_index_ = InternalizedStringRef::kNotAnArrayIndex;
}
}
namespace { namespace {
bool IsFastLiteralHelper(Handle<JSObject> boilerplate, int max_depth, bool IsFastLiteralHelper(Handle<JSObject> boilerplate, int max_depth,
@ -2113,6 +2132,19 @@ base::Optional<double> StringRef::ToNumber() {
return data()->AsString()->to_number(); return data()->AsString()->to_number();
} }
uint32_t InternalizedStringRef::array_index() const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleDereference allow_handle_dereference;
AllowHandleAllocation allow_handle_allocation;
uint32_t result;
if (!object()->AsArrayIndex(&result)) {
result = kNotAnArrayIndex;
}
return result;
}
return data()->AsInternalizedString()->array_index();
}
ObjectRef FixedArrayRef::get(int i) const { ObjectRef FixedArrayRef::get(int i) const {
if (broker()->mode() == JSHeapBroker::kDisabled) { if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation; AllowHandleAllocation handle_allocation;

View File

@ -66,6 +66,7 @@ enum class OddballType : uint8_t {
/* Subtypes of Name */ \ /* Subtypes of Name */ \
V(InternalizedString) \ V(InternalizedString) \
V(String) \ V(String) \
V(Symbol) \
/* Subtypes of HeapObject */ \ /* Subtypes of HeapObject */ \
V(AllocationSite) \ V(AllocationSite) \
V(Cell) \ V(Cell) \
@ -549,6 +550,12 @@ class StringRef : public NameRef {
bool IsExternalString() const; bool IsExternalString() const;
}; };
class SymbolRef : public NameRef {
public:
using NameRef::NameRef;
Handle<Symbol> object() const;
};
class JSTypedArrayRef : public JSObjectRef { class JSTypedArrayRef : public JSObjectRef {
public: public:
using JSObjectRef::JSObjectRef; using JSObjectRef::JSObjectRef;
@ -597,6 +604,9 @@ class InternalizedStringRef : public StringRef {
public: public:
using StringRef::StringRef; using StringRef::StringRef;
Handle<InternalizedString> object() const; Handle<InternalizedString> object() const;
uint32_t array_index() const;
static const uint32_t kNotAnArrayIndex = -1; // 2^32-1 is not a valid index.
}; };
class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) { class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {

View File

@ -1802,13 +1802,20 @@ Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
// Optimize access for constant {index}. // Optimize access for constant {index}.
HeapObjectMatcher mindex(index); HeapObjectMatcher mindex(index);
if (mindex.HasValue() && mindex.Value()->IsUniqueName()) { if (mindex.HasValue()) {
auto name = Handle<Name>::cast(mindex.Value()); ObjectRef name = mindex.Ref(broker());
uint32_t array_index; if (name.IsSymbol()) {
if (name->AsArrayIndex(&array_index)) { return ReduceNamedAccess(node, value, receiver_maps,
index = jsgraph()->Constant(static_cast<double>(array_index)); name.AsName().object(), access_mode);
} else { }
return ReduceNamedAccess(node, value, receiver_maps, name, access_mode); if (name.IsInternalizedString()) {
uint32_t array_index = name.AsInternalizedString().array_index();
if (array_index != InternalizedStringRef::kNotAnArrayIndex) {
index = jsgraph()->Constant(static_cast<double>(array_index));
} else {
return ReduceNamedAccess(node, value, receiver_maps,
name.AsName().object(), access_mode);
}
} }
} }