mirror of
https://github.com/phpv8/v8js.git
synced 2025-01-05 09:31:52 +00:00
send LowMemoryNotification before imposing memory limit, fixes #217
This commit is contained in:
parent
4faab8842c
commit
b2eb89e49e
@ -40,6 +40,14 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /*
|
|||||||
|
|
||||||
v8::Locker locker(isolate);
|
v8::Locker locker(isolate);
|
||||||
v8::HeapStatistics hs;
|
v8::HeapStatistics hs;
|
||||||
|
bool send_notification, has_sent_notification;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (send_notification) {
|
||||||
|
isolate->LowMemoryNotification();
|
||||||
|
has_sent_notification = true;
|
||||||
|
}
|
||||||
|
|
||||||
isolate->GetHeapStatistics(&hs);
|
isolate->GetHeapStatistics(&hs);
|
||||||
|
|
||||||
V8JSG(timer_mutex).lock();
|
V8JSG(timer_mutex).lock();
|
||||||
@ -54,13 +62,20 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /*
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (timer_ctx->memory_limit > 0 && hs.used_heap_size() > timer_ctx->memory_limit) {
|
if (timer_ctx->memory_limit > 0 && hs.used_heap_size() > timer_ctx->memory_limit) {
|
||||||
|
if (has_sent_notification) {
|
||||||
timer_ctx->killed = true;
|
timer_ctx->killed = true;
|
||||||
v8::V8::TerminateExecution(c->isolate);
|
v8::V8::TerminateExecution(c->isolate);
|
||||||
c->memory_limit_hit = true;
|
c->memory_limit_hit = true;
|
||||||
|
} else {
|
||||||
|
// force garbage collection, then check again
|
||||||
|
send_notification = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
V8JSG(timer_mutex).unlock();
|
V8JSG(timer_mutex).unlock();
|
||||||
|
} while(send_notification != has_sent_notification);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -209,10 +209,15 @@ void v8js_v8_call(v8js_ctx *c, zval **return_value,
|
|||||||
v8::HeapStatistics hs;
|
v8::HeapStatistics hs;
|
||||||
isolate->GetHeapStatistics(&hs);
|
isolate->GetHeapStatistics(&hs);
|
||||||
|
|
||||||
|
if (hs.used_heap_size() > memory_limit) {
|
||||||
|
isolate->LowMemoryNotification();
|
||||||
|
isolate->GetHeapStatistics(&hs);
|
||||||
|
|
||||||
if (hs.used_heap_size() > memory_limit) {
|
if (hs.used_heap_size() > memory_limit) {
|
||||||
c->memory_limit_hit = true;
|
c->memory_limit_hit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (c->memory_limit_hit) {
|
if (c->memory_limit_hit) {
|
||||||
// Execution has been terminated due to memory limit
|
// Execution has been terminated due to memory limit
|
||||||
|
Loading…
Reference in New Issue
Block a user