OLD | NEW |
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 RUNTIME_VM_CODE_DESCRIPTORS_H_ | 5 #ifndef RUNTIME_VM_CODE_DESCRIPTORS_H_ |
6 #define RUNTIME_VM_CODE_DESCRIPTORS_H_ | 6 #define RUNTIME_VM_CODE_DESCRIPTORS_H_ |
7 | 7 |
8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/datastream.h" |
10 #include "vm/globals.h" | 11 #include "vm/globals.h" |
11 #include "vm/growable_array.h" | 12 #include "vm/growable_array.h" |
12 #include "vm/object.h" | 13 #include "vm/object.h" |
13 #include "vm/log.h" | 14 #include "vm/log.h" |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 class DescriptorList : public ZoneAllocated { | 18 class DescriptorList : public ZoneAllocated { |
18 public: | 19 public: |
19 explicit DescriptorList(intptr_t initial_capacity) | 20 explicit DescriptorList(intptr_t initial_capacity) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 142 } |
142 | 143 |
143 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const; | 144 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const; |
144 | 145 |
145 private: | 146 private: |
146 GrowableArray<struct HandlerDesc> list_; | 147 GrowableArray<struct HandlerDesc> list_; |
147 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); | 148 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); |
148 }; | 149 }; |
149 | 150 |
150 | 151 |
| 152 // An encoded move from stack/constant to stack performed |
| 153 struct CatchEntryStatePair { |
| 154 enum { kCatchEntryStateIsMove = 1, kCatchEntryStateDestShift = 1 }; |
| 155 |
| 156 intptr_t src, dest; |
| 157 |
| 158 static CatchEntryStatePair FromConstant(intptr_t pool_id, |
| 159 intptr_t dest_slot) { |
| 160 CatchEntryStatePair pair; |
| 161 pair.src = pool_id; |
| 162 pair.dest = (dest_slot << kCatchEntryStateDestShift); |
| 163 return pair; |
| 164 } |
| 165 |
| 166 static CatchEntryStatePair FromMove(intptr_t src_slot, intptr_t dest_slot) { |
| 167 CatchEntryStatePair pair; |
| 168 pair.src = src_slot; |
| 169 pair.dest = |
| 170 (dest_slot << kCatchEntryStateDestShift) | kCatchEntryStateIsMove; |
| 171 return pair; |
| 172 } |
| 173 |
| 174 bool operator==(const CatchEntryStatePair& rhs) { |
| 175 return src == rhs.src && dest == rhs.dest; |
| 176 } |
| 177 }; |
| 178 |
| 179 |
| 180 // Used to construct CatchEntryState metadata for AoT mode of compilation. |
| 181 class CatchEntryStateMapBuilder : public ZoneAllocated { |
| 182 public: |
| 183 CatchEntryStateMapBuilder(); |
| 184 |
| 185 void NewMapping(intptr_t pc_offset); |
| 186 void AppendMove(intptr_t src_slot, intptr_t dest_slot); |
| 187 void AppendConstant(intptr_t pool_id, intptr_t dest_slot); |
| 188 void EndMapping(); |
| 189 RawTypedData* FinalizeCatchEntryStateMap(); |
| 190 |
| 191 private: |
| 192 class TrieNode; |
| 193 |
| 194 Zone* zone_; |
| 195 TrieNode* root_; |
| 196 intptr_t current_pc_offset_; |
| 197 GrowableArray<CatchEntryStatePair> moves_; |
| 198 uint8_t* buffer_; |
| 199 WriteStream stream_; |
| 200 |
| 201 DISALLOW_COPY_AND_ASSIGN(CatchEntryStateMapBuilder); |
| 202 }; |
| 203 |
| 204 |
151 // A CodeSourceMap maps from pc offsets to a stack of inlined functions and | 205 // A CodeSourceMap maps from pc offsets to a stack of inlined functions and |
152 // their positions. This is encoded as a little bytecode that pushes and pops | 206 // their positions. This is encoded as a little bytecode that pushes and pops |
153 // functions and changes the top function's position as the PC advances. | 207 // functions and changes the top function's position as the PC advances. |
154 // Decoding happens by running this bytecode until we reach the desired PC. | 208 // Decoding happens by running this bytecode until we reach the desired PC. |
155 // | 209 // |
156 // The implementation keeps track of two sets of state: one written to the byte | 210 // The implementation keeps track of two sets of state: one written to the byte |
157 // stream and one that is buffered. On the JIT, this buffering effectively gives | 211 // stream and one that is buffered. On the JIT, this buffering effectively gives |
158 // us a peephole optimization that merges adjacent advance PC bytecodes. On AOT, | 212 // us a peephole optimization that merges adjacent advance PC bytecodes. On AOT, |
159 // this allows to skip encoding our position until we reach a PC where we might | 213 // this allows to skip encoding our position until we reach a PC where we might |
160 // throw. | 214 // throw. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 const CodeSourceMap& map_; | 322 const CodeSourceMap& map_; |
269 const Array& functions_; | 323 const Array& functions_; |
270 const Function& root_; | 324 const Function& root_; |
271 | 325 |
272 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader); | 326 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader); |
273 }; | 327 }; |
274 | 328 |
275 } // namespace dart | 329 } // namespace dart |
276 | 330 |
277 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_ | 331 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_ |
OLD | NEW |