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