Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realms aka agents support #71

Open
playXE opened this issue Jul 2, 2021 · 8 comments
Open

Realms aka agents support #71

playXE opened this issue Jul 2, 2021 · 8 comments
Assignees

Comments

@playXE
Copy link
Collaborator

playXE commented Jul 2, 2021

Right now there is a single global object per runtime instance but ECMA262 defines realms.

https://262.ecma-international.org/#sec-code-realms

@jameslahm
Copy link
Member

I'd like to work on this~

@andrieshiemstra
Copy link
Contributor

Yeah this would be cool, quickjs calls these contexts

@playXE playXE assigned playXE and jameslahm and unassigned playXE Jul 2, 2021
@playXE
Copy link
Collaborator Author

playXE commented Jul 2, 2021

@jameslahm if you want to work on them I'll assign you to this issue. :)

@andrieshiemstra
Copy link
Contributor

My main reason for being interested in Realms is the ability to share loaded modules between Realms

The downside of doing this with spidermonkey/quickjs is that they don't realy provide control over how and how many modules are stored or cached.. this means that my projects need to shutdown and restart Runtimes every now and then to unload modules.

It would be nice if starlight got the ability to access the loaded modules in the Runtime, and be able to unload them.. and/or controll how many are cached for how long...

@playXE
Copy link
Collaborator Author

playXE commented Jul 4, 2021

@andrieshiemstra I think you can already unload modules just fine because they are stored inside HashMap<String,ModuleKind> so that should not be a big problem. Why I want realms is that because they make it easy to run test262 suite. Right now for each test262 test new runtime instance is created which takes some time: allocate 2GB of memory for GC, setup heap free list, etc. This time is not the slowest tho, Snapshots help to save it by a lot and running test262 does not take ten or twenty minutes but just a few minutes and now imagine how much time could be saved when there will be realms that are much cheaper compared to runtime.

@andrieshiemstra
Copy link
Contributor

Ok, and implementation wise, would there be a way for JsNativeFunctions to lookup the current realm? or even pass the &Realm to native unctions?

E.g. i'm working on a fetch api and would like to define the function and structs once at runtime/global level but init a CookieContainer per Realm

@playXE
Copy link
Collaborator Author

playXE commented Jul 4, 2021

I think realms should be stored inside the runtime and to access them Runtime::realm() should be used or something like that.

@playXE
Copy link
Collaborator Author

playXE commented Jul 4, 2021

Hmm Starlight's new GC allows us to get access to runtime instance from any GC allocated object so I guess this could also be used to obtain realm or runtime instance when you do not have direct access to it. It is possible due to how heap is implemented. We can identify small objects allocated inside blocks and it allows us to store runtime instance in the block and for large allocation runtime instance pointer can be stored directly in the header.

fn get_rt<T>(obj: GcPointer<T>) -> RuntimeRef {
    if obj.is_precise() {
       PreciseAllocation::from_cell(obj).runtime
    } else {
       Block::from_cell(obj).runtime
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants