1 | // Copyright 2018 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/roots.h" |
6 | |
7 | #include "src/elements-kind.h" |
8 | #include "src/objects-inl.h" |
9 | #include "src/visitors.h" |
10 | |
11 | namespace v8 { |
12 | namespace internal { |
13 | |
14 | const char* RootsTable::root_names_[RootsTable::kEntriesCount] = { |
15 | #define ROOT_NAME(type, name, CamelName) #name, |
16 | ROOT_LIST(ROOT_NAME) |
17 | #undef ROOT_NAME |
18 | }; |
19 | |
20 | // static |
21 | RootIndex RootsTable::RootIndexForFixedTypedArray( |
22 | ExternalArrayType array_type) { |
23 | switch (array_type) { |
24 | #define ARRAY_TYPE_TO_ROOT_INDEX(Type, type, TYPE, ctype) \ |
25 | case kExternal##Type##Array: \ |
26 | return RootIndex::kFixed##Type##ArrayMap; |
27 | |
28 | TYPED_ARRAYS(ARRAY_TYPE_TO_ROOT_INDEX) |
29 | #undef ARRAY_TYPE_TO_ROOT_INDEX |
30 | } |
31 | UNREACHABLE(); |
32 | } |
33 | |
34 | // static |
35 | RootIndex RootsTable::RootIndexForFixedTypedArray(ElementsKind elements_kind) { |
36 | switch (elements_kind) { |
37 | #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) \ |
38 | case TYPE##_ELEMENTS: \ |
39 | return RootIndex::kFixed##Type##ArrayMap; |
40 | TYPED_ARRAYS(TYPED_ARRAY_CASE) |
41 | default: |
42 | UNREACHABLE(); |
43 | #undef TYPED_ARRAY_CASE |
44 | } |
45 | } |
46 | |
47 | // static |
48 | RootIndex RootsTable::RootIndexForEmptyFixedTypedArray( |
49 | ElementsKind elements_kind) { |
50 | switch (elements_kind) { |
51 | #define ELEMENT_KIND_TO_ROOT_INDEX(Type, type, TYPE, ctype) \ |
52 | case TYPE##_ELEMENTS: \ |
53 | return RootIndex::kEmptyFixed##Type##Array; |
54 | |
55 | TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX) |
56 | #undef ELEMENT_KIND_TO_ROOT_INDEX |
57 | default: |
58 | UNREACHABLE(); |
59 | } |
60 | } |
61 | |
62 | void ReadOnlyRoots::Iterate(RootVisitor* visitor) { |
63 | visitor->VisitRootPointers(Root::kReadOnlyRootList, nullptr, |
64 | roots_table_.read_only_roots_begin(), |
65 | roots_table_.read_only_roots_end()); |
66 | visitor->Synchronize(VisitorSynchronization::kReadOnlyRootList); |
67 | } |
68 | |
69 | #ifdef DEBUG |
70 | |
71 | bool ReadOnlyRoots::CheckType(RootIndex index) const { |
72 | Object root(roots_table_[index]); |
73 | switch (index) { |
74 | #define CHECKTYPE(Type, name, CamelName) \ |
75 | case RootIndex::k##CamelName: \ |
76 | return root->Is##Type(); |
77 | READ_ONLY_ROOT_LIST(CHECKTYPE) |
78 | #undef CHECKTYPE |
79 | |
80 | default: |
81 | UNREACHABLE(); |
82 | return false; |
83 | } |
84 | } |
85 | |
86 | #endif // DEBUG |
87 | |
88 | } // namespace internal |
89 | } // namespace v8 |
90 | |