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