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

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

Issue 187503002: 1. Restructure reusable handles to make individual Scopes for each handle type (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_REUSABLE_HANDLES_H_ 5 #ifndef VM_REUSABLE_HANDLES_H_
6 #define VM_REUSABLE_HANDLES_H_ 6 #define VM_REUSABLE_HANDLES_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/handles.h" 9 #include "vm/handles.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 // The class ReusableHandleScope is used in regions of the 14 // The class ReusableHandleScope is used in regions of the
15 // virtual machine where isolate specific reusable handles are used. 15 // virtual machine where isolate specific reusable handles are used.
16 // This class asserts that we do not add code that will result in recursive 16 // This class asserts that we do not add code that will result in recursive
17 // uses of reusable handles. 17 // uses of reusable handles.
18 // It is used as follows: 18 // It is used as follows:
19 // { 19 // {
20 // ReusableHandleScope reused_handles(isolate); 20 // ReusableHandleScope reused_handles(isolate);
21 // .... 21 // ....
22 // ..... 22 // .....
23 // code that uses isolate specific reusable handles. 23 // code that uses isolate specific reusable handles.
24 // Array& funcs = reused_handles.ArrayHandle(); 24 // Array& funcs = reused_handles.ArrayHandle();
25 // .... 25 // ....
26 // } 26 // }
27
27 #if defined(DEBUG) 28 #if defined(DEBUG)
28 class ReusableObjectHandleScope : public StackResource { 29 #define REUSABLE_SCOPE(name) \
29 public: 30 class Reusable##name##HandleScope : public ValueObject { \
30 explicit ReusableObjectHandleScope(Isolate* isolate) 31 public: \
31 : StackResource(isolate), isolate_(isolate) { 32 explicit Reusable##name##HandleScope(Isolate* isolate) \
32 ASSERT(!isolate->reusable_handle_scope_active()); 33 : isolate_(isolate) { \
33 isolate->set_reusable_handle_scope_active(true); 34 ASSERT(!isolate->reusable_##name##_handle_scope_active()); \
34 } 35 isolate->set_reusable_##name##_handle_scope_active(true); \
35 ReusableObjectHandleScope() 36 } \
36 : StackResource(Isolate::Current()), isolate_(Isolate::Current()) { 37 Reusable##name##HandleScope() : isolate_(Isolate::Current()) { \
37 ASSERT(!isolate()->reusable_handle_scope_active()); 38 ASSERT(!isolate_->reusable_##name##_handle_scope_active()); \
38 isolate()->set_reusable_handle_scope_active(true); 39 isolate_->set_reusable_##name##_handle_scope_active(true); \
39 } 40 } \
40 ~ReusableObjectHandleScope() { 41 ~Reusable##name##HandleScope() { \
41 ASSERT(isolate()->reusable_handle_scope_active()); 42 ASSERT(isolate_->reusable_##name##_handle_scope_active()); \
42 isolate()->set_reusable_handle_scope_active(false); 43 isolate_->set_reusable_##name##_handle_scope_active(false); \
43 Handle().raw_ = Object::null(); 44 Handle().raw_ = name::null(); \
44 } 45 } \
45 Object& Handle() const { 46 name& Handle() const { \
46 ASSERT(isolate_->Object_handle_ != NULL); 47 ASSERT(isolate_->name##_handle_ != NULL); \
47 return *isolate_->Object_handle_; 48 return *isolate_->name##_handle_; \
48 } 49 } \
50 private: \
51 Isolate* isolate_; \
52 DISALLOW_COPY_AND_ASSIGN(Reusable##name##HandleScope); \
53 };
54 #else
55 #define REUSABLE_SCOPE(name) \
56 class Reusable##name##HandleScope : public ValueObject { \
57 public: \
58 explicit Reusable##name##HandleScope(Isolate* isolate) \
59 : handle_(isolate->name##_handle_) { \
60 } \
61 Reusable##name##HandleScope() \
62 : handle_(Isolate::Current()->name##_handle_) { \
63 } \
64 ~Reusable##name##HandleScope() { \
65 handle_->raw_ = name::null(); \
66 } \
67 name& Handle() const { \
68 ASSERT(handle_ != NULL); \
69 return *handle_; \
70 } \
71 private: \
72 name* handle_; \
73 DISALLOW_COPY_AND_ASSIGN(Reusable##name##HandleScope); \
74 };
75 #endif // defined(DEBUG)
76 REUSABLE_HANDLE_LIST(REUSABLE_SCOPE)
77 #undef REUSABLE_SCOPE
49 78
50 private: 79 #define REUSABLE_OBJECT_HANDLESCOPE(isolate) \
51 Isolate* isolate_; 80 ReusableObjectHandleScope reused_object_handle(isolate);
52 DISALLOW_COPY_AND_ASSIGN(ReusableObjectHandleScope); 81 #define REUSABLE_ARRAY_HANDLESCOPE(isolate) \
53 }; 82 ReusableArrayHandleScope reused_array_handle(isolate);
54 83 #define REUSABLE_STRING_HANDLESCOPE(isolate) \
55 84 ReusableStringHandleScope reused_string_handle(isolate);
56 class ReusableHandleScope : public StackResource { 85 #define REUSABLE_INSTANCE_HANDLESCOPE(isolate) \
57 public: 86 ReusableInstanceHandleScope reused_instance_handle(isolate);
58 explicit ReusableHandleScope(Isolate* isolate) 87 #define REUSABLE_FUNCTION_HANDLESCOPE(isolate) \
59 : StackResource(isolate), isolate_(isolate) { 88 ReusableFunctionHandleScope reused_function_handle(isolate);
60 ASSERT(!isolate->reusable_handle_scope_active()); 89 #define REUSABLE_FIELD_HANDLESCOPE(isolate) \
61 isolate->set_reusable_handle_scope_active(true); 90 ReusableFieldHandleScope reused_field_handle(isolate);
62 } 91 #define REUSABLE_CLASS_HANDLESCOPE(isolate) \
63 ReusableHandleScope() 92 ReusableClassHandleScope reused_class_handle(isolate);
64 : StackResource(Isolate::Current()), isolate_(Isolate::Current()) { 93 #define REUSABLE_TYPE_PARAMETER_HANDLESCOPE(isolate) \
65 ASSERT(!isolate()->reusable_handle_scope_active()); 94 ReusableTypeParameterHandleScope reused_type_parameter(isolate);
66 isolate()->set_reusable_handle_scope_active(true); 95 #define REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(isolate) \
67 } 96 ReusableTypeArgumentsHandleScope reused_type_arguments_handle(isolate);
68 ~ReusableHandleScope() {
69 ASSERT(isolate()->reusable_handle_scope_active());
70 isolate()->set_reusable_handle_scope_active(false);
71 #define CLEAR_REUSABLE_HANDLE(object) \
72 object##Handle().raw_ = Object::null(); \
73
74 REUSABLE_HANDLE_LIST(CLEAR_REUSABLE_HANDLE);
75 }
76
77 #define REUSABLE_HANDLE_ACCESSORS(object) \
78 object& object##Handle() const { \
79 ASSERT(isolate_->object##_handle_ != NULL); \
80 return *isolate_->object##_handle_; \
81 } \
82
83 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ACCESSORS)
84 #undef REUSABLE_HANDLE_ACCESSORS
85
86 private:
87 void ResetHandles();
88 Isolate* isolate_;
89 DISALLOW_COPY_AND_ASSIGN(ReusableHandleScope);
90 };
91 #else
92 class ReusableObjectHandleScope : public ValueObject {
93 public:
94 explicit ReusableObjectHandleScope(Isolate* isolate)
95 : handle_(isolate->Object_handle_) {
96 }
97 ReusableObjectHandleScope() : handle_(Isolate::Current()->Object_handle_) {
98 }
99 ~ReusableObjectHandleScope() {
100 handle_->raw_ = Object::null();
101 }
102 Object& Handle() const {
103 ASSERT(handle_ != NULL);
104 return *handle_;
105 }
106
107 private:
108 Object* handle_;
109 DISALLOW_COPY_AND_ASSIGN(ReusableObjectHandleScope);
110 };
111
112
113 class ReusableHandleScope : public ValueObject {
114 public:
115 explicit ReusableHandleScope(Isolate* isolate) : isolate_(isolate) {
116 }
117 ReusableHandleScope() : isolate_(Isolate::Current()) {
118 }
119 ~ReusableHandleScope() {
120 #define CLEAR_REUSABLE_HANDLE(object) \
121 object##Handle().raw_ = Object::null(); \
122
123 REUSABLE_HANDLE_LIST(CLEAR_REUSABLE_HANDLE);
124 }
125
126 #define REUSABLE_HANDLE_ACCESSORS(object) \
127 object& object##Handle() const { \
128 ASSERT(isolate_->object##_handle_ != NULL); \
129 return *isolate_->object##_handle_; \
130 } \
131
132 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ACCESSORS)
133 #undef REUSABLE_HANDLE_ACCESSORS
134
135 private:
136 void ResetHandles();
137 Isolate* isolate_;
138 DISALLOW_COPY_AND_ASSIGN(ReusableHandleScope);
139 };
140 #endif // defined(DEBUG)
141 97
142 } // namespace dart 98 } // namespace dart
143 99
144 #endif // VM_REUSABLE_HANDLES_H_ 100 #endif // VM_REUSABLE_HANDLES_H_
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698