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