mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Store snapshot templates in isolate, not context.
This lets us load the isolate without having to create a temp/dummy context just to get the templates. Call ContextDisposedNotification when a context is removed. Supposedly this can help/hint to the isolate about memory management.
This commit is contained in:
@@ -166,8 +166,8 @@ pub fn deinit(self: *Context) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self.handle_scope) |*scope| {
|
if (self.handle_scope) |*scope| {
|
||||||
scope.deinit();
|
|
||||||
v8.v8__Context__Exit(self.handle);
|
v8.v8__Context__Exit(self.handle);
|
||||||
|
scope.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,14 +93,10 @@ pub fn init(allocator: Allocator, platform: *const Platform, snapshot: *Snapshot
|
|||||||
var temp_scope: js.HandleScope = undefined;
|
var temp_scope: js.HandleScope = undefined;
|
||||||
temp_scope.init(isolate);
|
temp_scope.init(isolate);
|
||||||
defer temp_scope.deinit();
|
defer temp_scope.deinit();
|
||||||
const context_handle = isolate.createContextHandle(null, null);
|
|
||||||
|
|
||||||
v8.v8__Context__Enter(context_handle);
|
|
||||||
defer v8.v8__Context__Exit(context_handle);
|
|
||||||
|
|
||||||
inline for (JsApis, 0..) |JsApi, i| {
|
inline for (JsApis, 0..) |JsApi, i| {
|
||||||
JsApi.Meta.class_id = i;
|
JsApi.Meta.class_id = i;
|
||||||
const data = v8.v8__Context__GetDataFromSnapshotOnce(context_handle, snapshot.data_start + i);
|
const data = v8.v8__Isolate__GetDataFromSnapshotOnce(isolate.handle, snapshot.data_start + i);
|
||||||
const function_handle: *const v8.FunctionTemplate = @ptrCast(data);
|
const function_handle: *const v8.FunctionTemplate = @ptrCast(data);
|
||||||
// Make function template global/persistent
|
// Make function template global/persistent
|
||||||
v8.v8__Global__New(isolate.handle, @ptrCast(function_handle), &globals[i]);
|
v8.v8__Global__New(isolate.handle, @ptrCast(function_handle), &globals[i]);
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ pub fn removeContext(self: *ExecutionWorld) void {
|
|||||||
self.persisted_context.?.deinit();
|
self.persisted_context.?.deinit();
|
||||||
self.persisted_context = null;
|
self.persisted_context = null;
|
||||||
|
|
||||||
|
self.env.isolate.notifyContextDisposed();
|
||||||
_ = self.context_arena.reset(.{ .retain_with_limit = CONTEXT_ARENA_RETAIN });
|
_ = self.context_arena.reset(.{ .retain_with_limit = CONTEXT_ARENA_RETAIN });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ pub fn lowMemoryNotification(self: Isolate) void {
|
|||||||
v8.v8__Isolate__LowMemoryNotification(self.handle);
|
v8.v8__Isolate__LowMemoryNotification(self.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn notifyContextDisposed(self: Isolate) void {
|
||||||
|
_ = v8.v8__Isolate__ContextDisposedNotification(self.handle);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getHeapStatistics(self: Isolate) v8.HeapStatistics {
|
pub fn getHeapStatistics(self: Isolate) v8.HeapStatistics {
|
||||||
var res: v8.HeapStatistics = undefined;
|
var res: v8.HeapStatistics = undefined;
|
||||||
v8.v8__Isolate__GetHeapStatistics(self.handle, &res);
|
v8.v8__Isolate__GetHeapStatistics(self.handle, &res);
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ pub fn create() !Snapshot {
|
|||||||
var last_data_index: usize = 0;
|
var last_data_index: usize = 0;
|
||||||
inline for (JsApis, 0..) |_, i| {
|
inline for (JsApis, 0..) |_, i| {
|
||||||
@setEvalBranchQuota(10_000);
|
@setEvalBranchQuota(10_000);
|
||||||
const data_index = v8.v8__SnapshotCreator__AddData2(snapshot_creator, context, @ptrCast(templates[i]));
|
const data_index = v8.v8__SnapshotCreator__AddData(snapshot_creator, @ptrCast(templates[i]));
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
data_start = data_index;
|
data_start = data_index;
|
||||||
last_data_index = data_index;
|
last_data_index = data_index;
|
||||||
|
|||||||
Reference in New Issue
Block a user