roots.cc 2.33 KB
Newer Older
1 2 3 4 5
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/roots.h"
Dan Elphick's avatar
Dan Elphick committed
6

7
#include "src/elements-kind.h"
8
#include "src/objects-inl.h"
Dan Elphick's avatar
Dan Elphick committed
9
#include "src/visitors.h"
10 11 12 13

namespace v8 {
namespace internal {

14 15 16 17 18 19
const char* RootsTable::root_names_[RootsTable::kEntriesCount] = {
#define ROOT_NAME(type, name, CamelName) #name,
    ROOT_LIST(ROOT_NAME)
#undef ROOT_NAME
};

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
// static
RootIndex RootsTable::RootIndexForFixedTypedArray(
    ExternalArrayType array_type) {
  switch (array_type) {
#define ARRAY_TYPE_TO_ROOT_INDEX(Type, type, TYPE, ctype) \
  case kExternal##Type##Array:                            \
    return RootIndex::kFixed##Type##ArrayMap;

    TYPED_ARRAYS(ARRAY_TYPE_TO_ROOT_INDEX)
#undef ARRAY_TYPE_TO_ROOT_INDEX
  }
  UNREACHABLE();
}

// static
RootIndex RootsTable::RootIndexForFixedTypedArray(ElementsKind elements_kind) {
  switch (elements_kind) {
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) \
  case TYPE##_ELEMENTS:                           \
    return RootIndex::kFixed##Type##ArrayMap;
    TYPED_ARRAYS(TYPED_ARRAY_CASE)
    default:
      UNREACHABLE();
#undef TYPED_ARRAY_CASE
  }
}

// static
RootIndex RootsTable::RootIndexForEmptyFixedTypedArray(
    ElementsKind elements_kind) {
  switch (elements_kind) {
#define ELEMENT_KIND_TO_ROOT_INDEX(Type, type, TYPE, ctype) \
  case TYPE##_ELEMENTS:                                     \
    return RootIndex::kEmptyFixed##Type##Array;

    TYPED_ARRAYS(ELEMENT_KIND_TO_ROOT_INDEX)
#undef ELEMENT_KIND_TO_ROOT_INDEX
    default:
      UNREACHABLE();
  }
}

Dan Elphick's avatar
Dan Elphick committed
62 63 64 65 66 67 68
void ReadOnlyRoots::Iterate(RootVisitor* visitor) {
  visitor->VisitRootPointers(Root::kReadOnlyRootList, nullptr,
                             roots_table_.read_only_roots_begin(),
                             roots_table_.read_only_roots_end());
  visitor->Synchronize(VisitorSynchronization::kReadOnlyRootList);
}

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#ifdef DEBUG

bool ReadOnlyRoots::CheckType(RootIndex index) const {
  Object root(roots_table_[index]);
  switch (index) {
#define CHECKTYPE(Type, name, CamelName) \
  case RootIndex::k##CamelName:          \
    return root->Is##Type();
    READ_ONLY_ROOT_LIST(CHECKTYPE)
#undef CHECKTYPE

    default:
      UNREACHABLE();
      return false;
  }
}

#endif  // DEBUG

88 89
}  // namespace internal
}  // namespace v8