christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 33 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
| 35 | #include "v8.h" |
| 36 | |
| 37 | #include "arguments.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 38 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | #include "execution.h" |
| 40 | #include "ic-inl.h" |
| 41 | #include "factory.h" |
| 42 | #include "runtime.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 43 | #include "runtime-profiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "serialize.h" |
| 45 | #include "stub-cache.h" |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 46 | #include "regexp-stack.h" |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 47 | #include "ast.h" |
| 48 | #include "regexp-macro-assembler.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 49 | #include "platform.h" |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 50 | // Include native regexp-macro-assembler. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 51 | #ifndef V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +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" |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame^] | 58 | #elif V8_TARGET_ARCH_MIPS |
| 59 | #include "mips/regexp-macro-assembler-mips.h" |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 60 | #else // Unknown architecture. |
| 61 | #error "Unknown architecture." |
| 62 | #endif // Target architecture. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 63 | #endif // V8_INTERPRETED_REGEXP |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 65 | namespace v8 { |
| 66 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 67 | |
| 68 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 69 | const double DoubleConstant::min_int = kMinInt; |
| 70 | const double DoubleConstant::one_half = 0.5; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 71 | const double DoubleConstant::minus_zero = -0.0; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 72 | const double DoubleConstant::nan = OS::nan_value(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 73 | const double DoubleConstant::negative_infinity = -V8_INFINITY; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 74 | const char* RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 75 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | // |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 109 | // any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 120 | // signed intptr_t, lowest byte written first |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | // |
| 122 | // data-jump + st.pos: 01 1110 11, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 123 | // signed intptr_t, lowest byte written first |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 124 | // |
| 125 | // data-jump + comm.: 10 1110 11, |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 126 | // signed intptr_t, lowest byte written first |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 145 | const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 189 | void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 190 | *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
| 194 | void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 195 | *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) | |
| 196 | extra_tag << kTagBits | |
| 197 | kDefaultTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 209 | void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | WriteExtraTag(kDataJumpTag, top_tag); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 211 | for (int i = 0; i < kIntptrSize; i++) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 212 | *--pos_ = static_cast<byte>(data_delta); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 213 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 214 | data_delta = data_delta >> kBitsPerByte; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | void RelocInfoWriter::Write(const RelocInfo* rinfo) { |
| 220 | #ifdef DEBUG |
| 221 | byte* begin_pos = pos_; |
| 222 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | ASSERT(rinfo->pc() - last_pc_ >= 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 224 | ASSERT(RelocInfo::NUMBER_OF_MODES <= kMaxRelocModes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | // Use unsigned delta-encoding for pc. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 226 | uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 227 | RelocInfo::Mode rmode = rinfo->rmode(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 228 | |
| 229 | // The two most common modes are given small tags, and usually fit in a byte. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 230 | if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 231 | WriteTaggedPC(pc_delta, kEmbeddedObjectTag); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 232 | } else if (rmode == RelocInfo::CODE_TARGET) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 233 | WriteTaggedPC(pc_delta, kCodeTargetTag); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 234 | ASSERT(begin_pos - pos_ <= RelocInfo::kMaxCallSize); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 235 | } else if (RelocInfo::IsPosition(rmode)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 236 | // Use signed delta-encoding for data. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 237 | intptr_t data_delta = rinfo->data() - last_data_; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 238 | int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag |
| 239 | : kStatementPositionTag; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | // Check if data is small enough to fit in a tagged byte. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 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)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 253 | } else if (RelocInfo::IsComment(rmode)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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(); |
ricow@chromium.org | 2233451 | 2011-02-25 07:28:50 +0000 | [diff] [blame] | 258 | ASSERT(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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() { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 298 | intptr_t x = 0; |
| 299 | for (int i = 0; i < kIntptrSize; i++) { |
| 300 | x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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_; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 329 | // Signed right shift is arithmetic shift. Tested in test-utils.cc. |
| 330 | rinfo_.data_ += signed_b >> kPositionTypeTagBits; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 334 | inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 335 | if (tag == kStatementPositionTag) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 336 | return RelocInfo::STATEMENT_POSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | } else if (tag == kNonstatementPositionTag) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 338 | return RelocInfo::POSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 339 | } else { |
| 340 | ASSERT(tag == kCommentTag); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 341 | return RelocInfo::COMMENT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 357 | if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 358 | } else if (tag == kCodeTargetTag) { |
| 359 | ReadTaggedPC(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 360 | if (SetMode(RelocInfo::CODE_TARGET)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 361 | } else if (tag == kPositionTag) { |
| 362 | ReadTaggedPC(); |
| 363 | Advance(); |
| 364 | // Check if we want source positions. |
| 365 | if (mode_mask_ & RelocInfo::kPositionMask) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 366 | ReadTaggedData(); |
| 367 | if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 387 | Advance(kIntptrSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 388 | } |
| 389 | } else { |
| 390 | AdvanceReadPC(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 391 | if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 402 | // Relocation info is read backwards. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 415 | // Relocation info is read backwards. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 429 | #ifdef ENABLE_DISASSEMBLER |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 430 | const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | switch (rmode) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 432 | case RelocInfo::NONE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | return "no reloc"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 434 | case RelocInfo::EMBEDDED_OBJECT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 435 | return "embedded object"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 436 | case RelocInfo::CONSTRUCT_CALL: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | return "code target (js construct call)"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 438 | case RelocInfo::CODE_TARGET_CONTEXT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 439 | return "code target (context)"; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 440 | case RelocInfo::DEBUG_BREAK: |
| 441 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 442 | UNREACHABLE(); |
| 443 | #endif |
| 444 | return "debug break"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 445 | case RelocInfo::CODE_TARGET: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 446 | return "code target"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 447 | case RelocInfo::GLOBAL_PROPERTY_CELL: |
| 448 | return "global property cell"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 449 | case RelocInfo::RUNTIME_ENTRY: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 450 | return "runtime entry"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 451 | case RelocInfo::JS_RETURN: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 452 | return "js return"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 453 | case RelocInfo::COMMENT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | return "comment"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 455 | case RelocInfo::POSITION: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | return "position"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 457 | case RelocInfo::STATEMENT_POSITION: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 458 | return "statement position"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 459 | case RelocInfo::EXTERNAL_REFERENCE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | return "external reference"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 461 | case RelocInfo::INTERNAL_REFERENCE: |
| 462 | return "internal reference"; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 463 | case RelocInfo::DEBUG_BREAK_SLOT: |
| 464 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 465 | UNREACHABLE(); |
| 466 | #endif |
| 467 | return "debug break slot"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 468 | case RelocInfo::NUMBER_OF_MODES: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | UNREACHABLE(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 470 | return "number_of_modes"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | } |
| 472 | return "unknown relocation type"; |
| 473 | } |
| 474 | |
| 475 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 476 | void RelocInfo::Print(FILE* out) { |
| 477 | PrintF(out, "%p %s", pc_, RelocModeName(rmode_)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 478 | if (IsComment(rmode_)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 479 | PrintF(out, " (%s)", reinterpret_cast<char*>(data_)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 480 | } else if (rmode_ == EMBEDDED_OBJECT) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 481 | PrintF(out, " ("); |
| 482 | target_object()->ShortPrint(out); |
| 483 | PrintF(out, ")"); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 484 | } else if (rmode_ == EXTERNAL_REFERENCE) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | ExternalReferenceEncoder ref_encoder; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 486 | PrintF(out, " (%s) (%p)", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 487 | ref_encoder.NameOfAddress(*target_reference_address()), |
| 488 | *target_reference_address()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 489 | } else if (IsCodeTarget(rmode_)) { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 490 | Code* code = Code::GetCodeFromTargetAddress(target_address()); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 491 | PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()), |
| 492 | target_address()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 493 | } else if (IsPosition(rmode_)) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 494 | PrintF(out, " (%" V8_PTR_PREFIX "d)", data()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 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) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 500 | PrintF(out, " (deoptimization bailout %d)", id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 501 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 502 | } |
| 503 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 504 | PrintF(out, "\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 505 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 506 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 507 | |
| 508 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 509 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 510 | void RelocInfo::Verify() { |
| 511 | switch (rmode_) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 512 | case EMBEDDED_OBJECT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | Object::VerifyPointer(target_object()); |
| 514 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 515 | case GLOBAL_PROPERTY_CELL: |
| 516 | Object::VerifyPointer(target_cell()); |
| 517 | break; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 518 | case DEBUG_BREAK: |
| 519 | #ifndef ENABLE_DEBUGGER_SUPPORT |
| 520 | UNREACHABLE(); |
| 521 | break; |
| 522 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 523 | case CONSTRUCT_CALL: |
| 524 | case CODE_TARGET_CONTEXT: |
| 525 | case CODE_TARGET: { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 530 | Code* code = Code::GetCodeFromTargetAddress(addr); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 531 | Object* found = HEAP->FindCodeObject(addr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | ASSERT(found->IsCode()); |
| 533 | ASSERT(code->address() == HeapObject::cast(found)->address()); |
| 534 | break; |
| 535 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +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: |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 543 | case DEBUG_BREAK_SLOT: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 544 | case NONE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | break; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 546 | case NUMBER_OF_MODES: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | UNREACHABLE(); |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | #endif // DEBUG |
| 552 | |
| 553 | |
| 554 | // ----------------------------------------------------------------------------- |
| 555 | // Implementation of ExternalReference |
| 556 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 557 | ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) |
| 558 | : address_(Redirect(isolate, Builtins::c_function_address(id))) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | |
| 560 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 561 | ExternalReference::ExternalReference( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 562 | ApiFunction* fun, |
| 563 | Type type = ExternalReference::BUILTIN_CALL, |
| 564 | Isolate* isolate = NULL) |
| 565 | : address_(Redirect(isolate, fun->address(), type)) {} |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 566 | |
| 567 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 568 | ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate) |
| 569 | : address_(isolate->builtins()->builtin_address(name)) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | |
| 571 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 572 | ExternalReference::ExternalReference(Runtime::FunctionId id, |
| 573 | Isolate* isolate) |
| 574 | : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | |
| 576 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 577 | ExternalReference::ExternalReference(const Runtime::Function* f, |
| 578 | Isolate* isolate) |
| 579 | : address_(Redirect(isolate, f->entry)) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | |
| 581 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [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())) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 590 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 591 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | ExternalReference::ExternalReference(const Debug_Address& debug_address, |
| 593 | Isolate* isolate) |
| 594 | : address_(debug_address.address(isolate)) {} |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 595 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 596 | |
| 597 | ExternalReference::ExternalReference(StatsCounter* counter) |
| 598 | : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {} |
| 599 | |
| 600 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 601 | ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate) |
| 602 | : address_(isolate->get_address_from_id(id)) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 603 | |
| 604 | |
| 605 | ExternalReference::ExternalReference(const SCTableReference& table_ref) |
| 606 | : address_(table_ref.address()) {} |
| 607 | |
| 608 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 609 | ExternalReference ExternalReference::perform_gc_function(Isolate* isolate) { |
| 610 | return ExternalReference(Redirect(isolate, |
| 611 | FUNCTION_ADDR(Runtime::PerformGC))); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [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))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 623 | ExternalReference ExternalReference::delete_handle_scope_extensions( |
| 624 | Isolate* isolate) { |
| 625 | return ExternalReference(Redirect( |
| 626 | isolate, |
| 627 | FUNCTION_ADDR(HandleScope::DeleteExtensions))); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 631 | ExternalReference ExternalReference::random_uint32_function( |
| 632 | Isolate* isolate) { |
| 633 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random))); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 637 | ExternalReference ExternalReference::transcendental_cache_array_address( |
| 638 | Isolate* isolate) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 639 | return ExternalReference( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 640 | isolate->transcendental_cache()->cache_array_address()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 644 | ExternalReference ExternalReference::new_deoptimizer_function( |
| 645 | Isolate* isolate) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 646 | return ExternalReference( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 647 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 651 | ExternalReference ExternalReference::compute_output_frames_function( |
| 652 | Isolate* isolate) { |
| 653 | return ExternalReference( |
| 654 | Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 658 | ExternalReference ExternalReference::global_contexts_list(Isolate* isolate) { |
| 659 | return ExternalReference(isolate->heap()->global_contexts_list_address()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 663 | ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) { |
| 664 | return ExternalReference(isolate->keyed_lookup_cache()->keys_address()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 668 | ExternalReference ExternalReference::keyed_lookup_cache_field_offsets( |
| 669 | Isolate* isolate) { |
| 670 | return ExternalReference( |
| 671 | isolate->keyed_lookup_cache()->field_offsets_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 675 | ExternalReference ExternalReference::the_hole_value_location(Isolate* isolate) { |
| 676 | return ExternalReference(isolate->factory()->the_hole_value().location()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 680 | ExternalReference ExternalReference::arguments_marker_location( |
| 681 | Isolate* isolate) { |
| 682 | return ExternalReference(isolate->factory()->arguments_marker().location()); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 686 | ExternalReference ExternalReference::roots_address(Isolate* isolate) { |
| 687 | return ExternalReference(isolate->heap()->roots_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 691 | ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) { |
| 692 | return ExternalReference(isolate->stack_guard()->address_of_jslimit()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 696 | ExternalReference ExternalReference::address_of_real_stack_limit( |
| 697 | Isolate* isolate) { |
| 698 | return ExternalReference(isolate->stack_guard()->address_of_real_jslimit()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 702 | ExternalReference ExternalReference::address_of_regexp_stack_limit( |
| 703 | Isolate* isolate) { |
| 704 | return ExternalReference(isolate->regexp_stack()->limit_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 705 | } |
| 706 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 707 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 708 | ExternalReference ExternalReference::new_space_start(Isolate* isolate) { |
| 709 | return ExternalReference(isolate->heap()->NewSpaceStart()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 713 | ExternalReference ExternalReference::new_space_mask(Isolate* isolate) { |
| 714 | Address mask = reinterpret_cast<Address>(isolate->heap()->NewSpaceMask()); |
| 715 | return ExternalReference(mask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | } |
| 717 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 718 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 719 | ExternalReference ExternalReference::new_space_allocation_top_address( |
| 720 | Isolate* isolate) { |
| 721 | return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress()); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 722 | } |
| 723 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 724 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [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()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 735 | } |
| 736 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 737 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 738 | ExternalReference ExternalReference::handle_scope_level_address() { |
| 739 | return ExternalReference(HandleScope::current_level_address()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 753 | ExternalReference ExternalReference::scheduled_exception_address( |
| 754 | Isolate* isolate) { |
| 755 | return ExternalReference(isolate->scheduled_exception_address()); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [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 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [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 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 783 | ExternalReference ExternalReference::address_of_nan() { |
| 784 | return ExternalReference(reinterpret_cast<void*>( |
| 785 | const_cast<double*>(&DoubleConstant::nan))); |
| 786 | } |
| 787 | |
| 788 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 789 | #ifndef V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 790 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 791 | ExternalReference ExternalReference::re_check_stack_guard_state( |
| 792 | Isolate* isolate) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +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); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame^] | 800 | #elif V8_TARGET_ARCH_MIPS |
| 801 | function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 802 | #else |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 803 | UNREACHABLE(); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 804 | #endif |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 805 | return ExternalReference(Redirect(isolate, function)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 806 | } |
| 807 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 808 | ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 809 | return ExternalReference( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 810 | Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack))); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 811 | } |
| 812 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 813 | ExternalReference ExternalReference::re_case_insensitive_compare_uc16( |
| 814 | Isolate* isolate) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 815 | return ExternalReference(Redirect( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 816 | isolate, |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 817 | FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16))); |
| 818 | } |
| 819 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 820 | ExternalReference ExternalReference::re_word_character_map() { |
| 821 | return ExternalReference( |
| 822 | NativeRegExpMacroAssembler::word_character_map_address()); |
| 823 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 824 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 825 | ExternalReference ExternalReference::address_of_static_offsets_vector( |
| 826 | Isolate* isolate) { |
| 827 | return ExternalReference( |
| 828 | OffsetsVector::static_offsets_vector_address(isolate)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 829 | } |
| 830 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 831 | ExternalReference ExternalReference::address_of_regexp_stack_memory_address( |
| 832 | Isolate* isolate) { |
| 833 | return ExternalReference( |
| 834 | isolate->regexp_stack()->memory_address()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 835 | } |
| 836 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 837 | ExternalReference ExternalReference::address_of_regexp_stack_memory_size( |
| 838 | Isolate* isolate) { |
| 839 | return ExternalReference(isolate->regexp_stack()->memory_size_address()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 840 | } |
| 841 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 842 | #endif // V8_INTERPRETED_REGEXP |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 843 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 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 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 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) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 866 | return modulo(x, y); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 885 | ExternalReference ExternalReference::math_sin_double_function( |
| 886 | Isolate* isolate) { |
| 887 | return ExternalReference(Redirect(isolate, |
| 888 | FUNCTION_ADDR(math_sin_double), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 889 | FP_RETURN_CALL)); |
| 890 | } |
| 891 | |
| 892 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 893 | ExternalReference ExternalReference::math_cos_double_function( |
| 894 | Isolate* isolate) { |
| 895 | return ExternalReference(Redirect(isolate, |
| 896 | FUNCTION_ADDR(math_cos_double), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 897 | FP_RETURN_CALL)); |
| 898 | } |
| 899 | |
| 900 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 901 | ExternalReference ExternalReference::math_log_double_function( |
| 902 | Isolate* isolate) { |
| 903 | return ExternalReference(Redirect(isolate, |
| 904 | FUNCTION_ADDR(math_log_double), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 905 | FP_RETURN_CALL)); |
| 906 | } |
| 907 | |
| 908 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [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)) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [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); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 944 | ExternalReference ExternalReference::power_double_double_function( |
| 945 | Isolate* isolate) { |
| 946 | return ExternalReference(Redirect(isolate, |
| 947 | FUNCTION_ADDR(power_double_double), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 948 | FP_RETURN_CALL)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 952 | ExternalReference ExternalReference::power_double_int_function( |
| 953 | Isolate* isolate) { |
| 954 | return ExternalReference(Redirect(isolate, |
| 955 | FUNCTION_ADDR(power_double_int), |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 956 | FP_RETURN_CALL)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +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; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 966 | ExternalReference ExternalReference::double_fp_operation( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 967 | Token::Value operation, Isolate* isolate) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +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; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 980 | case Token::DIV: |
| 981 | function = &div_two_doubles; |
| 982 | break; |
| 983 | case Token::MOD: |
| 984 | function = &mod_two_doubles; |
| 985 | break; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 986 | default: |
| 987 | UNREACHABLE(); |
| 988 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 989 | // Passing true as 2nd parameter indicates that they return an fp value. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 990 | return ExternalReference(Redirect(isolate, |
| 991 | FUNCTION_ADDR(function), |
| 992 | FP_RETURN_CALL)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 996 | ExternalReference ExternalReference::compare_doubles(Isolate* isolate) { |
| 997 | return ExternalReference(Redirect(isolate, |
| 998 | FUNCTION_ADDR(native_compare_doubles), |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 999 | BUILTIN_CALL)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1003 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1004 | ExternalReference ExternalReference::debug_break(Isolate* isolate) { |
| 1005 | return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug::Break))); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1009 | ExternalReference ExternalReference::debug_step_in_fp_address( |
| 1010 | Isolate* isolate) { |
| 1011 | return ExternalReference(isolate->debug()->step_in_fp_addr()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1012 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1013 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1014 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1015 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1016 | void PositionsRecorder::RecordPosition(int pos) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1017 | ASSERT(pos != RelocInfo::kNoPosition); |
| 1018 | ASSERT(pos >= 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1019 | state_.current_position = pos; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [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 |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | void PositionsRecorder::RecordStatementPosition(int pos) { |
| 1029 | ASSERT(pos != RelocInfo::kNoPosition); |
| 1030 | ASSERT(pos >= 0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1031 | state_.current_statement_position = pos; |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [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 |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [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. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1045 | if (state_.current_statement_position != state_.written_statement_position) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1046 | EnsureSpace ensure_space(assembler_); |
| 1047 | assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1048 | state_.current_statement_position); |
| 1049 | state_.written_statement_position = state_.current_statement_position; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1050 | written = true; |
| 1051 | } |
| 1052 | |
| 1053 | // Write the position if it is different from what was written last time and |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [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) { |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1057 | EnsureSpace ensure_space(assembler_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1058 | assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
| 1059 | state_.written_position = state_.current_position; |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1060 | written = true; |
| 1061 | } |
| 1062 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1063 | // Return whether something was written. |
| 1064 | return written; |
| 1065 | } |
| 1066 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1067 | } } // namespace v8::internal |