Line data Source code
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 18438 : RootIndex RootsTable::RootIndexForFixedTypedArray(
22 : ExternalArrayType array_type) {
23 18438 : 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 990 : TYPED_ARRAYS(ARRAY_TYPE_TO_ROOT_INDEX)
29 : #undef ARRAY_TYPE_TO_ROOT_INDEX
30 : }
31 0 : UNREACHABLE();
32 : }
33 :
34 : // static
35 1848 : RootIndex RootsTable::RootIndexForFixedTypedArray(ElementsKind elements_kind) {
36 1848 : switch (elements_kind) {
37 : #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) \
38 : case TYPE##_ELEMENTS: \
39 : return RootIndex::kFixed##Type##ArrayMap;
40 168 : TYPED_ARRAYS(TYPED_ARRAY_CASE)
41 : default:
42 0 : UNREACHABLE();
43 : #undef TYPED_ARRAY_CASE
44 : }
45 : }
46 :
47 : // static
48 4219 : RootIndex RootsTable::RootIndexForEmptyFixedTypedArray(
49 : ElementsKind elements_kind) {
50 4219 : 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 478 : TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX)
56 : #undef ELEMENT_KIND_TO_ROOT_INDEX
57 : default:
58 0 : UNREACHABLE();
59 : }
60 : }
61 :
62 63025 : void ReadOnlyRoots::Iterate(RootVisitor* visitor) {
63 : visitor->VisitRootPointers(Root::kReadOnlyRootList, nullptr,
64 : roots_table_.read_only_roots_begin(),
65 126050 : roots_table_.read_only_roots_end());
66 63025 : visitor->Synchronize(VisitorSynchronization::kReadOnlyRootList);
67 63025 : }
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 121996 : } // namespace v8
|