| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.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_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 delete data; | 139 delete data; |
| 140 | 140 |
| 141 Isolate::SetCurrent(isolate); | 141 Isolate::SetCurrent(isolate); |
| 142 // Intialize stack limit in case we are running isolate in a | 142 // Intialize stack limit in case we are running isolate in a |
| 143 // different thread than in which it was initialized. | 143 // different thread than in which it was initialized. |
| 144 isolate->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(&isolate)); | 144 isolate->SetStackLimitFromCurrentTOS(reinterpret_cast<uword>(&isolate)); |
| 145 LongJump* base = isolate->long_jump_base(); | 145 LongJump* base = isolate->long_jump_base(); |
| 146 LongJump jump; | 146 LongJump jump; |
| 147 isolate->set_long_jump_base(&jump); | 147 isolate->set_long_jump_base(&jump); |
| 148 if (setjmp(*jump.Set()) == 0) { | 148 if (setjmp(*jump.Set()) == 0) { |
| 149 Zone zone; | 149 Zone zone(isolate); |
| 150 HandleScope handle_scope; | 150 HandleScope handle_scope(isolate); |
| 151 ASSERT(ClassFinalizer::FinalizePendingClasses()); | 151 ASSERT(ClassFinalizer::FinalizePendingClasses()); |
| 152 // Lookup the target class by name, create an instance and call the run | 152 // Lookup the target class by name, create an instance and call the run |
| 153 // method. | 153 // method. |
| 154 const String& lib_name = String::Handle(String::NewSymbol(library_url)); | 154 const String& lib_name = String::Handle(String::NewSymbol(library_url)); |
| 155 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); | 155 const Library& lib = Library::Handle(Library::LookupLibrary(lib_name)); |
| 156 ASSERT(!lib.IsNull()); | 156 ASSERT(!lib.IsNull()); |
| 157 const String& cls_name = String::Handle(String::NewSymbol(class_name)); | 157 const String& cls_name = String::Handle(String::NewSymbol(class_name)); |
| 158 const Class& target_class = Class::Handle(lib.LookupClass(cls_name)); | 158 const Class& target_class = Class::Handle(lib.LookupClass(cls_name)); |
| 159 // TODO(iposva): Deserialize or call the constructor after allocating. | 159 // TODO(iposva): Deserialize or call the constructor after allocating. |
| 160 // For now, we only support a non-parameterized or raw target class. | 160 // For now, we only support a non-parameterized or raw target class. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (result.IsUnhandledException()) { | 199 if (result.IsUnhandledException()) { |
| 200 UnhandledException& uhe = UnhandledException::Handle(); | 200 UnhandledException& uhe = UnhandledException::Handle(); |
| 201 uhe ^= result.raw(); | 201 uhe ^= result.raw(); |
| 202 ProcessUnhandledException(uhe); | 202 ProcessUnhandledException(uhe); |
| 203 } | 203 } |
| 204 ASSERT(result.IsNull()); | 204 ASSERT(result.IsNull()); |
| 205 free(class_name); | 205 free(class_name); |
| 206 isolate->StandardRunLoop(); | 206 isolate->StandardRunLoop(); |
| 207 | 207 |
| 208 } else { | 208 } else { |
| 209 Zone zone; | 209 Zone zone(isolate); |
| 210 HandleScope handle_scope; | 210 HandleScope handle_scope(isolate); |
| 211 const String& error = String::Handle( | 211 const String& error = String::Handle( |
| 212 Isolate::Current()->object_store()->sticky_error()); | 212 Isolate::Current()->object_store()->sticky_error()); |
| 213 const char* errmsg = error.ToCString(); | 213 const char* errmsg = error.ToCString(); |
| 214 fprintf(stderr, "%s\n", errmsg); | 214 fprintf(stderr, "%s\n", errmsg); |
| 215 exit(255); | 215 exit(255); |
| 216 } | 216 } |
| 217 isolate->set_long_jump_base(base); | 217 isolate->set_long_jump_base(base); |
| 218 Dart::ShutdownIsolate(); | 218 Dart::ShutdownIsolate(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 | 221 |
| 222 static bool CheckArguments(const char* library_url, const char* class_name) { | 222 static bool CheckArguments(const char* library_url, const char* class_name) { |
| 223 Zone zone; | 223 Isolate* isolate = Isolate::Current(); |
| 224 HandleScope handle_scope; | 224 Zone zone(isolate); |
| 225 HandleScope handle_scope(isolate); |
| 225 String& name = String::Handle(); | 226 String& name = String::Handle(); |
| 226 if (!ClassFinalizer::FinalizePendingClasses()) { | 227 if (!ClassFinalizer::FinalizePendingClasses()) { |
| 227 return false; | 228 return false; |
| 228 } | 229 } |
| 229 // Lookup the target class by name, create an instance and call the run | 230 // Lookup the target class by name, create an instance and call the run |
| 230 // method. | 231 // method. |
| 231 name ^= String::NewSymbol(library_url); | 232 name ^= String::NewSymbol(library_url); |
| 232 const Library& lib = Library::Handle(Library::LookupLibrary(name)); | 233 const Library& lib = Library::Handle(Library::LookupLibrary(name)); |
| 233 if (lib.IsNull()) { | 234 if (lib.IsNull()) { |
| 234 const String& error = String::Handle( | 235 const String& error = String::Handle( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 strdup(class_name), | 283 strdup(class_name), |
| 283 port_id)); | 284 port_id)); |
| 284 new Thread(RunIsolate, data); | 285 new Thread(RunIsolate, data); |
| 285 } else { | 286 } else { |
| 286 // Error spawning the isolate, maybe due to initialization errors or | 287 // Error spawning the isolate, maybe due to initialization errors or |
| 287 // errors while loading the application into spawned isolate, shut | 288 // errors while loading the application into spawned isolate, shut |
| 288 // it down and report error. | 289 // it down and report error. |
| 289 // Make sure to grab the error message out of the isolate before it has | 290 // Make sure to grab the error message out of the isolate before it has |
| 290 // been shutdown and to allocate it in the preserved isolates zone. | 291 // been shutdown and to allocate it in the preserved isolates zone. |
| 291 { | 292 { |
| 292 Zone zone; | 293 Zone zone(spawned_isolate); |
| 293 HandleScope scope; | 294 HandleScope scope(spawned_isolate); |
| 294 const String& error = String::Handle( | 295 const String& error = String::Handle( |
| 295 spawned_isolate->object_store()->sticky_error()); | 296 spawned_isolate->object_store()->sticky_error()); |
| 296 const char* temp_error_msg = error.ToCString(); | 297 const char* temp_error_msg = error.ToCString(); |
| 297 intptr_t err_len = strlen(temp_error_msg) + 1; | 298 intptr_t err_len = strlen(temp_error_msg) + 1; |
| 298 Zone* preserved_zone = preserved_isolate->current_zone(); | 299 Zone* preserved_zone = preserved_isolate->current_zone(); |
| 299 error_msg = reinterpret_cast<char*>(preserved_zone->Allocate(err_len)); | 300 error_msg = reinterpret_cast<char*>(preserved_zone->Allocate(err_len)); |
| 300 OS::SNPrint( | 301 OS::SNPrint( |
| 301 const_cast<char*>(error_msg), err_len, "%s", temp_error_msg); | 302 const_cast<char*>(error_msg), err_len, "%s", temp_error_msg); |
| 302 } | 303 } |
| 303 Dart::ShutdownIsolate(); | 304 Dart::ShutdownIsolate(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); | 347 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); |
| 347 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); | 348 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); |
| 348 // TODO(iposva): Allow for arbitrary messages to be sent. | 349 // TODO(iposva): Allow for arbitrary messages to be sent. |
| 349 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); | 350 void* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); |
| 350 | 351 |
| 351 // TODO(turnidge): Throw an exception when the return value is false? | 352 // TODO(turnidge): Throw an exception when the return value is false? |
| 352 PortMap::PostMessage(send_id, reply_id, data); | 353 PortMap::PostMessage(send_id, reply_id, data); |
| 353 } | 354 } |
| 354 | 355 |
| 355 } // namespace dart | 356 } // namespace dart |
| OLD | NEW |