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