| 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 | |
| 5 | #ifndef RUNTIME_VM_BASE_ISOLATE_H_ |
| 6 | #define RUNTIME_VM_BASE_ISOLATE_H_ |
| 7 | |
| 8 | #include "platform/assert.h" |
| 9 | #include "vm/globals.h" |
| 10 | |
| 11 | namespace dart { |
| 12 | |
| 13 | class HandleScope; |
| 14 | class StackResource; |
| 15 | class Thread; |
| 16 | class Zone; |
| 17 | |
| 18 | // A BaseIsolate contains just enough functionality to allocate |
| 19 | // StackResources. This allows us to inline the StackResource |
| 20 | // constructor/destructor for performance. |
| 21 | class BaseIsolate { |
| 22 | public: |
| 23 | #if defined(DEBUG) |
| 24 | void AssertCurrentThreadIsMutator() const; |
| 25 | #else |
| 26 | void AssertCurrentThreadIsMutator() const {} |
| 27 | #endif // DEBUG |
| 28 | |
| 29 | #if defined(DEBUG) |
| 30 | static void AssertCurrent(BaseIsolate* isolate); |
| 31 | #endif |
| 32 | |
| 33 | protected: |
| 34 | BaseIsolate() {} |
| 35 | |
| 36 | ~BaseIsolate() { |
| 37 | // Do not delete stack resources: top_resource_ and current_zone_. |
| 38 | } |
| 39 | |
| 40 | Thread* scheduled_mutator_thread_ = nullptr; |
| 41 | |
| 42 | // TODO(asiva): Currently we treat a mutator thread as a special thread |
| 43 | // and always schedule execution of Dart code on the same mutator thread |
| 44 | // object. The ApiLocalScope has been made thread specific but we still |
| 45 | // have scenarios where we do a temporary exit of an Isolate with live |
| 46 | // zones/handles in the API scope : |
| 47 | // - Dart_RunLoop() |
| 48 | // - IsolateSaver in Dart_NewNativePort |
| 49 | // Similarly, tracking async_stack_trace requires that we always reschedule |
| 50 | // on the same thread. |
| 51 | // We probably need a mechanism to return to the specific thread only |
| 52 | // for these specific cases. We should also determine if the embedder |
| 53 | // should allow exiting an isolate with live state in zones/handles in |
| 54 | // which case a new API for returning to the specific thread needs to be |
| 55 | // added. |
| 56 | Thread* mutator_thread_ = nullptr; |
| 57 | |
| 58 | private: |
| 59 | DISALLOW_COPY_AND_ASSIGN(BaseIsolate); |
| 60 | }; |
| 61 | |
| 62 | } // namespace dart |
| 63 | |
| 64 | #endif // RUNTIME_VM_BASE_ISOLATE_H_ |
| 65 | |