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

Side by Side Diff: runtime/vm/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 | « runtime/vm/isolate.h ('k') | runtime/vm/snapshot.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "vm/isolate.h" 5 #include "vm/isolate.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/text_buffer.h" 10 #include "platform/text_buffer.h"
(...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after
2769 memmove(mem, chars, len + 1); 2769 memmove(mem, chars, len + 1);
2770 return mem; 2770 return mem;
2771 } 2771 }
2772 2772
2773 2773
2774 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, 2774 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
2775 Dart_Port origin_id, 2775 Dart_Port origin_id,
2776 void* init_data, 2776 void* init_data,
2777 const char* script_url, 2777 const char* script_url,
2778 const Function& func, 2778 const Function& func,
2779 const Instance& message, 2779 SerializedObjectBuffer* message_buffer,
2780 Monitor* spawn_count_monitor, 2780 Monitor* spawn_count_monitor,
2781 intptr_t* spawn_count, 2781 intptr_t* spawn_count,
2782 const char* package_root, 2782 const char* package_root,
2783 const char* package_config, 2783 const char* package_config,
2784 bool paused, 2784 bool paused,
2785 bool errors_are_fatal, 2785 bool errors_are_fatal,
2786 Dart_Port on_exit_port, 2786 Dart_Port on_exit_port,
2787 Dart_Port on_error_port) 2787 Dart_Port on_error_port)
2788 : isolate_(NULL), 2788 : isolate_(NULL),
2789 parent_port_(parent_port), 2789 parent_port_(parent_port),
(...skipping 21 matching lines...) Expand all
2811 library_url_ = NewConstChar(lib_url.ToCString()); 2811 library_url_ = NewConstChar(lib_url.ToCString());
2812 2812
2813 String& func_name = String::Handle(); 2813 String& func_name = String::Handle();
2814 func_name ^= func.name(); 2814 func_name ^= func.name();
2815 func_name ^= String::ScrubName(func_name); 2815 func_name ^= String::ScrubName(func_name);
2816 function_name_ = NewConstChar(func_name.ToCString()); 2816 function_name_ = NewConstChar(func_name.ToCString());
2817 if (!cls.IsTopLevel()) { 2817 if (!cls.IsTopLevel()) {
2818 const String& class_name = String::Handle(cls.Name()); 2818 const String& class_name = String::Handle(cls.Name());
2819 class_name_ = NewConstChar(class_name.ToCString()); 2819 class_name_ = NewConstChar(class_name.ToCString());
2820 } 2820 }
2821 bool can_send_any_object = true; 2821 message_buffer->StealBuffer(&serialized_message_, &serialized_message_len_);
2822 SerializeObject(message, &serialized_message_, &serialized_message_len_, 2822
2823 can_send_any_object);
2824 // Inherit flags from spawning isolate. 2823 // Inherit flags from spawning isolate.
2825 Isolate::Current()->FlagsCopyTo(isolate_flags()); 2824 Isolate::Current()->FlagsCopyTo(isolate_flags());
2826 } 2825 }
2827 2826
2828 2827
2829 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, 2828 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
2830 void* init_data, 2829 void* init_data,
2831 const char* script_url, 2830 const char* script_url,
2832 const char* package_root, 2831 const char* package_root,
2833 const char* package_config, 2832 const char* package_config,
2834 const Instance& args, 2833 SerializedObjectBuffer* args_buffer,
2835 const Instance& message, 2834 SerializedObjectBuffer* message_buffer,
2836 Monitor* spawn_count_monitor, 2835 Monitor* spawn_count_monitor,
2837 intptr_t* spawn_count, 2836 intptr_t* spawn_count,
2838 bool paused, 2837 bool paused,
2839 bool errors_are_fatal, 2838 bool errors_are_fatal,
2840 Dart_Port on_exit_port, 2839 Dart_Port on_exit_port,
2841 Dart_Port on_error_port) 2840 Dart_Port on_error_port)
2842 : isolate_(NULL), 2841 : isolate_(NULL),
2843 parent_port_(parent_port), 2842 parent_port_(parent_port),
2844 origin_id_(ILLEGAL_PORT), 2843 origin_id_(ILLEGAL_PORT),
2845 init_data_(init_data), 2844 init_data_(init_data),
2846 on_exit_port_(on_exit_port), 2845 on_exit_port_(on_exit_port),
2847 on_error_port_(on_error_port), 2846 on_error_port_(on_error_port),
2848 script_url_(script_url), 2847 script_url_(script_url),
2849 package_root_(package_root), 2848 package_root_(package_root),
2850 package_config_(package_config), 2849 package_config_(package_config),
2851 library_url_(NULL), 2850 library_url_(NULL),
2852 class_name_(NULL), 2851 class_name_(NULL),
2853 function_name_(NULL), 2852 function_name_(NULL),
2854 serialized_args_(NULL), 2853 serialized_args_(NULL),
2855 serialized_args_len_(0), 2854 serialized_args_len_(0),
2856 serialized_message_(NULL), 2855 serialized_message_(NULL),
2857 serialized_message_len_(0), 2856 serialized_message_len_(0),
2858 spawn_count_monitor_(spawn_count_monitor), 2857 spawn_count_monitor_(spawn_count_monitor),
2859 spawn_count_(spawn_count), 2858 spawn_count_(spawn_count),
2860 isolate_flags_(), 2859 isolate_flags_(),
2861 paused_(paused), 2860 paused_(paused),
2862 errors_are_fatal_(errors_are_fatal) { 2861 errors_are_fatal_(errors_are_fatal) {
2863 function_name_ = NewConstChar("main"); 2862 function_name_ = NewConstChar("main");
2864 bool can_send_any_object = false; 2863 args_buffer->StealBuffer(&serialized_args_, &serialized_args_len_);
2865 SerializeObject(args, &serialized_args_, &serialized_args_len_, 2864 message_buffer->StealBuffer(&serialized_message_, &serialized_message_len_);
2866 can_send_any_object); 2865
2867 SerializeObject(message, &serialized_message_, &serialized_message_len_,
2868 can_send_any_object);
2869 // By default inherit flags from spawning isolate. These can be overridden 2866 // By default inherit flags from spawning isolate. These can be overridden
2870 // from the calling code. 2867 // from the calling code.
2871 Isolate::Current()->FlagsCopyTo(isolate_flags()); 2868 Isolate::Current()->FlagsCopyTo(isolate_flags());
2872 } 2869 }
2873 2870
2874 2871
2875 IsolateSpawnState::~IsolateSpawnState() { 2872 IsolateSpawnState::~IsolateSpawnState() {
2876 delete[] script_url_; 2873 delete[] script_url_;
2877 delete[] package_root_; 2874 delete[] package_root_;
2878 delete[] package_config_; 2875 delete[] package_config_;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2976 void IsolateSpawnState::DecrementSpawnCount() { 2973 void IsolateSpawnState::DecrementSpawnCount() {
2977 ASSERT(spawn_count_monitor_ != NULL); 2974 ASSERT(spawn_count_monitor_ != NULL);
2978 ASSERT(spawn_count_ != NULL); 2975 ASSERT(spawn_count_ != NULL);
2979 MonitorLocker ml(spawn_count_monitor_); 2976 MonitorLocker ml(spawn_count_monitor_);
2980 ASSERT(*spawn_count_ > 0); 2977 ASSERT(*spawn_count_ > 0);
2981 *spawn_count_ = *spawn_count_ - 1; 2978 *spawn_count_ = *spawn_count_ - 1;
2982 ml.Notify(); 2979 ml.Notify();
2983 } 2980 }
2984 2981
2985 } // namespace dart 2982 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate.h ('k') | runtime/vm/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698