off-thread-factory.h 2.79 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2020 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.

#ifndef V8_HEAP_OFF_THREAD_FACTORY_H_
#define V8_HEAP_OFF_THREAD_FACTORY_H_

#include <map>
#include <vector>
10
#include "src/base/logging.h"
11 12 13 14 15 16 17
#include "src/common/globals.h"
#include "src/handles/handles.h"
#include "src/heap/factory-base.h"
#include "src/heap/heap.h"
#include "src/heap/read-only-heap.h"
#include "src/heap/spaces.h"
#include "src/objects/heap-object.h"
18
#include "src/objects/map.h"
19
#include "src/objects/objects.h"
20
#include "src/objects/shared-function-info.h"
21 22 23 24 25 26 27 28
#include "src/roots/roots.h"

namespace v8 {
namespace internal {

class AstValueFactory;
class AstRawString;
class AstConsString;
29
class OffThreadIsolate;
30 31 32 33 34 35 36 37

class V8_EXPORT_PRIVATE OffThreadFactory
    : public FactoryBase<OffThreadFactory> {
 public:
  explicit OffThreadFactory(Isolate* isolate);

  ReadOnlyRoots read_only_roots() const { return roots_; }

38
#define ROOT_ACCESSOR(Type, name, CamelName) inline Handle<Type> name();
39
  READ_ONLY_ROOT_LIST(ROOT_ACCESSOR)
40 41 42 43 44
  // AccessorInfos appear mutable, but they're actually not mutated once they
  // finish initializing. In particular, the root accessors are not mutated and
  // are safe to access (as long as the off-thread job doesn't try to mutate
  // them).
  ACCESSOR_INFO_ROOT_LIST(ROOT_ACCESSOR)
45 46
#undef ROOT_ACCESSOR

47 48 49
  Handle<String> InternalizeString(const Vector<const uint8_t>& string);
  Handle<String> InternalizeString(const Vector<const uint16_t>& string);

50 51
  // The parser shouldn't allow the OffThreadFactory to get into a state where
  // it generates errors.
52 53
  Handle<Object> NewInvalidStringLengthError() { UNREACHABLE(); }
  Handle<Object> NewRangeError(MessageTemplate template_index) {
54 55
    UNREACHABLE();
  }
56

57
  Handle<FixedArray> StringWrapperForTest(Handle<String> string);
58 59 60 61 62 63 64 65

 private:
  friend class FactoryBase<OffThreadFactory>;

  // ------
  // Customization points for FactoryBase.
  HeapObject AllocateRaw(int size, AllocationType allocation,
                         AllocationAlignment alignment = kWordAligned);
66 67 68 69 70 71 72

  OffThreadIsolate* isolate() {
    // Downcast to the privately inherited sub-class using c-style casts to
    // avoid undefined behavior (as static_cast cannot cast across private
    // bases).
    // NOLINTNEXTLINE (google-readability-casting)
    return (OffThreadIsolate*)this;  // NOLINT(readability/casting)
73 74 75 76 77
  }
  inline bool CanAllocateInReadOnlySpace() { return false; }
  inline bool EmptyStringRootIsInitialized() { return true; }
  // ------

78
  Handle<String> MakeOrFindTwoCharacterString(uint16_t c1, uint16_t c2);
79

80
  void AddToScriptList(Handle<Script> shared);
81
  // ------
82

83 84 85 86 87 88 89
  ReadOnlyRoots roots_;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_OFF_THREAD_FACTORY_H_