Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Side by Side Diff: runtime/lib/isolate.cc

Issue 2650693004: VM: Fix memory leaks during isolate spawning (Closed)
Patch Set: Rebased & Renamed TakeBuffer -> StealBuffer Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/datastream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_native_api.h" 5 #include "include/dart_native_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bootstrap_natives.h" 7 #include "vm/bootstrap_natives.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 func = Closure::Cast(closure).function(); 232 func = Closure::Cast(closure).function();
233 if (func.IsImplicitClosureFunction() && func.is_static()) { 233 if (func.IsImplicitClosureFunction() && func.is_static()) {
234 #if defined(DEBUG) 234 #if defined(DEBUG)
235 Context& ctx = Context::Handle(); 235 Context& ctx = Context::Handle();
236 ctx = Closure::Cast(closure).context(); 236 ctx = Closure::Cast(closure).context();
237 ASSERT(ctx.num_variables() == 0); 237 ASSERT(ctx.num_variables() == 0);
238 #endif 238 #endif
239 // Get the parent function so that we get the right function name. 239 // Get the parent function so that we get the right function name.
240 func = func.parent_function(); 240 func = func.parent_function();
241 241
242 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value();
243 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id();
244 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id();
245
246 // We first try to serialize the message. In case the message is not
247 // serializable this will throw an exception.
248 SerializedObjectBuffer message_buffer;
249 {
250 MessageWriter writer(message_buffer.data_buffer(), &malloc_allocator,
251 &malloc_deallocator,
252 /* can_send_any_object = */ true,
253 message_buffer.data_length());
254 writer.WriteMessage(message);
255 }
256
242 const char* utf8_package_root = 257 const char* utf8_package_root =
243 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot); 258 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot);
244 const char* utf8_package_config = 259 const char* utf8_package_config =
245 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig); 260 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig);
246 261
247 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value();
248 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id();
249 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id();
250
251 IsolateSpawnState* state = new IsolateSpawnState( 262 IsolateSpawnState* state = new IsolateSpawnState(
252 port.Id(), isolate->origin_id(), isolate->init_callback_data(), 263 port.Id(), isolate->origin_id(), isolate->init_callback_data(),
253 String2UTF8(script_uri), func, message, 264 String2UTF8(script_uri), func, &message_buffer,
254 isolate->spawn_count_monitor(), isolate->spawn_count(), 265 isolate->spawn_count_monitor(), isolate->spawn_count(),
255 utf8_package_root, utf8_package_config, paused.value(), fatal_errors, 266 utf8_package_root, utf8_package_config, paused.value(), fatal_errors,
256 on_exit_port, on_error_port); 267 on_exit_port, on_error_port);
257 ThreadPool::Task* spawn_task = new SpawnIsolateTask(state); 268 ThreadPool::Task* spawn_task = new SpawnIsolateTask(state);
258 269
259 isolate->IncrementSpawnCount(); 270 isolate->IncrementSpawnCount();
260 if (FLAG_i_like_slow_isolate_spawn) { 271 if (FLAG_i_like_slow_isolate_spawn) {
261 // We block the parent isolate while the child isolate loads. 272 // We block the parent isolate while the child isolate loads.
262 Isolate* saved = Isolate::Current(); 273 Isolate* saved = Isolate::Current();
263 Thread::ExitIsolate(); 274 Thread::ExitIsolate();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 if (Dart::vm_snapshot_kind() == Snapshot::kAppAOT) { 354 if (Dart::vm_snapshot_kind() == Snapshot::kAppAOT) {
344 const Array& args = Array::Handle(Array::New(1)); 355 const Array& args = Array::Handle(Array::New(1));
345 args.SetAt( 356 args.SetAt(
346 0, 357 0,
347 String::Handle(String::New( 358 String::Handle(String::New(
348 "Isolate.spawnUri is not supported when using AOT compilation"))); 359 "Isolate.spawnUri is not supported when using AOT compilation")));
349 Exceptions::ThrowByType(Exceptions::kUnsupported, args); 360 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
350 UNREACHABLE(); 361 UNREACHABLE();
351 } 362 }
352 363
364 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value();
365 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id();
366 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id();
367
368 // We first try to serialize the arguments and the message. In case the
369 // arguments or the message are not serializable this will throw an exception.
370 SerializedObjectBuffer arguments_buffer;
371 SerializedObjectBuffer message_buffer;
372 {
373 MessageWriter writer(
374 arguments_buffer.data_buffer(), &malloc_allocator, &malloc_deallocator,
375 /* can_send_any_object = */ false, arguments_buffer.data_length());
376 writer.WriteMessage(args);
377 }
378 {
379 MessageWriter writer(
380 message_buffer.data_buffer(), &malloc_allocator, &malloc_deallocator,
381 /* can_send_any_object = */ false, arguments_buffer.data_length());
382 writer.WriteMessage(message);
383 }
384
353 // Canonicalize the uri with respect to the current isolate. 385 // Canonicalize the uri with respect to the current isolate.
354 const Library& root_lib = 386 const Library& root_lib =
355 Library::Handle(isolate->object_store()->root_library()); 387 Library::Handle(isolate->object_store()->root_library());
356 char* error = NULL; 388 char* error = NULL;
357 const char* canonical_uri = CanonicalizeUri(thread, root_lib, uri, &error); 389 const char* canonical_uri = CanonicalizeUri(thread, root_lib, uri, &error);
358 if (canonical_uri == NULL) { 390 if (canonical_uri == NULL) {
359 const String& msg = String::Handle(String::New(error)); 391 const String& msg = String::Handle(String::New(error));
360 ThrowIsolateSpawnException(msg); 392 ThrowIsolateSpawnException(msg);
361 } 393 }
362 394
363 const char* utf8_package_root = 395 const char* utf8_package_root =
364 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot); 396 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot);
365 const char* utf8_package_config = 397 const char* utf8_package_config =
366 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig); 398 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig);
367 399
368 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value();
369 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id();
370 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id();
371
372 IsolateSpawnState* state = new IsolateSpawnState( 400 IsolateSpawnState* state = new IsolateSpawnState(
373 port.Id(), isolate->init_callback_data(), canonical_uri, 401 port.Id(), isolate->init_callback_data(), canonical_uri,
374 utf8_package_root, utf8_package_config, args, message, 402 utf8_package_root, utf8_package_config, &arguments_buffer,
375 isolate->spawn_count_monitor(), isolate->spawn_count(), paused.value(), 403 &message_buffer, isolate->spawn_count_monitor(), isolate->spawn_count(),
376 fatal_errors, on_exit_port, on_error_port); 404 paused.value(), fatal_errors, on_exit_port, on_error_port);
377 405
378 // If we were passed a value then override the default flags state for 406 // If we were passed a value then override the default flags state for
379 // checked mode. 407 // checked mode.
380 if (!checked.IsNull()) { 408 if (!checked.IsNull()) {
381 bool val = checked.value(); 409 bool val = checked.value();
382 Dart_IsolateFlags* flags = state->isolate_flags(); 410 Dart_IsolateFlags* flags = state->isolate_flags();
383 flags->enable_asserts = val; 411 flags->enable_asserts = val;
384 flags->enable_type_checks = val; 412 flags->enable_type_checks = val;
385 } 413 }
386 414
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 uint8_t* data = NULL; 463 uint8_t* data = NULL;
436 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false); 464 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false);
437 writer.WriteMessage(msg); 465 writer.WriteMessage(msg);
438 466
439 PortMap::PostMessage(new Message(port.Id(), data, writer.BytesWritten(), 467 PortMap::PostMessage(new Message(port.Id(), data, writer.BytesWritten(),
440 Message::kOOBPriority)); 468 Message::kOOBPriority));
441 return Object::null(); 469 return Object::null();
442 } 470 }
443 471
444 } // namespace dart 472 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/datastream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698