| OLD | NEW |
| 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 "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/json.h" | 9 #include "platform/json.h" |
| 10 #include "lib/mirrors.h" | 10 #include "lib/mirrors.h" |
| 11 #include "vm/code_observers.h" | 11 #include "vm/code_observers.h" |
| 12 #include "vm/compiler_stats.h" | 12 #include "vm/compiler_stats.h" |
| 13 #include "vm/coverage.h" | 13 #include "vm/coverage.h" |
| 14 #include "vm/dart_api_state.h" | 14 #include "vm/dart_api_state.h" |
| 15 #include "vm/dart_entry.h" | 15 #include "vm/dart_entry.h" |
| 16 #include "vm/debugger.h" | 16 #include "vm/debugger.h" |
| 17 #include "vm/deopt_instructions.h" |
| 17 #include "vm/heap.h" | 18 #include "vm/heap.h" |
| 18 #include "vm/heap_histogram.h" | 19 #include "vm/heap_histogram.h" |
| 19 #include "vm/message_handler.h" | 20 #include "vm/message_handler.h" |
| 20 #include "vm/object_id_ring.h" | 21 #include "vm/object_id_ring.h" |
| 21 #include "vm/object_store.h" | 22 #include "vm/object_store.h" |
| 22 #include "vm/parser.h" | 23 #include "vm/parser.h" |
| 23 #include "vm/port.h" | 24 #include "vm/port.h" |
| 24 #include "vm/reusable_handles.h" | 25 #include "vm/reusable_handles.h" |
| 25 #include "vm/service.h" | 26 #include "vm/service.h" |
| 26 #include "vm/simulator.h" | 27 #include "vm/simulator.h" |
| 27 #include "vm/stack_frame.h" | 28 #include "vm/stack_frame.h" |
| 28 #include "vm/stub_code.h" | 29 #include "vm/stub_code.h" |
| 29 #include "vm/symbols.h" | 30 #include "vm/symbols.h" |
| 30 #include "vm/thread.h" | 31 #include "vm/thread.h" |
| 31 #include "vm/timer.h" | 32 #include "vm/timer.h" |
| 32 #include "vm/visitor.h" | 33 #include "vm/visitor.h" |
| 33 | 34 |
| 34 | 35 |
| 35 namespace dart { | 36 namespace dart { |
| 36 | 37 |
| 37 DEFINE_FLAG(bool, report_usage_count, false, | 38 DEFINE_FLAG(bool, report_usage_count, false, |
| 38 "Track function usage and report."); | 39 "Track function usage and report."); |
| 39 DEFINE_FLAG(bool, trace_isolates, false, | 40 DEFINE_FLAG(bool, trace_isolates, false, |
| 40 "Trace isolate creation and shut down."); | 41 "Trace isolate creation and shut down."); |
| 41 DECLARE_FLAG(bool, trace_deoptimization_verbose); | |
| 42 | 42 |
| 43 | 43 |
| 44 void Isolate::RegisterClass(const Class& cls) { | 44 void Isolate::RegisterClass(const Class& cls) { |
| 45 class_table()->Register(cls); | 45 class_table()->Register(cls); |
| 46 if (object_histogram() != NULL) object_histogram()->RegisterClass(cls); | 46 if (object_histogram() != NULL) object_histogram()->RegisterClass(cls); |
| 47 } | 47 } |
| 48 | 48 |
| 49 | 49 |
| 50 class IsolateMessageHandler : public MessageHandler { | 50 class IsolateMessageHandler : public MessageHandler { |
| 51 public: | 51 public: |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 | 264 |
| 265 #if defined(DEBUG) | 265 #if defined(DEBUG) |
| 266 // static | 266 // static |
| 267 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { | 267 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { |
| 268 ASSERT(isolate == Isolate::Current()); | 268 ASSERT(isolate == Isolate::Current()); |
| 269 } | 269 } |
| 270 #endif | 270 #endif |
| 271 | 271 |
| 272 | 272 |
| 273 void DeferredDouble::Materialize() { | |
| 274 RawDouble** double_slot = reinterpret_cast<RawDouble**>(slot()); | |
| 275 *double_slot = Double::New(value()); | |
| 276 | |
| 277 if (FLAG_trace_deoptimization_verbose) { | |
| 278 OS::PrintErr("materializing double at %" Px ": %g\n", | |
| 279 reinterpret_cast<uword>(slot()), value()); | |
| 280 } | |
| 281 } | |
| 282 | |
| 283 | |
| 284 void DeferredMint::Materialize() { | |
| 285 RawMint** mint_slot = reinterpret_cast<RawMint**>(slot()); | |
| 286 ASSERT(!Smi::IsValid64(value())); | |
| 287 Mint& mint = Mint::Handle(); | |
| 288 mint ^= Integer::New(value()); | |
| 289 *mint_slot = mint.raw(); | |
| 290 | |
| 291 if (FLAG_trace_deoptimization_verbose) { | |
| 292 OS::PrintErr("materializing mint at %" Px ": %" Pd64 "\n", | |
| 293 reinterpret_cast<uword>(slot()), value()); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 | |
| 298 void DeferredFloat32x4::Materialize() { | |
| 299 RawFloat32x4** float32x4_slot = reinterpret_cast<RawFloat32x4**>(slot()); | |
| 300 RawFloat32x4* raw_float32x4 = Float32x4::New(value()); | |
| 301 *float32x4_slot = raw_float32x4; | |
| 302 | |
| 303 if (FLAG_trace_deoptimization_verbose) { | |
| 304 float x = raw_float32x4->x(); | |
| 305 float y = raw_float32x4->y(); | |
| 306 float z = raw_float32x4->z(); | |
| 307 float w = raw_float32x4->w(); | |
| 308 OS::PrintErr("materializing Float32x4 at %" Px ": %g,%g,%g,%g\n", | |
| 309 reinterpret_cast<uword>(slot()), x, y, z, w); | |
| 310 } | |
| 311 } | |
| 312 | |
| 313 | |
| 314 void DeferredUint32x4::Materialize() { | |
| 315 RawUint32x4** uint32x4_slot = reinterpret_cast<RawUint32x4**>(slot()); | |
| 316 RawUint32x4* raw_uint32x4 = Uint32x4::New(value()); | |
| 317 *uint32x4_slot = raw_uint32x4; | |
| 318 | |
| 319 if (FLAG_trace_deoptimization_verbose) { | |
| 320 uint32_t x = raw_uint32x4->x(); | |
| 321 uint32_t y = raw_uint32x4->y(); | |
| 322 uint32_t z = raw_uint32x4->z(); | |
| 323 uint32_t w = raw_uint32x4->w(); | |
| 324 OS::PrintErr("materializing Uint32x4 at %" Px ": %x,%x,%x,%x\n", | |
| 325 reinterpret_cast<uword>(slot()), x, y, z, w); | |
| 326 } | |
| 327 } | |
| 328 | |
| 329 | |
| 330 void DeferredObjectRef::Materialize() { | |
| 331 DeferredObject* obj = Isolate::Current()->GetDeferredObject(index()); | |
| 332 *slot() = obj->object(); | |
| 333 if (FLAG_trace_deoptimization_verbose) { | |
| 334 OS::PrintErr("writing instance ref at %" Px ": %s\n", | |
| 335 reinterpret_cast<uword>(slot()), | |
| 336 Instance::Handle(obj->object()).ToCString()); | |
| 337 } | |
| 338 } | |
| 339 | |
| 340 | |
| 341 RawInstance* DeferredObject::object() { | |
| 342 if (object_ == NULL) { | |
| 343 Materialize(); | |
| 344 } | |
| 345 return object_->raw(); | |
| 346 } | |
| 347 | |
| 348 | |
| 349 void DeferredObject::Materialize() { | |
| 350 Class& cls = Class::Handle(); | |
| 351 cls ^= GetClass(); | |
| 352 | |
| 353 if (FLAG_trace_deoptimization_verbose) { | |
| 354 OS::PrintErr("materializing instance of %s (%" Px ", %" Pd " fields)\n", | |
| 355 cls.ToCString(), | |
| 356 reinterpret_cast<uword>(args_), | |
| 357 field_count_); | |
| 358 } | |
| 359 | |
| 360 const Instance& obj = Instance::ZoneHandle(Instance::New(cls)); | |
| 361 | |
| 362 Field& field = Field::Handle(); | |
| 363 Object& value = Object::Handle(); | |
| 364 for (intptr_t i = 0; i < field_count_; i++) { | |
| 365 field ^= GetField(i); | |
| 366 value = GetValue(i); | |
| 367 obj.SetField(field, value); | |
| 368 | |
| 369 if (FLAG_trace_deoptimization_verbose) { | |
| 370 OS::PrintErr(" %s <- %s\n", | |
| 371 String::Handle(field.name()).ToCString(), | |
| 372 value.ToCString()); | |
| 373 } | |
| 374 } | |
| 375 | |
| 376 object_ = &obj; | |
| 377 } | |
| 378 | |
| 379 | |
| 380 #define REUSABLE_HANDLE_INITIALIZERS(object) \ | 273 #define REUSABLE_HANDLE_INITIALIZERS(object) \ |
| 381 object##_handle_(NULL), | 274 object##_handle_(NULL), |
| 382 | 275 |
| 383 Isolate::Isolate() | 276 Isolate::Isolate() |
| 384 : store_buffer_(), | 277 : store_buffer_(), |
| 385 message_notify_callback_(NULL), | 278 message_notify_callback_(NULL), |
| 386 name_(NULL), | 279 name_(NULL), |
| 387 start_time_(OS::GetCurrentTimeMicros()), | 280 start_time_(OS::GetCurrentTimeMicros()), |
| 388 main_port_(0), | 281 main_port_(0), |
| 389 heap_(NULL), | 282 heap_(NULL), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 402 deopt_id_(0), | 295 deopt_id_(0), |
| 403 mutex_(new Mutex()), | 296 mutex_(new Mutex()), |
| 404 stack_limit_(0), | 297 stack_limit_(0), |
| 405 saved_stack_limit_(0), | 298 saved_stack_limit_(0), |
| 406 message_handler_(NULL), | 299 message_handler_(NULL), |
| 407 spawn_data_(0), | 300 spawn_data_(0), |
| 408 is_runnable_(false), | 301 is_runnable_(false), |
| 409 gc_prologue_callbacks_(), | 302 gc_prologue_callbacks_(), |
| 410 gc_epilogue_callbacks_(), | 303 gc_epilogue_callbacks_(), |
| 411 defer_finalization_count_(0), | 304 defer_finalization_count_(0), |
| 412 deopt_cpu_registers_copy_(NULL), | 305 deopt_context_(NULL), |
| 413 deopt_fpu_registers_copy_(NULL), | |
| 414 deopt_frame_copy_(NULL), | |
| 415 deopt_frame_copy_size_(0), | |
| 416 deferred_boxes_(NULL), | |
| 417 deferred_object_refs_(NULL), | |
| 418 deferred_objects_count_(0), | |
| 419 deferred_objects_(NULL), | |
| 420 stacktrace_(NULL), | 306 stacktrace_(NULL), |
| 421 stack_frame_index_(-1), | 307 stack_frame_index_(-1), |
| 422 object_histogram_(NULL), | 308 object_histogram_(NULL), |
| 423 object_id_ring_(NULL), | 309 object_id_ring_(NULL), |
| 424 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) | 310 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) |
| 425 reusable_handles_() { | 311 reusable_handles_() { |
| 426 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) { | 312 if (FLAG_print_object_histogram && (Dart::vm_isolate() != NULL)) { |
| 427 object_histogram_ = new ObjectHistogram(this); | 313 object_histogram_ = new ObjectHistogram(this); |
| 428 } | 314 } |
| 429 } | 315 } |
| 430 #undef REUSABLE_HANDLE_INITIALIZERS | 316 #undef REUSABLE_HANDLE_INITIALIZERS |
| 431 | 317 |
| 432 | 318 |
| 433 Isolate::~Isolate() { | 319 Isolate::~Isolate() { |
| 434 delete [] name_; | 320 delete [] name_; |
| 435 delete heap_; | 321 delete heap_; |
| 436 delete object_store_; | 322 delete object_store_; |
| 437 delete api_state_; | 323 delete api_state_; |
| 438 delete stub_code_; | 324 delete stub_code_; |
| 439 delete debugger_; | 325 delete debugger_; |
| 440 #if defined(USING_SIMULATOR) | 326 #if defined(USING_SIMULATOR) |
| 441 delete simulator_; | 327 delete simulator_; |
| 442 #endif | 328 #endif |
| 443 delete mutex_; | 329 delete mutex_; |
| 444 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. | 330 mutex_ = NULL; // Fail fast if interrupts are scheduled on a dead isolate. |
| 445 delete message_handler_; | 331 delete message_handler_; |
| 446 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. | 332 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. |
| 333 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. |
| 447 delete object_histogram_; | 334 delete object_histogram_; |
| 448 } | 335 } |
| 449 | 336 |
| 450 void Isolate::SetCurrent(Isolate* current) { | 337 void Isolate::SetCurrent(Isolate* current) { |
| 451 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); | 338 Thread::SetThreadLocal(isolate_key, reinterpret_cast<uword>(current)); |
| 452 } | 339 } |
| 453 | 340 |
| 454 | 341 |
| 455 // The single thread local key which stores all the thread local data | 342 // The single thread local key which stores all the thread local data |
| 456 // for a thread. Since an Isolate is the central repository for | 343 // for a thread. Since an Isolate is the central repository for |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 // Visit the dart api state for all local and persistent handles. | 744 // Visit the dart api state for all local and persistent handles. |
| 858 if (api_state() != NULL) { | 745 if (api_state() != NULL) { |
| 859 api_state()->VisitObjectPointers(visitor, visit_prologue_weak_handles); | 746 api_state()->VisitObjectPointers(visitor, visit_prologue_weak_handles); |
| 860 } | 747 } |
| 861 | 748 |
| 862 // Visit the top context which is stored in the isolate. | 749 // Visit the top context which is stored in the isolate. |
| 863 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); | 750 visitor->VisitPointer(reinterpret_cast<RawObject**>(&top_context_)); |
| 864 | 751 |
| 865 // Visit objects in the debugger. | 752 // Visit objects in the debugger. |
| 866 debugger()->VisitObjectPointers(visitor); | 753 debugger()->VisitObjectPointers(visitor); |
| 754 |
| 755 // Visit objects that are being used for deoptimization. |
| 756 if (deopt_context() != NULL) { |
| 757 deopt_context()->VisitObjectPointers(visitor); |
| 758 } |
| 867 } | 759 } |
| 868 | 760 |
| 869 | 761 |
| 870 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, | 762 void Isolate::VisitWeakPersistentHandles(HandleVisitor* visitor, |
| 871 bool visit_prologue_weak_handles) { | 763 bool visit_prologue_weak_handles) { |
| 872 if (api_state() != NULL) { | 764 if (api_state() != NULL) { |
| 873 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); | 765 api_state()->VisitWeakHandles(visitor, visit_prologue_weak_handles); |
| 874 } | 766 } |
| 875 } | 767 } |
| 876 | 768 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 | 964 |
| 1073 | 965 |
| 1074 template<class T> | 966 template<class T> |
| 1075 T* Isolate::AllocateReusableHandle() { | 967 T* Isolate::AllocateReusableHandle() { |
| 1076 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); | 968 T* handle = reinterpret_cast<T*>(reusable_handles_.AllocateScopedHandle()); |
| 1077 T::initializeHandle(handle, T::null()); | 969 T::initializeHandle(handle, T::null()); |
| 1078 return handle; | 970 return handle; |
| 1079 } | 971 } |
| 1080 | 972 |
| 1081 | 973 |
| 1082 static void FillDeferredSlots(DeferredSlot** slot_list) { | |
| 1083 DeferredSlot* slot = *slot_list; | |
| 1084 *slot_list = NULL; | |
| 1085 | |
| 1086 while (slot != NULL) { | |
| 1087 DeferredSlot* current = slot; | |
| 1088 slot = slot->next(); | |
| 1089 | |
| 1090 current->Materialize(); | |
| 1091 | |
| 1092 delete current; | |
| 1093 } | |
| 1094 } | |
| 1095 | |
| 1096 | |
| 1097 void Isolate::MaterializeDeferredBoxes() { | |
| 1098 FillDeferredSlots(&deferred_boxes_); | |
| 1099 } | |
| 1100 | |
| 1101 | |
| 1102 void Isolate::MaterializeDeferredObjects() { | |
| 1103 FillDeferredSlots(&deferred_object_refs_); | |
| 1104 } | |
| 1105 | |
| 1106 | |
| 1107 static char* GetRootScriptUri(Isolate* isolate) { | 974 static char* GetRootScriptUri(Isolate* isolate) { |
| 1108 const Library& library = | 975 const Library& library = |
| 1109 Library::Handle(isolate->object_store()->root_library()); | 976 Library::Handle(isolate->object_store()->root_library()); |
| 1110 ASSERT(!library.IsNull()); | 977 ASSERT(!library.IsNull()); |
| 1111 const String& script_name = String::Handle(library.url()); | 978 const String& script_name = String::Handle(library.url()); |
| 1112 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); | 979 return isolate->current_zone()->MakeCopyOfString(script_name.ToCString()); |
| 1113 } | 980 } |
| 1114 | 981 |
| 1115 | 982 |
| 1116 IsolateSpawnState::IsolateSpawnState(const Function& func, | 983 IsolateSpawnState::IsolateSpawnState(const Function& func, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 return func.raw(); | 1054 return func.raw(); |
| 1188 } | 1055 } |
| 1189 | 1056 |
| 1190 | 1057 |
| 1191 void IsolateSpawnState::Cleanup() { | 1058 void IsolateSpawnState::Cleanup() { |
| 1192 SwitchIsolateScope switch_scope(isolate()); | 1059 SwitchIsolateScope switch_scope(isolate()); |
| 1193 Dart::ShutdownIsolate(); | 1060 Dart::ShutdownIsolate(); |
| 1194 } | 1061 } |
| 1195 | 1062 |
| 1196 } // namespace dart | 1063 } // namespace dart |
| OLD | NEW |