Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 16 | // be used to endorse or promote products derived from this software without |
| 17 | // specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | // The original source code covered by the above license above has been |
| 32 | // modified significantly by Google Inc. |
| 33 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 34 | |
| 35 | #include "v8.h" |
| 36 | |
| 37 | #include "arguments.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 38 | #include "deoptimizer.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | #include "execution.h" |
| 40 | #include "ic-inl.h" |
| 41 | #include "factory.h" |
| 42 | #include "runtime.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 43 | #include "runtime-profiler.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | #include "serialize.h" |
| 45 | #include "stub-cache.h" |
| 46 | #include "regexp-stack.h" |
| 47 | #include "ast.h" |
| 48 | #include "regexp-macro-assembler.h" |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 49 | #include "platform.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | // Include native regexp-macro-assembler. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 51 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | #if V8_TARGET_ARCH_IA32 |
| 53 | #include "ia32/regexp-macro-assembler-ia32.h" |
| 54 | #elif V8_TARGET_ARCH_X64 |
| 55 | #include "x64/regexp-macro-assembler-x64.h" |
| 56 | #elif V8_TARGET_ARCH_ARM |
| 57 | #include "arm/regexp-macro-assembler-arm.h" |
| 58 | #else // Unknown architecture. |
| 59 | #error "Unknown architecture." |
| 60 | #endif // Target architecture. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 61 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 62 | |
| 63 | namespace v8 { |
| 64 | namespace internal { |
| 65 | |
| 66 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 67 | const double DoubleConstant::min_int = kMinInt; |
| 68 | const double DoubleConstant::one_half = 0.5; |
| 69 | const double DoubleConstant::negative_infinity = -V8_INFINITY; |
| 70 | |
| 71 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | // ----------------------------------------------------------------------------- |
| 73 | // Implementation of Label |
| 74 | |
| 75 | int Label::pos() const { |
| 76 | if (pos_ < 0) return -pos_ - 1; |
| 77 | if (pos_ > 0) return pos_ - 1; |
| 78 | UNREACHABLE(); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | // ----------------------------------------------------------------------------- |
| 84 | // Implementation of RelocInfoWriter and RelocIterator |
| 85 | // |
| 86 | // Encoding |
| 87 | // |
| 88 | // The most common modes are given single-byte encodings. Also, it is |
| 89 | // easy to identify the type of reloc info and skip unwanted modes in |
| 90 | // an iteration. |
| 91 | // |
| 92 | // The encoding relies on the fact that there are less than 14 |
| 93 | // different relocation modes. |
| 94 | // |
| 95 | // embedded_object: [6 bits pc delta] 00 |
| 96 | // |
| 97 | // code_taget: [6 bits pc delta] 01 |
| 98 | // |
| 99 | // position: [6 bits pc delta] 10, |
| 100 | // [7 bits signed data delta] 0 |
| 101 | // |
| 102 | // statement_position: [6 bits pc delta] 10, |
| 103 | // [7 bits signed data delta] 1 |
| 104 | // |
| 105 | // any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only |
| 106 | // 00 [6 bits pc delta] |
| 107 | // |
| 108 | // pc-jump: 00 1111 11, |
| 109 | // 00 [6 bits pc delta] |
| 110 | // |
| 111 | // pc-jump: 01 1111 11, |
| 112 | // (variable length) 7 - 26 bit pc delta, written in chunks of 7 |
| 113 | // bits, the lowest 7 bits written first. |
| 114 | // |
| 115 | // data-jump + pos: 00 1110 11, |
| 116 | // signed intptr_t, lowest byte written first |
| 117 | // |
| 118 | // data-jump + st.pos: 01 1110 11, |
| 119 | // signed intptr_t, lowest byte written first |
| 120 | // |
| 121 | // data-jump + comm.: 10 1110 11, |
| 122 | // signed intptr_t, lowest byte written first |
| 123 | // |
| 124 | const int kMaxRelocModes = 14; |
| 125 | |
| 126 | const int kTagBits = 2; |
| 127 | const int kTagMask = (1 << kTagBits) - 1; |
| 128 | const int kExtraTagBits = 4; |
| 129 | const int kPositionTypeTagBits = 1; |
| 130 | const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits; |
| 131 | |
| 132 | const int kEmbeddedObjectTag = 0; |
| 133 | const int kCodeTargetTag = 1; |
| 134 | const int kPositionTag = 2; |
| 135 | const int kDefaultTag = 3; |
| 136 | |
| 137 | const int kPCJumpTag = (1 << kExtraTagBits) - 1; |
| 138 | |
| 139 | const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; |
| 140 | const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; |
| 141 | |
| 142 | const int kVariableLengthPCJumpTopTag = 1; |
| 143 | const int kChunkBits = 7; |
| 144 | const int kChunkMask = (1 << kChunkBits) - 1; |
| 145 | const int kLastChunkTagBits = 1; |
| 146 | const int kLastChunkTagMask = 1; |
| 147 | const int kLastChunkTag = 1; |
| 148 | |
| 149 | |
| 150 | const int kDataJumpTag = kPCJumpTag - 1; |
| 151 | |
| 152 | const int kNonstatementPositionTag = 0; |
| 153 | const int kStatementPositionTag = 1; |
| 154 | const int kCommentTag = 2; |
| 155 | |
| 156 | |
| 157 | uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) { |
| 158 | // Return if the pc_delta can fit in kSmallPCDeltaBits bits. |
| 159 | // Otherwise write a variable length PC jump for the bits that do |
| 160 | // not fit in the kSmallPCDeltaBits bits. |
| 161 | if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; |
| 162 | WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag); |
| 163 | uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; |
| 164 | ASSERT(pc_jump > 0); |
| 165 | // Write kChunkBits size chunks of the pc_jump. |
| 166 | for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) { |
| 167 | byte b = pc_jump & kChunkMask; |
| 168 | *--pos_ = b << kLastChunkTagBits; |
| 169 | } |
| 170 | // Tag the last chunk so it can be identified. |
| 171 | *pos_ = *pos_ | kLastChunkTag; |
| 172 | // Return the remaining kSmallPCDeltaBits of the pc_delta. |
| 173 | return pc_delta & kSmallPCDeltaMask; |
| 174 | } |
| 175 | |
| 176 | |
| 177 | void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) { |
| 178 | // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump. |
| 179 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 180 | *--pos_ = pc_delta << kTagBits | tag; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 185 | *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
| 189 | void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 190 | *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) | |
| 191 | extra_tag << kTagBits | |
| 192 | kDefaultTag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) { |
| 197 | // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. |
| 198 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 199 | WriteExtraTag(extra_tag, 0); |
| 200 | *--pos_ = pc_delta; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) { |
| 205 | WriteExtraTag(kDataJumpTag, top_tag); |
| 206 | for (int i = 0; i < kIntptrSize; i++) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 207 | *--pos_ = static_cast<byte>(data_delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 208 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 209 | data_delta = data_delta >> kBitsPerByte; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | |
| 214 | void RelocInfoWriter::Write(const RelocInfo* rinfo) { |
| 215 | #ifdef DEBUG |
| 216 | byte* begin_pos = pos_; |
| 217 | #endif |
| 218 | Counters::reloc_info_count.Increment(); |
| 219 | ASSERT(rinfo->pc() - last_pc_ >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 220 | ASSERT(RelocInfo::NUMBER_OF_MODES <= kMaxRelocModes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 221 | // Use unsigned delta-encoding for pc. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 222 | uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 223 | RelocInfo::Mode rmode = rinfo->rmode(); |
| 224 | |
| 225 | // The two most common modes are given small tags, and usually fit in a byte. |
| 226 | if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
| 227 | WriteTaggedPC(pc_delta, kEmbeddedObjectTag); |
| 228 | } else if (rmode == RelocInfo::CODE_TARGET) { |
| 229 | WriteTaggedPC(pc_delta, kCodeTargetTag); |
| 230 | } else if (RelocInfo::IsPosition(rmode)) { |
| 231 | // Use signed delta-encoding for data. |
| 232 | intptr_t data_delta = rinfo->data() - last_data_; |
| 233 | int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag |
| 234 | : kStatementPositionTag; |
| 235 | // Check if data is small enough to fit in a tagged byte. |
| 236 | // We cannot use is_intn because data_delta is not an int32_t. |
| 237 | if (data_delta >= -(1 << (kSmallDataBits-1)) && |
| 238 | data_delta < 1 << (kSmallDataBits-1)) { |
| 239 | WriteTaggedPC(pc_delta, kPositionTag); |
| 240 | WriteTaggedData(data_delta, pos_type_tag); |
| 241 | last_data_ = rinfo->data(); |
| 242 | } else { |
| 243 | // Otherwise, use costly encoding. |
| 244 | WriteExtraTaggedPC(pc_delta, kPCJumpTag); |
| 245 | WriteExtraTaggedData(data_delta, pos_type_tag); |
| 246 | last_data_ = rinfo->data(); |
| 247 | } |
| 248 | } else if (RelocInfo::IsComment(rmode)) { |
| 249 | // Comments are normally not generated, so we use the costly encoding. |
| 250 | WriteExtraTaggedPC(pc_delta, kPCJumpTag); |
| 251 | WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag); |
| 252 | last_data_ = rinfo->data(); |
| 253 | } else { |
| 254 | // For all other modes we simply use the mode as the extra tag. |
| 255 | // None of these modes need a data component. |
| 256 | ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag); |
| 257 | WriteExtraTaggedPC(pc_delta, rmode); |
| 258 | } |
| 259 | last_pc_ = rinfo->pc(); |
| 260 | #ifdef DEBUG |
| 261 | ASSERT(begin_pos - pos_ <= kMaxSize); |
| 262 | #endif |
| 263 | } |
| 264 | |
| 265 | |
| 266 | inline int RelocIterator::AdvanceGetTag() { |
| 267 | return *--pos_ & kTagMask; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | inline int RelocIterator::GetExtraTag() { |
| 272 | return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | inline int RelocIterator::GetTopTag() { |
| 277 | return *pos_ >> (kTagBits + kExtraTagBits); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | inline void RelocIterator::ReadTaggedPC() { |
| 282 | rinfo_.pc_ += *pos_ >> kTagBits; |
| 283 | } |
| 284 | |
| 285 | |
| 286 | inline void RelocIterator::AdvanceReadPC() { |
| 287 | rinfo_.pc_ += *--pos_; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | void RelocIterator::AdvanceReadData() { |
| 292 | intptr_t x = 0; |
| 293 | for (int i = 0; i < kIntptrSize; i++) { |
| 294 | x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; |
| 295 | } |
| 296 | rinfo_.data_ += x; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | void RelocIterator::AdvanceReadVariableLengthPCJump() { |
| 301 | // Read the 32-kSmallPCDeltaBits most significant bits of the |
| 302 | // pc jump in kChunkBits bit chunks and shift them into place. |
| 303 | // Stop when the last chunk is encountered. |
| 304 | uint32_t pc_jump = 0; |
| 305 | for (int i = 0; i < kIntSize; i++) { |
| 306 | byte pc_jump_part = *--pos_; |
| 307 | pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; |
| 308 | if ((pc_jump_part & kLastChunkTagMask) == 1) break; |
| 309 | } |
| 310 | // The least significant kSmallPCDeltaBits bits will be added |
| 311 | // later. |
| 312 | rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; |
| 313 | } |
| 314 | |
| 315 | |
| 316 | inline int RelocIterator::GetPositionTypeTag() { |
| 317 | return *pos_ & ((1 << kPositionTypeTagBits) - 1); |
| 318 | } |
| 319 | |
| 320 | |
| 321 | inline void RelocIterator::ReadTaggedData() { |
| 322 | int8_t signed_b = *pos_; |
| 323 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 324 | rinfo_.data_ += signed_b >> kPositionTypeTagBits; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) { |
| 329 | if (tag == kStatementPositionTag) { |
| 330 | return RelocInfo::STATEMENT_POSITION; |
| 331 | } else if (tag == kNonstatementPositionTag) { |
| 332 | return RelocInfo::POSITION; |
| 333 | } else { |
| 334 | ASSERT(tag == kCommentTag); |
| 335 | return RelocInfo::COMMENT; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | |
| 340 | void RelocIterator::next() { |
| 341 | ASSERT(!done()); |
| 342 | // Basically, do the opposite of RelocInfoWriter::Write. |
| 343 | // Reading of data is as far as possible avoided for unwanted modes, |
| 344 | // but we must always update the pc. |
| 345 | // |
| 346 | // We exit this loop by returning when we find a mode we want. |
| 347 | while (pos_ > end_) { |
| 348 | int tag = AdvanceGetTag(); |
| 349 | if (tag == kEmbeddedObjectTag) { |
| 350 | ReadTaggedPC(); |
| 351 | if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; |
| 352 | } else if (tag == kCodeTargetTag) { |
| 353 | ReadTaggedPC(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | if (SetMode(RelocInfo::CODE_TARGET)) return; |
| 355 | } else if (tag == kPositionTag) { |
| 356 | ReadTaggedPC(); |
| 357 | Advance(); |
| 358 | // Check if we want source positions. |
| 359 | if (mode_mask_ & RelocInfo::kPositionMask) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 360 | ReadTaggedData(); |
| 361 | if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 362 | } |
| 363 | } else { |
| 364 | ASSERT(tag == kDefaultTag); |
| 365 | int extra_tag = GetExtraTag(); |
| 366 | if (extra_tag == kPCJumpTag) { |
| 367 | int top_tag = GetTopTag(); |
| 368 | if (top_tag == kVariableLengthPCJumpTopTag) { |
| 369 | AdvanceReadVariableLengthPCJump(); |
| 370 | } else { |
| 371 | AdvanceReadPC(); |
| 372 | } |
| 373 | } else if (extra_tag == kDataJumpTag) { |
| 374 | // Check if we want debug modes (the only ones with data). |
| 375 | if (mode_mask_ & RelocInfo::kDebugMask) { |
| 376 | int top_tag = GetTopTag(); |
| 377 | AdvanceReadData(); |
| 378 | if (SetMode(DebugInfoModeFromTag(top_tag))) return; |
| 379 | } else { |
| 380 | // Otherwise, just skip over the data. |
| 381 | Advance(kIntptrSize); |
| 382 | } |
| 383 | } else { |
| 384 | AdvanceReadPC(); |
| 385 | if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | done_ = true; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | RelocIterator::RelocIterator(Code* code, int mode_mask) { |
| 394 | rinfo_.pc_ = code->instruction_start(); |
| 395 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 396 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 397 | pos_ = code->relocation_start() + code->relocation_size(); |
| 398 | end_ = code->relocation_start(); |
| 399 | done_ = false; |
| 400 | mode_mask_ = mode_mask; |
| 401 | if (mode_mask_ == 0) pos_ = end_; |
| 402 | next(); |
| 403 | } |
| 404 | |
| 405 | |
| 406 | RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) { |
| 407 | rinfo_.pc_ = desc.buffer; |
| 408 | rinfo_.data_ = 0; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 409 | // Relocation info is read backwards. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 410 | pos_ = desc.buffer + desc.buffer_size; |
| 411 | end_ = pos_ - desc.reloc_size; |
| 412 | done_ = false; |
| 413 | mode_mask_ = mode_mask; |
| 414 | if (mode_mask_ == 0) pos_ = end_; |
| 415 | next(); |
| 416 | } |
| 417 | |
| 418 | |
| 419 | // ----------------------------------------------------------------------------- |
| 420 | // Implementation of RelocInfo |
| 421 | |
| 422 | |
| 423 | #ifdef ENABLE_DISASSEMBLER |
| 424 | const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { |
| 425 | switch (rmode) { |
| 426 | case RelocInfo::NONE: |
| 427 | return "no reloc"; |
| 428 | case RelocInfo::EMBEDDED_OBJECT: |
| 429 | return "embedded object"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 430 | case RelocInfo::CONSTRUCT_CALL: |
| 431 | return "code target (js construct call)"; |
| 432 | case RelocInfo::CODE_TARGET_CONTEXT: |
| 433 | return "code target (context)"; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 434 | case RelocInfo::DEBUG_BREAK: |
| 435 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 436 | UNREACHABLE(); |
| 437 | #endif |
| 438 | return "debug break"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 439 | case RelocInfo::CODE_TARGET: |
| 440 | return "code target"; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 441 | case RelocInfo::GLOBAL_PROPERTY_CELL: |
| 442 | return "global property cell"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | case RelocInfo::RUNTIME_ENTRY: |
| 444 | return "runtime entry"; |
| 445 | case RelocInfo::JS_RETURN: |
| 446 | return "js return"; |
| 447 | case RelocInfo::COMMENT: |
| 448 | return "comment"; |
| 449 | case RelocInfo::POSITION: |
| 450 | return "position"; |
| 451 | case RelocInfo::STATEMENT_POSITION: |
| 452 | return "statement position"; |
| 453 | case RelocInfo::EXTERNAL_REFERENCE: |
| 454 | return "external reference"; |
| 455 | case RelocInfo::INTERNAL_REFERENCE: |
| 456 | return "internal reference"; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 457 | case RelocInfo::DEBUG_BREAK_SLOT: |
| 458 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 459 | UNREACHABLE(); |
| 460 | #endif |
| 461 | return "debug break slot"; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | case RelocInfo::NUMBER_OF_MODES: |
| 463 | UNREACHABLE(); |
| 464 | return "number_of_modes"; |
| 465 | } |
| 466 | return "unknown relocation type"; |
| 467 | } |
| 468 | |
| 469 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 470 | void RelocInfo::Print(FILE* out) { |
| 471 | PrintF(out, "%p %s", pc_, RelocModeName(rmode_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 472 | if (IsComment(rmode_)) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 473 | PrintF(out, " (%s)", reinterpret_cast<char*>(data_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 474 | } else if (rmode_ == EMBEDDED_OBJECT) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 475 | PrintF(out, " ("); |
| 476 | target_object()->ShortPrint(out); |
| 477 | PrintF(out, ")"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 478 | } else if (rmode_ == EXTERNAL_REFERENCE) { |
| 479 | ExternalReferenceEncoder ref_encoder; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 480 | PrintF(out, " (%s) (%p)", |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 481 | ref_encoder.NameOfAddress(*target_reference_address()), |
| 482 | *target_reference_address()); |
| 483 | } else if (IsCodeTarget(rmode_)) { |
| 484 | Code* code = Code::GetCodeFromTargetAddress(target_address()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 485 | PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()), |
| 486 | target_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 487 | } else if (IsPosition(rmode_)) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 488 | PrintF(out, " (%" V8_PTR_PREFIX "d)", data()); |
| 489 | } else if (rmode_ == RelocInfo::RUNTIME_ENTRY) { |
| 490 | // Depotimization bailouts are stored as runtime entries. |
| 491 | int id = Deoptimizer::GetDeoptimizationId( |
| 492 | target_address(), Deoptimizer::EAGER); |
| 493 | if (id != Deoptimizer::kNotDeoptimizationEntry) { |
| 494 | PrintF(out, " (deoptimization bailout %d)", id); |
| 495 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 498 | PrintF(out, "\n"); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | } |
| 500 | #endif // ENABLE_DISASSEMBLER |
| 501 | |
| 502 | |
| 503 | #ifdef DEBUG |
| 504 | void RelocInfo::Verify() { |
| 505 | switch (rmode_) { |
| 506 | case EMBEDDED_OBJECT: |
| 507 | Object::VerifyPointer(target_object()); |
| 508 | break; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 509 | case GLOBAL_PROPERTY_CELL: |
| 510 | Object::VerifyPointer(target_cell()); |
| 511 | break; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 512 | case DEBUG_BREAK: |
| 513 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 514 | UNREACHABLE(); |
| 515 | break; |
| 516 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 517 | case CONSTRUCT_CALL: |
| 518 | case CODE_TARGET_CONTEXT: |
| 519 | case CODE_TARGET: { |
| 520 | // convert inline target address to code object |
| 521 | Address addr = target_address(); |
| 522 | ASSERT(addr != NULL); |
| 523 | // Check that we can find the right code object. |
| 524 | Code* code = Code::GetCodeFromTargetAddress(addr); |
| 525 | Object* found = Heap::FindCodeObject(addr); |
| 526 | ASSERT(found->IsCode()); |
| 527 | ASSERT(code->address() == HeapObject::cast(found)->address()); |
| 528 | break; |
| 529 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | case RUNTIME_ENTRY: |
| 531 | case JS_RETURN: |
| 532 | case COMMENT: |
| 533 | case POSITION: |
| 534 | case STATEMENT_POSITION: |
| 535 | case EXTERNAL_REFERENCE: |
| 536 | case INTERNAL_REFERENCE: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 537 | case DEBUG_BREAK_SLOT: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | case NONE: |
| 539 | break; |
| 540 | case NUMBER_OF_MODES: |
| 541 | UNREACHABLE(); |
| 542 | break; |
| 543 | } |
| 544 | } |
| 545 | #endif // DEBUG |
| 546 | |
| 547 | |
| 548 | // ----------------------------------------------------------------------------- |
| 549 | // Implementation of ExternalReference |
| 550 | |
| 551 | ExternalReference::ExternalReference(Builtins::CFunctionId id) |
| 552 | : address_(Redirect(Builtins::c_function_address(id))) {} |
| 553 | |
| 554 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 555 | ExternalReference::ExternalReference(ApiFunction* fun) |
| 556 | : address_(Redirect(fun->address())) {} |
| 557 | |
| 558 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 559 | ExternalReference::ExternalReference(Builtins::Name name) |
| 560 | : address_(Builtins::builtin_address(name)) {} |
| 561 | |
| 562 | |
| 563 | ExternalReference::ExternalReference(Runtime::FunctionId id) |
| 564 | : address_(Redirect(Runtime::FunctionForId(id)->entry)) {} |
| 565 | |
| 566 | |
| 567 | ExternalReference::ExternalReference(Runtime::Function* f) |
| 568 | : address_(Redirect(f->entry)) {} |
| 569 | |
| 570 | |
| 571 | ExternalReference::ExternalReference(const IC_Utility& ic_utility) |
| 572 | : address_(Redirect(ic_utility.address())) {} |
| 573 | |
| 574 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 575 | ExternalReference::ExternalReference(const Debug_Address& debug_address) |
| 576 | : address_(debug_address.address()) {} |
| 577 | #endif |
| 578 | |
| 579 | ExternalReference::ExternalReference(StatsCounter* counter) |
| 580 | : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {} |
| 581 | |
| 582 | |
| 583 | ExternalReference::ExternalReference(Top::AddressId id) |
| 584 | : address_(Top::get_address_from_id(id)) {} |
| 585 | |
| 586 | |
| 587 | ExternalReference::ExternalReference(const SCTableReference& table_ref) |
| 588 | : address_(table_ref.address()) {} |
| 589 | |
| 590 | |
| 591 | ExternalReference ExternalReference::perform_gc_function() { |
| 592 | return ExternalReference(Redirect(FUNCTION_ADDR(Runtime::PerformGC))); |
| 593 | } |
| 594 | |
| 595 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 596 | ExternalReference ExternalReference::fill_heap_number_with_random_function() { |
| 597 | return |
| 598 | ExternalReference(Redirect(FUNCTION_ADDR(V8::FillHeapNumberWithRandom))); |
| 599 | } |
| 600 | |
| 601 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 602 | ExternalReference ExternalReference::delete_handle_scope_extensions() { |
| 603 | return ExternalReference(Redirect(FUNCTION_ADDR( |
| 604 | HandleScope::DeleteExtensions))); |
| 605 | } |
| 606 | |
| 607 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 608 | ExternalReference ExternalReference::random_uint32_function() { |
| 609 | return ExternalReference(Redirect(FUNCTION_ADDR(V8::Random))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 613 | ExternalReference ExternalReference::transcendental_cache_array_address() { |
| 614 | return ExternalReference(TranscendentalCache::cache_array_address()); |
| 615 | } |
| 616 | |
| 617 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 618 | ExternalReference ExternalReference::new_deoptimizer_function() { |
| 619 | return ExternalReference( |
| 620 | Redirect(FUNCTION_ADDR(Deoptimizer::New))); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | ExternalReference ExternalReference::compute_output_frames_function() { |
| 625 | return ExternalReference( |
| 626 | Redirect(FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames))); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | ExternalReference ExternalReference::global_contexts_list() { |
| 631 | return ExternalReference(Heap::global_contexts_list_address()); |
| 632 | } |
| 633 | |
| 634 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 635 | ExternalReference ExternalReference::keyed_lookup_cache_keys() { |
| 636 | return ExternalReference(KeyedLookupCache::keys_address()); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | ExternalReference ExternalReference::keyed_lookup_cache_field_offsets() { |
| 641 | return ExternalReference(KeyedLookupCache::field_offsets_address()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
| 645 | ExternalReference ExternalReference::the_hole_value_location() { |
| 646 | return ExternalReference(Factory::the_hole_value().location()); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | ExternalReference ExternalReference::roots_address() { |
| 651 | return ExternalReference(Heap::roots_address()); |
| 652 | } |
| 653 | |
| 654 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 655 | ExternalReference ExternalReference::address_of_stack_limit() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 656 | return ExternalReference(StackGuard::address_of_jslimit()); |
| 657 | } |
| 658 | |
| 659 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 660 | ExternalReference ExternalReference::address_of_real_stack_limit() { |
| 661 | return ExternalReference(StackGuard::address_of_real_jslimit()); |
| 662 | } |
| 663 | |
| 664 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 665 | ExternalReference ExternalReference::address_of_regexp_stack_limit() { |
| 666 | return ExternalReference(RegExpStack::limit_address()); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | ExternalReference ExternalReference::new_space_start() { |
| 671 | return ExternalReference(Heap::NewSpaceStart()); |
| 672 | } |
| 673 | |
| 674 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 675 | ExternalReference ExternalReference::new_space_mask() { |
| 676 | return ExternalReference(reinterpret_cast<Address>(Heap::NewSpaceMask())); |
| 677 | } |
| 678 | |
| 679 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 680 | ExternalReference ExternalReference::new_space_allocation_top_address() { |
| 681 | return ExternalReference(Heap::NewSpaceAllocationTopAddress()); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | ExternalReference ExternalReference::heap_always_allocate_scope_depth() { |
| 686 | return ExternalReference(Heap::always_allocate_scope_depth_address()); |
| 687 | } |
| 688 | |
| 689 | |
| 690 | ExternalReference ExternalReference::new_space_allocation_limit_address() { |
| 691 | return ExternalReference(Heap::NewSpaceAllocationLimitAddress()); |
| 692 | } |
| 693 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 694 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 695 | ExternalReference ExternalReference::handle_scope_level_address() { |
| 696 | return ExternalReference(HandleScope::current_level_address()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | |
| 700 | ExternalReference ExternalReference::handle_scope_next_address() { |
| 701 | return ExternalReference(HandleScope::current_next_address()); |
| 702 | } |
| 703 | |
| 704 | |
| 705 | ExternalReference ExternalReference::handle_scope_limit_address() { |
| 706 | return ExternalReference(HandleScope::current_limit_address()); |
| 707 | } |
| 708 | |
| 709 | |
| 710 | ExternalReference ExternalReference::scheduled_exception_address() { |
| 711 | return ExternalReference(Top::scheduled_exception_address()); |
| 712 | } |
| 713 | |
| 714 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 715 | ExternalReference ExternalReference::address_of_min_int() { |
| 716 | return ExternalReference(reinterpret_cast<void*>( |
| 717 | const_cast<double*>(&DoubleConstant::min_int))); |
| 718 | } |
| 719 | |
| 720 | |
| 721 | ExternalReference ExternalReference::address_of_one_half() { |
| 722 | return ExternalReference(reinterpret_cast<void*>( |
| 723 | const_cast<double*>(&DoubleConstant::one_half))); |
| 724 | } |
| 725 | |
| 726 | |
| 727 | ExternalReference ExternalReference::address_of_negative_infinity() { |
| 728 | return ExternalReference(reinterpret_cast<void*>( |
| 729 | const_cast<double*>(&DoubleConstant::negative_infinity))); |
| 730 | } |
| 731 | |
| 732 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 733 | #ifndef V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 734 | |
| 735 | ExternalReference ExternalReference::re_check_stack_guard_state() { |
| 736 | Address function; |
| 737 | #ifdef V8_TARGET_ARCH_X64 |
| 738 | function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState); |
| 739 | #elif V8_TARGET_ARCH_IA32 |
| 740 | function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState); |
| 741 | #elif V8_TARGET_ARCH_ARM |
| 742 | function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState); |
| 743 | #else |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 744 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 745 | #endif |
| 746 | return ExternalReference(Redirect(function)); |
| 747 | } |
| 748 | |
| 749 | ExternalReference ExternalReference::re_grow_stack() { |
| 750 | return ExternalReference( |
| 751 | Redirect(FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack))); |
| 752 | } |
| 753 | |
| 754 | ExternalReference ExternalReference::re_case_insensitive_compare_uc16() { |
| 755 | return ExternalReference(Redirect( |
| 756 | FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16))); |
| 757 | } |
| 758 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 759 | ExternalReference ExternalReference::re_word_character_map() { |
| 760 | return ExternalReference( |
| 761 | NativeRegExpMacroAssembler::word_character_map_address()); |
| 762 | } |
| 763 | |
| 764 | ExternalReference ExternalReference::address_of_static_offsets_vector() { |
| 765 | return ExternalReference(OffsetsVector::static_offsets_vector_address()); |
| 766 | } |
| 767 | |
| 768 | ExternalReference ExternalReference::address_of_regexp_stack_memory_address() { |
| 769 | return ExternalReference(RegExpStack::memory_address()); |
| 770 | } |
| 771 | |
| 772 | ExternalReference ExternalReference::address_of_regexp_stack_memory_size() { |
| 773 | return ExternalReference(RegExpStack::memory_size_address()); |
| 774 | } |
| 775 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 776 | #endif // V8_INTERPRETED_REGEXP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 777 | |
| 778 | |
| 779 | static double add_two_doubles(double x, double y) { |
| 780 | return x + y; |
| 781 | } |
| 782 | |
| 783 | |
| 784 | static double sub_two_doubles(double x, double y) { |
| 785 | return x - y; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | static double mul_two_doubles(double x, double y) { |
| 790 | return x * y; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | static double div_two_doubles(double x, double y) { |
| 795 | return x / y; |
| 796 | } |
| 797 | |
| 798 | |
| 799 | static double mod_two_doubles(double x, double y) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 800 | return modulo(x, y); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 804 | // Helper function to compute x^y, where y is known to be an |
| 805 | // integer. Uses binary decomposition to limit the number of |
| 806 | // multiplications; see the discussion in "Hacker's Delight" by Henry |
| 807 | // S. Warren, Jr., figure 11-6, page 213. |
| 808 | double power_double_int(double x, int y) { |
| 809 | double m = (y < 0) ? 1 / x : x; |
| 810 | unsigned n = (y < 0) ? -y : y; |
| 811 | double p = 1; |
| 812 | while (n != 0) { |
| 813 | if ((n & 1) != 0) p *= m; |
| 814 | m *= m; |
| 815 | if ((n & 2) != 0) p *= m; |
| 816 | m *= m; |
| 817 | n >>= 2; |
| 818 | } |
| 819 | return p; |
| 820 | } |
| 821 | |
| 822 | |
| 823 | double power_double_double(double x, double y) { |
| 824 | int y_int = static_cast<int>(y); |
| 825 | if (y == y_int) { |
| 826 | return power_double_int(x, y_int); // Returns 1.0 for exponent 0. |
| 827 | } |
| 828 | if (!isinf(x)) { |
| 829 | if (y == 0.5) return sqrt(x); |
| 830 | if (y == -0.5) return 1.0 / sqrt(x); |
| 831 | } |
| 832 | if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) { |
| 833 | return OS::nan_value(); |
| 834 | } |
| 835 | return pow(x, y); |
| 836 | } |
| 837 | |
| 838 | |
| 839 | ExternalReference ExternalReference::power_double_double_function() { |
| 840 | return ExternalReference(Redirect(FUNCTION_ADDR(power_double_double))); |
| 841 | } |
| 842 | |
| 843 | |
| 844 | ExternalReference ExternalReference::power_double_int_function() { |
| 845 | return ExternalReference(Redirect(FUNCTION_ADDR(power_double_int))); |
| 846 | } |
| 847 | |
| 848 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 849 | static int native_compare_doubles(double y, double x) { |
| 850 | if (x == y) return EQUAL; |
| 851 | return x < y ? LESS : GREATER; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | |
| 855 | ExternalReference ExternalReference::double_fp_operation( |
| 856 | Token::Value operation) { |
| 857 | typedef double BinaryFPOperation(double x, double y); |
| 858 | BinaryFPOperation* function = NULL; |
| 859 | switch (operation) { |
| 860 | case Token::ADD: |
| 861 | function = &add_two_doubles; |
| 862 | break; |
| 863 | case Token::SUB: |
| 864 | function = &sub_two_doubles; |
| 865 | break; |
| 866 | case Token::MUL: |
| 867 | function = &mul_two_doubles; |
| 868 | break; |
| 869 | case Token::DIV: |
| 870 | function = &div_two_doubles; |
| 871 | break; |
| 872 | case Token::MOD: |
| 873 | function = &mod_two_doubles; |
| 874 | break; |
| 875 | default: |
| 876 | UNREACHABLE(); |
| 877 | } |
| 878 | // Passing true as 2nd parameter indicates that they return an fp value. |
| 879 | return ExternalReference(Redirect(FUNCTION_ADDR(function), true)); |
| 880 | } |
| 881 | |
| 882 | |
| 883 | ExternalReference ExternalReference::compare_doubles() { |
| 884 | return ExternalReference(Redirect(FUNCTION_ADDR(native_compare_doubles), |
| 885 | false)); |
| 886 | } |
| 887 | |
| 888 | |
| 889 | ExternalReferenceRedirector* ExternalReference::redirector_ = NULL; |
| 890 | |
| 891 | |
| 892 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 893 | ExternalReference ExternalReference::debug_break() { |
| 894 | return ExternalReference(Redirect(FUNCTION_ADDR(Debug::Break))); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | ExternalReference ExternalReference::debug_step_in_fp_address() { |
| 899 | return ExternalReference(Debug::step_in_fp_addr()); |
| 900 | } |
| 901 | #endif |
| 902 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 903 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 904 | void PositionsRecorder::RecordPosition(int pos) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 905 | ASSERT(pos != RelocInfo::kNoPosition); |
| 906 | ASSERT(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 907 | state_.current_position = pos; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | |
| 911 | void PositionsRecorder::RecordStatementPosition(int pos) { |
| 912 | ASSERT(pos != RelocInfo::kNoPosition); |
| 913 | ASSERT(pos >= 0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 914 | state_.current_statement_position = pos; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | |
| 918 | bool PositionsRecorder::WriteRecordedPositions() { |
| 919 | bool written = false; |
| 920 | |
| 921 | // Write the statement position if it is different from what was written last |
| 922 | // time. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 923 | if (state_.current_statement_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 924 | EnsureSpace ensure_space(assembler_); |
| 925 | assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 926 | state_.current_statement_position); |
| 927 | state_.written_statement_position = state_.current_statement_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 928 | written = true; |
| 929 | } |
| 930 | |
| 931 | // Write the position if it is different from what was written last time and |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 932 | // also different from the written statement position. |
| 933 | if (state_.current_position != state_.written_position && |
| 934 | state_.current_position != state_.written_statement_position) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 935 | EnsureSpace ensure_space(assembler_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 936 | assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
| 937 | state_.written_position = state_.current_position; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 938 | written = true; |
| 939 | } |
| 940 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 941 | // Return whether something was written. |
| 942 | return written; |
| 943 | } |
| 944 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 945 | } } // namespace v8::internal |