1 // Copyright 2020 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 #ifndef V8_HEAP_LOCAL_FACTORY_H_ 6 #define V8_HEAP_LOCAL_FACTORY_H_ 7 8 #include <map> 9 #include <vector> 10 11 #include "src/base/logging.h" 12 #include "src/common/globals.h" 13 #include "src/handles/handles.h" 14 #include "src/heap/factory-base.h" 15 #include "src/heap/heap.h" 16 #include "src/heap/read-only-heap.h" 17 #include "src/heap/spaces.h" 18 #include "src/objects/heap-object.h" 19 #include "src/objects/map.h" 20 #include "src/objects/objects.h" 21 #include "src/objects/shared-function-info.h" 22 #include "src/roots/roots.h" 23 24 namespace v8 { 25 namespace internal { 26 27 class AstValueFactory; 28 class AstRawString; 29 class AstConsString; 30 class LocalIsolate; 31 32 class V8_EXPORT_PRIVATE LocalFactory : public FactoryBase<LocalFactory> { 33 public: 34 explicit LocalFactory(Isolate* isolate); 35 read_only_roots()36 ReadOnlyRoots read_only_roots() const { return roots_; } 37 38 #define ROOT_ACCESSOR(Type, name, CamelName) inline Handle<Type> name(); 39 READ_ONLY_ROOT_LIST(ROOT_ACCESSOR) 40 // AccessorInfos appear mutable, but they're actually not mutated once they 41 // finish initializing. In particular, the root accessors are not mutated and 42 // are safe to access (as long as the off-thread job doesn't try to mutate 43 // them). ACCESSOR_INFO_ROOT_LIST(ROOT_ACCESSOR)44 ACCESSOR_INFO_ROOT_LIST(ROOT_ACCESSOR) 45 #undef ROOT_ACCESSOR 46 47 // The parser shouldn't allow the LocalFactory to get into a state where 48 // it generates errors. 49 Handle<Object> NewInvalidStringLengthError() { UNREACHABLE(); } NewRangeError(MessageTemplate template_index)50 Handle<Object> NewRangeError(MessageTemplate template_index) { 51 UNREACHABLE(); 52 } 53 54 private: 55 friend class FactoryBase<LocalFactory>; 56 57 // ------ 58 // Customization points for FactoryBase. 59 HeapObject AllocateRaw(int size, AllocationType allocation, 60 AllocationAlignment alignment = kWordAligned); 61 isolate()62 LocalIsolate* isolate() { 63 // Downcast to the privately inherited sub-class using c-style casts to 64 // avoid undefined behavior (as static_cast cannot cast across private 65 // bases). 66 // NOLINTNEXTLINE (google-readability-casting) 67 return (LocalIsolate*)this; // NOLINT(readability/casting) 68 } CanAllocateInReadOnlySpace()69 inline bool CanAllocateInReadOnlySpace() { return false; } EmptyStringRootIsInitialized()70 inline bool EmptyStringRootIsInitialized() { return true; } 71 // ------ 72 73 void AddToScriptList(Handle<Script> shared); 74 // ------ 75 76 ReadOnlyRoots roots_; 77 #ifdef DEBUG 78 bool a_script_was_added_to_the_script_list_ = false; 79 #endif 80 }; 81 82 } // namespace internal 83 } // namespace v8 84 85 #endif // V8_HEAP_LOCAL_FACTORY_H_ 86