5 #include "src/builtins/constants-table-builder.h" 7 #include "src/heap/heap-inl.h" 8 #include "src/isolate.h" 9 #include "src/roots-inl.h" 14 BuiltinsConstantsTableBuilder::BuiltinsConstantsTableBuilder(Isolate* isolate)
15 : isolate_(isolate), map_(isolate->heap()) {
17 DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(),
18 isolate_->heap()->builtins_constants_table());
23 DCHECK(RootsTable::IsImmortalImmovable(RootIndex::kEmptyFixedArray));
26 uint32_t BuiltinsConstantsTableBuilder::AddObject(Handle<Object>
object) {
30 RootIndex root_list_index;
31 DCHECK(!isolate_->roots_table().IsRootHandle(
object, &root_list_index));
34 DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(),
35 isolate_->heap()->builtins_constants_table());
38 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
41 DCHECK(isolate_->ShouldLoadConstantsFromRootList());
44 uint32_t* maybe_key = map_.Find(
object);
45 if (maybe_key ==
nullptr) {
46 DCHECK(object->IsHeapObject());
48 map_.Set(
object, index);
55 void BuiltinsConstantsTableBuilder::PatchSelfReference(
56 Handle<Object> self_reference, Handle<Code> code_object) {
60 RootIndex root_list_index;
61 DCHECK(!isolate_->roots_table().IsRootHandle(code_object, &root_list_index));
64 DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(),
65 isolate_->heap()->builtins_constants_table());
67 DCHECK(isolate_->ShouldLoadConstantsFromRootList());
69 DCHECK(self_reference->IsOddball());
70 DCHECK(Oddball::cast(*self_reference)->kind() ==
71 Oddball::kSelfReferenceMarker);
76 DCHECK(*self_reference != ReadOnlyRoots(isolate_).self_reference_marker());
80 if (map_.Delete(self_reference, &key)) {
81 DCHECK(code_object->IsCode());
82 map_.Set(code_object, key);
86 void BuiltinsConstantsTableBuilder::Finalize() {
87 HandleScope handle_scope(isolate_);
89 DCHECK_EQ(ReadOnlyRoots(isolate_).empty_fixed_array(),
90 isolate_->heap()->builtins_constants_table());
91 DCHECK(isolate_->ShouldLoadConstantsFromRootList());
94 if (map_.size() == 0)
return;
96 Handle<FixedArray> table =
97 isolate_->factory()->NewFixedArray(map_.size(), TENURED);
99 Builtins* builtins = isolate_->builtins();
100 ConstantsMap::IteratableScope it_scope(&map_);
101 for (
auto it = it_scope.begin(); it != it_scope.end(); ++it) {
103 Object* value = it.key();
104 if (value->IsCode() && Code::cast(value)->kind() == Code::BUILTIN) {
109 value = builtins->builtin(Code::cast(value)->builtin_index());
111 DCHECK(value->IsHeapObject());
112 table->set(index, value);
116 for (
int i = 0;
i < map_.size();
i++) {
117 DCHECK(table->get(
i)->IsHeapObject());
118 DCHECK_NE(ReadOnlyRoots(isolate_).undefined_value(), table->get(
i));
119 DCHECK_NE(ReadOnlyRoots(isolate_).self_reference_marker(), table->get(
i));
123 isolate_->heap()->SetBuiltinsConstantsTable(*table);