Chromium Code Reviews| 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 #ifndef VM_DART_API_IMPL_H_ | 5 #ifndef VM_DART_API_IMPL_H_ |
| 6 #define VM_DART_API_IMPL_H_ | 6 #define VM_DART_API_IMPL_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/native_arguments.h" | 9 #include "vm/native_arguments.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 #include "vm/timer.h" | |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 | 14 |
| 14 DECLARE_FLAG(bool, trace_api); | 15 DECLARE_FLAG(bool, trace_api); |
| 15 | 16 |
| 16 class ApiLocalScope; | 17 class ApiLocalScope; |
| 17 class ApiState; | 18 class ApiState; |
| 18 class FinalizablePersistentHandle; | 19 class FinalizablePersistentHandle; |
| 19 class LocalHandle; | 20 class LocalHandle; |
| 20 class PersistentHandle; | 21 class PersistentHandle; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 #define CHECK_ISOLATE_SCOPE(isolate) \ | 59 #define CHECK_ISOLATE_SCOPE(isolate) \ |
| 59 do { \ | 60 do { \ |
| 60 Isolate* tmp = (isolate); \ | 61 Isolate* tmp = (isolate); \ |
| 61 CHECK_ISOLATE(tmp); \ | 62 CHECK_ISOLATE(tmp); \ |
| 62 ApiState* state = tmp->api_state(); \ | 63 ApiState* state = tmp->api_state(); \ |
| 63 ASSERT(state); \ | 64 ASSERT(state); \ |
| 64 if (state->top_scope() == NULL) { \ | 65 if (state->top_scope() == NULL) { \ |
| 65 FATAL1("%s expects to find a current scope. Did you forget to call " \ | 66 FATAL1("%s expects to find a current scope. Did you forget to call " \ |
| 66 "Dart_EnterScope?", CURRENT_FUNC); \ | 67 "Dart_EnterScope?", CURRENT_FUNC); \ |
| 67 } \ | 68 } \ |
| 68 } while (0) | 69 } while (0); \ |
| 70 NativeToVmTimerScope __temp_isolate_timer__(isolate); | |
| 69 | 71 |
| 70 #define DARTSCOPE(isolate) \ | 72 #define DARTSCOPE(isolate) \ |
| 71 Isolate* __temp_isolate__ = (isolate); \ | 73 Isolate* __temp_isolate__ = (isolate); \ |
| 72 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ | 74 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ |
| 73 HANDLESCOPE(__temp_isolate__); | 75 HANDLESCOPE(__temp_isolate__); |
| 74 | 76 |
| 75 | 77 |
| 76 #define RETURN_TYPE_ERROR(isolate, dart_handle, type) \ | 78 #define RETURN_TYPE_ERROR(isolate, dart_handle, type) \ |
| 77 do { \ | 79 do { \ |
| 78 const Object& tmp = \ | 80 const Object& tmp = \ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 } | 255 } |
| 254 ~IsolateSaver() { | 256 ~IsolateSaver() { |
| 255 Isolate::SetCurrent(saved_isolate_); | 257 Isolate::SetCurrent(saved_isolate_); |
| 256 } | 258 } |
| 257 private: | 259 private: |
| 258 Isolate* saved_isolate_; | 260 Isolate* saved_isolate_; |
| 259 | 261 |
| 260 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); | 262 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); |
| 261 }; | 263 }; |
| 262 | 264 |
| 265 class VmToNativeTimerScope : public ValueObject { | |
| 266 public: | |
| 267 explicit VmToNativeTimerScope(Isolate* isolate) { | |
| 268 native_timer_ = &(isolate->timer_list().time_native_execution()); | |
| 269 native_timer_->Start(); | |
| 270 } | |
| 271 ~VmToNativeTimerScope() { | |
| 272 native_timer_->Stop(); | |
| 273 } | |
| 274 | |
| 275 private: | |
| 276 Timer* native_timer_; | |
| 277 DISALLOW_COPY_AND_ASSIGN(VmToNativeTimerScope); | |
| 278 }; | |
| 279 | |
| 280 class NativeToVmTimerScope : public ValueObject { | |
| 281 public: | |
| 282 explicit NativeToVmTimerScope(Isolate* isolate) | |
| 283 : dart_running_(false), | |
| 284 timer_list_(&(isolate->timer_list())) { | |
| 285 Timer* dart_timer = &(timer_list_->time_dart_execution()); | |
| 286 Timer* native_timer = &(timer_list_->time_native_execution()); | |
| 287 // Currently when a native function is setup without the auto scope | |
| 288 // setup parameter (leaf function) we would have the dart timer still | |
| 289 // running as we have not done any transitioning. If for some reason | |
| 290 // such a native function makes API call backs we should account for | |
| 291 // that. | |
| 292 if (dart_timer->running()) { | |
| 293 dart_running_ = true; | |
| 294 dart_timer->Stop(); | |
| 295 } else if (native_timer->running()) { | |
| 296 native_timer->Stop(); | |
| 297 } | |
|
turnidge
2014/02/11 21:24:33
Is it ever the case that neither timer is running
siva
2014/02/19 22:38:30
Changed the code to have just
if (dart_timer->runn
| |
| 298 } | |
| 299 ~NativeToVmTimerScope() { | |
| 300 if (dart_running_) { | |
| 301 Timer* dart_timer = &(timer_list_->time_dart_execution()); | |
| 302 dart_timer->Start(); | |
| 303 } else { | |
| 304 Timer* native_timer = &(timer_list_->time_native_execution()); | |
| 305 native_timer->Start(); | |
| 306 } | |
| 307 } | |
| 308 | |
| 309 private: | |
| 310 bool dart_running_; | |
| 311 TimerList* timer_list_; | |
| 312 DISALLOW_COPY_AND_ASSIGN(NativeToVmTimerScope); | |
| 313 }; | |
| 314 | |
| 263 // Start a scope in which no Dart API call backs are allowed. | 315 // Start a scope in which no Dart API call backs are allowed. |
| 264 #define START_NO_CALLBACK_SCOPE(isolate) \ | 316 #define START_NO_CALLBACK_SCOPE(isolate) \ |
| 265 isolate->IncrementNoCallbackScopeDepth() | 317 isolate->IncrementNoCallbackScopeDepth() |
| 266 | 318 |
| 267 // End a no Dart API call backs Scope. | 319 // End a no Dart API call backs Scope. |
| 268 #define END_NO_CALLBACK_SCOPE(isolate) \ | 320 #define END_NO_CALLBACK_SCOPE(isolate) \ |
| 269 isolate->DecrementNoCallbackScopeDepth() | 321 isolate->DecrementNoCallbackScopeDepth() |
| 270 | 322 |
| 271 #define CHECK_CALLBACK_STATE(isolate) \ | 323 #define CHECK_CALLBACK_STATE(isolate) \ |
| 272 if (isolate->no_callback_scope_depth() != 0) { \ | 324 if (isolate->no_callback_scope_depth() != 0) { \ |
| 273 return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \ | 325 return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \ |
| 274 } \ | 326 } \ |
| 275 | 327 |
| 276 #define ASSERT_CALLBACK_STATE(isolate) \ | 328 #define ASSERT_CALLBACK_STATE(isolate) \ |
| 277 ASSERT(isolate->no_callback_scope_depth() == 0) | 329 ASSERT(isolate->no_callback_scope_depth() == 0) |
| 278 | 330 |
| 279 } // namespace dart. | 331 } // namespace dart. |
| 280 | 332 |
| 281 #endif // VM_DART_API_IMPL_H_ | 333 #endif // VM_DART_API_IMPL_H_ |
| OLD | NEW |