| 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" | |
| 11 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| 12 #include "vm/growable_array.h" | 11 #include "vm/growable_array.h" |
| 13 #include "vm/object.h" | 12 #include "vm/object.h" |
| 14 #include "vm/log.h" | 13 #include "vm/log.h" |
| 15 | 14 |
| 16 namespace dart { | 15 namespace dart { |
| 17 | 16 |
| 18 class DescriptorList : public ZoneAllocated { | 17 class DescriptorList : public ZoneAllocated { |
| 19 public: | 18 public: |
| 20 explicit DescriptorList(intptr_t initial_capacity) | 19 explicit DescriptorList(intptr_t initial_capacity) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 141 } |
| 143 | 142 |
| 144 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const; | 143 RawExceptionHandlers* FinalizeExceptionHandlers(uword entry_point) const; |
| 145 | 144 |
| 146 private: | 145 private: |
| 147 GrowableArray<struct HandlerDesc> list_; | 146 GrowableArray<struct HandlerDesc> list_; |
| 148 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); | 147 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerList); |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 | 150 |
| 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 | |
| 205 // A CodeSourceMap maps from pc offsets to a stack of inlined functions and | 151 // A CodeSourceMap maps from pc offsets to a stack of inlined functions and |
| 206 // their positions. This is encoded as a little bytecode that pushes and pops | 152 // their positions. This is encoded as a little bytecode that pushes and pops |
| 207 // functions and changes the top function's position as the PC advances. | 153 // functions and changes the top function's position as the PC advances. |
| 208 // Decoding happens by running this bytecode until we reach the desired PC. | 154 // Decoding happens by running this bytecode until we reach the desired PC. |
| 209 // | 155 // |
| 210 // The implementation keeps track of two sets of state: one written to the byte | 156 // The implementation keeps track of two sets of state: one written to the byte |
| 211 // stream and one that is buffered. On the JIT, this buffering effectively gives | 157 // stream and one that is buffered. On the JIT, this buffering effectively gives |
| 212 // us a peephole optimization that merges adjacent advance PC bytecodes. On AOT, | 158 // us a peephole optimization that merges adjacent advance PC bytecodes. On AOT, |
| 213 // this allows to skip encoding our position until we reach a PC where we might | 159 // this allows to skip encoding our position until we reach a PC where we might |
| 214 // throw. | 160 // throw. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 const CodeSourceMap& map_; | 268 const CodeSourceMap& map_; |
| 323 const Array& functions_; | 269 const Array& functions_; |
| 324 const Function& root_; | 270 const Function& root_; |
| 325 | 271 |
| 326 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader); | 272 DISALLOW_COPY_AND_ASSIGN(CodeSourceMapReader); |
| 327 }; | 273 }; |
| 328 | 274 |
| 329 } // namespace dart | 275 } // namespace dart |
| 330 | 276 |
| 331 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_ | 277 #endif // RUNTIME_VM_CODE_DESCRIPTORS_H_ |
| OLD | NEW |