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

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

Issue 2654443003: Revert "VM: Fix memory leaks during isolate spawning" (Closed)
Patch Set: 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
257 const char* utf8_package_root = 242 const char* utf8_package_root =
258 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot); 243 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot);
259 const char* utf8_package_config = 244 const char* utf8_package_config =
260 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig); 245 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig);
261 246
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
262 IsolateSpawnState* state = new IsolateSpawnState( 251 IsolateSpawnState* state = new IsolateSpawnState(
263 port.Id(), isolate->origin_id(), isolate->init_callback_data(), 252 port.Id(), isolate->origin_id(), isolate->init_callback_data(),
264 String2UTF8(script_uri), func, &message_buffer, 253 String2UTF8(script_uri), func, message,
265 isolate->spawn_count_monitor(), isolate->spawn_count(), 254 isolate->spawn_count_monitor(), isolate->spawn_count(),
266 utf8_package_root, utf8_package_config, paused.value(), fatal_errors, 255 utf8_package_root, utf8_package_config, paused.value(), fatal_errors,
267 on_exit_port, on_error_port); 256 on_exit_port, on_error_port);
268 ThreadPool::Task* spawn_task = new SpawnIsolateTask(state); 257 ThreadPool::Task* spawn_task = new SpawnIsolateTask(state);
269 258
270 isolate->IncrementSpawnCount(); 259 isolate->IncrementSpawnCount();
271 if (FLAG_i_like_slow_isolate_spawn) { 260 if (FLAG_i_like_slow_isolate_spawn) {
272 // We block the parent isolate while the child isolate loads. 261 // We block the parent isolate while the child isolate loads.
273 Isolate* saved = Isolate::Current(); 262 Isolate* saved = Isolate::Current();
274 Thread::ExitIsolate(); 263 Thread::ExitIsolate();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (Dart::vm_snapshot_kind() == Snapshot::kAppAOT) { 343 if (Dart::vm_snapshot_kind() == Snapshot::kAppAOT) {
355 const Array& args = Array::Handle(Array::New(1)); 344 const Array& args = Array::Handle(Array::New(1));
356 args.SetAt( 345 args.SetAt(
357 0, 346 0,
358 String::Handle(String::New( 347 String::Handle(String::New(
359 "Isolate.spawnUri is not supported when using AOT compilation"))); 348 "Isolate.spawnUri is not supported when using AOT compilation")));
360 Exceptions::ThrowByType(Exceptions::kUnsupported, args); 349 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
361 UNREACHABLE(); 350 UNREACHABLE();
362 } 351 }
363 352
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
385 // Canonicalize the uri with respect to the current isolate. 353 // Canonicalize the uri with respect to the current isolate.
386 const Library& root_lib = 354 const Library& root_lib =
387 Library::Handle(isolate->object_store()->root_library()); 355 Library::Handle(isolate->object_store()->root_library());
388 char* error = NULL; 356 char* error = NULL;
389 const char* canonical_uri = CanonicalizeUri(thread, root_lib, uri, &error); 357 const char* canonical_uri = CanonicalizeUri(thread, root_lib, uri, &error);
390 if (canonical_uri == NULL) { 358 if (canonical_uri == NULL) {
391 const String& msg = String::Handle(String::New(error)); 359 const String& msg = String::Handle(String::New(error));
392 ThrowIsolateSpawnException(msg); 360 ThrowIsolateSpawnException(msg);
393 } 361 }
394 362
395 const char* utf8_package_root = 363 const char* utf8_package_root =
396 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot); 364 packageRoot.IsNull() ? NULL : String2UTF8(packageRoot);
397 const char* utf8_package_config = 365 const char* utf8_package_config =
398 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig); 366 packageConfig.IsNull() ? NULL : String2UTF8(packageConfig);
399 367
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
400 IsolateSpawnState* state = new IsolateSpawnState( 372 IsolateSpawnState* state = new IsolateSpawnState(
401 port.Id(), isolate->init_callback_data(), canonical_uri, 373 port.Id(), isolate->init_callback_data(), canonical_uri,
402 utf8_package_root, utf8_package_config, &arguments_buffer, 374 utf8_package_root, utf8_package_config, args, message,
403 &message_buffer, isolate->spawn_count_monitor(), isolate->spawn_count(), 375 isolate->spawn_count_monitor(), isolate->spawn_count(), paused.value(),
404 paused.value(), fatal_errors, on_exit_port, on_error_port); 376 fatal_errors, on_exit_port, on_error_port);
405 377
406 // If we were passed a value then override the default flags state for 378 // If we were passed a value then override the default flags state for
407 // checked mode. 379 // checked mode.
408 if (!checked.IsNull()) { 380 if (!checked.IsNull()) {
409 bool val = checked.value(); 381 bool val = checked.value();
410 Dart_IsolateFlags* flags = state->isolate_flags(); 382 Dart_IsolateFlags* flags = state->isolate_flags();
411 flags->enable_asserts = val; 383 flags->enable_asserts = val;
412 flags->enable_type_checks = val; 384 flags->enable_type_checks = val;
413 } 385 }
414 386
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 uint8_t* data = NULL; 435 uint8_t* data = NULL;
464 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false); 436 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false);
465 writer.WriteMessage(msg); 437 writer.WriteMessage(msg);
466 438
467 PortMap::PostMessage(new Message(port.Id(), data, writer.BytesWritten(), 439 PortMap::PostMessage(new Message(port.Id(), data, writer.BytesWritten(),
468 Message::kOOBPriority)); 440 Message::kOOBPriority));
469 return Object::null(); 441 return Object::null();
470 } 442 }
471 443
472 } // namespace dart 444 } // 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