v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
materialized-object-store.cc
Go to the documentation of this file.
1// Copyright 2021 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
6
8#include "src/heap/heap-inl.h"
10#include "src/objects/oddball.h"
11
12namespace v8 {
13namespace internal {
14
16 int index = StackIdToIndex(fp);
17 if (index == -1) {
19 }
21 CHECK_GT(array->length(), index);
22 return Cast<FixedArray>(Handle<Object>(array->get(index), isolate()));
23}
24
26 Address fp, DirectHandle<FixedArray> materialized_objects) {
27 int index = StackIdToIndex(fp);
28 if (index == -1) {
29 index = static_cast<int>(frame_fps_.size());
30 frame_fps_.push_back(fp);
31 }
32
34 array->set(index, *materialized_objects);
35}
36
38 auto it = std::find(frame_fps_.begin(), frame_fps_.end(), fp);
39 if (it == frame_fps_.end()) return false;
40 int index = static_cast<int>(std::distance(frame_fps_.begin(), it));
41
42 frame_fps_.erase(it);
43 Tagged<FixedArray> array = isolate()->heap()->materialized_objects();
44
45 CHECK_LT(index, array->length());
46 int fps_size = static_cast<int>(frame_fps_.size());
47 for (int i = index; i < fps_size; i++) {
48 array->set(i, array->get(i + 1));
49 }
50 array->set(fps_size, ReadOnlyRoots(isolate()).undefined_value());
51 return true;
52}
53
55 auto it = std::find(frame_fps_.begin(), frame_fps_.end(), fp);
56 return it == frame_fps_.end()
57 ? -1
58 : static_cast<int>(std::distance(frame_fps_.begin(), it));
59}
60
65
67 int length) {
69 if (array->length() >= length) {
70 return array;
71 }
72
73 int new_length = length > 10 ? length : 10;
75 new_length = 2 * array->length();
76 }
77
78 DirectHandle<FixedArray> new_array =
80 for (int i = 0; i < array->length(); i++) {
81 new_array->set(i, array->get(i));
82 }
83 Tagged<HeapObject> undefined_value =
84 ReadOnlyRoots(isolate()).undefined_value();
85 for (int i = array->length(); i < length; i++) {
86 new_array->set(i, undefined_value);
87 }
88 isolate()->heap()->SetRootMaterializedObjects(*new_array);
89 return new_array;
90}
91
92} // namespace internal
93} // namespace v8
Handle< FixedArray > NewFixedArray(int length, AllocationType allocation=AllocationType::kYoung)
V8_INLINE void SetRootMaterializedObjects(Tagged< FixedArray > objects)
Definition heap-inl.h:122
v8::internal::Factory * factory()
Definition isolate.h:1527
DirectHandle< FixedArray > EnsureStackEntries(int size)
DirectHandle< FixedArray > Get(Address fp)
void Set(Address fp, DirectHandle< FixedArray > materialized_objects)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define CHECK_GT(lhs, rhs)
#define CHECK_LT(lhs, rhs)