Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 1 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 3 | // All Rights Reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // - Redistributions of source code must retain the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer. |
| 11 | // |
| 12 | // - Redistribution in binary form must reproduce the above copyright |
| 13 | // notice, this list of conditions and the following disclaimer in the |
| 14 | // documentation and/or other materials provided with the distribution. |
| 15 | // |
| 16 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 17 | // be used to endorse or promote products derived from this software without |
| 18 | // specific prior written permission. |
| 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 21 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 22 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 24 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | // The original source code covered by the above license above has been |
| 33 | // modified significantly by Google Inc. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 34 | // Copyright 2012 the V8 project authors. All rights reserved. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | #ifndef V8_MIPS_ASSEMBLER_MIPS_INL_H_ |
| 38 | #define V8_MIPS_ASSEMBLER_MIPS_INL_H_ |
| 39 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 40 | #include "src/mips/assembler-mips.h" |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 41 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 42 | #include "src/assembler.h" |
| 43 | #include "src/debug.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | namespace v8 { |
| 47 | namespace internal { |
| 48 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 49 | |
| 50 | bool CpuFeatures::SupportsCrankshaft() { return IsSupported(FPU); } |
| 51 | |
| 52 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 53 | // ----------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 54 | // Operand and MemOperand. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 55 | |
| 56 | Operand::Operand(int32_t immediate, RelocInfo::Mode rmode) { |
| 57 | rm_ = no_reg; |
| 58 | imm32_ = immediate; |
| 59 | rmode_ = rmode; |
| 60 | } |
| 61 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 62 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 63 | Operand::Operand(const ExternalReference& f) { |
| 64 | rm_ = no_reg; |
| 65 | imm32_ = reinterpret_cast<int32_t>(f.address()); |
| 66 | rmode_ = RelocInfo::EXTERNAL_REFERENCE; |
| 67 | } |
| 68 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 69 | |
| 70 | Operand::Operand(Smi* value) { |
| 71 | rm_ = no_reg; |
| 72 | imm32_ = reinterpret_cast<intptr_t>(value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 73 | rmode_ = RelocInfo::NONE32; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 76 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 77 | Operand::Operand(Register rm) { |
| 78 | rm_ = rm; |
| 79 | } |
| 80 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 81 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 82 | bool Operand::is_reg() const { |
| 83 | return rm_.is_valid(); |
| 84 | } |
| 85 | |
| 86 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 87 | int Register::NumAllocatableRegisters() { |
| 88 | return kMaxNumAllocatableRegisters; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | int DoubleRegister::NumRegisters() { |
| 93 | return FPURegister::kMaxNumRegisters; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | int DoubleRegister::NumAllocatableRegisters() { |
| 98 | return FPURegister::kMaxNumAllocatableRegisters; |
| 99 | } |
| 100 | |
| 101 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 102 | int FPURegister::ToAllocationIndex(FPURegister reg) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 103 | DCHECK(reg.code() % 2 == 0); |
| 104 | DCHECK(reg.code() / 2 < kMaxNumAllocatableRegisters); |
| 105 | DCHECK(reg.is_valid()); |
| 106 | DCHECK(!reg.is(kDoubleRegZero)); |
| 107 | DCHECK(!reg.is(kLithiumScratchDouble)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 108 | return (reg.code() / 2); |
| 109 | } |
| 110 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 111 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 112 | // ----------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 113 | // RelocInfo. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 114 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 115 | void RelocInfo::apply(intptr_t delta, ICacheFlushMode icache_flush_mode) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 116 | if (IsCodeTarget(rmode_)) { |
| 117 | uint32_t scope1 = (uint32_t) target_address() & ~kImm28Mask; |
| 118 | uint32_t scope2 = reinterpret_cast<uint32_t>(pc_) & ~kImm28Mask; |
| 119 | |
| 120 | if (scope1 != scope2) { |
| 121 | Assembler::JumpLabelToJumpRegister(pc_); |
| 122 | } |
| 123 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 124 | if (IsInternalReference(rmode_)) { |
| 125 | // Absolute code pointer inside code object moves with the code object. |
| 126 | byte* p = reinterpret_cast<byte*>(pc_); |
| 127 | int count = Assembler::RelocateInternalReference(p, delta); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 128 | CpuFeatures::FlushICache(p, count * sizeof(uint32_t)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 129 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
| 133 | Address RelocInfo::target_address() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 134 | DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
| 135 | return Assembler::target_address_at(pc_, host_); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | |
| 139 | Address RelocInfo::target_address_address() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 140 | DCHECK(IsCodeTarget(rmode_) || |
| 141 | IsRuntimeEntry(rmode_) || |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 142 | rmode_ == EMBEDDED_OBJECT || |
| 143 | rmode_ == EXTERNAL_REFERENCE); |
| 144 | // Read the address of the word containing the target_address in an |
| 145 | // instruction stream. |
| 146 | // The only architecture-independent user of this function is the serializer. |
| 147 | // The serializer uses it to find out how many raw bytes of instruction to |
| 148 | // output before the next target. |
| 149 | // For an instruction like LUI/ORI where the target bits are mixed into the |
| 150 | // instruction bits, the size of the target will be zero, indicating that the |
| 151 | // serializer should not step forward in memory after a target is resolved |
| 152 | // and written. In this case the target_address_address function should |
| 153 | // return the end of the instructions to be patched, allowing the |
| 154 | // deserializer to deserialize the instructions as raw bytes and put them in |
| 155 | // place, ready to be patched with the target. After jump optimization, |
| 156 | // that is the address of the instruction that follows J/JAL/JR/JALR |
| 157 | // instruction. |
| 158 | return reinterpret_cast<Address>( |
| 159 | pc_ + Assembler::kInstructionsFor32BitConstant * Assembler::kInstrSize); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 163 | Address RelocInfo::constant_pool_entry_address() { |
| 164 | UNREACHABLE(); |
| 165 | return NULL; |
| 166 | } |
| 167 | |
| 168 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 169 | int RelocInfo::target_address_size() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 170 | return Assembler::kSpecialTargetSize; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 174 | void RelocInfo::set_target_address(Address target, |
| 175 | WriteBarrierMode write_barrier_mode, |
| 176 | ICacheFlushMode icache_flush_mode) { |
| 177 | DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
| 178 | Assembler::set_target_address_at(pc_, host_, target, icache_flush_mode); |
| 179 | if (write_barrier_mode == UPDATE_WRITE_BARRIER && |
| 180 | host() != NULL && IsCodeTarget(rmode_)) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 181 | Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 182 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 183 | host(), this, HeapObject::cast(target_code)); |
| 184 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 188 | Address Assembler::target_address_from_return_address(Address pc) { |
| 189 | return pc - kCallTargetAddressOffset; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | Address Assembler::break_address_from_return_address(Address pc) { |
| 194 | return pc - Assembler::kPatchDebugBreakSlotReturnOffset; |
| 195 | } |
| 196 | |
| 197 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 198 | Object* RelocInfo::target_object() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 199 | DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 200 | return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 204 | Handle<Object> RelocInfo::target_object_handle(Assembler* origin) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 205 | DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 206 | return Handle<Object>(reinterpret_cast<Object**>( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 207 | Assembler::target_address_at(pc_, host_))); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 211 | void RelocInfo::set_target_object(Object* target, |
| 212 | WriteBarrierMode write_barrier_mode, |
| 213 | ICacheFlushMode icache_flush_mode) { |
| 214 | DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 215 | Assembler::set_target_address_at(pc_, host_, |
| 216 | reinterpret_cast<Address>(target), |
| 217 | icache_flush_mode); |
| 218 | if (write_barrier_mode == UPDATE_WRITE_BARRIER && |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 219 | host() != NULL && |
| 220 | target->IsHeapObject()) { |
| 221 | host()->GetHeap()->incremental_marking()->RecordWrite( |
| 222 | host(), &Memory::Object_at(pc_), HeapObject::cast(target)); |
| 223 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 227 | Address RelocInfo::target_reference() { |
| 228 | DCHECK(rmode_ == EXTERNAL_REFERENCE); |
| 229 | return Assembler::target_address_at(pc_, host_); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 233 | Address RelocInfo::target_runtime_entry(Assembler* origin) { |
| 234 | DCHECK(IsRuntimeEntry(rmode_)); |
| 235 | return target_address(); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | void RelocInfo::set_target_runtime_entry(Address target, |
| 240 | WriteBarrierMode write_barrier_mode, |
| 241 | ICacheFlushMode icache_flush_mode) { |
| 242 | DCHECK(IsRuntimeEntry(rmode_)); |
| 243 | if (target_address() != target) |
| 244 | set_target_address(target, write_barrier_mode, icache_flush_mode); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | Handle<Cell> RelocInfo::target_cell_handle() { |
| 249 | DCHECK(rmode_ == RelocInfo::CELL); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 250 | Address address = Memory::Address_at(pc_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 251 | return Handle<Cell>(reinterpret_cast<Cell**>(address)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 255 | Cell* RelocInfo::target_cell() { |
| 256 | DCHECK(rmode_ == RelocInfo::CELL); |
| 257 | return Cell::FromValueAddress(Memory::Address_at(pc_)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 261 | void RelocInfo::set_target_cell(Cell* cell, |
| 262 | WriteBarrierMode write_barrier_mode, |
| 263 | ICacheFlushMode icache_flush_mode) { |
| 264 | DCHECK(rmode_ == RelocInfo::CELL); |
| 265 | Address address = cell->address() + Cell::kValueOffset; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 266 | Memory::Address_at(pc_) = address; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 267 | if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 268 | // TODO(1550) We are passing NULL as a slot because cell can never be on |
| 269 | // evacuation candidate. |
| 270 | host()->GetHeap()->incremental_marking()->RecordWrite( |
| 271 | host(), NULL, cell); |
| 272 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 276 | static const int kNoCodeAgeSequenceLength = 7 * Assembler::kInstrSize; |
| 277 | |
| 278 | |
| 279 | Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) { |
| 280 | UNREACHABLE(); // This should never be reached on Arm. |
| 281 | return Handle<Object>(); |
| 282 | } |
| 283 | |
| 284 | |
| 285 | Code* RelocInfo::code_age_stub() { |
| 286 | DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
| 287 | return Code::GetCodeFromTargetAddress( |
| 288 | Assembler::target_address_at(pc_ + Assembler::kInstrSize, host_)); |
| 289 | } |
| 290 | |
| 291 | |
| 292 | void RelocInfo::set_code_age_stub(Code* stub, |
| 293 | ICacheFlushMode icache_flush_mode) { |
| 294 | DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
| 295 | Assembler::set_target_address_at(pc_ + Assembler::kInstrSize, |
| 296 | host_, |
| 297 | stub->instruction_start()); |
| 298 | } |
| 299 | |
| 300 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 301 | Address RelocInfo::call_address() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 302 | DCHECK((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 303 | (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
| 304 | // The pc_ offset of 0 assumes mips patched return sequence per |
| 305 | // debug-mips.cc BreakLocationIterator::SetDebugBreakAtReturn(), or |
| 306 | // debug break slot per BreakLocationIterator::SetDebugBreakAtSlot(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 307 | return Assembler::target_address_at(pc_, host_); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | |
| 311 | void RelocInfo::set_call_address(Address target) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 312 | DCHECK((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 313 | (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
| 314 | // The pc_ offset of 0 assumes mips patched return sequence per |
| 315 | // debug-mips.cc BreakLocationIterator::SetDebugBreakAtReturn(), or |
| 316 | // debug break slot per BreakLocationIterator::SetDebugBreakAtSlot(). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 317 | Assembler::set_target_address_at(pc_, host_, target); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 318 | if (host() != NULL) { |
| 319 | Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 320 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 321 | host(), this, HeapObject::cast(target_code)); |
| 322 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | |
| 326 | Object* RelocInfo::call_object() { |
| 327 | return *call_object_address(); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | Object** RelocInfo::call_object_address() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 332 | DCHECK((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 333 | (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 334 | return reinterpret_cast<Object**>(pc_ + 2 * Assembler::kInstrSize); |
| 335 | } |
| 336 | |
| 337 | |
| 338 | void RelocInfo::set_call_object(Object* target) { |
| 339 | *call_object_address() = target; |
| 340 | } |
| 341 | |
| 342 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 343 | void RelocInfo::WipeOut() { |
| 344 | DCHECK(IsEmbeddedObject(rmode_) || |
| 345 | IsCodeTarget(rmode_) || |
| 346 | IsRuntimeEntry(rmode_) || |
| 347 | IsExternalReference(rmode_)); |
| 348 | Assembler::set_target_address_at(pc_, host_, NULL); |
| 349 | } |
| 350 | |
| 351 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 352 | bool RelocInfo::IsPatchedReturnSequence() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 353 | Instr instr0 = Assembler::instr_at(pc_); |
| 354 | Instr instr1 = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize); |
| 355 | Instr instr2 = Assembler::instr_at(pc_ + 2 * Assembler::kInstrSize); |
| 356 | bool patched_return = ((instr0 & kOpcodeMask) == LUI && |
| 357 | (instr1 & kOpcodeMask) == ORI && |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 358 | ((instr2 & kOpcodeMask) == JAL || |
| 359 | ((instr2 & kOpcodeMask) == SPECIAL && |
| 360 | (instr2 & kFunctionFieldMask) == JALR))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 361 | return patched_return; |
| 362 | } |
| 363 | |
| 364 | |
| 365 | bool RelocInfo::IsPatchedDebugBreakSlotSequence() { |
| 366 | Instr current_instr = Assembler::instr_at(pc_); |
| 367 | return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP); |
| 368 | } |
| 369 | |
| 370 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 371 | void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 372 | RelocInfo::Mode mode = rmode(); |
| 373 | if (mode == RelocInfo::EMBEDDED_OBJECT) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 374 | visitor->VisitEmbeddedPointer(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 375 | } else if (RelocInfo::IsCodeTarget(mode)) { |
| 376 | visitor->VisitCodeTarget(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 377 | } else if (mode == RelocInfo::CELL) { |
| 378 | visitor->VisitCell(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 379 | } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 380 | visitor->VisitExternalReference(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 381 | } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
| 382 | visitor->VisitCodeAgeSequence(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 383 | } else if (((RelocInfo::IsJSReturn(mode) && |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 384 | IsPatchedReturnSequence()) || |
| 385 | (RelocInfo::IsDebugBreakSlot(mode) && |
| 386 | IsPatchedDebugBreakSlotSequence())) && |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 387 | isolate->debug()->has_break_points()) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 388 | visitor->VisitDebugTarget(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 389 | } else if (RelocInfo::IsRuntimeEntry(mode)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 390 | visitor->VisitRuntimeEntry(this); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
| 395 | template<typename StaticVisitor> |
| 396 | void RelocInfo::Visit(Heap* heap) { |
| 397 | RelocInfo::Mode mode = rmode(); |
| 398 | if (mode == RelocInfo::EMBEDDED_OBJECT) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 399 | StaticVisitor::VisitEmbeddedPointer(heap, this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 400 | } else if (RelocInfo::IsCodeTarget(mode)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 401 | StaticVisitor::VisitCodeTarget(heap, this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 402 | } else if (mode == RelocInfo::CELL) { |
| 403 | StaticVisitor::VisitCell(heap, this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 404 | } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 405 | StaticVisitor::VisitExternalReference(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 406 | } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
| 407 | StaticVisitor::VisitCodeAgeSequence(heap, this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 408 | } else if (heap->isolate()->debug()->has_break_points() && |
| 409 | ((RelocInfo::IsJSReturn(mode) && |
| 410 | IsPatchedReturnSequence()) || |
| 411 | (RelocInfo::IsDebugBreakSlot(mode) && |
| 412 | IsPatchedDebugBreakSlotSequence()))) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 413 | StaticVisitor::VisitDebugTarget(heap, this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 414 | } else if (RelocInfo::IsRuntimeEntry(mode)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 415 | StaticVisitor::VisitRuntimeEntry(this); |
| 416 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | |
| 420 | // ----------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 421 | // Assembler. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 422 | |
| 423 | |
| 424 | void Assembler::CheckBuffer() { |
| 425 | if (buffer_space() <= kGap) { |
| 426 | GrowBuffer(); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 431 | void Assembler::CheckTrampolinePoolQuick() { |
| 432 | if (pc_offset() >= next_buffer_check_) { |
| 433 | CheckTrampolinePool(); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 438 | void Assembler::emit(Instr x) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 439 | if (!is_buffer_growth_blocked()) { |
| 440 | CheckBuffer(); |
| 441 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 442 | *reinterpret_cast<Instr*>(pc_) = x; |
| 443 | pc_ += kInstrSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 444 | CheckTrampolinePoolQuick(); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
| 448 | } } // namespace v8::internal |
| 449 | |
| 450 | #endif // V8_MIPS_ASSEMBLER_MIPS_INL_H_ |