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