Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: runtime/vm/allocation.h

Issue 1384403002: Preparation for moving reusable handles to thread and more cleanups: isolate -> thread based handle… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "vm/thread.h"
12 11
13 namespace dart { 12 namespace dart {
14 13
15 // Forward declarations. 14 // Forward declarations.
16 class Isolate; 15 class Isolate;
16 class Thread;
17 17
18 // Stack allocated objects subclass from this base class. Objects of this type 18 // Stack allocated objects subclass from this base class. Objects of this type
19 // cannot be allocated on either the C or object heaps. Destructors for objects 19 // cannot be allocated on either the C or object heaps. Destructors for objects
20 // of this type will not be run unless the stack is unwound through normal 20 // of this type will not be run unless the stack is unwound through normal
21 // program control flow. 21 // program control flow.
22 class ValueObject { 22 class ValueObject {
23 public: 23 public:
24 ValueObject() { } 24 ValueObject() { }
25 ~ValueObject() { } 25 ~ValueObject() { }
26 26
(...skipping 14 matching lines...) Expand all
41 // to using the mutator thread (which must also be the current thread). 41 // to using the mutator thread (which must also be the current thread).
42 explicit StackResource(Isolate* isolate) : thread_(NULL), previous_(NULL) { 42 explicit StackResource(Isolate* isolate) : thread_(NULL), previous_(NULL) {
43 Init((isolate == NULL) ? 43 Init((isolate == NULL) ?
44 NULL : reinterpret_cast<BaseIsolate*>(isolate)->mutator_thread_); 44 NULL : reinterpret_cast<BaseIsolate*>(isolate)->mutator_thread_);
45 } 45 }
46 46
47 explicit StackResource(Thread* thread) : thread_(NULL), previous_(NULL) { 47 explicit StackResource(Thread* thread) : thread_(NULL), previous_(NULL) {
48 Init(thread); 48 Init(thread);
49 } 49 }
50 50
51 virtual ~StackResource() { 51 virtual ~StackResource();
52 if (thread_ != NULL) {
53 StackResource* top = thread_->top_resource();
54 ASSERT(top == this);
55 thread_->set_top_resource(previous_);
56 }
57 #if defined(DEBUG)
58 if (thread_ != NULL) {
59 ASSERT(Thread::Current() == thread_);
60 BaseIsolate::AssertCurrent(reinterpret_cast<BaseIsolate*>(isolate()));
61 }
62 #endif
63 }
64 52
65 // Convenient access to the isolate of the thread of this resource. 53 // Convenient access to the isolate of the thread of this resource.
66 Isolate* isolate() const { 54 Isolate* isolate() const;
67 return thread_ == NULL ? NULL : thread_->isolate();
68 }
69 55
70 // The thread that owns this resource. 56 // The thread that owns this resource.
71 Thread* thread() const { return thread_; } 57 Thread* thread() const { return thread_; }
72 58
73 // Destroy stack resources of thread until top exit frame. 59 // Destroy stack resources of thread until top exit frame.
74 static void Unwind(Thread* thread) { UnwindAbove(thread, NULL); } 60 static void Unwind(Thread* thread) { UnwindAbove(thread, NULL); }
75 // Destroy stack resources of thread above new_top, exclusive. 61 // Destroy stack resources of thread above new_top, exclusive.
76 static void UnwindAbove(Thread* thread, StackResource* new_top); 62 static void UnwindAbove(Thread* thread, StackResource* new_top);
77 63
78 private: 64 private:
79 void Init(Thread* thread) { 65 void Init(Thread* thread);
80 // We can only have longjumps and exceptions when there is a current
81 // thread and isolate. If there is no current thread, we don't need to
82 // protect this case.
83 // TODO(23807): Eliminate this special case.
84 if (thread != NULL) {
85 ASSERT(Thread::Current() == thread);
86 thread_ = thread;
87 previous_ = thread_->top_resource();
88 ASSERT((previous_ == NULL) || (previous_->thread_ == thread));
89 thread_->set_top_resource(this);
90 }
91 }
92 66
93 Thread* thread_; 67 Thread* thread_;
94 StackResource* previous_; 68 StackResource* previous_;
95 69
96 DISALLOW_ALLOCATION(); 70 DISALLOW_ALLOCATION();
97 DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource); 71 DISALLOW_IMPLICIT_CONSTRUCTORS(StackResource);
98 }; 72 };
99 73
100 74
101 // Static allocated classes only contain static members and can never 75 // Static allocated classes only contain static members and can never
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 public: 125 public:
152 NoSafepointScope() {} 126 NoSafepointScope() {}
153 private: 127 private:
154 DISALLOW_COPY_AND_ASSIGN(NoSafepointScope); 128 DISALLOW_COPY_AND_ASSIGN(NoSafepointScope);
155 }; 129 };
156 #endif // defined(DEBUG) 130 #endif // defined(DEBUG)
157 131
158 } // namespace dart 132 } // namespace dart
159 133
160 #endif // VM_ALLOCATION_H_ 134 #endif // VM_ALLOCATION_H_
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/allocation.cc » ('j') | runtime/vm/gc_marker.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698