Commit 19f7cc49 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[Collections] Port Map.p.has to CSA/C++

Bug: v8:5717
Change-Id: I87cfef5d6d69106fd454338e77c2c703fcdba67b
Reviewed-on: https://chromium-review.googlesource.com/520576Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45674}
parent 3b7ff7a5
...@@ -1596,6 +1596,13 @@ ExternalReference ExternalReference::orderedhashtable_get_raw( ...@@ -1596,6 +1596,13 @@ ExternalReference ExternalReference::orderedhashtable_get_raw(
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f))); return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f)));
} }
template <typename CollectionType, int entrysize>
ExternalReference ExternalReference::orderedhashtable_has_raw(
Isolate* isolate) {
auto f = OrderedHashTable<CollectionType, entrysize>::HasKey;
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f)));
}
ExternalReference ExternalReference::try_internalize_string_function( ExternalReference ExternalReference::try_internalize_string_function(
Isolate* isolate) { Isolate* isolate) {
return ExternalReference(Redirect( return ExternalReference(Redirect(
...@@ -1631,6 +1638,11 @@ ExternalReference::orderedhashtable_get_raw<OrderedHashMap, 2>(Isolate*); ...@@ -1631,6 +1638,11 @@ ExternalReference::orderedhashtable_get_raw<OrderedHashMap, 2>(Isolate*);
template ExternalReference template ExternalReference
ExternalReference::orderedhashtable_get_raw<OrderedHashSet, 1>(Isolate*); ExternalReference::orderedhashtable_get_raw<OrderedHashSet, 1>(Isolate*);
template ExternalReference
ExternalReference::orderedhashtable_has_raw<OrderedHashMap, 2>(Isolate*);
template ExternalReference
ExternalReference::orderedhashtable_has_raw<OrderedHashSet, 1>(Isolate*);
ExternalReference ExternalReference::page_flags(Page* page) { ExternalReference ExternalReference::page_flags(Page* page) {
return ExternalReference(reinterpret_cast<Address>(page) + return ExternalReference(reinterpret_cast<Address>(page) +
MemoryChunk::kFlagsOffset); MemoryChunk::kFlagsOffset);
......
...@@ -1027,6 +1027,9 @@ class ExternalReference BASE_EMBEDDED { ...@@ -1027,6 +1027,9 @@ class ExternalReference BASE_EMBEDDED {
template <typename CollectionType, int entrysize> template <typename CollectionType, int entrysize>
static ExternalReference orderedhashtable_get_raw(Isolate* isolate); static ExternalReference orderedhashtable_get_raw(Isolate* isolate);
template <typename CollectionType, int entrysize>
static ExternalReference orderedhashtable_has_raw(Isolate* isolate);
static ExternalReference page_flags(Page* page); static ExternalReference page_flags(Page* page);
static ExternalReference ForDeoptEntry(Address entry); static ExternalReference ForDeoptEntry(Address entry);
......
...@@ -2950,6 +2950,11 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2950,6 +2950,11 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
InstallWithIntrinsicDefaultProto(isolate, map_get, InstallWithIntrinsicDefaultProto(isolate, map_get,
Context::MAP_GET_METHOD_INDEX); Context::MAP_GET_METHOD_INDEX);
Handle<JSFunction> map_has =
SimpleInstallFunction(prototype, "has", Builtins::kMapHas, 1, true);
InstallWithIntrinsicDefaultProto(isolate, map_has,
Context::MAP_HAS_METHOD_INDEX);
InstallSpeciesGetter(js_map_fun); InstallSpeciesGetter(js_map_fun);
} }
......
...@@ -19,9 +19,10 @@ class CollectionsBuiltinsAssembler : public CodeStubAssembler { ...@@ -19,9 +19,10 @@ class CollectionsBuiltinsAssembler : public CodeStubAssembler {
protected: protected:
Node* AllocateJSMap(Node* js_map_function); Node* AllocateJSMap(Node* js_map_function);
template <typename CollectionType, int entrysize> template <typename CollectionType, int entrysize>
Node* CallGetRaw(Node* const table, Node* const key); Node* CallGetRaw(Node* const table, Node* const key);
template <typename CollectionType, int entrysize>
Node* CallHasRaw(Node* const table, Node* const key);
}; };
Node* CollectionsBuiltinsAssembler::AllocateJSMap(Node* js_map_function) { Node* CollectionsBuiltinsAssembler::AllocateJSMap(Node* js_map_function) {
...@@ -174,6 +175,25 @@ Node* CollectionsBuiltinsAssembler::CallGetRaw(Node* const table, ...@@ -174,6 +175,25 @@ Node* CollectionsBuiltinsAssembler::CallGetRaw(Node* const table,
return result; return result;
} }
template <typename CollectionType, int entrysize>
Node* CollectionsBuiltinsAssembler::CallHasRaw(Node* const table,
Node* const key) {
Node* const function_addr = ExternalConstant(
ExternalReference::orderedhashtable_has_raw<CollectionType, entrysize>(
isolate()));
Node* const isolate_ptr =
ExternalConstant(ExternalReference::isolate_address(isolate()));
MachineType type_ptr = MachineType::Pointer();
MachineType type_tagged = MachineType::AnyTagged();
Node* const result =
CallCFunction3(type_tagged, type_ptr, type_tagged, type_tagged,
function_addr, isolate_ptr, table, key);
return result;
}
TF_BUILTIN(MapGet, CollectionsBuiltinsAssembler) { TF_BUILTIN(MapGet, CollectionsBuiltinsAssembler) {
Node* const receiver = Parameter(Descriptor::kReceiver); Node* const receiver = Parameter(Descriptor::kReceiver);
Node* const key = Parameter(Descriptor::kKey); Node* const key = Parameter(Descriptor::kKey);
...@@ -184,5 +204,17 @@ TF_BUILTIN(MapGet, CollectionsBuiltinsAssembler) { ...@@ -184,5 +204,17 @@ TF_BUILTIN(MapGet, CollectionsBuiltinsAssembler) {
Node* const table = LoadObjectField(receiver, JSMap::kTableOffset); Node* const table = LoadObjectField(receiver, JSMap::kTableOffset);
Return(CallGetRaw<OrderedHashMap, 2>(table, key)); Return(CallGetRaw<OrderedHashMap, 2>(table, key));
} }
TF_BUILTIN(MapHas, CollectionsBuiltinsAssembler) {
Node* const receiver = Parameter(Descriptor::kReceiver);
Node* const key = Parameter(Descriptor::kKey);
Node* const context = Parameter(Descriptor::kContext);
ThrowIfNotInstanceType(context, receiver, JS_MAP_TYPE, "Map.prototype.has");
Node* const table = LoadObjectField(receiver, JSMap::kTableOffset);
Return(CallHasRaw<OrderedHashMap, 2>(table, key));
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -541,6 +541,7 @@ namespace internal { ...@@ -541,6 +541,7 @@ namespace internal {
/* Map */ \ /* Map */ \
TFJ(MapConstructor, 1, kIterable) \ TFJ(MapConstructor, 1, kIterable) \
TFJ(MapGet, 1, kKey) \ TFJ(MapGet, 1, kKey) \
TFJ(MapHas, 1, kKey) \
\ \
/* Math */ \ /* Math */ \
/* ES6 #sec-math.abs */ \ /* ES6 #sec-math.abs */ \
......
...@@ -277,6 +277,12 @@ void ExternalReferenceTable::AddReferences(Isolate* isolate) { ...@@ -277,6 +277,12 @@ void ExternalReferenceTable::AddReferences(Isolate* isolate) {
Add(ExternalReference::orderedhashtable_get_raw<OrderedHashSet, 1>(isolate) Add(ExternalReference::orderedhashtable_get_raw<OrderedHashSet, 1>(isolate)
.address(), .address(),
"orderedhashtable_get_raw<OrderedHashSet, 1>"); "orderedhashtable_get_raw<OrderedHashSet, 1>");
Add(ExternalReference::orderedhashtable_has_raw<OrderedHashMap, 2>(isolate)
.address(),
"orderedhashtable_has_raw<OrderedHashMap, 2>");
Add(ExternalReference::orderedhashtable_has_raw<OrderedHashSet, 1>(isolate)
.address(),
"orderedhashtable_has_raw<OrderedHashSet, 1>");
Add(ExternalReference::log_enter_external_function(isolate).address(), Add(ExternalReference::log_enter_external_function(isolate).address(),
"Logger::EnterExternal"); "Logger::EnterExternal");
Add(ExternalReference::log_leave_external_function(isolate).address(), Add(ExternalReference::log_leave_external_function(isolate).address(),
......
...@@ -324,18 +324,6 @@ function MapSet(key, value) { ...@@ -324,18 +324,6 @@ function MapSet(key, value) {
} }
function MapHas(key) {
if (!IS_MAP(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,
'Map.prototype.has', this);
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
var hash = GetHash(key);
return MapFindEntry(table, numBuckets, key, hash) !== NOT_FOUND;
}
function MapDelete(key) { function MapDelete(key) {
if (!IS_MAP(this)) { if (!IS_MAP(this)) {
throw %make_type_error(kIncompatibleMethodReceiver, throw %make_type_error(kIncompatibleMethodReceiver,
...@@ -401,7 +389,6 @@ function MapForEach(f, receiver) { ...@@ -401,7 +389,6 @@ function MapForEach(f, receiver) {
utils.InstallGetter(GlobalMap.prototype, "size", MapGetSize); utils.InstallGetter(GlobalMap.prototype, "size", MapGetSize);
utils.InstallFunctions(GlobalMap.prototype, DONT_ENUM, [ utils.InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
"set", MapSet, "set", MapSet,
"has", MapHas,
"delete", MapDelete, "delete", MapDelete,
"clear", MapClearJS, "clear", MapClearJS,
"forEach", MapForEach "forEach", MapForEach
...@@ -412,7 +399,6 @@ utils.InstallFunctions(GlobalMap.prototype, DONT_ENUM, [ ...@@ -412,7 +399,6 @@ utils.InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
%InstallToContext([ %InstallToContext([
"map_set", MapSet, "map_set", MapSet,
"map_has", MapHas,
"map_delete", MapDelete, "map_delete", MapDelete,
"set_add", SetAdd, "set_add", SetAdd,
"set_has", SetHas, "set_has", SetHas,
......
...@@ -18742,19 +18742,18 @@ Handle<Derived> OrderedHashTable<Derived, entrysize>::Clear( ...@@ -18742,19 +18742,18 @@ Handle<Derived> OrderedHashTable<Derived, entrysize>::Clear(
} }
template <class Derived, int entrysize> template <class Derived, int entrysize>
bool OrderedHashTable<Derived, entrysize>::HasKey(Handle<Derived> table, Object* OrderedHashTable<Derived, entrysize>::HasKey(Isolate* isolate,
Handle<Object> key) { Derived* table,
Object* key) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
Isolate* isolate = table->GetIsolate(); int entry = table->KeyToFirstEntry(isolate, key);
Object* raw_key = *key;
int entry = table->KeyToFirstEntry(isolate, raw_key);
// Walk the chain in the bucket to find the key. // Walk the chain in the bucket to find the key.
while (entry != kNotFound) { while (entry != kNotFound) {
Object* candidate_key = table->KeyAt(entry); Object* candidate_key = table->KeyAt(entry);
if (candidate_key->SameValueZero(raw_key)) return true; if (candidate_key->SameValueZero(key)) return isolate->heap()->true_value();
entry = table->NextChainEntry(entry); entry = table->NextChainEntry(entry);
} }
return false; return isolate->heap()->false_value();
} }
template <class Derived, int entrysize> template <class Derived, int entrysize>
...@@ -18885,8 +18884,8 @@ template Handle<OrderedHashSet> OrderedHashTable<OrderedHashSet, 1>::Shrink( ...@@ -18885,8 +18884,8 @@ template Handle<OrderedHashSet> OrderedHashTable<OrderedHashSet, 1>::Shrink(
template Handle<OrderedHashSet> OrderedHashTable<OrderedHashSet, 1>::Clear( template Handle<OrderedHashSet> OrderedHashTable<OrderedHashSet, 1>::Clear(
Handle<OrderedHashSet> table); Handle<OrderedHashSet> table);
template bool OrderedHashTable<OrderedHashSet, 1>::HasKey( template Object* OrderedHashTable<OrderedHashSet, 1>::HasKey(
Handle<OrderedHashSet> table, Handle<Object> key); Isolate* isolate, OrderedHashSet* table, Object* key);
template Object* OrderedHashTable<OrderedHashSet, 1>::Get(Isolate* isolate, template Object* OrderedHashTable<OrderedHashSet, 1>::Get(Isolate* isolate,
OrderedHashSet* table, OrderedHashSet* table,
...@@ -18904,8 +18903,8 @@ template Handle<OrderedHashMap> OrderedHashTable<OrderedHashMap, 2>::Shrink( ...@@ -18904,8 +18903,8 @@ template Handle<OrderedHashMap> OrderedHashTable<OrderedHashMap, 2>::Shrink(
template Handle<OrderedHashMap> OrderedHashTable<OrderedHashMap, 2>::Clear( template Handle<OrderedHashMap> OrderedHashTable<OrderedHashMap, 2>::Clear(
Handle<OrderedHashMap> table); Handle<OrderedHashMap> table);
template bool OrderedHashTable<OrderedHashMap, 2>::HasKey( template Object* OrderedHashTable<OrderedHashMap, 2>::HasKey(
Handle<OrderedHashMap> table, Handle<Object> key); Isolate* isolate, OrderedHashMap* table, Object* key);
template Object* OrderedHashTable<OrderedHashMap, 2>::Get(Isolate* isolate, template Object* OrderedHashTable<OrderedHashMap, 2>::Get(Isolate* isolate,
OrderedHashMap* table, OrderedHashMap* table,
......
...@@ -399,7 +399,7 @@ class OrderedHashTable : public FixedArray { ...@@ -399,7 +399,7 @@ class OrderedHashTable : public FixedArray {
static Handle<Derived> Clear(Handle<Derived> table); static Handle<Derived> Clear(Handle<Derived> table);
// Returns a true if the OrderedHashTable contains the key // Returns a true if the OrderedHashTable contains the key
static bool HasKey(Handle<Derived> table, Handle<Object> key); static Object* HasKey(Isolate* isolate, Derived* table, Object* key);
// Returns a value if the OrderedHashTable contains the key, // Returns a value if the OrderedHashTable contains the key,
// otherwise returns undefined. // otherwise returns undefined.
......
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