11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include 'src/objects/ordered-hash-table.h' 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Using int as a dummy type-parameter to get access to these constants which 81cb0ef41Sopenharmony_ci// don't actually depend on the derived class. This avoids accidentially 91cb0ef41Sopenharmony_ci// depending on something from a concrete derived class. 101cb0ef41Sopenharmony_ciconst kSmallOrderedHashTableMaxCapacity: constexpr int31 111cb0ef41Sopenharmony_ci generates 'SmallOrderedHashTable<int>::kMaxCapacity'; 121cb0ef41Sopenharmony_ciconst kSmallOrderedHashTableNotFound: constexpr int31 131cb0ef41Sopenharmony_ci generates 'SmallOrderedHashTable<int>::kNotFound'; 141cb0ef41Sopenharmony_ciconst kSmallOrderedHashTableLoadFactor: constexpr int31 151cb0ef41Sopenharmony_ci generates 'SmallOrderedHashTable<int>::kLoadFactor'; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci@abstract 181cb0ef41Sopenharmony_ci@doNotGenerateCppClass 191cb0ef41Sopenharmony_ciextern class SmallOrderedHashTable extends HeapObject 201cb0ef41Sopenharmony_ci generates 'TNode<HeapObject>' { 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciextern macro SmallOrderedHashSetMapConstant(): Map; 241cb0ef41Sopenharmony_ciconst kSmallOrderedHashSetMap: Map = SmallOrderedHashSetMapConstant(); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci@doNotGenerateCppClass 271cb0ef41Sopenharmony_ciextern class SmallOrderedHashSet extends SmallOrderedHashTable { 281cb0ef41Sopenharmony_ci number_of_elements: uint8; 291cb0ef41Sopenharmony_ci number_of_deleted_elements: uint8; 301cb0ef41Sopenharmony_ci const number_of_buckets: uint8; 311cb0ef41Sopenharmony_ci @if(TAGGED_SIZE_8_BYTES) padding[5]: uint8; 321cb0ef41Sopenharmony_ci @ifnot(TAGGED_SIZE_8_BYTES) padding[1]: uint8; 331cb0ef41Sopenharmony_ci data_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]: 341cb0ef41Sopenharmony_ci JSAny|TheHole; 351cb0ef41Sopenharmony_ci hash_table[number_of_buckets]: uint8; 361cb0ef41Sopenharmony_ci chain_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]: 371cb0ef41Sopenharmony_ci uint8; 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci@export 411cb0ef41Sopenharmony_cimacro AllocateSmallOrderedHashSet(capacity: intptr): SmallOrderedHashSet { 421cb0ef41Sopenharmony_ci const hashTableSize = capacity / kSmallOrderedHashTableLoadFactor; 431cb0ef41Sopenharmony_ci dcheck( 441cb0ef41Sopenharmony_ci 0 <= hashTableSize && hashTableSize <= kSmallOrderedHashTableMaxCapacity); 451cb0ef41Sopenharmony_ci return new SmallOrderedHashSet{ 461cb0ef41Sopenharmony_ci map: kSmallOrderedHashSetMap, 471cb0ef41Sopenharmony_ci number_of_elements: 0, 481cb0ef41Sopenharmony_ci number_of_deleted_elements: 0, 491cb0ef41Sopenharmony_ci number_of_buckets: (Convert<uint8>(hashTableSize)), 501cb0ef41Sopenharmony_ci padding: ...ConstantIterator<uint8>(0), 511cb0ef41Sopenharmony_ci data_table: ...ConstantIterator(TheHole), 521cb0ef41Sopenharmony_ci hash_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound), 531cb0ef41Sopenharmony_ci chain_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound) 541cb0ef41Sopenharmony_ci }; 551cb0ef41Sopenharmony_ci} 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_cistruct HashMapEntry { 581cb0ef41Sopenharmony_ci key: JSAny|TheHole; 591cb0ef41Sopenharmony_ci value: JSAny|TheHole; 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciextern macro SmallOrderedHashMapMapConstant(): Map; 631cb0ef41Sopenharmony_ciconst kSmallOrderedHashMapMap: Map = SmallOrderedHashMapMapConstant(); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci@doNotGenerateCppClass 661cb0ef41Sopenharmony_ciextern class SmallOrderedHashMap extends SmallOrderedHashTable { 671cb0ef41Sopenharmony_ci number_of_elements: uint8; 681cb0ef41Sopenharmony_ci number_of_deleted_elements: uint8; 691cb0ef41Sopenharmony_ci const number_of_buckets: uint8; 701cb0ef41Sopenharmony_ci @if(TAGGED_SIZE_8_BYTES) padding[5]: uint8; 711cb0ef41Sopenharmony_ci @ifnot(TAGGED_SIZE_8_BYTES) padding[1]: uint8; 721cb0ef41Sopenharmony_ci data_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]: 731cb0ef41Sopenharmony_ci HashMapEntry; 741cb0ef41Sopenharmony_ci hash_table[number_of_buckets]: uint8; 751cb0ef41Sopenharmony_ci chain_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]: 761cb0ef41Sopenharmony_ci uint8; 771cb0ef41Sopenharmony_ci} 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci@export 801cb0ef41Sopenharmony_cimacro AllocateSmallOrderedHashMap(capacity: intptr): SmallOrderedHashMap { 811cb0ef41Sopenharmony_ci const hashTableSize = capacity / kSmallOrderedHashTableLoadFactor; 821cb0ef41Sopenharmony_ci dcheck( 831cb0ef41Sopenharmony_ci 0 <= hashTableSize && hashTableSize <= kSmallOrderedHashTableMaxCapacity); 841cb0ef41Sopenharmony_ci return new SmallOrderedHashMap{ 851cb0ef41Sopenharmony_ci map: kSmallOrderedHashMapMap, 861cb0ef41Sopenharmony_ci number_of_elements: 0, 871cb0ef41Sopenharmony_ci number_of_deleted_elements: 0, 881cb0ef41Sopenharmony_ci number_of_buckets: (Convert<uint8>(hashTableSize)), 891cb0ef41Sopenharmony_ci padding: ...ConstantIterator<uint8>(0), 901cb0ef41Sopenharmony_ci data_table: ...ConstantIterator(HashMapEntry{key: TheHole, value: TheHole}), 911cb0ef41Sopenharmony_ci hash_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound), 921cb0ef41Sopenharmony_ci chain_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound) 931cb0ef41Sopenharmony_ci }; 941cb0ef41Sopenharmony_ci} 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_cistruct NameDictionaryEntry { 971cb0ef41Sopenharmony_ci key: JSAny|TheHole; 981cb0ef41Sopenharmony_ci value: JSAny|TheHole; 991cb0ef41Sopenharmony_ci property_details: Smi|TheHole; 1001cb0ef41Sopenharmony_ci} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci@doNotGenerateCppClass 1031cb0ef41Sopenharmony_ciextern class SmallOrderedNameDictionary extends SmallOrderedHashTable { 1041cb0ef41Sopenharmony_ci hash: int32; 1051cb0ef41Sopenharmony_ci @if(TAGGED_SIZE_8_BYTES) padding_0: int32; 1061cb0ef41Sopenharmony_ci @ifnot(TAGGED_SIZE_8_BYTES) padding_0: void; 1071cb0ef41Sopenharmony_ci number_of_elements: uint8; 1081cb0ef41Sopenharmony_ci number_of_deleted_elements: uint8; 1091cb0ef41Sopenharmony_ci const number_of_buckets: uint8; 1101cb0ef41Sopenharmony_ci @if(TAGGED_SIZE_8_BYTES) padding_1[5]: uint8; 1111cb0ef41Sopenharmony_ci @ifnot(TAGGED_SIZE_8_BYTES) padding_1[1]: uint8; 1121cb0ef41Sopenharmony_ci data_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]: 1131cb0ef41Sopenharmony_ci NameDictionaryEntry; 1141cb0ef41Sopenharmony_ci hash_table[number_of_buckets]: uint8; 1151cb0ef41Sopenharmony_ci chain_table[number_of_buckets]: uint8; 1161cb0ef41Sopenharmony_ci} 117