Commit 1a061c8f authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

[heap, wasm] Pretenure allocations during Isolate initialization

All objects allocated during Isolate initialization are long living and
should be allocated in old space.

Bug: v8:12612
Change-Id: I394cbaa2ba45750b98bfa219afa0c538552de9c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3785148Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82006}
parent 2d367eb3
...@@ -4339,8 +4339,8 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data, ...@@ -4339,8 +4339,8 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
stack->jslimit(), reinterpret_cast<void*>(stack->base())); stack->jslimit(), reinterpret_cast<void*>(stack->base()));
} }
HandleScope scope(this); HandleScope scope(this);
Handle<WasmContinuationObject> continuation = Handle<WasmContinuationObject> continuation = WasmContinuationObject::New(
WasmContinuationObject::New(this, std::move(stack)); this, std::move(stack), AllocationType::kOld);
heap() heap()
->roots_table() ->roots_table()
.slot(RootIndex::kActiveContinuation) .slot(RootIndex::kActiveContinuation)
...@@ -4351,6 +4351,11 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data, ...@@ -4351,6 +4351,11 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
heap()->AddGCPrologueCallback(ResetBeforeGC, kGCTypeMarkSweepCompact, heap()->AddGCPrologueCallback(ResetBeforeGC, kGCTypeMarkSweepCompact,
nullptr); nullptr);
// Isolate initialization allocates long living objects that should be
// pretentured to old space.
DCHECK_IMPLIES(heap()->new_space(), (heap()->new_space()->Size() == 0) &&
(heap()->gc_count() == 0));
initialized_ = true; initialized_ = true;
return true; return true;
......
...@@ -1579,12 +1579,13 @@ Handle<PromiseResolveThenableJobTask> Factory::NewPromiseResolveThenableJobTask( ...@@ -1579,12 +1579,13 @@ Handle<PromiseResolveThenableJobTask> Factory::NewPromiseResolveThenableJobTask(
return handle(microtask, isolate()); return handle(microtask, isolate());
} }
Handle<Foreign> Factory::NewForeign(Address addr) { Handle<Foreign> Factory::NewForeign(Address addr,
AllocationType allocation_type) {
// Statically ensure that it is safe to allocate foreigns in paged spaces. // Statically ensure that it is safe to allocate foreigns in paged spaces.
static_assert(Foreign::kSize <= kMaxRegularHeapObjectSize); static_assert(Foreign::kSize <= kMaxRegularHeapObjectSize);
Map map = *foreign_map(); Map map = *foreign_map();
Foreign foreign = Foreign::cast(AllocateRawWithImmortalMap( Foreign foreign = Foreign::cast(
map.instance_size(), AllocationType::kYoung, map)); AllocateRawWithImmortalMap(map.instance_size(), allocation_type, map));
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
foreign.AllocateExternalPointerEntries(isolate()); foreign.AllocateExternalPointerEntries(isolate());
foreign.set_foreign_address(isolate(), addr); foreign.set_foreign_address(isolate(), addr);
......
...@@ -454,7 +454,8 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> { ...@@ -454,7 +454,8 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
Handle<JSReceiver> then, Handle<Context> context); Handle<JSReceiver> then, Handle<Context> context);
// Foreign objects are pretenured when allocated by the bootstrapper. // Foreign objects are pretenured when allocated by the bootstrapper.
Handle<Foreign> NewForeign(Address addr); Handle<Foreign> NewForeign(
Address addr, AllocationType allocation_type = AllocationType::kYoung);
Handle<Cell> NewCell(Handle<Object> value); Handle<Cell> NewCell(Handle<Object> value);
......
...@@ -33,22 +33,24 @@ Handle<Managed<CppType>> Managed<CppType>::FromRawPtr(Isolate* isolate, ...@@ -33,22 +33,24 @@ Handle<Managed<CppType>> Managed<CppType>::FromRawPtr(Isolate* isolate,
template <class CppType> template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromUniquePtr( Handle<Managed<CppType>> Managed<CppType>::FromUniquePtr(
Isolate* isolate, size_t estimated_size, Isolate* isolate, size_t estimated_size,
std::unique_ptr<CppType> unique_ptr) { std::unique_ptr<CppType> unique_ptr, AllocationType allocation_type) {
return FromSharedPtr(isolate, estimated_size, std::move(unique_ptr)); return FromSharedPtr(isolate, estimated_size, std::move(unique_ptr),
allocation_type);
} }
// static // static
template <class CppType> template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromSharedPtr( Handle<Managed<CppType>> Managed<CppType>::FromSharedPtr(
Isolate* isolate, size_t estimated_size, Isolate* isolate, size_t estimated_size,
std::shared_ptr<CppType> shared_ptr) { std::shared_ptr<CppType> shared_ptr, AllocationType allocation_type) {
reinterpret_cast<v8::Isolate*>(isolate) reinterpret_cast<v8::Isolate*>(isolate)
->AdjustAmountOfExternalAllocatedMemory(estimated_size); ->AdjustAmountOfExternalAllocatedMemory(estimated_size);
auto destructor = new ManagedPtrDestructor( auto destructor = new ManagedPtrDestructor(
estimated_size, new std::shared_ptr<CppType>{std::move(shared_ptr)}, estimated_size, new std::shared_ptr<CppType>{std::move(shared_ptr)},
Destructor); Destructor);
Handle<Managed<CppType>> handle = Handle<Managed<CppType>>::cast( Handle<Managed<CppType>> handle =
isolate->factory()->NewForeign(reinterpret_cast<Address>(destructor))); Handle<Managed<CppType>>::cast(isolate->factory()->NewForeign(
reinterpret_cast<Address>(destructor), allocation_type));
Handle<Object> global_handle = isolate->global_handles()->Create(*handle); Handle<Object> global_handle = isolate->global_handles()->Create(*handle);
destructor->global_handle_location_ = global_handle.location(); destructor->global_handle_location_ = global_handle.location();
GlobalHandles::MakeWeak(destructor->global_handle_location_, destructor, GlobalHandles::MakeWeak(destructor->global_handle_location_, destructor,
......
...@@ -79,12 +79,14 @@ class Managed : public Foreign { ...@@ -79,12 +79,14 @@ class Managed : public Foreign {
// the unique pointer will be released. // the unique pointer will be released.
static Handle<Managed<CppType>> FromUniquePtr( static Handle<Managed<CppType>> FromUniquePtr(
Isolate* isolate, size_t estimated_size, Isolate* isolate, size_t estimated_size,
std::unique_ptr<CppType> unique_ptr); std::unique_ptr<CppType> unique_ptr,
AllocationType allocation_type = AllocationType::kYoung);
// Create a {Managed<CppType>} from an existing {std::shared_ptr<CppType>}. // Create a {Managed<CppType>} from an existing {std::shared_ptr<CppType>}.
static Handle<Managed<CppType>> FromSharedPtr( static Handle<Managed<CppType>> FromSharedPtr(
Isolate* isolate, size_t estimated_size, Isolate* isolate, size_t estimated_size,
std::shared_ptr<CppType> shared_ptr); std::shared_ptr<CppType> shared_ptr,
AllocationType allocation_type = AllocationType::kYoung);
private: private:
// Internally this {Foreign} object stores a pointer to a new // Internally this {Foreign} object stores a pointer to a new
......
...@@ -1768,18 +1768,19 @@ void DecodeI64ExceptionValue(Handle<FixedArray> encoded_values, ...@@ -1768,18 +1768,19 @@ void DecodeI64ExceptionValue(Handle<FixedArray> encoded_values,
// static // static
Handle<WasmContinuationObject> WasmContinuationObject::New( Handle<WasmContinuationObject> WasmContinuationObject::New(
Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack, Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack,
Handle<HeapObject> parent) { Handle<HeapObject> parent, AllocationType allocation_type) {
stack->jmpbuf()->stack_limit = stack->jslimit(); stack->jmpbuf()->stack_limit = stack->jslimit();
stack->jmpbuf()->sp = stack->base(); stack->jmpbuf()->sp = stack->base();
stack->jmpbuf()->fp = kNullAddress; stack->jmpbuf()->fp = kNullAddress;
wasm::JumpBuffer* jmpbuf = stack->jmpbuf(); wasm::JumpBuffer* jmpbuf = stack->jmpbuf();
size_t external_size = stack->owned_size(); size_t external_size = stack->owned_size();
Handle<Foreign> managed_stack = Managed<wasm::StackMemory>::FromUniquePtr( Handle<Foreign> managed_stack = Managed<wasm::StackMemory>::FromUniquePtr(
isolate, external_size, std::move(stack)); isolate, external_size, std::move(stack), allocation_type);
Handle<Foreign> foreign_jmpbuf = Handle<Foreign> foreign_jmpbuf = isolate->factory()->NewForeign(
isolate->factory()->NewForeign(reinterpret_cast<Address>(jmpbuf)); reinterpret_cast<Address>(jmpbuf), allocation_type);
Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast( Handle<WasmContinuationObject> result =
isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE)); Handle<WasmContinuationObject>::cast(isolate->factory()->NewStruct(
WASM_CONTINUATION_OBJECT_TYPE, allocation_type));
result->set_jmpbuf(*foreign_jmpbuf); result->set_jmpbuf(*foreign_jmpbuf);
result->set_stack(*managed_stack); result->set_stack(*managed_stack);
result->set_parent(*parent); result->set_parent(*parent);
...@@ -1788,9 +1789,11 @@ Handle<WasmContinuationObject> WasmContinuationObject::New( ...@@ -1788,9 +1789,11 @@ Handle<WasmContinuationObject> WasmContinuationObject::New(
// static // static
Handle<WasmContinuationObject> WasmContinuationObject::New( Handle<WasmContinuationObject> WasmContinuationObject::New(
Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack) { Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack,
AllocationType allocation_type) {
auto parent = ReadOnlyRoots(isolate).undefined_value(); auto parent = ReadOnlyRoots(isolate).undefined_value();
return New(isolate, std::move(stack), handle(parent, isolate)); return New(isolate, std::move(stack), handle(parent, isolate),
allocation_type);
} }
// static // static
......
...@@ -1026,7 +1026,8 @@ class WasmContinuationObject ...@@ -1026,7 +1026,8 @@ class WasmContinuationObject
Struct> { Struct> {
public: public:
static Handle<WasmContinuationObject> New( static Handle<WasmContinuationObject> New(
Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack); Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack,
AllocationType allocation_type = AllocationType::kYoung);
static Handle<WasmContinuationObject> New( static Handle<WasmContinuationObject> New(
Isolate* isolate, Handle<WasmContinuationObject> parent); Isolate* isolate, Handle<WasmContinuationObject> parent);
...@@ -1037,7 +1038,8 @@ class WasmContinuationObject ...@@ -1037,7 +1038,8 @@ class WasmContinuationObject
private: private:
static Handle<WasmContinuationObject> New( static Handle<WasmContinuationObject> New(
Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack, Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack,
Handle<HeapObject> parent); Handle<HeapObject> parent,
AllocationType allocation_type = AllocationType::kYoung);
TQ_OBJECT_CONSTRUCTORS(WasmContinuationObject) TQ_OBJECT_CONSTRUCTORS(WasmContinuationObject)
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment