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 | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 33 | // Copyright 2006-2008 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" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 46 | namespace v8 { namespace internal { |
| 47 | |
| 48 | |
| 49 | // ----------------------------------------------------------------------------- |
| 50 | // Implementation of Label |
| 51 | |
| 52 | int Label::pos() const { |
| 53 | if (pos_ < 0) return -pos_ - 1; |
| 54 | if (pos_ > 0) return pos_ - 1; |
| 55 | UNREACHABLE(); |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | // ----------------------------------------------------------------------------- |
| 61 | // Implementation of RelocInfoWriter and RelocIterator |
| 62 | // |
| 63 | // Encoding |
| 64 | // |
| 65 | // The most common modes are given single-byte encodings. Also, it is |
| 66 | // easy to identify the type of reloc info and skip unwanted modes in |
| 67 | // an iteration. |
| 68 | // |
| 69 | // The encoding relies on the fact that there are less than 14 |
| 70 | // different relocation modes. |
| 71 | // |
| 72 | // embedded_object: [6 bits pc delta] 00 |
| 73 | // |
| 74 | // code_taget: [6 bits pc delta] 01 |
| 75 | // |
| 76 | // position: [6 bits pc delta] 10, |
| 77 | // [7 bits signed data delta] 0 |
| 78 | // |
| 79 | // statement_position: [6 bits pc delta] 10, |
| 80 | // [7 bits signed data delta] 1 |
| 81 | // |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 82 | // 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] | 83 | // 00 [6 bits pc delta] |
| 84 | // |
| 85 | // pc-jump: 00 1111 11, |
| 86 | // 00 [6 bits pc delta] |
| 87 | // |
| 88 | // pc-jump: 01 1111 11, |
| 89 | // (variable length) 7 - 26 bit pc delta, written in chunks of 7 |
| 90 | // bits, the lowest 7 bits written first. |
| 91 | // |
| 92 | // data-jump + pos: 00 1110 11, |
| 93 | // signed int, lowest byte written first |
| 94 | // |
| 95 | // data-jump + st.pos: 01 1110 11, |
| 96 | // signed int, lowest byte written first |
| 97 | // |
| 98 | // data-jump + comm.: 10 1110 11, |
| 99 | // signed int, lowest byte written first |
| 100 | // |
| 101 | const int kMaxRelocModes = 14; |
| 102 | |
| 103 | const int kTagBits = 2; |
| 104 | const int kTagMask = (1 << kTagBits) - 1; |
| 105 | const int kExtraTagBits = 4; |
| 106 | const int kPositionTypeTagBits = 1; |
| 107 | const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits; |
| 108 | |
| 109 | const int kEmbeddedObjectTag = 0; |
| 110 | const int kCodeTargetTag = 1; |
| 111 | const int kPositionTag = 2; |
| 112 | const int kDefaultTag = 3; |
| 113 | |
| 114 | const int kPCJumpTag = (1 << kExtraTagBits) - 1; |
| 115 | |
| 116 | const int kSmallPCDeltaBits = kBitsPerByte - kTagBits; |
| 117 | const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1; |
| 118 | |
| 119 | const int kVariableLengthPCJumpTopTag = 1; |
| 120 | const int kChunkBits = 7; |
| 121 | const int kChunkMask = (1 << kChunkBits) - 1; |
| 122 | const int kLastChunkTagBits = 1; |
| 123 | const int kLastChunkTagMask = 1; |
| 124 | const int kLastChunkTag = 1; |
| 125 | |
| 126 | |
| 127 | const int kDataJumpTag = kPCJumpTag - 1; |
| 128 | |
| 129 | const int kNonstatementPositionTag = 0; |
| 130 | const int kStatementPositionTag = 1; |
| 131 | const int kCommentTag = 2; |
| 132 | |
| 133 | |
| 134 | uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) { |
| 135 | // Return if the pc_delta can fit in kSmallPCDeltaBits bits. |
| 136 | // Otherwise write a variable length PC jump for the bits that do |
| 137 | // not fit in the kSmallPCDeltaBits bits. |
| 138 | if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; |
| 139 | WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag); |
| 140 | uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; |
| 141 | ASSERT(pc_jump > 0); |
| 142 | // Write kChunkBits size chunks of the pc_jump. |
| 143 | for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) { |
| 144 | byte b = pc_jump & kChunkMask; |
| 145 | *--pos_ = b << kLastChunkTagBits; |
| 146 | } |
| 147 | // Tag the last chunk so it can be identified. |
| 148 | *pos_ = *pos_ | kLastChunkTag; |
| 149 | // Return the remaining kSmallPCDeltaBits of the pc_delta. |
| 150 | return pc_delta & kSmallPCDeltaMask; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) { |
| 155 | // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump. |
| 156 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 157 | *--pos_ = pc_delta << kTagBits | tag; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | void RelocInfoWriter::WriteTaggedData(int32_t data_delta, int tag) { |
| 162 | *--pos_ = data_delta << kPositionTypeTagBits | tag; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) { |
| 167 | *--pos_ = top_tag << (kTagBits + kExtraTagBits) | |
| 168 | extra_tag << kTagBits | |
| 169 | kDefaultTag; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) { |
| 174 | // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump. |
| 175 | pc_delta = WriteVariableLengthPCJump(pc_delta); |
| 176 | WriteExtraTag(extra_tag, 0); |
| 177 | *--pos_ = pc_delta; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | void RelocInfoWriter::WriteExtraTaggedData(int32_t data_delta, int top_tag) { |
| 182 | WriteExtraTag(kDataJumpTag, top_tag); |
| 183 | for (int i = 0; i < kIntSize; i++) { |
| 184 | *--pos_ = data_delta; |
| 185 | data_delta = ArithmeticShiftRight(data_delta, kBitsPerByte); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | |
| 190 | void RelocInfoWriter::Write(const RelocInfo* rinfo) { |
| 191 | #ifdef DEBUG |
| 192 | byte* begin_pos = pos_; |
| 193 | #endif |
| 194 | Counters::reloc_info_count.Increment(); |
| 195 | ASSERT(rinfo->pc() - last_pc_ >= 0); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 196 | ASSERT(RelocInfo::NUMBER_OF_MODES < kMaxRelocModes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 197 | // Use unsigned delta-encoding for pc. |
| 198 | uint32_t pc_delta = rinfo->pc() - last_pc_; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 199 | RelocInfo::Mode rmode = rinfo->rmode(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | |
| 201 | // 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] | 202 | if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | WriteTaggedPC(pc_delta, kEmbeddedObjectTag); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 204 | } else if (rmode == RelocInfo::CODE_TARGET) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | WriteTaggedPC(pc_delta, kCodeTargetTag); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 206 | } else if (RelocInfo::IsPosition(rmode)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | // Use signed delta-encoding for data. |
| 208 | int32_t data_delta = rinfo->data() - last_data_; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 209 | int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag |
| 210 | : kStatementPositionTag; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | // Check if data is small enough to fit in a tagged byte. |
| 212 | if (is_intn(data_delta, kSmallDataBits)) { |
| 213 | WriteTaggedPC(pc_delta, kPositionTag); |
| 214 | WriteTaggedData(data_delta, pos_type_tag); |
| 215 | last_data_ = rinfo->data(); |
| 216 | } else { |
| 217 | // Otherwise, use costly encoding. |
| 218 | WriteExtraTaggedPC(pc_delta, kPCJumpTag); |
| 219 | WriteExtraTaggedData(data_delta, pos_type_tag); |
| 220 | last_data_ = rinfo->data(); |
| 221 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 222 | } else if (RelocInfo::IsComment(rmode)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | // Comments are normally not generated, so we use the costly encoding. |
| 224 | WriteExtraTaggedPC(pc_delta, kPCJumpTag); |
| 225 | WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag); |
| 226 | last_data_ = rinfo->data(); |
| 227 | } else { |
| 228 | // For all other modes we simply use the mode as the extra tag. |
| 229 | // None of these modes need a data component. |
| 230 | ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag); |
| 231 | WriteExtraTaggedPC(pc_delta, rmode); |
| 232 | } |
| 233 | last_pc_ = rinfo->pc(); |
| 234 | #ifdef DEBUG |
| 235 | ASSERT(begin_pos - pos_ <= kMaxSize); |
| 236 | #endif |
| 237 | } |
| 238 | |
| 239 | |
| 240 | inline int RelocIterator::AdvanceGetTag() { |
| 241 | return *--pos_ & kTagMask; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | inline int RelocIterator::GetExtraTag() { |
| 246 | return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | inline int RelocIterator::GetTopTag() { |
| 251 | return *pos_ >> (kTagBits + kExtraTagBits); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | inline void RelocIterator::ReadTaggedPC() { |
| 256 | rinfo_.pc_ += *pos_ >> kTagBits; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | inline void RelocIterator::AdvanceReadPC() { |
| 261 | rinfo_.pc_ += *--pos_; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | void RelocIterator::AdvanceReadData() { |
| 266 | int32_t x = 0; |
| 267 | for (int i = 0; i < kIntSize; i++) { |
| 268 | x |= *--pos_ << i * kBitsPerByte; |
| 269 | } |
| 270 | rinfo_.data_ += x; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | void RelocIterator::AdvanceReadVariableLengthPCJump() { |
| 275 | // Read the 32-kSmallPCDeltaBits most significant bits of the |
| 276 | // pc jump in kChunkBits bit chunks and shift them into place. |
| 277 | // Stop when the last chunk is encountered. |
| 278 | uint32_t pc_jump = 0; |
| 279 | for (int i = 0; i < kIntSize; i++) { |
| 280 | byte pc_jump_part = *--pos_; |
| 281 | pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits; |
| 282 | if ((pc_jump_part & kLastChunkTagMask) == 1) break; |
| 283 | } |
| 284 | // The least significant kSmallPCDeltaBits bits will be added |
| 285 | // later. |
| 286 | rinfo_.pc_ += pc_jump << kSmallPCDeltaBits; |
| 287 | } |
| 288 | |
| 289 | |
| 290 | inline int RelocIterator::GetPositionTypeTag() { |
| 291 | return *pos_ & ((1 << kPositionTypeTagBits) - 1); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | inline void RelocIterator::ReadTaggedData() { |
| 296 | int8_t signed_b = *pos_; |
| 297 | rinfo_.data_ += ArithmeticShiftRight(signed_b, kPositionTypeTagBits); |
| 298 | } |
| 299 | |
| 300 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 301 | inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 302 | if (tag == kStatementPositionTag) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 303 | return RelocInfo::STATEMENT_POSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | } else if (tag == kNonstatementPositionTag) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 305 | return RelocInfo::POSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 306 | } else { |
| 307 | ASSERT(tag == kCommentTag); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 308 | return RelocInfo::COMMENT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | |
| 313 | void RelocIterator::next() { |
| 314 | ASSERT(!done()); |
| 315 | // Basically, do the opposite of RelocInfoWriter::Write. |
| 316 | // Reading of data is as far as possible avoided for unwanted modes, |
| 317 | // but we must always update the pc. |
| 318 | // |
| 319 | // We exit this loop by returning when we find a mode we want. |
| 320 | while (pos_ > end_) { |
| 321 | int tag = AdvanceGetTag(); |
| 322 | if (tag == kEmbeddedObjectTag) { |
| 323 | ReadTaggedPC(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 324 | if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | } else if (tag == kCodeTargetTag) { |
| 326 | ReadTaggedPC(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 327 | if (*(reinterpret_cast<int*>(rinfo_.pc())) == 0x61) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | tag = 0; |
| 329 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 330 | if (SetMode(RelocInfo::CODE_TARGET)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | } else if (tag == kPositionTag) { |
| 332 | ReadTaggedPC(); |
| 333 | Advance(); |
| 334 | // Check if we want source positions. |
| 335 | if (mode_mask_ & RelocInfo::kPositionMask) { |
| 336 | // Check if we want this type of source position. |
| 337 | if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) { |
| 338 | // Finally read the data before returning. |
| 339 | ReadTaggedData(); |
| 340 | return; |
| 341 | } |
| 342 | } |
| 343 | } else { |
| 344 | ASSERT(tag == kDefaultTag); |
| 345 | int extra_tag = GetExtraTag(); |
| 346 | if (extra_tag == kPCJumpTag) { |
| 347 | int top_tag = GetTopTag(); |
| 348 | if (top_tag == kVariableLengthPCJumpTopTag) { |
| 349 | AdvanceReadVariableLengthPCJump(); |
| 350 | } else { |
| 351 | AdvanceReadPC(); |
| 352 | } |
| 353 | } else if (extra_tag == kDataJumpTag) { |
| 354 | // Check if we want debug modes (the only ones with data). |
| 355 | if (mode_mask_ & RelocInfo::kDebugMask) { |
| 356 | int top_tag = GetTopTag(); |
| 357 | AdvanceReadData(); |
| 358 | if (SetMode(DebugInfoModeFromTag(top_tag))) return; |
| 359 | } else { |
| 360 | // Otherwise, just skip over the data. |
| 361 | Advance(kIntSize); |
| 362 | } |
| 363 | } else { |
| 364 | AdvanceReadPC(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 365 | if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | done_ = true; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | RelocIterator::RelocIterator(Code* code, int mode_mask) { |
| 374 | rinfo_.pc_ = code->instruction_start(); |
| 375 | rinfo_.data_ = 0; |
| 376 | // relocation info is read backwards |
| 377 | pos_ = code->relocation_start() + code->relocation_size(); |
| 378 | end_ = code->relocation_start(); |
| 379 | done_ = false; |
| 380 | mode_mask_ = mode_mask; |
| 381 | if (mode_mask_ == 0) pos_ = end_; |
| 382 | next(); |
| 383 | } |
| 384 | |
| 385 | |
| 386 | RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) { |
| 387 | rinfo_.pc_ = desc.buffer; |
| 388 | rinfo_.data_ = 0; |
| 389 | // relocation info is read backwards |
| 390 | pos_ = desc.buffer + desc.buffer_size; |
| 391 | end_ = pos_ - desc.reloc_size; |
| 392 | done_ = false; |
| 393 | mode_mask_ = mode_mask; |
| 394 | if (mode_mask_ == 0) pos_ = end_; |
| 395 | next(); |
| 396 | } |
| 397 | |
| 398 | |
| 399 | // ----------------------------------------------------------------------------- |
| 400 | // Implementation of RelocInfo |
| 401 | |
| 402 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 403 | #ifdef ENABLE_DISASSEMBLER |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 404 | const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | switch (rmode) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 406 | case RelocInfo::NONE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | return "no reloc"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 408 | case RelocInfo::EMBEDDED_OBJECT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | return "embedded object"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 410 | case RelocInfo::EMBEDDED_STRING: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 411 | return "embedded string"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 412 | case RelocInfo::CONSTRUCT_CALL: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 413 | return "code target (js construct call)"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 414 | case RelocInfo::CODE_TARGET_CONTEXT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 415 | return "code target (context)"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 416 | case RelocInfo::CODE_TARGET: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 417 | return "code target"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 418 | case RelocInfo::RUNTIME_ENTRY: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 419 | return "runtime entry"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 420 | case RelocInfo::JS_RETURN: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 421 | return "js return"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 422 | case RelocInfo::COMMENT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 423 | return "comment"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 424 | case RelocInfo::POSITION: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | return "position"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 426 | case RelocInfo::STATEMENT_POSITION: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | return "statement position"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 428 | case RelocInfo::EXTERNAL_REFERENCE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 429 | return "external reference"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 430 | case RelocInfo::INTERNAL_REFERENCE: |
| 431 | return "internal reference"; |
| 432 | case RelocInfo::NUMBER_OF_MODES: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | UNREACHABLE(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 434 | return "number_of_modes"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 435 | } |
| 436 | return "unknown relocation type"; |
| 437 | } |
| 438 | |
| 439 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 440 | void RelocInfo::Print() { |
| 441 | PrintF("%p %s", pc_, RelocModeName(rmode_)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 442 | if (IsComment(rmode_)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 443 | PrintF(" (%s)", data_); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 444 | } else if (rmode_ == EMBEDDED_OBJECT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 445 | PrintF(" ("); |
| 446 | target_object()->ShortPrint(); |
| 447 | PrintF(")"); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 448 | } else if (rmode_ == EXTERNAL_REFERENCE) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | ExternalReferenceEncoder ref_encoder; |
| 450 | PrintF(" (%s) (%p)", |
| 451 | ref_encoder.NameOfAddress(*target_reference_address()), |
| 452 | *target_reference_address()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 453 | } else if (IsCodeTarget(rmode_)) { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 454 | Code* code = Code::GetCodeFromTargetAddress(target_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | PrintF(" (%s) (%p)", Code::Kind2String(code->kind()), target_address()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 456 | } else if (IsPosition(rmode_)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 457 | PrintF(" (%d)", data()); |
| 458 | } |
| 459 | |
| 460 | PrintF("\n"); |
| 461 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 462 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | |
| 464 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 465 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 466 | void RelocInfo::Verify() { |
| 467 | switch (rmode_) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 468 | case EMBEDDED_OBJECT: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | Object::VerifyPointer(target_object()); |
| 470 | break; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 471 | case CONSTRUCT_CALL: |
| 472 | case CODE_TARGET_CONTEXT: |
| 473 | case CODE_TARGET: { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 474 | // convert inline target address to code object |
| 475 | Address addr = target_address(); |
| 476 | ASSERT(addr != NULL); |
| 477 | // Check that we can find the right code object. |
| 478 | HeapObject* code = HeapObject::FromAddress(addr - Code::kHeaderSize); |
| 479 | Object* found = Heap::FindCodeObject(addr); |
| 480 | ASSERT(found->IsCode()); |
| 481 | ASSERT(code->address() == HeapObject::cast(found)->address()); |
| 482 | break; |
| 483 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 484 | case RelocInfo::EMBEDDED_STRING: |
| 485 | case RUNTIME_ENTRY: |
| 486 | case JS_RETURN: |
| 487 | case COMMENT: |
| 488 | case POSITION: |
| 489 | case STATEMENT_POSITION: |
| 490 | case EXTERNAL_REFERENCE: |
| 491 | case INTERNAL_REFERENCE: |
| 492 | case NONE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 493 | break; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 494 | case NUMBER_OF_MODES: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 495 | UNREACHABLE(); |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | #endif // DEBUG |
| 500 | |
| 501 | |
| 502 | // ----------------------------------------------------------------------------- |
| 503 | // Implementation of ExternalReference |
| 504 | |
| 505 | ExternalReference::ExternalReference(Builtins::CFunctionId id) |
| 506 | : address_(Builtins::c_function_address(id)) {} |
| 507 | |
| 508 | |
| 509 | ExternalReference::ExternalReference(Builtins::Name name) |
| 510 | : address_(Builtins::builtin_address(name)) {} |
| 511 | |
| 512 | |
| 513 | ExternalReference::ExternalReference(Runtime::FunctionId id) |
| 514 | : address_(Runtime::FunctionForId(id)->entry) {} |
| 515 | |
| 516 | |
| 517 | ExternalReference::ExternalReference(Runtime::Function* f) |
| 518 | : address_(f->entry) {} |
| 519 | |
| 520 | |
| 521 | ExternalReference::ExternalReference(const IC_Utility& ic_utility) |
| 522 | : address_(ic_utility.address()) {} |
| 523 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 524 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | ExternalReference::ExternalReference(const Debug_Address& debug_address) |
| 526 | : address_(debug_address.address()) {} |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 527 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | |
| 529 | ExternalReference::ExternalReference(StatsCounter* counter) |
| 530 | : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {} |
| 531 | |
| 532 | |
| 533 | ExternalReference::ExternalReference(Top::AddressId id) |
| 534 | : address_(Top::get_address_from_id(id)) {} |
| 535 | |
| 536 | |
| 537 | ExternalReference::ExternalReference(const SCTableReference& table_ref) |
| 538 | : address_(table_ref.address()) {} |
| 539 | |
| 540 | |
| 541 | ExternalReference ExternalReference::builtin_passed_function() { |
| 542 | return ExternalReference(&Builtins::builtin_passed_function); |
| 543 | } |
| 544 | |
| 545 | ExternalReference ExternalReference::the_hole_value_location() { |
| 546 | return ExternalReference(Factory::the_hole_value().location()); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | ExternalReference ExternalReference::address_of_stack_guard_limit() { |
| 551 | return ExternalReference(StackGuard::address_of_jslimit()); |
| 552 | } |
| 553 | |
| 554 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 555 | ExternalReference ExternalReference::address_of_regexp_stack_limit() { |
| 556 | return ExternalReference(RegExpStack::limit_address()); |
| 557 | } |
| 558 | |
| 559 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 560 | ExternalReference ExternalReference::new_space_start() { |
| 561 | return ExternalReference(Heap::NewSpaceStart()); |
| 562 | } |
| 563 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 564 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | ExternalReference ExternalReference::new_space_allocation_top_address() { |
| 566 | return ExternalReference(Heap::NewSpaceAllocationTopAddress()); |
| 567 | } |
| 568 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 569 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 570 | ExternalReference ExternalReference::heap_always_allocate_scope_depth() { |
| 571 | return ExternalReference(Heap::always_allocate_scope_depth_address()); |
| 572 | } |
| 573 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 574 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 575 | ExternalReference ExternalReference::new_space_allocation_limit_address() { |
| 576 | return ExternalReference(Heap::NewSpaceAllocationLimitAddress()); |
| 577 | } |
| 578 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 579 | |
| 580 | static double add_two_doubles(double x, double y) { |
| 581 | return x + y; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | static double sub_two_doubles(double x, double y) { |
| 586 | return x - y; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | static double mul_two_doubles(double x, double y) { |
| 591 | return x * y; |
| 592 | } |
| 593 | |
| 594 | |
| 595 | ExternalReference ExternalReference::double_fp_operation( |
| 596 | Token::Value operation) { |
| 597 | typedef double BinaryFPOperation(double x, double y); |
| 598 | BinaryFPOperation* function = NULL; |
| 599 | switch (operation) { |
| 600 | case Token::ADD: |
| 601 | function = &add_two_doubles; |
| 602 | break; |
| 603 | case Token::SUB: |
| 604 | function = &sub_two_doubles; |
| 605 | break; |
| 606 | case Token::MUL: |
| 607 | function = &mul_two_doubles; |
| 608 | break; |
| 609 | default: |
| 610 | UNREACHABLE(); |
| 611 | } |
| 612 | return ExternalReference(FUNCTION_ADDR(function)); |
| 613 | } |
| 614 | |
| 615 | |
| 616 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 617 | ExternalReference ExternalReference::debug_break() { |
| 618 | return ExternalReference(FUNCTION_ADDR(Debug::Break)); |
| 619 | } |
| 620 | |
| 621 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | ExternalReference ExternalReference::debug_step_in_fp_address() { |
| 623 | return ExternalReference(Debug::step_in_fp_addr()); |
| 624 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame^] | 625 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | |
| 627 | } } // namespace v8::internal |