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

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

Issue 474913004: - Account for number of pending tasks in old-space collections. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.cc » ('j') | runtime/vm/freelist.cc » ('J')
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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart.h" 8 #include "vm/dart.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 Dart_ExitScope(); 132 Dart_ExitScope();
133 } else { 133 } else {
134 *error = zone->PrintToString( 134 *error = zone->PrintToString(
135 "Unable to canonicalize uri '%s': no library tag handler found.", 135 "Unable to canonicalize uri '%s': no library tag handler found.",
136 uri.ToCString()); 136 uri.ToCString());
137 } 137 }
138 return retval; 138 return retval;
139 } 139 }
140 140
141 141
142 static bool CreateIsolate(IsolateSpawnState* state, char** error) { 142 static bool CreateIsolate(Isolate* parent_isolate,
143 Isolate* parent_isolate = Isolate::Current(); 143 IsolateSpawnState* state,
144 144 char** error) {
145 Dart_IsolateCreateCallback callback = Isolate::CreateCallback(); 145 Dart_IsolateCreateCallback callback = Isolate::CreateCallback();
146 if (callback == NULL) { 146 if (callback == NULL) {
147 *error = strdup("Null callback specified for isolate creation\n"); 147 *error = strdup("Null callback specified for isolate creation\n");
148 Isolate::SetCurrent(parent_isolate); 148 Isolate::SetCurrent(parent_isolate);
149 return false; 149 return false;
150 } 150 }
151 151
152 void* init_data = parent_isolate->init_callback_data(); 152 void* init_data = parent_isolate->init_callback_data();
153 Isolate* child_isolate = reinterpret_cast<Isolate*>( 153 Isolate* child_isolate = reinterpret_cast<Isolate*>(
154 (callback)(state->script_url(), 154 (callback)(state->script_url(),
155 state->function_name(), 155 state->function_name(),
156 init_data, 156 init_data,
157 error)); 157 error));
158 if (child_isolate == NULL) { 158 if (child_isolate == NULL) {
159 Isolate::SetCurrent(parent_isolate); 159 Isolate::SetCurrent(parent_isolate);
160 return false; 160 return false;
161 } 161 }
162 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate)); 162 state->set_isolate(reinterpret_cast<Isolate*>(child_isolate));
163 163
164 Isolate::SetCurrent(parent_isolate); 164 Isolate::SetCurrent(parent_isolate);
165 return true; 165 return true;
166 } 166 }
167 167
168 168
169 static RawObject* Spawn(NativeArguments* arguments, IsolateSpawnState* state) { 169 static RawObject* Spawn(Isolate* parent_isolate,
170 IsolateSpawnState* state) {
170 // Create a new isolate. 171 // Create a new isolate.
171 char* error = NULL; 172 char* error = NULL;
172 if (!CreateIsolate(state, &error)) { 173 if (!CreateIsolate(parent_isolate, state, &error)) {
173 delete state; 174 delete state;
174 const String& msg = String::Handle(String::New(error)); 175 const String& msg = String::Handle(String::New(error));
175 free(error); 176 free(error);
176 ThrowIsolateSpawnException(msg); 177 ThrowIsolateSpawnException(msg);
177 } 178 }
178 179
179 // The result of spawning an Isolate is an array with 3 elements: 180 // The result of spawning an Isolate is an array with 3 elements:
180 // [main_port, pause_capability, terminate_capability] 181 // [main_port, pause_capability, terminate_capability]
181 const Array& result = Array::Handle(Array::New(3)); 182 const Array& result = Array::Handle(Array::New(3));
182 183
(...skipping 23 matching lines...) Expand all
206 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); 207 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0));
207 if (closure.IsClosure()) { 208 if (closure.IsClosure()) {
208 Function& func = Function::Handle(); 209 Function& func = Function::Handle();
209 func = Closure::function(closure); 210 func = Closure::function(closure);
210 if (func.IsImplicitClosureFunction() && func.is_static()) { 211 if (func.IsImplicitClosureFunction() && func.is_static()) {
211 #if defined(DEBUG) 212 #if defined(DEBUG)
212 Context& ctx = Context::Handle(); 213 Context& ctx = Context::Handle();
213 ctx = Closure::context(closure); 214 ctx = Closure::context(closure);
214 ASSERT(ctx.num_variables() == 0); 215 ASSERT(ctx.num_variables() == 0);
215 #endif 216 #endif
216 return Spawn(arguments, new IsolateSpawnState(func)); 217 return Spawn(isolate, new IsolateSpawnState(func));
217 } 218 }
218 } 219 }
219 const String& msg = String::Handle(String::New( 220 const String& msg = String::Handle(String::New(
220 "Isolate.spawn expects to be passed a static or top-level function")); 221 "Isolate.spawn expects to be passed a static or top-level function"));
221 Exceptions::ThrowArgumentError(msg); 222 Exceptions::ThrowArgumentError(msg);
222 return Object::null(); 223 return Object::null();
223 } 224 }
224 225
225 226
226 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) { 227 DEFINE_NATIVE_ENTRY(Isolate_spawnUri, 1) {
227 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0)); 228 GET_NON_NULL_NATIVE_ARGUMENT(String, uri, arguments->NativeArgAt(0));
228 229
229 // Canonicalize the uri with respect to the current isolate. 230 // Canonicalize the uri with respect to the current isolate.
230 char* error = NULL; 231 char* error = NULL;
231 char* canonical_uri = NULL; 232 char* canonical_uri = NULL;
232 const Library& root_lib = 233 const Library& root_lib =
233 Library::Handle(arguments->isolate()->object_store()->root_library()); 234 Library::Handle(arguments->isolate()->object_store()->root_library());
234 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri, 235 if (!CanonicalizeUri(arguments->isolate(), root_lib, uri,
235 &canonical_uri, &error)) { 236 &canonical_uri, &error)) {
236 const String& msg = String::Handle(String::New(error)); 237 const String& msg = String::Handle(String::New(error));
237 ThrowIsolateSpawnException(msg); 238 ThrowIsolateSpawnException(msg);
238 } 239 }
239 240
240 return Spawn(arguments, new IsolateSpawnState(canonical_uri)); 241 return Spawn(isolate, new IsolateSpawnState(canonical_uri));
241 } 242 }
242 243
243 244
244 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) { 245 DEFINE_NATIVE_ENTRY(Isolate_sendOOB, 2) {
245 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0)); 246 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
246 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1)); 247 GET_NON_NULL_NATIVE_ARGUMENT(Array, msg, arguments->NativeArgAt(1));
247 248
248 // Make sure to route this request to the isolate library OOB mesage handler. 249 // Make sure to route this request to the isolate library OOB mesage handler.
249 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg))); 250 msg.SetAt(0, Smi::Handle(Smi::New(Message::kIsolateLibOOBMsg)));
250 251
(...skipping 11 matching lines...) Expand all
262 DEFINE_NATIVE_ENTRY(Isolate_mainPort, 0) { 263 DEFINE_NATIVE_ENTRY(Isolate_mainPort, 0) {
263 // The control port is being accessed as a regular port from Dart code. This 264 // The control port is being accessed as a regular port from Dart code. This
264 // is most likely due to the _startIsolate code in dart:isolate. Account for 265 // is most likely due to the _startIsolate code in dart:isolate. Account for
265 // this by increasing the number of open control ports. 266 // this by increasing the number of open control ports.
266 isolate->message_handler()->increment_control_ports(); 267 isolate->message_handler()->increment_control_ports();
267 268
268 return ReceivePort::New(isolate->main_port()); 269 return ReceivePort::New(isolate->main_port());
269 } 270 }
270 271
271 } // namespace dart 272 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.cc » ('j') | runtime/vm/freelist.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698