OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 RUNTIME_VM_SAFEPOINT_H_ | 5 #ifndef RUNTIME_VM_SAFEPOINT_H_ |
6 #define RUNTIME_VM_SAFEPOINT_H_ | 6 #define RUNTIME_VM_SAFEPOINT_H_ |
7 | 7 |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
10 #include "vm/thread.h" | 10 #include "vm/thread.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 313 |
314 | 314 |
315 // TransitionToGenerated is used to transition the safepoint state of a | 315 // TransitionToGenerated is used to transition the safepoint state of a |
316 // thread from "running vm code" or "running native code" to | 316 // thread from "running vm code" or "running native code" to |
317 // "running generated code" and ensures that the state is reverted back | 317 // "running generated code" and ensures that the state is reverted back |
318 // to "running vm code" or "running native code" when exiting the | 318 // to "running vm code" or "running native code" when exiting the |
319 // scope/frame. | 319 // scope/frame. |
320 class TransitionToGenerated : public TransitionSafepointState { | 320 class TransitionToGenerated : public TransitionSafepointState { |
321 public: | 321 public: |
322 explicit TransitionToGenerated(Thread* T) | 322 explicit TransitionToGenerated(Thread* T) |
323 : TransitionSafepointState(T), | 323 : TransitionSafepointState(T), execution_state_(T->execution_state()) { |
324 execution_state_(T->execution_state()) { | |
325 ASSERT(T == Thread::Current()); | 324 ASSERT(T == Thread::Current()); |
326 ASSERT((execution_state_ == Thread::kThreadInVM) || | 325 ASSERT((execution_state_ == Thread::kThreadInVM) || |
327 (execution_state_ == Thread::kThreadInNative)); | 326 (execution_state_ == Thread::kThreadInNative)); |
328 if (execution_state_ == Thread::kThreadInNative) { | 327 if (execution_state_ == Thread::kThreadInNative) { |
329 T->ExitSafepoint(); | 328 T->ExitSafepoint(); |
330 } | 329 } |
331 T->set_execution_state(Thread::kThreadInGenerated); | 330 T->set_execution_state(Thread::kThreadInGenerated); |
332 } | 331 } |
333 | 332 |
334 ~TransitionToGenerated() { | 333 ~TransitionToGenerated() { |
(...skipping 15 matching lines...) Expand all Loading... |
350 | 349 |
351 // TransitionToVM is used to transition the safepoint state of a | 350 // TransitionToVM is used to transition the safepoint state of a |
352 // thread from "running native code" to "running vm code" | 351 // thread from "running native code" to "running vm code" |
353 // and ensures that the state is reverted back to "running native code" | 352 // and ensures that the state is reverted back to "running native code" |
354 // when exiting the scope/frame. | 353 // when exiting the scope/frame. |
355 // This transition helper is mainly used in the error path of the | 354 // This transition helper is mainly used in the error path of the |
356 // Dart API implementations where we sometimes do not have an explicit | 355 // Dart API implementations where we sometimes do not have an explicit |
357 // transition set up. | 356 // transition set up. |
358 class TransitionToVM : public TransitionSafepointState { | 357 class TransitionToVM : public TransitionSafepointState { |
359 public: | 358 public: |
360 explicit TransitionToVM(Thread* T) : TransitionSafepointState(T), | 359 explicit TransitionToVM(Thread* T) |
361 execution_state_(T->execution_state()) { | 360 : TransitionSafepointState(T), execution_state_(T->execution_state()) { |
362 ASSERT(T == Thread::Current()); | 361 ASSERT(T == Thread::Current()); |
363 ASSERT((execution_state_ == Thread::kThreadInVM) || | 362 ASSERT((execution_state_ == Thread::kThreadInVM) || |
364 (execution_state_ == Thread::kThreadInNative)); | 363 (execution_state_ == Thread::kThreadInNative)); |
365 if (execution_state_ == Thread::kThreadInNative) { | 364 if (execution_state_ == Thread::kThreadInNative) { |
366 T->ExitSafepoint(); | 365 T->ExitSafepoint(); |
367 T->set_execution_state(Thread::kThreadInVM); | 366 T->set_execution_state(Thread::kThreadInVM); |
368 } | 367 } |
369 ASSERT(T->execution_state() == Thread::kThreadInVM); | 368 ASSERT(T->execution_state() == Thread::kThreadInVM); |
370 } | 369 } |
371 | 370 |
372 ~TransitionToVM() { | 371 ~TransitionToVM() { |
373 ASSERT(thread()->execution_state() == Thread::kThreadInVM); | 372 ASSERT(thread()->execution_state() == Thread::kThreadInVM); |
374 if (execution_state_ == Thread::kThreadInNative) { | 373 if (execution_state_ == Thread::kThreadInNative) { |
375 thread()->set_execution_state(Thread::kThreadInNative); | 374 thread()->set_execution_state(Thread::kThreadInNative); |
376 thread()->EnterSafepoint(); | 375 thread()->EnterSafepoint(); |
377 } | 376 } |
378 } | 377 } |
379 | 378 |
380 private: | 379 private: |
381 uint32_t execution_state_; | 380 uint32_t execution_state_; |
382 DISALLOW_COPY_AND_ASSIGN(TransitionToVM); | 381 DISALLOW_COPY_AND_ASSIGN(TransitionToVM); |
383 }; | 382 }; |
384 | 383 |
385 } // namespace dart | 384 } // namespace dart |
386 | 385 |
387 #endif // RUNTIME_VM_SAFEPOINT_H_ | 386 #endif // RUNTIME_VM_SAFEPOINT_H_ |
OLD | NEW |