| OLD | NEW |
| 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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. |
| 6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
| 7 | 7 |
| 8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 9 | 9 |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 RawCode* CodePatcher::GetNativeCallAt(uword return_address, | 83 RawCode* CodePatcher::GetNativeCallAt(uword return_address, |
| 84 const Code& code, | 84 const Code& code, |
| 85 NativeFunction* target) { | 85 NativeFunction* target) { |
| 86 ASSERT(code.ContainsInstructionAt(return_address)); | 86 ASSERT(code.ContainsInstructionAt(return_address)); |
| 87 NativeCallPattern call(return_address, code); | 87 NativeCallPattern call(return_address, code); |
| 88 *target = call.native_function(); | 88 *target = call.native_function(); |
| 89 return call.target(); | 89 return call.target(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 | |
| 93 // This class pattern matches on a load from the object pool. Loading on | |
| 94 // ARM is complicated because it can take four possible different forms. We | |
| 95 // match backwards from the end of the sequence so we can reuse the code for | |
| 96 // matching object pool loads at calls. | |
| 97 class EdgeCounter : public ValueObject { | |
| 98 public: | |
| 99 EdgeCounter(uword pc, const Code& code) | |
| 100 : end_(pc - FlowGraphCompiler::EdgeCounterIncrementSizeInBytes()), | |
| 101 object_pool_(ObjectPool::Handle(code.GetObjectPool())) { | |
| 102 // An IsValid predicate is complicated and duplicates the code in the | |
| 103 // decoding function. Instead we rely on decoding the pattern which | |
| 104 // will assert partial validity. | |
| 105 } | |
| 106 | |
| 107 RawObject* edge_counter() const { | |
| 108 Register ignored; | |
| 109 intptr_t index; | |
| 110 InstructionPattern::DecodeLoadWordFromPool(end_, &ignored, &index); | |
| 111 ASSERT(ignored == R0); | |
| 112 return object_pool_.ObjectAt(index); | |
| 113 } | |
| 114 | |
| 115 private: | |
| 116 // The object pool load is followed by the fixed-size edge counter | |
| 117 // incrementing code: | |
| 118 // ldr ip, [r0, #+11] | |
| 119 // adds ip, ip, #2 | |
| 120 // str ip, [r0, #+11] | |
| 121 static const intptr_t kAdjust = 3 * Instr::kInstrSize; | |
| 122 | |
| 123 uword end_; | |
| 124 const ObjectPool& object_pool_; | |
| 125 }; | |
| 126 | |
| 127 | |
| 128 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { | |
| 129 ASSERT(code.ContainsInstructionAt(pc)); | |
| 130 EdgeCounter counter(pc, code); | |
| 131 return counter.edge_counter(); | |
| 132 } | |
| 133 | |
| 134 } // namespace dart | 92 } // namespace dart |
| 135 | 93 |
| 136 #endif // defined TARGET_ARCH_ARM | 94 #endif // defined TARGET_ARCH_ARM |
| OLD | NEW |