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,
stack->jslimit(), reinterpret_cast<void*>(stack->base()));
}
HandleScope scope(this);
Handle<WasmContinuationObject> continuation =
WasmContinuationObject::New(this, std::move(stack));
Handle<WasmContinuationObject> continuation = WasmContinuationObject::New(
this, std::move(stack), AllocationType::kOld);
heap()
->roots_table()
.slot(RootIndex::kActiveContinuation)
......@@ -4351,6 +4351,11 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
heap()->AddGCPrologueCallback(ResetBeforeGC, kGCTypeMarkSweepCompact,
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;
return true;
......
......@@ -1579,12 +1579,13 @@ Handle<PromiseResolveThenableJobTask> Factory::NewPromiseResolveThenableJobTask(
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.
static_assert(Foreign::kSize <= kMaxRegularHeapObjectSize);
Map map = *foreign_map();
Foreign foreign = Foreign::cast(AllocateRawWithImmortalMap(
map.instance_size(), AllocationType::kYoung, map));
Foreign foreign = Foreign::cast(
AllocateRawWithImmortalMap(map.instance_size(), allocation_type, map));
DisallowGarbageCollection no_gc;
foreign.AllocateExternalPointerEntries(isolate());
foreign.set_foreign_address(isolate(), addr);
......
......@@ -454,7 +454,8 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
Handle<JSReceiver> then, Handle<Context> context);
// 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);
......
......@@ -33,22 +33,24 @@ Handle<Managed<CppType>> Managed<CppType>::FromRawPtr(Isolate* isolate,
template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromUniquePtr(
Isolate* isolate, size_t estimated_size,
std::unique_ptr<CppType> unique_ptr) {
return FromSharedPtr(isolate, estimated_size, std::move(unique_ptr));
std::unique_ptr<CppType> unique_ptr, AllocationType allocation_type) {
return FromSharedPtr(isolate, estimated_size, std::move(unique_ptr),
allocation_type);
}
// static
template <class CppType>
Handle<Managed<CppType>> Managed<CppType>::FromSharedPtr(
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)
->AdjustAmountOfExternalAllocatedMemory(estimated_size);
auto destructor = new ManagedPtrDestructor(
estimated_size, new std::shared_ptr<CppType>{std::move(shared_ptr)},
Destructor);
Handle<Managed<CppType>> handle = Handle<Managed<CppType>>::cast(
isolate->factory()->NewForeign(reinterpret_cast<Address>(destructor)));
Handle<Managed<CppType>> handle =
Handle<Managed<CppType>>::cast(isolate->factory()->NewForeign(
reinterpret_cast<Address>(destructor), allocation_type));
Handle<Object> global_handle = isolate->global_handles()->Create(*handle);
destructor->global_handle_location_ = global_handle.location();
GlobalHandles::MakeWeak(destructor->global_handle_location_, destructor,
......
......@@ -79,12 +79,14 @@ class Managed : public Foreign {
// the unique pointer will be released.
static Handle<Managed<CppType>> FromUniquePtr(
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>}.
static Handle<Managed<CppType>> FromSharedPtr(
Isolate* isolate, size_t estimated_size,
std::shared_ptr<CppType> shared_ptr);
std::shared_ptr<CppType> shared_ptr,
AllocationType allocation_type = AllocationType::kYoung);
private:
// Internally this {Foreign} object stores a pointer to a new
......
......@@ -1768,18 +1768,19 @@ void DecodeI64ExceptionValue(Handle<FixedArray> encoded_values,
// static
Handle<WasmContinuationObject> WasmContinuationObject::New(
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()->sp = stack->base();
stack->jmpbuf()->fp = kNullAddress;
wasm::JumpBuffer* jmpbuf = stack->jmpbuf();
size_t external_size = stack->owned_size();
Handle<Foreign> managed_stack = Managed<wasm::StackMemory>::FromUniquePtr(
isolate, external_size, std::move(stack));
Handle<Foreign> foreign_jmpbuf =
isolate->factory()->NewForeign(reinterpret_cast<Address>(jmpbuf));
Handle<WasmContinuationObject> result = Handle<WasmContinuationObject>::cast(
isolate->factory()->NewStruct(WASM_CONTINUATION_OBJECT_TYPE));
isolate, external_size, std::move(stack), allocation_type);
Handle<Foreign> foreign_jmpbuf = isolate->factory()->NewForeign(
reinterpret_cast<Address>(jmpbuf), allocation_type);
Handle<WasmContinuationObject> result =
Handle<WasmContinuationObject>::cast(isolate->factory()->NewStruct(
WASM_CONTINUATION_OBJECT_TYPE, allocation_type));
result->set_jmpbuf(*foreign_jmpbuf);
result->set_stack(*managed_stack);
result->set_parent(*parent);
......@@ -1788,9 +1789,11 @@ Handle<WasmContinuationObject> WasmContinuationObject::New(
// static
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();
return New(isolate, std::move(stack), handle(parent, isolate));
return New(isolate, std::move(stack), handle(parent, isolate),
allocation_type);
}
// static
......
......@@ -1026,7 +1026,8 @@ class WasmContinuationObject
Struct> {
public:
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(
Isolate* isolate, Handle<WasmContinuationObject> parent);
......@@ -1037,7 +1038,8 @@ class WasmContinuationObject
private:
static Handle<WasmContinuationObject> New(
Isolate* isolate, std::unique_ptr<wasm::StackMemory> stack,
Handle<HeapObject> parent);
Handle<HeapObject> parent,
AllocationType allocation_type = AllocationType::kYoung);
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