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