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

src: invoke per-isolate setters earlier #25608

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

This patch moves the invocation of:

  • SetHostInitializeImportMetaObjectCallback
  • SetHostImportModuleDynamicallyCallback
  • SetPromiseRejectCallback

and the DTrace-related:

  • AddGCPrologueCallback(DTraceGCStartCallback)
  • AddGCEpilogueCallback(DTraceGCEndCallback).

into node::NewIsolate(), and moves the performance-timeline-related:

  • AddGCPrologueCallback(performance::MarkGarbageCollectionStart)
  • AddGCEpilogueCallback(performance::MarkGarbageCollectionEnd)

that needs per-Environment data into the Environment constructor,
instead of scattering the initialization code around in bindings.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

This patch moves the invocation of:

- `SetHostInitializeImportMetaObjectCallback`
- `SetHostImportModuleDynamicallyCallback`
- `SetPromiseRejectCallback`

and the DTrace-related:

- `AddGCPrologueCallback(DTraceGCStartCallback)`
- `AddGCEpilogueCallback(DTraceGCEndCallback)`.

into `node::NewIsolate()`, and moves the performance-timeline-related:

- `AddGCPrologueCallback(performance::MarkGarbageCollectionStart)`
- `AddGCEpilogueCallback(performance::MarkGarbageCollectionEnd)`

that needs per-Environment data into the `Environment` constructor,
instead of scattering the initialization code around in bindings.
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Jan 21, 2019

// NOTE: the following two callbacks currently CHECKs that the isolates
// have associated environments.
isolate->SetHostInitializeImportMetaObjectCallback(
Copy link
Member Author

@joyeecheung joyeecheung Jan 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure if we should do this here, or in Environment constructor, since these two callbacks do not handle the cases when the isolates' current context does not have Environments associated. Does it make sense to simply crash if the user tries to access import() or import.meta from a context without an associated environment? Or should we return an empty Maybe/do nothing in the callbacks instead? Or should we postpone this to the Environment initialization? (But then the Environments would control per-isolate states)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s tricky… I think for now crashing is okay (and the best we can do), and anything more would require interaction with embedders (which would be the main source for this not working).

Copy link
Member

@devsnek devsnek Jan 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think these esm ones should have been moved. they are set in response to core opting into handling them. if the handlers don't get attached, we shouldn't have these handlers enabled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with @devsnek. Embedders can install their own after the call to NewIsolate().

@joyeecheung
Copy link
Member Author

@joyeecheung joyeecheung requested review from addaleax and bnoordhuis and removed request for addaleax January 21, 2019 12:46

// NOTE: the following two callbacks currently CHECKs that the isolates
// have associated environments.
isolate->SetHostInitializeImportMetaObjectCallback(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s tricky… I think for now crashing is okay (and the best we can do), and anything more would require interaction with embedders (which would be the main source for this not working).

@@ -440,8 +432,6 @@ void Initialize(Local<Object> target,
env->constants_string(),
constants,
attr).ToChecked();

SetupGarbageCollectionTracking(env);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually prefer for this to stay here. It makes the code more local and more obvious to me, and only adds the callbacks when they are actually used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax this is currently unconditionally called when the isolate goes through bootstrapping - maybe this should be delayed until the first time the user adds an gc performance observer..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joyeecheung If that’s feasible, it sounds good to me, but I’m more worried about code organization than performance.

Also, I’m just noticing that we never remove these listeners … that’s a bug that we should fix if we can?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #25647 – I’m happy to close it if you want to do sth in this PR :)

Copy link
Member Author

@joyeecheung joyeecheung Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax Thanks, I think I'd prefer wrapping SetupGarbageCollectionTracking into a binding method and call it from JS when it's actually needed - that's probably orthorgnal to #25647


// NOTE: the following two callbacks currently CHECKs that the isolates
// have associated environments.
isolate->SetHostInitializeImportMetaObjectCallback(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with @devsnek. Embedders can install their own after the call to NewIsolate().

isolate->SetHostImportModuleDynamicallyCallback(
loader::ModuleWrap::ImportModuleDynamically);

#if defined HAVE_DTRACE || defined HAVE_ETW
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're here: #if defined(HAVE_DTRACE) || defined(HAVE_ETW) - the paren-less style is unidiomatic.

@joyeecheung joyeecheung added the blocked PRs that are blocked by other issues or PRs. label Jan 31, 2019
@joyeecheung
Copy link
Member Author

Blocked by #25853

@joyeecheung joyeecheung removed the blocked PRs that are blocked by other issues or PRs. label Feb 7, 2019
@joyeecheung
Copy link
Member Author

On a second thought, I think the current invocation order looks more reasonable, so I am closing this PR.

@joyeecheung joyeecheung closed this Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants