• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include 'src/objects/ordered-hash-table.h'
6
7// Using int as a dummy type-parameter to get access to these constants which
8// don't actually depend on the derived class. This avoids accidentially
9// depending on something from a concrete derived class.
10const kSmallOrderedHashTableMaxCapacity: constexpr int31
11    generates 'SmallOrderedHashTable<int>::kMaxCapacity';
12const kSmallOrderedHashTableNotFound: constexpr int31
13    generates 'SmallOrderedHashTable<int>::kNotFound';
14const kSmallOrderedHashTableLoadFactor: constexpr int31
15    generates 'SmallOrderedHashTable<int>::kLoadFactor';
16
17@abstract
18@doNotGenerateCppClass
19extern class SmallOrderedHashTable extends HeapObject
20    generates 'TNode<HeapObject>' {
21}
22
23extern macro SmallOrderedHashSetMapConstant(): Map;
24const kSmallOrderedHashSetMap: Map = SmallOrderedHashSetMapConstant();
25
26@doNotGenerateCppClass
27extern class SmallOrderedHashSet extends SmallOrderedHashTable {
28  number_of_elements: uint8;
29  number_of_deleted_elements: uint8;
30  const number_of_buckets: uint8;
31  @if(TAGGED_SIZE_8_BYTES) padding[5]: uint8;
32  @ifnot(TAGGED_SIZE_8_BYTES) padding[1]: uint8;
33  data_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]:
34      JSAny|TheHole;
35  hash_table[number_of_buckets]: uint8;
36  chain_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]:
37      uint8;
38}
39
40@export
41macro AllocateSmallOrderedHashSet(capacity: intptr): SmallOrderedHashSet {
42  const hashTableSize = capacity / kSmallOrderedHashTableLoadFactor;
43  dcheck(
44      0 <= hashTableSize && hashTableSize <= kSmallOrderedHashTableMaxCapacity);
45  return new SmallOrderedHashSet{
46    map: kSmallOrderedHashSetMap,
47    number_of_elements: 0,
48    number_of_deleted_elements: 0,
49    number_of_buckets: (Convert<uint8>(hashTableSize)),
50    padding: ...ConstantIterator<uint8>(0),
51    data_table: ...ConstantIterator(TheHole),
52    hash_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound),
53    chain_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound)
54  };
55}
56
57struct HashMapEntry {
58  key: JSAny|TheHole;
59  value: JSAny|TheHole;
60}
61
62extern macro SmallOrderedHashMapMapConstant(): Map;
63const kSmallOrderedHashMapMap: Map = SmallOrderedHashMapMapConstant();
64
65@doNotGenerateCppClass
66extern class SmallOrderedHashMap extends SmallOrderedHashTable {
67  number_of_elements: uint8;
68  number_of_deleted_elements: uint8;
69  const number_of_buckets: uint8;
70  @if(TAGGED_SIZE_8_BYTES) padding[5]: uint8;
71  @ifnot(TAGGED_SIZE_8_BYTES) padding[1]: uint8;
72  data_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]:
73      HashMapEntry;
74  hash_table[number_of_buckets]: uint8;
75  chain_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]:
76      uint8;
77}
78
79@export
80macro AllocateSmallOrderedHashMap(capacity: intptr): SmallOrderedHashMap {
81  const hashTableSize = capacity / kSmallOrderedHashTableLoadFactor;
82  dcheck(
83      0 <= hashTableSize && hashTableSize <= kSmallOrderedHashTableMaxCapacity);
84  return new SmallOrderedHashMap{
85    map: kSmallOrderedHashMapMap,
86    number_of_elements: 0,
87    number_of_deleted_elements: 0,
88    number_of_buckets: (Convert<uint8>(hashTableSize)),
89    padding: ...ConstantIterator<uint8>(0),
90    data_table: ...ConstantIterator(HashMapEntry{key: TheHole, value: TheHole}),
91    hash_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound),
92    chain_table: ...ConstantIterator<uint8>(kSmallOrderedHashTableNotFound)
93  };
94}
95
96struct NameDictionaryEntry {
97  key: JSAny|TheHole;
98  value: JSAny|TheHole;
99  property_details: Smi|TheHole;
100}
101
102@doNotGenerateCppClass
103extern class SmallOrderedNameDictionary extends SmallOrderedHashTable {
104  hash: int32;
105  @if(TAGGED_SIZE_8_BYTES) padding_0: int32;
106  @ifnot(TAGGED_SIZE_8_BYTES) padding_0: void;
107  number_of_elements: uint8;
108  number_of_deleted_elements: uint8;
109  const number_of_buckets: uint8;
110  @if(TAGGED_SIZE_8_BYTES) padding_1[5]: uint8;
111  @ifnot(TAGGED_SIZE_8_BYTES) padding_1[1]: uint8;
112  data_table[Convert<intptr>(number_of_buckets) * kSmallOrderedHashTableLoadFactor]:
113      NameDictionaryEntry;
114  hash_table[number_of_buckets]: uint8;
115  chain_table[number_of_buckets]: uint8;
116}
117