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

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

Issue 11970024: Simplify exception handler table (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | « no previous file | runtime/vm/debugger.cc » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 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 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_CODE_DESCRIPTORS_H_ 5 #ifndef VM_CODE_DESCRIPTORS_H_
6 #define VM_CODE_DESCRIPTORS_H_ 6 #define VM_CODE_DESCRIPTORS_H_
7 7
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 Stackmap& stack_map_; 92 Stackmap& stack_map_;
93 GrowableObjectArray& list_; 93 GrowableObjectArray& list_;
94 DISALLOW_COPY_AND_ASSIGN(StackmapTableBuilder); 94 DISALLOW_COPY_AND_ASSIGN(StackmapTableBuilder);
95 }; 95 };
96 96
97 97
98 class ExceptionHandlerList : public ZoneAllocated { 98 class ExceptionHandlerList : public ZoneAllocated {
99 public: 99 public:
100 struct HandlerDesc { 100 struct HandlerDesc {
101 intptr_t try_index; // Try block index handled by the handler.
102 intptr_t outer_try_index; // Try block in which this try block is nested. 101 intptr_t outer_try_index; // Try block in which this try block is nested.
103 intptr_t pc_offset; // Handler PC offset value. 102 intptr_t pc_offset; // Handler PC offset value.
104 const Array* handler_types; // Catch clause guards. 103 const Array* handler_types; // Catch clause guards.
105 }; 104 };
106 105
107 ExceptionHandlerList() : list_() {} 106 ExceptionHandlerList() : list_() {}
108 107
109 intptr_t Length() const { 108 intptr_t Length() const {
110 return list_.length(); 109 return list_.length();
111 } 110 }
112 111
113 intptr_t TryIndex(int index) const { 112 void AddPlaceHolder() {
114 return list_[index].try_index; 113 struct HandlerDesc data;
115 } 114 data.outer_try_index = -1;
116 intptr_t OuterTryIndex(int index) const { 115 data.pc_offset = -1;
117 return list_[index].outer_try_index; 116 data.handler_types = NULL;
118 } 117 list_.Add(data);
119 intptr_t PcOffset(int index) const {
120 return list_[index].pc_offset;
121 }
122 const Array& HandlerTypes(int index) const {
123 return *list_[index].handler_types;
124 }
125 void SetPcOffset(int index, intptr_t handler_pc) {
126 list_[index].pc_offset = handler_pc;
127 } 118 }
128 119
129 void AddHandler(intptr_t try_index, 120 void AddHandler(intptr_t try_index,
130 intptr_t outer_try_index, 121 intptr_t outer_try_index,
131 intptr_t pc_offset, 122 intptr_t pc_offset,
132 const Array& handler_types) { 123 const Array& handler_types) {
133 struct HandlerDesc data; 124 ASSERT(try_index >= 0);
134 data.try_index = try_index; 125 while (Length() <= try_index) {
135 data.outer_try_index = outer_try_index; 126 AddPlaceHolder();
136 data.pc_offset = pc_offset; 127 }
128 list_[try_index].outer_try_index = outer_try_index;
129 list_[try_index].pc_offset = pc_offset;
137 ASSERT(handler_types.IsZoneHandle()); 130 ASSERT(handler_types.IsZoneHandle());
138 data.handler_types = &handler_types; 131 list_[try_index].handler_types = &handler_types;
139 list_.Add(data);
140 } 132 }
141 133
142 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) { 134 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) {
143 intptr_t num_handlers = Length(); 135 intptr_t num_handlers = Length();
144 const ExceptionHandlers& handlers = 136 const ExceptionHandlers& handlers =
145 ExceptionHandlers::Handle(ExceptionHandlers::New(num_handlers)); 137 ExceptionHandlers::Handle(ExceptionHandlers::New(num_handlers));
146 for (intptr_t i = 0; i < num_handlers; i++) { 138 for (intptr_t i = 0; i < num_handlers; i++) {
147 handlers.SetHandlerInfo(i, TryIndex(i), OuterTryIndex(i), 139 // Assert that every element in the array has been initialized.
148 (entry_point + PcOffset(i))); 140 ASSERT(list_[i].handler_types != NULL);
149 handlers.SetHandledTypes(i, HandlerTypes(i)); 141 handlers.SetHandlerInfo(i,
142 list_[i].outer_try_index,
143 (entry_point + list_[i].pc_offset));
144 handlers.SetHandledTypes(i, *list_[i].handler_types);
150 } 145 }
151 return handlers.raw(); 146 return handlers.raw();
152 } 147 }
153 148
154 private: 149 private:
155 GrowableArray<struct HandlerDesc> list_; 150 GrowableArray<struct HandlerDesc> list_;
156 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); 151 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList);
157 }; 152 };
158 153
159 } // namespace dart 154 } // namespace dart
160 155
161 #endif // VM_CODE_DESCRIPTORS_H_ 156 #endif // VM_CODE_DESCRIPTORS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698