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