Skip to content

Allow managing V8 heap limits#427

Merged
piscisaureus merged 17 commits into
denoland:masterfrom
mraerino:feat/heap-limits
Jul 30, 2020
Merged

Allow managing V8 heap limits#427
piscisaureus merged 17 commits into
denoland:masterfrom
mraerino:feat/heap-limits

Conversation

@mraerino
Copy link
Copy Markdown
Contributor

@mraerino mraerino commented Jul 28, 2020

Applies to denoland/deno#6916

V8 allows setting the max_old_generation_size and max_young_generation_size create parameters through a handy helper: https://chromium.googlesource.com/v8/v8/+/e423f0040333dd3ab410b3c6cab5b71a4f75fa6a/include/v8.h#6409

This PR also exposes the methods to register a callback when the limit is reached, so a crash of V8 can be avoided.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jul 28, 2020

CLA assistant check
All committers have signed the CLA.

Comment thread src/binding.cc Outdated
@mraerino mraerino marked this pull request as ready for review July 28, 2020 13:59
@mraerino mraerino requested a review from piscisaureus July 28, 2020 13:59
@mraerino mraerino marked this pull request as draft July 28, 2020 14:41
@mraerino
Copy link
Copy Markdown
Contributor Author

mraerino commented Jul 28, 2020

ok, when trying this out in deno_core i'm getting a linker error...

  = note: Undefined symbols for architecture x86_64:
            "_v8__ResourceConstraints__ConfigureDefaultsFromHeapSize", referenced from:
                rusty_v8::isolate_create_params::raw::ResourceConstraints::configure_defaults_from_heap_size::h0bff31ae2991bf2e in librusty_v8-22814f38384a97cd.rlib(rusty_v8-22814f38384a97cd.3vpkah4o8p3w6byd.rcgu.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

@bartlomieju
Copy link
Copy Markdown
Member

ok, when trying this out in deno_core i'm getting a linker error...

  = note: Undefined symbols for architecture x86_64:
            "_v8__ResourceConstraints__ConfigureDefaultsFromHeapSize", referenced from:
                rusty_v8::isolate_create_params::raw::ResourceConstraints::configure_defaults_from_heap_size::h0bff31ae2991bf2e in librusty_v8-22814f38384a97cd.rlib(rusty_v8-22814f38384a97cd.3vpkah4o8p3w6byd.rcgu.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

@mraerino cargo clean && cargo build fixes usually fixes those errors

@piscisaureus
Copy link
Copy Markdown
Member

ok, when trying this out in deno_core i'm getting a linker error...

Yeah that's a known issue. Once the build script has either downloaded or built libdeno.{a|lib} it will not automatically rebuild/re-download it when there are updates. Patches that fix this are always welcome :)

Comment thread src/isolate.rs Outdated
/// Don't pass a null-pointer for the callback!
/// Make sure the callback only casts `data` to the type the `data` argument
/// here.
pub unsafe fn add_near_heap_limit_callback(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this needs to be unsafe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, the caller might have to do some casting but i'm thinking of making a generics-based safe impl in Deno for this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generics based safe is a bit tricky. You'd have to pass an owned pointer like Box<T> or Rc<T>. This thing would need to be dropped when the isolate is disposed or the heap limit callback is removed.

Copy link
Copy Markdown
Contributor Author

@mraerino mraerino Jul 29, 2020

Choose a reason for hiding this comment

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

yup, that's the idea

Comment thread src/isolate.rs Outdated
Comment thread src/isolate_create_params.rs Outdated
@mraerino
Copy link
Copy Markdown
Contributor Author

i'm still getting a linker error when running cargo test -p deno_core in Deno.

I have this change in my core/Cargo.toml:

-rusty_v8 = "0.7.0"
+rusty_v8 = { path = "../../rusty_v8" }

This is how i'm using it: denoland/deno#6914

I did cargo clean in both projects and deno builds fine, but tests fail with the linker problem. Any clues?

@piscisaureus
Copy link
Copy Markdown
Member

The implementation of this "feature" looks good to me now. The only thing that's missing is a test.

@piscisaureus
Copy link
Copy Markdown
Member

piscisaureus commented Jul 29, 2020 via email

@mraerino
Copy link
Copy Markdown
Contributor Author

Are you sure you had V8_FROM_SOURCE set when you built it?

somehow missed that concept. using it now, thanks!

@mraerino mraerino marked this pull request as ready for review July 29, 2020 23:53
@mraerino mraerino requested a review from piscisaureus July 29, 2020 23:54
Comment thread tests/test_api.rs Outdated
Comment thread tests/test_api.rs Outdated
mraerino and others added 2 commits July 30, 2020 12:14
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
@mraerino
Copy link
Copy Markdown
Contributor Author

tests added. could you review again?

Copy link
Copy Markdown
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

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

LGTM - thanks @mraerino!

@piscisaureus piscisaureus merged commit b0dc42f into denoland:master Jul 30, 2020
@mraerino mraerino deleted the feat/heap-limits branch August 5, 2020 00:14
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

Successfully merging this pull request may close these issues.

5 participants