0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-12 00:54:15 -05:00

Fix the 'heap_limits' test (#430)

After upgrading to V8 8.6.337, with a 20 MB heap limit, the
near-heap-limit callback never gets called before V8 runs out of memory.

It turns out that this test exhibits memory allocation behavior which
produces so little actual garbage that 'scavenge' type garbage
collections make memory usage go up rather than down. Because of this,
V8 runs out of memory in the middle of a garbage collection cycle, after
it has already decided that there's no need to run the near-heap-limit
callback.

The issue is fixed by making sure that some actual garbage is produced
alongside with the retained objects that will eventually fill up the
heap.
This commit is contained in:
Bert Belder 2020-08-05 22:45:25 +02:00
parent 24fa76aaaa
commit 954163ab07
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -3334,7 +3334,7 @@ extern "C" fn heap_limit_callback(
fn heap_limits() {
let _setup_guard = setup();
let params = v8::CreateParams::default().heap_limits(0, 20 * 1024 * 1024); // 20 MB
let params = v8::CreateParams::default().heap_limits(0, 10 << 20); // 10 MB.
let isolate = &mut v8::Isolate::new(params);
let mut test_state = TestHeapLimitState::default();
@ -3342,10 +3342,23 @@ fn heap_limits() {
isolate.add_near_heap_limit_callback(heap_limit_callback, state_ptr);
let scope = &mut v8::HandleScope::new(isolate);
let context = v8::Context::new(scope);
let scope = &mut v8::ContextScope::new(scope, context);
// Allocate some strings; 20 MB is reached at about 800k iterations.
// Allocate JavaScript arrays until V8 calls the near-heap-limit callback.
// It takes about 100-200k iterations of this loop to get to that point.
for _ in 0..1_000_000 {
v8::String::new(scope, "HelloWorld").unwrap();
eval(
scope,
r#"
"hello 🦕 world"
.repeat(5)
.split("🦕", 2)
.map((s) => s.split(""))
.shift()
"#,
)
.unwrap();
if test_state.near_heap_limit_callback_calls > 0 {
break;
}