| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "vm/timeline_analysis.h" | 45 #include "vm/timeline_analysis.h" |
| 46 #include "vm/timer.h" | 46 #include "vm/timer.h" |
| 47 #include "vm/visitor.h" | 47 #include "vm/visitor.h" |
| 48 | 48 |
| 49 | 49 |
| 50 namespace dart { | 50 namespace dart { |
| 51 | 51 |
| 52 DECLARE_FLAG(bool, print_metrics); | 52 DECLARE_FLAG(bool, print_metrics); |
| 53 DECLARE_FLAG(bool, timing); | 53 DECLARE_FLAG(bool, timing); |
| 54 DECLARE_FLAG(bool, trace_service); | 54 DECLARE_FLAG(bool, trace_service); |
| 55 DECLARE_FLAG(bool, trace_service_verbose); |
| 55 | 56 |
| 56 DEFINE_FLAG(bool, trace_isolates, false, | 57 DEFINE_FLAG(bool, trace_isolates, false, |
| 57 "Trace isolate creation and shut down."); | 58 "Trace isolate creation and shut down."); |
| 58 DEFINE_FLAG(bool, pause_isolates_on_start, false, | 59 DEFINE_FLAG(bool, pause_isolates_on_start, false, |
| 59 "Pause isolates before starting."); | 60 "Pause isolates before starting."); |
| 60 DEFINE_FLAG(bool, pause_isolates_on_exit, false, | 61 DEFINE_FLAG(bool, pause_isolates_on_exit, false, |
| 61 "Pause isolates exiting."); | 62 "Pause isolates exiting."); |
| 62 DEFINE_FLAG(bool, pause_isolates_on_unhandled_exceptions, false, | 63 DEFINE_FLAG(bool, pause_isolates_on_unhandled_exceptions, false, |
| 63 "Pause isolates on unhandled exceptions."); | 64 "Pause isolates on unhandled exceptions."); |
| 64 | 65 |
| (...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 deferred_interrupts_ = stack_limit_ & deferred_interrupts_mask_; | 1518 deferred_interrupts_ = stack_limit_ & deferred_interrupts_mask_; |
| 1518 | 1519 |
| 1519 // Clear deferrable interrupts, if present. | 1520 // Clear deferrable interrupts, if present. |
| 1520 stack_limit_ &= ~deferred_interrupts_mask_; | 1521 stack_limit_ &= ~deferred_interrupts_mask_; |
| 1521 | 1522 |
| 1522 if ((stack_limit_ & kInterruptsMask) == 0) { | 1523 if ((stack_limit_ & kInterruptsMask) == 0) { |
| 1523 // No other pending interrupts. Restore normal stack limit. | 1524 // No other pending interrupts. Restore normal stack limit. |
| 1524 stack_limit_ = saved_stack_limit_; | 1525 stack_limit_ = saved_stack_limit_; |
| 1525 } | 1526 } |
| 1526 } | 1527 } |
| 1528 if (FLAG_trace_service && FLAG_trace_service_verbose) { |
| 1529 OS::Print("[+%" Pd64 "ms] Isolate %s deferring OOB interrupts\n", |
| 1530 Dart::timestamp(), name()); |
| 1531 } |
| 1527 } | 1532 } |
| 1528 | 1533 |
| 1529 | 1534 |
| 1530 void Isolate::RestoreOOBMessageInterrupts() { | 1535 void Isolate::RestoreOOBMessageInterrupts() { |
| 1531 MutexLocker ml(mutex_); | 1536 MutexLocker ml(mutex_); |
| 1532 ASSERT(deferred_interrupts_mask_ == kMessageInterrupt); | 1537 ASSERT(deferred_interrupts_mask_ == kMessageInterrupt); |
| 1533 deferred_interrupts_mask_ = 0; | 1538 deferred_interrupts_mask_ = 0; |
| 1534 if (deferred_interrupts_ != 0) { | 1539 if (deferred_interrupts_ != 0) { |
| 1535 if (stack_limit_ == saved_stack_limit_) { | 1540 if (stack_limit_ == saved_stack_limit_) { |
| 1536 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; | 1541 stack_limit_ = (~static_cast<uword>(0)) & ~kInterruptsMask; |
| 1537 } | 1542 } |
| 1538 stack_limit_ |= deferred_interrupts_; | 1543 stack_limit_ |= deferred_interrupts_; |
| 1539 deferred_interrupts_ = 0; | 1544 deferred_interrupts_ = 0; |
| 1540 } | 1545 } |
| 1546 if (FLAG_trace_service && FLAG_trace_service_verbose) { |
| 1547 OS::Print("[+%" Pd64 "ms] Isolate %s restoring OOB interrupts\n", |
| 1548 Dart::timestamp(), name()); |
| 1549 } |
| 1541 } | 1550 } |
| 1542 | 1551 |
| 1543 | 1552 |
| 1544 RawError* Isolate::HandleInterrupts() { | 1553 RawError* Isolate::HandleInterrupts() { |
| 1545 uword interrupt_bits = GetAndClearInterrupts(); | 1554 uword interrupt_bits = GetAndClearInterrupts(); |
| 1546 if ((interrupt_bits & kVMInterrupt) != 0) { | 1555 if ((interrupt_bits & kVMInterrupt) != 0) { |
| 1547 if (store_buffer()->Overflowed()) { | 1556 if (store_buffer()->Overflowed()) { |
| 1548 if (FLAG_verbose_gc) { | 1557 if (FLAG_verbose_gc) { |
| 1549 OS::PrintErr("Scavenge scheduled by store buffer overflow.\n"); | 1558 OS::PrintErr("Scavenge scheduled by store buffer overflow.\n"); |
| 1550 } | 1559 } |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 return Object::null(); | 2106 return Object::null(); |
| 2098 } | 2107 } |
| 2099 // Grab run function. | 2108 // Grab run function. |
| 2100 const Library& developer_lib = Library::Handle(Library::DeveloperLibrary()); | 2109 const Library& developer_lib = Library::Handle(Library::DeveloperLibrary()); |
| 2101 ASSERT(!developer_lib.IsNull()); | 2110 ASSERT(!developer_lib.IsNull()); |
| 2102 const Function& run_extension = Function::Handle( | 2111 const Function& run_extension = Function::Handle( |
| 2103 developer_lib.LookupLocalFunction(Symbols::_runExtension())); | 2112 developer_lib.LookupLocalFunction(Symbols::_runExtension())); |
| 2104 ASSERT(!run_extension.IsNull()); | 2113 ASSERT(!run_extension.IsNull()); |
| 2105 | 2114 |
| 2106 const Array& arguments = | 2115 const Array& arguments = |
| 2107 Array::Handle(Array::New(kPendingEntrySize, Heap::kNew)); | 2116 Array::Handle(Array::New(kPendingEntrySize + 1, Heap::kNew)); |
| 2108 Object& result = Object::Handle(); | 2117 Object& result = Object::Handle(); |
| 2109 String& method_name = String::Handle(); | 2118 String& method_name = String::Handle(); |
| 2110 Instance& closure = Instance::Handle(); | 2119 Instance& closure = Instance::Handle(); |
| 2111 Array& parameter_keys = Array::Handle(); | 2120 Array& parameter_keys = Array::Handle(); |
| 2112 Array& parameter_values = Array::Handle(); | 2121 Array& parameter_values = Array::Handle(); |
| 2113 Instance& reply_port = Instance::Handle(); | 2122 Instance& reply_port = Instance::Handle(); |
| 2114 Instance& id = Instance::Handle(); | 2123 Instance& id = Instance::Handle(); |
| 2115 for (intptr_t i = 0; i < calls.Length(); i += kPendingEntrySize) { | 2124 for (intptr_t i = 0; i < calls.Length(); i += kPendingEntrySize) { |
| 2116 // Grab arguments for call. | 2125 // Grab arguments for call. |
| 2117 closure ^= calls.At(i + kPendingHandlerIndex); | 2126 closure ^= calls.At(i + kPendingHandlerIndex); |
| 2118 ASSERT(!closure.IsNull()); | 2127 ASSERT(!closure.IsNull()); |
| 2119 arguments.SetAt(kPendingHandlerIndex, closure); | 2128 arguments.SetAt(kPendingHandlerIndex, closure); |
| 2120 method_name ^= calls.At(i + kPendingMethodNameIndex); | 2129 method_name ^= calls.At(i + kPendingMethodNameIndex); |
| 2121 ASSERT(!method_name.IsNull()); | 2130 ASSERT(!method_name.IsNull()); |
| 2122 arguments.SetAt(kPendingMethodNameIndex, method_name); | 2131 arguments.SetAt(kPendingMethodNameIndex, method_name); |
| 2123 parameter_keys ^= calls.At(i + kPendingKeysIndex); | 2132 parameter_keys ^= calls.At(i + kPendingKeysIndex); |
| 2124 ASSERT(!parameter_keys.IsNull()); | 2133 ASSERT(!parameter_keys.IsNull()); |
| 2125 arguments.SetAt(kPendingKeysIndex, parameter_keys); | 2134 arguments.SetAt(kPendingKeysIndex, parameter_keys); |
| 2126 parameter_values ^= calls.At(i + kPendingValuesIndex); | 2135 parameter_values ^= calls.At(i + kPendingValuesIndex); |
| 2127 ASSERT(!parameter_values.IsNull()); | 2136 ASSERT(!parameter_values.IsNull()); |
| 2128 arguments.SetAt(kPendingValuesIndex, parameter_values); | 2137 arguments.SetAt(kPendingValuesIndex, parameter_values); |
| 2129 reply_port ^= calls.At(i + kPendingReplyPortIndex); | 2138 reply_port ^= calls.At(i + kPendingReplyPortIndex); |
| 2130 ASSERT(!reply_port.IsNull()); | 2139 ASSERT(!reply_port.IsNull()); |
| 2131 arguments.SetAt(kPendingReplyPortIndex, reply_port); | 2140 arguments.SetAt(kPendingReplyPortIndex, reply_port); |
| 2132 id ^= calls.At(i + kPendingIdIndex); | 2141 id ^= calls.At(i + kPendingIdIndex); |
| 2133 arguments.SetAt(kPendingIdIndex, id); | 2142 arguments.SetAt(kPendingIdIndex, id); |
| 2143 arguments.SetAt(kPendingEntrySize, Bool::Get(FLAG_trace_service)); |
| 2134 | 2144 |
| 2145 if (FLAG_trace_service) { |
| 2146 OS::Print( |
| 2147 "[+%" Pd64 "ms] Isolate %s invoking _runExtension for %s\n", |
| 2148 Dart::timestamp(), name(), method_name.ToCString()); |
| 2149 } |
| 2135 result = DartEntry::InvokeFunction(run_extension, arguments); | 2150 result = DartEntry::InvokeFunction(run_extension, arguments); |
| 2151 if (FLAG_trace_service) { |
| 2152 OS::Print( |
| 2153 "[+%" Pd64 "ms] Isolate %s : _runExtension complete for %s\n", |
| 2154 Dart::timestamp(), name(), method_name.ToCString()); |
| 2155 } |
| 2136 if (result.IsError()) { | 2156 if (result.IsError()) { |
| 2137 if (result.IsUnwindError()) { | 2157 if (result.IsUnwindError()) { |
| 2138 // Propagate the unwind error. Remaining service extension calls | 2158 // Propagate the unwind error. Remaining service extension calls |
| 2139 // are dropped. | 2159 // are dropped. |
| 2140 return result.raw(); | 2160 return result.raw(); |
| 2141 } else { | 2161 } else { |
| 2142 // Send error back over the protocol. | 2162 // Send error back over the protocol. |
| 2143 Service::PostError(method_name, | 2163 Service::PostError(method_name, |
| 2144 parameter_keys, | 2164 parameter_keys, |
| 2145 parameter_values, | 2165 parameter_values, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2163 return r; | 2183 return r; |
| 2164 } | 2184 } |
| 2165 | 2185 |
| 2166 | 2186 |
| 2167 void Isolate::AppendServiceExtensionCall(const Instance& closure, | 2187 void Isolate::AppendServiceExtensionCall(const Instance& closure, |
| 2168 const String& method_name, | 2188 const String& method_name, |
| 2169 const Array& parameter_keys, | 2189 const Array& parameter_keys, |
| 2170 const Array& parameter_values, | 2190 const Array& parameter_values, |
| 2171 const Instance& reply_port, | 2191 const Instance& reply_port, |
| 2172 const Instance& id) { | 2192 const Instance& id) { |
| 2193 if (FLAG_trace_service) { |
| 2194 OS::Print( |
| 2195 "[+%" Pd64 "ms] Isolate %s ENQUEUING request for extension %s\n", |
| 2196 Dart::timestamp(), name(), method_name.ToCString()); |
| 2197 } |
| 2173 GrowableObjectArray& calls = | 2198 GrowableObjectArray& calls = |
| 2174 GrowableObjectArray::Handle(pending_service_extension_calls()); | 2199 GrowableObjectArray::Handle(pending_service_extension_calls()); |
| 2175 if (calls.IsNull()) { | 2200 if (calls.IsNull()) { |
| 2176 calls ^= GrowableObjectArray::New(); | 2201 calls ^= GrowableObjectArray::New(); |
| 2177 ASSERT(!calls.IsNull()); | 2202 ASSERT(!calls.IsNull()); |
| 2178 set_pending_service_extension_calls(calls); | 2203 set_pending_service_extension_calls(calls); |
| 2179 } | 2204 } |
| 2180 ASSERT(kPendingHandlerIndex == 0); | 2205 ASSERT(kPendingHandlerIndex == 0); |
| 2181 calls.Add(closure); | 2206 calls.Add(closure); |
| 2182 ASSERT(kPendingMethodNameIndex == 1); | 2207 ASSERT(kPendingMethodNameIndex == 1); |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2775 void IsolateSpawnState::DecrementSpawnCount() { | 2800 void IsolateSpawnState::DecrementSpawnCount() { |
| 2776 ASSERT(spawn_count_monitor_ != NULL); | 2801 ASSERT(spawn_count_monitor_ != NULL); |
| 2777 ASSERT(spawn_count_ != NULL); | 2802 ASSERT(spawn_count_ != NULL); |
| 2778 MonitorLocker ml(spawn_count_monitor_); | 2803 MonitorLocker ml(spawn_count_monitor_); |
| 2779 ASSERT(*spawn_count_ > 0); | 2804 ASSERT(*spawn_count_ > 0); |
| 2780 *spawn_count_ = *spawn_count_ - 1; | 2805 *spawn_count_ = *spawn_count_ - 1; |
| 2781 ml.Notify(); | 2806 ml.Notify(); |
| 2782 } | 2807 } |
| 2783 | 2808 |
| 2784 } // namespace dart | 2809 } // namespace dart |
| OLD | NEW |