@@ -40,27 +40,47 @@ static void v8js_timer_interrupt_handler(v8::Isolate *isolate, void *data) { /*
4040
4141 v8::Locker locker (isolate);
4242 v8::HeapStatistics hs;
43- isolate->GetHeapStatistics (&hs);
43+ bool send_notification = false ;
44+ bool has_sent_notification = false ;
4445
45- V8JSG (timer_mutex).lock ();
46+ do {
47+ if (send_notification) {
48+ #if PHP_V8_API_VERSION >= 3028036
49+ isolate->LowMemoryNotification ();
50+ #else
51+ v8::V8::LowMemoryNotification ();
52+ #endif
53+ has_sent_notification = true ;
54+ }
4655
47- for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG (timer_stack).begin ();
48- it != V8JSG (timer_stack).end (); it ++) {
49- v8js_timer_ctx *timer_ctx = *it;
50- v8js_ctx *c = timer_ctx->ctx ;
56+ isolate->GetHeapStatistics (&hs);
5157
52- if (c->isolate != isolate || timer_ctx->killed ) {
53- continue ;
54- }
58+ V8JSG (timer_mutex).lock ();
59+
60+ for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG (timer_stack).begin ();
61+ it != V8JSG (timer_stack).end (); it ++) {
62+ v8js_timer_ctx *timer_ctx = *it;
63+ v8js_ctx *c = timer_ctx->ctx ;
64+
65+ if (c->isolate != isolate || timer_ctx->killed ) {
66+ continue ;
67+ }
5568
56- if (timer_ctx->memory_limit > 0 && hs.used_heap_size () > timer_ctx->memory_limit ) {
57- timer_ctx->killed = true ;
58- v8::V8::TerminateExecution (c->isolate );
59- c->memory_limit_hit = true ;
69+ if (timer_ctx->memory_limit > 0 && hs.used_heap_size () > timer_ctx->memory_limit ) {
70+ if (has_sent_notification) {
71+ timer_ctx->killed = true ;
72+ v8::V8::TerminateExecution (c->isolate );
73+ c->memory_limit_hit = true ;
74+ } else {
75+ // force garbage collection, then check again
76+ send_notification = true ;
77+ break ;
78+ }
79+ }
6080 }
61- }
6281
63- V8JSG (timer_mutex).unlock ();
82+ V8JSG (timer_mutex).unlock ();
83+ } while (send_notification != has_sent_notification);
6484}
6585/* }}} */
6686
0 commit comments