| 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 "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 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2538   OSThread* os_thread = OSThread::Current(); | 2538   OSThread* os_thread = OSThread::Current(); | 
| 2539   if (os_thread != NULL) { | 2539   if (os_thread != NULL) { | 
| 2540     // We are about to associate the thread with an isolate and it would | 2540     // We are about to associate the thread with an isolate and it would | 
| 2541     // not be possible to correctly track no_safepoint_scope_depth for the | 2541     // not be possible to correctly track no_safepoint_scope_depth for the | 
| 2542     // thread in the constructor/destructor of MonitorLocker, | 2542     // thread in the constructor/destructor of MonitorLocker, | 
| 2543     // so we create a MonitorLocker object which does not do any | 2543     // so we create a MonitorLocker object which does not do any | 
| 2544     // no_safepoint_scope_depth increments/decrements. | 2544     // no_safepoint_scope_depth increments/decrements. | 
| 2545     MonitorLocker ml(threads_lock(), false); | 2545     MonitorLocker ml(threads_lock(), false); | 
| 2546 | 2546 | 
| 2547     // Check to make sure we don't already have a mutator thread. | 2547     // Check to make sure we don't already have a mutator thread. | 
| 2548     if (is_mutator && mutator_thread_ != NULL) { | 2548     if (is_mutator && scheduled_mutator_thread_ != NULL) { | 
| 2549       return NULL; | 2549       return NULL; | 
| 2550     } | 2550     } | 
| 2551 | 2551 | 
| 2552     // If a safepoint operation is in progress wait for it | 2552     // If a safepoint operation is in progress wait for it | 
| 2553     // to finish before scheduling this thread in. | 2553     // to finish before scheduling this thread in. | 
| 2554     while (!bypass_safepoint && safepoint_handler()->SafepointInProgress()) { | 2554     while (!bypass_safepoint && safepoint_handler()->SafepointInProgress()) { | 
| 2555       ml.Wait(); | 2555       ml.Wait(); | 
| 2556     } | 2556     } | 
| 2557 | 2557 | 
| 2558     // Now get a free Thread structure. | 2558     // Now get a free Thread structure. | 
| 2559     thread = thread_registry()->GetFreeThreadLocked(this, is_mutator); | 2559     thread = thread_registry()->GetFreeThreadLocked(this, is_mutator); | 
| 2560     ASSERT(thread != NULL); | 2560     ASSERT(thread != NULL); | 
| 2561 | 2561 | 
| 2562     thread->ResetHighWatermark(); | 2562     thread->ResetHighWatermark(); | 
| 2563 | 2563 | 
| 2564     // Set up other values and set the TLS value. | 2564     // Set up other values and set the TLS value. | 
| 2565     thread->isolate_ = this; | 2565     thread->isolate_ = this; | 
| 2566     ASSERT(heap() != NULL); | 2566     ASSERT(heap() != NULL); | 
| 2567     thread->heap_ = heap(); | 2567     thread->heap_ = heap(); | 
| 2568     thread->set_os_thread(os_thread); | 2568     thread->set_os_thread(os_thread); | 
| 2569     ASSERT(thread->execution_state() == Thread::kThreadInNative); | 2569     ASSERT(thread->execution_state() == Thread::kThreadInNative); | 
| 2570     thread->set_execution_state(Thread::kThreadInVM); | 2570     thread->set_execution_state(Thread::kThreadInVM); | 
| 2571     thread->set_safepoint_state(0); | 2571     thread->set_safepoint_state(0); | 
| 2572     thread->set_vm_tag(VMTag::kVMTagId); | 2572     thread->set_vm_tag(VMTag::kVMTagId); | 
| 2573     ASSERT(thread->no_safepoint_scope_depth() == 0); | 2573     ASSERT(thread->no_safepoint_scope_depth() == 0); | 
| 2574     os_thread->set_thread(thread); | 2574     os_thread->set_thread(thread); | 
| 2575     if (is_mutator) { | 2575     if (is_mutator) { | 
| 2576       mutator_thread_ = thread; | 2576       scheduled_mutator_thread_ = thread; | 
| 2577       if ((Dart::vm_isolate() != NULL) && | 2577       if ((Dart::vm_isolate() != NULL) && | 
| 2578           (heap() != Dart::vm_isolate()->heap())) { | 2578           (heap() != Dart::vm_isolate()->heap())) { | 
| 2579         mutator_thread_->set_top(0); | 2579         scheduled_mutator_thread_->set_top(0); | 
| 2580         mutator_thread_->set_end(0); | 2580         scheduled_mutator_thread_->set_end(0); | 
| 2581       } | 2581       } | 
| 2582     } | 2582     } | 
| 2583     Thread::SetCurrent(thread); | 2583     Thread::SetCurrent(thread); | 
| 2584     os_thread->EnableThreadInterrupts(); | 2584     os_thread->EnableThreadInterrupts(); | 
| 2585   } | 2585   } | 
| 2586   return thread; | 2586   return thread; | 
| 2587 } | 2587 } | 
| 2588 | 2588 | 
| 2589 void Isolate::UnscheduleThread(Thread* thread, | 2589 void Isolate::UnscheduleThread(Thread* thread, | 
| 2590                                bool is_mutator, | 2590                                bool is_mutator, | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 2612     thread->EnterSafepoint(); | 2612     thread->EnterSafepoint(); | 
| 2613   } | 2613   } | 
| 2614   OSThread* os_thread = thread->os_thread(); | 2614   OSThread* os_thread = thread->os_thread(); | 
| 2615   ASSERT(os_thread != NULL); | 2615   ASSERT(os_thread != NULL); | 
| 2616   os_thread->DisableThreadInterrupts(); | 2616   os_thread->DisableThreadInterrupts(); | 
| 2617   os_thread->set_thread(NULL); | 2617   os_thread->set_thread(NULL); | 
| 2618   OSThread::SetCurrent(os_thread); | 2618   OSThread::SetCurrent(os_thread); | 
| 2619   if (is_mutator) { | 2619   if (is_mutator) { | 
| 2620     if ((Dart::vm_isolate() != NULL) && | 2620     if ((Dart::vm_isolate() != NULL) && | 
| 2621         (heap() != Dart::vm_isolate()->heap())) { | 2621         (heap() != Dart::vm_isolate()->heap())) { | 
| 2622       if (mutator_thread_->HasActiveTLAB()) { | 2622       if (scheduled_mutator_thread_->HasActiveTLAB()) { | 
| 2623         heap()->AbandonRemainingTLAB(mutator_thread_); | 2623         heap()->AbandonRemainingTLAB(scheduled_mutator_thread_); | 
| 2624       } | 2624       } | 
| 2625     } | 2625     } | 
| 2626     ASSERT(!mutator_thread_->HasActiveTLAB()); | 2626     ASSERT(!scheduled_mutator_thread_->HasActiveTLAB()); | 
| 2627     mutator_thread_ = NULL; | 2627     scheduled_mutator_thread_ = NULL; | 
| 2628   } | 2628   } | 
| 2629   thread->isolate_ = NULL; | 2629   thread->isolate_ = NULL; | 
| 2630   thread->heap_ = NULL; | 2630   thread->heap_ = NULL; | 
| 2631   thread->set_os_thread(NULL); | 2631   thread->set_os_thread(NULL); | 
| 2632   thread->set_execution_state(Thread::kThreadInNative); | 2632   thread->set_execution_state(Thread::kThreadInNative); | 
| 2633   thread->set_safepoint_state(Thread::SetAtSafepoint(true, 0)); | 2633   thread->set_safepoint_state(Thread::SetAtSafepoint(true, 0)); | 
| 2634   thread->clear_pending_functions(); | 2634   thread->clear_pending_functions(); | 
| 2635   ASSERT(thread->no_safepoint_scope_depth() == 0); | 2635   ASSERT(thread->no_safepoint_scope_depth() == 0); | 
| 2636   // Return thread structure. | 2636   // Return thread structure. | 
| 2637   thread_registry()->ReturnThreadLocked(is_mutator, thread); | 2637   thread_registry()->ReturnThreadLocked(is_mutator, thread); | 
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2855 void IsolateSpawnState::DecrementSpawnCount() { | 2855 void IsolateSpawnState::DecrementSpawnCount() { | 
| 2856   ASSERT(spawn_count_monitor_ != NULL); | 2856   ASSERT(spawn_count_monitor_ != NULL); | 
| 2857   ASSERT(spawn_count_ != NULL); | 2857   ASSERT(spawn_count_ != NULL); | 
| 2858   MonitorLocker ml(spawn_count_monitor_); | 2858   MonitorLocker ml(spawn_count_monitor_); | 
| 2859   ASSERT(*spawn_count_ > 0); | 2859   ASSERT(*spawn_count_ > 0); | 
| 2860   *spawn_count_ = *spawn_count_ - 1; | 2860   *spawn_count_ = *spawn_count_ - 1; | 
| 2861   ml.Notify(); | 2861   ml.Notify(); | 
| 2862 } | 2862 } | 
| 2863 | 2863 | 
| 2864 }  // namespace dart | 2864 }  // namespace dart | 
| OLD | NEW | 
|---|