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 #ifndef VM_ALLOCATION_H_ | 5 #ifndef VM_ALLOCATION_H_ |
6 #define VM_ALLOCATION_H_ | 6 #define VM_ALLOCATION_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/base_isolate.h" | 9 #include "vm/base_isolate.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 }; | 29 }; |
30 | 30 |
31 | 31 |
32 // Stack resources subclass from this base class. The VM will ensure that the | 32 // Stack resources subclass from this base class. The VM will ensure that the |
33 // destructors of these objects are called before the stack is unwound past the | 33 // destructors of these objects are called before the stack is unwound past the |
34 // objects location on the stack. Use stack resource objects if objects | 34 // objects location on the stack. Use stack resource objects if objects |
35 // need to be destroyed even in the case of exceptions when a Longjump is done | 35 // need to be destroyed even in the case of exceptions when a Longjump is done |
36 // to a stack frame above the frame where these objects were allocated. | 36 // to a stack frame above the frame where these objects were allocated. |
37 class StackResource { | 37 class StackResource { |
38 public: | 38 public: |
39 explicit StackResource(BaseIsolate* isolate) | 39 explicit StackResource(Isolate* isolate) |
40 : isolate_(isolate), previous_(NULL) { | 40 : isolate_(reinterpret_cast<BaseIsolate*>(isolate)), previous_(NULL) { |
koda
2014/05/05 21:51:28
Use implicit_cast from platform/globals.h.
| |
41 // We can only have longjumps and exceptions when there is a current | 41 // We can only have longjumps and exceptions when there is a current |
42 // isolate. If there is no current isolate, we don't need to | 42 // isolate. If there is no current isolate, we don't need to |
43 // protect this case. | 43 // protect this case. |
44 if (isolate != NULL) { | 44 if (isolate_ != NULL) { |
45 previous_ = isolate->top_resource(); | 45 previous_ = isolate_->top_resource(); |
46 isolate->set_top_resource(this); | 46 isolate_->set_top_resource(this); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 virtual ~StackResource() { | 50 virtual ~StackResource() { |
51 if (isolate() != NULL) { | 51 if (isolate_ != NULL) { |
52 StackResource* top = isolate()->top_resource(); | 52 StackResource* top = isolate_->top_resource(); |
53 ASSERT(top == this); | 53 ASSERT(top == this); |
54 isolate()->set_top_resource(previous_); | 54 isolate_->set_top_resource(previous_); |
55 } | 55 } |
56 #if defined(DEBUG) | 56 #if defined(DEBUG) |
57 if (isolate() != NULL) { | 57 if (isolate_ != NULL) { |
58 BaseIsolate::AssertCurrent(isolate()); | 58 BaseIsolate::AssertCurrent(isolate_); |
59 } | 59 } |
60 #endif | 60 #endif |
61 } | 61 } |
62 | 62 |
63 BaseIsolate* isolate() const { return isolate_; } | 63 // We can only create StackResources with Isolates, so provide the original |
64 // isolate to the subclasses. The only reason we have a BaseIsolate in the | |
65 // StackResource is to break the header include cycles. | |
66 Isolate* isolate() const { return reinterpret_cast<Isolate*>(isolate_); } | |
koda
2014/05/05 21:51:28
Use down_cast.
| |
64 | 67 |
65 private: | 68 private: |
66 BaseIsolate* const isolate_; // Current isolate for this stack resource. | 69 BaseIsolate* const isolate_; // Current isolate for this stack resource. |
67 StackResource* previous_; | 70 StackResource* previous_; |
68 | 71 |
69 DISALLOW_ALLOCATION(); | 72 DISALLOW_ALLOCATION(); |
70 DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource); | 73 DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource); |
71 }; | 74 }; |
72 | 75 |
73 | 76 |
(...skipping 29 matching lines...) Expand all Loading... | |
103 // deallocated by invoking DeleteAll() on the zone they live in. | 106 // deallocated by invoking DeleteAll() on the zone they live in. |
104 void operator delete(void* pointer) { UNREACHABLE(); } | 107 void operator delete(void* pointer) { UNREACHABLE(); } |
105 | 108 |
106 private: | 109 private: |
107 DISALLOW_COPY_AND_ASSIGN(ZoneAllocated); | 110 DISALLOW_COPY_AND_ASSIGN(ZoneAllocated); |
108 }; | 111 }; |
109 | 112 |
110 } // namespace dart | 113 } // namespace dart |
111 | 114 |
112 #endif // VM_ALLOCATION_H_ | 115 #endif // VM_ALLOCATION_H_ |
OLD | NEW |