• 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@abstract
6extern class Name extends PrimitiveHeapObject {
7  raw_hash_field: NameHash;
8}
9
10bitfield struct NameHash extends uint32 {
11  hash_field_type: HashFieldType: 2 bit;
12  array_index_value: uint32: 24 bit;
13  array_index_length: uint32: 6 bit;
14}
15
16// This is the same as Name, but with the information that there are no other
17// kinds of names.
18type AnyName = PrivateSymbol|PublicSymbol|String;
19
20bitfield struct SymbolFlags extends uint32 {
21  is_private: bool: 1 bit;
22  is_well_known_symbol: bool: 1 bit;
23  is_in_public_symbol_table: bool: 1 bit;
24  is_interesting_symbol: bool: 1 bit;
25  is_private_name: bool: 1 bit;
26  is_private_brand: bool: 1 bit;
27}
28
29extern class Symbol extends Name {
30  flags: SymbolFlags;
31  description: String|Undefined;
32}
33
34type PublicSymbol extends Symbol;
35type PrivateSymbol extends Symbol;
36
37const kMaxCachedArrayIndexLength: constexpr uint32
38    generates 'Name::kMaxCachedArrayIndexLength';
39const kMaxArrayIndexSize: constexpr uint32
40    generates 'Name::kMaxArrayIndexSize';
41const kNofHashBitFields: constexpr int31
42    generates 'Name::HashFieldTypeBits::kSize';
43const kArrayIndexValueBits: constexpr int31
44    generates 'Name::kArrayIndexValueBits';
45const kDoesNotContainCachedArrayIndexMask: constexpr uint32
46    generates 'Name::kDoesNotContainCachedArrayIndexMask';
47const kNameEmptyHashField: NameHash = NameHash{
48  hash_field_type: HashFieldType::kEmpty,
49  array_index_value: 0,
50  array_index_length: 0
51};
52
53macro ContainsCachedArrayIndex(hash: uint32): bool {
54  return (hash & kDoesNotContainCachedArrayIndexMask) == 0;
55}
56
57const kArrayIndexValueBitsShift: uint32 = kNofHashBitFields;
58const kArrayIndexLengthBitsShift: uint32 =
59    kNofHashBitFields + kArrayIndexValueBits;
60
61macro TenToThe(exponent: uint32): uint32 {
62  dcheck(exponent <= 9);
63  let answer: int32 = 1;
64  for (let i: int32 = 0; i < Signed(exponent); i++) {
65    answer = answer * 10;
66  }
67  return Unsigned(answer);
68}
69
70macro IsIntegerIndex(hash: NameHash): bool {
71  return hash.hash_field_type == HashFieldType::kIntegerIndex;
72}
73
74macro MakeArrayIndexHash(value: uint32, length: uint32): NameHash {
75  // This is in sync with StringHasher::MakeArrayIndexHash.
76  dcheck(length <= kMaxArrayIndexSize);
77  const one: uint32 = 1;
78  dcheck(TenToThe(kMaxCachedArrayIndexLength) < (one << kArrayIndexValueBits));
79  let rawHash: uint32 = value;
80  rawHash = (rawHash << kArrayIndexValueBitsShift) |
81      (length << kArrayIndexLengthBitsShift);
82  dcheck(
83      (length <= kMaxCachedArrayIndexLength) ==
84      ContainsCachedArrayIndex(rawHash));
85  const hash: NameHash = %RawDownCast<NameHash>(rawHash);
86  dcheck(IsIntegerIndex(hash));
87  return hash;
88}
89